Advertisement
Guest User

cf-userlogin.php

a guest
Sep 1st, 2012
1,582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.77 KB | None | 0 0
  1. <?php
  2. /**
  3. * Advanced HiddenProject Content Management System - Game Login
  4. *
  5. * Copyright (c) 2012 Naufal Hardiansyah (www.gremory.cu.cc)
  6. * The program is distributed under the terms of the GNU General Public License
  7. *
  8. * This file is part of Advanced HiddenProject Content Management System (AdvHPContentMS).
  9. *
  10. * AdvHPContentMS is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * Naufal Hardiansyah, either version 3 of the License, or any later version.
  13. *
  14. * AdvHPContentMS is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with AdvHPContentMS. If not, see .
  21. **/
  22. /** DateTime::diff issues
  23. * SEEMS THERE IS AN ISSUE WITH PHP >= 5.3.0
  24. * SO I DECIDED TO CREATE AN ALTERNATE FUNCTION TO SOLVE IT, TO ENABLE THIS FUNCTION:
  25. * REPLACE:
  26. $datetime1 = new DateTime(date('Y-m-d h:i:s'));
  27. $datetime2 = new DateTime($UpgradeExpire);
  28. $interval = $datetime1->diff($datetime2);
  29. $UpgDays = $interval->format('%R%a');
  30. * WITH:
  31. $UpgDays = date_diff(date('Y-m-d h:i:s'), $UpgradeExpire);
  32. * ENABLE THIS FUNCTION:
  33. function date_diff($date1, $date2) {
  34. $current = $date1;
  35. $datetime2 = date_create($date2);
  36. $count = 0;
  37. while (date_create($current) < $datetime2){
  38. $current = gmdate("Y-m-d", strtotime("+1 day", strtotime($current)));
  39. $count++;
  40. }
  41. return $count;
  42. }
  43. **/
  44.  
  45. /** READS CONFIGURATIONS **/
  46. require_once 'config.php';
  47.  
  48. /** DEFINES CLASSES **/
  49. DefineClass('class.content');
  50. DefineClass('class.core');
  51.  
  52. /** SETS CONTENT TYPE **/
  53. header("Content-Type: text/xml");
  54.  
  55. /** CREATES NEW CLASSES **/
  56. $Content = new HiddenProjectCMS();
  57. $Client = new Core();
  58. $XML = new SimpleXMLElement('');
  59. $DOM = new DOMDocument();
  60.  
  61. /** CONFIGURES MYSQL PARAMETERS **/
  62. $MySQL = new stdClass();
  63. $MySQL->HOST = Configurations::MySQLHost;
  64. $MySQL->USER = Configurations::MySQLUser;
  65. $MySQL->PASS = Configurations::MySQLPass;
  66. $MySQL->DATA = Configurations::MySQLData;
  67. $Content->MYSQL = $MySQL;
  68.  
  69. /** INITIALIZES MYSQL CONNECTIONS **/
  70. $Content->Initialize('Connection');
  71.  
  72. if (isset($_POST['strUsername']) AND isset($_POST['strPassword'])) {
  73. $Username = $Content->DBase('EscapeString', array( 0 => $_POST['strUsername'] ));
  74. $Password = $Client->Initialize('UserToken', array( 0 => $_POST['strPassword'], 1 => $Username ));
  75. $upgdays = -1;
  76.  
  77. /** PARSES USER DATA **/
  78. if ($stmt = $Content->DBase('Prepare', array( 0 => 'SELECT id, iUpgExp, iEmailSent, iAge, iAccess, strEmail FROM `etl_users` WHERE strUsername=? AND strPassword=? LIMIT 1' ))) {
  79. $stmt->bind_param("ss", $Username, $Password);
  80. $stmt->execute();
  81. $stmt->bind_result($user_id, $UpgradeExpire, $ActivationFlag, $Age, $Access, $Email);
  82. if ($stmt->fetch()) {
  83. /** HANDLES USER UPGRADE DAYS **/
  84. $datetime1 = new DateTime(date('Y-m-d h:i:s'));
  85. $datetime2 = new DateTime($UpgradeExpire);
  86. $interval = $datetime1->diff($datetime2);
  87. $UpgDays = $interval->format('%R%a');
  88.  
  89. /** PARSES USER UPGRADE DAYS **/
  90. if ($UpgDays <= -0 AND $UpgDays != +0 OR $UpgDays == 0)
  91. $UpgDays = -1;
  92.  
  93. $XML->addAttribute('bSuccess', '1');
  94. $XML->addAttribute('user_id', $user_id);
  95. $XML->addAttribute('iAccess', $Access);
  96. $XML->addAttribute('iUpg', $UpgDays >= 0 ? 1 : 0);
  97. $XML->addAttribute('iAge', $Age);
  98. $XML->addAttribute('sToken', $Password);
  99. $XML->addAttribute('dUpgExp', preg_replace('/\s+/', 'T', $UpgradeExpire));
  100. $XML->addAttribute('iUpgDays', $UpgDays);
  101. $XML->addAttribute('iSendEmail', $ActivationFlag);
  102. $XML->addAttribute('strEmail', $Email);
  103. $XML->addAttribute('bCCOnly', 0);
  104. } else {
  105. $XML->addAttribute('bSuccess', '0');
  106. $XML->addAttribute('sMsg', 'The username and password you entered did not match. Please check the spelling and try again.');
  107. }
  108. } $stmt->close();
  109.  
  110. /** READS XML DATA **/
  111. $DOM->loadXML($XML->asXML());
  112. $DOM->getElementsByTagName('login');
  113. $DOC = $DOM->getElementsByTagName('login');
  114. foreach ($DOC as $ELEMENT) {
  115. if ($ELEMENT->getAttribute('bSuccess') == '1') {
  116. /** SOME ADDONS **/
  117. $Content->DBase('Query', array( 0 => "UPDATE `etl_users` SET iUpgDays={$UpgDays} WHERE id={$user_id}" ));
  118. $Content->DBase('Query', array( 0 => "UPDATE `etl_users_items` SET bEquip=0 WHERE sES='ar' AND user_id={$user_id}" ));
  119. $sql = $Content->DBase('Query', array( 0 => "SELECT * FROM `etl_users_items` WHERE user_id={$user_id} AND item_id=2" ));
  120. if ($sql->num_rows > 0)
  121. $Content->DBase('Query', array( 0 => "UPDATE `etl_users_items` SET bEquip=1 WHERE sES='ar' AND user_id={$user_id} AND item_id=6" ));
  122. else
  123. $Content->DBase('Query', array( 0 => "INSERT INTO etl_users_items (item_id, user_id, bEquipp, sES, iLvl) VALUES ('6', '$user_id', '1', 'ar', '1')" ));
  124.  
  125. /** INITIALIZES SERVER LIST **/
  126. $ServerList = $Content->DBase('Query', array( 0 => "SELECT * FROM etl_servers LIMIT 10" ));
  127. while ($server = $ServerList->fetch_assoc()) {
  128. $child = $XML->addChild('servers');
  129. $child->addAttribute('sName', $server['sName']);
  130. $child->addAttribute('sIP', $server['sIP']);
  131. $child->addAttribute('iCount', $server['iCount']);
  132. $child->addAttribute('iMax', $server['iCount'] >= $server['iMax'] ? -1 : $server['iMax']);
  133. $child->addAttribute('bOnline', $server['bOnline']);
  134. $child->addAttribute('iChat', $server['iChat']);
  135. $child->addAttribute('bUpg', $server['bUpg']);
  136. $child->addAttribute('sLang', 'xx');
  137. }
  138.  
  139. /** INITIALIZES LOGIN STATUS **/
  140. $Client->HandleUser('Login', array( 0 => $Content, 1 => $_POST['strUsername'], 2 => $_POST['strPassword'] ));
  141. break;
  142. }
  143. }
  144. } else {
  145. $XML->addAttribute('bSuccess', '0');
  146. $XML->addAttribute('sMsg', 'Invalid Input');
  147. }
  148.  
  149. /** PARSES XML DOM **/
  150. $XMLDOM = dom_import_simplexml($XML);
  151. $XMLString = $XMLDOM->ownerDocument->saveXML($XMLDOM->ownerDocument->documentElement);
  152.  
  153. /** PRINTS FINAL OUTPUT **/
  154. $Content->SITE->CONTENT = $XMLString;
  155. $Content->FlushContent(false);
  156. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement