summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 883536c)
raw | patch | inline | side by side (parent: 883536c)
author | fgsfds <pvt.fgsfds@gmail.com> | |
Sun, 18 Aug 2019 20:07:32 +0000 (23:07 +0300) | ||
committer | fgsfds <pvt.fgsfds@gmail.com> | |
Sun, 18 Aug 2019 20:07:55 +0000 (23:07 +0300) |
src/mastersrv/master.c | patch | blob | history |
diff --git a/src/mastersrv/master.c b/src/mastersrv/master.c
index 1dfed7ddfa601eb7ad72d6e54565cc6fe6259481..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;
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;