-
Notifications
You must be signed in to change notification settings - Fork 1
/
FM_IP_LOG.sma
105 lines (83 loc) · 3.37 KB
/
FM_IP_LOG.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
#include "feckinmad/fm_global"
#include "feckinmad/fm_sql_player"
#include "feckinmad/fm_sql_tquery"
#include <fakemeta>
#define MAX_ADDRESS_LEN 16
enum eAddressData_t
{
m_sPlayerAddress[MAX_ADDRESS_LEN],
m_iPlayerAddressIdent,
m_iPlayerAddressTimeStamp
}
new g_sQuery[MAX_QUERY_LEN]
public plugin_init()
{
fm_RegisterPlugin()
}
public fm_SQLPlayerIdent(id, iPlayerIdent)
{
if (!is_dedicated_server()) // loopback
{
return PLUGIN_CONTINUE
}
new Data[eAddressData_t]
get_user_ip(id, Data[m_sPlayerAddress], MAX_ADDRESS_LEN - 1, 1)
Data[m_iPlayerAddressIdent] = iPlayerIdent
Data[m_iPlayerAddressTimeStamp] = get_systime()
formatex(g_sQuery, charsmax(g_sQuery), "SELECT address_id FROM player_address WHERE player_address = INET_ATON('%s')", Data[m_sPlayerAddress])
fm_SQLAddThreadedQuery(g_sQuery, "Handle_SelectAddress", QUERY_DISPOSABLE, PRIORITY_LOWEST, Data, _:eAddressData_t)
return PLUGIN_CONTINUE
}
public Handle_SelectAddress(iFailState, Handle:hQuery, sError[], iError, Data[], iDataLen, Float:fQueueTime, iQueryIdent)
{
fm_DebugPrintLevel(1, "Handle_SelectAddress: %f", fQueueTime)
if(fm_SQLCheckThreadedError(iFailState, hQuery, sError, iError))
{
return PLUGIN_HANDLED
}
if (!SQL_NumResults(hQuery))
{
formatex(g_sQuery, charsmax(g_sQuery), "INSERT INTO player_address (player_address) VALUES (INET_ATON('%s'));", Data[m_sPlayerAddress])
fm_SQLAddThreadedQuery(g_sQuery, "Handle_InsertAddress", QUERY_DISPOSABLE, PRIORITY_LOWEST, Data, _:eAddressData_t)
return PLUGIN_HANDLED
}
else
{
new iAddressIndex = SQL_ReadResult(hQuery, 0)
formatex(g_sQuery, charsmax(g_sQuery), "INSERT INTO player_address_link (player_id, address_id, last_used, times_used) VALUES ('%d', '%d', '%d', '1') ON DUPLICATE KEY UPDATE times_used = times_used + 1, last_used = %d;", Data[m_iPlayerAddressIdent], iAddressIndex, Data[m_iPlayerAddressTimeStamp], Data[m_iPlayerAddressTimeStamp])
fm_SQLAddThreadedQuery(g_sQuery, "Handle_InsertPlayerAddress", QUERY_DISPOSABLE, PRIORITY_LOWEST, Data, _:eAddressData_t)
}
return PLUGIN_HANDLED
}
public Handle_InsertAddress(iFailState, Handle:hQuery, sError[], iError, Data[], iDataLen, Float:fQueueTime, iQueryIdent)
{
fm_DebugPrintLevel(1, "Handle_InsertAddress: %f", fQueueTime)
if(fm_SQLCheckThreadedError(iFailState, hQuery, sError, iError))
{
return PLUGIN_HANDLED
}
new iAddressIndex = SQL_GetInsertId(hQuery)
if (!iAddressIndex)
{
fm_WarningLog("iAddressIndex == 0")
return PLUGIN_HANDLED
}
formatex(g_sQuery, charsmax(g_sQuery), "INSERT INTO player_address_link (player_id, address_id, last_used, times_used) VALUES ('%d', '%d', '%d', '1') ON DUPLICATE KEY UPDATE times_used = times_used + 1, last_used = %d;", Data[m_iPlayerAddressIdent], iAddressIndex, Data[m_iPlayerAddressTimeStamp], Data[m_iPlayerAddressTimeStamp])
fm_SQLAddThreadedQuery(g_sQuery, "Handle_InsertPlayerAddress", QUERY_DISPOSABLE, PRIORITY_LOWEST, Data, eAddressData_t)
return PLUGIN_HANDLED
}
public Handle_InsertPlayerAddress(iFailState, Handle:hQuery, sError[], iError, Data[], iDataLen, Float:fQueueTime, iQueryIdent)
{
fm_DebugPrintLevel(1, "Handle_InsertPlayerAddress: %f", fQueueTime)
if(fm_SQLCheckThreadedError(iFailState, hQuery, sError, iError))
{
return PLUGIN_HANDLED
}
new iPlayerAddressIndex = SQL_GetInsertId(hQuery)
if (!iPlayerAddressIndex)
{
fm_WarningLog("iPlayerAddressIndex == 0")
return PLUGIN_HANDLED
}
return PLUGIN_HANDLED
}