· 5 years ago · Aug 21, 2020, 07:42 PM
1//#pragma semicolon 1
2
3//new Handle:DB;
4//float G_ELO[MAXPLAYERS+1];
5/*
6public OnPluginStart()
7{
8 InitDB(DB); // DB활성화띠
9
10 RegConsoleCmd("sm_test", Command_Test);
11 RegConsoleCmd("say", SayHook);
12 RegConsoleCmd("say_team", SayHook);
13}
14public OnMapStart()
15{
16 InitDB(DB); // DB활성화띠
17}
18public OnMapEnd()
19{
20 if(DB != INVALID_HANDLE) CloseHandle(DB);
21 DB = INVALID_HANDLE;
22}
23*/
24/*
25public ConnectReset(Client)
26{
27 if(LoginCheck[Client] == 0) //비로그인시
28 {
29 SkinName[Client] = DEFAULT_NAME;
30 SkinCode[Client] = CODE_NONE;
31 SkinArms[Client] = CODE_NONE;
32 SkinEnable[Client] = 0;
33 LightEnt[Client] = INVALID_ENT_REFERENCE;
34
35 ShoesName[Client] = DEFAULT_NAME;
36 ShoesCode[Client] = 0;
37 ShoesColors[Client] = COLORS_NONE;
38 Vibration01[Client] = 0;
39 ShoesEnable[Client] = 0;
40
41 LaserName[Client] = DEFAULT_NAME;
42 LaserCode[Client] = 0;
43 LaserColors[Client] = COLORS_NONE;
44 Vibration02[Client] = 0;
45 LaserEnable[Client] = 0;
46
47 KnifeName[Client] = DEFAULT_NAME;
48 KnifeCode01[Client] = 0;
49 KnifeCode02[Client] = 0;
50 KnifeEnable[Client] = 0;
51
52 PetName[Client] = DEFAULT_NAME;
53 PetCode[Client] = CODE_NONE;
54 PetAni[Client] = CODE_NONE;
55 PetEnt[Client] = INVALID_ENT_REFERENCE;
56 PetEnable[Client] = 0;
57
58 TrailName[Client] = DEFAULT_NAME;
59 TrailCode[Client] = CODE_NONE;
60 TrailEnable[Client] = 0;
61
62 TagName[Client] = DEFAULT_NAME;
63 TagEnable[Client] = 0;
64 TeamChat[Client] = false;
65
66 Point[Client] = 0;
67 Cash[Client] = 0;
68 Point_Rank[Client] = 0;
69 Class[Client] = 0;
70
71 //장비장착변수
72 Weapon1[Client] = 0; //무기
73 Wskin[Client] = 0; //무기스킨
74 Body[Client] = 0; //스킨(아바타)
75 Caps[Client] = 0; //투구
76 Shoulder[Client] = 0; //숄더
77 Bealt[Client] = 0; //벨트
78 Shirts[Client] = 0; //상의
79 Pants[Client] = 0; //하의
80 Ring[Client] = 0; //반지
81 Necklace[Client] = 0; //목걸이
82 Armlet[Client] = 0; //팔찌
83 Title1[Client] = 0; //칭호
84 Tag1[Client] = 0; //태그
85
86 Gak[Client] = 0; //전직정보
87 Job[Client] = 1; //직업:1=모험가
88 Level[Client] = DefaultLv;
89 EXP[Client] = 0;
90 SP[Client] = DefaultLv*LvSP;
91 STP[Client] = DefaultLv*LvSTP;
92 KillPoint[Client] = 0; //킬포인트
93 RestPoint[Client] = 0; //휴식포인트
94
95 Striking[Client] = 0; //표시 공격력
96 Vitality[Client] = 0; //표시 종합 체력
97 Evasion[Client] = 0; //회피율
98
99 //언젠가 생길변수(스텟)
100 STR[Client] = 0;
101 DEX[Client] = 0;
102 INT[Client] = 0; //INT는 SQL 문법 오류날까봐 실제변수랑 다르게 저장, Intelligence
103 LUK[Client] = 0;
104 HP[Client] = 0;
105 Mp[Client] = 0;
106
107 BGM_On[Client] = false; //브금 끄기로 설정
108
109 for(new i = 1; i < MAX_ITEMS; i++) Item[Client][i] = 0;
110 for(new i = 1; i < MAX_SKILLS; i++) Skill[Client][i] = 0;
111 }
112}
113InitDB(&Handle:DbHNDL) //DB활성화
114{
115 // Errormessage Buffer
116 new String:Error[255];
117 // COnnect to the DB
118 DbHNDL = SQL_Connect("FadeRPG", true, Error, sizeof(Error));
119 // If something fails we quit
120 if(DbHNDL == INVALID_HANDLE)
121 {
122 SetFailState(Error);
123 }
124 new String:charquery[64];
125 Format(charquery, sizeof(charquery), "SET NAMES \"UTF8\"");
126 SQL_FastQuery(DbHNDL, charquery);
127 //유저
128 SQL_TQuery(DbHNDL, SQL_ErrorCheckCallBack, "create table if not exists User(id bigint primary key not null AUTO_INCREMENT, steamauthid varchar(256) CHARACTER SET utf8, Name varchar(256) CHARACTER SET utf8, Level bigint DEFAULT 0, SP bigint DEFAULT 0, EXP bigint DEFAULT 0, Job bigint DEFAULT 0, Cash bigint DEFAULT 0, Point bigint DEFAULT 0, RestPoint bigint DEFAULT 0, KillPoint bigint DEFAULT 0, STP bigint DEFAULT 0, Gak bigint DEFAULT 0, Point_Rank bigint DEFAULT 0, Class bigint DEFAULT 0);", 0);
129 //장비장착데이터
130 //SQL_TQuery(DbHNDL, Loading4, "create table if not exists EquipData(id bigint primary key not null AUTO_INCREMENT, steamauthid varchar(256) CHARACTER SET utf8, Name varchar(256) CHARACTER SET utf8, Weapon bigint DEFAULT 0,Wskin bigint DEFAULT 0, Body bigint DEFAULT 0, Caps bigint DEFAULT 0, Shoulder bigint DEFAULT 0, Bealt bigint DEFAULT 0, Shirts bigint DEFAULT 0, Pants bigint DEFAULT 0, Ring bigint DEFAULT 0, Necklace bigint DEFAULT 0, Armlet bigint DEFAULT 0, Title bigint DEFAULT 0, Tag bigint DEFAULT 0, SkinEnable bigint DEFAULT 0, ShoesEnable bigint DEFAULT 0, LaserEnable bigint DEFAULT 0, KnifeEnable bigint DEFAULT 0, PetEnable bigint DEFAULT 0, TrailEnable bigint DEFAULT 0, TagEnable bigint DEFAULT 0, Vibration01 bigint DEFAULT 0, Vibration02 bigint DEFAULT 0, SkinName VARCHAR(128) NOT NULL, ShoesName VARCHAR(128) NOT NULL, LaserName VARCHAR(128) NOT NULL, KnifeName VARCHAR(128) NOT NULL, PetName VARCHAR(128) NOT NULL, TrailName VARCHAR(128) NOT NULL, TagName VARCHAR(128) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=UTF8;", 0);
131 SQL_TQuery(DbHNDL, SQL_ErrorCheckCallBack, "create table if not exists EquipData(id bigint primary key not null AUTO_INCREMENT, steamauthid varchar(256) CHARACTER SET utf8, Name varchar(256) CHARACTER SET utf8, Weapon bigint DEFAULT 0,Wskin bigint DEFAULT 0, Body bigint DEFAULT 0, Caps bigint DEFAULT 0, Shoulder bigint DEFAULT 0, Bealt bigint DEFAULT 0, Shirts bigint DEFAULT 0, Pants bigint DEFAULT 0, Ring bigint DEFAULT 0, Necklace bigint DEFAULT 0, Armlet bigint DEFAULT 0, Title bigint DEFAULT 0, Tag bigint DEFAULT 0, SkinEnable bigint DEFAULT 0, ShoesEnable bigint DEFAULT 0, LaserEnable bigint DEFAULT 0, KnifeEnable bigint DEFAULT 0, PetEnable bigint DEFAULT 0, TrailEnable bigint DEFAULT 0, TagEnable bigint DEFAULT 0, Vibration01 bigint DEFAULT 0, Vibration02 bigint DEFAULT 0, SkinName VARCHAR(128) CHARACTER SET utf8, ShoesName VARCHAR(128) CHARACTER SET utf8, LaserName VARCHAR(128) CHARACTER SET utf8, KnifeName VARCHAR(128) CHARACTER SET utf8, PetName VARCHAR(128) CHARACTER SET utf8, TrailName VARCHAR(128) CHARACTER SET utf8, TagName VARCHAR(128) CHARACTER SET utf8) ENGINE=MyISAM DEFAULT CHARSET=UTF8;", 0);
132 //스텟데이터
133 SQL_TQuery(DbHNDL, SQL_ErrorCheckCallBack, "create table if not exists RPGData(id bigint primary key not null AUTO_INCREMENT, steamauthid varchar(256) CHARACTER SET utf8, Name varchar(256) CHARACTER SET utf8, STR bigint DEFAULT 0, DEX bigint DEFAULT 0, Intelligence bigint DEFAULT 0, LUK bigint DEFAULT 0, HP bigint DEFAULT 0, Mp bigint DEFAULT 0, Striking bigint DEFAULT 0, Vitality bigint DEFAULT 0, Evasion bigint DEFAULT 0);", 0);
134 //포문돌리는데이터:아이템큐브,스킬큐브
135 SQL_TQuery(DbHNDL, SQL_ErrorCheckCallBack, "create table if not exists SkillCube(id bigint primary key not null AUTO_INCREMENT, steamauthid varchar(256) CHARACTER SET utf8, Name varchar(256) CHARACTER SET utf8);", 0);
136 SQL_TQuery(DbHNDL, SQL_ErrorCheckCallBack, "create table if not exists ItemCube(id bigint primary key not null AUTO_INCREMENT, steamauthid varchar(256) CHARACTER SET utf8, Name varchar(256) CHARACTER SET utf8);", 0);
137}
138*/
139//========================================================
140// 1. 로드부분
141//========================================================
142/*
143//클라이언트 스팀ID값을 받았을때(서버입장시)
144public OnClientAuthorized(Client, const String:auth[])
145{
146 if(!IsFakeClient(Client))
147 {
148 SQL_CheckClientData(DB, Client, auth); //입장시 데이터 로드
149 }
150}
151*/
152SQL_CheckClientData(Handle:iDataBase, Client, const String:Steamid[])
153{
154 if(iDataBase != INVALID_HANDLE)
155 {
156 decl String:Query[128];
157 Format(Query, sizeof(Query), "SELECT * FROM playerinfo WHERE steamauthid = '%s';", Steamid);
158 SQL_TQuery(iDataBase, SQL_CheckClient, Query, Client);
159 //여기서부터 백고미
160 //타입:1
161 Format(Query, sizeof(Query), "SELECT * FROM User WHERE steamauthid = '%s';", Steamid);
162 SQL_TQuery(iDataBase, DataLoad1, Query, Client);
163 //타입:2
164 Format(Query, sizeof(Query), "SELECT * FROM EquipData WHERE steamauthid = '%s';", Steamid);
165 SQL_TQuery(iDataBase, DataLoad2, Query, Client);
166 //타입:3
167 Format(Query, sizeof(Query), "SELECT * FROM RPGData WHERE steamauthid = '%s';", Steamid);
168 SQL_TQuery(iDataBase, DataLoad3, Query, Client);
169 //타입:4
170 Format(Query, sizeof(Query), "SELECT * FROM SkillCube WHERE steamauthid = '%s';", Steamid);
171 SQL_TQuery(iDataBase, DataLoad4, Query, Client);
172 //타입:5
173 Format(Query, sizeof(Query), "SELECT * FROM ItemCube WHERE steamauthid = '%s';", Steamid);
174 SQL_TQuery(iDataBase, DataLoad5, Query, Client);
175 }
176}
177public SQL_CheckClient(Handle:owner, Handle:handle, const String:error[], any:Client)
178{
179 char steamID[32];
180 new String:user_name[64];
181 GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID));
182 GetClientName(Client, user_name, sizeof(user_name));
183
184 if(handle == INVALID_HANDLE)
185 {
186 PrintToServer("[RANK] Error : %s", error);
187 }
188 // 데이터 발견
189 else if(SQL_GetRowCount(handle))
190 {
191 if(SQL_HasResultSet(handle))
192 {
193 while(SQL_FetchRow(handle))
194 {
195 G_ELO[Client] = SQL_FetchFloat(handle, 2);
196 }
197
198 InGameUpdatePlayer(steamID,user_name);
199
200 PrintToChatAll("%s(%i) joined the server.", user_name, G_ELO[Client]);
201 PrintToServer("%s(%i) joined the server.", user_name, G_ELO[Client]);
202 }
203 }
204 // 데이터가 없을 경우
205 else if(SQL_GetRowCount(handle) == 0)
206 {
207 if(GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID)))
208 {
209 AddPlayer(steamID,user_name);
210 }
211 PrintToServer("아몰랑2");
212 }
213}
214InGameUpdatePlayer(const String:steamauthid[], const String:Name[64]) //인게임플레이어 체크할려고 만듬(내가쓰던거엔 안써도됨)
215{
216 new String:Query[255], String:curdate[32];
217 FormatTime(curdate, sizeof(curdate), "%Y/%m/%d %X", GetTime());
218 Format(Query, sizeof(Query), "UPDATE playerinfo SET nickname = '%s', isplayeringame = '1', lastplaydate = '%s' WHERE steamauthid = '%s'", Name, curdate, steamauthid);
219 SQL_TQuery(DB, SQL_ErrorCheckCallBack, Query);
220}
221AddPlayer(const String:steamauthid[], const String:user_name[64])
222{
223 new String:Query[255], String:curdate[32];
224 FormatTime(curdate, sizeof(curdate), "%Y/%m/%d %X", GetTime()); // 참고 주소 - http://cplusplus.com/reference/clibrary/ctime/strftime/
225
226 Format(Query, sizeof(Query), "INSERT IGNORE INTO playerinfo VALUES ('%s', '%s', '1200.0', '1', '%s', '%s')", steamauthid, user_name,curdate,curdate);
227
228 SQL_TQuery(DB, SQL_ErrorCheckCallBack, Query);
229}
230//유저데이터 로드
231public DataLoad1(Handle:owner, Handle:handle, const String:error[], any:Client)
232{
233 char steamID[32];
234 new String:user_name[64];
235 GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID));
236 GetClientName(Client, user_name, sizeof(user_name));
237
238 if(handle == INVALID_HANDLE)
239 {
240 PrintToServer("[RANK] Error : %s", error);
241 }
242 // 데이터 발견
243 else if(SQL_GetRowCount(handle))
244 {
245 if(SQL_HasResultSet(handle))
246 {
247 while(SQL_FetchRow(handle))
248 {
249 Level[Client] = SQL_FetchInt(handle, 3);
250 SP[Client] = SQL_FetchInt(handle, 4);
251 EXP[Client] = SQL_FetchInt(handle, 5);
252 Job[Client] = SQL_FetchInt(handle, 6);
253 Cash[Client] = SQL_FetchInt(handle, 7);
254 Point[Client] = SQL_FetchInt(handle, 8);
255 RestPoint[Client] = SQL_FetchInt(handle, 9);
256 KillPoint[Client] = SQL_FetchInt(handle, 10);
257 STP[Client] = SQL_FetchInt(handle, 11);
258 Gak[Client] = SQL_FetchInt(handle, 12);
259 Point_Rank[Client] = SQL_FetchInt(handle, 13);
260 Class[Client] = SQL_FetchInt(handle, 14);
261 }
262 //PrintToChatAll("%s(%i) joined the server.", user_name, G_ELO[Client]);
263 //PrintToServer("%s(%i) joined the server.", user_name, G_ELO[Client]);
264 }
265 }
266 // 데이터가 없을 경우
267 else if(SQL_GetRowCount(handle) == 0)
268 {
269 if(GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID)))
270 {
271 F_AddPlayer(steamID, user_name, 1);
272 }
273 //PrintToServer("아몰랑2");
274 }
275}
276//장비장착데이터
277public DataLoad2(Handle:owner, Handle:handle, const String:error[], any:Client)
278{
279 char steamID[32];
280 new String:user_name[64];
281 GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID));
282 GetClientName(Client, user_name, sizeof(user_name));
283
284 if(handle == INVALID_HANDLE)
285 {
286 PrintToServer("[RANK] Error : %s", error);
287 }
288 // 데이터 발견
289 else if(SQL_GetRowCount(handle))
290 {
291 if(SQL_HasResultSet(handle))
292 {
293 while(SQL_FetchRow(handle))
294 {
295 Weapon1[Client] = SQL_FetchInt(handle, 3);
296 Wskin[Client] = SQL_FetchInt(handle, 4);
297 Body[Client] = SQL_FetchInt(handle, 5);
298 Caps[Client] = SQL_FetchInt(handle, 6);
299 Shoulder[Client] = SQL_FetchInt(handle, 7);
300 Bealt[Client] = SQL_FetchInt(handle, 8);
301 Shirts[Client] = SQL_FetchInt(handle, 9);
302 Pants[Client] = SQL_FetchInt(handle, 10);
303 Ring[Client] = SQL_FetchInt(handle, 11);
304 Necklace[Client] = SQL_FetchInt(handle, 12);
305 Armlet[Client] = SQL_FetchInt(handle, 13);
306 Title1[Client] = SQL_FetchInt(handle, 14);
307 Tag1[Client] = SQL_FetchInt(handle, 15);
308
309 SkinEnable[Client] = SQL_FetchInt(handle, 16);
310 ShoesEnable[Client] = SQL_FetchInt(handle, 17);
311 LaserEnable[Client] = SQL_FetchInt(handle, 18);
312 KnifeEnable[Client] = SQL_FetchInt(handle, 19);
313 PetEnable[Client] = SQL_FetchInt(handle, 20);
314 TrailEnable[Client] = SQL_FetchInt(handle, 21);
315 TagEnable[Client] = SQL_FetchInt(handle, 22);
316 Vibration01[Client] = SQL_FetchInt(handle, 23);
317 Vibration02[Client] = SQL_FetchInt(handle, 24);
318
319 SQL_FetchString(handle, 25, SkinName[Client], sizeof(SkinName[]));
320 SQL_FetchString(handle, 26, ShoesName[Client], sizeof(ShoesName[]));
321 SQL_FetchString(handle, 27, LaserName[Client], sizeof(LaserName[]));
322 SQL_FetchString(handle, 28, KnifeName[Client], sizeof(KnifeName[]));
323 SQL_FetchString(handle, 29, PetName[Client], sizeof(PetName[]));
324 SQL_FetchString(handle, 30, TrailName[Client], sizeof(TrailName[]));
325 SQL_FetchString(handle, 31, TagName[Client], sizeof(TagName[]));
326 Code_Check(Client);
327 }
328 //PrintToChatAll("%s(%i) joined the server.", user_name, G_ELO[Client]);
329 //PrintToServer("%s(%i) joined the server.", user_name, G_ELO[Client]);
330 }
331 }
332 // 데이터가 없을 경우
333 else if(SQL_GetRowCount(handle) == 0)
334 {
335 if(GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID)))
336 {
337 F_AddPlayer(steamID, user_name, 2);
338 }
339 //PrintToServer("아몰랑2");
340 }
341}
342//스텟데이터
343public DataLoad3(Handle:owner, Handle:handle, const String:error[], any:Client)
344{
345 char steamID[32];
346 new String:user_name[64];
347 GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID));
348 GetClientName(Client, user_name, sizeof(user_name));
349
350 if(handle == INVALID_HANDLE)
351 {
352 PrintToServer("[RANK] Error : %s", error);
353 }
354 // 데이터 발견
355 else if(SQL_GetRowCount(handle))
356 {
357 if(SQL_HasResultSet(handle))
358 {
359 while(SQL_FetchRow(handle))
360 {
361 STR[Client] = SQL_FetchInt(handle, 3);
362 DEX[Client] = SQL_FetchInt(handle, 4);
363 INT[Client] = SQL_FetchInt(handle, 5);
364 LUK[Client] = SQL_FetchInt(handle, 6);
365 HP[Client] = SQL_FetchInt(handle, 7);
366 Mp[Client] = SQL_FetchInt(handle, 8);
367 Striking[Client] = SQL_FetchInt(handle, 9);
368 Vitality[Client] = SQL_FetchInt(handle, 10);
369 Evasion[Client] = SQL_FetchInt(handle, 11);
370 }
371 //PrintToChatAll("%s(%i) joined the server.", user_name, G_ELO[Client]);
372 //PrintToServer("%s(%i) joined the server.", user_name, G_ELO[Client]);
373 }
374 }
375 // 데이터가 없을 경우
376 else if(SQL_GetRowCount(handle) == 0)
377 {
378 if(GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID)))
379 {
380 F_AddPlayer(steamID, user_name, 3);
381 }
382 //PrintToServer("아몰랑2");
383 }
384}
385//스킬큐브
386public DataLoad4(Handle:owner, Handle:handle, const String:error[], any:Client)
387{
388 char steamID[32];
389 new String:user_name[64];
390 GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID));
391 GetClientName(Client, user_name, sizeof(user_name));
392
393 if(handle == INVALID_HANDLE)
394 {
395 PrintToServer("[RANK] Error : %s", error);
396 }
397 // 데이터 발견
398 else if(SQL_GetRowCount(handle))
399 {
400 if(SQL_HasResultSet(handle))
401 {
402 while(SQL_FetchRow(handle))
403 {
404 for(new x = 1; x < MAX_SKILLS; x++)
405 {
406 Skill[client][x] = SQL_FetchInt(handle, x+2); //원래값은 +2였는데 여기선모르겠음..테스트해봐야함
407 }
408 }
409 //PrintToChatAll("%s(%i) joined the server.", user_name, G_ELO[Client]);
410 //PrintToServer("%s(%i) joined the server.", user_name, G_ELO[Client]);
411 }
412 }
413 // 데이터가 없을 경우
414 else if(SQL_GetRowCount(handle) == 0)
415 {
416 if(GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID)))
417 {
418 F_AddPlayer(steamID, user_name, 4);
419 }
420 //PrintToServer("아몰랑2");
421 }
422}
423//아이템큐브
424public DataLoad5(Handle:owner, Handle:handle, const String:error[], any:Client)
425{
426 char steamID[32];
427 new String:user_name[64];
428 GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID));
429 GetClientName(Client, user_name, sizeof(user_name));
430
431 if(handle == INVALID_HANDLE)
432 {
433 PrintToServer("[RANK] Error : %s", error);
434 }
435 // 데이터 발견
436 else if(SQL_GetRowCount(handle))
437 {
438 if(SQL_HasResultSet(handle))
439 {
440 while(SQL_FetchRow(handle))
441 {
442 for(new x = 1; x < MAX_ITEMS; x++)
443 {
444 Item[client][x] = SQL_FetchInt(handle, x+2); //원래값+2였는데 테스트해봐야함
445 }
446 }
447 //PrintToChatAll("%s(%i) joined the server.", user_name, G_ELO[Client]);
448 //PrintToServer("%s(%i) joined the server.", user_name, G_ELO[Client]);
449 }
450 }
451 // 데이터가 없을 경우
452 else if(SQL_GetRowCount(handle) == 0)
453 {
454 if(GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID)))
455 {
456 F_AddPlayer(steamID, user_name, 5);
457 }
458 //PrintToServer("아몰랑2");
459 }
460}
461F_AddPlayer(const String:steamauthid[], const String:user_name[64], Type) //데이터없으면 값넣어줌
462{
463 new String:Query[255], String:curdate[32];
464 FormatTime(curdate, sizeof(curdate), "%Y/%m/%d %X", GetTime()); // 참고 주소 - http://cplusplus.com/reference/clibrary/ctime/strftime/
465 if(Type == 1) //유저
466 {
467 //INSERT IGNORE INTO:데이터가 있으면 값을 안넣음.(쿼리처리)
468 Format(Query, sizeof(Query), "INSERT IGNORE INTO User (steamauthid,Name) VALUES ('%s','%s');", steamauthid, user_name);
469 }
470 if(Type == 2) //장비장착데이터
471 {
472 Format(Query, sizeof(Query), "INSERT INTO EquipData (steamauthid,Name) VALUES ('%s','%s');", steamauthid,user_name);
473 }
474 if(Type == 3) //스텟데이터
475 {
476 Format(Query, sizeof(Query), "INSERT INTO RPGData (steamauthid,Name) VALUES ('%s','%s');", steamauthid,user_name);
477 }
478 if(Type == 4) //스킬데이터
479 {
480 Format(Query, sizeof(Query), "INSERT INTO SkillCube (steamauthid,Name) VALUES ('%s', \"%N\");", steamauthid,user_name);
481 }
482 if(Type == 5) //아이템데이터
483 {
484 Format(Query, sizeof(Query), "INSERT INTO ItemCube (steamauthid,Name) VALUES ('%s', \"%N\");", steamauthid,user_name);
485 }
486 SQL_TQuery(DB, SQL_ErrorCheckCallBack, Query);
487}
488//========================================================
489// 2. 저장부분
490//========================================================
491public OnClientDisconnect(Client) //나갈땐 무조건 전부다저장해야함
492{
493 char steamID[32];
494 new String:user_name[64];
495 //저장
496 if(GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID)))
497 {
498 GetClientName(Client, user_name, sizeof(user_name));
499 UpdatePlayerTaiga(steamID, user_name, G_ELO[Client]); //타이가 원본
500 //UpdatePlayerAllFloat(steamID, user_name, G_ELO[Client]); //저장할모든실수값
501 //UpdatePlayerAllInt(steamID, user_name, G_ELO[Client]); //저장할모든정수값
502 //UpdatePlayerAllString(steamID, user_name, G_ELO[Client]); //저장할모든문자열값
503
504 //G_ELO[Client] = 0.0; //서버내 변수 값 초기화인듯
505 }
506}
507UpdatePlayerTaiga(const String:steamauthid[], const String:Name[64], float L_ELO)
508{
509 new String:Query[255], String:curdate[32];
510 FormatTime(curdate, sizeof(curdate), "%Y/%m/%d %X", GetTime());
511 Format(Query, sizeof(Query), "UPDATE playerinfo SET nickname = '%s', isplayeringame = 0, elo = '%f', lastplaydate = '%s' WHERE steamauthid = '%s'", Name, L_ELO, curdate, steamauthid);
512 SQL_TQuery(DB, SQL_ErrorCheckCallBack, Query);
513}
514UpdatePlayerAllFloat(const String:steamauthid[], const String:Name[64], float L_ELO)
515{
516 new String:Query[255], String:curdate[32];
517 FormatTime(curdate, sizeof(curdate), "%Y/%m/%d %X", GetTime());
518 Format(Query, sizeof(Query), "UPDATE playerinfo SET nickname = '%s', isplayeringame = 0, elo = '%f', lastplaydate = '%s' WHERE steamauthid = '%s'", Name, L_ELO, curdate, steamauthid);
519 SQL_TQuery(DB, SQL_ErrorCheckCallBack, Query);
520}
521UpdatePlayerAllInt(const String:steamauthid[], const String:Name[64], int L_ELO)
522{
523 new String:Query[255], String:curdate[32];
524 FormatTime(curdate, sizeof(curdate), "%Y/%m/%d %X", GetTime());
525 Format(Query, sizeof(Query), "UPDATE playerinfo SET nickname = '%s', isplayeringame = 0, elo = '%f', lastplaydate = '%s' WHERE steamauthid = '%s'", Name, L_ELO, curdate, steamauthid);
526 SQL_TQuery(DB, SQL_ErrorCheckCallBack, Query);
527}
528UpdatePlayerAllString(const String:steamauthid[], const String:Name[64], const char[] string1)
529{
530 new String:Query[255], String:curdate[32];
531 const char[] string2;
532 strcopy(string1, sizeof(string1), string2);
533 FormatTime(curdate, sizeof(curdate), "%Y/%m/%d %X", GetTime());
534 Format(Query, sizeof(Query), "UPDATE playerinfo SET nickname = '%s', isplayeringame = 0, elo = '%f', lastplaydate = '%s' WHERE steamauthid = '%s'", Name, string2, curdate, steamauthid);
535 SQL_TQuery(DB, SQL_ErrorCheckCallBack, Query);
536}
537//각부분저장
538//1. 유저데이터저장
539public DATADBSAVE(Client)
540{
541 char steamID[32];
542 new String:user_name[64];
543 //저장
544 if(GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID)))
545 {
546 //스팀ID, 이름, 필드이름, 변수이름, 저장할 정수값
547 UpdatePlayerInt(steamID, user_name, "User", "Level", Level[Client]); //저장할정수값
548 UpdatePlayerInt(steamID, user_name, "User", "SP", SP[Client]); //저장할정수값
549 UpdatePlayerInt(steamID, user_name, "User", "EXP", EXP[Client]); //저장할정수값
550 UpdatePlayerInt(steamID, user_name, "User", "Job", Job[Client]); //저장할정수값
551 UpdatePlayerInt(steamID, user_name, "User", "Cash", Cash[Client]); //저장할정수값
552 UpdatePlayerInt(steamID, user_name, "User", "Point", Point[Client]); //저장할정수값
553 UpdatePlayerInt(steamID, user_name, "User", "RestPoint", RestPoint[Client]); //저장할정수값
554 UpdatePlayerInt(steamID, user_name, "User", "KillPoint", KillPoint[Client]); //저장할정수값
555 UpdatePlayerInt(steamID, user_name, "User", "STP", STP[Client]); //저장할정수값
556 UpdatePlayerInt(steamID, user_name, "User", "Gak", Gak[Client]); //저장할정수값
557 UpdatePlayerInt(steamID, user_name, "User", "Point_Rank", Point_Rank[Client]); //저장할정수값
558 UpdatePlayerInt(steamID, user_name, "User", "Class", Class[Client]); //저장할정수값
559 }
560}
561//2. 장비장착데이터저장
562public DATADBSAVE2(Client, Type)
563{
564 char steamID[32];
565 new String:user_name[64];
566 //저장
567 if(GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID)))
568 {
569 //1 = 무기장착변수값(정수), 2 = 활성화값(정수)+문자열값
570 if(Type == 1)
571 {
572 //스팀ID, 이름, 필드이름, 변수이름, 저장할 정수값
573 UpdatePlayerInt(steamID, user_name, "EquipData", "Weapon", Weapon1[Client]); //저장할정수값
574 UpdatePlayerInt(steamID, user_name, "EquipData", "Wskin", Wskin[Client]); //저장할정수값
575 UpdatePlayerInt(steamID, user_name, "EquipData", "Body", Body[Client]); //저장할정수값
576 UpdatePlayerInt(steamID, user_name, "EquipData", "Caps", Caps[Client]); //저장할정수값
577 UpdatePlayerInt(steamID, user_name, "EquipData", "Shoulder", Shoulder[Client]); //저장할정수값
578 UpdatePlayerInt(steamID, user_name, "EquipData", "Bealt", Bealt[Client]); //저장할정수값
579 UpdatePlayerInt(steamID, user_name, "EquipData", "Shirts", Shirts[Client]); //저장할정수값
580 UpdatePlayerInt(steamID, user_name, "EquipData", "Pants", Pants[Client]); //저장할정수값
581 UpdatePlayerInt(steamID, user_name, "EquipData", "Ring", Ring[Client]); //저장할정수값
582 UpdatePlayerInt(steamID, user_name, "EquipData", "Necklace", Necklace[Client]); //저장할정수값
583 UpdatePlayerInt(steamID, user_name, "EquipData", "Armlet", Armlet[Client]); //저장할정수값
584 UpdatePlayerInt(steamID, user_name, "EquipData", "Title", Title1[Client]); //저장할정수값
585 UpdatePlayerInt(steamID, user_name, "EquipData", "Tag", Tag1[Client]); //저장할정수값
586 }
587 if(Type == 2)
588 {
589 UpdatePlayerInt(steamID, user_name, "EquipData", "SkinEnable", SkinEnable[Client]); //저장할정수값
590 UpdatePlayerInt(steamID, user_name, "EquipData", "ShoesEnable", ShoesEnable[Client]); //저장할정수값
591 UpdatePlayerInt(steamID, user_name, "EquipData", "LaserEnable", LaserEnable[Client]); //저장할정수값
592 UpdatePlayerInt(steamID, user_name, "EquipData", "KnifeEnable", KnifeEnable[Client]); //저장할정수값
593 UpdatePlayerInt(steamID, user_name, "EquipData", "PetEnable", PetEnable[Client]); //저장할정수값
594 UpdatePlayerInt(steamID, user_name, "EquipData", "TrailEnable", TrailEnable[Client]); //저장할정수값
595 UpdatePlayerInt(steamID, user_name, "EquipData", "TagEnable", TagEnable[Client]); //저장할정수값
596 UpdatePlayerInt(steamID, user_name, "EquipData", "Vibration01", Vibration01[Client]); //저장할정수값
597 UpdatePlayerInt(steamID, user_name, "EquipData", "Vibration02", Vibration02[Client]); //저장할정수값
598 UpdatePlayerString(steamID, user_name, "EquipData", "SkinName", SkinName[Client]); //저장할문자열값
599 UpdatePlayerString(steamID, user_name, "EquipData", "ShoesName", ShoesName[Client]); //저장할문자열값
600 UpdatePlayerString(steamID, user_name, "EquipData", "LaserName", LaserName[Client]); //저장할문자열값
601 UpdatePlayerString(steamID, user_name, "EquipData", "KnifeName", KnifeName[Client]); //저장할문자열값
602 UpdatePlayerString(steamID, user_name, "EquipData", "PetName", PetName[Client]); //저장할문자열값
603 UpdatePlayerString(steamID, user_name, "EquipData", "TrailName", TrailName[Client]); //저장할문자열값
604 UpdatePlayerString(steamID, user_name, "EquipData", "TagName", TagName[Client]); //저장할문자열값
605 }
606 }
607}
608//3. RPG데이터저장
609public DATADBSAVE3(Client)
610{
611 char steamID[32];
612 new String:user_name[64];
613 //저장
614 if(GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID)))
615 {
616 UpdatePlayerInt(steamID, user_name, "RPGData", "STR", STR[Client]); //저장할정수값
617 UpdatePlayerInt(steamID, user_name, "RPGData", "DEX", DEX[Client]); //저장할정수값
618 UpdatePlayerInt(steamID, user_name, "RPGData", "Intelligence", INT[Client]); //저장할정수값
619 UpdatePlayerInt(steamID, user_name, "RPGData", "LUK", LUK[Client]); //저장할정수값
620 UpdatePlayerInt(steamID, user_name, "RPGData", "HP", HP[Client]); //저장할정수값
621 UpdatePlayerInt(steamID, user_name, "RPGData", "Mp", Mp[Client]); //저장할정수값
622 UpdatePlayerInt(steamID, user_name, "RPGData", "Striking", Striking[Client]); //저장할정수값
623 UpdatePlayerInt(steamID, user_name, "RPGData", "Vitality", Vitality[Client]); //저장할정수값
624 UpdatePlayerInt(steamID, user_name, "RPGData", "Evasion", Evasion[Client]); //저장할정수값
625 }
626}
627//4. 스킬데이터저장
628public SkillSave(Client, x) //스킬 지정 저장
629{
630 char steamID[32];
631 new String:user_name[64];
632 if(GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID)))
633 {
634 //스팀ID, 필드이름, SET '이름', SET 이름'정수', 저장할정수값
635 UpdatePlayerCubeInt(steamID, "SkillCube", "Skill", x, Skill[Client][x]);
636 }
637}
638//5. 아이템데이터저장
639public ItemSave(Client, x) //아이템 지정 저장
640{
641 char steamID[32];
642 new String:user_name[64];
643 if(GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID)))
644 {
645 //스팀ID, 필드이름, SET '이름', SET 이름'정수', 저장할정수값
646 UpdatePlayerCubeInt(steamID, "ItemCube", "Item", x, Item[Client][x]);
647 }
648}
649//스팀ID, 이름, 필드이름, 변수이름, 저장할 실수값
650UpdatePlayerFloat(const String:steamauthid[], const String:Name[64], const String:FieldName[64], const String:Variable[64], float L_ELO)
651{
652 new String:Query[255];
653 Format(Query, sizeof(Query), "UPDATE %s SET Name = '%s', %s = '%f' WHERE steamauthid = '%s'", FieldName, Name, Variable, L_ELO, steamauthid);
654 SQL_TQuery(DB, SQL_ErrorCheckCallBack, Query);
655}
656//스팀ID, 이름, 필드이름, 변수이름, 저장할 정수값
657UpdatePlayerInt(const String:steamauthid[], const String:Name[64], const String:FieldName[64], const String:Variable[64], int L_ELO)
658{
659 new String:Query[255];
660 Format(Query, sizeof(Query), "UPDATE %s SET Name = '%s', %s = '%i' WHERE steamauthid = '%s'", FieldName, Name, Variable, L_ELO, steamauthid);
661 SQL_TQuery(DB, SQL_ErrorCheckCallBack, Query);
662}
663//스팀ID, 이름, 필드이름, 변수이름, 저장할 문자열값
664UpdatePlayerString(const String:steamauthid[], const String:Name[64], const String:FieldName[64], const String:Variable[64], const char[] string1)
665{
666 new String:Query[255];
667 const char[] string2;
668 strcopy(string1, sizeof(string1), string2);
669 Format(Query, sizeof(Query), "UPDATE %s SET Name = '%s', %s = '%s' WHERE steamauthid = '%s'", FieldName, Name, Variable, string2, steamauthid);
670 SQL_TQuery(DB, SQL_ErrorCheckCallBack, Query);
671}
672//스팀ID, SET '이름', 필드이름, SET 이름'변수', 저장할정수값
673UpdatePlayerCubeInt(const String:steamauthid[], const String:FieldName[64],const String:Name[64], int Variable, int L_ELO)
674{
675 new String:Query[255];
676 Format(Query, sizeof(Query), "UPDATE %s SET %s%i = '%i' WHERE steamauthid = '%s'", FieldName, Name, Variable, L_ELO, steamauthid);
677 SQL_TQuery(DB, SQL_ErrorCheckCallBack, Query);
678}
679//========================================================
680// 3. 커맨드
681//========================================================
682//커맨드
683public Action:Command_Test(Client, args)
684{
685 // Use our function to write something to the DB
686 AddPlayer("STEAM_:xxx", "Some name or so");
687
688 // Prints all users out
689 ReadAll();
690
691 //Updates a single player
692 //UpdatePlayer("STEAM_:xxx", "Petrus is a much cooler name");
693
694
695 return Plugin_Handled;
696}
697ReadAll()
698{
699 new String:Query[255];
700 Format(Query, sizeof(Query), "SELECT * FROM playerinfo");
701
702 // Send our Query to the Function
703 SQL_TQuery(DB, SQL_ReadAll, Query);
704}
705public SQL_ReadAll(Handle:owner, Handle:hndl, const String:error[], any:data)
706{
707 // We need to know the rowcount, in this case 2-1 because field begins at 0
708 new RowCount = SQL_GetFieldCount(hndl);
709
710 // Temp, just for debugging or so
711 new field;
712
713 // Buffer for our result
714 new String:Buffer[255];
715
716 // We need to fetch each row to get the results of it
717 while(SQL_FetchRow(hndl))
718 {
719 //데이터한줄씩읽어옴
720 for(new i; i< RowCount; i++)
721 {
722 // Gets the String from field i
723 SQL_FetchString(hndl, i, Buffer, sizeof(Buffer));
724 PrintToServer("Field %d | Row: %d | String: %s", field, i, Buffer);
725 }
726 // Increment our fieldcount
727 field++;
728 }
729}
730//========================================================
731// 4. 체크함수
732//========================================================
733//맨마지막
734// SQL 에러 출력 함수
735public SQL_ErrorCheckCallBack(Handle:owner, Handle:hndl, const String:error[], any:data)
736{
737 if(hndl == INVALID_HANDLE)
738 {
739 SetFailState("쿼리 실패! %s %s", error , data);
740 LogError("쿼리 실패! %s %s", error , data);
741 PrintToServer("쿼리 실패! %s %s", error , data);
742 }
743}
744/*
745//세이훅
746public Action:SayHook(Client, Arguments)
747{
748 // 서버 채팅은 통과
749 if (Client == 0) return Plugin_Continue;
750
751 new String:Msg[256];
752 GetCmdArgString(Msg, sizeof(Msg));
753 Msg[strlen(Msg)-1] = '\0';
754 if(StrContains(Msg[1], "!인벤토리") == 0)
755 {
756 //Menu_Main(Client, 0);
757 }
758 char steamID[32];
759 new String:user_name[64];
760 if(GetClientAuthId(Client, AuthId_Steam2, steamID, sizeof(steamID)))
761 {
762 GetClientName(Client, user_name, sizeof(user_name));
763 ReplaceString(Msg[0], 2, "\"", "", false); // 따옴표 제거
764 AddMessage(steamID,user_name,Msg[0]);
765 }
766 return Plugin_Continue;
767}
768*/
769AddMessage(const String:steamauthid[], const String:user_name[64], const String:message[64])
770{
771 new String:Query[255], String:curdate[32];
772 FormatTime(curdate, sizeof(curdate), "%Y/%m/%d %X", GetTime()); // 참고 주소 - http://cplusplus.com/reference/clibrary/ctime/strftime/
773
774 Format(Query, sizeof(Query), "INSERT INTO systemchat VALUES ('0','%s','%s','%s','%s')", steamauthid, user_name,message,curdate);
775
776 SQL_TQuery(DB, SQL_ErrorCheckCallBack, Query);
777}
778
779//========================================================
780// 5. 랭킹
781//========================================================
782SQL_ClientRankInfo(Handle:handle, Client, Target)
783{
784 if(handle != INVALID_HANDLE && !IsFakeClient(Target))
785 {
786 new String:SteamID[128], String:Query[128];
787 GetClientAuthId(Target, AuthId_Steam2, SteamID, sizeof(SteamID));
788
789 new Handle:Datapack = CreateDataPack();
790 WritePackCell(Datapack, Client);
791 WritePackCell(Datapack, Target);
792
793 Format(Query, sizeof(Query), "SELECT COUNT(*) + 1 FROM User WHERE Point_Rank > (SELECT Point_Rank FROM User WHERE SteamID = '%s')", SteamID);
794 SQL_TQuery(DB, SQL_RankInfo, Query, Datapack, DBPrio_High);
795 }
796}
797public SQL_RankInfo(Handle:owner, Handle:handle, const String:error[], any:Datapack)
798{
799 if(handle != INVALID_HANDLE)
800 {
801 new Client, Target;
802 ResetPack(Datapack);
803 Client = ReadPackCell(Datapack);
804 Target = ReadPackCell(Datapack);
805
806 if(SQL_GetRowCount(handle))
807 {
808 if(SQL_HasResultSet(handle))
809 {
810 while(SQL_FetchRow(handle)) Ranking[Target] = SQL_FetchInt(handle, 0);
811 DisplayMenu_Information(Client, Target);
812 }
813 }
814 }
815}
816