Skip to content

Commit 743ae7a

Browse files
v9.7
- Improved Cache system
1 parent e77d04b commit 743ae7a

File tree

2 files changed

+86
-13
lines changed

2 files changed

+86
-13
lines changed

plugins/TF2Sandbox-SaveSystem.smx

3.97 KB
Binary file not shown.

scripting/TF2Sandbox-SaveSystem.sp

Lines changed: 86 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// 3.Delete...
88
// 4.Set Permission...
99
// 5.Load others project...
10-
// 6.Check Cache System...
10+
// 6.Cache System...
1111
// 7.Connect to Cloud Storage
1212
//
1313
////////////////////////
@@ -17,7 +17,7 @@
1717
#define DEBUG
1818

1919
#define PLUGIN_AUTHOR "Battlefield Duck"
20-
#define PLUGIN_VERSION "9.6"
20+
#define PLUGIN_VERSION "9.7"
2121

2222
#include <sourcemod>
2323
#include <sdktools>
@@ -52,7 +52,8 @@ char g_cCurrentMap[64];
5252
bool g_bPermission[MAXPLAYERS + 1][MAX_SLOT + 1]; //client, slot
5353

5454
//Cache system
55-
bool g_bIsClientInServer[MAXPLAYERS + 1] = false;
55+
Handle g_hCacheTimer[MAXPLAYERS + 1] = INVALID_HANDLE;
56+
5657
bool g_bWaitingForPlayers;
5758

5859
int g_iCoolDown[MAXPLAYERS + 1] = 0;
@@ -235,14 +236,18 @@ public void OnClientPutInServer(int client)
235236
g_bPermission[client][j] = false;
236237

237238
//Cache system
238-
g_bIsClientInServer[client] = true;
239+
g_hCacheTimer[client] = INVALID_HANDLE;
240+
239241
if(g_bWaitingForPlayers) CreateTimer(30.0, Timer_Load, client);
240242
else CreateTimer(5.0, Timer_Load, client);
241243
}
242244

243245
public void OnClientDisconnect(int client)
244246
{
245-
g_bIsClientInServer[client] = false;
247+
if (g_hCacheTimer[client] != INVALID_HANDLE)
248+
{
249+
KillTimer(g_hCacheTimer[client]);
250+
}
246251
}
247252

248253
public void TF2_OnWaitingForPlayersStart()
@@ -296,17 +301,25 @@ public Action Timer_LoadMap(Handle timer, int client)
296301
//Cache system
297302
public Action Timer_Save(Handle timer, int client)
298303
{
299-
if (IsValidClient(client) && !IsFakeClient(client)) SaveData(client, 0);
304+
if (!IsValidClient(client))
305+
{
306+
return Plugin_Stop;
307+
}
300308

301-
if (g_bIsClientInServer[client]) CreateTimer(10.0, Timer_Save, client);
309+
SaveData(client, 0);
310+
311+
return Plugin_Continue;
302312
}
303313

304314
public Action Timer_Load(Handle timer, int client)
305315
{
306316
if (IsValidClient(client) && !IsFakeClient(client) && !g_bWaitingForPlayers)
307317
{
308318
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+
}
310323
}
311324
else CreateTimer(5.0, Timer_Load, client);
312325
}
@@ -410,7 +423,7 @@ public Action Command_MainMenu(int client, int args)
410423
if (GetClientInGame() > 1) menu.AddItem("LOADOTHERS", menuinfo);
411424
else menu.AddItem("LOADOTHERS", menuinfo, ITEMDRAW_DISABLED);
412425

413-
Format(menuinfo, sizeof(menuinfo), " Check Cache System... ", client);
426+
Format(menuinfo, sizeof(menuinfo), " Cache System... ", client);
414427
menu.AddItem("CACHE", menuinfo);
415428

416429
Format(menuinfo, sizeof(menuinfo), " Connect to Cloud Storage... ", client);
@@ -907,7 +920,17 @@ public Action Command_CheckCacheMenu(int client, int args)
907920
char menuinfo[255];
908921
Menu menu = new Menu(Handler_CheckCacheMenu);
909922

910-
Format(menuinfo, sizeof(menuinfo), "TF2 Sandbox - Save System Main Menu %s \nMap: %s\n \nPlugin Author: BattlefieldDuck\nCredits: Danct12, Leadkiller, aIM...\n \nCache 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 \nMap: %s\n \nPlugin Author: BattlefieldDuck\nCredits: Danct12, Leadkiller, aIM...\n \nCache System: %s\n ", PLUGIN_VERSION, g_cCurrentMap, cacheStatus);
911934
menu.SetTitle(menuinfo);
912935

913936
int iSlot = 0;
@@ -922,9 +945,18 @@ public Action Command_CheckCacheMenu(int client, int args)
922945

923946
menu.AddItem(cSlot, menuinfo, ITEMDRAW_DISABLED);
924947

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");
926952
menu.AddItem("REFRESH", menuinfo);
927953

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+
928960
menu.ExitBackButton = true;
929961
menu.ExitButton = false;
930962
menu.Display(client, MENU_TIME_FOREVER);
@@ -938,6 +970,23 @@ public int Handler_CheckCacheMenu(Menu menu, MenuAction action, int client, int
938970
menu.GetItem(selection, info, sizeof(info));
939971

940972
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+
}
941990
}
942991
else if (action == MenuAction_Cancel)
943992
{
@@ -1173,7 +1222,17 @@ void LoadFunction(int loader, int slot, char cFileName[255])
11731222
}
11741223
CloseHandle(g_hFileEditting[loader]);
11751224

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+
}
11771236
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);
11781237
}
11791238
}
@@ -1213,7 +1272,21 @@ public Action Timer_LoadProps(Handle timer, Handle dp)
12131272
}
12141273
if (IsEndOfFile(g_hFileEditting[loader]))
12151274
{
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+
}
12171290
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);
12181291
}
12191292
else

0 commit comments

Comments
 (0)