]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/add.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / lib / commands / add.c
index 5b45d1bf2c33723cef025067dd737508f198f6a8..dc5febbd8eac788ba006ce1ebae78fbd1aa87ac9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *     
  */
 
+#include <config.h>
+
 #include <stdio.h>
+#include <string.h>
 #include "misc.h"
 #include "player.h"
-#include "var.h"
+#include "plague.h"
 #include "sect.h"
 #include "nat.h"
 #include "xy.h"
@@ -52,97 +55,88 @@ add(void)
     struct natstr *natp;
     struct sctstr sect;
     struct nstr_sect nstr;
-    register int i;
-    s_char cntryname[21];
-    s_char pname[21];
+    int i;
+    char cntryname[sizeof(natp->nat_cnam)];
+    char pname[sizeof(natp->nat_pnam)];
     natid coun;
     natid freecn;
-    s_char prompt[128];
-    s_char buf[1024];
-    s_char *p;
-    s_char loopflag;
+    char prompt[128];
+    char buf[1024];
+    char *p;
     int stat;
     struct nstr_item ni;
     struct lndstr land;
+    struct realmstr realm;
+    time_t current_time = time(NULL);
 
     for (freecn = 0; NULL != (natp = getnatp(freecn)); freecn++) {
-       if ((natp->nat_stat & STAT_INUSE) == 0)
+       if (natp->nat_stat == STAT_UNUSED)
            break;
     }
     if (freecn < MAXNOC)
        sprintf(prompt, "New country number? (%d is unused) ", freecn);
     else
        strcpy(prompt, "New country number? (they all seem to be used) ");
-    while ((p = getstarg(player->argp[1], prompt, buf)) && *p) {
-       coun = atoi(p);
-       if (coun < MAXNOC)
-           break;
-       pr("Max # countries is %d\n", MAXNOC);
-       player->argp[1] = 0;
-    }
+    p = getstarg(player->argp[1], prompt, buf);
     if (p == 0 || *p == 0)
+       return RET_SYN;
+    i = atoi(p);
+    if (i >= MAXNOC) {
+       pr("Max # countries is %d\n", MAXNOC);
        return RET_FAIL;
+    }
+    coun = i;
     if (coun == 0) {
        pr("Not allowed to add country #0\n");
        return RET_FAIL;
     }
     natp = getnatp(coun);
-    while ((p = getstarg(player->argp[2], "Country Name? ", buf)) && *p) {
-       if (strlen(p) < 20) {
-           (void)strcpy(cntryname, p);
-           break;
-       }
-       pr("Too long.\n");
-       player->argp[2] = 0;
+    p = getstarg(player->argp[2], "Country Name? ", buf);
+    if (p == 0 || *p == 0)
+       return RET_SYN;
+    if (strlen(p) >= sizeof(cntryname)) {
+       pr("Country name too long\n");
+       return RET_FAIL;
     }
+    strcpy(cntryname, p);
+    p = getstarg(player->argp[3], "Representative? ", buf);
     if (p == 0 || *p == 0)
-       return RET_OK;
-    while ((p = getstarg(player->argp[3], "Representative? ", buf)) && *p) {
-       if (strlen(p) < 20) {
-           (void)strcpy(pname, p);
-           break;
-       }
-       pr("Too long.\n");
-       player->argp[3] = 0;
+       return RET_SYN;
+    if (strlen(p) >= sizeof(pname)) {
+       pr("Representative too long\n");
+       return RET_FAIL;
     }
+    strcpy(pname, p);
+    p = getstarg(player->argp[4],
+                "Status? (visitor, new, active, god, delete) ", buf);
     if (p == 0 || *p == 0)
-       return RET_OK;
-    loopflag = 1;
-    stat = natp->nat_stat;
-    strcpy(prompt, "Status? (visitor, new, active, god, delete) ");
-    while (loopflag && (p = getstarg(player->argp[4], prompt, buf))) {
-       loopflag = 0;
-       switch (*p) {
-       case 'v':
-           stat = STAT_INUSE;
-           break;
-       case 'n':
-           stat = STAT_NEW | STAT_INUSE;
-           break;
-       case 'a':
-           stat = STAT_NORM | STAT_INUSE;
-           break;
-       case 'g':
-           stat = STAT_GOD | STAT_NORM | STAT_INUSE;
-           break;
-       case 'd':
-           stat = 0;
-           break;
-       default:
-           pr("Illegal selection\n");
-           loopflag = 1;
-           break;
-       }
-       player->argp[4] = 0;
+       return RET_SYN;
+    switch (*p) {
+    case 'v':
+       stat = STAT_VIS;
+       break;
+    case 'n':
+       stat = STAT_NEW;
+       break;
+    case 'a':
+       stat = STAT_ACTIVE;
+       break;
+    case 'g':
+       stat = STAT_GOD;
+       break;
+    case 'd':
+       stat = STAT_UNUSED;
+       break;
+    default:
+       pr("Illegal status\n");
+       return RET_SYN;
     }
-    if (p == 0)
-       return RET_OK;
     p = getstarg(player->argp[5],
                 "Check, wipe, or ignore existing sectors (c|w|i) ", buf);
     if (p == 0)
-       return RET_OK;
+       return RET_SYN;
     snxtitem_all(&ni, EF_LAND);
-    while (nxtitem(&ni, (s_char *)&land)) {
+    while (nxtitem(&ni, &land)) {
        if (land.lnd_own == coun) {
            makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
                     land.lnd_y);
@@ -171,15 +165,24 @@ add(void)
                sect.sct_defense = 0;
                sect.sct_own = 0;
                sect.sct_oldown = 0;
-               if (sect.sct_type != SCT_MOUNT &&
-                   sect.sct_type != SCT_PLAINS) {
-                   sect.sct_type = SCT_RURAL;
-                   sect.sct_newtype = SCT_RURAL;
-               }
+               if (sect.sct_type == SCT_BSPAN ||
+                   sect.sct_type == SCT_BTOWER)
+                   sect.sct_newtype = sect.sct_type = SCT_WATER;
+               else if (sect.sct_type != SCT_MOUNT &&
+                   sect.sct_type != SCT_PLAINS)
+                   sect.sct_newtype = sect.sct_type = SCT_RURAL;
                /* No dist path */
                sect.sct_dist_x = sect.sct_x;
                sect.sct_dist_y = sect.sct_y;
-               sect.sct_nv = 0;
+               memset(sect.sct_item, 0, sizeof(sect.sct_item));
+               memset(sect.sct_del, 0, sizeof(sect.sct_del));
+               memset(sect.sct_dist, 0, sizeof(sect.sct_dist));
+               sect.sct_mines = 0;
+               sect.sct_pstage = PLG_HEALTHY;
+               sect.sct_ptime = 0;
+               sect.sct_che = 0;
+               sect.sct_che_target = 0;
+               sect.sct_fallout = 0;
                putsect(&sect);
                pr("wiped\n");
            } else {
@@ -188,26 +191,26 @@ add(void)
        }
     }
 
-    if ((natp->nat_stat & (STAT_INUSE | STAT_NORM | STAT_GOD)) ==
-       STAT_INUSE) {
+    if (natp->nat_stat == STAT_NEW || natp->nat_stat == STAT_VIS) {
        *natp->nat_hostaddr = '\0';
        *natp->nat_hostname = '\0';
        *natp->nat_userid = '\0';
        natp->nat_btu = 0;
-       natp->nat_connected = 0;
        natp->nat_reserve = 0;
        natp->nat_tgms = 0;
-       natp->nat_ystart = 0;
-       natp->nat_xstart = 0;
        natp->nat_ycap = 0;
        natp->nat_xcap = 0;
        natp->nat_yorg = 0;
        natp->nat_xorg = 0;
        natp->nat_dayno = 0;
        natp->nat_minused = 0;
-       memset(natp->nat_b, 0, sizeof(natp->nat_b));
-       (void)time(&natp->nat_last_login);
-       (void)time(&natp->nat_last_logout);
+       for (i = 0; i < MAXNOR; i++) {
+           getrealm(i, coun, &realm);
+           realm.r_xl = realm.r_xh = realm.r_yl = realm.r_yh = 0;
+           realm.r_timestamp = current_time;
+           putrealm(&realm);
+       }
+       natp->nat_last_login = natp->nat_last_login = 0;
        natp->nat_money = 0;
        natp->nat_level[NAT_TLEV] = start_technology;
        natp->nat_level[NAT_RLEV] = start_research;
@@ -221,7 +224,7 @@ add(void)
     } else
        pr("No special initializations done...\n");
 
-    for (i = 0; i < SCT_MAXDEF + 8; i++)
+    for (i = 0; i <= PRI_MAX; i++)
        natp->nat_priorities[i] = -1;
     natp->nat_flags =
        NF_FLASH | NF_BEEP | NF_COASTWATCH | NF_SONAR | NF_TECHLISTS;