maintenance.pwn 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. #include <YSI\y_hooks>
  2. new SystemUpdate, SystemTimer;
  3. new Text:UpdateIn[2];
  4. hook OnGameModeInit() {
  5. UpdateIn[0] = TextDrawCreate(483.999969, 431.007720, "Server_update_in:");
  6. TextDrawLetterSize(UpdateIn[0], 0.424666, 1.612444);
  7. TextDrawAlignment(UpdateIn[0], 1);
  8. TextDrawColor(UpdateIn[0], -1);
  9. TextDrawSetShadow(UpdateIn[0], 0);
  10. TextDrawSetOutline(UpdateIn[0], 1);
  11. TextDrawBackgroundColor(UpdateIn[0], 255);
  12. TextDrawFont(UpdateIn[0], 1);
  13. TextDrawSetProportional(UpdateIn[0], 1);
  14. TextDrawSetShadow(UpdateIn[0], 0);
  15. UpdateIn[1] = TextDrawCreate(595.181335, 431.007720, "00:00");
  16. TextDrawLetterSize(UpdateIn[1], 0.424666, 1.612444);
  17. TextDrawAlignment(UpdateIn[1], 1);
  18. TextDrawColor(UpdateIn[1], -1);
  19. TextDrawSetShadow(UpdateIn[1], 0);
  20. TextDrawSetOutline(UpdateIn[1], 1);
  21. TextDrawBackgroundColor(UpdateIn[1], 255);
  22. TextDrawFont(UpdateIn[1], 1);
  23. TextDrawSetProportional(UpdateIn[1], 1);
  24. TextDrawSetShadow(UpdateIn[1], 0);
  25. return 1;
  26. }
  27. hook OnPlayerConnect(playerid) {
  28. if(SystemUpdate > 0) {
  29. TextDrawShowForPlayer(playerid, UpdateIn[0]);
  30. TextDrawShowForPlayer(playerid, UpdateIn[1]);
  31. }
  32. }
  33. hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  34. if(arrAntiCheat[playerid][ac_iFlags][AC_DIALOGSPOOFING] > 0) return 1;
  35. new string[6];
  36. switch(dialogid)
  37. {
  38. case DIALOG_MAINTENANCE:
  39. {
  40. if(response) {
  41. if(isnull(inputtext)) return ShowPlayerDialogEx(playerid, DIALOG_MAINTENANCE, DIALOG_STYLE_INPUT, "How long should the timer run?", "Please specify in seconds how long before the server kicks all users & shuts down?\n\nWARNING: This action can't be undone!", "Shutdown", "Exit");
  42. if(!(30 <= strval(inputtext) < 3541)) return ShowPlayerDialogEx(playerid, DIALOG_MAINTENANCE, DIALOG_STYLE_INPUT, "How long should the timer run?", "Please specify in seconds how long before the server kicks all users & shuts down?\n\nWARNING: This action can't be undone!", "Shutdown", "Exit");
  43. if(PlayerInfo[playerid][pAdmin] < 1337) return SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to perform this action!");
  44. SendClientMessageToAllEx(COLOR_LIGHTBLUE, "* The server will be going down for Scheduled Maintenance. (See bottom right screen)");
  45. GameTextForAll("~n~~n~~n~~n~~y~] Scheduled Maintenance Alert ]", 5000, 3);
  46. SystemUpdate = strval(inputtext);
  47. format(string, sizeof(string), "%s", STimeConvert(SystemUpdate));
  48. TextDrawShowForAll(UpdateIn[0]);
  49. TextDrawSetString(UpdateIn[1], string);
  50. TextDrawShowForAll(UpdateIn[1]);
  51. if(SystemUpdate != 0) KillTimer(SystemTimer);
  52. SystemTimer = SetTimer("MaintenanceTimer", 1000, true);
  53. }
  54. else SendClientMessageEx(playerid, COLOR_WHITE, "You have cancelled doing a maintenance restart.");
  55. }
  56. }
  57. return 1;
  58. }
  59. CMD:announcem(playerid, params[])
  60. {
  61. if(PlayerInfo[playerid][pAdmin] < 1337) return SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to use this command.");
  62. ShowPlayerDialogEx(playerid, DIALOG_MAINTENANCE, DIALOG_STYLE_INPUT, "How long should the timer run?", "Please specify in seconds how long before the server kicks all users & shuts down?\n\nWARNING: This action can't be undone!", "Shutdown", "Exit");
  63. return 1;
  64. }
  65. forward MaintenanceTimer();
  66. public MaintenanceTimer() {
  67. new string[6];
  68. if(--SystemUpdate == 0) KillTimer(SystemTimer), Maintenance();
  69. if(SystemUpdate == 15) GameTextForAll("~n~~n~~n~~n~~w~Please ~r~log out ~w~now to ensure ~y~account data ~w~has been ~g~saved~w~!", 5000, 3);
  70. if(SystemUpdate < 0) SystemUpdate = 0;
  71. format(string, sizeof(string), "%s", STimeConvert(SystemUpdate));
  72. TextDrawSetString(UpdateIn[1], string);
  73. TextDrawShowForAll(UpdateIn[1]);
  74. return 1;
  75. }
  76. STimeConvert(time) {
  77. new jmin;
  78. new jsec;
  79. new string[128];
  80. if(time > 59 && time < 3600){
  81. jmin = floatround(time/60);
  82. jsec = floatround(time - jmin*60);
  83. format(string,sizeof(string),"%02d:%02d",jmin,jsec);
  84. }
  85. else{
  86. jsec = floatround(time);
  87. format(string,sizeof(string),"00:%02d",jsec);
  88. }
  89. return string;
  90. }
  91. forward Maintenance();
  92. public Maintenance()
  93. {
  94. new string[128];
  95. ABroadCast(COLOR_YELLOW, "{AA3333}Maintenance{FFFF00}: Freezing Accounts...", 1);
  96. foreach(new i: Player)
  97. {
  98. TogglePlayerControllable(i, false);
  99. }
  100. ABroadCast(COLOR_YELLOW, "{AA3333}Maintenance{FFFF00}: Locking Paintball Arenas...", 1);
  101. for(new i = 0; i < MAX_ARENAS; i++)
  102. {
  103. foreach(new p: Player)
  104. {
  105. if(!GetPVarType(p, "IsInArena")) continue;
  106. new arenaid = GetPVarInt(p, "IsInArena");
  107. if(arenaid == i)
  108. {
  109. if(PaintBallArena[arenaid][pbBidMoney] > 0)
  110. {
  111. GivePlayerCash(p,PaintBallArena[GetPVarInt(p, "IsInArena")][pbBidMoney]);
  112. format(string,sizeof(string),"You have been refunded a total of $%d because of premature closure.",PaintBallArena[GetPVarInt(p, "IsInArena")][pbBidMoney]);
  113. SendClientMessageEx(p, COLOR_WHITE, string);
  114. }
  115. if(arenaid == GetPVarInt(p, "ArenaNumber"))
  116. {
  117. switch(PaintBallArena[arenaid][pbGameType])
  118. {
  119. case 1:
  120. {
  121. if(PlayerInfo[p][pDonateRank] < 3)
  122. {
  123. PlayerInfo[p][pPaintTokens] += 3;
  124. format(string,sizeof(string),"You have been refunded a total of %d Paintball Tokens because of premature closure.",3);
  125. SendClientMessageEx(p, COLOR_WHITE, string);
  126. }
  127. }
  128. case 2:
  129. {
  130. if(PlayerInfo[p][pDonateRank] < 3)
  131. {
  132. PlayerInfo[p][pPaintTokens] += 4;
  133. format(string,sizeof(string),"You have been refunded a total of %d Paintball Tokens because of premature closure.",4);
  134. SendClientMessageEx(p, COLOR_WHITE, string);
  135. }
  136. }
  137. case 3:
  138. {
  139. if(PlayerInfo[p][pDonateRank] < 3)
  140. {
  141. PlayerInfo[p][pPaintTokens] += 5;
  142. format(string,sizeof(string),"You have been refunded a total of %d Paintball Tokens because of premature closure.",5);
  143. SendClientMessageEx(p, COLOR_WHITE, string);
  144. }
  145. }
  146. case 4:
  147. {
  148. if(PlayerInfo[p][pDonateRank] < 3)
  149. {
  150. PlayerInfo[p][pPaintTokens] += 5;
  151. format(string,sizeof(string),"You have been refunded a total of %d Paintball Tokens because of premature closure.",5);
  152. SendClientMessageEx(p, COLOR_WHITE, string);
  153. }
  154. }
  155. case 5:
  156. {
  157. if(PlayerInfo[p][pDonateRank] < 3)
  158. {
  159. PlayerInfo[p][pPaintTokens] += 6;
  160. format(string,sizeof(string),"You have been refunded a total of %d Paintball Tokens because of premature closure.",6);
  161. SendClientMessageEx(p, COLOR_WHITE, string);
  162. }
  163. }
  164. }
  165. }
  166. LeavePaintballArena(p, arenaid);
  167. }
  168. }
  169. ResetPaintballArena(i);
  170. PaintBallArena[i][pbLocked] = 2;
  171. }
  172. foreach(new i: Player)
  173. {
  174. GameTextForPlayer(i, "Scheduled Maintenance..", 5000, 5);
  175. }
  176. ABroadCast(COLOR_YELLOW, "{AA3333}Maintenance{FFFF00}: Force Saving Accounts...", 1);
  177. SendRconCommand("password asdatasdhwda");
  178. SendRconCommand("hostname Next Generation Roleplay [Restarting for Maintenance]");
  179. foreach(new i: Player)
  180. {
  181. if(gPlayerLogged{i}) {
  182. SetPVarInt(i, "RestartKick", 1);
  183. //g_mysql_SaveAccount(i);
  184. OnPlayerStatsUpdate(i);
  185. break; // We only need to save one person at a time.
  186. }
  187. }
  188. SetTimer("FinishMaintenance", 60000, false);
  189. //g_mysql_DumpAccounts();
  190. return 1;
  191. }
  192. forward FinishMaintenance();
  193. public FinishMaintenance()
  194. {
  195. foreach(new i: Player) Kick(i);
  196. ABroadCast(COLOR_YELLOW, "{AA3333}Maintenance{FFFF00}: Force Saving Houses...", 1);
  197. SaveHouses();
  198. ABroadCast(COLOR_YELLOW, "{AA3333}Maintenance{FFFF00}: Force Saving Dynamic Doors...", 1);
  199. SaveDynamicDoors();
  200. ABroadCast(COLOR_YELLOW, "{AA3333}Maintenance{FFFF00}: Force Saving Garages...", 1);
  201. SaveGarages();
  202. ABroadCast(COLOR_YELLOW, "{AA3333}Maintenance{FFFF00}: Force Saving Map Icons...", 1);
  203. SaveDynamicMapIcons();
  204. ABroadCast(COLOR_YELLOW, "{AA3333}Maintenance{FFFF00}: Force Saving Gates...", 1);
  205. SaveGates();
  206. ABroadCast(COLOR_YELLOW, "{AA3333}Maintenance{FFFF00}: Force Saving Event Points...", 1);
  207. SaveEventPoints();
  208. ABroadCast(COLOR_YELLOW, "{AA3333}Maintenance{FFFF00}: Force Saving Paintball Arenas...", 1);
  209. SavePaintballArenas();
  210. ABroadCast(COLOR_YELLOW, "{AA3333}Maintenance{FFFF00}: Force Saving Server Configuration", 1);
  211. Misc_Save();
  212. ABroadCast(COLOR_YELLOW, "{AA3333}Maintenance{FFFF00}: Force Saving Office Elevator...", 1);
  213. SaveElevatorStuff();
  214. ABroadCast(COLOR_YELLOW, "{AA3333}Maintenance{FFFF00}: Force Saving Mail Boxes...", 1);
  215. SaveMailboxes();
  216. ABroadCast(COLOR_YELLOW, "{AA3333}Maintenance{FFFF00}: Force Saving Speed Cameras...", 1);
  217. SaveSpeedCameras();
  218. ABroadCast(COLOR_YELLOW, "{AA3333}Maintenance{FFFF00}: Force Saving Points...", 1);
  219. for (new i=0; i<MAX_POINTS; i++)
  220. {
  221. SavePoint(i);
  222. }
  223. if(rflstatus > 0) {
  224. ABroadCast(COLOR_YELLOW, "{AA3333}Maintenance{FFFF00}: Force Saving RFL Teams...", 1);
  225. SaveRelayForLifeTeams();
  226. }
  227. g_mysql_SavePrices();
  228. ABroadCast(COLOR_YELLOW, "{AA3333}Maintenance{FFFF00}: Force Saving Turfs...", 1);
  229. SaveTurfWars();
  230. ABroadCast(COLOR_YELLOW, "{AA3333}Maintenance{FFFF00}: Streamer Plugin Shutting Down...", 1);
  231. DestroyAllDynamicObjects();
  232. DestroyAllDynamic3DTextLabels();
  233. DestroyAllDynamicCPs();
  234. DestroyAllDynamicMapIcons();
  235. DestroyAllDynamicRaceCPs();
  236. DestroyAllDynamicAreas();
  237. g_mysql_SaveMOTD();
  238. SetTimer("ShutDown", 5000, false);
  239. return 1;
  240. }
  241. forward ShutDown();
  242. public ShutDown()
  243. {
  244. return SendRconCommand("exit");
  245. }