Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. <?php
  2. // Laczenie z serwerem csgo
  3. $ip = "xxxxxxxxxxx";
  4. $port = "xxxxx";
  5.  
  6. $socket = socket_create(AF_INET, SOCK_DGRAM, 0);
  7. $result = socket_connect($socket, $ip, $port);
  8.  
  9. if($result < 0)
  10. echo "connect() failed.nReason: ($result) n";
  11.  
  12. $data = "xFFxFFxFFxFFx54x53x6Fx75x72x63x65x20x45x6Ex67x69x6Ex65x20x51x75x65x72x79x00";
  13. socket_write($socket, $data, strlen($data));
  14.  
  15. $out = socket_read($socket, 4096);
  16.  
  17.  
  18. $queryData = explode("x00", substr($out, 6), 5);
  19.  
  20. $server['name'] = $queryData[0];
  21.  
  22. $servers = array (
  23. 'multimod' => array(
  24. "title" => "$server['name']",
  25. "prefix" => "dem"
  26. )
  27. );
  28. $filesPerPage = 20;
  29. # Size in bytes
  30. function format_size($size, $round = 0)
  31. {
  32. $sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
  33. for ($i=0; $size > 1024 && isset($sizes[$i+1]); $i++)
  34. $size /= 1024;
  35. return round($size, $round)." ".$sizes[$i];
  36. }
  37. function browse($path)
  38. {
  39. global $servers;
  40. global $filesPerPage;
  41. $data = array();
  42. $page = $_GET['page'];
  43. $page = !isset($page) || $page < 1 ? 0 : $page - 1;
  44. $prefix = $servers[$path]['prefix'];
  45. $prefix_sz = strlen($prefix) + 1;
  46. $offsets = array(
  47. map => $prefix_sz,
  48. start => $prefix_sz + 11,
  49. end => $prefix_sz + 23
  50. );
  51. if(is_dir($path))
  52. {
  53. $files = glob($path."/*.zip");
  54. $count = count($files);
  55. $pages = ceil( $count / $filesPerPage );
  56. $page = $page >= $pages ? $pages - 1 : $page;
  57. $begin = $count - ($page + 1) * $filesPerPage;
  58. $end = $count - $page * $filesPerPage;
  59. for($i = $begin < 0 ? 0 : $begin; $i < $end; ++$i)
  60. {
  61. $file = end( explode('/', $files[$i]) );
  62. $name_end = strrpos($file, ".dem");
  63. $name_end = $name_end === FALSE ? strrpos($file, ".zip") : $name_end;
  64. $tmpfilesize = @filesize($files[$i]);
  65. if($name_end === FALSE)
  66. continue;
  67. $tmp = array();
  68. $tmp[map] = substr($file, $offsets[map], $name_end - $offsets[end]+1);
  69. $tmp[start] = substr($file, $offsets[start], 10);
  70. $tmp[end] = substr($file, $offsets[end], 10);
  71. $tmp[file] = $file;
  72. $tmp[size] = format_size($tmpfilesize);
  73. $tmp[path] = $files[$i];
  74. $data[] = $tmp;
  75. }
  76. $files = array();
  77. }
  78. echo '<!-- Lista dem -->
  79. <div class="dema" id="d1"><table style="text-align: center;"><thead>
  80. <tr><td colspan="6" class="day">Demka</td></tr>
  81. <tr>
  82. <th>URL</th>
  83. <th>Mapa</th>
  84. <th>Start</th>
  85. <th>Stop</th>
  86. <th>Rozmiar</th>
  87. <th></th>
  88. </tr></thead>';
  89. if($count > 0)
  90. {
  91. foreach($data as $field)
  92. {
  93. echo '<tr>
  94. <td class="url"><input type="text" value="http://'.$_SERVER[HTTP_HOST].''.$_SERVER[REQUEST_URI].''.$field[path].'"></td>
  95. <td>'.$field[map].'</td>
  96. <td>'.$field[start].'</td>
  97. <td>'.$field[stop].'</td>
  98. <td>'.$field[size].'</td>
  99. <td class="dl"><a href="http://'.$_SERVER[HTTP_HOST].''.$_SERVER[REQUEST_URI].''.$field[path].'">Pobierz</a></td>
  100. </tr>';
  101. }
  102. }
  103. else
  104. {
  105. echo '<tr><td align="center">- Brak demek -</td></tr>';
  106. }
  107. echo '</table><br></div>';
  108. if($pages > 1)
  109. {
  110. echo '<div class="pagination">';
  111. for($i = 0; $i < $pages; ++$i)
  112. {
  113. if($pages > 10)
  114. {
  115. if($i > 2 && $i < $page - 1)
  116. {
  117. echo '...';
  118. $i = $page - 1;
  119. }
  120. else
  121. if($i > $page + 1 && $i > 2 && $i < $pages - 3)
  122. {
  123. echo '...';
  124. $i = $pages - 3;
  125. }
  126. }
  127. if($i != $page)
  128. echo '<a href="?page='.($i + 1).'&server='.$path.'">'.($i + 1).'</a>';
  129. else
  130. echo '<span>'.($page + 1).'</span>';
  131. }
  132. echo '</div>';
  133. }
  134. }
  135. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement