· 7 years ago · Feb 21, 2019, 06:08 PM
1public OnPluginStart()
2{
3 // Cmds
4 RegConsoleCmd("sm_ranga", CMD_Grade, "Wyświetla główne menu rang.");
5
6 // Hooks
7 HookEvent( "round_end", Event_RoundEnd);
8
9 // MySql shit
10 DB_Connect();
11}
12
13public Action __________________________________________________________(){}
14public OnClientAuthorized(client, const String:auth[])
15{
16 CheckRank(client, false);
17}
18
19public void OnClientDisconnect(int client)
20{
21 CheckRank(client, true);
22 DB_SaveInfo(client);
23}
24
25public Action ________________________________________________________(){}
26public Action DB_Connect()
27{
28 if(SQL_CheckConfig("rankme"))
29 {
30 char DBBuffer[512];
31 g_hSql = SQL_Connect("rankme", true, DBBuffer, sizeof(DBBuffer));
32 if (g_hSql == INVALID_HANDLE)
33 LogError("[kento_rangi] Could not connect: %s", DBBuffer);
34 else
35 {
36 SQL_LockDatabase(g_hSql);
37 SQL_FastQuery(g_hSql, "CREATE TABLE IF NOT EXISTS 5vs5_mirage (auth_data VARCHAR(48) NOT NULL PRIMARY KEY default '',\
38 name VARCHAR(64) NOT NULL default '',\
39 points INT NOT NULL default 0,\
40 rank INT NOT NULL default 0)\
41 ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;");
42 SQL_UnlockDatabase(g_hSql);
43 }
44 }
45 else
46 SetFailState("Nie mozna odnalezc konfiguracji 'rankme' w databases.cfg.");
47}
48
49public DB_SaveInfo(int client)
50{
51 if(!IsValidClient(client) || IsFakeClient(client))
52 return;
53
54 char authid[64];
55 if(!GetClientAuthId(client, AuthId_Steam2, authid, sizeof(authid)))
56 return;
57
58 char nick[64];
59 char EscapedName[64];
60
61 GetClientName(client, nick, sizeof(nick));
62 SQL_EscapeString(g_hSql, nick, EscapedName, sizeof(nick));
63
64 char query[2048];
65 Format(query, sizeof(query), "INSERT INTO `5vs5_mirage` (auth_data, name, points, rank) VALUES ('%s', '%s', %d, %d) ON DUPLICATE KEY UPDATE name=VALUES(name), points=VALUES(points), rank=VALUES(rank)", authid, EscapedName, g_iPoints[client], g_iRank[client]);
66 SQL_TQuery(g_hSql, DB_SaveInfoCallback, query);
67}
68
69public void DB_TopCallback(Handle owner, Handle hndl, const char[] error, DataPack info_pack)
70{
71 if(hndl == INVALID_HANDLE)
72 {
73 LogError("[TOP] Query failed! %s", error);
74 return;
75 }
76
77 info_pack.Reset(); // Get some info !
78 int client = info_pack.ReadCell();
79
80 if(client == 0 || !IsClientInGame(client))
81 return;
82
83 delete info_pack;
84
85 int i;
86
87 Menu menu = new Menu(TOP_Handler, MENU_ACTIONS_ALL);
88 menu.SetTitle("[#TOP] Nick - Ranga - Punkty");
89
90 char menu_item[256];
91 char sAuth[64];
92
93 while(SQL_FetchRow(hndl))
94 {
95 i++;
96 SQL_FetchString(hndl, 0, menu_item, sizeof(menu_item)); // name
97
98 Format(menu_item, sizeof(menu_item), "#%d - %s - %s - [%d]", i, menu_item, g_sRanksNames[SQL_FetchInt(hndl, 2)], SQL_FetchInt(hndl, 1));
99 menu.AddItem(sAuth, menu_item);
100 }
101
102 if(i == 0)
103 menu.AddItem("no_records", "Wygląda na to, że ranking jest czysty.");
104
105 menu.ExitButton = true;
106 menu.Display(client, 0);
107}
108
109public DB_SaveInfoCallback(Handle owner, Handle query, const char[] error, any data)
110{
111 if(query == INVALID_HANDLE)
112 {
113 LogError("[kento_rangi] Failed to save client info (error: %s)", error);
114 return;
115 }
116}