src/lib/commands/chan.c

Go to the documentation of this file.
00001 /*
00002  *  Empire - A multi-player, client/server Internet based war game.
00003  *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
00004  *                           Ken Stevens, Steve McClure
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  *  ---
00021  *
00022  *  See files README, COPYING and CREDITS in the root of the source
00023  *  tree for related information and legal notices.  It is expected
00024  *  that future projects/authors will amend these files as needed.
00025  *
00026  *  ---
00027  *
00028  *  chan.c: Change country/representative name
00029  * 
00030  *  Known contributors to this file:
00031  *     Steve McClure, 2000
00032  */
00033 
00034 #include <config.h>
00035 
00036 #include "commands.h"
00037 #include "news.h"
00038 #include "optlist.h"
00039 #include <ctype.h>
00040 
00041 int
00042 chan(void)
00043 {
00044     char *temp;
00045     struct natstr *natp;
00046     char *p;
00047     natid cn;
00048     int charge;
00049     int nonb;
00050     int btucost;
00051     char buf[1024];
00052     struct natstr *us;
00053 
00054     if ((p =
00055          getstarg(player->argp[1], "country name or representative? ",
00056                   buf)) == 0)
00057         return RET_SYN;
00058     us = getnatp(player->cnum);
00059     if (us->nat_stat == STAT_VIS) {
00060         pr("Visitor countries can't change their country name or representative.\n");
00061         return RET_FAIL;
00062     }
00063     switch (*p) {
00064     case 'n':
00065     case 'c':
00066         charge = 0;
00067         btucost = 0;
00068         if (us->nat_stat == STAT_ACTIVE) {
00069             if (opt_BLITZ == 0) {
00070                 if (us->nat_btu < 254) {
00071                     pr("You need 254 btus to change your country name!\n");
00072                     return RET_FAIL;
00073                 }
00074                 pr("This command costs 254 BTU's and 10%% of your money.\n");
00075                 if (!confirm("Are you sure you want to do this? "))
00076                     return RET_FAIL;
00077                 btucost = 254;
00078                 if (us->nat_money <= 0)
00079                     charge = 0;
00080                 else
00081                     charge = us->nat_money / 10;
00082             }
00083         }
00084         if ((p =
00085              getstarg(player->argp[2], "New country name -- ", buf)) == 0)
00086             return RET_SYN;
00087         p[sizeof(us->nat_cnam) - 1] = 0;
00088         for (cn = 0; NULL != (natp = getnatp(cn)); cn++) {
00089             if (!strcmp(p, natp->nat_cnam)) {
00090                 pr("Country #%d is already called `%s'!\n", cn, p);
00091                 return RET_FAIL;
00092             }
00093         }
00094         nonb = 0;
00095         for (temp = p; *temp != '\0'; temp++) {
00096             if (iscntrl(*temp)) {
00097                 pr("No control characters allowed in country names!\n");
00098                 return RET_FAIL;
00099             } else if (*temp != ' ')
00100                 nonb = 1;
00101         }
00102         if (!nonb) {
00103             pr("Must have a non-blank name!\n");
00104             return RET_FAIL;
00105         }
00106         player->dolcost += charge;
00107         player->btused += btucost;
00108         strcpy(us->nat_cnam, p);
00109         putnat(us);
00110         nreport(player->cnum, N_NAME_CHNG, 0, 1);
00111         break;
00112     case 'p':
00113     case 'r':
00114         pr("(note: these are stored in plain text.)\n");
00115         if ((p = getstarg(player->argp[2],
00116                           "New representative name -- ", buf)) == 0)
00117             return RET_SYN;
00118         p[sizeof(us->nat_pnam) - 1] = 0;
00119         strcpy(us->nat_pnam, p);
00120         putnat(us);
00121         break;
00122     default:
00123         pr("Only \"country\" or \"representative\" can change.\n");
00124         return RET_SYN;
00125     }
00126     return RET_OK;
00127 }

Generated on Fri Mar 28 11:01:11 2008 for empserver by  doxygen 1.5.2