forked from VANCOLD/fm_drive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FM_ADMIN_ACCESS.sma
184 lines (149 loc) · 4.95 KB
/
FM_ADMIN_ACCESS.sma
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
DESCRIPTION
-Grant admins their access when they connect.
NOTES
-Provides natives for other plugins to access an admins "real" name, unique ident # and access level. This is used when checking if
a user can run a command, and when printing a command to all users when an an admin successfully runs it.
-Relies on a forward from FM_ADMIN_API, fm_AdminInfoUpdated()
-Provides password functionality for use in cases where a user shares their account.
COMMANDS
-"admin_refresh" - Allows a player to manually reload their access e.g. If their password failed.
AUTHOR:
-watch
DATE:
-2006 - 2010
*/
#include "feckinmad/fm_global"
#include "feckinmad/fm_admin_api"
#include "feckinmad/fm_admin_access"
new const g_sPasswordField[] = "_fm_auth_password"
new g_PlayerAdminInfo[MAX_PLAYERS + 1][eAdmin_t]
new g_iMaxPlayers
new Float:g_fPlayerNextAdminRefresh[MAX_PLAYERS + 1]
public plugin_init()
{
fm_RegisterPlugin()
register_concmd("admin_refresh", "Admin_Refresh")
g_iMaxPlayers = get_maxplayers()
copy(g_PlayerAdminInfo[0][m_sAdminName], 5, "RCON")
g_PlayerAdminInfo[0][m_iAdminIdent] = -1
}
public Admin_Refresh(id)
{
if (!id)
{
return PLUGIN_HANDLED
}
new Float:fGameTime = get_gametime()
if (fGameTime < g_fPlayerNextAdminRefresh[id])
{
console_print(id, "Please wait another %d seconds before attempting to refresh your admin", floatround(g_fPlayerNextAdminRefresh[id] - fGameTime, floatround_ceil))
return PLUGIN_HANDLED
}
console_print(id, "Attempting to refresh your admin")
g_fPlayerNextAdminRefresh[id] = fGameTime + 10.0
ClientAuthorized(id)
return PLUGIN_HANDLED
}
public plugin_natives()
{
register_native("fm_GetUserRealname","Native_GetRealName")
register_native("fm_GetUserAccess","Native_GetAccess")
register_native("fm_GetUserIdent","Native_GetIdentifier")
register_library(g_sAdminAccessLibName)
}
public fm_AdminInfoUpdated()
{
for (new i = 1; i <= g_iMaxPlayers; i++)
{
if (is_user_connected(i) || is_user_connecting(i))
{
ClientAuthorized(i)
}
}
}
public client_connect(id)
{
arrayset(g_PlayerAdminInfo[id], 0, eAdmin_t)
}
public client_authorized(id)
{
ClientAuthorized(id)
}
ClientAuthorized(id)
{
arrayset(g_PlayerAdminInfo[id], 0, eAdmin_t)
new sName[MAX_NAME_LEN], sAuthid[MAX_AUTHID_LEN]
get_user_authid(id, sAuthid, charsmax(sAuthid))
new iCount = fm_GetAdminCount()
new eBuffer[eAdmin_t], sPassword[32]
for (new i = 0; i < iCount; i++)
{
fm_GetAdminInfoByIndex(i, eBuffer)
if(eBuffer[m_iAdminActive] && equali(sAuthid, eBuffer[m_sAdminAuthid]))
{
get_user_name(id, sName, charsmax(sName))
get_user_info(id, g_sPasswordField, sPassword, charsmax(sPassword))
if (equal(eBuffer[m_sAdminPassword], sPassword))
{
fm_CopyStruc(eBuffer, g_PlayerAdminInfo[id], eAdmin_t)
log_amx("\"%s\"<%s>(%s) authorized. Access: %d Ident: %d", sName, g_PlayerAdminInfo[id][m_sAdminAuthid], g_PlayerAdminInfo[id][m_sAdminName], g_PlayerAdminInfo[id][m_iAdminAccess], g_PlayerAdminInfo[id][m_iAdminIdent])
console_print(id, "You authorized using <%s> with access level %d", g_PlayerAdminInfo[id][m_sAdminAuthid], g_PlayerAdminInfo[id][m_iAdminAccess])
}
else if (!sPassword[0])
{
console_print(id, "You must specify your password to authorize. Check the forum for more information")
log_amx("\"%s\"<%s>(%s) failed to authorize (No password specified). Access: %d Ident: %d", sName, eBuffer[m_sAdminAuthid], eBuffer[m_sAdminName], eBuffer[m_iAdminAccess], eBuffer[m_iAdminIdent])
}
else
{
console_print(id, "Your authorization password was incorrect. Contact a senior admin for help")
log_amx("\"%s\"<%s>(%s) failed to authorize (Incorrect password). Access: %d Ident: %d", sName, eBuffer[m_sAdminAuthid], eBuffer[m_sAdminName], eBuffer[m_iAdminAccess], eBuffer[m_iAdminIdent])
}
break
}
}
}
public client_disconnected(id)
{
if (g_PlayerAdminInfo[id][m_iAdminAccess] > 0)
{
new sName[MAX_NAME_LEN]; get_user_name(id, sName, charsmax(sName))
log_amx("\"%s\"<%s>(%s) disconnected. Access: %d Ident: %d", sName, g_PlayerAdminInfo[id][m_sAdminAuthid], g_PlayerAdminInfo[id][m_sAdminName], g_PlayerAdminInfo[id][m_iAdminAccess], g_PlayerAdminInfo[id][m_iAdminIdent])
}
arrayset(g_PlayerAdminInfo[id], 0, eAdmin_t)
}
public Native_GetRealName()
{
new id = get_param(1)
if (id < 0 || id > g_iMaxPlayers)
{
log_error(AMX_ERR_NATIVE, "Player out of range (%d)", id)
return 0
}
if (g_PlayerAdminInfo[id][m_sAdminName][0])
set_string(2, g_PlayerAdminInfo[id][m_sAdminName], get_param(3))
else
set_string(2, "Player", get_param(3))
return 1
}
public Native_GetAccess()
{
new id = get_param(1)
if (id < 1 || id > g_iMaxPlayers)
{
log_error(AMX_ERR_NATIVE, "Player out of range (%d)", id)
return 0
}
return g_PlayerAdminInfo[id][m_iAdminAccess]
}
public Native_GetIdentifier()
{
new id = get_param(1)
if (id < 0 || id > g_iMaxPlayers)
{
log_error(AMX_ERR_NATIVE, "Player out of range (%d)", id)
return 0
}
return g_PlayerAdminInfo[id][m_iAdminIdent]
}