summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0e57892)
raw | patch | inline | side by side (parent: 0e57892)
author | fgsfds <pvt.fgsfds@gmail.com> | |
Mon, 5 Jun 2023 16:52:12 +0000 (16:52 +0000) | ||
committer | Dmitry D. Chernov <blackdoomer@yandex.ru> | |
Tue, 6 Jun 2023 02:37:15 +0000 (12:37 +1000) |
src/mastersrv/master.c | patch | blob | history |
diff --git a/src/mastersrv/master.c b/src/mastersrv/master.c
index e27cde1f9e57815cd012a47b20d5390213a47f4f..1e1bc7b0e1d0d4a901bf6c6d562e8923d8405df6 100644 (file)
--- a/src/mastersrv/master.c
+++ b/src/mastersrv/master.c
ENetAddress addr;
addr.host = 0;
addr.port = ms_port;
- ms_host = enet_host_create(&addr, MS_MAX_CLIENTS, NET_CH_COUNT, 0, 0);
+ ms_host = enet_host_create(&addr, MS_MAX_CLIENTS, NET_CH_COUNT + 1, 0, 0);
if (!ms_host)
u_fatal("could not create enet host on port %d", ms_port);
if (!handle_msg(msgid, event.peer)) {
// cheeky cunt sending invalid messages
ban_peer(event.peer, "unknown message");
+ } else {
+ // can't reset connection right now because we still have packets to dispatch
+ enet_peer_disconnect_later(event.peer, 0);
}
break;
case ENET_EVENT_TYPE_DISCONNECT:
event.peer->data = NULL;
+ // u_log(LOG_NOTE, "%s:%d disconnected", u_iptostr(event.peer->address.host), event.peer->address.port);
break;
default:
}
const time_t now = time(NULL);
+
+ // time out servers
for (int i = 0; i < max_servers; ++i) {
if (servers[i].host) {
if (servers[i].death_time <= now) {
}
}
}
+
+ // time out clients
+ if (ms_host && ms_host->peers) {
+ for (size_t i = 0; i < ms_host->peerCount; ++i) {
+ ENetPeer *peer = ms_host->peers + i;
+ if ((peer->state >= ENET_PEER_STATE_CONNECTING && peer->state <= ENET_PEER_STATE_DISCONNECT_LATER) && peer->data) {
+ const time_t timeout = (time_t)(intptr_t)peer->data;
+ if (timeout < now) {
+ u_log(LOG_NOTE, "client %s:%d timed out", u_iptostr(peer->address.host), peer->address.port);
+ peer->data = NULL;
+ enet_peer_reset(peer);
+ }
+ }
+ }
+ }
}
}