aboutsummaryrefslogtreecommitdiffstats
path: root/src/server/Main.hx
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2020-06-03 14:56:44 +0300
committerRblSb <msrblsb@gmail.com>2020-06-03 14:56:44 +0300
commitf70382462d69db15e11e642b5f8c5baa9357133a (patch)
tree37d0a42588c7869d9ae7ed585db9f057c97c0498 /src/server/Main.hx
parent6bb620cb803a6587dcbacc4a3360cbf3d75f3064 (diff)
Detect broken connections
Diffstat (limited to 'src/server/Main.hx')
-rw-r--r--src/server/Main.hx15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/server/Main.hx b/src/server/Main.hx
index 6c7753c..ee4d478 100644
--- a/src/server/Main.hx
+++ b/src/server/Main.hx
@@ -101,6 +101,20 @@ class Main {
server.listen(port);
wss = new WSServer({server: server});
wss.on("connection", onConnect);
+
+ new Timer(25000).run = () -> {
+ for (client in clients) {
+ if (client.isAlive) {
+ client.isAlive = false;
+ client.ws.ping();
+ continue;
+ }
+ client.ws.terminate();
+ onMessage(client, {
+ type: Disconnected
+ }, true);
+ }
+ };
}
public function exit():Void {
@@ -276,6 +290,7 @@ class Main {
final client = new Client(ws, req, id, name, 0);
client.isAdmin = isAdmin;
clients.push(client);
+ ws.on("pong", () -> client.isAlive = true);
onMessage(client, {
type: Connected
}, true);
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage