Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Laczenie z serwerem csgo
- $ip = "xxxxxxxxxxx";
- $port = "xxxxx";
- $socket = socket_create(AF_INET, SOCK_DGRAM, 0);
- $result = socket_connect($socket, $ip, $port);
- if($result < 0)
- echo "connect() failed.nReason: ($result) n";
- $data = "xFFxFFxFFxFFx54x53x6Fx75x72x63x65x20x45x6Ex67x69x6Ex65x20x51x75x65x72x79x00";
- socket_write($socket, $data, strlen($data));
- $out = socket_read($socket, 4096);
- $queryData = explode("x00", substr($out, 6), 5);
- $server['name'] = $queryData[0];
- $servers = array (
- 'multimod' => array(
- "title" => "$server['name']",
- "prefix" => "dem"
- )
- );
- $filesPerPage = 20;
- # Size in bytes
- function format_size($size, $round = 0)
- {
- $sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
- for ($i=0; $size > 1024 && isset($sizes[$i+1]); $i++)
- $size /= 1024;
- return round($size, $round)." ".$sizes[$i];
- }
- function browse($path)
- {
- global $servers;
- global $filesPerPage;
- $data = array();
- $page = $_GET['page'];
- $page = !isset($page) || $page < 1 ? 0 : $page - 1;
- $prefix = $servers[$path]['prefix'];
- $prefix_sz = strlen($prefix) + 1;
- $offsets = array(
- map => $prefix_sz,
- start => $prefix_sz + 11,
- end => $prefix_sz + 23
- );
- if(is_dir($path))
- {
- $files = glob($path."/*.zip");
- $count = count($files);
- $pages = ceil( $count / $filesPerPage );
- $page = $page >= $pages ? $pages - 1 : $page;
- $begin = $count - ($page + 1) * $filesPerPage;
- $end = $count - $page * $filesPerPage;
- for($i = $begin < 0 ? 0 : $begin; $i < $end; ++$i)
- {
- $file = end( explode('/', $files[$i]) );
- $name_end = strrpos($file, ".dem");
- $name_end = $name_end === FALSE ? strrpos($file, ".zip") : $name_end;
- $tmpfilesize = @filesize($files[$i]);
- if($name_end === FALSE)
- continue;
- $tmp = array();
- $tmp[map] = substr($file, $offsets[map], $name_end - $offsets[end]+1);
- $tmp[start] = substr($file, $offsets[start], 10);
- $tmp[end] = substr($file, $offsets[end], 10);
- $tmp[file] = $file;
- $tmp[size] = format_size($tmpfilesize);
- $tmp[path] = $files[$i];
- $data[] = $tmp;
- }
- $files = array();
- }
- echo '<!-- Lista dem -->
- <div class="dema" id="d1"><table style="text-align: center;"><thead>
- <tr><td colspan="6" class="day">Demka</td></tr>
- <tr>
- <th>URL</th>
- <th>Mapa</th>
- <th>Start</th>
- <th>Stop</th>
- <th>Rozmiar</th>
- <th></th>
- </tr></thead>';
- if($count > 0)
- {
- foreach($data as $field)
- {
- echo '<tr>
- <td class="url"><input type="text" value="http://'.$_SERVER[HTTP_HOST].''.$_SERVER[REQUEST_URI].''.$field[path].'"></td>
- <td>'.$field[map].'</td>
- <td>'.$field[start].'</td>
- <td>'.$field[stop].'</td>
- <td>'.$field[size].'</td>
- <td class="dl"><a href="http://'.$_SERVER[HTTP_HOST].''.$_SERVER[REQUEST_URI].''.$field[path].'">Pobierz</a></td>
- </tr>';
- }
- }
- else
- {
- echo '<tr><td align="center">- Brak demek -</td></tr>';
- }
- echo '</table><br></div>';
- if($pages > 1)
- {
- echo '<div class="pagination">';
- for($i = 0; $i < $pages; ++$i)
- {
- if($pages > 10)
- {
- if($i > 2 && $i < $page - 1)
- {
- echo '...';
- $i = $page - 1;
- }
- else
- if($i > $page + 1 && $i > 2 && $i < $pages - 3)
- {
- echo '...';
- $i = $pages - 3;
- }
- }
- if($i != $page)
- echo '<a href="?page='.($i + 1).'&server='.$path.'">'.($i + 1).'</a>';
- else
- echo '<span>'.($page + 1).'</span>';
- }
- echo '</div>';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement