搜索
 找回密码
 加入

[PHP] Nation Transfer Script (种族转换脚本)

ctgwglzc 2008-12-6 10:44:19 1222
  1. <?php  

  2. include('./anti_inject.php');

  3. parth1tr();
  4. parth1('100%', 2, 'center');
  5. echo 'Nation Transfer ;
  6. parth2();
  7. parth2tr();

  8. if (isset($_SESSION['sesuser'])) {
  9. if ($_GET['Confirmed'] == 1) {
  10. $connect = odbc_connect("$dbname", "$dbuser", "$dbpass");
  11. $query = "SELECT strCharID1, strCharID2, strCharID3 FROM Account_Char WHERE strAccountID ='" . $_SESSION['sesuser'] . "' ";
  12. $results = odbc_exec($connect, $query);
  13. // Store all char names in var's.....
  14. while (odbc_fetch_row($results)) {
  15. $char1 = odbc_result($results, 1);
  16. $char2 = odbc_result($results, 2);
  17. $char3 = odbc_result($results, 3);
  18. }
  19. // Confirm they have a character
  20. if ((empty($char1)) && (empty($char2)) && (empty($char3))) {
  21. part1('100%', 1, 1, 'center');
  22. echo '
  23. Your not part of a Nation, how do you expect to change it?';
  24. echo '

  25. Back
  26. ';
  27. part2();
  28. } else {
  29. // Confirm none of the chars are logged in..
  30. // Updated during the for loop

  31. $query = "SELECT count(strCharID) FROM CURRENTUSER WHERE strCharID = '" . $char1 . "' OR strCharID = '" . $char2 . "' OR strCharID = '" . $char3 . "'";
  32. $results = odbc_exec($connect, $query);
  33. while (odbc_fetch_row($results)) {
  34. $online = odbc_result($results, 1);
  35. }
  36. if (strlen(trim($online)) > 0) {
  37. part1('100%', 1, 1, 'center');
  38. echo '
  39. All characters must be logged out of the game first!';
  40. echo '

  41. Back
  42. ';
  43. part2();
  44. die();
  45. }
  46. // Check they aren't in a clan on any of 3 characters.

  47. $query = "SELECT count(Knights) FROM USERDATA WHERE strUserID = '" . $char1 . "' OR strUserID = '" . $char2 . "' OR strUserID = '" . $char3 . "'";
  48. $results = odbc_exec($connect, $query);
  49. while (odbc_fetch_row($results)) {
  50. $knights = odbc_result($results, 1);
  51. }
  52. if ($knights != 0) {
  53. part1('100%', 1, 1, 'center');
  54. echo '
  55. All characters on account have to be clanless.';
  56. echo '

  57. Back
  58. ';
  59. part2();
  60. die();
  61. }
  62. $query = "SELECT COUNT(*) FROM NT_LOG WHERE DATEDIFF(Hour,[Date],GETDATE()) < 48 AND Account = '" . $_SESSION['sesuser'] . "'";
  63. $results = odbc_exec($connect, $query);
  64. while (odbc_fetch_row($results)) {
  65. $logcheck = odbc_result($results, 1);
  66. }
  67. if ($logcheck > 0) {
  68. part1('100%', 1, 1, 'center');
  69. echo '
  70. You may only use this feature once every 48hours.';
  71. echo '

  72. Back
  73. ';
  74. part2();
  75. die();
  76. } else {
  77. // Get the nation and calculate desired nation
  78. $query = "SELECT strAccountID, bNation FROM ACCOUNT_CHAR WHERE strAccountID = '" . $_SESSION['sesuser'] . "'";
  79. $results = odbc_exec($connect, $query);
  80. while (odbc_fetch_row($results)) {
  81. $nation = odbc_result($results, 2);
  82. }
  83. if ($nation == 1) $desiredNation = 2;
  84. if ($nation == 2) $desiredNation = 1;
  85. // Test 1
  86. $check1 = odbc_exec($connect, "SELECT COUNT(*) FROM USERDATA WHERE Nation='" . $desiredNation . "'");
  87. $check2 = odbc_exec($connect, "SELECT COUNT(*) FROM USERDATA");

  88. $tot1 = odbc_result ($check1, 1);
  89. $tot2 = odbc_result($check2, 1);
  90. if ($tot1 / $tot2 > 0.6) {
  91. part1('100%', 1, 1, 'center');
  92. echo '
  93. Sorry your desired nation has too many users.';
  94. echo '
  95. The desired population must be less than 60% Population!';
  96. echo '

  97. Back
  98. ';
  99. part2();
  100. die();
  101. }
  102. // Test 2
  103. $check3 = odbc_exec($connect, "SELECT SUM(Loyalty) AS nps FROM TB_USER WHERE Nation='" . $desiredNation . "'");
  104. $check4 = odbc_exec($connect, "SELECT SUM(Loyalty) AS totnps FROM TB_USER");
  105. $nps = odbc_result_all($check3);
  106. $totnps = odbc_result_all($check4);
  107. if ($nps / $totnps > 0.575) {
  108. part1('100%', 1, 1, 'center');
  109. echo '
  110. Sorry your desired nation has too many National Points.';
  111. echo '
  112. The desired population must be less than 57% total National Points!';
  113. echo '

  114. Back
  115. ';
  116. part2();
  117. die();
  118. } else {
  119. // Calculate the newrace + class of the characters..
  120. foreach (array($char1, $char2, $char3) as $char) {
  121. if ($char != "") {
  122. $getuser = "SELECT strCharID FROM CURRENTUSER where strCharID = '" . $char . "'";
  123. $getusere = odbc_exec($connect, $getuser);
  124. $characterID = odbc_result($getusere, 1);

  125. if (strlen(trim($characterID)) > 0) {
  126. $killed = 1;
  127. KillUserAndWait(trim($characterID), $connect);
  128. }
  129. $query = "SELECT strUserID, Race, Class FROM USERDATA WHERE strUserID = '" . $char . "'";
  130. $results = odbc_exec($connect, $query);
  131. while (odbc_fetch_row($results)) {
  132. $race = odbc_result($results, 2);
  133. $class = odbc_result($results, 3);
  134. }

  135. if ($race < 12) {
  136. $hashmap = array (1 => 11, 2 => 12, 3 => 13, 4 => 13, 11 => 1);
  137. $NewRace = $hashmap[$race];
  138. } elseif (($race == 12) || ($race == 13) || ($race == 14)) {
  139. if ($class == 201) $NewRace = 1;
  140. elseif ($class == 202) $NewRace = 2;
  141. elseif ($class == 203) $NewRace = 3;
  142. elseif ($class == 204) $NewRace = 4;
  143. elseif ($class == 205) $NewRace = 1;
  144. elseif ($class == 207) $NewRace = 2;
  145. elseif ($class == 209) $NewRace = 3;
  146. elseif ($class == 211) $NewRace = 4;
  147. }
  148. if ($class >= 199) {
  149. $NewClass = $class - 100;
  150. } else {
  151. $NewClass = $class + 100;
  152. }
  153. if (($NewRace == '') || ($NewClass == '')) {
  154. part1('100%', 1, 1, 'center');
  155. echo 'Error: (Char: ' . $char . ')
  156. New Class:';
  157. echo $NewClass;
  158. echo '
  159. New Race:';
  160. echo $NewRace;
  161. echo '
  162. Old Class:';
  163. echo $class;
  164. echo '
  165. Old Race:';
  166. echo $race;
  167. echo '

  168. Back
  169. ';
  170. part2();
  171. die();
  172. }
  173. $query = "UPDATE USERDATA SET Nation = '" . $desiredNation . "', Race = '" . $NewRace . "', Class = '" . $NewClass . "', Zone = 21, PX = 33550, PZ = 38400, PY = 0 WHERE strUserID = '" . $char . "'";
  174. $results = odbc_exec($connect, $query);
  175. }
  176. }
  177. $query = "INSERT INTO NT_LOG([Date], Account, Char1, Char2, Char3, NationTo) VALUES (GETDATE(), '" . $_SESSION['sesuser'] . "', '" . $char1 . "', '" . $char2 . "', '" . $char3 . "', '" . $desiredNation . "')";
  178. $results = odbc_exec($connect, $query);
  179. $query = "UPDATE ACCOUNT_CHAR SET bNation = '" . $desiredNation . "' WHERE strAccountID = '" . $_SESSION['sesuser'] . "'";
  180. $results = odbc_exec($connect, $query);
  181. }
  182. // Done
  183. part1tr();
  184. part1('100%', 1, 1, 'center');
  185. echo 'Done';
  186. echo '

  187. Back';
  188. if ($killed == 1) { echo '
  189. A character was disconnected during this process'; }
  190. part2();
  191. part2tr();
  192. }
  193. }
  194. } else {
  195. part1tr();
  196. part1('25%', 1, 1, 'center');
  197. echo 'Please confirm your transfer:




  198. You must be logged out of all characters

  199. You must be Clanless on all characters

  200. You may only use this feature once every 48hours

  201. The Desired Nation must be Less Than 60% Total Population

  202. The Desired Nation must be Less Than 57.5% Total National Points





  203. ';
  204. part2();
  205. part2tr();
  206. }
  207. } else {
  208. part1('100%', 1, 1, 'center');
  209. echo 'You must login first!';
  210. part2();
  211. }

  212. ?>
复制代码

2 回复

ctgwglzc
2008-12-6 10:43:40
楼主

附文中引用的anti_inject.php(反SQL注入功能)

点击查看详情
  1. <?php

  2. //simple anti sql injection function written by Heretic

  3. include('sql_inject_log.php');

  4. function test($tekst)
  5. {
  6.         $tekst = strtolower($tekst);
  7.         $helpTekst = $tekst;
  8.         $tekst = strip_tags($tekst);
  9.         $banlist = array ("'", ";", "%", "$", "-", ">", "drop", """, "<", "\", "|", "/", "=", "echo", "insert", "select", "update", "delete", "distinct", "having", "truncate", "replace", "handler", "like", "procedure", "limit", "order by", "group by", "asc", "desc", "union", "include", "userdata", "tb_user", "account_char");
  10.         $tekst = str_replace($banlist, " ", $tekst);
  11.         $tekst = trim($tekst);
  12.         if (strcmp($helpTekst,$tekst)) filelogs('attack_log', $helpTekst);
  13.         return($tekst);
  14. }

  15. function test_link($linkx)
  16. {
  17.         $linkx = strtolower($linkx);
  18.         $helpLink = $linkx;
  19.         $linkx = strip_tags($linkx);
  20.         $banlist = array ("'", ";", "%", "$", "-", ">", "drop", """, "<", "\", "|", "=", "echo", "insert", "select", "update", "delete", "distinct", "having", "truncate", "replace", "handler", "like", "procedure", "limit", "order by", "group by", "asc", "desc", "union", "include", "userdata", "tb_user", "account_char");
  21.         $linkx = str_replace($banlist, " ", $linkx);
  22.         $linkx = trim($linkx);
  23.         if (strcmp($helpLink,$linkx))
  24.         {
  25.                 return true;
  26.         }else return false;       
  27. }

  28. ?>
复制代码
ctgwglzc
2008-12-6 10:44:19
楼主

sql_inject_log.php

  1. <?php

  2. //function downloaded from ragezone.com, post written by john_d

  3. function filelogs($type, $query)
  4. {
  5.         $agent = $_SERVER['HTTP_USER_AGENT'];
  6.     $uri = $_SERVER['REQUEST_URI'];
  7.     $ip = $_SERVER['REMOTE_ADDR'];
  8.     $ref = $_SERVER['HTTP_REFERER'];
  9.     $dtime = date('r');
  10.      
  11.     if($ref == ""){
  12.         $ref = "None";
  13.     }
  14.     if($user == ""){
  15.         $user = "None";
  16.     }
  17.     $location = "./Logs/";
  18.     $type = $location . $type . ".txt";
  19.     $entry_line = "$dtime - IP: $ip | Agent: $agent  | URL: $uri | Referrer: $ref | Query : $query \n";
  20.     $fp = fopen("$type", "a");
  21.     fputs($fp, $entry_line);
  22.     fclose($fp);  
  23. }


  24. ?>
复制代码
高级模式
游客