diff --git a/src/mastersrv/master.c b/src/mastersrv/master.c
index 304f6b532ff2f0957187ea75c5326fb57a803e9b..ca1c129895cb851f83c68d026288706b462bf011 100644 (file)
--- a/src/mastersrv/master.c
+++ b/src/mastersrv/master.c
#include <string.h>
#include <enet/enet.h>
#include <enet/types.h>
+#include <time.h>
#define MS_VERSION "0.2"
#define MS_MAXSRVS 128
enet_uint8 s_mode;
enet_uint8 s_protocol;
enet_uint16 s_port;
- enet_uint32 ttl;
+ time_t deathtime;
};
typedef struct ms_server_s ms_server;
char ms_urgent[255] = "";
int ms_port = 25660;
-int ms_timeout = 100000;
+int ms_timeout = 100;
size_t b_read = 0;
size_t b_write = 0;
ms_port = atoi(argv[++i]);
}
} else if (!strcmp(argv[i], "-t") & (i + 1 < argc)) {
- ms_timeout = atoi(argv[++i]) * 1000;
+ ms_timeout = atoi(argv[++i]);
}
}
}
ms_srv[i].s_ip[0] = '\0';
ms_srv[i].s_name[0] = '\0';
ms_srv[i].s_map[0] = '\0';
- ms_srv[i].ttl = 0;
+ ms_srv[i].deathtime = 0;
}
ENetAddress addr;
enet_uint8 proto = 0;
enet_uint8 pw = 0;
while (!shutdown) {
- while (enet_host_service(ms_host, &event, 1) > 0) {
+ while (enet_host_service(ms_host, &event, 5000) > 0) {
switch (event.type) {
case ENET_EVENT_TYPE_CONNECT:
printf(LC_MS_CONN, event.peer->address.host, event.peer->address.port);
ms_srv[i].s_pw = pw;
ms_srv[i].s_mode = gm;
- ms_srv[i].ttl = ms_timeout;
+ ms_srv[i].deathtime = time(NULL) + ms_timeout;
printf(LC_MS_UPD, i, ip, port, name, map, gm, pl, mpl, proto, pw);
break;
ms_srv[i].s_pw = pw;
ms_srv[i].s_mode = gm;
ms_srv[i].s_protocol = proto;
- ms_srv[i].ttl = ms_timeout;
+ ms_srv[i].deathtime = time(NULL) + ms_timeout;
ms_srv[i].used = 1;
}
}
+ time_t now = time(NULL);
for (int i = 0; i < MS_MAXSRVS; ++i) {
if (ms_srv[i].used) {
- if (--(ms_srv[i].ttl) == 0) {
+ if (ms_srv[i].deathtime <= now) {
ms_srv[i].used = 0;
printf(LC_MS_TIME, i, ms_srv[i].s_ip, ms_srv[i].s_port);
--ms_count;