127 while($this->stop !==
true){
128 $this->
synchronized(
function(){
131 $r = [$socket = $this->socket];
134 if(socket_select($r, $w, $e, 0) === 1){
135 if(($client = socket_accept($this->socket)) !==
false){
136 socket_set_block($client);
137 socket_set_option($client, SOL_SOCKET, SO_KEEPALIVE, 1);
139 for($n = 0; $n < $this->maxClients; ++$n){
140 if($this->{
"client" . $n} === null){
141 $this->{
"client" . $n} = $client;
142 $this->{
"status" . $n} = 0;
143 $this->{
"timeout" . $n} = microtime(
true) + 5;
149 @socket_close($client);
154 for($n = 0; $n < $this->maxClients; ++$n){
155 $client = &$this->{
"client" . $n};
156 if($client !== null){
157 if($this->{
"status" . $n} !== -1 and $this->stop !==
true){
158 if($this->{
"status" . $n} === 0 and $this->{
"timeout" . $n} < microtime(
true)){
159 $this->{
"status" . $n} = -1;
162 $p = $this->readPacket($client, $size, $requestID, $packetType, $payload);
164 $this->{
"status" . $n} = -1;
166 }elseif($p === null){
172 if($this->{
"status" . $n} !== 1){
173 $this->{
"status" . $n} = -1;
177 $this->response =
"";
182 if($this->{
"status" . $n} !== 1){
183 $this->{
"status" . $n} = -1;
187 "serverStatus" => unserialize($this->serverStatus),
188 "logger" => str_replace(
"\n",
"\r\n", trim($this->logger->getMessages()))
190 $this->writePacket($client, $requestID, 0, serialize($res));
191 $this->response =
"";
194 if($this->{
"status" . $n} !== 0){
195 $this->{
"status" . $n} = -1;
198 if($payload === $this->password){
199 socket_getpeername($client, $addr, $port);
200 $this->response =
"[INFO] Successful Rcon connection from: /$addr:$port";
201 $this->response =
"";
202 $this->writePacket($client, $requestID, 2,
"");
203 $this->{
"status" . $n} = 1;
205 $this->{
"status" . $n} = -1;
206 $this->writePacket($client, -1, 2,
"");
211 if($this->{
"status" . $n} !== 1){
212 $this->{
"status" . $n} = -1;
215 if(strlen($payload) > 0){
216 $this->cmd = ltrim($payload);
217 $this->
synchronized(
function(){
218 $this->waiting =
true;
221 $this->waiting =
false;
222 $this->writePacket($client, $requestID, 0, str_replace(
"\n",
"\r\n", trim($this->response)));
223 $this->response =
"";
230 @socket_set_option($client, SOL_SOCKET, SO_LINGER, [
"l_onoff" => 1,
"l_linger" => 1]);
231 @socket_shutdown($client, 2);
232 @socket_set_block($client);
233 @socket_read($client, 1);
234 @socket_close($client);
235 $this->{
"status" . $n} = 0;
236 $this->{
"client" . $n} = null;
241 unset($this->socket, $this->cmd, $this->response, $this->stop);