Advertisement
Guest User

Untitled

a guest
Nov 13th, 2015
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 26.40 KB | None | 0 0
  1. 1c1,2
  2. < //Heavily remodified by Visolator/Kyuande.
  3. ---
  4. > // Heavily remodified by Visolator/Kyuande.
  5. > // (many) patches from TheBlackParrot
  6. 3c4,27
  7. < if($Server::AS::dir $= "")
  8. ---
  9. > $Pref::Server::AS::SaveDirectory = "saves/AutoSaver/";
  10. > $Pref::Server::AS::Announce = true;
  11. > $Pref::Server::AS::AnnounceSaveName = true;
  12. > $Pref::Server::AS::SavingInterval = 5;
  13. > $Pref::Server::AS::DetailedReport = true;
  14. > $Pref::Server::AS::SaveEvents = true;
  15. > // 0 = host, 1 = original owner, 2 = public
  16. > // http://forum.blockland.us/index.php?topic=255914.msg7446537#msg7446537
  17. > $Pref::Server::AS::LoadOwnership = 1;
  18. > $Pref::Server::AS::SaveOwnership = true;
  19. > $Pref::Server::AS::AllowOverwriting = true;
  20. > $Pref::Server::AS::AutoloadPreviousSave = true;
  21. > $Pref::Server::AS::SaveEvenIfSame = false;
  22. > // 1 = admin, 2 = super admin, 3 = host
  23. > $Pref::Server::AS::WhoCanSave = 2;
  24. > $Pref::Server::AS::LastAutoSave = "";
  25. > $Pref::Server::AS::LastBrickCount = 0;
  26. > $Pref::Server::AS::LastEventCount = 0;
  27. >
  28. > if(isFile("config/server/AutoSaver.prefs.cs")) {
  29. >   exec("config/server/AutoSaver.prefs.cs");
  30. > }
  31. >
  32. > if($Pref::Server::AS::SaveDirectory $= "")
  33. 5c29
  34. <   if(isFile("Add-Ons/System_ReturnToBlockland/server.cs"))
  35. ---
  36. >   if(isFile("Add-Ons/System_ReturnToBlockland/server.cs") || isFunction(RTB_registerPref))
  37. 7c31
  38. <       if(!$RTB::Hooks::ServerControl)
  39. ---
  40. >       if(!$RTB::Hooks::ServerControl && isFile("Add-Ons/System_ReturnToBlockland/hooks/serverControl.cs"))
  41. 10,19c34,46
  42. <       RTB_registerPref("Announce", "Autosaver", "$Server::AS::announce", "bool", "Support_AutoSaver", 1, 0, 0);
  43. <       RTB_registerPref("Folder location", "Autosaver", "$Server::AS::dir", "string 50 50", "Support_AutoSaver", "saves/AutoSaver/", 0, 0);
  44. <       RTB_registerPref("Announce savename", "Autosaver", "$Server::AS::announceSaveName", "bool", "Support_AutoSaver", 1, 0);
  45. <       RTB_registerPref("Interval", "Autosaver", "$Server::AS::interval", "int 0 16", "Support_AutoSaver", 5, 0, 0);
  46. <       RTB_registerPref("Report stats", "Autosaver", "$Server::AS::report", "bool", "Support_AutoSaver", 1, 0, 0);
  47. <       RTB_registerPref("Save events", "Autosaver", "$Server::AS::saveEvents", "bool", "Support_AutoSaver", 1, 0, 0);
  48. <       RTB_registerPref("Save ownership", "Autosaver", "$Server::AS::saveOwnership", "bool", "Support_AutoSaver", 1, 0, 0);
  49. <       RTB_registerPref("Overwrite temp save", "Autosaver", "$Server::AS::overwriteSave", "bool", "Support_AutoSaver", 0, 0, 0);
  50. <       RTB_registerPref("Autoload save on start", "Autosaver", "$Server::AS::autoload", "bool", "Support_AutoSaver", 1, 0, 0);
  51. <       RTB_registerPref("Autosave duplicates", "Autosaver", "$Server::AS::SaveRelatedBrickcount", "bool", "Support_AutoSaver", 0, 0, 0);
  52. ---
  53. >       // Blockland Glass can hook into these as legacy prefs, you should be fine
  54. >       RTB_registerPref("Announce", "Autosaver", "$Pref::Server::AS::Announce", "bool", "Support_AutoSaver", 1, 0, 0);
  55. >       RTB_registerPref("Folder location", "Autosaver", "$Pref::Server::AS::SaveDirectory", "string 50 50", "Support_AutoSaver", "saves/AutoSaver/", 1, 0);
  56. >       RTB_registerPref("Announce savename", "Autosaver", "$Pref::Server::AS::AnnounceSaveName", "bool", "Support_AutoSaver", 1, 0);
  57. >       RTB_registerPref("Interval", "Autosaver", "$Pref::Server::AS::SavingInterval", "int 0 16", "Support_AutoSaver", 10, 0, 0);
  58. >       RTB_registerPref("Report stats", "Autosaver", "$Pref::Server::AS::DetailedReport", "bool", "Support_AutoSaver", 1, 0, 0);
  59. >       RTB_registerPref("Save events", "Autosaver", "$Pref::Server::AS::SaveEvents", "bool", "Support_AutoSaver", 1, 0, 0);
  60. >       RTB_registerPref("Save ownership", "Autosaver", "$Pref::Server::AS::SaveOwnership", "bool", "Support_AutoSaver", 1, 0, 0);
  61. >       RTB_registerPref("Load ownership", "Autosaver", "$Pref::Server::AS::LoadOwnership", "list Host 0 Owner 1 Public 2", "Support_AutoSaver", 1, 0, 0);
  62. >       RTB_registerPref("Overwrite temp save", "Autosaver", "$Pref::Server::AS::AllowOverwriting", "bool", "Support_AutoSaver", 1, 0, 0);
  63. >       RTB_registerPref("Autoload save on start", "Autosaver", "$Pref::Server::AS::AutoloadPreviousSave", "bool", "Support_AutoSaver", 1, 1, 0);
  64. >       RTB_registerPref("Autosave duplicates", "Autosaver", "$Pref::Server::AS::SaveEvenIfSame", "bool", "Support_AutoSaver", 0, 0, 0);
  65. >       RTB_registerPref("Allowed to save", "Autosaver", "$Pref::Server::AS::WhoCanSave", "list Admins 1 SuperAdmins 2 Host 3", "Support_AutoSaver", 2, 1, 0);
  66. 21,32c48,57
  67. <   else
  68. <   {
  69. <       $Server::AS::dir = "saves/AutoSaver/";
  70. <       $Server::AS::announce = true;
  71. <       $Server::AS::announceSaveName = true;
  72. <       $Server::AS::interval = 5;
  73. <       $Server::AS::report = true;
  74. <       $Server::AS::saveEvents = true;
  75. <       $Server::AS::saveOwnership = true;
  76. <       $Server::AS::overwriteSave = true;
  77. <       $Server::AS::autoload = true;
  78. <       $Server::AS::SaveRelatedBrickcount = false;
  79. ---
  80. > }
  81. >
  82. > // double-checking
  83. > if($Pref::Server::AS::SavingInterval $= "") {
  84. >   $Pref::Server::AS::SavingInterval = 0;
  85. > }
  86. >
  87. > function GameConnection::isHost(%this) {
  88. >   if(%this.bl_id == getNumKeyID() || %this.bl_id == 999999) {
  89. >       return 1;
  90. 33a59,60
  91. >
  92. >   return 0;
  93. 36,43c63,81
  94. < if(isFile("config/server/AutoSaver.cs"))
  95. <   exec("config/server/AutoSaver.cs");
  96. <
  97. < function Server_AutoloadSave()
  98. < {
  99. <   announce("\c5Autoloading last autosaved build.");
  100. <   if($Server::AS::Pref["LastAutoSave"] !$= "")
  101. <       loadAutoSaveBuild($Server::AS::Pref["LastAutoSave"]);
  102. ---
  103. > function GameConnection::canAutoSaveBricks(%this) {
  104. >   switch($Pref::Server::AS::WhoCanSave) {
  105. >       case 3:
  106. >           if(%this.isHost()) {
  107. >               return 1;
  108. >           }
  109. >
  110. >       case 2:
  111. >           if(%this.isSuperAdmin) {
  112. >               return 1;
  113. >           }
  114. >
  115. >       case 1:
  116. >           if(%this.isAdmin) {
  117. >               return 1;
  118. >           }
  119. >   }
  120. >
  121. >   return 0;
  122. 48,49c86,89
  123. <   $Server::AS::HasAutoLoaded = 1;
  124. <   schedule(5000, 0, Server_AutoloadSave);
  125. ---
  126. >   if($Pref::Server::AS::AutoloadPreviousSave) {
  127. >       $Server::AS::HasAutoLoaded = 1;
  128. >       schedule(5000, 0, LoadAutoSave, "last");
  129. >   }
  130. 54c94,95
  131. <   if(!%this.isSuperAdmin)
  132. ---
  133. >   if(!%this.canAutoSaveBricks()) {
  134. >       %this.play2D(errorSound);
  135. 55a97
  136. >   }
  137. 58a101
  138. >       %this.play2D(errorSound);
  139. 69,71c112,113
  140. < function serverCmdLoadAutoSave(%this, %msg0, %msg1, %msg2, %msg3, %msg4, %msg5, %msg6, %msg7, %msg8, %msg9)
  141. < {
  142. <   if(!%this.isSuperAdmin)
  143. ---
  144. > function serverCmdLoadAutoSave(%this, %msg0, %msg1, %msg2, %msg3, %msg4, %msg5, %msg6, %msg7, %msg8, %msg9) {
  145. >   if(!%this.canAutoSaveBricks())
  146. 74,75c116,123
  147. <   for(%i = 0; %i < 9; %i++)
  148. <       %msg = %msg SPC %msg[%i];
  149. ---
  150. >   if(strstr(%msg0, " ") == -1) {
  151. >       for(%i = 0; %i < 9; %i++)
  152. >           %msg = %msg SPC %msg[%i];
  153. >   } else {
  154. >       // command was triggered via console
  155. >       %msg = %msg0;
  156. >   }
  157. >
  158. 82,84c130,135
  159. <   if(%msg $= "last")
  160. <   {
  161. <       Server_AutoloadSave();
  162. ---
  163. >   LoadAutoSave(%msg);
  164. > }
  165. >
  166. > function LoadAutoSave(%save)
  167. > {
  168. >   if(%save $= "") {
  169. 88c139,147
  170. <   loadAutoSaveBuild(%msg);
  171. ---
  172. >   if(%save $= "last") {
  173. >       if($Pref::Server::AS::LastAutoSave !$= "") {
  174. >           announce("\c5Loading previous autosave...");
  175. >           loadAutoSaveBuild($Pref::Server::AS::LastAutoSave);
  176. >       }
  177. >       return;
  178. >   }
  179. >
  180. >   loadAutoSaveBuild(%save);
  181. 108c167
  182. < function loadAutoSaveBuildPath(%path)
  183. ---
  184. > function loadAutoSaveBuild(%name)
  185. 110,114c169,171
  186. <   if(!isFile(%path))
  187. <   {
  188. <       announce("loadAutoSaveBuildPath() - invalid save file (" @ %path @ ")");
  189. <       return;
  190. <   }
  191. ---
  192. >   //if(%name $= "last") {
  193. >   //  %name = $Pref::Server::AS::LastAutoSave;
  194. >   //}
  195. 116c173,174
  196. <   if(fileExt(%path) !$= ".bls")
  197. ---
  198. >   %path = $Pref::Server::AS::SaveDirectory @ %name @ ".bls";
  199. >   if(!isFile(%path))
  200. 118c176
  201. <       announce("loadAutoSaveBuildPath() - invalid save (" @ %path @ ")");
  202. ---
  203. >       announce("loadAutoSaveBuild() - invalid save (" @ %path @ ")");
  204. 123d180
  205. <
  206. 129c186
  207. <   serverDirectSaveFileLoad(%path, 3, "", 1);
  208. ---
  209. >   serverDirectSaveFileLoad(%path, 3, "", $Pref::Server::AS::LoadOwnership);
  210. 134,139c191,192
  211. < function loadAutoSaveBuild(%name)
  212. < {
  213. <   %path = $Server::AS::dir @ %name @ ".bls";
  214. <   if(!isFile(%path))
  215. <   {
  216. <       announce("loadAutoSaveBuild() - invalid save (" @ %path @ ")");
  217. ---
  218. > function scheduleNextSave(%diff) {
  219. >   if($Pref::Server::AS::SavingInterval <= 0) {
  220. 143,151c196,202
  221. <   cancel($Server_AS_schedule);
  222. <   //Put it as a temp file in case they have to reload it
  223. <   WriteFromToFile(%path, "base/server/temp/temp.bls");
  224. <  
  225. <   %quotaObj = getCurrentQuotaObject();
  226. <   clearCurrentQuotaObject();
  227. <   serverDirectSaveFileLoad(%path, 3, "", 1);
  228. <   if(isObject(%quotaObj))
  229. <       setCurrentQuotaObject(%quotaObj);
  230. ---
  231. >   %next_time = mFloor($Pref::Server::AS::SavingInterval * 60000 - %diff);
  232. >   if(%next_time < 60000)
  233. >       %next_time = 60000;
  234. >
  235. >   if(!isEventPending($Server_AS_schedule)) {
  236. >       $Server_AS_schedule = schedule(%next_time, 0, Server_AS1_begin);
  237. >   }
  238. 162c213
  239. <   if($Server::AS::saveOwnership)
  240. ---
  241. >   if($Pref::Server::AS::SaveOwnership)
  242. 164c215
  243. <   if($Server::AS::saveEvents)
  244. ---
  245. >   if($Pref::Server::AS::SaveEvents)
  246. 171c222,224
  247. <       $Server_AS_schedule = schedule($Server::AS::interval * 60 * 1000, 0, Server_AS1_begin);
  248. ---
  249. >       if($Pref::Server::AS::SavingInterval > 0) {
  250. >           $Server_AS_schedule = schedule($Pref::Server::AS::SavingInterval * 60 * 1000, 0, Server_AS1_begin);
  251. >       }
  252. 177c230
  253. <   if($Server::AS::announce)
  254. ---
  255. >   if($Pref::Server::AS::Announce)
  256. 179,180c232,233
  257. <       %eventMsg = ($Server::AS::saveEvents ? "\c6[\c4Events\c6]" : "");
  258. <       %ownerMsg = ($Server::AS::saveOwnership ? "\c6[\c4Ownership\c6]" : "");
  259. ---
  260. >       %eventMsg = ($Pref::Server::AS::SaveEvents ? "\c6[\c4Events\c6]" : "");
  261. >       %ownerMsg = ($Pref::Server::AS::SaveOwnership ? "\c6[\c4Ownership\c6]" : "");
  262. 184c237
  263. <   $time_beg = getSimTime();
  264. ---
  265. >   $time_beg = $Sim::Time;
  266. 186c239
  267. <   %dir = $Server::AS::dir;
  268. ---
  269. >   %dir = $Pref::Server::AS::SaveDirectory;
  270. 195,198c248,253
  271. <       %g = mainBrickGroup.getObject(%i);
  272. <       %b = %g.getCount();
  273. <       $Server::AS::state = "B: begin collecting groups (group "@ %g @")";
  274. <       if(%b > 0)
  275. ---
  276. >       // %g == %brickGroup
  277. >       // %brickCount = %g.getCount()
  278. >       %brickGroup = mainBrickGroup.getObject(%i);
  279. >       %count = %brickGroup.getCount();
  280. >       $Server::AS::state = "B: begin collecting groups (group "@ %brickGroup @")";
  281. >       if(%count > 0)
  282. 200,201c255,256
  283. <           %g.Server_AS_stop = %b;
  284. <           $Server::AS_groups::group[$Server::AS_groups::group_count] = %g;
  285. ---
  286. >           %brickGroup.Server_AS_stop = %count;
  287. >           $Server::AS_groups::group[$Server::AS_groups::group_count] = %brickGroup;
  288. 208,209c263
  289. <   if(isObject($Server::AS1::FO))
  290. <   {
  291. ---
  292. >   if(isObject($Server::AS1::FO)) {
  293. 211c265,266
  294. <       $Server::AS1::FO.delete();
  295. ---
  296. >   } else {
  297. >       $Server::AS1::FO = new FileObject();
  298. 214d268
  299. <   $Server::AS1::FO = new FileObject();
  300. 226,229d279
  301. <       $Server::AS1::FO.delete();
  302. <
  303. <       if($Server::AS::interval < 5)
  304. <           $Server::AS::interval = 1;
  305. 231,232c281
  306. <       if($Server::AS::interval > 16)
  307. <           $Server::AS::interval = 16;
  308. ---
  309. >       %diff = $Sim::Time - $time_beg;
  310. 234,236c283
  311. <       %diff = (getSimTime() - $time_beg);
  312. <
  313. <       if($Server::AS::announce)
  314. ---
  315. >       if($Pref::Server::AS::Announce)
  316. 242,247c289
  317. <       %next_time = 60 * 1000 - %diff;
  318. <       %next_time = $Server::AS::interval * 60 * 1000 - %diff;
  319. <       if(%next_time < 60000)
  320. <           %next_time = $Server::AS::interval * 60 * 1000;
  321. <
  322. <       $Server_AS_schedule = schedule(%next_time, 0, Server_AS1_begin);
  323. ---
  324. >       scheduleNextSave(%diff*1000);
  325. 251c293
  326. < function Server_AS1_nextGroup(%f)
  327. ---
  328. > function Server_AS1_nextGroup()
  329. 252a295,296
  330. >   %file = $Server::AS1::FO;
  331. >
  332. 257c301
  333. <       return Server_AS1_end(%f);
  334. ---
  335. >       return Server_AS1_end();
  336. 259c303
  337. <   %g = $Server::AS_groups::group[$Server::AS_groups::cur_group];
  338. ---
  339. >   %brickGroup = $Server::AS_groups::group[$Server::AS_groups::cur_group];
  340. 261c305
  341. <   Server_AS1_nextBrick(%f, %g, 0);
  342. ---
  343. >   Server_AS1_nextBrick(%brickGroup, 0);
  344. 264c308,311
  345. < function Server_AS1_nextBrick(%f, %g, %c)
  346. ---
  347. > // please quit using single letter variables, they don't speed things up, nor do they slow things down, it just confuses everyone
  348. > // - TBP
  349. >
  350. > function Server_AS1_nextBrick(%brickGroup, %current)
  351. 266,267c313,318
  352. <   if(%c >= %g.getCount())
  353. <       return Server_AS1_nextGroup(%f);
  354. ---
  355. >   %file = $Server::AS1::FO;
  356. >
  357. >   if(%current >= %brickGroup.getCount())
  358. >       return Server_AS1_nextGroup();
  359. >
  360. >   %brick = %brickGroup.getObject(%current);
  361. 269c320
  362. <   if(%g.getObject(%c).isPlanted)
  363. ---
  364. >   if(%brick.isPlanted)
  365. 271c322
  366. <       %f.writeLine(%g.getObject(%c).getID());
  367. ---
  368. >       %file.writeLine(%brick.getID());
  369. 274,281d324
  370. <   else if(isObject(%g.getObject(%c)))
  371. <   {
  372. <       %del = 1;
  373. <       for(%i=0;%i<clientgroup.getCount();%i++)
  374. <       {
  375. <           if(clientgroup.getObject(%i).player.tempBrick == %g.getObject(%c))
  376. <               %del = 0;
  377. <       }
  378. 283,287c326
  379. <       if(%del) //This helps delete unwanted temp bricks that don't belong to anyone
  380. <           %g.getObject(%c).delete();
  381. <   }
  382. <
  383. <   schedule(0, 0, Server_AS1_nextBrick, %f, %g, %c+1);
  384. ---
  385. >   schedule(0, 0, Server_AS1_nextBrick, %brickGroup, %current+1);
  386. 290c329
  387. < function Server_AS1_end(%f)
  388. ---
  389. > function Server_AS1_end()
  390. 292,293c331
  391. <   %f.close();
  392. <   %f.delete();
  393. ---
  394. >   $Server::AS1::FO.close();
  395. 304c342
  396. <   %dir = $Server::AS::dir;
  397. ---
  398. >   %dir = $Pref::Server::AS::SaveDirectory;
  399. 321,322c359,363
  400. <   $Server::AS::TempA.path = %dir @ "SAVETEMP_1.bls";
  401. <   $Server::AS::TempB.path = %dir @ "SAVETEMP_2.bls";
  402. ---
  403. >   %fileA = $Server::AS::TempA;
  404. >   %fileB = $Server::AS::TempB;
  405. >
  406. >   %fileA.path = %dir @ "SAVETEMP_1.bls";
  407. >   %fileB.path = %dir @ "SAVETEMP_2.bls";
  408. 324,327c365,368
  409. <   $Server::AS::TempB.openForWrite($Server::AS::TempB.path);
  410. <   $Server::AS::TempB.writeLine("This is a Blockland save file.  You probably shouldn't modify it cause you'll mess it up.");
  411. <   $Server::AS::TempB.writeLine("1");
  412. <   $Server::AS::TempB.writeLine(%desc);
  413. ---
  414. >   %fileB.openForWrite(%fileb.path);
  415. >   %fileB.writeLine("This is a Blockland save file.  You probably shouldn't modify it cause you'll mess it up.");
  416. >   %fileB.writeLine("1");
  417. >   %fileB.writeLine("Autosaved at" SPC getDateTime() SPC "on" SPC $Server::Name);
  418. 330c371
  419. <       $Server::AS::TempB.writeLine(getColorIDTable(%i));
  420. ---
  421. >       %fileB.writeLine(getColorIDTable(%i));
  422. 332c373
  423. <   $Server::AS::TempB.writeLine("Linecount "@ $Server::AS_groups::brick_count);
  424. ---
  425. >   %fileB.writeLine("Linecount "@ $Server::AS_groups::brick_count);
  426. 336,337c377,378
  427. <   $Server::AS::TempA.openForRead($Server::AS::TempA.path);
  428. <   Server_AS2_nextLine($Server::AS::TempA, $Server::AS::TempB);
  429. ---
  430. >   %fileA.openForRead(%fileA.path);
  431. >   Server_AS2_nextLine();
  432. 340c381
  433. < function Server_AS2_nextLine(%f_A, %f_B, %c)
  434. ---
  435. > function Server_AS2_nextLine(%fileA, %fileB, %c)
  436. 341a383,385
  437. >   %fileA = $Server::AS::TempA;
  438. >   %fileB = $Server::AS::TempB;
  439. >
  440. 343,344d386
  441. <   %events = $Server::AS::saveEvents;
  442. <   %ownership = $Server::AS::saveOwnership;
  443. 346c388
  444. <   if(!%f_A.isEOF())
  445. ---
  446. >   if(!%fileA.isEOF())
  447. 348c390
  448. <       %brick = %f_A.readLine();
  449. ---
  450. >       %brick = %fileA.readLine();
  451. 362c404
  452. <           %f_B.writeLine(%brick.getDataBlock().uiName @ "\" " @ %brick.getPosition() SPC %brick.getAngleID() SPC %brick.isBasePlate() SPC %brick.getColorID()
  453. ---
  454. >           %fileB.writeLine(%brick.getDataBlock().uiName @ "\" " @ %brick.getPosition() SPC %brick.getAngleID() SPC %brick.isBasePlate() SPC %brick.getColorID()
  455. 365,366c407,408
  456. <           if(%ownership && !$Server::LAN)
  457. <               %f_B.writeLine("+-OWNER " @ getBrickGroupFromObject(%brick).bl_id);
  458. ---
  459. >           if($Pref::Server::AS::SaveOwnership && !$Server::LAN)
  460. >               %fileB.writeLine("+-OWNER " @ getBrickGroupFromObject(%brick).bl_id);
  461. 368c410
  462. <           if(%events)
  463. ---
  464. >           if($Pref::Server::AS::SaveEvents)
  465. 371c413
  466. <                   %f_B.writeLine("+-NTOBJECTNAME " @ %brick.getName());
  467. ---
  468. >                   %fileB.writeLine("+-NTOBJECTNAME " @ %brick.getName());
  469. 373c415,416
  470. <               for(%b = 0; %b < %brick.numEvents; %b++)
  471. ---
  472. >               // %b = %eventNum
  473. >               for(%eventNum = 0; %eventNum < %brick.numEvents; %eventNum++)
  474. 376,377c419,420
  475. <                   %targetClass = %brick.eventTargetIdx[%b] >= 0 ? getWord(getField($InputEvent_TargetListfxDTSBrick_[%brick.eventInputIdx[%b]], %brick.eventTargetIdx[%b]), 1) : "fxDtsBrick";
  476. <                   %paramList = $OutputEvent_parameterList[%targetClass, %brick.eventOutputIdx[%b]];
  477. ---
  478. >                   %targetClass = %brick.eventTargetIdx[%eventNum] >= 0 ? getWord(getField($InputEvent_TargetListfxDTSBrick_[%brick.eventInputIdx[%eventNum]], %brick.eventTargetIdx[%eventNum]), 1) : "fxDtsBrick";
  479. >                   %paramList = $OutputEvent_parameterList[%targetClass, %brick.eventOutputIdx[%eventNum]];
  480. 379c422,423
  481. <                   for(%c = 0; %c < 4; %c++)
  482. ---
  483. >                   // %c = %paramNum
  484. >                   for(%paramNum = 0; %paramNum < 4; %paramNum++)
  485. 381,384c425,429
  486. <                       if(firstWord(getField(%paramList, %c)) $= "dataBlock" && isObject(%brick.eventOutputParameter[%b, %c + 1]))
  487. <                           %params = %params TAB %brick.eventOutputParameter[%b, %c + 1];
  488. <                       else
  489. <                           %params = %params TAB %brick.eventOutputParameter[%b, %c + 1];
  490. ---
  491. >                       if(%params $= "") {
  492. >                           %params = %brick.eventOutputParameter[%eventNum, %paramNum + 1];
  493. >                       } else {
  494. >                           %params = %params TAB %brick.eventOutputParameter[%eventNum, %paramNum + 1];
  495. >                       }
  496. 386,387c431,432
  497. <                   %f_B.writeLine("+-EVENT" TAB %b TAB %brick.eventEnabled[%b] TAB %brick.eventInput[%b] TAB %brick.eventDelay[%b] TAB %brick.eventTarget[%b]
  498. <                       TAB %brick.eventNT[%b] TAB %brick.eventOutput[%b] @ %params);
  499. ---
  500. >                   %fileB.writeLine("+-EVENT" TAB %eventNum TAB %brick.eventEnabled[%eventNum] TAB %brick.eventInput[%eventNum] TAB %brick.eventDelay[%eventNum] TAB %brick.eventTarget[%eventNum]
  501. >                       TAB %brick.eventNT[%eventNum] TAB %brick.eventOutput[%eventNum] TAB %params);
  502. 392c437
  503. <               %f_B.writeLine("+-EMITTER " @ %brick.emitter.emitter.uiName @ "\" " @ %brick.emitterDirection);
  504. ---
  505. >               %fileB.writeLine("+-EMITTER " @ %brick.emitter.emitter.uiName @ "\" " @ %brick.emitterDirection);
  506. 395c440
  507. <               %f_B.writeLine("+-LIGHT " @ %brick.getLightID().getDataBlock().uiName @ "\" "); // Not sure if something else comes after the name
  508. ---
  509. >               %fileB.writeLine("+-LIGHT " @ %brick.getLightID().getDataBlock().uiName @ "\" "); // Not sure if something else comes after the name
  510. 398c443
  511. <               %f_B.writeLine("+-ITEM " @ %brick.item.getDataBlock().uiName @ "\" " @ %brick.itemPosition SPC %brick.itemDirection SPC %brick.itemRespawnTime);
  512. ---
  513. >               %fileB.writeLine("+-ITEM " @ %brick.item.getDataBlock().uiName @ "\" " @ %brick.itemPosition SPC %brick.itemDirection SPC %brick.itemRespawnTime);
  514. 401c446
  515. <               %f_B.writeLine("+-AUDIOEMITTER " @ %brick.audioEmitter.getProfileID().uiName @ "\" "); // Not sure if something else comes after the name
  516. ---
  517. >               %fileB.writeLine("+-AUDIOEMITTER " @ %brick.audioEmitter.getProfileID().uiName @ "\" "); // Not sure if something else comes after the name
  518. 404c449
  519. <               %f_B.writeLine("+-VEHICLE " @ %brick.vehicleSpawnMarker.uiName @ "\" " @ %brick.reColorVehicle);
  520. ---
  521. >               %fileB.writeLine("+-VEHICLE " @ %brick.vehicleSpawnMarker.uiName @ "\" " @ %brick.reColorVehicle);
  522. 407c452
  523. <       return schedule(0, 0, Server_AS2_nextLine, %f_A, %f_B, %c);
  524. ---
  525. >       return schedule(0, 0, Server_AS2_nextLine, %c);
  526. 414c459
  527. <       Server_AS2_end(%f_A, %f_B);
  528. ---
  529. >       Server_AS2_end();
  530. 418c463
  531. < function Server_AS2_end(%f_A, %f_B)
  532. ---
  533. > function Server_AS2_end()
  534. 420,422c465,470
  535. <   %f_A.close();
  536. <   %f_B.close();
  537. <   %dir = $Server::AS::dir;
  538. ---
  539. >   %fileA = $Server::AS::TempA;
  540. >   %fileB = $Server::AS::TempB;
  541. >
  542. >   %fileA.close();
  543. >   %fileB.close();
  544. >   %dir = $Pref::Server::AS::SaveDirectory;
  545. 427,439c475,487
  546. <   %save_time = mFloatLength(getSubStr(getWord(getDateTime(), 1), 0, 2), 0);
  547. <   %s = "AM";
  548. <   %timeS = %save_time;
  549. <   if(%timeS == 0)
  550. <       %timeS = 1;
  551. <   if(%save_time >= 12)
  552. <   {
  553. <       %timeS = %save_time - 12;
  554. <       %s = "PM";
  555. <       if(%timeS == 12)
  556. <       {
  557. <           %timeS = 12;
  558. <           %s = "AM";
  559. ---
  560. >   %timeString = strReplace(getWord(%date, 1), ":", ".");
  561. >   if($Pref::Server::AS::Use12HourTime) {
  562. >       %hour = mFloatLength(getSubStr(getWord(getDateTime(), 1), 0, 2), 0);
  563. >       // i just dropped your original 24h --> 12h script, i was essentially rewriting it
  564. >       // - TBP
  565. >       if(%hour < 12) {
  566. >           %suffix = "AM";
  567. >       }
  568. >       if(%hour >= 12) {
  569. >           %suffix = "PM";
  570. >           if(%hour > 12) {
  571. >               %hour -= 12;
  572. >           }
  573. 440a489
  574. >       %timeString = %hour @ strReplace(getSubStr(getWord(%date, 1), 2, strLen(%date)), ":", ".") @ %suffix;
  575. 442d490
  576. <   %timeS = %timeS @ strReplace(getSubStr(getWord(getDateTime(), 1), 2, 3), ":", ".") @ %s;
  577. 444,447c492,498
  578. <   $Server::AS::RelatedBrickCount = 0;
  579. <   if($Server::AS::Pref["LastBrickCount"] == $Server::AS_groups::brick_count && $Server::AS::Pref["LastEventCount"] == $Server::AS_groups::event_count)
  580. <       $Server::AS::RelatedBrickCount = 1;
  581. <   else
  582. ---
  583. >   %countMismatch = 0;
  584. >   if($Pref::Server::AS::LastBrickCount == $Server::AS_groups::brick_count)
  585. >       %countMismatch = 1;
  586. >   if($Pref::Server::AS::SaveEvents && $Pref::Server::AS::LastEventCount != $Server::AS_groups::event_count)
  587. >       %countMismatch = 0;
  588. >
  589. >   if(!%countMismatch)
  590. 449,450c500,501
  591. <       $Server::AS::Pref["LastEventCount"] = $Server::AS_groups::event_count;
  592. <       $Server::AS::Pref["LastBrickCount"] = $Server::AS_groups::brick_count;
  593. ---
  594. >       $Pref::Server::AS::LastEventCount = $Server::AS_groups::event_count;
  595. >       $Pref::Server::AS::LastBrickCount = $Server::AS_groups::brick_count;
  596. 453c504
  597. <   if(!$Server::AS::RelatedBrickCount && !$Server::AS::SaveRelatedBrickcount)
  598. ---
  599. >   if(!%countMismatch && !$Pref::Server::AS::SaveEvenIfSame)
  600. 455,457c506,508
  601. <       %direc = %dir @ "Autosave " @ getWord(%date, 0) @ " at " @ %timeS @ ".bls";
  602. <       if(isFile(%direc)) //Overwrite it, just delete it for sure
  603. <           fileDelete(%direc);
  604. ---
  605. >       %filename = %dir @ "Autosave " @ getWord(%date, 0) @ " at " @ %timeString @ ".bls";
  606. >       if(isFile(%filename)) //Overwrite it, just delete it for sure
  607. >           fileDelete(%filename);
  608. 459c510
  609. <       fileCopy(%f_B.path, %direc);
  610. ---
  611. >       fileCopy(%fileB.path, %filename);
  612. 461c512
  613. <   else if($Server::AS::SaveRelatedBrickcount)
  614. ---
  615. >   else if($Pref::Server::AS::SaveEvenIfSame)
  616. 463,465c514,516
  617. <       %direc = %dir @ "Autosave " @ getWord(%date, 0) @ " at " @ %timeS @ ".bls";
  618. <       if(isFile(%direc)) //Overwrite it, just delete it for sure
  619. <           fileDelete(%direc);
  620. ---
  621. >       %filename = %dir @ "Autosave " @ getWord(%date, 0) @ " at " @ %timeString @ ".bls";
  622. >       if(isFile(%filename)) //Overwrite it, just delete it for sure
  623. >           fileDelete(%filename);
  624. 467c518
  625. <       fileCopy(%f_B.path, %direc);
  626. ---
  627. >       fileCopy(%fileB.path, %filename);
  628. 470,471c521,523
  629. <   if($Server::AS::overwriteSave)
  630. <       fileCopy(%f_B.path, "base/server/temp/temp.bls");
  631. ---
  632. >   // so far this is the only thing i'm happy you did, viso
  633. >   if($Pref::Server::AS::AllowOverwriting)
  634. >       fileCopy(%fileB.path, "base/server/temp/temp.bls");
  635. 473,474c525,526
  636. <   fileDelete(%f_A.path);
  637. <   fileDelete(%f_B.path);
  638. ---
  639. >   fileDelete(%fileA.path);
  640. >   fileDelete(%fileB.path);
  641. 476,477c528,529
  642. <   %f_A.delete();
  643. <   %f_B.delete();
  644. ---
  645. >   %fileA.delete();
  646. >   %fileB.delete();
  647. 481,493c533,544
  648. <   if($Server::AS::interval < 5)
  649. <       $Server::AS::interval = 1;
  650. <
  651. <   if($Server::AS::interval > 16)
  652. <       $Server::AS::interval = 16;
  653. <
  654. <   %diff = (getSimTime() - $time_beg);
  655. <   %time = %diff / 1000;
  656. <   %msg = "in \c6"@ mFloatLength(%time, 2) @" \c5second" @ (%time == 1 ? "" : "s");
  657. <   if(%time < 1)
  658. <       %msg = "\c6instantly";
  659. <
  660. <   %bGroups = $Server::AS_groups::cur_group;
  661. ---
  662. >   %diff = $Sim::Time - $time_beg;
  663. >   %msg = "in \c5"@ getTimeString(mFloatLength(%diff, 2));
  664. >   // not really instantly
  665. >   // if(%time < 1)
  666. >   // %msg = "\c6instantly";
  667. >
  668. >   %brickGroups = $Server::AS_groups::cur_group;
  669. >
  670. >   if(!%countMismatch && !$Pref::Server::AS::SaveEvenIfSame)
  671. >       $Pref::Server::AS::LastAutoSave = fileBase(%filename);
  672. >   else if($Pref::Server::AS::SaveEvenIfSame)
  673. >       $Pref::Server::AS::LastAutoSave = fileBase(%filename);
  674. 495,500c546
  675. <   if(!$Server::AS::RelatedBrickCount && !$Server::AS::SaveRelatedBrickcount)
  676. <       $Server::AS::Pref["LastAutoSave"] = fileBase(%direc);
  677. <   else if($Server::AS::SaveRelatedBrickcount)
  678. <       $Server::AS::Pref["LastAutoSave"] = fileBase(%direc);
  679. <
  680. <   if($Server::AS::announce)
  681. ---
  682. >   if($Pref::Server::AS::Announce)
  683. 502c548
  684. <       if($Server::AS::RelatedBrickCount && !$Server::AS::SaveRelatedBrickcount)
  685. ---
  686. >       if(%countMismatch && !$Pref::Server::AS::SaveEvenIfSame) {
  687. 503a550
  688. >       }
  689. 506,507c553,554
  690. <           if($Server::AS::announceSaveName)
  691. <               %saveMsg = " Saved as \c6" @ $Server::AS::Pref["LastAutoSave"] @ "\c5.";
  692. ---
  693. >           if($Pref::Server::AS::AnnounceSaveName)
  694. >               %saveMsg = " Saved as \c6" @ $Pref::Server::AS::LastAutoSave @ "\c5.";
  695. 512c559
  696. <           if($Server::AS::report)
  697. ---
  698. >           if($Pref::Server::AS::DetailedReport)
  699. 514c561
  700. <                   " \c5and \c6" @ %bGroups @ " group" @ (%bGroups == 1 ? "" : "s") @ " \c5have been saved.");
  701. ---
  702. >                   " \c5and \c6" @ %brickGroups @ " group" @ (%brickGroups == 1 ? "" : "s") @ " \c5have been saved.");
  703. 518c565
  704. <   if($Server::AS::RelatedBrickCount && !$Server::AS::SaveRelatedBrickcount)
  705. ---
  706. >   if(%countMismatch && !$Pref::Server::AS::SaveEvenIfSame)
  707. 521c568
  708. <       echo("[AutoSaver] - Autosaved " @ $Server::AS_groups::brick_count @ " bricks " @ %msg @ ". Saved as " @ $Server::AS::Pref["LastAutoSave"] @ ".");
  709. ---
  710. >       echo("[AutoSaver] - Autosaved " @ $Server::AS_groups::brick_count @ " bricks " @ %msg @ ". Saved as " @ $Pref::Server::AS::LastAutoSave @ ".");
  711. 523c570
  712. <   if($Server::AS::report)
  713. ---
  714. >   if($Pref::Server::AS::DetailedReport)
  715. 525c572
  716. <       if(!$Server::AS::RelatedBrickCount)
  717. ---
  718. >       if(!%countMismatch)
  719. 527c574
  720. <               " and " @ %bGroups @ " group" @ (%bGroups == 1 ? "" : "s") @ ".");
  721. ---
  722. >               " and " @ %brickGroups @ " group" @ (%brickGroups == 1 ? "" : "s") @ ".");
  723. 530c577,578
  724. <   export("$Server::AS::Pref*", "config/server/AutoSaver.cs");
  725. ---
  726. >   // since you're so paranoid
  727. >   export("$Pref::Server::AS*", "config/server/AutoSaver.prefs.cs");
  728. 532,535c580
  729. <   %next_time = 60 * 1000 - %diff;
  730. <   %next_time = $Server::AS::interval * 60 * 1000 - %diff;
  731. <   if(%next_time < 60000)
  732. <       %next_time = $Server::AS::interval * 60 * 1000;
  733. ---
  734. >   scheduleNextSave(%diff*1000);
  735. 537c582
  736. <   $Server_AS_schedule = schedule(%next_time, 0, Server_AS1_begin);
  737. ---
  738. >   discoverFile(%filename);
  739. 540,541c585,593
  740. < cancel($Server_AS_schedule);
  741. < $Server_AS_schedule = schedule($Server::AS::interval * 60 * 1000, 0, Server_AS1_begin);
  742. \ No newline at end of file
  743. ---
  744. > scheduleNextSave(0);
  745. >
  746. > package AutoSaverPackage {
  747. >   function onServerDestroyed() {
  748. >       $Server::AS::HasAutoLoaded = 0;
  749. >       return parent::onServerDestroyed();
  750. >   }
  751. > };
  752. > activatePackage(AutoSaverPackage);
  753. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement