]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/natsub.c
Update known contributors comments
[empserver] / src / lib / subs / natsub.c
index 5247e3d4d0bedca855f29d1e8a8810f1709934d3..ad4a0def51c9a8a7f48e0e302c7a962cfdc6a75a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *
  *  Known contributors to this file:
  *     Markus Armbruster, 2008
+ *     Ron Koenderink, 2008-2009
  */
 
 #include <config.h>
 
 #include <string.h>
+#include <ctype.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -41,6 +43,7 @@
 #include "game.h"
 #include "nat.h"
 #include "optlist.h"
+#include "prototypes.h"
 #include "tel.h"
 #include "xy.h"
 
@@ -84,7 +87,6 @@ nat_reset(struct natstr *natp, enum nat_status stat, coord x, coord y)
        natp->nat_yorg = 0;
     }
 
-    natp->nat_dayno = 0;
     natp->nat_timeused = 0;
     natp->nat_update = 0;
 
@@ -97,7 +99,7 @@ nat_reset(struct natstr *natp, enum nat_status stat, coord x, coord y)
     game_tick_to_now(&natp->nat_access);
     natp->nat_reserve = 0;
     natp->nat_money = stat == STAT_SANCT ? start_cash : 0;
-    natp->nat_last_login = natp->nat_last_login = 0;
+    natp->nat_last_login = natp->nat_last_logout = 0;
     natp->nat_newstim = 0;
     natp->nat_annotim = 0;
     natp->nat_level[NAT_HLEV] = start_happiness;
@@ -113,3 +115,38 @@ nat_reset(struct natstr *natp, enum nat_status stat, coord x, coord y)
 
     return natp;
 }
+
+int
+check_nat_name(char *cname)
+{
+    struct natstr *natp;
+    natid cn;
+    int allblank;
+    char *p;
+
+    if (strlen(cname) >= sizeof(natp->nat_cnam)) {
+       pr("Country name too long\n");
+       return 0;
+    }
+
+    allblank = 1;
+    for (p = cname; *p != '\0'; p++) {
+       if (iscntrl(*p)) {
+           pr("No control characters allowed in country names!\n");
+           return 0;
+       } else if (!isspace(*p))
+           allblank = 0;
+    }
+    if (allblank) {
+       pr("Country name can't be all blank\n");
+       return 0;
+    }
+
+    for (cn = 0; NULL != (natp = getnatp(cn)); cn++) {
+       if (!strcmp(cname, natp->nat_cnam)) {
+           pr("Country #%d is already called `%s'\n", cn, cname);
+           return 0;
+       }
+    }
+    return 1;
+}