-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameserver.php
executable file
·175 lines (167 loc) · 6.72 KB
/
gameserver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/*
* gameserver.php
*
* Copyright 2021 Jim Richardson <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
* game server start up
*/
//echo "hello there <br>";
include 'inc/master.inc.php';
$Auth = new Auth ();
$build = "6620-2864687030";
$version = "1.001";
$time = "1653110483";
$module = "Game_Server";
$user = $Auth->getAuth();
$bserver = explode('=',$_SERVER['QUERY_STRING']);
$we_are_here = $settings['url'];
if($user->loggedIn()) {
//set the sidebar option to logout;
$user_data = array (
'user_id' => $user->id,
'user_name' => $user->username,
'ip' => ip2long($_SERVER['REMOTE_ADDR']),
'start_time' => time()
) ;
if ($database->get_row('select * from allowed_users where user_id = '.$user->id)) {
$where = array('user_id' => $user->id);
unset($user_data['user_id']);
$database->update('allowed_users',$user_data,$where);
}
else {
$database->insert('allowed_users',$user_data);
}
}
else {
redirect('login.php');
}
$is[0] = 'N/A';
require DOC_ROOT. '/inc/xpaw/SourceQuery/bootstrap.php'; // load xpaw
use xPaw\SourceQuery\SourceQuery;
define( 'SQ_TIMEOUT', $settings['SQ_TIMEOUT'] );
define( 'SQ_ENGINE', SourceQuery::SOURCE );
define( 'LOG', DOC_ROOT.'/logs/ajax.log');
$bserver = trim($bserver[1]);
//echo "$bserver<br>";
$template = new template;
$sidebar_data = array();
$header_vars['title'] = "$module - $bserver";
$sql = "select * from server1 order by `host_name` ASC";
$sidebar_data['bmenu'] = '';
$sidebar_data['smenu'] = '';
$servers = $database->get_results($sql);
foreach ($servers as $server) {
$fname = trim($server['host_name']);
$href = "gameserver.php?server=$fname";
if(!$server['enabled']) {
$sidebar_data['smenu'] .='<li><a class="" href="'.$href.'" style="color:red;"><img style="width:16px;" src="'.$server['logo'].'"> '.$server['server_name'].' </a></li>';
continue;
}
$href = 'gameserver.php?server='.$server['host_name'];
if ($bserver == $server['host_name'] ) {$class = 'active';} else {$class='';}
$sidebar_data['smenu'] .='<li><a class="'.$class.'" href="'.$href.'"><img style="width:16px;" src="'.$server['logo'].'"> '.$server['server_name'].' </a></li>';
}
$sql = "select * from base_servers where `enabled` = 1 and `extraip` = 0 ORDER BY `fname` ASC";
$base_servers = $database->get_results($sql);
foreach ($base_servers as $server) {
$sidebar_data['bmenu'] .='<li><a class="" href="baseserver.php?server='.$server['fname'].'"><i class="bi bi-server" style="font-size:12px;"></i>'.$server['fname'].'</a></li>';
}
$sql = "select * from server1 where host_name = '$bserver'";
$this_server = $database->get_row($sql);
//print_r($this_server);
$this_server['cfg_file'] = str_replace(PHP_EOL,'<br>',file_get_contents($this_server['location'].'/'.$this_server['game'].'/cfg/'.$this_server['host_name'].'.cfg'));
$this_server['server_update'] = date("d-m-Y H:i:s a",$this_server['server_update']);
if ($this_server['starttime']) {$this_server['starttime'] = date("d-m-Y H:i:s a",$this_server['starttime']);}
$info = get_server_info($this_server);
$uri = parse_url($this_server['url']);
$url = $uri['scheme']."://".$uri['host'].':'.$this_server['bport'];
if(isset($uri['path'])){ $url .= $uri['path'];}
$v = json_decode(geturl("$url/api.php?action=game_detail&filter=$bserver&server=".$this_server['fname']),true); //needs replacing with ajax_send
//$info = array_merge($info,array_change_key_case($v[$bserver]));
$this_server = array_change_key_case(array_merge_recursive($this_server,$info));
$this_server['players'] -= $this_server['bots'];
//$this_server['rserver_update'] = date('d-m-y h: i:s a',$this_server['rserver_update']);
if ($this_server['secure']) {$this_server['secure'] = 'true';} else {$this_server['secure'] = 'false';}
//if(!empty($this_server['mem'])) {
// print_r($this_server);
// $this_server['mem'] .="%";
// $this_server['cpu'] .="%";
//}
$page['join_link'] = 'steam://connect/'.$this_server['host'].':'.$this_server['port'].'/';
$is = explode("\t",trim(shell_exec('du -hs '.$this_server['install_dir'])));
$this_server['install_size'] = $is[0];
$x = json_encode($this_server);
$sidebar_data['servers'] = 'Game Servers';
$sidebar_data['base_servers'] = 'Base Servers';
$page['title'] = "Game Server $bserver";
$template->load('templates/subtemplates/header.html'); // load header
$template->replace_vars($header_vars);
$page['header'] = $template->get_template();
$template->load('templates/subtemplates/sidebar.html'); //sidebar
$template->replace_vars($sidebar_data);
$page['sidebar'] =$template->get_template();
$template->load('templates/subtemplates/footer.html');
$page['footer'] = $template->get_template();
$page['bserver'] = $bserver;
$page['url'] = $url;
//$v = json_decode(geturl($this_server['url'].'/ajaxv2.php?action=game_detail&filter='.$bserver),true);
//$v[$bserver] = array_change_key_case($v[$bserver]);
//die(print_r($v,true));
$template->load('templates/gameserver.html');
$template->replace_vars($page);
$template->replace_vars($this_server);
//die('just about to publish');
//$template->replace_vars($v[$bserver]);
$template->publish();
function get_server_info($server) {
// return xpaw info
$xpaw = new SourceQuery( );
try
{
$xpaw->Connect( $server['host'], $server['port'], SQ_TIMEOUT, SQ_ENGINE );
$sub_cmd = 'GetInfo';
$info = $xpaw->GetInfo();
if ($info['Players'] > 0) {
// get player list
$players = $xpaw->GetPlayers();
if(!empty($players)) {$info['player_list'] = $players;}
}
$rules = $xpaw->GetRules();
$info['vars'] = $rules;
}
catch( Exception $e )
{
$Exception = $e;
if (strpos($Exception,'Failed to read any data from socket'))
{
$Exception = 'Failed to read any data from socket Module (Ajax - get_server_info '.$sub_cmd.')';
//file_put_contents(LOG,$Exception,PHP_EOL,FILE_APPEND);
}
$info['l_status'] = 'offline';
$info['steamid'] = 'N/A';
$info['map'] = 'N/A';
$info['hostname'] = 'N/A';
$xpaw->Disconnect();
return $info;
}
$info['l_status'] = 'online';
$xpaw->Disconnect();
return $info;
}
?>