forked from ben-watch/feckinmad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFM_MESSAGE_PLAYERSTATS.sma
91 lines (73 loc) · 2.04 KB
/
FM_MESSAGE_PLAYERSTATS.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
#include "feckinmad/fm_global"
#include "feckinmad/fm_sql_tquery"
#define SECONDS_IN_DAY 86400
#define RECORDS_BEGAN 2008
new const g_sStatsQuery[] = "SELECT COUNT(player_id) FROM players WHERE player_lastconnect > UNIX_TIMESTAMP() - %d;"
new const g_sAllStatsQuery[] = "SELECT COUNT(player_id) FROM players"
new g_iCurrentMessage
enum
{
QUERY_DAY = 0,
QUERY_MONTH,
QUERY_YEAR,
QUERY_ALLTIME,
QUERY_COUNT
}
new g_iQueryLen[QUERY_COUNT] =
{
SECONDS_IN_DAY,
SECONDS_IN_DAY * 30,
SECONDS_IN_DAY * 365,
0
}
new g_sStatsText[QUERY_COUNT][] =
{
"24 hours",
"month",
"year",
"2008"
}
new g_iQueryStats[QUERY_COUNT]
new g_iQueryIdent[QUERY_COUNT]
public plugin_init()
{
fm_RegisterPlugin()
new g_sQuery[256]
for (new i = 0; i < QUERY_COUNT - 1; i++)
{
formatex(g_sQuery, charsmax(g_sQuery), g_sStatsQuery, g_iQueryLen[i])
g_iQueryIdent[i] = fm_SQLAddThreadedQuery(g_sQuery, "Handle_PlayerStatsQuery", QUERY_DISPOSABLE, PRIORITY_LOW)
}
formatex(g_sQuery, charsmax(g_sQuery), g_sAllStatsQuery)
g_iQueryIdent[QUERY_ALLTIME] = fm_SQLAddThreadedQuery(g_sQuery, "Handle_PlayerStatsQuery", QUERY_DISPOSABLE, PRIORITY_LOW)
}
public Handle_PlayerStatsQuery(iFailState, Handle:hQuery, sError[], iError, Data[], iDataLen, Float:fQueueTime, iQueryIdent)
{
fm_DebugPrintLevel(1, "Handle_Handle_PlayerStatsQuery: %f", fQueueTime)
if(fm_SQLCheckThreadedError(iFailState, hQuery, sError, iError))
{
return PLUGIN_HANDLED
}
for (new i = 0; i < QUERY_COUNT ; i++)
{
if (g_iQueryIdent[i] == iQueryIdent)
{
g_iQueryStats[i] = SQL_ReadResult(hQuery, 0)
break
}
}
return PLUGIN_HANDLED
}
public fm_ScreenMessage(sBuffer[], iSize)
{
if (g_iCurrentMessage >= QUERY_COUNT)
{
g_iCurrentMessage = 0
}
if (!g_iQueryStats[g_iCurrentMessage])
{
formatex(sBuffer, iSize, "All your player stats belong to us")
}
formatex(sBuffer, iSize, "%d unique players have connected to the server %s %s", g_iQueryStats[g_iCurrentMessage], g_iCurrentMessage != QUERY_ALLTIME ? "in the last" : "since", g_sStatsText[g_iCurrentMessage])
g_iCurrentMessage++
}