Advertisement
Guest User

Untitled

a guest
Nov 11th, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.65 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class parser
  5. {
  6. private
  7. $data = '',
  8. $pointer = 0;
  9.  
  10. public function __construct($data)
  11. {
  12. $this->data = $data;
  13. }
  14.  
  15. public function pos()
  16. {
  17. return $this->pointer;
  18. }
  19.  
  20. public function size()
  21. {
  22. return mb_strlen($this->data);
  23. }
  24.  
  25. public function read($len = 0)
  26. {
  27. if ($len == 0)
  28. {
  29. $len = $this->size();
  30. }
  31.  
  32. $string = mb_substr($this->data, $this->pointer, $len);
  33.  
  34. $this->pointer += $len;
  35.  
  36. return $string;
  37. }
  38.  
  39. public function field($type, $len, $chrs = false, $implode = true)
  40. {
  41. $data = unpack($type, $this->read($len));
  42.  
  43. if ($chrs)
  44. {
  45. $data = array_map('chr', $data);
  46. }
  47.  
  48. return $implode ? implode('', $data) : $data;
  49. }
  50.  
  51. /* Parser functions */
  52.  
  53. public function parseStr($len = 0)
  54. {
  55. if ($len == 0)
  56. {
  57. $len = $this->parseUshort();
  58.  
  59. if ($len == 0)
  60. {
  61. return;
  62. }
  63. }
  64.  
  65. return $this->field('c*', $len, true);
  66. }
  67.  
  68. public function parseBool()
  69. {
  70. return (bool) $this->parseByte();
  71. }
  72.  
  73. public function parseByte()
  74. {
  75. return $this->field('C*', 1);
  76. }
  77.  
  78. public function parseBytes($len)
  79. {
  80. return $this->field('l*', $len);
  81. }
  82.  
  83. public function parseDouble()
  84. {
  85. $data = unpack('d*', strrev($this->read(8)));
  86.  
  87. return implode('', $data);
  88. }
  89.  
  90. public function parseFloat()
  91. {
  92. $data = unpack('f*', strrev($this->read(4)));
  93.  
  94. return implode('', $data);
  95. }
  96.  
  97. public function parseInt()
  98. {
  99. return $this->field('l*', 4);
  100. }
  101.  
  102. public function parseShort()
  103. {
  104. return $this->field('s*', 2);
  105. }
  106.  
  107. public function parseUint()
  108. {
  109. return $this->field('N*', 4);
  110. }
  111.  
  112. public function parseUshort()
  113. {
  114. return $this->field('n*', 2);
  115. }
  116.  
  117. /* Dumper functions */
  118.  
  119. public function dumpBool()
  120. {
  121. return $this->parseByte() ? 'true' : 'false';
  122. }
  123. }
  124.  
  125. error_reporting(0);
  126.  
  127. // Load room list
  128. $file = new parser(gzuncompress(file_get_contents('http://haxball.com/list3')));
  129.  
  130. // Not bothered about these
  131. $local3 = $file->parseByte();
  132. $local4 = $file->parseUint();
  133.  
  134. $rooms = array();
  135.  
  136. while ($file->pos() < $file->size())
  137. {
  138. $room = new parser($file->read($file->parseUshort()));
  139.  
  140. $ver = $room->parseUshort();
  141. $id = $room->parseStr();
  142. $name = $room->parseStr();
  143. $players = $room->parseByte();
  144. $max_players = $room->parseByte();
  145. $password = $room->parseBool();
  146. $country = $room->parseStr();
  147. $latitude = $room->parseFloat();
  148. $longitude = $room->parseFloat();
  149.  
  150. $rooms[] = array(
  151. 'ver' => $ver,
  152. 'id' => $id,
  153. 'name' => $name,
  154. 'players' => $players,
  155. 'max_players' => $max_players,
  156. 'password' => $password,
  157. 'country' => $country,
  158. 'latitude' => $latitude,
  159. 'longitude' => $longitude,
  160. 'distance' => $distance
  161. );
  162. }
  163.  
  164.  
  165. //include 'inc/config.php';
  166.  
  167.  
  168. //$dba = new mysqli($config['database']['hostname'], $config['database']['username'], $config['database']['password'], $config['database']['database']);
  169.  
  170. $config2['database']['type'] = 'mysql';
  171. $config2['database']['database'] = 'helloweb4';
  172. $config2['database']['table_prefix'] = 'mybb_';
  173.  
  174. $config2['database']['hostname'] = 'sql.helloweb.home.pl';
  175. $config2['database']['username'] = 'helloweb4';
  176. $config2['database']['password'] = '.d9WHC1gQEY';
  177.  
  178.  
  179. $linksb = mysql_connect($config2['database']['hostname'], $config2['database']['username'], $config2['database']['password']);
  180. mysql_select_db($config2['database']['database'], $linksb);
  181.  
  182. $sbrooms = array();
  183. $hos = array();
  184.  
  185. $sqlhos=mysql_query("SELECT `uid`, `usergroup` FROM `mybb_users` WHERE `usergroup` = 20 ORDER BY `uid` DESC");
  186. while($wynikhos = mysql_fetch_array($sqlhos)) {
  187. array_push($hos, $wynikhos['uid']);
  188. }
  189.  
  190. $sqlsb=mysql_query("SELECT * FROM `mybb_mysb_shouts` WHERE `shout_msg` LIKE '%http://www.haxball.com/?roomid=%' AND `shout_date` >= (".time()." - 20200) ORDER BY `id` DESC");
  191. while($wyniksb = mysql_fetch_array($sqlsb)) {
  192. $uid = $wyniksb['uid'];
  193. $pattern = '/roomid=[~0-9A-Za-z]*/';
  194. if(preg_match($pattern, $wyniksb['shout_msg'], $matches)) {
  195. $roomid = substr($matches[0], -64);
  196.  
  197. foreach($rooms as $key=>$val){
  198. if(preg_match("#$roomid#", $val['id'])){
  199.  
  200. foreach($sbrooms as $key2=>$val2){
  201. if(preg_match("#$roomid#", $val2['id'])){
  202. $nie = 1;
  203. }
  204. }
  205.  
  206. if($nie == 0) {
  207. $sbrooms[] = array(
  208. 'ver' => $val['ver'],
  209. 'id' => $val['id'],
  210. 'name' => $val['name'],
  211. 'players' => $val['players'],
  212. 'max_players' => $val['max_players'],
  213. 'password' => $val['password'],
  214. 'country' => $val['country'],
  215. 'latitude' => $val['latitude'],
  216. 'longitude' => $val['longitude'],
  217. 'distance' => $val['distance'],
  218. 'shoutuid' => $wyniksb['uid']
  219. );
  220. }
  221.  
  222. $nie = 0;
  223. }
  224. }
  225.  
  226. }
  227.  
  228. }
  229.  
  230.  
  231.  
  232. $roomssb = '<ul class="nav profile-sidenav" id="profile-sidenav" style="width:100%; margin-top:0; text-align: left;">
  233. <li class="active" style="color: white;
  234. text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.2);
  235. background-image: url(../images/ababab.png);margin: 0 0 -1px;
  236. padding: 8px 14px;
  237. border: 1px solid #E5E5E5;"><i class="icon-play pull-right" style="margin: 3px 0"></i> Zagraj z nami!</li>';
  238.  
  239.  
  240. foreach($sbrooms as $klucz=>$war) {
  241. $roomssb .= '<li class="" style="margin: 0 0 -1px;
  242. padding: 8px 14px;
  243. border: 1px solid #E5E5E5;"><span class="smalltext">
  244. ';
  245.  
  246. if(in_array($war['shoutuid'], $hos) && (preg_match("#pl-hb#", $war['name']) || preg_match("#PL-HB#", $war['name']))) {
  247. $roomssb .= '<i class="icon-star pull-right" style="margin: 10px 0px 0 0;" data-rel="tooltip" data-placement="left" title="Oficjalny pokój PL-HB"></i>';
  248. }
  249.  
  250. if($war['password'] == 1) {
  251. $roomssb .= '<i class="icon-lock pull-right" style="margin: 10px 0px 0 0;" data-rel="tooltip" data-placement="left" title="Pokój chroniony hasłem"></i>
  252. <div style="margin-top: 3px;float: left;line-height: 15px;"><p class="ellipsis" style="width: 220px;"><a href="http://www.haxball.com/?roomid='.$war['id'].'&pass=1">'.$war['name'].'</a><p>';
  253. } else {
  254. $roomssb .= '<div style="margin-top: 3px;float: left;line-height: 15px;"><p class="ellipsis" style="width: 220px;"><a href="http://www.haxball.com/?roomid='.$war['id'].'">'.$war['name'].'</a></p>';
  255. }
  256. $roomssb .= '<span style="font-size: 12px;"><span class="muted">Liczba graczy: </span>'.$war['players'].'/'.$war['max_players'].'</span></div><br style="clear:both;"></span></li>
  257. ';
  258.  
  259. }
  260.  
  261. if(!$sbrooms) {
  262. $roomssb .= '<li class="muted" style="margin: 0 0 -1px;
  263. padding: 8px 14px;
  264. border: 1px solid #E5E5E5;">
  265. Teraz nie gramy na żadnym pokoju.
  266. <i class="icon-info-sign pull-right" style="margin-top:3px; margin-right:-1px;" data-placement="left" data-rel="tooltip" data-original-title="Jeśli chcesz, aby twój pokój pojawił się na tej liście, wyślij na shoutboxie odnośnik do niego. Pąmiętaj, że pokój nie może być ukryty!" data-placement="left"></i>
  267. </li>
  268. ';
  269.  
  270. }
  271.  
  272. $roomssb .= '</ul>';
  273.  
  274. // echo'<link href="css/bootstrap.min.css" rel="stylesheet">';
  275. echo $roomssb;
  276.  
  277. if($_GET['hehe']) {
  278. print_r($sbrooms);
  279. }
  280.  
  281.  
  282. if($_GET['all']) {
  283. print_r($rooms);
  284. }
  285.  
  286.  
  287. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement