-
Notifications
You must be signed in to change notification settings - Fork 0
/
amx_show.sma
273 lines (234 loc) · 7.95 KB
/
amx_show.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#include <amxmodx>
#include <amxmisc>
#pragma defclasslib sqlx sqlite
#include <sqlx>
#include <reapi>
// PLUGIN INFO
#define PLUGIN "ShowPlayerName"
#define VERSION "1.0"
#define AUTHOR "mi0"
// DATABASE INFO
#define BASE "amxshow"
#define TABLE "users"
enum _:PlayerInfo
{
Name[33],
IP[33],
Steam[64]
}
new Handle:g_iSQLTuple
new g_szUserName[MAX_PLAYERS + 1][33]
new Array:g_aTempPlayerArray
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_concmd("amx_show", "OnCmdShow", ADMIN_BAN, " - Used to check if the player has any other nicknames")
if (SQL_SetAffinity("sqlite") == 0)
{
log_amx("No sqlite driver found!")
set_fail_state("No sqlite driver found!")
}
}
public plugin_cfg()
{
g_aTempPlayerArray = ArrayCreate(PlayerInfo)
SQL_Init()
}
public plugin_end()
{
SQL_FreeHandle(g_iSQLTuple)
}
SQL_Init()
{
// Create DataBase Tuple used to connect to the SQL Server
g_iSQLTuple = SQL_MakeDbTuple("", "", "", BASE)
if (g_iSQLTuple == Empty_Handle)
{
set_fail_state("[%s] Failed to create tuple [%s]", PLUGIN, BASE)
}
// Format the query and launch a thread worker to wait for its execution
// (The thread worker is not that necessary since the players still havent connected so they wont experience any lag)
new szQuery[256]
formatex(szQuery, charsmax(szQuery), "CREATE TABLE IF NOT EXISTS `%s`\
(`id` INTEGER PRIMARY KEY AUTOINCREMENT,\
`username` VARCHAR(32) NOT NULL,\
`useraddress` VARCHAR(32) NOT NULL,\
`usersteam` VARCHAR(64) NOT NULL);", TABLE)
SQL_ThreadQuery(g_iSQLTuple, "QueryEmptyHandle", szQuery)
}
public client_connect(id)
{
// Get user name
get_user_name(id, g_szUserName[id], charsmax(g_szUserName[]))
}
public client_authorized(id)
{
// Save user name
Func_SavePlayerName(id)
}
public client_infochanged(id)
{
// Check if the player have changed their name
new szNewName[64]
get_user_info(id, "name", szNewName, charsmax(szNewName))
if (equal(szNewName, g_szUserName[id]))
{
return
}
// Copy the name to the global name holder and save it to the data base
copy(g_szUserName[id], charsmax(g_szUserName[]), szNewName)
Func_SavePlayerName(id)
}
public OnCmdShow(id, iLevel, iCID)
{
if (!cmd_access(id, iLevel, iCID, 2))
{
return PLUGIN_HANDLED
}
// Get client's arguments
new szArg[33]
read_argv(1, szArg, charsmax(szArg))
// Target the player by the arguments
new iTargetPlayer = cmd_target(id, szArg, CMDTARGET_ALLOW_SELF)
if (!iTargetPlayer)
{
return PLUGIN_HANDLED
}
// Inform the player some bullshit
console_print(id, "[%s] A request has been sent!", PLUGIN)
console_print(id, "[%s] Note that the plugin is using external storage and the request might take some time!", PLUGIN)
console_print(id, "[%s] Also note that we are using ^"identifiers^" that can be changed and the information might not be 100% accurate", PLUGIN)
// Request player names
Func_RequestPlayer(id, iTargetPlayer)
return PLUGIN_HANDLED
}
Func_RequestPlayer(id, iTargetPlayer)
{
// Get addtional user information to track them by
new szUserIP[33], szUserAuthID[33]
get_user_ip(iTargetPlayer, szUserIP, charsmax(szUserIP), 1)
get_user_authid(iTargetPlayer, szUserAuthID, charsmax(szUserAuthID))
// Format the query and launch a thread worker to wait for its execution
new szQuery[128], szID[2]
szID[0] = id; szID[1] = iTargetPlayer
formatex(szQuery, charsmax(szQuery), "SELECT * FROM `%s` WHERE `useraddress` = '%s' OR `usersteam` = '%s';", TABLE, szUserIP, szUserAuthID)
SQL_ThreadQuery(g_iSQLTuple, "OnCommandSelectExecuted", szQuery, szID, sizeof(szID))
}
public OnCommandSelectExecuted(iFailState, Handle:iQuery, szError[], iErrorNum, szData[])
{
if (iFailState != TQUERY_SUCCESS)
{
log_amx("[%s] Failed to select", PLUGIN)
log_amx("[%s] %s", PLUGIN, szError)
return
}
new id = szData[0], iTargetPlayer = szData[1]
// Get addtional user information to track them by
new szUserIP[33], szUserAuthID[33], bool:bPlayerSteam = is_user_steam(iTargetPlayer)
get_user_ip(iTargetPlayer, szUserIP, charsmax(szUserIP), 1)
get_user_authid(iTargetPlayer, szUserAuthID, charsmax(szUserAuthID))
new eTempArray[PlayerInfo]
new iRowCount = SQL_NumResults(iQuery)
if (!iRowCount)
{
client_print(id, print_console, "[%s] We could not find any players matching the players information", PLUGIN)
return
}
if (SQL_MoreResults(iQuery))
{
for (new i = 0; i < iRowCount; i++)
{
SQL_ReadResult(iQuery, 1, eTempArray[Name], charsmax(eTempArray[Name]))
SQL_ReadResult(iQuery, 2, eTempArray[IP], charsmax(eTempArray[IP]))
SQL_ReadResult(iQuery, 3, eTempArray[Steam], charsmax(eTempArray[Steam]))
ArrayPushArray(g_aTempPlayerArray, eTempArray)
SQL_NextRow(iQuery)
}
}
// Format the frame and print target player addtional information
console_print(id, "*************************************************")
console_print(id, "Player Successfuly Requested")
console_print(id, "*************************************************")
console_print(id, "Information =>")
console_print(id, "Player IP: %s", szUserIP)
console_print(id, "Player SteamID: %s", szUserAuthID)
console_print(id, "Is Player Steam: %s", bPlayerSteam ? "Yes" : "Not")
console_print(id, "Results Found: %i", iRowCount)
console_print(id, "*************************************************")
console_print(id, "Nicknames with same IP(%s) =>", szUserIP)
for (new i = 0; i < iRowCount; i++)
{
ArrayGetArray(g_aTempPlayerArray, i, eTempArray)
if (equal(eTempArray[IP], szUserIP))
{
console_print(id, "Player Name: %s; Player SteamID: %s;", eTempArray[Name], eTempArray[Steam])
}
}
console_print(id, "*************************************************")
if (equal("HLTV", szUserAuthID) || equal("STEAM_ID_LAN", szUserAuthID) || equali("VALVE_ID_LAN", szUserAuthID))
{
console_print(id, "The Player has the standard cracked SteamID and cannot be tracked trough it!", szUserAuthID)
}
else
{
console_print(id, "Nicknames with same SteamID(%s) =>", szUserAuthID)
if (!bPlayerSteam)
{
console_print(id, "This information can be inaccurate!!!")
}
for (new i = 0; i < iRowCount; i++)
{
ArrayGetArray(g_aTempPlayerArray, i, eTempArray)
if (equal(eTempArray[Steam], szUserAuthID))
{
console_print(id, "Player Name: %s; Player IP: %s;", eTempArray[Name], eTempArray[IP])
}
}
}
console_print(id, "*************************************************")
ArrayClear(g_aTempPlayerArray)
}
Func_SavePlayerName(id)
{
// Get addtional user information to track them by
new szUserIP[33], szUserAuthID[33]
get_user_ip(id, szUserIP, charsmax(szUserIP), 1)
get_user_authid(id, szUserAuthID, charsmax(szUserAuthID))
// Format the query and launch a thread worker to wait for its execution
new szQuery[128], szID[1]
szID[0] = id
formatex(szQuery, charsmax(szQuery), "SELECT * FROM `%s` WHERE `username` = '%s' AND `useraddress` = '%s' AND `usersteam` = '%s';", TABLE, g_szUserName[id], szUserIP, szUserAuthID)
SQL_ThreadQuery(g_iSQLTuple, "OnSelectExecuted", szQuery, szID, 1)
}
public OnSelectExecuted(iFailState, Handle:iQuery, szError[], iErrorCode, szData[1])
{
if (iFailState != TQUERY_SUCCESS)
{
log_amx("[%s] Failed to select", PLUGIN)
log_amx("[%s] %s", PLUGIN, szError)
return
}
// Check if anything is selected
if (SQL_NumResults(iQuery) > 0)
{
return
}
new id = szData[0]
log_amx("[%s] Saving user %s", PLUGIN, g_szUserName[id])
server_print("[%s] Saving user %s", PLUGIN, g_szUserName[id])
// Get addtional user information to track them by
new szUserIP[33], szUserAuthID[33]
get_user_ip(id, szUserIP, charsmax(szUserIP), 1)
get_user_authid(id, szUserAuthID, charsmax(szUserAuthID))
// Format the query and launch a thread worker to wait for its execution
new szQuery[128]
formatex(szQuery, charsmax(szQuery), "INSERT INTO `%s` (`username`, `useraddress`, `usersteam`) VALUES ('%s', '%s', '%s');", TABLE, g_szUserName[id], szUserIP, szUserAuthID)
SQL_ThreadQuery(g_iSQLTuple, "QueryEmptyHandle", szQuery)
}
public QueryEmptyHandle(iFailState, Handle:iQuery, szError[])
{
if (iFailState != TQUERY_SUCCESS)
{
log_amx(szError)
}
}