]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/natsub.c
Update copyright notice
[empserver] / src / lib / subs / natsub.c
index 8a676f23394a30a5858830a08674013354650660..cdec7a40446017b7d13c75164ea0cc3cc281c6c4 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
@@ -34,6 +34,7 @@
 #include <config.h>
 
 #include <string.h>
+#include <ctype.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -41,6 +42,7 @@
 #include "game.h"
 #include "nat.h"
 #include "optlist.h"
+#include "prototypes.h"
 #include "tel.h"
 #include "xy.h"
 
@@ -84,7 +86,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;
 
@@ -113,3 +114,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;
+}