src/lib/common/check.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  *  check.c: Check a sector, plane, land unit, ship or nuke
00029  * 
00030  *  Known contributors to this file:
00031  *     Steve McClure, 1998
00032  */
00033 
00034 #include <config.h>
00035 
00036 #include "commodity.h"
00037 #include "file.h"
00038 #include "land.h"
00039 #include "loan.h"
00040 #include "misc.h"
00041 #include "nat.h"
00042 #include "nsc.h"
00043 #include "nuke.h"
00044 #include "plane.h"
00045 #include "player.h"
00046 #include "prototypes.h"
00047 #include "sect.h"
00048 #include "ship.h"
00049 #include "trade.h"
00050 #include "xy.h"
00051 
00052 /* Note that timestamps make things tricky.  And, we don't
00053  * really care about the timestamp, we just care about the rest
00054  * of the structure.  So, we make a copy, and zero the timestamps
00055  * in both copies, and then compare. */
00056 
00057 int
00058 check_sect_ok(struct sctstr *sectp)
00059 {
00060     struct sctstr chksect;
00061     struct sctstr tsect;
00062 
00063     getsect(sectp->sct_x, sectp->sct_y, &chksect);
00064     memcpy(&tsect, sectp, sizeof(struct sctstr));
00065     tsect.sct_timestamp = chksect.sct_timestamp = 0;
00066     if (memcmp(&tsect, &chksect, sizeof(struct sctstr))) {
00067         pr("Sector %s has changed!\n",
00068            xyas(sectp->sct_x, sectp->sct_y, player->cnum));
00069         return 0;
00070     }
00071     return 1;
00072 }
00073 
00074 int
00075 check_ship_ok(struct shpstr *shipp)
00076 {
00077     struct shpstr chkship;
00078     struct shpstr tship;
00079 
00080     getship(shipp->shp_uid, &chkship);
00081     memcpy(&tship, shipp, sizeof(struct shpstr));
00082     tship.shp_timestamp = chkship.shp_timestamp = 0;
00083     if (memcmp(&tship, &chkship, sizeof(struct shpstr))) {
00084         pr("Ship #%d has changed!\n", shipp->shp_uid);
00085         return 0;
00086     }
00087     return 1;
00088 }
00089 
00090 int
00091 check_plane_ok(struct plnstr *planep)
00092 {
00093     struct plnstr chkplane;
00094     struct plnstr tplane;
00095 
00096     getplane(planep->pln_uid, &chkplane);
00097     memcpy(&tplane, planep, sizeof(struct plnstr));
00098     tplane.pln_timestamp = chkplane.pln_timestamp = 0;
00099     if (memcmp(&tplane, &chkplane, sizeof(struct plnstr))) {
00100         pr("Plane #%d has changed!\n", planep->pln_uid);
00101         return 0;
00102     }
00103     return 1;
00104 }
00105 
00106 int
00107 check_land_ok(struct lndstr *landp)
00108 {
00109     struct lndstr chkland;
00110     struct lndstr tland;
00111 
00112     getland(landp->lnd_uid, &chkland);
00113     memcpy(&tland, landp, sizeof(struct lndstr));
00114     tland.lnd_timestamp = chkland.lnd_timestamp = 0;
00115     if (memcmp(&tland, &chkland, sizeof(struct lndstr))) {
00116         pr("Land unit #%d has changed!\n", landp->lnd_uid);
00117         return 0;
00118     }
00119     return 1;
00120 }
00121 
00122 int
00123 check_nuke_ok(struct nukstr *nukep)
00124 {
00125     struct nukstr chknuke;
00126     struct nukstr tnuke;
00127 
00128     getnuke(nukep->nuk_uid, &chknuke);
00129     memcpy(&tnuke, nukep, sizeof(struct nukstr));
00130     tnuke.nuk_timestamp = chknuke.nuk_timestamp = 0;
00131     if (memcmp(&tnuke, &chknuke, sizeof(struct nukstr))) {
00132         pr("Nuke %d has changed!\n", nukep->nuk_uid);
00133         return 0;
00134     }
00135     return 1;
00136 }
00137 
00138 int
00139 check_loan_ok(struct lonstr *loanp)
00140 {
00141     struct lonstr chkloan;
00142 
00143     getloan(loanp->l_uid, &chkloan);
00144     if (memcmp(loanp, &chkloan, sizeof(struct lonstr))) {
00145         pr("Loan %d has changed!\n", loanp->l_uid);
00146         return 0;
00147     }
00148     return 1;
00149 }
00150 
00151 int
00152 check_comm_ok(struct comstr *commp)
00153 {
00154     struct comstr chkcomm;
00155 
00156     getcomm(commp->com_uid, &chkcomm);
00157     if (memcmp(commp, &chkcomm, sizeof(struct comstr))) {
00158         pr("Commodity %d has changed!\n", commp->com_uid);
00159         return 0;
00160     }
00161     return 1;
00162 }
00163 
00164 int
00165 check_trade_ok(struct trdstr *tp)
00166 {
00167     struct trdstr chktrade;
00168 
00169     gettrade(tp->trd_uid, &chktrade);
00170     if (memcmp(tp, &chktrade, sizeof(struct trdstr))) {
00171         pr("Trade lot #%d has changed!\n", tp->trd_uid);
00172         return 0;
00173     }
00174     return 1;
00175 }

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