Skip to content

Commit 58969ac

Browse files
authored
Merge branch 'release/2.1.0' into feature/periodic-tasks
2 parents 99384cf + 0d8ba1d commit 58969ac

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

public/js/status.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* @param {Object} data
3737
*/
3838
const clientConnected = (data) => {
39-
elClientList.append(new Option(`${data.ip}:${data.port}`, data.port));
39+
elClientList.append(new Option(data.client, data.client));
4040
elClientCount.textContent = data.clientCount;
4141
};
4242

@@ -46,7 +46,7 @@
4646
*/
4747
const clientDisconnected = (data) => {
4848
[...elClientList.options].some((option, index) => {
49-
if (parseInt(option.value) === data.port) {
49+
if (option.value === data.client) {
5050
elClientList.options[index].remove();
5151
return true;
5252
}
@@ -63,19 +63,21 @@
6363
elMaxClients.textContent = serverinfo.maxClients;
6464
elMaxConnections.textContent = serverinfo.maxConnectionsPerIp;
6565
elMaxRequetsPerMinute.textContent = serverinfo.maxRequetsPerMinute;
66-
for (let port in serverinfo.clients) {
67-
let ip = serverinfo.clients[port];
68-
elClientList.append(new Option(ip + ':' + port, port));
66+
for (let client in serverinfo.clients) {
67+
if (!serverinfo.clients.hasOwnProperty(client)) {
68+
continue;
69+
}
70+
elClientList.append(new Option(client, client));
6971
}
7072
};
7173

7274
/**
7375
* Indicate client activity by animating/blinking entry in clients-list.
74-
* @param {int} port
76+
* @param {string} port
7577
*/
76-
const clientActivity = (port) => {
78+
const clientActivity = (client) => {
7779
[...elClientList.options].some((option, index) => {
78-
if (parseInt(option.value) === port) {
80+
if (option.value === client) {
7981
elClientList.options[index].style.color = 'red';
8082
setTimeout(() => {
8183
if (elClientList.options[index]) {

src/Application/StatusApplication.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ public function setServerInfo(array $serverInfo): bool
9797
*/
9898
public function clientConnected(string $ip, int $port): void
9999
{
100-
$this->serverClients[$port] = $ip;
100+
$client = $ip . ':' . $port;
101+
$this->serverClients[$client] = true;
101102
$this->serverClientCount++;
102-
$this->statusMsg('Client connected: ' . $ip . ':' . $port);
103+
$this->statusMsg('Client connected: ' . $client);
103104
$data = [
104-
'ip' => $ip,
105-
'port' => $port,
105+
'client' => $client,
106106
'clientCount' => $this->serverClientCount,
107107
];
108108
$encodedData = $this->encodeData('clientConnected', $data);
@@ -118,14 +118,15 @@ public function clientConnected(string $ip, int $port): void
118118
*/
119119
public function clientDisconnected(string $ip, int $port): void
120120
{
121-
if (!isset($this->serverClients[$port])) {
121+
$client = $ip . ':' . $port;
122+
if (!isset($this->serverClients[$client])) {
122123
return;
123124
}
124-
unset($this->serverClients[$port]);
125+
unset($this->serverClients[$client]);
125126
$this->serverClientCount--;
126-
$this->statusMsg('Client disconnected: ' . $ip . ':' . $port);
127+
$this->statusMsg('Client disconnected: ' . $client);
127128
$data = [
128-
'port' => $port,
129+
'client' => $client,
129130
'clientCount' => $this->serverClientCount,
130131
];
131132
$encodedData = $this->encodeData('clientDisconnected', $data);
@@ -135,12 +136,12 @@ public function clientDisconnected(string $ip, int $port): void
135136
/**
136137
* This method will be called by server whenever there is activity on a port.
137138
*
138-
* @param int $port
139+
* @param string $client
139140
* @return void
140141
*/
141-
public function clientActivity(int $port): void
142+
public function clientActivity(string $client): void
142143
{
143-
$encodedData = $this->encodeData('clientActivity', $port);
144+
$encodedData = $this->encodeData('clientActivity', $client);
144145
$this->sendAll($encodedData);
145146
}
146147

src/Connection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ private function handle(string $data): bool
249249

250250
// trigger status application:
251251
if ($this->server->hasApplication('status')) {
252-
$this->server->getApplication('status')->clientActivity($this->port);
252+
$client = $this->ip . ':' . $this->port;
253+
$this->server->getApplication('status')->clientActivity($client);
253254
}
254255

255256
if (!isset($decodedData['type'])) {

src/Server.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ protected function createConnection($resource): Connection
9696
public function run(): void
9797
{
9898
while (true) {
99-
$changed_sockets = $this->allsockets;
100-
@stream_select($changed_sockets, $write = null, $except = null, 0, 5000);
10199
$this->timers->runAll();
100+
101+
$changed_sockets = $this->allsockets;
102+
@stream_select($changed_sockets, $write, $except, 0, 5000);
102103
foreach ($changed_sockets as $socket) {
103104
if ($socket == $this->master) {
104105
if (($ressource = stream_socket_accept($this->master)) === false) {

0 commit comments

Comments
 (0)