PageRenderTime 203ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 1ms

/epoch_3/php/WW2/scripts/resetscript.php

https://github.com/Naddiseo/WW2Game
PHP | 353 lines | 257 code | 36 blank | 60 comment | 3 complexity | 4aa804676b29d5a0d9f93e3ffab3572f MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0
  1. <?
  2. /***
  3. World War II MMORPG
  4. Copyright (C) 2009-2010 Richard Eames
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ***/
  16. /** Changelog
  17. 29th May, 10 Update for age 18
  18. 24th Apr, 10 Update for age 17
  19. ---- Mar, 10
  20. 26th Feb, 10 Update for age 15 added area stuff to hof
  21. 26th Dec, 09 Update for age 14
  22. 28th Nov, 09 Update for age 13
  23. 1st Nov, 09. Update for age 12
  24. 28th Sept, 09. Update for age 11
  25. 30th Aug, 09. Update for age 10
  26. 26th July, 09. Update for age 9 or eight...
  27. 28th June, 09. Ran for age 7. User.sflevel -> User.ralevel
  28. 24th June, 09 - click -> Recruit, hof.race -> hof.nation
  29. 23rd June, 09 (pre age 8, initial)
  30. */
  31. /*
  32. // move top 30 up from area 2->1
  33. update User set area=4 where area=2 and rank <=30 and rank >=1 and active=1;
  34. // move top 60 up from area 2->2
  35. update User set area=5 where area=3 and rank <= 60 and rank >= 1 and active=1;
  36. //move bottom 60 down from area 2->3
  37. update User set area=6 where area=2 and rank >= 181 and rank <= 240 and active=1;
  38. update User set area=1 where area=4;
  39. update User set area=2 where area=5;
  40. update User set area=3 where area=6;
  41. */
  42. // First, tell all the scripts that we're running without HTML
  43. $incron = true;
  44. // Include everything we need
  45. require_once('vsys.php');
  46. $hof = $_AGE;
  47. die("MAKE SURE THE AGE IS CORRECT");
  48. /*
  49. Stage 1 : Back up the tables
  50. */
  51. // A list of tables that we'll use, so need to back up
  52. $tableList = array(
  53. 'BattleLog',
  54. 'SpyLog',
  55. 'User',
  56. 'Weapon'
  57. );
  58. foreach ($tableList as $table) {
  59. // Copy the tables
  60. echo "resetscript: dropping $table$hof if exists\n";
  61. @mysql_query("drop table if exists hof$hof");
  62. echo "resetscript: backing up table $table as $table$hof\n";
  63. $q = mysql_query("CREATE TABLE IF NOT EXISTS $table$hof SELECT * FROM $table") or die(mysql_error());
  64. }
  65. // TODO: update for table column names.
  66. // create the new HOF table
  67. $hofTable = "CREATE TABLE IF NOT EXISTS `hof{$hof}` (
  68. `id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
  69. `uid` INT(10) NOT NULL DEFAULT 0,
  70. `area` TINYINT(2) NOT NULL DEFAULT 2,
  71. `username` VARCHAR( 50 ) NOT NULL ,
  72. `alliance` VARCHAR( 50 ) DEFAULT 0,
  73. `nation` SMALLINT( 1 ) NOT NULL DEFAULT 0,
  74. `bankper` TINYINT( 2 ) NOT NULL DEFAULT 0,
  75. `officerup` INT( 10 ) NOT NULL DEFAULT 0,
  76. `untrained` INT( 11 ) NOT NULL DEFAULT 0,
  77. `trainedsa` INT( 11 ) NOT NULL DEFAULT 0,
  78. `trainedda` INT( 11 ) NOT NULL DEFAULT 0,
  79. `samerc` INT( 11 ) NOT NULL DEFAULT 0,
  80. `damerc` INT( 11 ) NOT NULL DEFAULT 0,
  81. `spies` INT( 11 ) NOT NULL DEFAULT 0,
  82. `sf` INT( 11 ) NOT NULL DEFAULT 0,
  83. `raupgrade` INT( 2 ) NOT NULL DEFAULT 0,
  84. `saupgrade` INT( 2 ) NOT NULL DEFAULT 0,
  85. `daupgrade` INT( 2 ) NOT NULL DEFAULT 0,
  86. `caupgrade` INT( 2 ) NOT NULL DEFAULT 0,
  87. `sa` BIGINT( 15 ) NOT NULL DEFAULT 0,
  88. `da` BIGINT( 15 ) NOT NULL DEFAULT 0,
  89. `ca` BIGINT( 15 ) NOT NULL DEFAULT 0,
  90. `ra` BIGINT( 15 ) NOT NULL DEFAULT 0,
  91. `sarank` INT( 11 ) NOT NULL DEFAULT 0,
  92. `darank` INT( 11 ) NOT NULL DEFAULT 0,
  93. `carank` INT( 11 ) NOT NULL DEFAULT 0,
  94. `rarank` INT( 11 ) NOT NULL DEFAULT 0,
  95. `goldwon` BIGINT( 15 ) NOT NULL DEFAULT 0,
  96. `goldlost` BIGINT( 15 ) NOT NULL DEFAULT 0,
  97. `battleswon` BIGINT( 15 ) NOT NULL DEFAULT 0,
  98. `battleslost` BIGINT( 15 ) NOT NULL DEFAULT 0,
  99. `battlesdefended` BIGINT( 15 ) NOT NULL DEFAULT 0,
  100. `battlesuuwon` BIGINT(15) NOT NULL DEFAULT 0,
  101. `battlesuulost` BIGINT(15) NOT NULL DEFAULT 0,
  102. `theftscore` BIGINT( 15 ) NOT NULL DEFAULT 0,
  103. `theftuu` BIGINT( 15 ) NOT NULL DEFAULT 0,
  104. `theftgold` BIGINT( 15 ) NOT NULL DEFAULT 0,
  105. `up` INT( 11 ) NOT NULL DEFAULT 0,
  106. `income` INT( 11 ) NOT NULL DEFAULT 0,
  107. `numofficers` INT( 11 ) NOT NULL DEFAULT 0,
  108. PRIMARY KEY ( `ID` ),
  109. UNIQUE (
  110. `username`
  111. )
  112. ) TYPE = MYISAM ;";
  113. mysql_query($hofTable) or die("2:".mysql_error());
  114. mysql_query("truncate hof$hof") or die(mysql_error());
  115. echo "resetscript: inserting primary values into hof$hof\n";
  116. // insert the basic values
  117. $hofq = mysql_query("
  118. INSERT INTO
  119. hof$hof
  120. (
  121. uid,
  122. area,
  123. username,
  124. alliance,
  125. nation,
  126. bankper,
  127. officerup,
  128. untrained,
  129. trainedsa,
  130. trainedda,
  131. samerc,
  132. damerc,
  133. spies,
  134. sf,
  135. raupgrade,
  136. saupgrade,
  137. daupgrade,
  138. caupgrade,
  139. sa,
  140. da,
  141. ca,
  142. ra,
  143. sarank,
  144. darank,
  145. carank,
  146. rarank,
  147. up,
  148. numofficers
  149. )
  150. SELECT
  151. id,
  152. area,
  153. username,
  154. alliance,
  155. nation,
  156. bankper,
  157. officerup,
  158. uu,
  159. sasoldiers,
  160. dasoldiers,
  161. samercs,
  162. damercs,
  163. spies,
  164. specialforces,
  165. ralevel,
  166. salevel,
  167. dalevel,
  168. calevel,
  169. sa,
  170. da,
  171. ca,
  172. ra,
  173. sarank,
  174. darank,
  175. carank,
  176. rarank,
  177. up,
  178. numofficers
  179. FROM
  180. User
  181. WHERE
  182. active = 1;
  183. ") or die("1:".mysql_error());
  184. $users = User::getActiveUsers(false, false);
  185. $nusers = count($users);
  186. $i = 0;
  187. foreach($users as $user) {
  188. echo "resetscript: (" . round(($i / $nusers)*100, 2) . "%) calculating user ($user->id:$user->username)\n";
  189. $i++;
  190. $ret = null;
  191. $q = mysql_query("select sum(goldStolen) as retCode from BattleLog where attackerId = $user->id") or die(mysql_error());
  192. $a = mysql_fetch_object($q);
  193. $ret->goldTaken = (float)$a->retCode;
  194. $q = mysql_query("select sum(goldStolen) as retCode from BattleLog where targetId = $user->id") or die(mysql_error());
  195. $a = mysql_fetch_object($q);
  196. $ret->goldLost = (float)$a->retCode;
  197. $q = mysql_query("select count(*) as retCode from BattleLog where isSuccess = 1 and attackerId = $user->id") or die(mysql_error());
  198. $a = mysql_fetch_object($q);
  199. $ret->battlesWon = (float)$a->retCode;
  200. $q = mysql_query("select count(*) as retCode from BattleLog where isSuccess = 1 and targetId = $user->id") or die(mysql_error());
  201. $a = mysql_fetch_object($q);
  202. $ret->battlesDefended = (float)$a->retCode;
  203. $q = mysql_query("select count(*) as retCode from BattleLog where isSuccess = 0 and attackerId = $user->id") or die(mysql_error());
  204. $a = mysql_fetch_object($q);
  205. $ret->battlesLost = (float)$a->retCode;
  206. $q = mysql_query("select count(*) as retCode from BattleLog where isSuccess = 0 and targetId = $user->id") or die(mysql_error());
  207. $a = mysql_fetch_object($q);
  208. $ret->battlesNotDefended = (float)$a->retCode;
  209. $q = mysql_query("select sum(attackerHostages) as retCode from BattleLog where attackerId = $user->id") or die(mysql_error());
  210. $a = mysql_fetch_object($q);
  211. $ret->powTaken = (float)$a->retCode;
  212. $q = mysql_query("select sum(targetHostages) as retCode from BattleLog where targetId = $user->id") or die(mysql_error());
  213. $a = mysql_fetch_object($q);
  214. $ret->powTaken += (float)$a->retCode;
  215. $q = mysql_query("select sum(attackerHostages) as retCode from BattleLog where targetId = $user->id") or die(mysql_error());
  216. $a = mysql_fetch_object($q);
  217. $ret->powLost = (float)$a->retCode;
  218. $q = mysql_query("select sum(targetHostages) as retCode from BattleLog where attackerId = $user->id") or die(mysql_error());
  219. $a = mysql_fetch_object($q);
  220. $ret->powLost += (float)$a->retCode;
  221. $ret->income = $user->getIncome();
  222. $ret->theftScore = 0;
  223. $q = mysql_query("select * from SpyLog where type=1 and attackerId = $user->id and isSuccess = 1 and weaponamount > 0") or die(mysql_error());
  224. while ($r = mysql_fetch_object($q)) {
  225. $ret->theftScore += ($r->weaponamount * $conf['weapon' . $r->weapontype2 . 'strength']);
  226. }
  227. $q = mysql_query("select sum(goldStolen) as retCode from SpyLog where type=2 and attackerId = $user->id") or die(mysql_error());
  228. $a = mysql_fetch_object($q);
  229. $ret->theftGold = (float)$a->retCode;
  230. $q = mysql_query("select sum(hostages) as retCode from SpyLog where type > 0 and attackerId = $user->id") or die(mysql_error());
  231. $a = mysql_fetch_object($q);
  232. $ret->theftUU = (float)$a->retCode;
  233. $sql = "
  234. update hof$hof
  235. set
  236. goldwon = $ret->goldTaken,
  237. goldlost = $ret->goldLost,
  238. battleswon = $ret->battlesWon,
  239. battleslost = $ret->battlesLost,
  240. battlesdefended = $ret->battlesDefended,
  241. battlesuuwon = $ret->powTaken,
  242. battlesuulost = $ret->powLost,
  243. theftscore = $ret->theftScore,
  244. theftuu = $ret->theftUU,
  245. theftgold = $ret->theftGold,
  246. income = $ret->income
  247. where
  248. uid = $user->id
  249. ";
  250. mysql_query($sql) or die(mysql_error());
  251. }
  252. // Tables to Truncate
  253. $clean = array(
  254. 'BattleLog',
  255. 'Recruit',
  256. 'SpyLog',
  257. 'Weapon',
  258. );
  259. foreach ($clean as $tbl) {
  260. echo "resetscript: truncating table $tbl\n";
  261. $sql = "TRUNCATE $tbl";
  262. mysql_query($sql) or die(mysql_error());
  263. }
  264. // Now reset the Mercenaries table
  265. $sql = "
  266. update
  267. Mercenaries
  268. set
  269. attackspeccount = 0,
  270. defspeccount = 0,
  271. untrainedcount = 0;
  272. ";
  273. mysql_query($sql) or die(mysql_error());
  274. echo "resetscript: resetting User\n";
  275. // reset User
  276. $sql = "
  277. update
  278. User
  279. set
  280. gclick = 15,
  281. dalevel = 0,
  282. salevel = 0,
  283. gold = {$conf['start-gold']},
  284. bank = 0,
  285. attackturns = {$conf['start-attackturns']},
  286. up = 0,
  287. calevel = 0,
  288. ralevel = 0,
  289. sasoldiers = {$conf['start-sasoldiers']},
  290. samercs = 0,
  291. dasoldiers = {$conf['start-dasoldiers']},
  292. damercs = 0,
  293. uu = {$conf['start-uu']},
  294. spies = 0,
  295. commandergold = 0,
  296. gameSkill = gameSkill + 3000,
  297. specialforces = 0,
  298. SA = 0,
  299. DA = 0,
  300. CA = 0,
  301. RA = 0,
  302. hhlevel = 0,
  303. officerup = 0,
  304. changenick = 0,
  305. clicks = 0,
  306. clickall = 0,
  307. bankimg = 0
  308. ";
  309. mysql_query($sql) or die(mysql_error());
  310. ?>