Advertisement
Guest User

Untitled

a guest
Jun 10th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. <?php
  2.  
  3. class Database {
  4. function __construct()
  5. {
  6. $connections = array('logon'=>array('user'=>'root',
  7. 'pass'=>'lolpwned',
  8. 'host'=>'127.0.0.1',
  9. 'db_name'=>'logon'),
  10. 'website'=>array('user'=>'root',
  11. 'pass'=>'lolpwned',
  12. 'host'=>'127.0.0.1',
  13. 'db_name'=>'website'),
  14. 'vote'=>array('user'=>'root',
  15. 'pass'=>'lolpwned',
  16. 'host'=>'127.0.0.1',
  17. 'db_name'=>'vote')
  18. );
  19. $realms = array('Warground'=>array('char'=>array('user'=>'root',
  20. 'pass'=>'lolpwned',
  21. 'host'=>'127.0.0.1',
  22. 'db_name'=>'warground_char'),
  23. 'world'=>array('user'=>'root',
  24. 'pass'=>'lolpwned',
  25. 'host'=>'127.0.0.1',
  26. 'db_name'=>'warground_world'),
  27. 'max_online'=>'200')
  28. 'Destruction'=>array('char'=>array('user'=>'root',
  29. 'pass'=>'lolpwned',
  30. 'host'=>'127.0.0.1',
  31. 'db_name'=>'destruction_char'),
  32. 'world'=>array('user'=>'root',
  33. 'pass'=>'lolpwned',
  34. 'host'=>'127.0.0.1',
  35. 'db_name'=>'destructionworld'),
  36. 'max_online'=>'200')
  37.  
  38. );
  39.  
  40. $this->connections = $connections;
  41. $this->realms = $realms;
  42.  
  43.  
  44. }
  45. function get_stats()
  46. {
  47.  
  48.  
  49. foreach( $this->realms as $realm => $db_array )
  50. {
  51. $horde = 0;
  52. $alliance = 0;
  53. $i = 0;
  54.  
  55. $char = $db_array['char'];
  56.  
  57. $con = $this->con($char, true);
  58.  
  59. $sql = 'select race from characters where online="1"';
  60.  
  61. $array = $this->query_to_array( $sql );
  62.  
  63. foreach( $array as $k=>$v )
  64. {
  65. $race = $v['race'];
  66.  
  67.  
  68.  
  69. if( $race == "2" || $race == "5" || $race == "6" || $race == "8" || $race == "10" )
  70. {
  71. $horde = $horde+1;
  72.  
  73. }
  74. else { $alliance = $alliance+1; }
  75.  
  76. }
  77. $count_online = count( $array );
  78. $max_online = $db_array['max_online'];
  79. $percent = $count_online / $max_online;
  80. $percent = round( $percent * 100 );
  81.  
  82. echo('
  83. <center><span class="stat_head">'.$realm.'</span>
  84. <center><span class="players_online">'.$count_online.'/'.$max_online.'</span></center>
  85. <div class="bar_bg"><div class="active_bar" style="width:'.$percent.'%;"></div></div>
  86. <span style="color:red;">[ H: '.$horde.' ]&nbsp;&nbsp;</span>
  87. <span style="color:lime;">[ A: '.$alliance.' ]</span>
  88. ');
  89.  
  90.  
  91.  
  92. }
  93. }
  94.  
  95. function con( $db, $realm=false ) {
  96.  
  97. if(!$realm)
  98. {
  99. $user = $this->connections[$db]['user'];
  100. $pass = $this->connections[$db]['pass'];
  101. $host = $this->connections[$db]['host'];
  102. $data = $this->connections[$db]['db_name'];
  103. }
  104. else{
  105.  
  106. $user = $db['user'];
  107. $pass = $db['pass'];
  108. $host = $db['host'];
  109. $data = $db['db_name'];
  110. //echo $user."::".$pass."::".$host."::".$data;
  111.  
  112. }
  113.  
  114.  
  115. $con = mysql_connect( $host, $user, $pass ) or die('Error: cannot connect to database!');
  116. $con = mysql_select_db( $data, $con );
  117.  
  118. return $con;
  119.  
  120. }
  121. function query( $sql, $con = NULL ) {
  122.  
  123. if( $con == NULL )
  124. {
  125. $result = mysql_query( $sql ) or die ('Error: check query string!'.mysql_error());
  126. }
  127. else
  128. {
  129. $result = mysql_query( $sql, $con ) or die ('Error: check query string!'.mysql_error());
  130. }
  131. return $result;
  132. }
  133. function count_char( $char, $realm, $id )
  134. {
  135. $chardb = $this->realms[$realm]['char'];
  136. $this->con( $chardb, true );
  137. $char = 'select guid,name from characters where guid="'.$char.'" and account="'.$id.'"';
  138. $result_char = $this->query( $char );
  139. $count = $this->num_rows( $result_char );
  140. return $count;
  141.  
  142. }
  143. function num_rows( $resource ) {
  144. return @mysql_num_rows( $resource );
  145. }
  146.  
  147. function query_to_array( $query ) {
  148.  
  149. if( $con != NULL )
  150. {
  151. $result = mysql_query( $query ) or die ('Error: check query string!'.mysql_error());
  152. }
  153. else {
  154. $result = mysql_query( $query ) or die ('Error: check query string!'.mysql_error());
  155. }
  156.  
  157. $i=0;
  158.  
  159. while( $row = mysql_fetch_array( $result ) )
  160. {
  161. $array[$i] = $row;
  162. $i++;
  163. }
  164. return $array;
  165.  
  166. }
  167.  
  168. function ReturnObject( $result )
  169. {
  170. $return = mysql_fetch_object( $result );
  171.  
  172. return $return or die('Error: object could not be retrieved!');
  173. }
  174. function update_sid( $username )
  175. {
  176. $this->con( 'logon' );
  177. $sid = md5(uniqid(rand(), true));
  178. $_SESSION['sid'] = $sid;
  179.  
  180. $sql = 'update account set sid="'.$sid.'" where username="'.$username.'"';
  181. $this->query( $sql );
  182. }
  183. }
  184.  
  185. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement