· 7 years ago · Jan 25, 2019, 09:42 PM
1public void MySql_Connect()
2{
3 db = SQL_Connect("hsfadverts",true, db_error, sizeof(db_error));
4 if(db == null)
5 {
6 SQL_GetError(db, db_error, sizeof(db_error));
7 SetFailState("\n\n\n[Call of Duty] Cannot connect to the DB: %s\n\n\n", db_error);
8 }
9 CREATE TABLE IF NOT EXISTS callofduty (id INT(32) NOT NULL DEFAULT NULL AUTO_INCREMENT, steamid VARCHAR(128) NOT NULL, info_sniper VARCHAR(64) NOT NULL DEFAULT '0;0;0;0;0;0;0', info_rusher VARCHAR(64) NOT NULL DEFAULT '0;0;0;0;0;0;0',
10 info_sharpshooter VARCHAR(64) NOT NULL DEFAULT '0;0;0;0;0;0;0', info_protector VARCHAR(64) NOT NULL DEFAULT '0;0;0;0;0;0;0', info_makarov VARCHAR(64) NOT NULL DEFAULT '0;0;0;0;0;0;0', info_firesupport VARCHAR(64) NOT NULL DEFAULT '0;0;0;0;0;0;0',
11 info_demolitions VARCHAR(64) NOT NULL DEFAULT '0;0;0;0;0;0;0', info_cptsoap VARCHAR(64) NOT NULL DEFAULT '0;0;0;0;0;0;0', info_ghost VARCHAR(64) NOT NULL DEFAULT '0;0;0;0;0;0;0', info_sapper VARCHAR(64) NOT NULL DEFAULT '0;0;0;0;0;0;0',
12 info_commando VARCHAR(64) NOT NULL DEFAULT '0;0;0;0;0;0;0', info_rambo VARCHAR(64) NOT NULL DEFAULT '0;0;0;0;0;0;0', info_cptprice VARCHAR(64) NOT NULL DEFAULT '0;0;0;0;0;0;0', info_engineer VARCHAR(64) NOT NULL DEFAULT '0;0;0;0;0;0;0', PRIMARY KEY(id))
13
14 SQL_Query(db, "SET CHARACTER SET utf8");
15 PrintToServer("[Call of Duty] Connected to MySQL successfuly!");
16}
17public void MySql_LoadClient(int client)
18{
19 char steamid[32];
20 char e_steamid[32];
21 GetClientAuthId(client, AuthId_Engine, steamid, sizeof(steamid));
22 ExplodeSteamId(steamid,e_steamid,sizeof(e_steamid));
23 Format (db_query, sizeof(db_query), "SELECT * FROM callofduty WHERE steamid='%s'", e_steamid);
24 SQL_TQuery(db, MySql_OnLoadPlayer, db_query, client);
25}
26public void MySql_OnLoadPlayer(Handle owner, Handle query, const char[] error, any client)
27{
28 if(query == INVALID_HANDLE)
29 {
30 LogError("[Call of Duty] MySql-Query failed! Error: %s\n\n\n", error);
31 }
32 else
33 {
34 b_ClientVerified[client] = false;
35 char steamid[32];
36 char e_steamid[32];
37 GetClientAuthId(client, AuthId_Engine, steamid, sizeof(steamid));
38 ExplodeSteamId(steamid,e_steamid,sizeof(e_steamid));
39 if(!SQL_FetchRow(query))
40 {
41 Handle datapack = CreateDataPack();
42 WritePackCell(datapack, client);
43 WritePackString(datapack, e_steamid);
44 Format(db_query, sizeof(db_query), "INSERT INTO callofduty (steamid) VALUES ('%s')",e_steamid);
45 SQL_TQuery(db, MySql_OnInsertPlayerToDB, db_query, datapack);
46 }
47 else
48 {
49 Format (db_query, sizeof(db_query), "SELECT * FROM callofduty WHERE steamid='%s'", e_steamid);
50 SQL_TQuery(db, MySql_OnLoadPlayerPost, db_query, client);
51 }
52 }
53 CloseHandle(query);
54}
55public void MySql_OnInsertPlayerToDB(Handle owner, Handle query, const char[] error, any datapack)
56{
57 if(query == INVALID_HANDLE)
58 {
59 LogError("[FurienGO] MySql-Query failed! Error: %s\n\n\n", error);
60 }
61 else
62 {
63 char e_steamid[32];
64 ResetPack(datapack);
65 int client = ReadPackCell(datapack);
66 ReadPackString(datapack, e_steamid, sizeof(e_steamid));
67 Format (db_query, sizeof(db_query), "SELECT * FROM callofduty WHERE steamid='%s'", e_steamid);
68 SQL_TQuery(db, MySql_OnLoadPlayerPost, db_query, client);
69 }
70 CloseHandle(query);
71}
72public void MySql_OnLoadPlayerPost(Handle owner, Handle query, const char[] error, any client)
73{
74 if(query == INVALID_HANDLE)
75 {
76 LogError("[[Call of Duty] MySql-Query failed! Error: %s\n\n\n", error);
77 }
78 else
79 {
80 if(SQL_FetchRow(query))
81 {
82 char sClientData[32];
83 char sClientDataExploded[7][32];
84 for(int i = 2; i < 16; i++)
85 {
86 SQL_FetchString(query, i, sClientData, sizeof(sClientData))
87 ExplodeString(sClientData, ";", sClientDataExploded, sizeof(sClientDataExploded), sizeof(sClientDataExploded[]));
88 i_gClientClassLvl[client][view_as<ClassType>(i-1)] = StringToInt(sClientDataExploded[0]);
89 i_gClientClassExp[client][view_as<ClassType>(i-1)] = StringToInt(sClientDataExploded[1]);
90 for(int x; x < view_as<int>(Attri_Count); x++)
91 {
92 i_gClientClassAttributes[client][view_as<ClassType>(i-1)][view_as<ClassAttributes>(x)] = StringToInt(sClientDataExploded[x+2]);
93 }
94 i_gClientClassAttributesPoints[client][view_as<ClassType>(i-1)] = StringToInt(sClientDataExploded[6]);
95 }
96 b_ClientVerified[client] = true;
97 }
98 }
99 CloseHandle(query);
100}
101stock void MySql_SaveClient(int client)
102{
103 if(b_ClientVerified[client] == true)
104 {
105 char steamid[32];
106 char e_steamid[32];
107
108 char sClientData[15][64]
109 GetClientAuthId(client, AuthId_Engine, steamid, sizeof(steamid));
110 ExplodeSteamId(steamid,e_steamid,sizeof(e_steamid));
111 for(int i = 1 ; i < view_as<int>(Class_Count); i++)
112 {
113 Format(sClientData[i], sizeof(sClientData), "%i;%i;%i;%i;%i;%i;%i",
114 i_gClientClassLvl[client][view_as<ClassType>(i)],
115 i_gClientClassExp[client][view_as<ClassType>(i)],
116 i_gClientClassAttributes[client][view_as<ClassType>(i)][view_as<ClassAttributes>(0)],
117 i_gClientClassAttributes[client][view_as<ClassType>(i)][view_as<ClassAttributes>(1)],
118 i_gClientClassAttributes[client][view_as<ClassType>(i)][view_as<ClassAttributes>(2)],
119 i_gClientClassAttributes[client][view_as<ClassType>(i)][view_as<ClassAttributes>(3)],
120 i_gClientClassAttributesPoints[client][view_as<ClassType>(i)]);
121 }
122 Format(db_query, sizeof(db_query), "UPDATE callofduty SET info_sniper='%s', info_rusher='%s', info_sharpshooter='%s', info_protector='%s', info_makarov='%s', info_firesupport='%s', info_demolitions='%s', info_cptsoap='%s', info_ghost='%s', info_sapper='%s', info_commando='%s', info_rambo='%s', info_cptprice='%s', info_engineer='%s' WHERE steamid='%s'", sClientData[1], sClientData[2], sClientData[3], sClientData[4], sClientData[5], sClientData[6], sClientData[7], sClientData[8], sClientData[9], sClientData[10], sClientData[11], sClientData[12], sClientData[13], sClientData[14], e_steamid);
123 if(db != null)
124 {
125 SQL_TQuery(db, MySql_OnSaveClient, db_query, client);
126 }
127 }
128}
129public void MySql_OnSaveClient(Handle owner, Handle query, const char[] error, any money)
130{
131 if(query == INVALID_HANDLE)
132 {
133 LogError("[FurienGO] MySql-Query failed! Error: %s\n\n\n", error);
134 }
135 CloseHandle(query);
136}