DEADSOFTWARE

Master: Sleep for more than 1ms when idle
[d2df-sdl.git] / src / mastersrv / master.c
index 9745694cef8c88a08005f5833e314cfab92d8298..1dfed7ddfa601eb7ad72d6e54565cc6fe6259481 100644 (file)
@@ -50,8 +50,8 @@ struct ms_server_s {
 typedef struct ms_server_s ms_server;
 
 const char ms_game_ver[] = "0.63";
-char ms_motd[256] = "";
-char ms_urgent[256] = "";
+char ms_motd[255] = "";
+char ms_urgent[255] = "";
 
 int ms_port = 25660;
 int ms_timeout = 100000;
@@ -141,8 +141,18 @@ void d_getargs (int argc, char *argv[]) {
 
 int d_readtextfile (const char *fname, char *buf, size_t max) {
   FILE *f = fopen(fname, "r");
+  char *const end = buf + max - 1;
+  char *p = buf;
   if (f) {
-    fgets(buf, max, f);
+    char ln[max];
+    char *const lend = ln + max - 1;
+    while(p < end && fgets(ln, sizeof(ln), f)) {
+      for (char *n = ln; n < lend && *n && *n != '\r' && *n != '\n'; ++n) {
+        *(p++) = *n;
+        if (p == end) break;
+      }
+    }
+    *p = '\0';
     fclose(f);
     return 0;
   }
@@ -268,7 +278,7 @@ int main (int argc, char *argv[]) {
   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);