搜索
 找回密码
 加入

转族程序,PHP

ctgwglzc 2009-10-12 15:53:34 1282
  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 '</br>Your not part of a Nation, how do you expect to change it?';
  23.             echo '</br></br><a href="./index.php">Back</a></br>';
  24.             part2();
  25.         } else {
  26.             // Confirm none of the chars are logged in..
  27.             // Updated during the for loop

  28.             $query = "SELECT count(strCharID) FROM CURRENTUSER WHERE strCharID = '" . $char1 . "' OR strCharID = '" . $char2 . "' OR strCharID = '" . $char3 . "'";
  29.             $results = odbc_exec($connect, $query);
  30.             while (odbc_fetch_row($results)) {
  31.                 $online = odbc_result($results, 1);
  32.             }
  33.               if (strlen(trim($online != 0)) > 0) {
  34.                 part1('100%', 1, 1, 'center');
  35.                 echo '</br>All characters must be logged out of the game first!';
  36.                 echo '</br></br><a href="./index.php">Back</a></br>';
  37.                 part2();
  38.                 die();
  39.             }
  40.             // Check they aren't in a clan on any of 3 characters.
  41.             
  42.             $query = "SELECT count(Knights) FROM USERDATA WHERE strUserID = '" . $char1 . "' OR strUserID = '" . $char2 . "' OR strUserID = '" . $char3 . "'";
  43.             $results = odbc_exec($connect, $query);
  44.             while (odbc_fetch_row($results)) {
  45.                 $knights = odbc_result($results, 1);
  46.             }
  47.             if (trim($Knights) > 0) {
  48.                 part1('100%', 1, 1, 'center');
  49.                 echo '</br>All characters on account have to be clanless.';
  50.                 echo '</br></br><a href="./index.php">Back</a></br>';
  51.                 part2();
  52.                 die();
  53.             }
  54.             $query = "SELECT COUNT(*) FROM NT_LOG WHERE DATEDIFF(Hour,[Date],GETDATE()) < 48 AND Account = '" . $_SESSION['sesuser'] . "'";
  55.             $results = odbc_exec($connect, $query);
  56.             while (odbc_fetch_row($results)) {
  57.                 $logcheck = odbc_result($results, 1);
  58.             }
  59.             if ($logcheck > 0) {
  60.                 part1('100%', 1, 1, 'center');
  61.                 echo '</br>You may only use this feature once every 48hours.';
  62.                 echo '</br></br><a href="./index.php">Back</a></br>';
  63.                 part2();
  64.                 die();
  65.             } else {
  66.                 // Get the nation and calculate desired nation
  67.                 $query = "SELECT strAccountID, bNation FROM ACCOUNT_CHAR WHERE strAccountID = '" . $_SESSION['sesuser'] . "'";
  68.                 $results = odbc_exec($connect, $query);
  69.                 while (odbc_fetch_row($results)) {
  70.                     $nation = odbc_result($results, 2);
  71.                 }
  72.                 if ($nation == 1) $desiredNation = 2;
  73.                 if ($nation == 2) $desiredNation = 1;
  74.                 // Test 1
  75.                 $check1 = odbc_exec($connect, "SELECT COUNT(*) FROM USERDATA WHERE Nation='" . $desiredNation . "'");
  76.                 $check2 = odbc_exec($connect, "SELECT COUNT(*) FROM USERDATA");

  77.                 $tot1 = odbc_result ($check1, 1);
  78.                 $tot2 = odbc_result($check2, 1);
  79.                 if ($tot1 / $tot2 > 0.6) {
  80.                     part1('100%', 1, 1, 'center');
  81.                     echo '</br>Sorry your desired nation has too many users.';
  82.                     echo '</br>The desired population must be less than 60% Population!';
  83.                     echo '</br></br><a href="./index.php">Back</a></br>';
  84.                     part2();
  85.                     die();
  86.                 }
  87.                 // Test 2
  88.                 $check3 = odbc_exec($connect, "SELECT SUM(Loyalty) AS nps FROM USERDATA WHERE Nation='" . $desiredNation . "'");
  89.                 $check4 = odbc_exec($connect, "SELECT SUM(Loyalty) AS totnps FROM USERDATA");
  90.                 $nps = odbc_result_all($check3);
  91.                 $totnps = odbc_result_all($check4);
  92.                 if ($nps / $totnps > 0.575) {
  93.                     part1('100%', 1, 1, 'center');
  94.                     echo '</br>Sorry your desired nation has too many National Points.';
  95.                     echo '</br>The desired population must be less than 57% total National Points!';
  96.                     echo '</br></br><a href="./index.php">Back</a></br>';
  97.                     part2();
  98.                     die();
  99.                 } else {
  100.                     // Calculate the newrace + class of the characters..
  101.                     foreach (array($char1, $char2, $char3) as $char) {
  102.                         if ($char != "") {
  103.                         $getuser = "SELECT strCharID FROM CURRENTUSER where strCharID = '" . $char . "'";
  104.                         $getusere = odbc_exec($connect, $getuser);
  105.                         $characterID = odbc_result($getusere, 1);

  106.                         if (strlen(trim($characterID)) > 0) {
  107.                         $killed = 1;
  108.                         KillUserAndWait(trim($characterID), $connect);
  109.                          }
  110.                             $query = "SELECT strUserID, Race, Class FROM USERDATA WHERE strUserID = '" . $char . "'";
  111.                             $results = odbc_exec($connect, $query);
  112.                             while (odbc_fetch_row($results)) {
  113.                                 $race = odbc_result($results, 2);
  114.                                 $class = odbc_result($results, 3);
  115.                             }

  116.                             if ($race < 12) {
  117.                                 $hashmap = array (1 => 11, 2 => 12, 3 => 13, 4 => 13, 11 => 1);
  118.                                 $NewRace = $hashmap[$race];
  119.                             } elseif (($race == 12) || ($race == 13) || ($race == 14)) {
  120.                                 if ($class == 201) $NewRace = 1;
  121.                                 elseif ($class == 202) $NewRace = 2;
  122.                                 elseif ($class == 203) $NewRace = 3;
  123.                                 elseif ($class == 204) $NewRace = 4;
  124.                                 elseif ($class == 205) $NewRace = 1;
  125.                                 elseif ($class == 207) $NewRace = 2;
  126.                                 elseif ($class == 209) $NewRace = 3;
  127.                                 elseif ($class == 211) $NewRace = 4;
  128.                             }
  129.                             if ($class >= 199) {
  130.                                 $NewClass = $class - 100;
  131.                             } else {
  132.                                 $NewClass = $class + 100;
  133.                             }
  134.                             if (($NewRace == '') || ($NewClass == '')) {
  135.                                 part1('100%', 1, 1, 'center');
  136.                                 echo 'Error: (Char: ' . $char . ')</br> New Class:';
  137.                                 echo $NewClass;
  138.                                 echo '</br> New Race:';
  139.                                 echo $NewRace;
  140.                                 echo '</br> Old Class:';
  141.                                 echo $class;
  142.                                 echo '</br> Old Race:';
  143.                                 echo $race;
  144.                                 echo '</br></br><a href="./index.php">Back</a></br>';
  145.                                 part2();
  146.                                 die();
  147.                             }
  148.                             $query = "UPDATE USERDATA SET Nation = '" . $desiredNation . "', Race = '" . $NewRace . "', Class = '" . $NewClass . "', Zone = 21, PX = 33550, PZ = 38400, PY = 0 WHERE strUserID = '" . $char . "'";
  149.                             $results = odbc_exec($connect, $query);
  150.                         }
  151.                     }
  152.                     $query = "INSERT INTO NT_LOG([Date], Account, Char1, Char2, Char3, NationTo) VALUES (GETDATE(), '" . $_SESSION['sesuser'] . "', '" . $char1 . "', '" . $char2 . "', '" . $char3 . "', '" . $desiredNation . "')";
  153.                     $results = odbc_exec($connect, $query);
  154.                     $query = "UPDATE ACCOUNT_CHAR SET bNation = '" . $desiredNation . "' WHERE strAccountID = '" . $_SESSION['sesuser'] . "'";
  155.                     $results = odbc_exec($connect, $query);
  156.                 }
  157.                 // Done
  158.                 part1tr();
  159.                 part1('100%', 1, 1, 'center');
  160.                 echo 'Done';
  161. echo '</br></br><a href="./index.php">Back</a>';
  162.                 if ($killed == 1) { echo '</br>A character was disconnected during this process'; }
  163.                 part2();
  164.                 part2tr();
  165.             }
  166.         }
  167.     } else {
  168.         part1tr();
  169.         part1('25%', 1, 1, 'center');
  170.         echo 'Please confirm your transfer:</br></br></br>
  171.         <li>You must be <b>logged out</b> of <b>all</b> characters</li>
  172.         <li>You must be <b>Clanless</b> on <b>all</b> characters</li>
  173.         <li>You may only use this feature <b>once</b> every 48hours</li>
  174.         <li>The Desired Nation must be <b>Less Than</b> 60% Total Population </li>
  175.         <li>The Desired Nation must be <b>Less Than</b> 57.5% Total National Points</li></br></br>
  176.         <FORM method=post name=confirm action=index.php?act=NationTransfer&Confirmed=1>
  177.             <input class="input" type="submit" value="Confirm">
  178.             </form>';
  179.         part2();
  180.         part2tr();
  181.     }
  182. } else {
  183.     part1('100%', 1, 1, 'center');
  184.     echo 'You must login first!';
  185.     part2();
  186. }

  187. ?>
复制代码

0 回复

高级模式
游客