7
7
// 3.Delete...
8
8
// 4.Set Permission...
9
9
// 5.Load others project...
10
- // 6.Check Cache System...
10
+ // 6.Cache System...
11
11
// 7.Connect to Cloud Storage
12
12
//
13
13
////////////////////////
17
17
#define DEBUG
18
18
19
19
#define PLUGIN_AUTHOR " Battlefield Duck"
20
- #define PLUGIN_VERSION " 9.6 "
20
+ #define PLUGIN_VERSION " 9.7 "
21
21
22
22
#include <sourcemod>
23
23
#include <sdktools>
@@ -52,7 +52,8 @@ char g_cCurrentMap[64];
52
52
bool g_bPermission [MAXPLAYERS + 1 ][MAX_SLOT + 1 ]; //client, slot
53
53
54
54
//Cache system
55
- bool g_bIsClientInServer [MAXPLAYERS + 1 ] = false ;
55
+ Handle g_hCacheTimer [MAXPLAYERS + 1 ] = INVALID_HANDLE ;
56
+
56
57
bool g_bWaitingForPlayers ;
57
58
58
59
int g_iCoolDown [MAXPLAYERS + 1 ] = 0 ;
@@ -235,14 +236,18 @@ public void OnClientPutInServer(int client)
235
236
g_bPermission [client ][j ] = false ;
236
237
237
238
//Cache system
238
- g_bIsClientInServer [client ] = true ;
239
+ g_hCacheTimer [client ] = INVALID_HANDLE ;
240
+
239
241
if (g_bWaitingForPlayers ) CreateTimer (30.0 , Timer_Load , client );
240
242
else CreateTimer (5.0 , Timer_Load , client );
241
243
}
242
244
243
245
public void OnClientDisconnect (int client )
244
246
{
245
- g_bIsClientInServer [client ] = false ;
247
+ if (g_hCacheTimer [client ] != INVALID_HANDLE )
248
+ {
249
+ KillTimer (g_hCacheTimer [client ]);
250
+ }
246
251
}
247
252
248
253
public void TF2_OnWaitingForPlayersStart ()
@@ -296,17 +301,25 @@ public Action Timer_LoadMap(Handle timer, int client)
296
301
//Cache system
297
302
public Action Timer_Save (Handle timer , int client )
298
303
{
299
- if (IsValidClient (client ) && ! IsFakeClient (client )) SaveData (client , 0 );
304
+ if (! IsValidClient (client ))
305
+ {
306
+ return Plugin_Stop ;
307
+ }
300
308
301
- if (g_bIsClientInServer [client ]) CreateTimer (10.0 , Timer_Save , client );
309
+ SaveData (client , 0 );
310
+
311
+ return Plugin_Continue ;
302
312
}
303
313
304
314
public Action Timer_Load (Handle timer , int client )
305
315
{
306
316
if (IsValidClient (client ) && ! IsFakeClient (client ) && ! g_bWaitingForPlayers )
307
317
{
308
318
if (DataFileExist (client , 0 )) Command_CacheMenu (client , - 1 );
309
- else CreateTimer (5.0 , Timer_Save , client );
319
+ else if (g_hCacheTimer [client ] == INVALID_HANDLE )
320
+ {
321
+ g_hCacheTimer [client ] = CreateTimer (5.0 , Timer_Save , client , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE );
322
+ }
310
323
}
311
324
else CreateTimer (5.0 , Timer_Load , client );
312
325
}
@@ -410,7 +423,7 @@ public Action Command_MainMenu(int client, int args)
410
423
if (GetClientInGame () > 1 ) menu .AddItem (" LOADOTHERS" , menuinfo );
411
424
else menu .AddItem (" LOADOTHERS" , menuinfo , ITEMDRAW_DISABLED );
412
425
413
- Format (menuinfo , sizeof (menuinfo ), " Check Cache System... " , client );
426
+ Format (menuinfo , sizeof (menuinfo ), " Cache System... " , client );
414
427
menu .AddItem (" CACHE" , menuinfo );
415
428
416
429
Format (menuinfo , sizeof (menuinfo ), " Connect to Cloud Storage... " , client );
@@ -907,7 +920,17 @@ public Action Command_CheckCacheMenu(int client, int args)
907
920
char menuinfo [255 ];
908
921
Menu menu = new Menu (Handler_CheckCacheMenu );
909
922
910
- Format (menuinfo , sizeof (menuinfo ), " TF2 Sandbox - Save System Main Menu %s \n Map: %s \n \n Plugin Author: BattlefieldDuck\n Credits: Danct12, Leadkiller, aIM...\n \n Cache System: RUNNING\n " , PLUGIN_VERSION , g_cCurrentMap );
923
+ char cacheStatus [48 ];
924
+ if (g_hCacheTimer [client ] == INVALID_HANDLE )
925
+ {
926
+ cacheStatus = " STOPPED" ;
927
+ }
928
+ else
929
+ {
930
+ cacheStatus = " RUNNING" ;
931
+ }
932
+
933
+ Format (menuinfo , sizeof (menuinfo ), " TF2 Sandbox - Save System Main Menu %s \n Map: %s \n \n Plugin Author: BattlefieldDuck\n Credits: Danct12, Leadkiller, aIM...\n \n Cache System: %s \n " , PLUGIN_VERSION , g_cCurrentMap , cacheStatus );
911
934
menu .SetTitle (menuinfo );
912
935
913
936
int iSlot = 0 ;
@@ -922,9 +945,18 @@ public Action Command_CheckCacheMenu(int client, int args)
922
945
923
946
menu .AddItem (cSlot , menuinfo , ITEMDRAW_DISABLED );
924
947
925
- Format (menuinfo , sizeof (menuinfo ), " Refresh" );
948
+ Format (menuinfo , sizeof (menuinfo ), " Load current cache data" );
949
+ menu .AddItem (" LOAD" , menuinfo );
950
+
951
+ Format (menuinfo , sizeof (menuinfo ), " Refresh\n " );
926
952
menu .AddItem (" REFRESH" , menuinfo );
927
953
954
+ Format (menuinfo , sizeof (menuinfo ), " ---------------------\n !!! Restarting cache system will lost the cache data !!!\n " );
955
+ menu .AddItem (" " , menuinfo , ITEMDRAW_DISABLED );
956
+
957
+ Format (menuinfo , sizeof (menuinfo ), " Restart cache system" );
958
+ menu .AddItem (" RESTART" , menuinfo );
959
+
928
960
menu .ExitBackButton = true ;
929
961
menu .ExitButton = false ;
930
962
menu .Display (client , MENU_TIME_FOREVER );
@@ -938,6 +970,23 @@ public int Handler_CheckCacheMenu(Menu menu, MenuAction action, int client, int
938
970
menu .GetItem (selection , info , sizeof (info ));
939
971
940
972
if (StrEqual (" REFRESH" , info )) Command_CheckCacheMenu (client , 0 );
973
+ else if (StrEqual (" LOAD" , info ))
974
+ {
975
+ LoadData (client , client , 0 );
976
+
977
+ Command_CheckCacheMenu (client , 0 );
978
+ }
979
+ else if (StrEqual (" RESTART" , info ))
980
+ {
981
+ char cFileName [255 ];
982
+ GetBuildPath (client , 0 , cFileName );
983
+
984
+ if (FileExists (cFileName )) DeleteFile (cFileName ); //Delete
985
+
986
+ Build_PrintToChat (client , " Cache system restarted" );
987
+
988
+ Command_CheckCacheMenu (client , 0 );
989
+ }
941
990
}
942
991
else if (action == MenuAction_Cancel )
943
992
{
@@ -1173,7 +1222,17 @@ void LoadFunction(int loader, int slot, char cFileName[255])
1173
1222
}
1174
1223
CloseHandle (g_hFileEditting [loader ]);
1175
1224
1176
- if (slot == 0 ) Build_PrintToChat (loader , " Load Result >> Loaded: \x04 %i \x01 , Error: \x04 %i \x01 >> Cache Loaded" , g_iCountEntity , g_iCountLoop - g_iCountEntity );
1225
+ if (slot == 0 )
1226
+ {
1227
+ Build_PrintToChat (loader , " Load Result >> Loaded: \x04 %i \x01 , Error: \x04 %i \x01 >> Cache Loaded" , g_iCountEntity , g_iCountLoop - g_iCountEntity );
1228
+
1229
+ DeleteFile (cFileName );
1230
+
1231
+ if (g_hCacheTimer [loader ] == INVALID_HANDLE )
1232
+ {
1233
+ g_hCacheTimer [loader ] = CreateTimer (5.0 , Timer_Save , loader , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE );
1234
+ }
1235
+ }
1177
1236
else Build_PrintToChat (loader , " Load Result >> Loaded: \x04 %i \x01 , Error: \x04 %i \x01 >> Loaded Slot\x04 %i \x01 " , g_iCountEntity , g_iCountLoop - g_iCountEntity , slot );
1178
1237
}
1179
1238
}
@@ -1213,7 +1272,21 @@ public Action Timer_LoadProps(Handle timer, Handle dp)
1213
1272
}
1214
1273
if (IsEndOfFile (g_hFileEditting [loader ]))
1215
1274
{
1216
- if (slot == 0 ) Build_PrintToChat (loader , " Load Result >> Loaded: \x04 %i \x01 , Error: \x04 %i \x01 >> Cache Loaded" , g_iCountEntity , g_iCountLoop - g_iCountEntity );
1275
+ if (slot == 0 )
1276
+ {
1277
+ Build_PrintToChat (loader , " Load Result >> Loaded: \x04 %i \x01 , Error: \x04 %i \x01 >> Cache Loaded" , g_iCountEntity , g_iCountLoop - g_iCountEntity );
1278
+
1279
+ CloseHandle (g_hFileEditting [loader ]);
1280
+
1281
+ DeleteFile (cFileName );
1282
+
1283
+ if (g_hCacheTimer [loader ] == INVALID_HANDLE )
1284
+ {
1285
+ g_hCacheTimer [loader ] = CreateTimer (5.0 , Timer_Save , loader , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE );
1286
+ }
1287
+
1288
+ return ;
1289
+ }
1217
1290
else Build_PrintToChat (loader , " Load Result >> Loaded: \x04 %i \x01 , Error: \x04 %i \x01 >> Loaded Slot\x04 %i \x01 " , g_iCountEntity , g_iCountLoop - g_iCountEntity , slot );
1218
1291
}
1219
1292
else
0 commit comments