You can subscribe to this list here.
2004 |
Jan
(49) |
Feb
(121) |
Mar
(88) |
Apr
(36) |
May
(27) |
Jun
(55) |
Jul
(3) |
Aug
(40) |
Sep
(30) |
Oct
(54) |
Nov
(35) |
Dec
(21) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(71) |
Feb
(15) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
(5) |
Nov
|
Dec
|
2006 |
Jan
|
Feb
(1) |
Mar
(38) |
Apr
(2) |
May
(3) |
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(21) |
Jul
(3) |
Aug
|
Sep
|
Oct
|
Nov
(2) |
Dec
|
2008 |
Jan
(14) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Frans S. <gu...@us...> - 2008-01-18 21:12:32
|
Update of /cvsroot/galaxyng/NG_Stable/Source In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv24640 Modified Files: Makefile Log Message: Added indent target Index: Makefile =================================================================== RCS file: /cvsroot/galaxyng/NG_Stable/Source/Makefile,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Makefile 17 Jan 2008 23:18:19 -0000 1.1 --- Makefile 18 Jan 2008 21:12:33 -0000 1.2 *************** *** 206,209 **** --- 206,212 ---- etags $(SOURCES) + indent: + indent *.c + depend: -@makedepend -Y -- $(CFLAGS) -- $(GNG_SRCS) $(WOPR_SRCS) |
Update of /cvsroot/galaxyng/NG_Stable/lib In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv9654/lib Added Files: Makefile globals.c list.c loadNGConfig.c lockFile.c logging.c mail.c strutl.c util.c Log Message: baseline version as used at sifar.xs4all.nl --- NEW FILE: loadNGConfig.c --- #include "galaxy.h" #include "galaxyng.h" #include "util.h" /****f* LoadGame/readDefaults * NAME * readDefaults -- read game defaults * FUNCTION * Read defaults from a configuration file : .galaxyngrc * NOTES * Has a memory leak. * SEE ALSO * game ****** */ void initServerOptions(game* aGame) { /* initialize values */ aGame->serverOptions.sendmail = NULL; aGame->serverOptions.encode = NULL; aGame->serverOptions.compress = NULL; aGame->serverOptions.GMemail = NULL; aGame->serverOptions.GMname = NULL; aGame->serverOptions.GMpassword = NULL; aGame->serverOptions.SERVERemail = NULL; aGame->serverOptions.SERVERname = NULL; aGame->serverOptions.ReplyTo = NULL; aGame->serverOptions.fontpath = NULL; aGame->serverOptions.due = NULL; aGame->serverOptions.tick_interval = NULL; } void readDefaults(game *aGame, FILE * f) { char* isRead; /* to check for EOF */ char* key; /* the key part of the name/value pair */ for (isRead = fgets(lineBuffer, LINE_BUFFER_SIZE, f); isRead; isRead = fgets(lineBuffer, LINE_BUFFER_SIZE, f)) { key = getstr(lineBuffer); if (key[0] != '\0') { if (noCaseStrcmp("GMemail", key) == 0) { if (aGame->serverOptions.GMemail) free(aGame->serverOptions.GMemail); aGame->serverOptions.GMemail = strdup(getstr(0)); } else if (noCaseStrcmp("GMname", key) == 0) { if (aGame->serverOptions.GMname) free(aGame->serverOptions.GMname); aGame->serverOptions.GMname = strdup(getstr(0)); } else if (noCaseStrcmp("GMpassword", key) == 0) { if (aGame->serverOptions.GMpassword) free(aGame->serverOptions.GMpassword); aGame->serverOptions.GMpassword = strdup(getstr(0)); } else if (noCaseStrcmp("SERVERemail", key) == 0) { if (aGame->serverOptions.SERVERemail) free(aGame->serverOptions.SERVERemail); aGame->serverOptions.SERVERemail = strdup(getstr(0)); } else if (noCaseStrcmp("SERVERname", key) == 0) { if (aGame->serverOptions.SERVERname) free(aGame->serverOptions.SERVERname); aGame->serverOptions.SERVERname = strdup(getstr(0)); } else if (noCaseStrcmp("ReplyTo", key) == 0) { if (aGame->serverOptions.ReplyTo) free(aGame->serverOptions.ReplyTo); aGame->serverOptions.ReplyTo = strdup(getstr(0)); } else if (noCaseStrcmp("compress", key) == 0) { if (aGame->serverOptions.compress) free(aGame->serverOptions.compress); aGame->serverOptions.compress = strdup(getstr(0)); } else if (noCaseStrcmp("encode", key) == 0) { if (aGame->serverOptions.encode) free(aGame->serverOptions.encode); aGame->serverOptions.encode = strdup(getstr(0)); } else if (noCaseStrcmp("sendmail", key) == 0) { if (aGame->serverOptions.sendmail) free(aGame->serverOptions.sendmail); aGame->serverOptions.sendmail = strdup(getstr(0)); } else if (noCaseStrcmp("starttime", key) == 0) { if (aGame->starttime) free(aGame->starttime); aGame->starttime = strdup(getstr(0)); } else if (noCaseStrcmp("fontpath", key) == 0) { if (aGame->serverOptions.fontpath) free(aGame->serverOptions.fontpath); aGame->serverOptions.fontpath = strdup(getstr(0)); } else if (noCaseStrcmp("due", key) == 0) { if (aGame->serverOptions.due) free(aGame->serverOptions.due); aGame->serverOptions.due = strdup(getstr(0)); } else if (noCaseStrcmp("tick", key) == 0) { if (aGame->serverOptions.tick_interval) free(aGame->serverOptions.tick_interval); aGame->serverOptions.tick_interval = strdup(getstr(0)); } else { printf("Unknown key \"%s\"\n", key); } } } if (aGame->serverOptions.due == NULL) aGame->serverOptions.due = strdup("soon"); if (aGame->serverOptions.tick_interval == NULL) aGame->serverOptions.tick_interval = strdup("48"); if (aGame->serverOptions.SERVERemail == NULL) { char* logfile = createString("%s/Games/log/%s", galaxynghome, aGame->name); FILE* logfp = fopen(logfile, "+w"); fprintf(stderr, "SERVERemail is a required entry in your .galaxyngrc\n"); fprintf(logfp, "SERVERemail is a required entry in your .galaxyngrc\n"); fclose(logfp); exit(EXIT_FAILURE); } if (aGame->serverOptions.SERVERname == NULL) aGame->serverOptions.SERVERname = strdup("GalaxyNG Server"); if (aGame->serverOptions.GMemail == NULL) aGame->serverOptions.GMemail = strdup(aGame->serverOptions.SERVERemail); if (aGame->serverOptions.GMname == NULL) aGame->serverOptions.GMname = strdup("GalaxyNG GM"); if (aGame->serverOptions.ReplyTo == NULL) aGame->serverOptions.ReplyTo = strdup(aGame->serverOptions.SERVERemail); if (aGame->serverOptions.GMpassword == NULL) aGame->serverOptions.GMpassword = strdup(""); } /****f* LoadGame/loadConfig * NAME * loadConfig -- read configuration files * FUNCTION * reads defaults from $GALAXYNGHOME/.galaxyngrc * and then from $GALAXYNGHOME/data/<gamename>/.galaxyngrc **** */ void loadNGConfig(game *aGame) { FILE *f; initServerOptions(aGame); sprintf(lineBuffer, "%s/.galaxyngrc", galaxynghome); if ((f = fopen(lineBuffer, "r"))) { readDefaults(aGame, f); fclose(f); } sprintf(lineBuffer, "%s/data/%s/.galaxyngrc", galaxynghome, aGame->name); if ((f = fopen(lineBuffer, "r"))) { readDefaults(aGame, f); fclose(f); } } --- NEW FILE: strutl.c --- #include "strutl.h" /****f* strutl/getstr * * NAME * getstr -- extract a word from a longer string * SYNOPSIS * char *getstr(char *s) * word = getstr(someString) * FUNCTION * Extract a word from a string of words. A word is any things that * is seperated by white spaces or a comma, any string that is * delimited by quotes ("), or or any string delimited by { }. * * The function is intended to parse a string word by word. It * should be first called as: * * firstword = getstr(myStringOfWords); * * This gets the first word from the string pointed to by * myStringOfWords. Then consecutive calls of * * nextword = getstr(NULL); * * you get the remaining words. * * White spaces inside a quote delimited word are turned into * underscores. * * In a string a ';' signifies the start of a comment. Any words * after a ';' are not parsed. * * In the non comment part ';' and '<' are removed before the words * are returned. * * RESULTS * word = a pointer to a nul terminated string. * * Program is aborted if the length of the word is longer than 256, * since then some is most likely trying to crack your system. * * When there are no more words"\0" is returned. * NOTES * This function can only work on one string at the time since it * works with a statically allocated buffer. This function is used * almost everywhere in the program. * SOURCE */ char * getstr( char *s ) { static char *s1; static char buf[256]; int i; int j; if ( s ) s1 = s; /* first invocation of this function, for an order line. Each next * times, for the same order line, s1 will "progress" by a word to * the right */ assert( s1 != NULL ); i = 0; for ( ; *s1 && isspace( *s1 ); s1++ ) /* skips spaces */ ; if ( *s1 == '"' ) { /* Players can enclose name (ie : including spaces) with double quotes */ for ( s1++; *s1 && *s1 != '"'; ) { buf[i] = isspace( *s1 ) ? '_' : *s1; s1++; i++; assert( i < 256 ); /* abort execution if s1 too long */ } } else if ( *s1 == '{' ) { for ( s1++; *s1 && *s1 != '}'; ) { buf[i] = *s1; s1++; i++; assert( i < 256 ); /* abort execution if s1 too long */ } } else { if ( *s1 != ';' ) { /* otherwise, it's a comment */ for ( ; *s1 && !isspace( *s1 ) && *s1 != ','; ) { /* space or ',' can be used as separators, */ buf[i] = *s1; s1++; i++; assert( i < 256 ); /* abort execution if s1 too long */ } } } buf[i] = '\0'; if ( *s1 ) s1++; /* Skip ',' or space */ /* CB, 19980922. Remove ";" and "<" from names (planets, ships...), * * * * * to * protect machine report from corruption. Don't break messages * * * * * and * comments. */ i = 0; j = 0; while ( buf[j] && j < 256 ) { if ( buf[j] != ';' && buf[j] != '<' ) { buf[i] = buf[j]; i++; } j++; } if ( i ) buf[i] = '\0'; return buf; } /***********/ /****f* strutl/makestrlist * NAME * makestrlist -- create an element for a string list * FUNCTION * * RESULT * Pointer to an initialized strlist structure. * BUGS * This function has a wrong name. * SOURCE */ strlist* makestrlist(char* ns) { strlist* s; strlist* cur; char* tmp; char* sPtr; char* ePtr; char* sep; cur = NULL; sPtr = tmp = strdup(ns); sep = ePtr = strpbrk(sPtr, "\n\r"); if (ePtr == NULL) { cur = (strlist*)allocStruct(strlist); cur->str = tmp; return cur; } do { if ( cur ) { cur->next = ( strlist * ) allocStruct( strlist ); cur = cur->next; } else s = cur = ( strlist * ) allocStruct( strlist ); *ePtr = '\0'; cur->str = strdup( sPtr ); if (*sep == '\n' && *(ePtr+1) == '\r') sPtr = ePtr + 2; else sPtr = ePtr + 1; } while ((sep = ePtr = strpbrk(sPtr, "\n\r")) != NULL); if (*sPtr != '\0') { cur->next = ( strlist * ) allocStruct( strlist ); cur = cur->next; cur->str = strdup(sPtr); } free( tmp ); return s; } /*********/ /****f* strutl/freestrlist * NAME * freestrlist -- free memory used by a string list. * SYNOPSIS * void freestrlist(strlist *s) * FUNCTION * Free all memory used by a string list. Before * trying to free the memory used by an element check * if the element is valid. * SOURCE */ void freestrlist( strlist *s ) { strlist *s2; pdebug( DFULL, "free strlist\n" ); while ( s ) { validateStruct( strlist, s ); s2 = s->next; free( s->str ); free( s ); s = s2; } } void dumpstrlist(strlist *aStrlist) { for (; aStrlist; aStrlist = aStrlist->next) { printf("%s\n", aStrlist->str); } } /****f* strutl/noCaseStrcmp * NAME * noCaseStrcmp -- * SYNOPSIS * int noCaseStrcmp(char *s, char *t) * FUNCTION * Compare two strings without paying no attention to the case of * the letters. * RESULT * 0 s == t * -1 s < t * 1 s > t * SOURCE */ int noCaseStrcmp(const char *s, const char *t) { for (; tolower(*s) == tolower(*t); s++, t++) if (*s == '\0') return 0; return (int) (tolower(*s) - tolower(*t)); } /*********/ /****f* strutl/noCaseStrncmp * NAME * noCaseStrncmp -- * SYNOPSIS * int noCaseStrncmp(char *, char *, int) * result = noCaseStrncmp(s, t, n) * FUNCTION * Compare two strings without paying no attention to the case of * the letters, but compare no more than n characters. * RESULT * 0 s == t * -1 s < t * 1 s > t * SOURCE */ int noCaseStrncmp(const char *s, const char *t, int n) { for (n--; (tolower(*s) == tolower(*t)) && (n > 0); s++, t++, n--) if (*s == '\0') return 0; return (int) (tolower(*s) - tolower(*t)); } /***********/ char* strlwr(char* str) { char* ptr = str; while (*ptr) { if (isupper(*ptr)) *ptr = tolower(*ptr); ptr++; } return str; } --- NEW FILE: list.c --- #include "list.h" #include <stdlib.h> #include <string.h> #include <assert.h> /****h* GalaxyNG/List * NAME * List -- a number of list manipulating functions. ***** */ /****i* List/numberOfElementsF * NAME * numberOfElementsF -- ******* */ int numberOfElementsF(list *aList) { list *el; int noEl; noEl = 0; if (aList) for (el = aList; el; el = el->next) noEl++; return noEl; } /****i* List/add2ListF * NAME * add2ListF -- ****** */ void add2ListF(list **aList, list *anElement) { anElement->next = *aList; *aList = anElement; } /****f* List/freelist * NAME * freelist -- free all members in a list ***** */ void freelist(void *base) { list *p, *p2; pdebug(DFULL2, "freelist"); p = base; while (p) { p2 = p->next; free(p->name); free(p); p = p2; pdebug(DFULL2, "."); } pdebug(DFULL2, "\n"); } /****i* List/addListF * NAME * addListF -- ****** */ void addListF(list **aList, list *anElement) { list *curElement; if (*aList == NULL) { *aList = anElement; } else { for (curElement = *aList; curElement->next; curElement = curElement->next); curElement->next = anElement; } } /****i* List/insertListF * NAME * insertListF -- ****** */ void insertListF(list **aList, list* where, list *anElement) { list *curElement; list *listEnd; if (*aList == NULL) { *aList = anElement; } else { for (curElement = *aList; curElement->next; curElement = curElement->next) { if (curElement == where) { break; } } for (listEnd = anElement; listEnd->next; listEnd = listEnd->next) ; listEnd->next = curElement->next; curElement->next = anElement; } } /****** List/findElementF * NAME * findElementF -- * SYNOPSIS * list *findElementF(list *aList, char *name) * FUNCTION * Find an element in a list based on the name * of the element. * INPUTS * aList -- pointer to the first element in the list. * name -- name of the element to find. * RESULT * Address of the element or NULL in case the * element was not found. ****** */ list* findElementF(list *aList, char *name) { list *anElement; for (anElement = aList; anElement; anElement = anElement->next) { if (!noCaseStrcmp(anElement->name, name)) break; } return anElement; } /****f* List/removeListF * NAME * removeListF - * FUNCTION * Remove an element from a list. * NOTE * Do not use this function directly, use the * macro remList() * SEE ALSO * remList() ****** */ void removeListF(list **aList, list *anElement) { list *prevElement; assert(anElement != NULL); if (*aList == anElement) *aList = anElement->next; else { for (prevElement = *aList; prevElement->next != anElement; prevElement = prevElement->next) { assert(prevElement != NULL); } prevElement->next = anElement->next; } free(anElement); } /****f* List/ptonum * NAME * ptonum -- convert pointer to index number * SYNOPSIS * void *ptonum(void *base, void *target) * FUNCTION * Gives the index number of an element in a list. * INPUTS * base - base address of the list * target - the element * RESULT * the index number of the element. * SEE ALSO * numtop() ******* */ int ptonum(void *base, void *target) { list *p; int i; for (p = base, i = 1; p; p = p->next, i++) if (p == target) return i; return 0; } /****f* List/numtop * NAME * numtop -- convert index number to pointer * SYNOPSIS * void *numtop(void *base, int n) * FUNCTION * Look up an element in a list using it's index number. * INPUTS * base - base address of the list * n - index number * RESULT * address of the element. ******* */ void * numtop(void *base, int n) { list *p; int i; i = 0; for (p = base; p; p = p->next) { i++; if (i == n) return p; } return 0; } /****f* List/setName * NAME * setNameF * FUNCTION * Set the name of an element in a list. * NOTE * Do not use this function directly, use the * macro setName() * SEE ALSO * setName() ****** */ void setNameF(list *anElement, const char *name) { free(anElement->name); anElement->name = strdup(name); } void dumpList(char* label, list* aList, void* callback(void*)) { list* curElement; fprintf(stderr, "*** %s ***\n", label); for (curElement = aList; curElement; curElement=curElement->next) { fprintf(stderr, "%lX: %s\n", curElement->cookie, curElement->name); callback((void*)curElement); } } void* allocStructF(unsigned int n, long cookie) { list *p; p = calloc(1, n); if (p == 0) { pdebug(DERR, "Out of memory, aborting program.\n"); exit(1); } p->cookie = cookie; p->name = NULL; p->next = NULL; return (void *) p; } --- NEW FILE: Makefile --- # # $Id: Makefile,v 1.1 2008/01/17 23:18:33 gumpu Exp $ # CFLAGS = -Wall -pedantic -I../include $(ADDTL_CFLAGS) CC = gcc SOURCES=strutl.c logging.c list.c globals.c mail.c util.c loadNGConfig.c \ lockFile.c OBJECTS=$(SOURCES:.c=.o) all : libgalaxyng.a libgalaxyng.a: $(OBJECTS) ar cr libgalaxyng.a $(OBJECTS) clean: rm -f libgalaxyng.a $(OBJECTS) *~ depend: makedepend -- $(CFLAGS) -- $(SOURCES) # DO NOT DELETE THIS LINE -- make depend depends on it. strutl.o: ../include/strutl.h ../include/cookies.h ../include/logging.h logging.o: ../include/logging.h list.o: ../include/list.h ../include/util.h ../include/galaxy.h list.o: ../include/strutl.h ../include/cookies.h ../include/logging.h globals.o: ../include/galaxy.h ../include/strutl.h ../include/cookies.h globals.o: ../include/logging.h mail.o: ../include/mail.h ../include/galaxy.h ../include/strutl.h mail.o: ../include/logging.h ../include/util.h ../include/list.h util.o: ../include/util.h ../include/galaxy.h ../include/strutl.h util.o: ../include/logging.h ../include/list.h util.o: ../include/create.h ../include/avl.h ../include/loadgame.h --- NEW FILE: lockFile.c --- #include <sys/types.h> #include <unistd.h> #include <stdlib.h> #include <fcntl.h> #include <sys/stat.h> #include <errno.h> #include <limits.h> #include <signal.h> static int readData(int fd, void* buf, size_t nbrBytes) { size_t toRead; size_t nbrRead = 0; ssize_t result; do { if (nbrBytes - nbrRead > SSIZE_MAX) toRead = SSIZE_MAX; else toRead = nbrBytes - nbrRead; if ((result = read(fd, (char*)buf+nbrRead, toRead)) >= 0) nbrRead += result; else if (errno != EINTR) return 0; } while (nbrRead < nbrBytes); return 1; } static int writeData(int fd, const void* buf, size_t nbrBytes) { size_t toWrite; size_t written = 0; ssize_t result; do { if (nbrBytes - written > SSIZE_MAX) toWrite = SSIZE_MAX; else toWrite = nbrBytes - written; if ((result = write(fd, (const char*)buf + written, toWrite)) >= 0) written += result; else if (errno != EINTR) return 0; } while (written < nbrBytes); return 1; } int spcLockFile(const char* lfpath) { int attempt; int fd; int result; pid_t pid; /* try 3 times, if we fail, we lose */ for (attempt = 0; attempt < 3; attempt++) { if ((fd = open(lfpath, O_RDWR|O_CREAT|O_EXCL, S_IRWXU)) == -1) { if (errno != EEXIST) return -1; if ((fd = open(lfpath, O_RDONLY)) == -1) return -1; result = readData(fd, &pid, sizeof(pid)); close(fd); if (result) { if (pid == getpid()) return 1; if (kill(pid, 0) == -1) { if (errno != ESRCH) return -1; attempt--; unlink(lfpath); continue; } } sleep(1); continue; } pid = getpid(); if (!writeData(fd, &pid, sizeof(pid))) { close(fd); return -1; } close(fd); attempt--; } /* If we've made it to here, three attempts have been made and the * lock could not be obtained. Return an error code indicating * failure to obtain the requested lock. */ return 0; } --- NEW FILE: mail.c --- #include "mail.h" #include "util.h" #include <assert.h> #include <stdarg.h> #include <stdlib.h> #include <string.h> /****h* GalaxyNG/Mail * FUNCTION * This module contains functions to create, * fill and send email messages. ***** */ void createMailToAllHeader(game *aGame) { player* aPlayer; int state; if (aGame->serverOptions.SERVERemail) { if (aGame->serverOptions.SERVERname) { printf("From: %s <%s>\n", aGame->serverOptions.SERVERname, aGame->serverOptions.SERVERemail); } else { printf("From: %s\n", aGame->serverOptions.SERVERemail); } } printf("To: %s\nBCC: ", aGame->serverOptions.GMemail); for (aPlayer = aGame->players, state = 0; aPlayer; aPlayer = aPlayer->next) { if (!(aPlayer->flags & F_DEAD)) { if (state == 0) { printf(" %s", aPlayer->addr); state = 1; } else { printf(",\n %s", aPlayer->addr); } } } printf("\nSubject:\n"); } /****f* Mail/createEnvelope * NAME * createEnvelope -- create an envelope. * FUNCTION * Creates and initializes an envelope. ****** */ envelope* createEnvelope() { envelope *e; e = malloc(sizeof(envelope)); assert(e != NULL); e->to = NULL; e->from = NULL; e->replyto = NULL; e->subject = NULL; e->from_address = NULL; e->from_name = NULL; e->bcc = NULL; e->cc = NULL; e->compress = FALSE; e->contentType = NULL; e->contentEncoding = NULL; e->contentDescription = NULL; return e; } /****f* Mail/readEnvelope * NAME * readEnvelope -- create an envelope, filling in values from mail header. * FUNCTION * Creates and initializes an envelope from a file. ****** */ envelope* readEnvelope(FILE* fp) { envelope *e; char buffer[4096]; char* ptr; e = createEnvelope(); while (fgets(buffer, 4096, fp) != NULL) { *(strchr(buffer, '\n')) = '\0'; if (buffer[0] == '\0') break; /* end of headers */ if ((ptr = strchr(buffer, ':')) == NULL) continue; /* skip header, no : in it */ *ptr = '\0'; if (noCaseStrcmp(buffer, "from") == 0) { e->from = strdup(ptr+2); } else if (noCaseStrcmp(buffer, "to") == 0) { e->to = strdup(ptr+2); } else if (noCaseStrcmp(buffer, "subject") == 0) { e->subject = strdup(ptr+2); } else if (noCaseStrcmp(buffer, "cc") == 0) { e->cc = strdup(ptr+2); } else if (noCaseStrcmp(buffer, "content-type") == 0) { e->contentType = strdup(ptr+2); } else if (noCaseStrcmp(buffer, "content-transfer-encoding") == 0) { e->contentEncoding = strdup(ptr+2); } else if (noCaseStrcmp(buffer, "content-description") == 0) { e->contentDescription = strdup(ptr+2); } else continue; } return e; } /****f* Mail/setHeader * NAME * setHeader -- write something on the envelope. * SYNOPSIS * void setHeader(envelope *e, int headerType, char *format, ...) * FUNCTION * Dynamically create a mail header. ******* */ void setHeader(envelope *e, int headerType, char *format, ...) { int n; va_list ap; assert(e != NULL); va_start(ap, format); #ifdef WIN32 vsprintf(lineBuffer, format, ap); #else n = vsnprintf(lineBuffer, LINE_BUFFER_SIZE, format, ap); assert(n != -1); #endif va_end(ap); switch(headerType) { case MAILHEADER_TO: if (e->to) free(e->to); e->to = strdup(lineBuffer); break; case MAILHEADER_FROM: if (e->from) free(e->from); e->from = strdup(lineBuffer); break; case MAILHEADER_REPLYTO: if (e->replyto) free(e->replyto); e->replyto = strdup(lineBuffer); break; case MAILHEADER_SUBJECT: if (e->subject) free(e->subject); e->subject = strdup(lineBuffer); break; case MAILHEADER_BCC: if (e->bcc) free(e->bcc); e->bcc = strdup(lineBuffer); break; case MAILHEADER_CC: if (e->cc) free(e->cc); e->cc = strdup(lineBuffer); break; case MAILHEADER_CONTENTTYPE: if (e->contentType) free(e->contentType); e->contentType = strdup(lineBuffer); break; case MAILHEADER_CONTENTENCODING: if (e->contentEncoding) free(e->contentEncoding); e->contentEncoding = strdup(lineBuffer); break; case MAILHEADER_CONTENTDESCRIPTION: if (e->contentDescription) free(e->contentDescription); e->contentDescription = strdup(lineBuffer); default: assert(0); } } /****f* Mail/destroyEnvelope * NAME * destroyEnvelope -- free memory used by an envelope. * SYNOPSIS * destroyEnvelope(envelope *e) ******** */ void destroyEnvelope(envelope *e) { assert(e != NULL); if (e->to) free(e->to); if (e->from) free(e->from); if (e->from_address) free(e->from_address); if (e->from_name) free(e->from_name); if (e->replyto) free(e->replyto); if (e->subject) free(e->subject); if (e->bcc) free(e->bcc); if (e->cc) free(e->cc); if (e->contentType) free(e->contentType); if (e->contentEncoding) free(e->contentEncoding); if (e->contentDescription) free(e->contentDescription); free(e); } /****f* Mail/eMail_old * NAME * eMail_old -- mail the contents of a file to someone. * FUNCTION * Mail a file to someone. * INPUTS * e -- envelope * aGame -- game structure, contains settings for mailer etc. * fileName -- name of the file to send. * RESULT * status 0, all OK. * >0, something went wrong * BUGS * Does not write anything to the log file. ****** */ int eMail_old(game *aGame, envelope *e, char *fileName) { FILE* mailFile; char template[128]; int result; char command[4096]; pdebug(DFULL, "eMail\n"); sprintf(template, "%s/galaxyXXXXXX", tempdir); assert(fileName != NULL); assert(aGame != NULL); mailFile = fdopen(mkstemp(template), "w"); result = 1; assert(e->to); assert(e->subject); if (e->from_address && e->from_name) { fprintf(mailFile, "From: %s <%s>\n", e->from_name, e->from_address); } else if (e->from) { fprintf(mailFile, "From: %s\n", e->from); } fprintf(mailFile, "To: %s\n", e->to); fprintf(mailFile, "Subject: %s\n", e->subject); if (e->replyto) fprintf(mailFile, "Reply-To: %s\n", e->replyto); if (e->bcc) fprintf(mailFile, "BCC: %s\n", e->bcc); if (e->cc) fprintf(mailFile, "CC: %s\n", e->cc); if (e->contentType) fprintf(mailFile, "Content-Type: %s\n", e->contentType); if (e->contentEncoding) fprintf(mailFile, "Content-tranfer-encoding: %s\n", e->contentEncoding); if (e->contentDescription) fprintf(mailFile, "Content-description: %s\n", e->contentDescription); #ifndef WIN32 if (e->compress && aGame->serverOptions.compress && aGame->serverOptions.encode) { addMimeHeader(mailFile); } fprintf(mailFile, "\n\n"); if (e->compress && aGame->serverOptions.compress && aGame->serverOptions.encode) { char *relative_path; char *ptr; char zipped_name[4096]; char encoded_name[4096]; addMimeText(mailFile); fprintf(mailFile, "Turn report is attached as .zip file.\n\n"); relative_path = strstr(fileName, "reports"); if (relative_path == NULL) { fprintf(stderr, "Reports are not in their standards position\n"); relative_path = fileName; } strcpy(zipped_name, fileName); if ((ptr = strrchr(zipped_name, '.')) != NULL) *ptr = '_'; strcat(zipped_name, ".zip"); strcpy(encoded_name, fileName); if ((ptr = strrchr(encoded_name, '.')) != NULL) *ptr = '_'; result = ssystem("%s %s %s > /dev/null 2>&1", aGame->serverOptions.compress, zipped_name, relative_path); result |= ssystem("%s < %s > %s 2> /dev/null", aGame->serverOptions.encode, zipped_name, encoded_name); addMimeZip(mailFile); result |= appendToMail(encoded_name, mailFile); addMimeEnd(mailFile); result |= ssystem("rm %s %s", zipped_name, encoded_name); } else { result = appendToMail(fileName, mailFile); } #endif fclose(mailFile); #ifndef WIN32 sprintf(command, "%s", aGame->serverOptions.sendmail); if (e->from_address) { char tmpBuf[4096]; sprintf(tmpBuf, " -f \"%s\"", e->from_address); strcat(command, tmpBuf); } if (e->from_name) { char tmpBuf[4096]; sprintf(tmpBuf, " -F \"%s\"", e->from_name); strcat(command, tmpBuf); } result |= ssystem("%s < %s", command, template); result |= ssystem("rm %s", template); #endif return result; } /****f* Mail/eMail * NAME * eMail -- mail the contents of a file to someone. * FUNCTION * Mail a file to someone. * INPUTS * e -- envelope * aGame -- game structure, contains settings for mailer etc. * fileName -- name of the file to send. * RESULT * status 0, all OK. * >0, something went wrong * BUGS * Does not write anything to the log file. ****** */ int eMail(game *aGame, envelope *e, char *fileName) { FILE* mailFile; char template[128]; int result; char command[4096]; pdebug(DFULL, "eMail %s\n", fileName ); sprintf(template, "%s/galaxyXXXXXX", tempdir); assert(fileName != NULL); assert(aGame != NULL); mailFile = fdopen(mkstemp(template), "w"); result = 1; assert(e->to); assert(e->subject); if (e->from_address && e->from_name) { fprintf(mailFile, "From: %s <%s>\n", e->from_name, e->from_address); } else if (e->from) { fprintf(mailFile, "From: %s\n", e->from); } fprintf(mailFile, "To: %s\n", e->to); fprintf(mailFile, "Subject: %s\n", e->subject); if (e->replyto) fprintf(mailFile, "Reply-To: %s\n", e->replyto); if (e->bcc) fprintf(mailFile, "BCC: %s\n", e->bcc); if (e->cc) fprintf(mailFile, "CC: %s\n", e->cc); if (e->contentType) fprintf(mailFile, "Content-Type: %s\n", e->contentType); if (e->contentEncoding) fprintf(mailFile, "Content-tranfer-encoding: %s\n", e->contentEncoding); if (e->contentDescription) fprintf(mailFile, "Content-description: %s\n", e->contentDescription); #ifndef WIN32 addMimeHeader(mailFile); fprintf(mailFile, "\n\n"); if (e->compress && aGame->serverOptions.compress && aGame->serverOptions.encode) { char *relative_path; char *ptr; char zipped_name[4096]; char encoded_name[4096]; addMimeText(mailFile); fprintf(mailFile, "Turn report is attached as .zip file.\n\n"); relative_path = strstr(fileName, "reports"); if (relative_path == NULL) { relative_path = fileName; } strcpy(zipped_name, fileName); if ((ptr = strrchr(zipped_name, '.')) != NULL) *ptr = '_'; strcat(zipped_name, ".zip"); strcpy(encoded_name, fileName); strcat(encoded_name, "_enc"); if ((ptr = strrchr(encoded_name, '.')) != NULL) *ptr = '_'; result = ssystem("%s %s %s > /dev/null 2>&1", aGame->serverOptions.compress, zipped_name, relative_path); result |= ssystem("%s < %s > %s 2> /dev/null", aGame->serverOptions.encode, zipped_name, encoded_name); addMimeZip(mailFile); result |= appendToMail(encoded_name, mailFile); addMimeEnd(mailFile); result |= ssystem("rm %s %s", zipped_name, encoded_name); } else { char *relative_path; char *ptr; char dos_name[4096]; char encoded_name[4096]; addMimeText(mailFile); fprintf(mailFile, "Turn report is attached as text file.\n\n"); relative_path = strstr(fileName, "reports"); if (relative_path == NULL) { relative_path = fileName; } strcpy(encoded_name, fileName); strcat(encoded_name, "_enc"); strcpy(dos_name, fileName); strcat(dos_name, "_dos"); if ((ptr = strrchr(encoded_name, '.')) != NULL) *ptr = '_'; result = ssystem("/usr/bin/unix2dos -n %s %s 2> /dev/null", relative_path, dos_name); result |= ssystem("%s < %s > %s 2> /dev/null", aGame->serverOptions.encode, dos_name, encoded_name); addMimeTXT(mailFile, aGame->turn); result |= appendToMail(encoded_name, mailFile); addMimeEnd(mailFile); // result |= ssystem("rm %s %s" , encoded_name, dos_name); } #endif fclose(mailFile); #ifndef WIN32 sprintf(command, "%s", aGame->serverOptions.sendmail); if (e->from_address) { char tmpBuf[4096]; sprintf(tmpBuf, " -f \"%s\"", e->from_address); strcat(command, tmpBuf); } if (e->from_name) { char tmpBuf[4096]; sprintf(tmpBuf, " -F \"%s\"", e->from_name); strcat(command, tmpBuf); } result |= ssystem("%s < %s", command, template); result |= ssystem("rm %s", template); #endif return result; } void addMimeHeader(FILE *mailFile) { fprintf(mailFile, "Mime-Version: 1.0\n"); fprintf(mailFile, "Content-Type: multipart/mixed; boundary=\"9jxsPFA5p3P2qPhR\"\n"); fprintf(mailFile, "Content-Disposition: inline\n"); } void addMimeText(FILE *mailFile) { fprintf(mailFile, "--9jxsPFA5p3P2qPhR\n"); fprintf(mailFile, "Content-Type: text/plain; charset=us-ascii\n"); fprintf(mailFile, "Content-Disposition: inline\n"); fprintf(mailFile, "\n"); } void addMimeUUE(FILE *mailFile) { fprintf(mailFile, "--9jxsPFA5p3P2qPhR\n"); fprintf(mailFile, "Content-Type: application/zip\n"); fprintf(mailFile, "Content-Disposition: attachment; filename=\"turn.zip\"\n"); fprintf(mailFile, "Content-Transfer-Encoding: base64\n"); fprintf(mailFile, "\n"); } void addMimeZip(FILE *mailFile) { fprintf(mailFile, "--9jxsPFA5p3P2qPhR\n"); fprintf(mailFile, "Content-Type: application/zip\n"); fprintf(mailFile, "Content-Disposition: attachment; filename=\"turn.zip\"\n"); fprintf(mailFile, "Content-Transfer-Encoding: base64\n"); fprintf(mailFile, "\n"); } void addMimeTXT(FILE *mailFile, int turn) { fprintf(mailFile, "--9jxsPFA5p3P2qPhR\n"); fprintf(mailFile, "Content-Type: text/plain\n"); fprintf(mailFile, "Content-Disposition: attachment; filename=\"turn%02d.txt\"\n", turn); fprintf(mailFile, "Content-Transfer-Encoding: base64\n"); fprintf(mailFile, "\n"); } void addMimeEnd(FILE *mailFile) { fprintf(mailFile, "\n--9jxsPFA5p3P2qPhR--\n"); } int appendToMail(char *fileName, FILE *mailFile) { FILE *f; char *isRead; f = fopen(fileName, "r"); if (f) { for (isRead = fgets(lineBuffer, LINE_BUFFER_SIZE, f); isRead; isRead = fgets(lineBuffer, LINE_BUFFER_SIZE, f)) { fputs(lineBuffer, mailFile); } fclose(f); return FALSE; } else { return TRUE; } } /****f* Process/getReturnAddress * NAME * getReturnAddress * FUNCTION * Extract the return address from a players email. ****** */ char * getReturnAddress( FILE *orders ) { char *isRead; char *c; for ( isRead = fgets( lineBuffer, LINE_BUFFER_SIZE, orders ); isRead; isRead = fgets( lineBuffer, LINE_BUFFER_SIZE, orders ) ) { /* WIN32 */ if ( noCaseStrncmp( string_mail_to, lineBuffer, 3 ) == 0 ) break; } assert( isRead != NULL ); for ( c = lineBuffer; *c; c++ ) { if ( *c == '\n' ) *c = '\0'; } return strdup( lineBuffer + 3 ); } void gmNotify(char* subject, char* filename, game* aGame) { envelope* env; env = createEnvelope(); if (aGame == NULL) { char buffer[4096]; FILE* tmpFP; aGame = (game*)malloc(sizeof(game)); loadNGConfig(aGame); if (aGame->serverOptions.GMemail == NULL) { fprintf(stderr, "**ERROR** Could not load game or config in " "gmNotify!!!\n"); fprintf(stderr, "This is the message that was trying to be " "delivered:\n"); fprintf(stderr, "Subject: %s\n", subject); tmpFP = fopen(filename, "r"); while (fgets(buffer, 4096, tmpFP) != NULL) fprintf(stderr, "%s", buffer); fclose(tmpFP); return; } } env->to = strdup(aGame->serverOptions.GMemail); env->from = strdup(aGame->serverOptions.SERVERemail); env->replyto = strdup(aGame->serverOptions.ReplyTo); env->subject = strdup(subject); eMail(aGame, env, filename); destroyEnvelope(env); return; } --- NEW FILE: util.c --- #include "util.h" #include <stdlib.h> #include <limits.h> #include <math.h> #include <assert.h> #include <stdarg.h> #include <time.h> #include <ctype.h> #include <string.h> #include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> #ifndef WIN32 #include <unistd.h> #endif #ifdef WIN32 #include <direct.h> #endif #include "create.h" [...1721 lines suppressed...] rewind(inMail); /* read all the header stuff which only goes until the first blank line */ while (fgets(buffer, sizeof(char)*4096, inMail)) { if (buffer[0] == '\n') break; } /* now copy everything up to the (optional) #end */ while (fgets(buffer, sizeof(char)*4096, inMail)) { if (noCaseStrncmp(buffer, "#end", 4) == 0) { fprintf(outMail, "%s", buffer); break; } fprintf(outMail, "%s", buffer); } return; } --- NEW FILE: globals.c --- #include "galaxy.h" char map[MAPWIDTH][MAPHEIGHT]; char buf[LINE_BUFFER_SIZE]; /****v* GalaxyNG/lineBuffer * NAME * lineBuffer -- global line buffer. * NOTES * 2 is there to prevent buffer overflows. * SOURCE */ char lineBuffer[2 * LINE_BUFFER_SIZE]; /******/ /****v* GalaxyNG/productname * NAME * productname -- things a planet can produce. * SOURCE */ char *productname[] = { "CAP", "MAT", 0, "Drive", "Weapons", "Shields", "Cargo", }; /******/ int nbrProducts = sizeof(productname) / sizeof(char *); FILE *turnFile = NULL; /******/ /****v* GalaxyNG/galaxynghome * NAME * galaxynghome -- path to all data files * SOURCE */ char *galaxynghome = NULL; /*****/ /****v* GalaxyNG/tempdir * NAME * tempdir -- path to the directory used to store temporary files. * SOURCE */ char *tempdir = NULL; /*****/ /****v* GalaxyNG/options * NAME * options -- options available to players. * FUNCTION * Associative array to look-up option flag by option names. * SOURCE */ struct option options[] = { {"anonymous", F_ANONYMOUS}, {"autoUnload", F_AUTOUNLOAD}, {"prodTable", F_PRODTABLE}, {"sortGroups", F_SORTGROUPS}, {"groupForeCast", F_GROUPFORECAST}, {"planetForeCast", F_PLANETFORECAST}, {"shipTypeForecast", F_SHIPTYPEFORECAST}, {"routesForecast", F_ROUTESFORECAST}, {"compress", F_COMPRESS}, {"gplus", F_GPLUS}, {"machineReport", F_MACHINEREPORT}, /* CB 1998 - Experimental */ {"battleProtocol", F_BATTLEPROTOCOL}, {"xmlReport", F_XMLREPORT}, /* KDW 2003 */ {"txtReport", F_TXTREPORT}, {NULL, 0} }; char* string_mail_subject = "subject:"; /* Dutch: onderwerp: */ char* string_mail_to = "to:"; /* Dutch: aan: */ char* string_mail_from = "from:"; /* Dutch: van: */ /**********/ --- NEW FILE: logging.c --- #include "logging.h" static enum DebugLevels debugLevel = DNONE; static enum LogLevels logLevel = LNONE; static FILE* logFile = NULL; /****f* logging/pdebug * NAME * pdebug -- dump a message to stdout * SYNOPSIS * void pdebug(int level, char *format,...) * FUNCTION * Dump a debug message to stdout. Each message has a debug level. * Messages are only printed if they have a level below the debug * level (specified in the global debugLevel). * INPUTS * level -- debug level of the message * format -- format string for the messgage * ... -- other parameters * SOURCE */ void pdebug(enum DebugLevels level, char *format, ...) { va_list ap; if (level <= debugLevel) { va_start(ap, format); vprintf(format, ap); va_end(ap); } } /*******/ /****f* logging/plog * NAME * plog -- dump a messgage to the log file. * SYNOPSIS * void plog(int level, char *format,...) * FUNCTION * Dump a log message to the logfile. Each message has a log level. * Messages are only stored if they have a level below the * log level (specified in the global logLevel). * INPUTS * level -- log level of the message * format -- format string for the messgage * ... -- other parameters * SOURCE */ void plog(enum LogLevels level, char *format, ...) { va_list ap; if (level <= logLevel && logFile) { va_start(ap, format); vfprintf(logFile, format, ap); va_end(ap); } } /**********/ /****f* logging/plogtime * NAME * plogtime -- write current time and date to the log file. * SYNOPSIS * void plogtime(int level) * SOURCE */ void plogtime(enum LogLevels level) { if (level <= logLevel && logFile) { time_t ttp; char timeBuffer[255]; time(&ttp); strftime(timeBuffer, 255, "%H:%M:%S %a %b %d %Y\n", localtime(&ttp)); fprintf(logFile, "%s", timeBuffer); } } /***********/ /****f* logging/setDebugLevel * NAME * setDebugLevel -- set the system debugging level * SYNOPSIS * enum DebugLevels setDebugLevel(enum DebugLevels level) * FUNCTION * set the system debugging level * SOURCE */ enum DebugLevels setDebugLevel(enum DebugLevels level) { enum DebugLevels lastLevel = debugLevel; debugLevel = level; return lastLevel; } /****f* logging/setLogLevel * NAME * setLogLevel -- set the system logging level * SYNOPSIS * enum LogLevels setLogLevel(enum LogLevels level) * FUNCTION * set the system logging level * SOURCE */ enum LogLevels setLogLevel(enum LogLevels level) { enum LogLevels lastLevel = logLevel; logLevel = level; return lastLevel; } /****f* logging/openLog * NAME * openLog -- open a log file. * FUNCTION * Open a log file. Close the previous log file if open. * SOURCE */ int openLog(char *name, char* mode) { if (logFile) fclose(logFile); if ((logFile = fopen(name, mode)) == NULL) { fprintf(stderr, "Could not open log file %s\n", name); return 1; } setvbuf(logFile, NULL, _IONBF, 0); return 0; } /**********/ void closeLog() { if (logFile) { fclose(logFile); logFile = NULL; } } |
Update of /cvsroot/galaxyng/NG_Stable/include In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv9654/include Added Files: avl.h battle.h cookies.h create.h galaxy.h galaxyng.h influence.h list.h loadgame.h logging.h mail.h phase.h process.h report.h report_m.h report_xml.h savegame.h selftest.h strutl.h util.h wopr.h Log Message: baseline version as used at sifar.xs4all.nl --- NEW FILE: influence.h --- #if !defined(INFLUENCE_H_) #define INFLUENCE_H_ #include "galaxy.h" #include "list.h" #include "util.h" /* this is to enable the current map to be created as an image */ #include <gd.h> #include <avl.h> enum map_type { AllMaps = -1, FirstMap=0, EffIndMap=0, ShipAttMap, ShipDefMap, LocationMap, PublicMap, NbrMaps }; #endif --- NEW FILE: savegame.h --- #ifndef GNG_SAVEGAME_H #define GNG_SAVEGAME_H #include "galaxy.h" #include "list.h" #include "util.h" #if defined(DRAW_INFLUENCE_MAP) void draw_maps(game* aGame); #endif void writeString(char *s); void writeFloat(double f); void writeInt(int i); void writeLong(long l); void savegame(game *aGame); #endif /* GNG_SAVEGAME_H */ --- NEW FILE: cookies.h --- #if !defined(COOKIES_H_) #define COOKIES_H_ /****d* GalaxyNG/Cookies * NAME * Cookies -- magic cookies used for sanity checks. * SOURCE */ #define COOKIEplanet 0x01DFEE01 #define COOKIEgroup 0x02DEEE12 #define COOKIEbattle 0x03DDEE23 #define COOKIEplayer 0x04DCEE34 #define COOKIEalliance 0x05DBEE45 #define COOKIEfleetname 0x06DAEE56 #define COOKIEparticipant 0x07D9EE67 #define COOKIEbatstat 0x08D8EE78 #define COOKIEAplanet 0x09D7EE89 #define COOKIEAalliance 0x0AD6EE9A #define COOKIEshiptype 0x0BD5EEAB #define COOKIEbombing 0x0CD4EEBC #define COOKIEplanet_claim 0x0DD3EECD #define COOKIEstrlist 0x0ED2EEDE #define COOKIEgame 0x0FD4EEDF #define COOKIEgamespecification 0xF1AABEEF #define COOKIEnewplayer 0xF1EA5747 #define COOKIEgameOpts 0xF2AABEEF #define COOKIEplayerOpts 0xF2EA5747 #define COOKIEplanetTemplate 0xF2D4EEDF #define COOKIEemailList 0xF2FAFEED /******/ #define allocStruct(t) allocStructF(sizeof(t), COOKIE ## t) #define isStruct(t,p) (p->cookie == COOKIE ## t) #define validateStruct(t,p) if(!(p->cookie == COOKIE ## t)) \ { printf("validateStruct Failed in line %d of %s\n", __LINE__ , __FILE__);exit(100); } ; void* allocStructF(unsigned int n, long cookie); #endif --- NEW FILE: avl.h --- /* * ANSI C Library for maintainance of AVL Balanced Trees * * ref.: * G. M. Adelson-Velskij & E. M. Landis * Doklady Akad. Nauk SSSR 146 (1962), 263-266 * * see also: * D. E. Knuth: The Art of Computer Programming Vol.3 (Sorting and Searching) * * (C) 2000 Daniel Nagy, Budapest University of Technology and Economics * Released under GNU General Public License (GPL) version 2 * */ #ifndef _AVL_H #define _AVL_H 1 /* Data structures */ /* One element of the AVL tree */ typedef struct avl { struct avl* left; struct avl* right; signed char balance; } avl; /* An AVL tree */ typedef struct avl_tree { avl* root; int(*compar)(void* a,void* b); } avl_tree; /* Public methods */ /* Insert element a into the AVL tree t * returns 1 if the depth of the tree has grown * Warning: do not insert elements already present */ int avl_insert(avl_tree* t,avl* a); /* Remove an element a from the AVL tree t * returns -1 if the depth of the tree has shrunk * Warning: if the element is not present in the tree, * returns 0 as if it had been removed succesfully. */ int avl_remove(avl_tree* t, avl* a); /* Remove the root of the AVL tree t * Warning: dumps core if t is empty */ int avl_removeroot(avl_tree* t); /* Iterate through elements in t from a range between a and b (inclusive) * for each element calls iter(a) until it returns 0 * returns the last value returned by iterator or 0 if there were no calls * Warning: a<=b must hold */ int avl_range(avl_tree* t,avl* a,avl* b,int(*iter)(avl* a)); /* Iterate through elements in t equal to a * for each element calls iter(a) until it returns 0 * returns the last value returned by iterator or 0 if there were no calls */ int avl_search(avl_tree* t, avl* a,int(*iter)(avl* a)); #endif /* avl.h */ --- NEW FILE: phase.h --- #ifndef GNG_PHASE_H #define GNG_PHASE_H #include "galaxy.h" /* $Id: phase.h,v 1.1 2008/01/17 23:18:31 gumpu Exp $ */ /* void giveposition(void); */ void convertcap(planet *p); void unloadcap(planet *p, double x); void unloadcol(planet *p, double x, player *P); void unloadgroup(group *g, player *P, double amount); int kill(group *attack, group *target); int mustBomb(player *P, group *g); player *determineOwnership(game *aGame, planet *targetPlanet, player *aPlayer); void bombPlanet(game *aGame, planet *p); void bombphase(game *aGame); void joinphase(game *aGame); void loadphase(game *aGame); void interceptphase(game *aGame); void fleetphase(game *aGame); void movephase(game *aGame); void unloadphase(game *aGame); void producephase(game *aGame); void produceShip(planet *aPlanet, double industry); void produceMatCap(planet *aPlanet, double industry); void produceTechnology(planet *aPlanet, double industry); void producePopulation(planet *aPlanet); void sortphase(game *aGame); double ftrunc2(double x); void cktech(group *g); int nametocargotype(char *s); #endif /* GNG_PHASE_H */ --- NEW FILE: mail.h --- #ifndef GNG_MAIL_H #define GNG_MAIL_H #include "galaxy.h" #include "util.h" #ifdef WIN32 #include <stdio.h> #include <stdarg.h> #include <TCHAR.H> #endif /****s* Mail/envelope * NAME * envelope -- envelope for an email message. * PURPOSE * Store the envelope of an email message. * SOURCE */ typedef struct envelope { int compress; /* Compress the body before sending */ char* to; /* destination */ char* from; /* Who sent it */ char* subject; char* replyto; char* cc; char* bcc; char* contentType; char* contentEncoding; char* contentDescription; char* from_address; char* from_name; } envelope; /********/ /****d* Mail/MailHeaderTypes * NAME * MailHeaderTypes -- things we can write on the envelope * SOURCE */ enum {MAILHEADER_TO = 1, MAILHEADER_FROM, MAILHEADER_SUBJECT, MAILHEADER_REPLYTO, MAILHEADER_CC, MAILHEADER_BCC, MAILHEADER_CONTENTTYPE, MAILHEADER_CONTENTENCODING, MAILHEADER_CONTENTDESCRIPTION }; /******/ void createMailToAllHeader(game *aGame); envelope* createEnvelope(void); envelope* readEnvelope(FILE* fp); void destroyEnvelope(envelope *e); void setHeader(envelope *e, int headerType, char *format, ...); int eMail(game *aGame, envelope *e, char *fileName); int eMail_old(game *aGame, envelope *e, char *fileName); char* getReturnAddress(FILE * orders); void addMimeHeader(FILE *mailFile); void addMimeText(FILE *mailFile); void addMimeZip(FILE *mailFile); void addMimeTXT(FILE *mailFile, int turn); void addMimeEnd(FILE *mailFile); int appendToMail(char *fileName, FILE *mailFile); void gmNotify(char* subject, char* filename, game* aGame); #endif /* GNG_MAIL_H */ --- NEW FILE: galaxyng.h --- #ifndef GNG_GALAXYNG_H #define GNG_GALAXYNG_H #include <stdio.h> #include <stdlib.h> #include <math.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include "galaxy.h" #include "util.h" #include "loadgame.h" #include "process.h" #include "create.h" #define CMD_RUN_REAL 1 /* -run will mail turn reports */ #define CMD_RUN_DUMMY 2 /* -run will save turn reports to disk */ #define CMD_CHECK_REAL 1 #define CMD_CHECK_DUMMY 2 enum { CMD_DUMP_MAP = 1, CMD_DUMP_LASTORDERS, CMD_DUMP_PLAYERS, CMD_DUMP_PSCORE, CMD_DUMP_HALL, CMD_DUMP_MAILHEADER, CMD_DUMP_TEAM_INFO, CMD_DUMP_TEAM_REPORT_NAMES, CMD_DUMP_MAP_GNUPLOT }; void SetDirectoryVariables( void ); int CMD_immediate(int argc, char** argv); int CMD_create( int argc, char **argv ); int CMD_mail0( int argc, char **argv, int kind ); int CMD_run( int argc, char **argv, int kind ); int CMD_webcheck( int argc, char **argv, int kind ); int CMD_check( int argc, char **argv, int kind ); #if 0 int CMD_checkFile( int argc, char **argv, int kind ); #endif int CMD_report( int argc, char **argv ); int CMD_webreport( int argc, char **argv ); int CMD_score( int argc, char **argv ); int CMD_graph( int argc, char **argv ); int CMD_dump( int argc, char **argv, int kind ); int CMD_test( int argc, char **argv ); int CMD_relay( int argc, char **argv ); int CMD_template( int argc, char **argv ); int CMD_selftest( ); int CMD_battletest( int argc, char **argv ); #if defined(DRAW_INFLUENCE_MAP) int CMD_influence( int argc, char **argv ); #endif int checkTime( game *aGame ); int relayMessage(game *aGame, envelope *anEnvelope, char *nationName, player *from, emailList *to ); int CMD_ordersdue(int argc, char** argv); int CMD_clean(int argc, char** argv); #endif /* GNG_GALAXYNG_H */ --- NEW FILE: strutl.h --- #if !defined(STRUTL_H_) #define STRUTL_H_ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <malloc.h> #include <assert.h> #include "cookies.h" #include "logging.h" /****s* GalaxyNG/strlist * NAME * strlist -- * PURPOSE * Structure to store strings. Used to store orders, mistakes, and * messages. * NOTES * Has a wrong name. Should be called String or so, since it is * an element in a list. * SOURCE */ typedef struct strlist { struct strlist *next; long cookie; char *str; } strlist; /********/ char* getstr(char* s); strlist* makestrlist(char* ns); void freestrlist(strlist* s); void dumpstrlist(strlist* aStrlist); int noCaseStrncmp(const char *s, const char *t, int n); int noCaseStrcmp(const char *s, const char *t); char* strlwr(char* str); #endif --- NEW FILE: report.h --- #ifndef GNG_REPORT_H #define GNG_REPORT_H /* $Id: report.h,v 1.1 2008/01/17 23:18:31 gumpu Exp $ */ #include "galaxy.h" #include "loadgame.h" #include "list.h" #include "util.h" #include "mail.h" #include "report_m.h" #include "report_xml.h" #ifdef WIN32 /* #include <varargs.h> */ #include <stdarg.h> #include <stdio.h> #endif #define FORMATBUFFERSIZE 512 #define MAXNOFIELDS 100 #define M_ALIGN_LEFT 0 #define M_ALIGN_RIGHT 1 #define M_ALIGN_CENTER 2 /****s* GalaxyNG/fielddef * NAME * fielddef -- Printing field definitions. * PURPOSE * Stores information about the fields in a row of a table. * The turn report consists of a number of tables. Each table * consists of a number of rows of fields. The fields in * a table are aligned. To get them aligned the maximum fields * length needs to be known. This length is stored in this * structure. Tables are printed in a two step process. * In the first step nothing is printed and the maximum field * length is computed. In the second step the maximum field length * is used to align and print the fields. * SOURCE */ typedef struct fielddef { int fieldSizes[MAXNOFIELDS]; int fieldNumber; int format; FILE *destination; } fielddef; /********/ #define G_MODE_OWN 0 #define G_MODE_BATTLE 1 #define G_MODE_ALIEN 2 game *createDummyGame(void); void highScoreList(game *aGame); void mailGMReport(game *aGame, char *gameName); void createGMReport(game *aGame, char *gameName, FILE * gmreport); int mailTurnReport(game *aGame, player *aPlayer, long kind); void saveTurnReport(game *aGame, player *aPlayer, long kind); void createTurnReport(game *aGame, player *aPlayer, FILE * report, long kind); void createHeader(game *aGame, player *aPlayer, FILE * reportfile); void appendToFile(char *fileName, FILE * report); void report(game *aGame, player *P, FILE * report); void score(game *g1, game *g2, int html, FILE * dest); void rateRaces(player *playerList); void storeLength(fielddef *fields, int length); void formatReset(fielddef *fields); void formatString(char *s, fielddef *fields); void formatStringCenter(char *s, fielddef *fields); void formatStringMode(char *s, fielddef *fields, int mode); void formatFloat(double g, fielddef *fields); void formatInteger(int i, fielddef *fields); void GformatInteger(int i, fielddef *fields); void BformatInteger(int i, fielddef *fields, char *form); void formatReturn(fielddef *fields); void formatPrint(fielddef *fields); void formatLabels(char *labels, char *align, fielddef *fields); void dumpItem(fielddef *fields, int mode); int visibleShipTypes(game *aGame, player *P2, player *P); int canseeBombing(game *aGame, player *P); void formatChar(char c, fielddef *fields, int mode); void reportPlanet(planet *p, fielddef *fields); void GreportPlanet(planet *planets, planet *p, fielddef *fields); void reportProduction(planet *p, fielddef *fields); void GreportProduction(planet *planets, planet *p, fielddef *fields); void reportGroup(group *g, int n, fielddef *fields, int mode); void GreportGroup(planet *planets, player *P, group *g, int n, fielddef *fields, int mode, int phase); void reportMap(game *aGame, player *P, fielddef *fields); void reportMap_gnuplot(game *aGame, player *P, fielddef *fields); void reportGlobalMessages(strlist *messages, fielddef *fields); void reportMessages(player *P, fielddef *fields); void reportOrders(player *P, fielddef *fields); void reportMistakes(player *P, fielddef *fields); void reportLastOrders(player *players, fielddef *fields); void reportStatus(player *players, player *P, fielddef *fields); void reportYourShipTypes(player *P, fielddef *fields); void reportShipTypes(game *aGame, player *P, fielddef *fields); void reportShipType(shiptype *t, fielddef *fields); void GreportShipType(shiptype *t, fielddef *fields); void reportBattles(game *aGame, player *P, fielddef *fields); void reportBombings(game *aGame, player *P, fielddef *fields); void reportIncoming(game *aGame, player *P, fielddef *fields); void reportYourPlanets(planet *planets, player *P, fielddef *fields); void reportProdTable(planet *planets, player *P, fielddef *fields); void reportRoutes(planet *planets, player *P, fielddef *fields); void reportPlanetsSeen(game *aGame, player *P, fielddef *fields); void reportUnidentifiedPlanets(planet *planets, player *P, fielddef *fields); void reportUninhabitedPlanets(planet *planets, player *P, fielddef *fields); void reportYourGroups(planet *planets, player *P, fielddef *fields); void reportFleets(player *P, fielddef *fields); void GreportFleets(planet *planets, player *P, fielddef *fields); void reportGroupsSeen(game *aGame, player *P, fielddef *fields); void reportGameOptions(game *aGame, fielddef *fields); void reportOptions(game *aGame, player *P, fielddef *fields); void tagVisiblePlanets(planet *planets, player *P); void yourPlanetsForecast(planet *planets, player *P, fielddef *fields); void yourStatusForecast(planet *planets, player *P, fielddef *fields); void reportHall(game *aGame, fielddef *fields); void reportTeam(game *aGame, fielddef *fields, int team); void reportPlayers(player *players, fielddef *fields); void reportRaceProduction(player *players, fielddef *fields); void reportGMBombings(game *aGame, fielddef *fields); void scorePercent(game *g1, fielddef *fields); #if FS_NEW_FORECAST void reportForecast( game *aGame, char *raceName, FILE *forecast ); #endif #endif /* GNG_REPORT_H */ --- NEW FILE: list.h --- #ifndef GNG_LIST_H #define GNG_LIST_H #include <stdlib.h> #include <string.h> #include "util.h" /****s* List/list * NAME * list -- list structure * FUNCTION * Defines the basic structure of a list. * The same layout is copied in all other structures (Planets, shiptype, * battle etc) that we like to store in lists. * Since all these structures start with the same three fields we * can use a number of standard functions to manipulate the lists. * * Base pointer First element Second element * +--+ +------------+ +------------+ * | *-------->| next | *---------->| next | *----------> * +--+ | cookie | | | cookie | | * | name | | | name | | * +------------+ +------------+ * | other data | | other data | * * The cookie is used to do sanity checks. Each kind of list * has its own unique cookie. This way we can check if the * base pointer really points to a list of planets and not * to a list of shiptypes for instance. * SOURCE */ typedef struct list { struct list *next; long cookie; char *name; } list; /**********/ /****f* List/add2List * NAME * add2List -- macro, add an element to the beginning of a list * FUNCTION * Add an element to the beginning of a list. * INPUTS * l -- base address of a list. * e -- address of the element to be added. * EXAMPLE * add2List(&Player->shiptypes, newShipType); * SEE ALSO * add2ListF(), addList() * SOURCE */ #define add2List(l,e) add2ListF((list **)l,(list *)e) /**********/ /****f* List/addList * NAME * addList -- macro, add an element to the end of a list * FUNCTION * Add an element to a list. * Uses evil casts to make it work on different * type of lists and elements, so one function can * be used to add a player to a list of players * and a planet to a list of planets. * INPUTS * l -- pointer to the base of a list. * e -- address of the element to be added. * EXAMPLE * addList(&Player->shiptypes, newShipType); * SEE ALSO * addListF(), add2List() * SOURCE */ #define addList(l,e) addListF((list **)l,(list *)e) /**********/ /****f* List/insertList * NAME * insertList -- macro, add an element to a list after the given element * FUNCTION * Add an element to a list after a specified member, the end if the * member isn't found. * Uses evil casts to make it work on different * type of lists and elements, so one function can * be used to add a player to a list of players * and a planet to a list of planets. * INPUTS * l -- pointer to the base of a list. * a -- address of the anchor element * e -- address of the element to be added. * EXAMPLE * addList(&Player->orders, orderBeingProcessed, mistake); * SEE ALSO * insertListF(), addList(), add2List() * SOURCE */ #define insertList(l,a, e) insertListF((list **)l, (list*)a, (list *)e) /*******/ /****f* List/remList * NAME * remList -- macro, remove an element from a list * SYNOPSIS * remList(l, e) * FUNCTION * INPUTS * l -- pointer to the base of the list. * e -- address of the element to be removed. * SEE ALSO * removeListF(), addList() * SOURCE */ #define remList(l,e) removeListF((list **)l,(list *)e) /********/ /****f* List/findElement * NAME * findElement -- macro, find an element in a list * SYNOPSIS * findElement(t,l,n) * INPUTS * t -- type of the element * l -- base of the list * n -- name of the element (pointer to a string) * SOURCE */ #define findElement(t,l,n) (t *)findElementF((list *)l,n) #define copyElement(t,l,n) (t *)copyElementF((list *)l,n) /********/ /****i* List/numberOfElements * NAME * numberOfElements * SOURCE */ #define numberOfElements(l) numberOfElementsF((list *)l) /********/ /****f* List/setName * NAME * setName -- macro, set the name of an element * SEE ALSO * setNameF() * SOURCE */ #define setName(e, n) setNameF((list *)e, n) /*******/ void add2ListF(list **aList, list *anElement); void freelist(void *base); void addListF(list **aList, list *anElement); void insertListF(list **aList, list* anchor, list *anElement); list *findElementF(list *aList, char *name); void removeListF(list **aList, list *anElement); void setNameF(list *anElement, const char *name); int numberOfElementsF(list *aList); int ptonum(void *base, void *target); void *numtop(void *base, int n); void dumpList(char* label, list* aList, void* callback(void*)); #endif /* GNG_LIST_H */ --- NEW FILE: galaxy.h --- #ifndef GNG_GALAXY_H #define GNG_GALAXY_H /* * * GalaxyNG - UNIX Version * * Created by * o Frans Slothouber (rfsber #at# xs4all.nl), * o Christophe Barbier, * o Jacco van Weert, * o Tommy Lindqvist, * o Rogerio Fung. * * This code contains parts of the the orginal Galaxy code which was * created by Russell Wallace (RWA...@va...), and updated by * the Galaxy PBeM Development Group which include: * o Russell Wallace (RWA...@va...) * o Tim Myers (tm...@un...), * o Robert Stone (st...@at...), * o Mayan Moudgill (mou...@cs...), * o Graeme Griffiths (gr...@ab...), * o K Pankhurst (k.p...@ic...). * */ /****h* GalaxyNG/GameElements * FUNCTION * This module has data types for the core elements of the game * and functions to manipulate them. ***** * Will move to another file later on */ /****h* GalaxyNG/Configuration * FUNCTION * This module has data types for the game configuration. * (As specified in the galaxyng.rc file). ***** * Will move to another file later on */ #include "strutl.h" #include "cookies.h" #include "logging.h" #define _GNU_SOURCE #include <stdio.h> #define NAMESIZE 21 /* Maximum length of a name */ #define MAXPOP 1000.0 /* How many people are turned into one colonist */ #define POPPERCOL 8 /* Population increase per turn */ #define POPINC 0.08 /* Number of industry points needed to produce one unit of ship */ #define INDPERSHIP 10 /* Number of industry points needed to produce one unit of CAP */ #define INDPERCAP 5 /* Minimum amount of cargo that has to be uploaded or downloaded */ #define AMOUNTMIN 0.01 #define BATTLEMAGIC 3.107232506 #define DRIVEMAGIC 20.0 /* Turn at which the first phase ends. During the first phase there is a * strict policy for idle players. */ #define ENDPHASE1TURN 12 /* the number of turns one is allowed to miss during the first phase */ #define ORDERGAP1 2 /* the number of turns one is allowed to miss during phase 2 */ #define ORDERGAP2 5 /* CB-19980922. At least TURNS_LEFT from arrival to allow recall a * group/fleet i */ #define TURNS_LEFT 4 #define MAPWIDTH 80 #define MAPHEIGHT 40 #define TRUE 1 #define FALSE 0 #define LINE_BUFFER_SIZE 1024 #define eq == #define Report 0 #define Forecast 1 /* May be this could help turns viewer */ #define MACHINEREPORT_VERSION 0.1 #define XMLREPORT_VERSION 1.5 #define GNG_MAJOR 6 #define GNG_MINOR 4 #define GNG_RELEASE 10 #define GNG_DATE "October 2007" #define getLine(f) fgets(lineBuffer, LINE_BUFFER_SIZE, f) void usage(void); /****d* GameElements/ProductTypes * NAME * ProductTypes -- things a planet can produce. * SOURCE */ enum { PR_CAP, PR_MAT, PR_SHIP, PR_DRIVE, PR_WEAPONS, PR_SHIELDS, PR_CARGO }; /*********/ /****d* GameElements/CargoTypes * NAME * CargoTypes * SOURCE */ enum { CG_CAP, CG_MAT, CG_COL, CG_EMPTY, MAXCARGO }; /*****/ /****d* GalaxyNG/ErrorTypes * NAME * ErrorTypes * SOURCE */ enum error_type { INFO, WARNING, ERROR }; /*******/ typedef struct mapdimensions { double x1, y1; double x2, y2; } mapdimensions; struct player; typedef struct player player; /****s* GameElements/fleetname * NAME * fleetname -- name of a fleet and its speed. * PURPOSE * Structure to keep track of all fleet names of a race. * Can be an element in a standard list. * NOTES * fleetspeed is computed in the fleetphase(), it is not stored * in the turn file. So fleetspeed is incorrect for most of the * time. * SOURCE */ typedef struct fleetname { /* basic list structure */ struct fleetname *next; long cookie; char *name; /* end basic list */ double fleetspeed; } fleetname; /*********/ /****s* GameElements/shiptype * NAME * shiptype -- design of a ship. * PURPOSE * Structure to keep track of all shiptypes of a race. * Can be an element in a standard list. * SOURCE */ typedef struct shiptype { /* basic list structure */ struct shiptype *next; long cookie; char *name; /* end basic list */ double drive; int attacks; double weapons; double shields; double cargo; int flag; } shiptype; /**************/ /****d* GameElements/PlanetFlags * NAME * PlanetFlags -- * FUNCTION * Planet was visable the previous turn, * used by forecast functions to prevent people * from looking into the future. That is examine * planets they will visit next turn before the next * turn runs. * SOURCE */ #define PL_VISPREVTURN 1 /*******/ /****s* GameElements/planet * NAME * planet -- * PURPOSE * Store information about planets. * ATTRIBUTES * inprogress -- Production spent in the last turns, in case * a ship takes several turns to produce. * spent -- production spend on upgrading ships. * SOURCE */ typedef struct planet { /* basic list structure */ struct planet *next; long cookie; char *name; /* end basic list */ player *owner; double x, y; double size; double resources; double pop; double ind; int producing; shiptype *producingshiptype; double cap; double mat; double col; double inprogress; /* Production spent in the last turns */ double spent; struct planet *routes[MAXCARGO]; long flags; } planet; /*********/ /****d** GameElements/GroupFlags * NAME * GroupFlags * SOURCE */ #define GF_INTERCEPT 1 /* group got intercept order */ #define GF_INBATTLE1 2 /* group took part in a battle in phase 1 */ #define GF_INBATTLE2 4 /* group took part in a battle in phase 2 */ /*******/ /****s* GameElements/group * NAME * group -- group structure * FUNCTION * Structure to keep track of groups. * ATTRIBUTES * next * cookie * name - unused. * number - group number, used as a name. * type - ship type of the ships in the group. * drive, weapons, shields, cargo - techlevels of the group. * loadtype - type of cargo loaded. * load - the total amount of cargo loaded. * from - planet of origin. * where - destination planet. * To see how these are used see groupLocation() * dist - distance left to destination planet. * ships - quantity of ships (before a battle if any) * left - quantity of ships surviving a battle * flags - see GroupFlags * thefleet - the fleet the group is part of, if any * attack - cached for speed * defense - cached for speed * location - cached for speed * canshoot - array with one element per ship that indicates * if the ship can fire or not. * alive - array with one element per ship that indicates * if the ship is still alive of not. * numberOfAttackers -- * numberOfAttackersLeft -- * SOURCE */ typedef struct group { struct group *next; unsigned long cookie; char *name; int number; shiptype *type; double drive; double weapons; double shields; double cargo; int loadtype; double load; planet *from; planet *where; double dist; int ships; int left; long flags; fleetname *thefleet; double attack; double defense; int *canshoot; int *alive; int numberOfAttackers; int numberOfAttackersLeft; planet *location; } group; /************/ /****s* GalaxyNG/alliance * NAME * alliance * FUNCTION * Structure to keep track who are part of an alliance. * Can be an element in a standard list. * SOURCE */ typedef struct alliance { struct alliance *next; long cookie; char *name; player *who; } alliance; /**************/ /****s* Battle/participant * NAME * participant -- participant in a battle. * PURPOSE * Structure to keep track of who took part in a battle. * Can be an element in a standard list. * SOURCE */ typedef struct participant { struct participant *next; long cookie; char *name; player *who; group *groups; } participant; /***********/ /****s* Battle/shot * NAME * shot * PURPOSE * Information about a single shot. * SOURCE */ typedef struct shot { player *attacker; shiptype *atype; player *target; shiptype *ttype; int result; } shot; /*********/ /****s* Battle/bprotocol * NAME * bprotocol -- * PURPOSE * Keep track of who fired on who (shot). * SOURCE */ typedef struct bprotocol { long size; /* maximum size */ long cur; /* current size */ shot *shots; /* Array of shots, grows when needed */ } bprotocol; /*******/ /****s* Battle/battle * NAME * battle -- battle structure * PURPOSE * Structure to keep track of all battles that took place. * Can be an element in a standard list. * SOURCE */ typedef struct battle { struct battle *next; long cookie; char *name; planet *where; participant *participants; bprotocol *protocol; int phase; /* Either GF_INBATTLE1 or GF_INBATTLE2 */ } battle; /**************/ /****s* Battle/bombing * NAME * bombing -- bombing structure * PURPOSE * Structure to keep track of which planets were bombed. * Can be an element in a standard list. * SOURCE */ typedef struct bombing { struct bombing *next; long cookie; char *name; planet *where; player *owner; double pop; double ind; int producing; shiptype *producingshiptype; double cap; double mat; double col; player *who; alliance *viewers; } bombing; /*************/ /****s* GameElements/planet_claim * NAME * planet_claim * PURPOSE * Structure to keep track which planets a race claims. * SOURCE */ typedef struct planet_claim { struct planet_claim *next; long cookie; char *name; struct planet *planet_claimed; } planet_claim; /******/ /****s* GameElements/option * NAME * option -- an option a player can switch on or off * PURPOSE * optionName -- the name of the option as used in the O order * optionMask -- */ typedef struct option { char *optionName; long optionMask; } option; /******/ /****s* GameElements/player * NAME * player -- * PURPOSE * Stores information about a race and the person that plays it. * BUGS * This should be called race! * ATTRIBUTES * unused3, unused4, unused5 * -- For future expansion. * masslost -- Total amount of ship mass lost since turn 0. * massproduced -- Total amount of ship mass produces since turn 0. * rating -- Used for the high score list. * team -- for which team does the player play. * realName; -- For in the Hall of Fame * SOURCE */ struct player { player *next; long cookie; char *name; char *addr; char *pswd; int pswdstate; double drive; double weapons; double shields; double cargo; fleetname *fleetnames; shiptype *shiptypes; alliance *allies; group *groups; double mx, my, msize; char *realName; /* For in the Hall of Fame */ int team; int unused3; /* For future expansion */ int unused4; /* For future expansion */ int unused5; /* For future expansion */ double masslost; double massproduced; int lastorders; long flags; strlist *orders; strlist *messages; strlist *mistakes; planet_claim *claimed_planets; double totPop; /* Cache */ double totInd; /* Cache */ double totCap; /* Cache */ double totMat; /* Cache */ double totCol; /* Cache */ int numberOfPlanets; /* Cache */ int rating; /* Used for the high score list */ }; /********/ /****d* GameElements/PlayerFlags * NAME * PlayerFlags * SOURCE */ /* Player want to stay anonymous */ #define F_ANONYMOUS 1 #define F_AUTOUNLOAD 2 #define F_PRODTABLE 4 #define F_SORTGROUPS 8 #define F_GROUPFORECAST 16 #define F_PLANETFORECAST 32 #define F_SHIPTYPEFORECAST 64 #define F_ROUTESFORECAST 128 /* used by the rateRace function */ #define F_SORTED 256 /* Compress turn reports before sending then */ #define F_COMPRESS 512 #define F_GPLUS 1024 /* Players ask for a "machine" turn report 19980620 */ #define F_MACHINEREPORT 2048 /* Include a battle protocol */ #define F_BATTLEPROTOCOL 4096 /* Make every /n a cr lf (not used, can be reused) */ #define F_CRLF 8192 /* Players ask for an xml turn report 19990611 */ #define F_XMLREPORT 16384 /* player is no longer active */ #define F_DEAD 32768 /* is a text report wanted? */ #define F_TXTREPORT 65536 /****************/ /****s* Configuration/server [CB 20010425] * NAME * server -- NG server options structure * PURPOSE * All server options in one place. * Usually feed with .galaxyngrc file * SOURCE */ typedef struct server { char* sendmail; /* the command to email a file */ char* GMemail; /* GM reports go to this address */ char* GMname; /* name the email should appear to be from */ char* GMpassword; /* GM password, for the relay command */ char* SERVERemail; /* Server email */ char* SERVERname; /* name the email should appear to be from */ char* ReplyTo; /* Server replyto */ char* compress; /* the command to compress the body of an email */ char* encode; /* the command to encode the compressed body */ char* fontpath; /* the directory where the fonts are located */ char* due; /* this is used for the -due command */ char* tick_interval; /* this is used for the -immediate command */ } server; /*******/ /****s* Configuration/gameOpt [CB 20010425] * NAME * gameOpt -- NG game options structure * PURPOSE * All game options in one place. * Usualy feed with *.glx file * SOURCE */ typedef struct gameOpt { long gameOptions; int galactic_peace; double initial_drive; double initial_weapons; double initial_shields; double initial_cargo; } gameOpt; /*******/ /****s* GameElements/game * NAME * game -- game structure * PURPOSE * Entry point to all data for one game. * SOURCE */ typedef struct game { player *next; long cookie; char *name; server serverOptions; gameOpt gameOptions; /* the time at which a turn is started, used for sanity check. */ char *starttime; int turn; double galaxysize; /* CB-20010408 */ player *players; /* list with races */ planet *planets; /* list with planets */ battle *battles; /* list with battles */ bombing *bombings; /* list with bombings */ strlist *messages; /* list with messages */ } game; /*******/ typedef struct emailList { /* basic list structure */ struct emailList* next; long cookie; char* name; /* end basic list */ char* addr; char* pswd; } emailList; /****d* GameElements/GameFlags * NAME * GameFlags * SOURCE */ /* Game Options Flags */ #define GAME_NONGBOMBING 1 /* planet is bombed completely and does not change owners */ #define GAME_KEEPPRODUCTION 2 /* production already spent is not lost after a switch of production type */ #define GAME_CREATECIRCLE 4 /* Create systems along the edge of a circle. */ #define GAME_NODROP 8 /* Do not drop idle players */ #define GAME_SAVECOPY 16 /* Save a copy of the turn report in /report when running a turn */ #define GAME_SPHERICALGALAXY 32 /* Galaxy is mapped on a sphere CB-20010401 */ /**********/ extern char map[MAPWIDTH][MAPHEIGHT]; extern char buf[LINE_BUFFER_SIZE]; extern char lineBuffer[2 * LINE_BUFFER_SIZE]; extern char* galaxynghome; extern char* tempdir; extern char* productname[]; extern char* string_mail_to; extern char* string_mail_subject; extern char* string_mail_from; /* used in loadgame.c, should be a parameter */ extern FILE *turnFile; extern struct option options[]; extern char *vcreate; extern char vcid[]; extern char *vprocess; extern char *vphase; extern char *vreport; extern char *vbattle; extern char *vsavegame; extern char *vloadgame; extern int nbrProducts; void loadNGConfig(game* aGame); int spcLockFile(const char* lfpath); #endif /* GNG_GALAXY_H */ --- NEW FILE: process.h --- #ifndef GNG_PROCESS_H #define GNG_PROCESS_H #include "galaxy.h" #include "list.h" #include "util.h" #include "savegame.h" #include "loadgame.h" #include "phase.h" #include "battle.h" #include "report.h" #include "selftest.h" #ifdef WIN32 #include <stdarg.h> #include <stdio.h> /* #include <varargs.h> */ #endif /* $Id: process.h,v 1.1 2008/01/17 23:18:31 gumpu Exp $ */ /****s* GalaxyNG/orderinfo * NAME * orderinfo * PURPOSE * map a order name to its function * SOURCE */ typedef struct _orderinfo orderinfo; struct _orderinfo { char *name; void (*func) (game *aGame, player *, strlist **); }; /******/ /****d* GalaxyNG/RESCODES * NAME * RESCODES -- Error Codes for the orders checker function * SOURCE */ enum ResCodes { RES_OK, /* no error */ RES_NO_ORDERS, /* missing orders */ RES_ERR_GALAXY, /* no #GALAXY line */ RES_NO_GAME, /* can't find the game name */ RES_PASSWORD, /* password mismatch */ RES_PLAYER, /* player name doesn't exist */ RES_TURNRAN, /* orders sent in for a turnt that ran */ RES_DESTINATION, /* can't find the race sending email to */ RES_NODESTINATION, RES_NO_ORDERS_TURN_NBR, /* missing turn number in orders */ RES_NO_REPORT_TURN_NBR, /* missing turn number in a report request */ RES_DEAD_PLAYER /* tried to relay to a dead player */ }; /**********/ #define ORDER_SIZE 1 /* order functions */ void at_order(game *aGame, player *, strlist **); void eq_order(game *aGame, player *, strlist **); /* FS * * * * * * * * * * * * * * * * * * * * * * * * * * * 12/1999 * * * * * * * */ void a_order(game *aGame, player *, strlist **); void b_order(game *aGame, player *, strlist **); void c_order(game *aGame, player *, strlist **); void d_order(game *aGame, player *, strlist **); void e_order(game *aGame, player *, strlist **); void f_order(game *aGame, player *, strlist **); void g_order(game *aGame, player *, strlist **); void h_order(game *aGame, player *, strlist **); /* CB-1990923 * * * * * * * * * * * * * * * * * * * * */ void i_order(game *aGame, player *, strlist **); void j_order(game *aGame, player *, strlist **); /* free k */ void l_order(game *aGame, player *, strlist **); void m_order(game *aGame, player *, strlist **); void n_order(game *aGame, player *, strlist **); void o_order(game *aGame, player *, strlist **); void p_order(game *aGame, player *, strlist **); void q_order(game *aGame, player *, strlist **); void r_order(game *aGame, player *, strlist **); void s_order(game *aGame, player *, strlist **); void t_order(game *aGame, player *, strlist **); void u_order(game *aGame, player *, strlist **); void v_order(game *aGame, player *, strlist **); void w_order(game *aGame, player *, strlist **); void x_order(game *aGame, player *, strlist **); void y_order(game *aGame, player *, strlist **); void z_order(game *aGame, player *, strlist **); void mistake(player *P, enum error_type, strlist *s, char *format, ...); void copyOrders(game *aGame, FILE * orders, char *raceName, char *password, char* final_orders, int theTurnNumber); int areValidOrders(FILE * ordersFile, game **aGame, char **raceName, char **password, char** final_orders, int* theTurnNumber, char **galaxyline ); void preComputeGroupData(game *aGame); void removeDeadPlayer(game *aGame); int getTurnNumber(FILE * orders); char *getDestination(char* subject_line); void doOrders(game *aGame, player *aPlayer, orderinfo *orderInfo, int phase); int runTurn(game *aGame, char *ordersFileName); #if FS_NEW_FORECAST void checkOrders(game *aGame, char *raceName ); #else void checkOrders(game *aGame, char *raceName, FILE * forecast, int kind); #endif void generateErrorMessage(int resNumber, game *aGame, char *raceName, int theTurnNumber, FILE * forecast, char* galaxyline ); #endif /* GNG_PROCESS_H */ --- NEW FILE: report_xml.h --- #include "galaxy.h" #include "report.h" #include "list.h" /* Needed for xml report */ void report_xml(game* aGame, player* P, FILE* report, int type); void rMR_XML(void); void rGZ_XML(void); void rPW_XML(game* aGame, player *P); void rMM_XML(game* aGame, player *P, strlist *messages, char *c); void rGO_XML(game* aGame); void rOP_XML(game* aGame, player *P); void rOD_XML(game* aGame, player *P); void rMK_XML(game* aGame, player *P); void rST_XML(game* aGame, player *P); void rSH_XML(game* aGame, player *P); void rBT_XML(game* aGame, player *P); void rBB_XML(game* aGame, player *P); void rGP_XML(group *g, int n, int mode); void rMP_XML(game* aGame, player *P); void rIC_XML(game* aGame, player *P); void rAP_XML(game* aGame, player *P); void rPL_XML(planet *p, char *owner); void rRT_XML(game* aGame, player *P); void rPT_XML(game* aGame, player *P); void rGG_XML(game* aGame, player *P); void rFL_XML(game* aGame, player *P); void rGS_XML(game* aGame, player *P); void rPD_XML(planet *p); void rEN_XML(void); --- NEW FILE: battle.h --- #ifndef GNG_BATTLE_H #define GNG_BATTLE_H #include "galaxy.h" /****s* Battle/batstat * NAME * batstat * PURPOSE * Structure to track all groups of one player involved in a battle. * ATTRIBUTES * targetArray -- An array with pointers to all groups. * First all armed groups, then all unarmed groups * canshoot -- array with one element per ship that indicates * if the ship can fire and has fired. * noEnemies -- number of enemies. * enemies -- * SOURCE */ typedef struct batstat { struct batstat *next; long cookie; char *name; player *who; group *groups; double maxAttack; double minDefense; int numberOfTargets; int numberOfAttackers; int numberOfAttackersLeft; int noEnemies; struct batstat **enemies; } batstat; /***** END batstat ******/ int isWon(batstat *aBatstat); int isDraw(batstat *aBatstat); void fightphase(game *aGame, int phase); void attack(bprotocol *aProtocol, batstat *attackingSide, group *attackingGroup, int attackingShip, batstat *targetSide, group *targetGroup, int targetShip); battle *isBattle(player *players, planet *p); int mustBattle(participant *participants); int attackersLeft(batstat *aBatstat); void resetSides(batstat *aBatstat); int canShoot(group *g); void dumpBattle(battle *b); int shoot(group *attacker, group *defender); void allocEnemies(batstat *batstats); void doBattle(batstat *batstats, bprotocol *p, int phase); group *selectTargetGroup(batstat *attackingSide, batstat **targetSide, int *ship); group *selectAttackingGroup(batstat *batstats, batstat **attackingSide, int *ship); void updateGroups(battle *b); bprotocol *allocProtocol(void); void addShot(bprotocol *p, player *attacker, shiptype *t1, player *target, shiptype *t2, int result); #endif /* GNG_BATTLE_H */ --- NEW FILE: logging.h --- #if !defined(LOGGING_H_) #define LOGGING_H_ #include <stdio.h> #include <stdarg.h> #include <time.h> /****d* GalaxyNG/DebugLevels * NAME * DebugLevels -- * FUNCTION * DFULL * DWARN * DSTOP * DERR ****** */ enum DebugLevels {DNONE, DERR, DSTOP, DWARN, DFULL, DFULL2}; /****d* GalaxyNG/LogLevels * NAME * LogLevels -- * FUNCTION * LFULL -- Log everything. This creates huge log files. * LPART -- Partial log, used when a turn is ran, messages at this level * end up in the GM report. * LBRIEF -- Be brief. Used during an orders check * LNONE -- Don't log anything. * SEE ALSO * plog() * SOURCE */ enum LogLevels {LNONE, LBRIEF, LPART, LFULL}; /******/ void pdebug(enum DebugLevels level, char *format, ...); void plog(enum LogLevels level, char *format, ...); void plogtime(enum LogLevels level); int openLog(char* filename, char* mode); void closeLog(void); enum LogLevels setLogLevel(enum LogLevels level); enum DebugLevels setDebugLevel(enum DebugLevels level); #endif --- NEW FILE: create.h --- #ifndef GNG_CREATEGAME_H #define GNG_CREATEGAME_H /* $Id: create.h,v 1.1 2008/01/17 23:18:30 gumpu Exp $ */ #include "galaxy.h" #include "avl.h" #include <fcntl.h> #ifdef WIN32 /* #include <varargs.h> */ #include <stdarg.h> #include <stdio.h> #endif /****s* Create/newplayer * NAME * newplayer -- * SOURCE */ typedef struct newplayer { struct newplayer *next; long cookie; char *name; char *addr; char *pswd; int numberOfHomePlanets; double *coreSizes; /* array of doubles; */ double *coreXOffset; double *coreYOffset; int team; int done; /* has been selected in a team game */ } newplayer; /**********/ /****s* Create/gamespecification * NAME * gamespecification -- * FUNCTIONS * Defines the layout of a game, and other things too. * SOURCE */ typedef struct gamespecification { player *next; long cookie; char *name; newplayer *players; double galaxySize; double minDist; double radiusEmptyPlanets; double radiusSecondaryPlanets; int numberOfHomePlanets; double *coreSizes; /* Default size of each core home planet */ int numberOfEmptyPlanets; int numberOfStuffPlanets; int numberOfPlayers; int numberOfRows; int numberOfColumns; int teamGame; gameOpt gameOptions; /* CB 20010425 */ } gamespecification; /*******/ int createGameDirectories(char *name); player *createPlayer(gamespecification *aGameSpec, game *aGame, newplayer *aNewPlayer); gamespecification *readGameSpec(FILE * specfile); void printGameSpecs(gamespecification *gspec); void swap_data(double *v1, double *v2); void Add_Empty_Planets(game *aGame, int nplanets, double empty_dist, double x, double y, int *planet_name, double low_range, double up_range); planet *Add_Core_Home_Planet(game *aGame, double min_dist, int *planet_name, player *Player, double size, double px, double py); planet *Add_Circle_Home_Planet(game *aGame, int pnum, double min_dist, double sphere, int *planet_name, player *aPlayer, int num_players); void Randomize_Planet_Numbers(game *aGame); void Add_Stuff_Planets(game *aGame, int stuff_planets, int *planet_name); int createStandardLayout(gamespecification *aGameSpec, game *aGame, int planet_name); int createCheckeredLayout(gamespecification *aGameSpec, game *aGame, int planet_name); double CalcCirclegalaxysize(int num, double dist, double sphere); game *creategame(gamespecification *gspec); void Add_Circle_Stuff_Planets(game *aGame, int stuff_planets, int *planet_name, double sphere); void Add_Extra_Circle_Stuff_Planets(game *aGame, int circle_stuff_planets, double x, double y, int *planet_name, int min_dist); void Add_Center_Planet(game *aGame, int *planet_name); newplayer *getNextTeamPlayer(newplayer *aNewPlayer, int team); void Add_Extra_Home_Planets(game *aGame, double x, double y, double size, double max_radius, int *planet_name, player *aPlayer, double px, double py); void setTeamAllies(player *firstPlayer); void Add_Team_Stuff_Planets(game *aGame, gamespecification *aGameSpec, int *planet_name); void initUniqifyValues(void); #endif /* GNG_CREATEGAME_H */ --- NEW FILE: util.h --- #ifndef GNG_UTIL_H #define GNG_UTIL_H #include "galaxy.h" #include <limits.h> #include "list.h" #ifdef WIN32 #include <stdarg.h> #include <stdio.h> #endif /* $Id: util.h,v 1.1 2008/01/17 23:18:32 gumpu Exp $ */ /* this function is meant to copy the body of the message into another * file. Note that it is "destructive" in that it won't remember the last * location in the file. Its' initial purpose is to put the body of the * sent mail in the reply to the user upon some sort of failure (request * for a turn in the future, relay to someone that doesn't exist, etc. */ void copyEmailBody(FILE *inMail, FILE *outMail); void loadRanTab(FILE * f); void saveRanTab(FILE * f); unsigned int krandom(void); void resetErnie(unsigned long seed); int frand3(int r); void ftrunc3(void); FILE *Fopen(char *filename, char *mode); FILE *GOS_fopen(char *filename, char *mode); int GOS_mkdir(char *filename, int mode); int GOS_delete(char *filename); int GOS_copy(char *fromfile, char *tofile); void *alloc(unsigned int n); double frand(double x); double frand2(void); planet *addplanet(game *aGame); int atwar(player *P, player *P2); double weaponmass(shiptype *t); double typemass(shiptype *t); double shipmass(group *g); double groupSpeed(group *g); double fleetSpeed(fleetname *fl, group *g); /* CB-19980922 */ double cargospace(group *g); double calcdefense(group *target); int cankill(group *attack, group *target); int numOfGroupsInFleet(fleetname *fl, group *g); void putmap(mapdimensions *md, double x, double y, int c); double dist(game *aGame, planet *p1, planet *p2); /* CB-20010401 */ void send(game *aGame, group *g, planet *p); /* CB-20010401 */ void recall(game *aGame, group *g); /* CB-19980923 */ void setproduction(game *aGame, planet *p, int t); double groupx(game *aGame, group *g); double groupy(game *aGame, group *g); void freebattles(game *aGame); void freemessages(void); void freegame(game *aGame); double effectiveIndustry(double pop, double ind); void dumpGame(void); void dumpPlanets(planet *aPlanet); void dumpPlayers(player *aPlayer); char *createString(char *format, ...); int ssystem(char *format, ...); void savefprintf(FILE * f, char *format, ...); int canseegroup(player *P, group *g); int canseeplanet(player *P, planet *p); int isunidentified(player *P, planet *p); int isuninhabited(player *P, planet *p); double typeSpeed(shiptype *t); double typeDefense(shiptype *t); double groupDefense(group *g); double groupAttack(group *g); void *allocStructF(unsigned int n, long cookie); planet *findPlanet(game *aGame, char *name); planet *groupLocation(game *aGame, group *g); double round2(double); double roundup2(double); void numberGroup(player *aPlayer, group *aGroup); group *findgroup(player *P, char *s); void raceStatus(game *aGame); double effectiveIndustry(double pop, double ind); double addShipAtt(game* aGame, planet* p); char* rightNow(void); #endif /* GNG_UTIL_H */ --- NEW FILE: report_m.h --- #include "galaxy.h" #include "list.h" #include "report.h" /* Needed for machine report */ /* void reports_m (char *gameName); */ void report_m(player *P, game *aGame, FILE *reportFile); void rHE_M(game *aGame, player *P); void rMR_M(void); void rGZ_M(game *aGame); void rPW_M(game *aGame, player *P); void rMM_M(game *aGame, player *P, strlist *messages, char *c); void rGO_M(game *aGame); void rOP_M(game *aGame, player *P); void rOD_M(game *aGame, player *P); void rMK_M(game *aGame, player *P); void rST_M(game *aGame, player *P); void rSH_M(game *aGame, player *P); void rBT_M(game *aGame, player *P); void rBB_M(game *aGame, player *P); void rGP_M(group *g, int n, int mode); void rMP_M(game *aGame, player *P); void rIC_M(game *aGame, player *P); void rAP_M(game *aGame, player *P); void rPL_M(planet *p); void rRT_M(game *aGame, player *P); void rPT_M(game *aGame, player *P); void rGG_M(game *aGame, player *P); void rFL_M(game *aGame, player *P); void rGS_M(game *aGame, player *P); void rPD_M(planet *p); void rEN_M(void); --- NEW FILE: wopr.h --- #ifndef GNG_WOPR_H #define GNG_WOPR_H #define READING_NONE 0 #define READING_TYPES 1 #define READING_GROUPS 2 game *WOPR_createGame( ); shiptype *WOPR_createShiptype( char *name, double drive, int attacks, double weapons, double shields, double cargo ); void WOPR_allies( game *aGame, char *playerName1, char *playerName2 ); int WOPR_battle( int argc, char **argv ); player *WOPR_addPlayer( game *aGame, char *name ); int parse_group( game *aGame, player *aPlayer ); int WOPR_parse_type( game *aGame, player *aPlayer ); int WOPR_parse_scenario( FILE *scenario, game *aGame ); void WOPR_usage( void ); #endif /* GNG_WOPR_H */ --- NEW FILE: loadgame.h --- #ifndef GNG_LOADGAME_H #d... [truncated message content] |
From: Frans S. <gu...@us...> - 2008-01-17 23:18:27
|
Update of /cvsroot/galaxyng/NG_Stable/Util In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv9654/Util Added Files: mail_report.header mail_report.tail makefile run_game.header run_game.tail Log Message: baseline version as used at sifar.xs4all.nl --- NEW FILE: mail_report.tail --- NOTICEDIR=notices BULLETIN=$NOTICEDIR/global.bulletin INFO=$NOTICEDIR/$1.info NOTICE=$NOTICEDIR/$1.$2.notice GNOTICE=$NOTICEDIR/$2.notice TEMPFILE=$TEMPDIR/g$1$2.txt TEMPFILE2=$TEMPDIR/g$1-$2-mtemp2 ZTEMPFILE=$TEMPDIR/g$1-$2-mtemp.zip case $5 in ( A | a ) { SUBJECT="Galaxy Game $1 Turn $2 Report for $3"; } ;; ( M | m ) { SUBJECT="Galaxy Game $1 Turn $2 Machine Report for $3"; } ;; ( X | x ) { SUBJECT="Galaxy Game $1 Turn $2 XML Report for $3"; } ;; esac BTITLE="Bulletins for Galaxy Game $1 Turn $2" # Report comes through stdin. Think of it as a birth canal. rm -f $TEMPFILE echo \ "To:" $4 "("$3") From: " $FROM " (GalaxyNG Engine) Reply-To:" $REPLY_TO " Sender:" $SENDER " Subject:" $SUBJECT " " > $TEMPFILE2 echo $BTITLE > $TEMPFILE echo "" >> $TEMPFILE if test ! "$5" = M; then if test -r $NOTICE; then echo $1" NOTICE " >>$TEMPFILE; \ cat $NOTICE >> $TEMPFILE; \ echo " " >> $TEMPFILE; fi if test -r $GNOTICE; then \ cat $GNOTICE >> $TEMPFILE; \ echo " " >> $TEMPFILE; fi if test -r $BULLETIN; then echo "NOTES " >>$TEMPFILE; \ cat $BULLETIN >> $TEMPFILE; \ echo " " >> $TEMPFILE; fi if test -r $INFO; then echo $1" INFO " >>$TEMPFILE; \ cat $INFO >> $TEMPFILE; \ echo " " >> $TEMPFILE; fi fi if test "$5" = m -o "$5" = a -o "$5" = x; then { cat - >> $TEMPFILE zip -j $ZTEMPFILE $TEMPFILE rm -f $TEMPFILE uuencode $ZTEMPFILE report.zip > $TEMPFILE cat $TEMPFILE2 $TEMPFILE | $SENDMAIL } else { cat $TEMPFILE2 $TEMPFILE - | $SENDMAIL } fi rm -f $TEMPFILE $TEMPFILE2 $ZTEMPFILE --- NEW FILE: mail_report.header --- #!/bin/bash ## $Id: mail_report.header,v 1.1 2008/01/17 23:18:30 gumpu Exp $ ## ## This is a script that uses SENDMAIL to mail reports out. This is done ## to provide maximal flexability. Your machine and version of SENDMAIL ## may require to you tweak the settings below. Information regarding this ## will be provided as it becomes available. ## ## ## ## Arguments to mail_reports: ## ## $1 - Name of the game to mail reports for. ## $2 - Turn Number ## $3 - Race Name ## $4 - Address ## $5 - Type ( M == machine A == plain text ## m == machine compressed, a == plain text compressed) ## ## Settings! Don't overlook! # # Option to include notice file for a particular turn: # # Put a file called "Game.1.notice" in the directory where this # script is executed. NOTE that "Game" must be capitalized. # # Your sendmail command and the appropriate flags. # -ba = ARPANET header parsing # -t = Parse To: header # -oi = Immediate processing. This could be changed to queue or # background depending on how you want to do things. --- NEW FILE: run_game.header --- # Function: run a galaxyng turn # Synopsis: run_game <game_name> [turn number] # # $Id: run_game.header,v 1.1 2008/01/17 23:18:30 gumpu Exp $ # # # Settings # --- NEW FILE: makefile --- # # $Id: makefile,v 1.1 2008/01/17 23:18:30 gumpu Exp $ # clean: rm -f *~ depend: @: # DO NOT DELETE THIS LINE -- make depend depends on it. --- NEW FILE: run_game.tail --- GALAXY=$BASE/galaxyng GAME=$1 # Script cd $BASE if { test -z $2; } then { # # Determine current turn number from next_turn # TURN=`cat data/$1/next_turn` } else { # # We land here in case of a re-run of a turn. Set the turn # number to the second parameter. # TURN=$2 } fi if { ! test -e orders/$GAME/$TURN.all; } then { # # If the #.all file doesn't exist, create it. # Copy the orders of all nations into a single file. # cat orders/$GAME/*.$TURN > orders/$GAME/$TURN.all # Clean-up: # Since all individual order sets for each nation have been copied # to $TURN.all we can remove them. # rm -f orders/$GAME/*.$TURN } fi # # Delete the old turn reports # rm reports/$GAME/*.txt # # Run turn and email turn reports. # $GALAXY -run $GAME orders/$GAME/$TURN.all $TURN # # Create the web directory if necessary # if { test ! -d $WWWHOME/$GAME/ ; } then { mkdir $WWWHOME/$GAME/ ; } fi # # Create the influence map and move it to the web directory. # Uncomment the following lines if you want to create a public # influence map. # #$GALAXY -influence $GAME public $TURN #mv data/$GAME/public_$TURN.png $WWWHOME/$GAME/ # # Create the high score list in HTML and copy it to the web directory. # $GALAXY -score $GAME > $WWWHOME/$GAME/score.html # # Alternatively, uncomment the following lines to copy the plain text # high score list to the web directory. # #cp notices/$GAME.score $WWWHOME/$GAME/score$TURN.txt #chmod a+r $WWWHOME/$GAME/score$TURN.txt # # Copy the next_turn file to the web directory so it can be used by the # web server to determine the current turn number # cp data/$GAME/next_turn $WWWHOME/$GAME/ # # Done. # |
Update of /cvsroot/galaxyng/NG_Stable/Source In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv9654/Source Added Files: Makefile a_order.c angostur.ttf at_order.c avl.c b_order.c battle.c c_order.c checkTime.c cmd_battletest.c cmd_check.c cmd_clean.c cmd_create.c cmd_dump.c cmd_graph.c cmd_immediate.c cmd_mail0.c cmd_ordersdue.c cmd_relay.c cmd_relaymessage.c cmd_report.c cmd_run.c cmd_score.c cmd_selftest.c cmd_template.c cmd_test.c cmd_webcheck.c cmd_webreport.c create.c d_order.c e_order.c eq_order.c f_order.c g_order.c galaxyng.c h_order.c i_order.c influence.c j_order.c l_order.c list.c loadgame.c m_order.c n_order.c o_order.c p_order.c phase.c process.c q_order.c r_order.c report.c report_m.c report_xml.c s_order.c savegame.c selftest.c t_order.c u_order.c unittest.c usage.c v_order.c w_order.c wopr.c x_order.c y_order.c z_order.c Log Message: baseline version as used at sifar.xs4all.nl --- NEW FILE: b_order.c --- #include "galaxyng.h" /****f* Process/b_order * NAME * b_order -- break off ships from a group or remove a group from a fleet * SOURCE */ void b_order( game *aGame, player *P, strlist **s ) { group *g; /* pointer to named group */ group *g2; /* pointer to new group */ int i; /* int value for number of ships */ char *ns; /* char value for number of ships */ DBUG_ENTER( "b_order" ); /* find the named group */ g = findgroup( P, getstr( 0 ) ); if ( !g ) { mistake( P, INFO, *s, "Group not recognized." ); DBUG_VOID_RETURN; } /* check to see if we're detaching from a fleet */ ns = getstr( 0 ); if ( noCaseStrncmp( ns, "fleet", 5 ) == 0 ) { if ( !epsilon( g->dist, 0.0, 0.0001 ) ) { mistake( P, WARNING, *s, "Fleet is in hyperspace." ); DBUG_VOID_RETURN; } g->thefleet = 0; DBUG_VOID_RETURN; } /* are there enough ships to detach? */ i = atoi( ns ); if ( i > g->ships ) { /* FS Dec 1998 */ mistake( P, INFO, *s, "Not enough ships in group." ); DBUG_VOID_RETURN; } /* this was an odd problem */ if ( i < 0 ) { /* KDW July 1999 */ mistake( P, WARNING, *s, "Can't have negative number of ships." ); DBUG_VOID_RETURN; } /* create a new group for what's being broken off and add it to * the list of groups the player owns */ g2 = allocStruct( group ); *g2 = *g; g2->ships = i; g->ships -= i; g2->thefleet = 0; g2->next = NULL; numberGroup( P, g2 ); g2->name = ( char * ) malloc( 8 ); sprintf( g2->name, "%d", g2->number ); addList( &P->groups, g2 ); DBUG_VOID_RETURN; } /******/ --- NEW FILE: w_order.c --- #include "galaxyng.h" /****f* Process/w_order * NAME * w_order -- declare war on another race. * SOURCE */ void w_order( game *aGame, player *P, strlist **s ) { player *P2; alliance *a; DBUG_ENTER( "w_order" ); if ( aGame->turn < aGame->gameOptions.galactic_peace ) { mistake( P, ERROR, *s, "Galactic Peace enforced until turn %d.", aGame->gameOptions.galactic_peace ); DBUG_VOID_RETURN; } P2 = findElement( player, aGame->players, getstr( 0 ) ); if ( !P2 ) { mistake( P, ERROR, *s, "Race not recognized." ); DBUG_VOID_RETURN; } for ( a = P->allies; a; a = a->next ) { if ( a->who == P2 ) { remList( &P->allies, a ); DBUG_VOID_RETURN; } } DBUG_VOID_RETURN; } /***** END w_order *****/ --- NEW FILE: angostur.ttf --- (This appears to be a binary file; contents omitted.) --- NEW FILE: cmd_score.c --- #include "galaxyng.h" /****f* CLI/CMD_score * NAME * CMD_score -- Show highscore list. * FUNCTION * Write a HTML-ized version of the highscore list to stdout. * SOURCE */ int CMD_score( int argc, char **argv ) { int result; int turn_nbr; game *aGameThisTurn; game *aGamePrevTurn; result = EXIT_FAILURE; switch(argc) { case 3: turn_nbr = LG_CURRENT_TURN; break; case 4: turn_nbr = atoi(argv[3]); break; default: usage(); break; } if ( ( aGameThisTurn = loadgame( argv[2], turn_nbr ) ) ) { if ( ( aGamePrevTurn = loadgame( aGameThisTurn->name, aGameThisTurn->turn - 1 ) ) ) { score( aGamePrevTurn, aGameThisTurn, TRUE, stdout ); result = EXIT_SUCCESS; } else { fprintf( stderr, "Could not load game \"%s\", turn %d\n", argv[2], turn_nbr ); } } else { fprintf( stderr, "Could not load game \"%s\" turn %d\n", argv[2], turn_nbr ); } return result; } --- NEW FILE: savegame.c --- #include <assert.h> #include <string.h> #include "savegame.h" /****h* GalaxyNG/SaveGame * NAME * SaveGame -- a number of functions to save a turn to file. * FUNCTION * The whole game structure is written to file in a structured way. * All data is written in ASCII format. Each value is written * on a separate line. And empty line indicates a zero value. * Pointers are converted to index number. This is possible because * all pointers that are used in the game structure are pointers * to elements in a list. * **** * ADDED * The option to write out a .png file of the current map ***** */ char *vsavegame = "$Id: savegame.c,v 1.1 2008/01/17 23:18:29 gumpu Exp $"; /****i* SaveGame/writeString * NAME * writeString -- write a string to file. ***** */ void writeString(char *s) { fprintf(turnFile, "%s\n", s); } /****i* SaveGame/writeFloat * NAME * writeFloat -- write a float to file. ***** */ void writeFloat(double d) { if (d != 0) fprintf(turnFile, "%g\n", d); else fprintf(turnFile, "\n"); } /****i* SaveGame/writeInt * NAME * writeInt ***** */ void writeInt(int i) { if (i) fprintf(turnFile, "%d\n", i); else fprintf(turnFile, "\n"); } /****i* SaveGame/writeLong * NAME * writeLong ***** */ void writeLong(long l) { if (l) fprintf(turnFile, "%ld\n", l); else fprintf(turnFile, "\n"); } /****i* SaveGame/savegame * NAME * savegame -- save a turn to file. * RESULTS * A file with the name <turn number>.new * (optional) a file with the name <turn number>.png * NOTES * The extension .new is there cause of historical reasons. * BUGS * Uses Fopen(). * SOURCE */ void savegame(game *aGame) { player* P; planet* p; sprintf(buf, "%s/data/%s/next_turn", galaxynghome, aGame->name); turnFile = fopen(buf, "w"); assert(turnFile != NULL); fprintf(turnFile, "%d", aGame->turn + 1); fclose(turnFile); sprintf(buf, "%s/data/%s/%d.new", galaxynghome, aGame->name, aGame->turn); turnFile = fopen(buf, "w"); assert(turnFile != NULL); writeString(vcid); /* Galaxy version */ writeInt(aGame->turn); writeFloat(aGame->galaxysize); writeString("@GameOptions"); /* CB-20010407 */ writeFloat(aGame->gameOptions.gameOptions); writeInt(aGame->gameOptions.galactic_peace*-1); writeFloat(aGame->gameOptions.initial_drive); writeFloat(aGame->gameOptions.initial_weapons); writeFloat(aGame->gameOptions.initial_shields); writeFloat(aGame->gameOptions.initial_cargo); writeString("@EGameOptions"); writeString("@Players"); for (P = aGame->players; P; P = P->next) { shiptype *aShipType; fleetname *aFleetName; writeString(P->name); writeString(P->addr); writeString(P->pswd); writeFloat(P->drive); writeFloat(P->weapons); writeFloat(P->shields); writeFloat(P->cargo); writeFloat(P->mx); writeFloat(P->my); writeFloat(P->msize); writeString(P->realName); writeInt(P->team); writeInt(P->unused3); writeInt(P->unused4); writeInt(P->unused5); writeFloat(P->masslost); writeFloat(P->massproduced); writeInt(P->lastorders); writeLong(P->flags); writeString("@ShipTypes"); for (aShipType = P->shiptypes; aShipType; aShipType = aShipType->next) { writeString(aShipType->name); writeFloat(aShipType->drive); writeInt(aShipType->attacks); writeFloat(aShipType->weapons); writeFloat(aShipType->shields); writeFloat(aShipType->cargo); } writeString("@EShipTypes"); writeString("@Fleets"); for (aFleetName = P->fleetnames; aFleetName; aFleetName = aFleetName->next) { writeString(aFleetName->name); } writeString("@EFleets"); } writeString("@EPlayers"); for (P = aGame->players; P; P = P->next) { alliance *anAlliance; writeString("@Allies"); for (anAlliance = P->allies; anAlliance; anAlliance = anAlliance->next) { writeInt(ptonum(aGame->players, anAlliance->who)); } writeString("@EAllies"); } writeString("@Planets"); for (p = aGame->planets; p; p = p->next) { player *owner; writeString(p->name); if ((owner = p->owner)) { writeInt(ptonum(aGame->players, owner)); } else { writeInt(0); } writeFloat(p->x); writeFloat(p->y); writeFloat(p->size); writeFloat(p->resources); writeFloat(p->pop); writeFloat(p->ind); writeInt(p->producing); if (p->producingshiptype) { assert(owner != NULL); writeInt(ptonum(owner->shiptypes, p->producingshiptype)); } else { writeInt(0); } writeFloat(p->cap); writeFloat(p->mat); writeFloat(p->col); writeFloat(p->inprogress); writeFloat(p->spent); /* Should be removed */ } writeString("@EPlanets"); writeString("@Routes"); for (p = aGame->planets; p; p = p->next) { int routeIndex; for (routeIndex = 0; routeIndex < MAXCARGO; routeIndex++) { if (p->routes[routeIndex]) writeInt(ptonum(aGame->planets, p->routes[routeIndex])); else writeInt(0); } } writeString("@ERoutes"); for (P = aGame->players; P; P = P->next) { group *aGroup; writeString("@PGroups"); for (aGroup = P->groups; aGroup; aGroup = aGroup->next) { writeInt(ptonum(P->shiptypes, aGroup->type)); writeInt(aGroup->number); writeFloat(aGroup->drive); writeFloat(aGroup->weapons); writeFloat(aGroup->shields); writeFloat(aGroup->cargo); writeInt(aGroup->loadtype); writeFloat(aGroup->load); if (aGroup->from) writeInt(ptonum(aGame->planets, aGroup->from)); else writeInt(0); if (aGroup->where) writeInt(ptonum(aGame->planets, aGroup->where)); else writeInt(0); writeFloat(aGroup->dist); writeInt(aGroup->ships); if (aGroup->thefleet) writeInt(ptonum(P->fleetnames, aGroup->thefleet)); else writeInt(0); } writeString("@EPGroups"); } saveRanTab(turnFile); fclose(turnFile); } /****/ --- NEW FILE: influence.c --- #include "galaxy.h" #include "influence.h" #include "loadgame.h" int draw_maps(game* aGame, enum map_type type); int CMD_influence(int argc, char* argv[]) { game* aGame; char* type; int result; int turn_nbr; enum map_type map_type; result = EXIT_FAILURE; switch (argc) { case 1: case 2: usage(); return result; case 3: type = "all"; turn_nbr = -1; /* load current turn */ break; case 4: type = argv[3]; turn_nbr = -1; /* load current turn */ break; case 5: type = argv[3]; turn_nbr = atoi(argv[4]); break; default: usage(); return result; } if (strcasecmp(type, "all") == 0) { map_type = AllMaps; } else if (strcasecmp(type, "industry") == 0) { map_type = EffIndMap; } else if (strcasecmp(type, "attack") == 0) { map_type = ShipAttMap; } else if (strcasecmp(type, "defend") == 0) { map_type = ShipDefMap; } else if (strcasecmp(type, "location") == 0) { map_type = LocationMap; } else if (strcasecmp(type, "public") == 0) { map_type = PublicMap; } else { usage(); } if ((aGame = loadgame(argv[2], turn_nbr))) { loadNGConfig(aGame); if (map_type == AllMaps) { for (map_type = FirstMap; map_type < NbrMaps; map_type++) result += draw_maps(aGame, map_type); } else { result = draw_maps(aGame, map_type); } } else { fprintf(stderr, "Could not load game \"%s\".\n", argv[2]); } return result; } struct _map { float* influence; float* factor; } pi_map[901][901]; int draw_maps(game* aGame, enum map_type map_type) { player* P; planet* p; group* gp; FILE* mapfile; /* output for map */ char* err; char map_title[64]; gdImagePtr map_png; /* image */ int white; /* colour indices */ int ship; float scale; int brect[8]; int i, j, k; int iscale; char font[1024]; int idx, x, y, player_nbr; int x0, y0, df, d_e, d_se; int r, g, b; int map_height; int name_rows; float weight; float influence; float factor, limit; int map_colors[][4] = { {0, 0, 0, 0}, /* black */ {255, 255, 255, 0}, /* white */ {255, 0, 0, 0}, /* ship color */ {0, 255, 127, 0}, /* spring green */ {205, 92, 92, 0}, /* indian red */ {132, 112, 255, 0}, /* light slate blue */ {193, 255, 193, 0}, /* DarkSeaGreen1 */ {238, 154, 73, 0}, /* tan2 */ {178, 34, 34, 0}, /* firebrick */ {85, 107, 47, 0}, /* dark olive green */ {255, 250, 205, 0}, /* lemon chiffon */ {240, 255, 255, 0}, /* azure */ {230, 230, 250, 0}, /* lavender */ {255, 228, 225, 0}, /* misty rose */ {235, 245, 230, 0}, /* mint cream */ {135, 206, 250, 0}, /* light sky blue */ /**/ {176, 224, 230, 0}, /* powder blue */ {0, 206, 209, 0}, /* dark turquoise */ {0, 255, 255, 0}, /* cyan */ {102, 205, 170, 0}, /* medium aquamarine */ {46, 139, 87, 0}, /* sea green */ {152, 251, 152, 0}, /* pale green */ {173, 255, 47, 0}, /* green yellow */ {107, 142, 35, 0}, /* olive drab */ /**/ {238, 232, 170, 0}, /* pale goldenrod */ {255, 215, 0, 0}, /* gold */ {222, 184, 135, 0}, /* burlywood */ {255, 160, 122, 0}, /* light salmon */ {255, 140, 0, 0}, /* dark orange */ {240, 128, 128, 0}, /* light coral */ {100, 149, 237, 0}, /* cornflower blue */ {255, 99, 71, 0}, /* tomato */ {255, 105, 180, 0}, /* hot pink */ /**/ {219, 112, 147, 0}, /* pale violet red */ {176, 48, 96, 0}, /* maroon */ {186, 85, 211, 0}, /* medium orchid */ {148, 0, 211, 0}, /* dark violet */ {255, 250, 250, 0}, /* snow1 */ {255, 246, 143, 0}, /* khaki1 */ {238, 220, 130, 0}, /* LightGoldenrod2 */ {205, 155, 155, 0}, /* RosyBrown3 */ {139, 95, 101, 0}, /* LightPink4 */ {205, 150, 205, 0}, /* plum3 */ }; int nbr_of_players, nbr_of_colors; int x1, y1; /* temporary coordinates */ /*long total_mem = 0;*/ nbr_of_colors = sizeof(map_colors) / (sizeof(int)*4); nbr_of_players = numberOfElements(aGame->players); scale = 900.0 / aGame->galaxysize; iscale = (int)scale; if (aGame->serverOptions.fontpath) sprintf(font, "%s/influence.ttf", aGame->serverOptions.fontpath); else strcpy(font, "./influence.ttf"); name_rows = nbr_of_players / 4 + ((nbr_of_players % 4) != 0); switch(map_type) { case EffIndMap: sprintf(buf, "%s/data/%s/effind_%d.png", galaxynghome, aGame->name, aGame->turn); strcpy(map_title, "Effective Industry"); break; #if 0 case ShipAttMap: sprintf(buf, "%s/data/%s/shpatt_%d.png", galaxynghome, aGame->name, aGame->turn); strcpy(map_title, "Ship Attack Potential"); break; case ShipDefMap: sprintf(buf, "%s/data/%s/shpdef_%d.png", galaxynghome, aGame->name, aGame->turn); strcpy(map_title, "Ship Defense Potential"); break; #endif case LocationMap: sprintf(buf, "%s/data/%s/location_%d.png", galaxynghome, aGame->name, aGame->turn); strcpy(map_title, "Locations Only"); break; case PublicMap: sprintf(buf, "%s/data/%s/public_%d.png", galaxynghome, aGame->name, aGame->turn); strcpy(map_title, "Overview"); name_rows = 0; break; default: break; } mapfile = GOS_fopen(buf, "wb"); map_height = 902 + (name_rows+1)*17+2; map_png = gdImageCreateTrueColor(902, map_height); for (i = 0; i < nbr_of_colors; i++) { map_colors[i][3] = gdImageColorAllocate(map_png, map_colors[i][0], map_colors[i][1], map_colors[i][2]); } white = map_colors[1][3]; ship = map_colors[2][3]; gdImageRectangle(map_png, 0, 0, 901, map_height-1, white); gdImageRectangle(map_png, 0, 901, 902, 902, white); gdImageLine(map_png, 0, map_height-1, map_height-1, map_height-1, white); gdImageLine(map_png, 0, 919, map_height-1, 919, white); sprintf(buf, "Map Size: %d", (int)aGame->galaxysize); err = gdImageStringFT((gdImagePtr) NULL, &brect[0], white, font, 12., 0., 0, 0, buf); if (err) fprintf(stderr, "%s\n", err); gdImageStringFT(map_png, NULL, white, font, 12., 0., 3, 916, buf); gdImageLine(map_png, 5 + brect[4], 914, 5+(10*scale) + brect[4], 914, white); for (i = 0; i <= 1; i++) { gdImageLine(map_png, 5+(10*i*scale) + brect[4], 914, 5+(10*i*scale) + brect[4], 908, white); } strcpy(buf, "(10 LY)"); gdImageStringFT(map_png, NULL, white, font, 12.0, 0., 7+brect[4]+10*scale, 916, buf); {int dist_used = 9 + brect[4] + 10*scale; err = gdImageStringFT((gdImagePtr) NULL, &brect[0], white, font, 12., 0., 0, 0, buf); if (err) fprintf(stderr, "%s\n", err); gdImageLine(map_png, dist_used + brect[4], 919, dist_used+brect[4], 902, white); gdImageLine(map_png, 902 - (dist_used + brect[4]), 919, 902 - (dist_used+brect[4]), 902, white); sprintf(buf, "Turn: %d", aGame->turn); gdImageStringFT(map_png, NULL, white, font, 12.0, 0., 904 - (dist_used+brect[4]), 916, buf); } sprintf(buf, "%s: %s", aGame->name, map_title); err = gdImageStringFT((gdImagePtr) NULL, &brect[0], white, font, 12., 0., 0, 0, buf); if (err) fprintf(stderr, "%s\n", err); gdImageStringFT(map_png, NULL, white, font, 12., 0., 451 - (brect[4] / 2), 916, buf); /* set up variables to hold the influence, one float for each * player. We'll combine at the end */ for (j = 0; j < 900; j++) { for (k = 0; k < 900; k++) { if (pi_map[j][k].influence != NULL) { memset((void*)pi_map[j][k].influence, 0, sizeof(float)*nbr_of_players); memset((void*)pi_map[j][k].factor, 0, sizeof(float)*nbr_of_players); } } } if (name_rows) { int row; int name_len; /* draw the player names in the key */ i = 3; /* nations off by 3 due to * black/white/ship color */ j = 0; row = 0; for (P = aGame->players; P; P = P->next) { if (i == nbr_of_colors) { i = 3; } strcpy(buf, P->name); name_len = strlen(buf); while (1) { err = gdImageStringFT((gdImagePtr) NULL, &brect[0], white, font, 12., 0., 0, 0, buf); if (brect[4] < 220) break; buf[--name_len] = '\0'; } err = gdImageStringFT(map_png, NULL, map_colors[i][3], font, 12., 0., 3 + (j*225), 933 + (row * 16), buf); if (err) fprintf(stderr, "%s\n", err); j++; if (j == 4) { j = 0; row++; } i++; } } switch(map_type) { case EffIndMap: case ShipAttMap: case ShipDefMap: /* now add up the influence for each player */ for (p = aGame->planets; p; p = p->next) { player* owner; owner = p->owner; player_nbr = ptonum(aGame->players, owner) - 1; if (player_nbr < 0 && map_type == EffIndMap) continue; switch(map_type) { case EffIndMap: weight = effectiveIndustry(p->pop, p->ind); influence = factor = 0.9; limit = 0.5; break; #if 0 case ShipAttMap: weight=addShipAtt(aGame, p); influence = factor = 0.925; limit = 0.1; break; case ShipDefMap: weight=addShipDef(aGame, P); influence = factor = 0.925; limit = 0.1; break; #endif default: break; } x = (int) ((scale * p->x) + 1); y = (int) ((scale * p->y) + 1); idx = 1; while (weight > limit) { weight *= factor; influence *= factor; x0 = 0; y0 = idx; df = 1 - idx; d_e = 3; d_se = -2 * idx + 5; do { if (x+x0 < 900 && y + y0 < 900) { x1 = x+x0; y1 = y+y0; if (pi_map[x1][y1].influence == NULL) { /*total_mem += sizeof(float)*nbr_of_players*2;*/ pi_map[x1][y1].influence = (float*)calloc(nbr_of_players, sizeof(float)); pi_map[x1][y1].factor = (float*)calloc(nbr_of_players, sizeof(float)); } pi_map[x1][y1].influence[player_nbr] += weight; pi_map[x1][y1].factor[player_nbr] += influence; } if (x0 && (x-x0 > 1 && y+y0<900)) { x1 = x - x0; y1 = y + y0; if (pi_map[x1][y1].influence == NULL) { /*total_mem += sizeof(float)*nbr_of_players*2;*/ pi_map[x1][y1].influence = (float*)calloc(nbr_of_players, sizeof(float)); pi_map[x1][y1].factor = (float*)calloc(nbr_of_players, sizeof(float)); } pi_map[x1][y1].influence[player_nbr] += weight; pi_map[x1][y1].factor[player_nbr] += influence; } if (y0 && (x+x0 < 900 && y-y0 > 1)) { x1 = x+x0; y1 = y-y0; if (pi_map[x1][y1].influence == NULL) { /*total_mem += sizeof(float)*nbr_of_players*2;*/ pi_map[x1][y1].influence = (float*)calloc(nbr_of_players, sizeof(float)); pi_map[x1][y1].factor = (float*)calloc(nbr_of_players, sizeof(float)); } pi_map[x1][y1].influence[player_nbr] += weight; pi_map[x1][y1].factor[player_nbr] += influence; } if (x0 && y0 && (x-x0>1 && y-y0>1)) { x1 = x - x0; y1 = y - y0; if (pi_map[x1][y1].influence == NULL) { /*total_mem += sizeof(float)*nbr_of_players*2;*/ pi_map[x1][y1].influence = (float*)calloc(nbr_of_players, sizeof(float)); pi_map[x1][y1].factor = (float*)calloc(nbr_of_players, sizeof(float)); } pi_map[x1][y1].influence[player_nbr] += weight; pi_map[x1][y1].factor[player_nbr] += influence; } if (x0 != y0) { if (x+y0<900 && y+x0<900) { x1 = x+y0; y1 = y+x0; if (pi_map[x1][y1].influence == NULL) { /*total_mem += sizeof(float)*nbr_of_players*2;*/ pi_map[x1][y1].influence = (float*)calloc(nbr_of_players, sizeof(float)); pi_map[x1][y1].factor = (float*)calloc(nbr_of_players, sizeof(float)); } pi_map[x1][y1].influence[player_nbr] += weight; pi_map[x1][y1].factor[player_nbr] += influence; } if (x0 && (x+y0<900 && y-x0>1)) { x1 = x+y0; y1 = y-x0; if (pi_map[x1][y1].influence == NULL) { /*total_mem += sizeof(float)*nbr_of_players*2;*/ pi_map[x1][y1].influence = (float*)calloc(nbr_of_players, sizeof(float)); pi_map[x1][y1].factor = (float*)calloc(nbr_of_players, sizeof(float)); } pi_map[x1][y1].influence[player_nbr] += weight; pi_map[x1][y1].factor[player_nbr] += influence; } if (y0 && (x-y0>1 && y+x0<900)) { x1 = x-y0; y1 = y+x0; if (pi_map[x1][y1].influence == NULL) { /*total_mem += sizeof(float)*nbr_of_players*2;*/ pi_map[x1][y1].influence = (float*)calloc(nbr_of_players, sizeof(float)); pi_map[x1][y1].factor = (float*)calloc(nbr_of_players, sizeof(float)); } pi_map[x1][y1].influence[player_nbr] += weight; pi_map[x1][y1].factor[player_nbr] += influence; } if (x0 && y0 && (x-y0>1 && y-x0>1)) { x1 = x-y0; y1 = y-x0; if (pi_map[x1][y1].influence == NULL) { /*total_mem += sizeof(float)*nbr_of_players*2;*/ pi_map[x1][y1].influence = (float*)calloc(nbr_of_players, sizeof(float)); pi_map[x1][y1].factor = (float*)calloc(nbr_of_players, sizeof(float)); } pi_map[x1][y1].influence[player_nbr] += weight; pi_map[x1][y1].factor[player_nbr] += influence; } } if (df < 0) { df += d_e; d_e += 2; d_se += 2; } else { df += d_se; d_e += 2; d_se += 4; y0--; } x0++; } while (x0 < y0); idx++; } } /*fprintf(stderr, "total mem used: %ld\n", total_mem);*/ for (i = 1; i < 900; i++) { for (j = 1; j < 900; j++) { int winning_player; float max_weight; max_weight = 0.0; winning_player = -1; for (k = 0; k < nbr_of_players; k++) { if (pi_map[i][j].influence == NULL) continue; if (max_weight < pi_map[i][j].influence[k]) { max_weight = pi_map[i][j].influence[k]; winning_player = k; if (pi_map[i][j].factor[k] > 1.0) pi_map[i][j].factor[k] = 1.0; } } if (winning_player == -1) continue; r = map_colors[(winning_player%40)+3][0] * pi_map[i][j].factor[winning_player]; g = map_colors[(winning_player%40)+3][1] * pi_map[i][j].factor[winning_player]; b = map_colors[(winning_player%40)+3][2] * pi_map[i][j].factor[winning_player]; gdImageSetPixel(map_png, i, j, gdImageColorResolve(map_png, r, g, b)); } } break; case LocationMap: for (p = aGame->planets; p; p = p->next) { player* owner; owner = p->owner; player_nbr = ptonum(aGame->players, owner) - 1; if (player_nbr < 0) continue; x = (int) ((scale * p->x) + 1); y = (int) ((scale * p->y) + 1); r = map_colors[(player_nbr%40)+3][0]; g = map_colors[(player_nbr%40)+3][1]; b = map_colors[(player_nbr%40)+3][2]; gdImageArc(map_png, x, y, 8, 8, 0, 360, gdImageColorResolve(map_png, r, g, b)); } break; case PublicMap: for (p = aGame->planets; p; p = p->next) { player* owner; owner = p->owner; player_nbr = ptonum(aGame->players, owner) - 1; if (player_nbr < 0) continue; x = (int) ((scale * p->x) + 1); y = (int) ((scale * p->y) + 1); gdImageArc(map_png, x, y, 9, 9, 0, 360, gdImageColorResolve(map_png, 0, 255, 0)); } break; case AllMaps: case NbrMaps: /* Trouble in River City - these should never happen */ break; } /* put in markers for all planets */ for (p = aGame->planets; p; p = p->next) { x = (int) ((scale * p->x) + 1); y = (int) ((scale * p->y) + 1); gdImageArc(map_png, x, y, 3, 3, 0, 360, white); } /* put in markers for ships in transit */ for (P = aGame->players; P; P = P->next) { for (gp = P->groups; gp; gp = gp->next) { if (groupLocation(aGame, gp) == NULL) { x = (int) ((scale * groupx(aGame, gp)) + 1); y = (int) ((scale * groupy(aGame, gp)) + 1); gdImageArc(map_png, x, y, 2, 2, 0, 360, ship); } } } gdImagePng(map_png, mapfile); fclose(mapfile); gdImageDestroy(map_png); return 1; } --- NEW FILE: Makefile --- # # $Id: Makefile,v 1.1 2008/01/17 23:18:19 gumpu Exp $ # # This are the setting for a Sun Sparc Station and Linux Box # # !! Warning !! # DO NOT USE -O2 OR ANY OTHER FORM OF OPTIMIZATION # IT WILL BREAK THE CODE # # # NOTE # # There will be many errors if you run 'make depend' -- this is # expected. I've added the option to not include the standard # directories. In practice the standard headers don't change, but # they are easily located in different places on different # systems. As it is written, the makedepend command will generate # all the local dependencies needed to ensure that all objects will # be updated if a header changes, and that's all we really need. # # I would suggest that the 'make depend' command only be run by a # developer, as we can recognize the standard headers in the error # messages and ignore them, while still recognizing other errors # # This makefile is much bigger than necessary. With a few implicit # rules it could be a fraction of the size. However not all versions # of make support this. This makefile will hopefully work with even # all versions of make. # # # Influence mapping: # if you want to have a .png map generated when the -influence # command is used, then you'll need to have libgd # (http://www.boutell.com/gd/) installed with png, jpeg, and # freetype support enabled and uncomment the following lines: ADDTL_CFLAGS = -DDRAW_INFLUENCE_MAP ADDTL_LIBS = -lgd -lpng -lz -ljpeg -lfreetype ADDTL_SRCS = influence.c ADDTL_OBJS = influence.o # # NOTE: that influence mapping is now turned on by default and you'll # have to comment out the above lines to get rid of it # CFLAGS = -Wall -pedantic -I../include -I$(HOME)/include CFLAGS += $(ADDTL_CFLAGS) #CFLAGS += -fdelete-null-pointer-checks -std=gnu99 -D__USE_GNU #CFLAGS += -pipe -Wcast-qual -Wconversion -Wfloat-equal -Wformat=2 #CFLAGS += -Wmissing-declarations -Wmissing-format-attribute -Wnested-externs #CFLAGS += -Wredundant-decls -Wstrict-prototypes -Wunreachable-code LIBS = -L$(HOME)/lib -L /usr/local/lib -L../lib -lgalaxyng -lm $(ADDTL_LIBS) CC=gcc GNG_SRCS=galaxyng.c loadgame.c savegame.c create.c phase.c battle.c \ process.c report.c selftest.c report_xml.c cmd_template.c cmd_run.c \ report_m.c avl.c usage.c cmd_immediate.c influence.c checkTime.c \ cmd_check.c cmd_relay.c cmd_relaymessage.c cmd_create.c cmd_mail0.c \ cmd_clean.c cmd_report.c cmd_score.c cmd_graph.c cmd_dump.c \ cmd_test.c cmd_selftest.c cmd_battletest.c cmd_ordersdue.c \ cmd_webcheck.c cmd_webreport.c $(ADDTL_SOURCES) GNG_OBJS=$(GNG_SRCS:.c=.o) WOPR_SRCS=wopr.c WOPR_OBJS=$(WOPR_SRCS:.c=.o) GALAXYNG=galaxyng WOPR=wopr all: $(GALAXYNG) loadgame.o: loadgame.c $(CC) $(CFLAGS) -c loadgame.c -o loadgame.o cmd_template.o: cmd_template.c $(CC) $(CFLAGS) -c cmd_template.c -o cmd_template.o cmd_relay.o: cmd_relay.c $(CC) $(CFLAGS) -c cmd_relay.c -o cmd_relay.o cmd_relaymessage.o: cmd_relaymessage.c $(CC) $(CFLAGS) -c cmd_relaymessage.c -o cmd_relaymessage.o cmd_create.o: cmd_create.c $(CC) $(CFLAGS) -c cmd_create.c -o cmd_create.o cmd_mail0.o: cmd_mail0.c $(CC) $(CFLAGS) -c cmd_mail0.c -o cmd_mail0.o cmd_immediate.o: cmd_immediate.c $(CC) $(CFLAGS) -c cmd_immediate.c -o cmd_immediate.o cmd_run.o: cmd_run.c $(CC) $(CFLAGS) -c cmd_run.c -o cmd_run.o cmd_clean.o: cmd_clean.c $(CC) $(CFLAGS) -c cmd_clean.c -o cmd_clean.o cmd_report.o: cmd_report.c $(CC) $(CFLAGS) -c cmd_report.c -o cmd_report.o cmd_webreport.o: cmd_webreport.c $(CC) $(CFLAGS) -c cmd_webreport.c -o cmd_webreport.o cmd_score.o: cmd_score.c $(CC) $(CFLAGS) -c cmd_score.c -o cmd_score.o cmd_graph.o: cmd_graph.c $(CC) $(CFLAGS) -c cmd_graph.c -o cmd_graph.o cmd_dump.o: cmd_dump.c $(CC) $(CFLAGS) -c cmd_dump.c -o cmd_dump.o cmd_test.o: cmd_test.c $(CC) $(CFLAGS) -c cmd_test.c -o cmd_test.o cmd_selftest.o: cmd_selftest.c $(CC) $(CFLAGS) -c cmd_selftest.c -o cmd_selftest.o cmd_battletest.o: cmd_battletest.c $(CC) $(CFLAGS) -c cmd_battletest.c -o cmd_battletest.o cmd_ordersdue.o: cmd_ordersdue.c $(CC) $(CFLAGS) -c cmd_ordersdue.c -o cmd_ordersdue.o usage.o: usage.c $(CC) $(CFLAGS) -c usage.c -o usage.o savegame.o: savegame.c $(CC) $(CFLAGS) -c savegame.c -o savegame.o mail0.o: mail0.c $(CC) $(CFLAGS) -c mail0.c -o mail0.o phase.o: phase.c $(CC) $(CFLAGS) -c phase.c -o phase.o battle.o: battle.c $(CC) $(CFLAGS) -c battle.c -o battle.o process.o: process.c $(CC) $(CFLAGS) -c process.c -o process.o report.o: report.c $(CC) $(CFLAGS) -c report.c -o report.o list.o: list.c $(CC) $(CFLAGS) -c list.c -o list.o ordersdue.o: ordersdue.c $(CC) $(CFLAGS) -c ordersdue.c -o ordersdue.o report_xml.o: report_xml.c $(CC) $(CFLAGS) -c report_xml.c -o report_xml.o report_m.o: report_m.c $(CC) $(CFLAGS) -c report_m.c -o report_m.o avl.o: avl.c $(CC) $(CFLAGS) -c avl.c -o avl.o influence.o: influence.c $(CC) $(CFLAGS) -c influence.c -o influence.o galaxyng.o: galaxyng.c $(CC) $(CFLAGS) -c galaxyng.c -o galaxyng.o wopr.o: wopr.c $(CC) $(CFLAGS) -c wopr.c -o wopr.o $(GALAXYNG): $(GNG_OBJS) ../lib/libgalaxyng.a $(CC) $(GNG_OBJS) -o $(GALAXYNG) $(LIBS) $(WOPR): $(WOPR_OBJS) $(CC) $(WOPR_OBJS) -o $(WOPR) $(LIBS) clean: rm -f $(GNG_OBJS) $(WOPR_OBJS) rm -f $(GALAXYNG) rm -f $(GALAXYNG).o rm -f $(WOPR) rm -f $(WOPR).o rm -f core rm -f *.*~ rm -f *~ rm -f tags rm -f $(DOCS) rm -f masterindex.html #========================================================= # For development #========================================================= test: galaxyng cp galaxyng $(HOME)/Games/galaxyng count: egrep -v -G "^ \*" *.c *.h | egrep -v -G "/\*" | wc TAGS: $(SOURCES) etags $(SOURCES) depend: -@makedepend -Y -- $(CFLAGS) -- $(GNG_SRCS) $(WOPR_SRCS) # DO NOT DELETE THIS LINE -- make depend depends on it. galaxyng.o: ../include/galaxy.h ../include/strutl.h ../include/cookies.h galaxyng.o: ../include/logging.h ../include/util.h ../include/list.h galaxyng.o: ../include/process.h ../include/savegame.h ../include/loadgame.h galaxyng.o: ../include/phase.h ../include/battle.h ../include/report.h galaxyng.o: ../include/mail.h ../include/report_m.h ../include/report_xml.h galaxyng.o: ../include/selftest.h ../include/create.h ../include/avl.h galaxyng.o: ../include/galaxyng.h loadgame.o: ../include/loadgame.h ../include/galaxy.h ../include/strutl.h loadgame.o: ../include/cookies.h ../include/logging.h ../include/list.h loadgame.o: ../include/util.h savegame.o: ../include/savegame.h ../include/galaxy.h ../include/strutl.h savegame.o: ../include/cookies.h ../include/logging.h ../include/list.h savegame.o: ../include/util.h create.o: ../include/create.h ../include/galaxy.h ../include/strutl.h create.o: ../include/cookies.h ../include/logging.h ../include/avl.h create.o: ../include/list.h ../include/util.h ../include/report.h create.o: ../include/loadgame.h ../include/mail.h ../include/report_m.h create.o: ../include/report_xml.h ../include/savegame.h ../include/process.h create.o: ../include/phase.h ../include/battle.h ../include/selftest.h phase.o: ../include/galaxy.h ../include/strutl.h ../include/cookies.h phase.o: ../include/logging.h ../include/list.h ../include/util.h phase.o: ../include/phase.h ../include/loadgame.h ../include/savegame.h battle.o: ../include/battle.h ../include/galaxy.h ../include/strutl.h battle.o: ../include/cookies.h ../include/logging.h ../include/list.h battle.o: ../include/util.h process.o: ../include/process.h ../include/galaxy.h ../include/strutl.h process.o: ../include/cookies.h ../include/logging.h ../include/list.h process.o: ../include/util.h ../include/savegame.h ../include/loadgame.h process.o: ../include/phase.h ../include/battle.h ../include/report.h process.o: ../include/mail.h ../include/report_m.h ../include/report_xml.h process.o: ../include/selftest.h report.o: ../include/report.h ../include/galaxy.h ../include/strutl.h report.o: ../include/cookies.h ../include/logging.h ../include/loadgame.h report.o: ../include/list.h ../include/util.h ../include/mail.h report.o: ../include/report_m.h ../include/report_xml.h ../include/create.h report.o: ../include/avl.h selftest.o: ../include/selftest.h ../include/galaxy.h ../include/strutl.h selftest.o: ../include/cookies.h ../include/logging.h ../include/util.h selftest.o: ../include/list.h ../include/create.h ../include/avl.h selftest.o: ../include/process.h ../include/savegame.h ../include/loadgame.h selftest.o: ../include/phase.h ../include/battle.h ../include/report.h selftest.o: ../include/mail.h ../include/report_m.h ../include/report_xml.h report_xml.o: ../include/create.h ../include/galaxy.h ../include/strutl.h report_xml.o: ../include/cookies.h ../include/logging.h ../include/avl.h report_xml.o: ../include/report_xml.h ../include/report.h report_xml.o: ../include/loadgame.h ../include/list.h ../include/util.h report_xml.o: ../include/mail.h ../include/report_m.h cmd_template.o: ../include/galaxyng.h ../include/galaxy.h ../include/strutl.h cmd_template.o: ../include/cookies.h ../include/logging.h ../include/util.h cmd_template.o: ../include/list.h ../include/loadgame.h ../include/process.h cmd_template.o: ../include/savegame.h ../include/phase.h ../include/battle.h cmd_template.o: ../include/report.h ../include/mail.h ../include/report_m.h cmd_template.o: ../include/report_xml.h ../include/selftest.h cmd_template.o: ../include/create.h ../include/avl.h cmd_run.o: ../include/galaxyng.h ../include/galaxy.h ../include/strutl.h cmd_run.o: ../include/cookies.h ../include/logging.h ../include/util.h cmd_run.o: ../include/list.h ../include/loadgame.h ../include/process.h cmd_run.o: ../include/savegame.h ../include/phase.h ../include/battle.h cmd_run.o: ../include/report.h ../include/mail.h ../include/report_m.h cmd_run.o: ../include/report_xml.h ../include/selftest.h ../include/create.h cmd_run.o: ../include/avl.h report_m.o: ../include/create.h ../include/galaxy.h ../include/strutl.h report_m.o: ../include/cookies.h ../include/logging.h ../include/avl.h report_m.o: ../include/report_m.h ../include/list.h ../include/util.h report_m.o: ../include/report.h ../include/loadgame.h ../include/mail.h report_m.o: ../include/report_xml.h avl.o: ../include/avl.h usage.o: ../include/galaxy.h ../include/strutl.h ../include/cookies.h usage.o: ../include/logging.h cmd_immediate.o: ../include/galaxyng.h ../include/galaxy.h cmd_immediate.o: ../include/strutl.h ../include/cookies.h cmd_immediate.o: ../include/logging.h ../include/util.h ../include/list.h cmd_immediate.o: ../include/loadgame.h ../include/process.h cmd_immediate.o: ../include/savegame.h ../include/phase.h ../include/battle.h cmd_immediate.o: ../include/report.h ../include/mail.h ../include/report_m.h cmd_immediate.o: ../include/report_xml.h ../include/selftest.h cmd_immediate.o: ../include/create.h ../include/avl.h influence.o: ../include/galaxy.h ../include/strutl.h ../include/cookies.h influence.o: ../include/logging.h ../include/influence.h ../include/list.h influence.o: ../include/util.h ../include/avl.h ../include/loadgame.h checkTime.o: ../include/galaxyng.h ../include/galaxy.h ../include/strutl.h checkTime.o: ../include/cookies.h ../include/logging.h ../include/util.h checkTime.o: ../include/list.h ../include/loadgame.h ../include/process.h checkTime.o: ../include/savegame.h ../include/phase.h ../include/battle.h checkTime.o: ../include/report.h ../include/mail.h ../include/report_m.h checkTime.o: ../include/report_xml.h ../include/selftest.h checkTime.o: ../include/create.h ../include/avl.h cmd_check.o: ../include/galaxyng.h ../include/galaxy.h ../include/strutl.h cmd_check.o: ../include/cookies.h ../include/logging.h ../include/util.h cmd_check.o: ../include/list.h ../include/loadgame.h ../include/process.h cmd_check.o: ../include/savegame.h ../include/phase.h ../include/battle.h cmd_check.o: ../include/report.h ../include/mail.h ../include/report_m.h cmd_check.o: ../include/report_xml.h ../include/selftest.h cmd_check.o: ../include/create.h ../include/avl.h cmd_relay.o: ../include/galaxyng.h ../include/galaxy.h ../include/strutl.h cmd_relay.o: ../include/cookies.h ../include/logging.h ../include/util.h cmd_relay.o: ../include/list.h ../include/loadgame.h ../include/process.h cmd_relay.o: ../include/savegame.h ../include/phase.h ../include/battle.h cmd_relay.o: ../include/report.h ../include/mail.h ../include/report_m.h cmd_relay.o: ../include/report_xml.h ../include/selftest.h cmd_relay.o: ../include/create.h ../include/avl.h cmd_relaymessage.o: ../include/galaxyng.h ../include/galaxy.h cmd_relaymessage.o: ../include/strutl.h ../include/cookies.h cmd_relaymessage.o: ../include/logging.h ../include/util.h ../include/list.h cmd_relaymessage.o: ../include/loadgame.h ../include/process.h cmd_relaymessage.o: ../include/savegame.h ../include/phase.h cmd_relaymessage.o: ../include/battle.h ../include/report.h ../include/mail.h cmd_relaymessage.o: ../include/report_m.h ../include/report_xml.h cmd_relaymessage.o: ../include/selftest.h ../include/create.h cmd_relaymessage.o: ../include/avl.h cmd_create.o: ../include/galaxyng.h ../include/galaxy.h ../include/strutl.h cmd_create.o: ../include/cookies.h ../include/logging.h ../include/util.h cmd_create.o: ../include/list.h ../include/loadgame.h ../include/process.h cmd_create.o: ../include/savegame.h ../include/phase.h ../include/battle.h cmd_create.o: ../include/report.h ../include/mail.h ../include/report_m.h cmd_create.o: ../include/report_xml.h ../include/selftest.h cmd_create.o: ../include/create.h ../include/avl.h cmd_mail0.o: ../include/galaxyng.h ../include/galaxy.h ../include/strutl.h cmd_mail0.o: ../include/cookies.h ../include/logging.h ../include/util.h cmd_mail0.o: ../include/list.h ../include/loadgame.h ../include/process.h cmd_mail0.o: ../include/savegame.h ../include/phase.h ../include/battle.h cmd_mail0.o: ../include/report.h ../include/mail.h ../include/report_m.h cmd_mail0.o: ../include/report_xml.h ../include/selftest.h cmd_mail0.o: ../include/create.h ../include/avl.h cmd_clean.o: ../include/galaxyng.h ../include/galaxy.h ../include/strutl.h cmd_clean.o: ../include/cookies.h ../include/logging.h ../include/util.h cmd_clean.o: ../include/list.h ../include/loadgame.h ../include/process.h cmd_clean.o: ../include/savegame.h ../include/phase.h ../include/battle.h cmd_clean.o: ../include/report.h ../include/mail.h ../include/report_m.h cmd_clean.o: ../include/report_xml.h ../include/selftest.h cmd_clean.o: ../include/create.h ../include/avl.h cmd_report.o: ../include/galaxyng.h ../include/galaxy.h ../include/strutl.h cmd_report.o: ../include/cookies.h ../include/logging.h ../include/util.h cmd_report.o: ../include/list.h ../include/loadgame.h ../include/process.h cmd_report.o: ../include/savegame.h ../include/phase.h ../include/battle.h cmd_report.o: ../include/report.h ../include/mail.h ../include/report_m.h cmd_report.o: ../include/report_xml.h ../include/selftest.h cmd_report.o: ../include/create.h ../include/avl.h cmd_score.o: ../include/galaxyng.h ../include/galaxy.h ../include/strutl.h cmd_score.o: ../include/cookies.h ../include/logging.h ../include/util.h cmd_score.o: ../include/list.h ../include/loadgame.h ../include/process.h cmd_score.o: ../include/savegame.h ../include/phase.h ../include/battle.h cmd_score.o: ../include/report.h ../include/mail.h ../include/report_m.h cmd_score.o: ../include/report_xml.h ../include/selftest.h cmd_score.o: ../include/create.h ../include/avl.h cmd_graph.o: ../include/galaxyng.h ../include/galaxy.h ../include/strutl.h cmd_graph.o: ../include/cookies.h ../include/logging.h ../include/util.h cmd_graph.o: ../include/list.h ../include/loadgame.h ../include/process.h cmd_graph.o: ../include/savegame.h ../include/phase.h ../include/battle.h cmd_graph.o: ../include/report.h ../include/mail.h ../include/report_m.h cmd_graph.o: ../include/report_xml.h ../include/selftest.h cmd_graph.o: ../include/create.h ../include/avl.h cmd_dump.o: ../include/galaxyng.h ../include/galaxy.h ../include/strutl.h cmd_dump.o: ../include/cookies.h ../include/logging.h ../include/util.h cmd_dump.o: ../include/list.h ../include/loadgame.h ../include/process.h cmd_dump.o: ../include/savegame.h ../include/phase.h ../include/battle.h cmd_dump.o: ../include/report.h ../include/mail.h ../include/report_m.h cmd_dump.o: ../include/report_xml.h ../include/selftest.h ../include/create.h cmd_dump.o: ../include/avl.h cmd_test.o: ../include/galaxyng.h ../include/galaxy.h ../include/strutl.h cmd_test.o: ../include/cookies.h ../include/logging.h ../include/util.h cmd_test.o: ../include/list.h ../include/loadgame.h ../include/process.h cmd_test.o: ../include/savegame.h ../include/phase.h ../include/battle.h cmd_test.o: ../include/report.h ../include/mail.h ../include/report_m.h cmd_test.o: ../include/report_xml.h ../include/selftest.h ../include/create.h cmd_test.o: ../include/avl.h cmd_selftest.o: ../include/galaxyng.h ../include/galaxy.h ../include/strutl.h cmd_selftest.o: ../include/cookies.h ../include/logging.h ../include/util.h cmd_selftest.o: ../include/list.h ../include/loadgame.h ../include/process.h cmd_selftest.o: ../include/savegame.h ../include/phase.h ../include/battle.h cmd_selftest.o: ../include/report.h ../include/mail.h ../include/report_m.h cmd_selftest.o: ../include/report_xml.h ../include/selftest.h cmd_selftest.o: ../include/create.h ../include/avl.h cmd_battletest.o: ../include/galaxyng.h ../include/galaxy.h cmd_battletest.o: ../include/strutl.h ../include/cookies.h cmd_battletest.o: ../include/logging.h ../include/util.h ../include/list.h cmd_battletest.o: ../include/loadgame.h ../include/process.h cmd_battletest.o: ../include/savegame.h ../include/phase.h cmd_battletest.o: ../include/battle.h ../include/report.h ../include/mail.h cmd_battletest.o: ../include/report_m.h ../include/report_xml.h cmd_battletest.o: ../include/selftest.h ../include/create.h ../include/avl.h cmd_ordersdue.o: ../include/galaxyng.h ../include/galaxy.h cmd_ordersdue.o: ../include/strutl.h ../include/cookies.h cmd_ordersdue.o: ../include/logging.h ../include/util.h ../include/list.h cmd_ordersdue.o: ../include/loadgame.h ../include/process.h cmd_ordersdue.o: ../include/savegame.h ../include/phase.h ../include/battle.h cmd_ordersdue.o: ../include/report.h ../include/mail.h ../include/report_m.h cmd_ordersdue.o: ../include/report_xml.h ../include/selftest.h cmd_ordersdue.o: ../include/create.h ../include/avl.h wopr.o: ../include/galaxy.h ../include/strutl.h ../include/cookies.h wopr.o: ../include/logging.h ../include/util.h ../include/list.h wopr.o: ../include/process.h ../include/savegame.h ../include/loadgame.h wopr.o: ../include/phase.h ../include/battle.h ../include/report.h wopr.o: ../include/mail.h ../include/report_m.h ../include/report_xml.h wopr.o: ../include/selftest.h ../include/create.h ../include/avl.h wopr.o: ../include/wopr.h --- NEW FILE: avl.c --- /* * ANSI C Library for maintainance of AVL Balanced Trees * * ref.: * G. M. Adelson-Velskij & E. M. Landis * Doklady Akad. Nauk SSSR 146 (1962), 263-266 * * see also: * D. E. Knuth: The Art of Computer Programming Vol.3 (Sorting and Searching) * * (C) 2000 Daniel Nagy, Budapest University of Technology and Economics * Released under GNU General Public License (GPL) version 2 * */ #include "avl.h" #include <stdio.h> /* Private methods */ /* Swing to the left * Warning: no balance maintainance */ void avl_swl(avl** root){ avl* a=*root; avl* b=a->right; *root=b; a->right=b->left; b->left=a; } /* Swing to the right * Warning: no balance maintainance */ void avl_swr(avl** root){ avl* a=*root; avl* b=a->left; *root=b; a->left=b->right; b->right=a; } /* Balance maintainance after especially nasty swings */ void avl_nasty(avl* root){ switch(root->balance){ case -1:root->left->balance=0; root->right->balance=1; break; case 1: root->left->balance=-1; root->right->balance=0; break; case 0: root->left->balance=0; root->right->balance=0; } root->balance=0; } /* Public methods */ /* Insert element a into the AVL tree t * returns 1 if the depth of the tree has grown * Warning: do not insert elements already present */ int avl_insert(avl_tree* t,avl* a) { /* initialize */ a->left=0; a->right=0; a->balance=0; /* insert into an empty tree */ if(!t->root){ t->root=a; return 1; } if(t->compar(t->root,a)>0){ /* insert into the left subtree */ if(t->root->left){ avl_tree left_subtree; left_subtree.root=t->root->left; left_subtree.compar=t->compar; if(avl_insert(&left_subtree,a)){ switch(t->root->balance--){ case 1: return 0; case 0: return 1; } if(t->root->left->balance<0){ avl_swr(&(t->root)); t->root->balance=0; t->root->right->balance=0; }else{ avl_swl(&(t->root->left)); avl_swr(&(t->root)); avl_nasty(t->root); } }else t->root->left=left_subtree.root; return 0; }else{ t->root->left=a; if(t->root->balance--) return 0; return 1; } }else{ /* insert into the right subtree */ if(t->root->right){ avl_tree right_subtree; right_subtree.root=t->root->right; right_subtree.compar=t->compar; if(avl_insert(&right_subtree,a)){ switch(t->root->balance++){ case -1: return 0; case 0: return 1; } if(t->root->right->balance>0){ avl_swl(&(t->root)); t->root->balance=0; t->root->left->balance=0; }else{ avl_swr(&(t->root->right)); avl_swl(&(t->root)); avl_nasty(t->root); } }else t->root->right=right_subtree.root; return 0; }else{ t->root->right=a; if(t->root->balance++) return 0; return 1; } } } /* Remove an element a from the AVL tree t * returns -1 if the depth of the tree has shrunk * Warning: if the element is not present in the tree, * returns 0 as if it had been removed succesfully. */ int avl_remove(avl_tree* t, avl* a) { int b; if(t->root==a) return avl_removeroot(t); b=t->compar(t->root,a); if(b>=0){ /* remove from the left subtree */ int ch; avl_tree left_subtree; if((left_subtree.root = t->root->left) != NULL) { left_subtree.compar=t->compar; ch=avl_remove(&left_subtree,a); t->root->left=left_subtree.root; if(ch){ switch(t->root->balance++){ case -1: return -1; case 0: return 0; } switch(t->root->right->balance){ case 0: avl_swl(&(t->root)); t->root->balance=-1; t->root->left->balance=1; return 0; case 1: avl_swl(&(t->root)); t->root->balance=0; t->root->left->balance=0; return -1; } avl_swr(&(t->root->right)); avl_swl(&(t->root)); avl_nasty(t->root); return -1; } } } if(b<=0){ /* remove from the right subtree */ int ch; avl_tree right_subtree; if((right_subtree.root = t->root->right) != NULL) { right_subtree.compar=t->compar; ch=avl_remove(&right_subtree,a); t->root->right=right_subtree.root; if(ch){ switch(t->root->balance--){ case 1: return -1; case 0: return 0; } switch(t->root->left->balance){ case 0: avl_swr(&(t->root)); t->root->balance=1; t->root->right->balance=-1; return 0; case -1:avl_swr(&(t->root)); t->root->balance=0; t->root->right->balance=0; return -1; } avl_swl(&(t->root->left)); avl_swr(&(t->root)); avl_nasty(t->root); return -1; } } } return 0; } /* Remove the root of the AVL tree t * Warning: dumps core if t is empty */ int avl_removeroot(avl_tree* t) { int ch; avl* a; if(!t->root->left){ if(!t->root->right){ t->root=0; return -1; } t->root=t->root->right; return -1; } if(!t->root->right){ t->root=t->root->left; return -1; } if(t->root->balance<0){ /* remove from the left subtree */ a=t->root->left; while(a->right) a=a->right; }else{ /* remove from the right subtree */ a=t->root->right; while(a->left) a=a->left; } ch=avl_remove(t,a); a->left=t->root->left; a->right=t->root->right; a->balance=t->root->balance; t->root=a; if(a->balance==0) return ch; return 0; } /* Iterate through elements in t from a range between a and b (inclusive) * for each element calls iter(a) until it returns 0 * returns the last value returned by iterator or 0 if there were no calls * Warning: a<=b must hold */ int avl_range(avl_tree* t,avl* a,avl* b,int(*iter)(avl* a)) { int x,c=0; if(!t->root) return 0; x=t->compar(t->root,a); if(a!=b){ if(x<0){ x=t->compar(t->root,b); if(x>0) x=0; } } if(x>=0){ /* search in the left subtree */ avl_tree left_subtree; if((left_subtree.root = t->root->left) != NULL) { left_subtree.compar=t->compar; if(!(c=avl_range(&left_subtree,a,b,iter))) if(x>0) return 0; } } if(x==0){ if(!(c=iter(t->root))) return 0; } if(x<=0){ /* search in the right subtree */ avl_tree right_subtree; if((right_subtree.root = t->root->right) != NULL) { /* if(right_subtree.root=t->root->right){ */ right_subtree.compar=t->compar; if(!(c=avl_range(&right_subtree,a,b,iter))) if(x<0) return 0; } } return c; } /* Iterate through elements in t equal to a * for each element calls iter(a) until it returns 0 * returns the last value returned by iterator or 0 if there were no calls */ int avl_search(avl_tree* t,avl* a,int(*iter)(avl* a)) { return avl_range(t,a,a,iter); } --- NEW FILE: cmd_webreport.c --- #include "galaxyng.h" /****f* CLI/CMD_webreport * NAME * CMD_webreport -- output a text copy of a turn report. * SYNOPSIS * ./galaxyng -webreport < file_with_email * int CMD_report(int argc, char **argv) * FUNCTION * Recreate a turn report of a given turn. Output it for the player * that requested it. * SOURCE */ int CMD_webreport( int argc, char **argv ) { int result; char *logName; logName = createString( "%s/log/orders_processed.txt", galaxynghome ); openLog( logName, "a" ); free( logName ); plogtime( LBRIEF ); result = EXIT_FAILURE; #if 0 if ( argc >= 2 ) { char* raceName; char* password; char* final_orders; int resNumber, theTurnNumber; game* aGame; raceName = NULL; password = NULL; final_orders = NULL; aGame = NULL; resNumber = areValidOrders( stdin, &aGame, &raceName, &password, &final_orders, &theTurnNumber ); plog(LBRIEF, "Report request from %s for turn %d.\n", raceName, theTurnNumber); if ( ( resNumber == RES_TURNRAN ) || ( ( resNumber == RES_OK ) && ( theTurnNumber == LG_CURRENT_TURN ) ) ) { game *aGame2; if ( theTurnNumber > 0 ) { aGame2 = loadgame( aGame->name, theTurnNumber - 1 ); } else if ( theTurnNumber == LG_CURRENT_TURN ) { theTurnNumber = aGame->turn; aGame2 = loadgame( aGame->name, theTurnNumber - 1 ); } else { aGame2 = loadgame( aGame->name, 0 ); } if ( aGame2 ) { player *aPlayer; int index; loadNGConfig( aGame2 ); if ( theTurnNumber > 0 ) { /* Rerun the turn */ char *ordersName; ordersName = createString( "%s/orders/%s/%d.all", galaxynghome, aGame2->name, theTurnNumber ); runTurn( aGame2, ordersName ); free( ordersName ); } /* Translate the current race name into the name used during the turn that is requested */ aPlayer = findElement( player, aGame->players, raceName ); index = ptonum( aGame->players, aPlayer ); aPlayer = numtop( aGame2->players, index ); if ( theTurnNumber == 0 ) aPlayer->pswdstate = 1; highScoreList( aGame2 ); createTurnReport( aGame2, aPlayer, stdout, 0 ); } else { printf("\n\nThe turn you requested is no longer available...\n" ); } } else if ( resNumber == RES_OK ) { printf("MAJOR TROUBLE\n"); printf("You can't request a %s report for turn %d.\n\n", aGame->name, theTurnNumber); printf("Turn %d hasn't happened yet. While I'm a good " "(some say great) server, I can't predict the future for " "you.\n\n", theTurnNumber); } else { if (resNumber == RES_NO_ORDERS_TURN_NBR) resNumber = RES_NO_REPORT_TURN_NBR; generateErrorMessage( resNumber, aGame, raceName, theTurnNumber, stdout ); } result = ( result ) ? EXIT_FAILURE : EXIT_SUCCESS; if ( raceName ) free( raceName ); if ( password ) free( password ); } closeLog( ); #endif return result; } --- NEW FILE: cmd_report.c --- #include "galaxyng.h" /****f* CLI/CMD_report * NAME * CMD_report -- send a copy of a turn report. * SYNOPSIS * ./galaxyng -check < file_with_email * int CMD_report(int argc, char **argv) * FUNCTION * Recreate a turn report of a given turn. Send it to the player * that requested it. * BUGS * Does not send XML nor machine reports. * SOURCE */ int CMD_report( int argc, char **argv ) { int result; char *logName; logName = createString( "%s/log/orders_processed.txt", galaxynghome ); openLog( logName, "a" ); free( logName ); plogtime( LBRIEF ); result = EXIT_FAILURE; if ( argc >= 2 ) { char* returnAddress; char* raceName; char* password; char* galaxyline = NULL; char* final_orders; int resNumber, theTurnNumber; game* aGame; FILE* report; char* reportName; envelope *anEnvelope; anEnvelope = createEnvelope( ); returnAddress = getReturnAddress( stdin ); theTurnNumber = getTurnNumber( stdin ); plog(LBRIEF, "Report request from %s for turn %d.\n", returnAddress, theTurnNumber); raceName = NULL; password = NULL; final_orders = NULL; aGame = NULL; resNumber = areValidOrders( stdin, &aGame, &raceName, &password, &final_orders, &theTurnNumber, &galaxyline ); reportName = createString("%s/temp_report_copy_%d_%s", tempdir, theTurnNumber, returnAddress); { char *ptr = strrchr(reportName, '/')+1; while (*ptr) { if (!isalnum(*ptr) || isspace(*ptr)) *ptr = '_'; ptr++; } } plog(LBRIEF, "Report is in \"%s\"\n", reportName); setHeader( anEnvelope, MAILHEADER_TO, "%s", returnAddress ); setHeader(anEnvelope, MAILHEADER_REPLYTO, aGame->serverOptions.ReplyTo); anEnvelope->from_name = strdup(aGame->serverOptions.SERVERname); anEnvelope->from_address = strdup(aGame->serverOptions.SERVERemail); report = fopen(reportName, "w"); if ( ( resNumber == RES_TURNRAN ) || ( ( resNumber == RES_OK ) && ( theTurnNumber == LG_CURRENT_TURN ) ) ) { game *aGame2; if ( theTurnNumber > 0 ) { aGame2 = loadgame( aGame->name, theTurnNumber - 1 ); } else if ( theTurnNumber == LG_CURRENT_TURN ) { theTurnNumber = aGame->turn; aGame2 = loadgame( aGame->name, theTurnNumber - 1 ); } else { aGame2 = loadgame( aGame->name, 0 ); } if ( aGame2 ) { player *aPlayer; int index; loadNGConfig( aGame2 ); setHeader( anEnvelope, MAILHEADER_SUBJECT, "[GNG] %s turn %d report copy for %s", aGame->name, theTurnNumber, raceName ); if ( theTurnNumber > 0 ) { /* Rerun the turn */ char *ordersName; ordersName = createString( "%s/orders/%s/%d.all", galaxynghome, aGame2->name, theTurnNumber ); runTurn( aGame2, ordersName ); free( ordersName ); } /* Translate the current race name into the name used during the turn that is requested */ aPlayer = findElement( player, aGame->players, raceName ); index = ptonum( aGame->players, aPlayer ); aPlayer = numtop( aGame2->players, index ); if (aPlayer->flags & F_COMPRESS) anEnvelope->compress = TRUE; if ( theTurnNumber == 0 ) aPlayer->pswdstate = 1; highScoreList( aGame2 ); createTurnReport( aGame2, aPlayer, report, 0 ); } else { setHeader( anEnvelope, MAILHEADER_SUBJECT, "[GNG] %s turn %d report copy for %s", aGame->name, theTurnNumber, raceName ); fprintf( report, "\n\nThe turn you requested is no longer available...\n" ); } } else if ( resNumber == RES_OK ) { setHeader( anEnvelope, MAILHEADER_SUBJECT, "[GNG] Major Trouble" ); fprintf(report, "You can't request a %s report for turn %d.\n\n", aGame->name, theTurnNumber); fprintf(report, "Turn %d hasn't happened yet. While I'm a good " "(some say great) server, I can't predict the future for " "you.\n\n", theTurnNumber); } else { setHeader( anEnvelope, MAILHEADER_SUBJECT, "[GNG] Major Trouble" ); if (resNumber == RES_NO_ORDERS_TURN_NBR) resNumber = RES_NO_REPORT_TUR... [truncated message content] |
From: Frans S. <gu...@us...> - 2008-01-17 23:18:17
|
Update of /cvsroot/galaxyng/NG_Stable/ARE In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv9654/ARE Added Files: are.c makefile Log Message: baseline version as used at sifar.xs4all.nl --- NEW FILE: are.c --- /* $Id: are.c,v 1.1 2008/01/17 23:18:19 gumpu Exp $ */ /****h* Galaxy/ARE * NAME * ARE - automatic registration engine * SYNOPSIS * are <game name> <player limit> <total planet size> * <maximum planet size> <max. number of planets> * < <email> * FUNCTION * Automate the registration process for a game. * The program processes email send in by players wishing to join * a particular game. * * In addition players can specify their home planet sizes * by including the line: * * #PLANETS <size of planet 1> <size of planet 2> ... <size of planet n> * * in the body of their email. * * INPUTS * game name -- * player limit -- maximum number of players that can enroll. * total planet size -- limit on the sum of all planet sizes. * maximum planet size -- limit on the size of each planet. * max. number of planets -- limit on the number of planet that can * be specified. * email -- that what formail generates. * RESULTS * A confirmation message is send to the players. * Three kind of messages can be generated: * (1) You are accepted. * (2) The game is full. * (3) You made an error in your #PLANETS line. * * The email address and planet sizes are written to two files: * (1) $GALAXYHOME/<game name>.players for players that were accepted * (2) $GALAXYHOME/<game name>.standby for players that were rejected. * The contents of these files can be pasted into your .glx file. * $GALAXYHOME is either the value you gave it, or if it is undefined, * $HOME/Games. * * * The programs does the following checks on the #PLANETS line * (1) Whether the size of a single planet exceeds the limit set. * (2) Whether too many planets are specified. * (3) Whether the sum of all sizes exceeds the limit set. * (4) Whether the sum of all sizes is too small. This will be most * likely be because the player made an error. If this error then * shows up in the turn 0 the player is most likely to drop out. * * If any of these errors occur the player is notified and has * to retransmit the enroll request. * * EXAMPLE * * The entry in the .procmailrc file to accept 25 players for the * game Jangi. Players can specify a maximum of 5 planets, of which * the total size should now exceed 2000.0. Each single planet * should be no larger that 1000.0 * * GALAXYNGHOME=$HOME/Games * * :0 rw :jangi.lock * * ^Subject.*Join Jangi * |/usr/bin/formail -rkbt -s {continued on the next line} * $GALAXYNGHOME/are Jangi 25 2000 1000 5 | /usr/sbin/sendmail -t * * This assumes the program is installed in $GALAXYNGHOME * * Players can now enroll in the game sending you an email with * the subject: * * "Join Jangi" ******* */ #include <stdio.h> #include <ctype.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <assert.h> #define eq == #define TRUE 1 #define FALSE 0 #define LINE_BUFFER_SIZE 1024 char lineBuffer[LINE_BUFFER_SIZE+2] ; /****** ARE/UserDefines * NAME * UserDefines -- * FUNCTION * Please change these to reflect your own system's settings. * SOURCE */ #define FROMHEADER "From: Registration_Engine <ngs...@xs...>\n" #define SUBJECT "Subject: Enrollment Reply\n" #define REPLYTO "Reply-To: rf...@xs...\n" #define CCHEADER "Cc: rf...@xs...\n" /*******/ /****v* GalaxyNG/galaxynghome * NAME * galaxynghome -- path to all data files * SOURCE */ char *galaxynghome = NULL; /*****/ #define T_PLAYER 1 #define T_STANDBY 2 int countPlayersRegistered(char *gameName); int registerPlayer(char *address, char *planets, char *gameName, int type); void playerMessage(char *gameName, char *address, char *planets); void standbyMessage(char *gameName); int getPlanetSizes(FILE *orders, char **planets, double totalPlanetSize, int maxNumberOfPlanets, double maxPlanetSize); char *getReturnAddress(FILE *orders); char *getstr(char *s); int noCaseStrncmp(char *s, char *t, int n); void badPlanetMessage(char *planets); int main(int argc, char **argv) { int errorCode; char *value; if ((value = getenv("GALAXYNGHOME"))) { galaxynghome = strdup(value); } else if ((value = getenv("HOME"))) { sprintf(lineBuffer, "%s/Games", value); galaxynghome = strdup(lineBuffer); } else { galaxynghome = strdup("/please/set/your/HOME/or/GALAXYNGHOME/variable"); } errorCode = EXIT_FAILURE; if (argc eq 6) { int maxNumberOfPlayers, curNumberOfPlayers, maxNumberOfPlanets; double totalPlanetSize, maxPlanetSize; int ret; char sys_string[2000]; curNumberOfPlayers = countPlayersRegistered(argv[1]); maxNumberOfPlayers = atoi(argv[2]); totalPlanetSize = atof(argv[3]); maxPlanetSize = atof(argv[4]); maxNumberOfPlanets = atoi(argv[5]); if (curNumberOfPlayers >= 0) { char *address; if ((address = getReturnAddress(stdin))) { char *planets; printf("To: %s\n%s%s%s%s", address, FROMHEADER, CCHEADER, SUBJECT, REPLYTO); printf( "\n\nMessage from A.R.E (Automatic Registration Engine)\n" "\n" "\nGreetings,\n"); sprintf(sys_string,"/bin/grep %s %s/%s.players > /dev/null",address,galaxynghome,argv[1]); ret = system(sys_string); if (ret==0) { printf("\nERROR:\n" "You are already registered for this game\n"); exit(0); } if (getPlanetSizes(stdin, &planets, totalPlanetSize, maxNumberOfPlanets, maxPlanetSize)) { errorCode = registerPlayer( address, planets, argv[1], (curNumberOfPlayers < maxNumberOfPlayers) ? T_PLAYER : T_STANDBY); if (errorCode == EXIT_SUCCESS) { if (curNumberOfPlayers < maxNumberOfPlayers) { playerMessage(argv[1], address, planets); } else { standbyMessage(argv[1]); } } } else { /* Player made a mistake in planet sizes */ badPlanetMessage(planets); } if (planets) free(planets); if (address) free(address); } else { fprintf(stderr, "ARE: Can't determine return address.\n"); } } else { fprintf(stderr, "ARE: Can't determine the number players that enrolled.\n"); } } else { fprintf(stderr, "ARE: Incorrect number of parameters.\n" "ARE: Correct usage: are <gamename> <limit>\n" " <total planet size> <maximum planet size>\n" " <maximum number of planets>\n" ); } return errorCode; } int getPlanetSizes(FILE *orders, char **planets, double totalPlanetSize, int maxNumberOfPlanets, double maxPlanetSize) { char *isRead; char *c, *ns; double totalSize = 0.0; int numberOfPlanets = 0, result; double size; int tooBig; result = TRUE; /* All is OK */ for (isRead = fgets(lineBuffer, LINE_BUFFER_SIZE, orders); isRead; isRead = fgets(lineBuffer, LINE_BUFFER_SIZE, orders)) { if (noCaseStrncmp("#PLANETS", lineBuffer, 3) == 0) break; } printf("\n"); if (isRead != NULL) { getstr(lineBuffer); tooBig = FALSE; printf("\nProcessing your planet specifications.\n"); for (ns = getstr(0); ns[0] != '\0'; ns = getstr(0)) { size = atof(ns); totalSize += size; if (size > maxPlanetSize) { tooBig = TRUE; } numberOfPlanets++; } if (tooBig) { printf("\nERROR:\n" "One or more of your planets are larger than the\n" "limit of %.1f set by the game master.\n\n", maxPlanetSize); result = FALSE; } if (numberOfPlanets > maxNumberOfPlanets) { printf("\nERROR:\n" "You specified %d planets, only %d planets are allowed.\n\n", numberOfPlanets, maxNumberOfPlanets); result = FALSE; } if (totalSize > totalPlanetSize) { printf("\nERROR:\n" "The sum of the sizes of all your planets is %9.2f.\n" "This exceeds the limit of %9.2f set by your game master.\n" "Please reduce the size of some of your planets.\n\n", totalSize, totalPlanetSize); result = FALSE; } if (totalSize < totalPlanetSize - 25.0) { printf("\nWARNING:\n" "The sum of the sizes of your planets is: %9.2f\n" "The maximum limit set by your game master is: %9.2f\n" "This means that you can increase the size of one (or more) of\n" "your planets by %.2f!\n" "My guess is that you want to edit and retransmit your\n" "specification and make use of this additional space.\n\n", totalSize, totalPlanetSize, totalPlanetSize - totalSize); result = FALSE; } *planets = strdup(lineBuffer + 8); if (result) { printf("All planets are OK.\n\n"); } } else { *planets = NULL; /* no planet sizes were specified */ } return result; } /****** ARE/registerPlayer * NAME * registerPlayer -- * FUNCTION * * RESULT * errorCode * EXIT_SUCCESS All is OK * EXIT_FAILURE Something went wrong * Address of the player that registered is appended to * either <gameName>.players or <gameName>.standby ****** */ int registerPlayer(char *address, char *planets, char *gameName, int type) { FILE *registerFile; char *readit; int errorCode; errorCode = EXIT_SUCCESS; if (type eq T_PLAYER) { sprintf(lineBuffer, "%s/%s.players", galaxynghome, gameName); } else { sprintf(lineBuffer, "%s/%s.standby", galaxynghome, gameName); } if ((registerFile = fopen(lineBuffer, "a"))) { fprintf(registerFile, "start_player\n"); fprintf(registerFile, "email %s\n", address); fprintf(registerFile, "end_player"); if (planets) { fprintf(registerFile, " %s", planets); } else { fprintf(registerFile, "\n"); } fclose(registerFile); } else { fprintf(stderr, "ARE: can't open %s\n", lineBuffer); errorCode = EXIT_FAILURE; } return errorCode; } /****** ARE/countPlayersRegistered * NAME * countPlayersRegistered * SYNOPSIS * int countPlayersRegistered(char *) * count = countPlayersRegistered(gameName) * FUNCTION * Count the number of players that registered sofar for a game. * This is done by counting the number of lines in the * <gamename>.players file. * INPUTS * gameName -- Name of the game the player is enrolling in. * RESULT * count * < 0 -- something went wrong, registration file could not be opened. * >= 0 -- number of players that registered sofar * SEE ALSO * GAMEPATH ******** */ int countPlayersRegistered(char *gameName) { FILE *registerFile; char *fileName; int count; sprintf(lineBuffer, "%s/%s.players", galaxynghome, gameName); fileName = strdup(lineBuffer); if ((registerFile = fopen(fileName, "r"))) { char *readIt; count = 0; for(readIt = fgets (lineBuffer, LINE_BUFFER_SIZE, registerFile); readIt; readIt = fgets (lineBuffer, LINE_BUFFER_SIZE, registerFile)) { count++; } fclose(registerFile); count /= 3; /* count one player per 3 lines */ } else { /* Maybe the file does not exist yet */ if (registerFile = fopen(fileName, "w")) { count = 0; fclose(registerFile); } else { fprintf(stderr, "ARE: can't open %s\n", fileName); count = -1; } } free(fileName); return count; } void badPlanetMessage(char *planets) { printf( "\nYou tried to enroll using the following #PLANETS specification\n" " %s\n", planets); printf( "This line contains one or more errors/warnings as described above.\n" "You are therefore not yet enrolled in the game.\n" "Please correct the mistake and retransmit the enroll request.\n"); } /****** ARE/playerMessage * NAME * playerMessage -- write the "accepted" message * FUNCTION * Prints the "You Are Accepted" message to stdout. ****** */ void playerMessage(char *gameName, char *address, char *planets) { printf( "I am happy to report that you have been accepted for the game %s.\n" "Your address:\n" " %s\n" "has been added to the list.\n" " \n", gameName, address); if (planets) { printf("Your planet sizes will be:\n %s\n\n", planets); } printf( "Please note that I am a program. My only function is to register\n" "your name. I am not smart enough to answer any questions that you\n" "might have put in your mail.\n" "\n" "For more information about GalaxyNG, have a look at\n" " http://galaxyng.sourceforge.net/\n" "Now is a good time to read the manual:\n" " http://galaxyng.sourceforge.net/manual.php\n" "and the FAQ: \n" " http://galaxyng.sourceforge.net/faq.php\n\n" "If you then still have questions, join the Galaxy mailing list:\n" " \n" "\n" "Happy Hunting in Galaxy %s!\n\n", gameName); } void standbyMessage(char *gameName) { printf( "\nIt's my sad duty to report that the game %s is already full.\n" "\n\n" "Please note that I am a program, and that my only function is to\n" "register your name. I am not smart enough to answer any\n" "questions that you might have put in your email, so please do\n" "not get angry because they are not answered.\n" "\n" "Have Fun!\n\n", gameName); } /****f* ARE/getstr * * NAME * getstr -- extract a word from a longer string * SYNOPSIS * char *getstr(char *s) * word = getstr(someString) * FUNCTION * Extract a word from a string of words. A word is any things that * is seperated by white spaces or a comma, any string that is * delimited by quotes ("), or or any string delimited by { }. * * The function is intended to parse a string word by word. It * should be first called as: * * firstword = getstr(myStringOfWords); * * This gets the first word from the string pointed to by * myStringOfWords. Then consecutive calls of * * nextword = getstr(NULL); * * you get the remaining words. * * White spaces inside a quote delimited word are turned into * underscores. * * In a string a ';' signifies the start of a comment. Any words * after a ';' are not parsed. * * In the non comment part ';' and '<' are removed before the words * are returned. * * RESULTS * word = a pointer to a nul terminated string. * * Program is aborted if the length of the word is longer than 256, * since then some is most likely trying to crack your system. * * When there are no more words"\0" is returned. * NOTES * This function can only work on one string at the time since it * works with a statically allocated buffer. This function is used * almost every where in the program. * SOURCE */ char * getstr(char *s) { static char *s1; static char buf[256]; int i, j; if (s) s1 = s; /* first invocation of this function, for an order line. Each next times, for the same order line, s1 will "progress" by a word to the right */ assert (s1 != NULL); i = 0; for (; *s1 && isspace(*s1); s1++); /* skips spaces */ if (*s1 eq '"') { /* Players can enclose name (ie : including spaces) with double quotes */ for (s1++; *s1 && *s1 != '"';) { buf[i] = isspace(*s1) ? '_' : *s1; s1++; i++; assert(i < 256); /* abort execution if s1 too long */ } } else if (*s1 eq '{') { for (s1++; *s1 && *s1 != '}';) { buf[i] = *s1; s1++; i++; assert(i < 256); /* abort execution if s1 too long */ } } else { if (*s1 != ';') { /* otherwise, it's a comment */ for (; *s1 && !isspace(*s1) && *s1 != ',';) { /* space or ',' can be used as separators, */ buf[i] = *s1; s1++; i++; assert(i < 256); /* abort execution if s1 too long */ } } } buf[i] = '\0'; if (*s1) s1++; /* Skip ',' or space */ /* CB, 19980922. Remove ";" and "<" from names (planets, ships...), to protect machine report from corruption. Don't break messages and comments. */ i = 0; j = 0; while (buf[j] && j < 256) { if (buf[j] != ';' && buf[j] != '<') { buf[i] = buf[j]; i++; } j++; } if (i) buf[i] = '\0'; return buf; } /***********/ /****f* ARE/getReturnAddress * NAME * getReturnAddress * FUNCTION * Extract the return address from a players email. ****** */ char * getReturnAddress(FILE *orders) { char *isRead; char *c; for (isRead = fgets(lineBuffer, LINE_BUFFER_SIZE, orders); isRead; isRead = fgets(lineBuffer, LINE_BUFFER_SIZE, orders)) { if (noCaseStrncmp("To:", lineBuffer, 3) == 0) break; } assert(isRead != NULL); for (c = lineBuffer; *c; c++) { if (*c == '\n') *c = '\0'; } return strdup(lineBuffer + 3) ; } /****f* ARE/noCaseStrncmp * NAME * noCaseStrncmp -- * SYNOPSIS * int noCaseStrncmp(char *, char *, int) * result = noCaseStrncmp(s, t, n) * FUNCTION * Compare two strings without paying no attention to the case of * the letters, but compare no more than n characters. * RESULT * 0 s == t * -1 s < t * 1 s > t * SOURCE */ int noCaseStrncmp(char *s, char *t, int n) { for (n--; (tolower(*s) == tolower(*t)) && (n > 0); s++, t++, n--) if (*s == '\0') return 0; return (int) (tolower(*s) - tolower(*t)); } /***********/ --- NEW FILE: makefile --- # # $Id: makefile,v 1.1 2008/01/17 23:18:19 gumpu Exp $ # are: are.c gcc -g are.c -o are clean: rm -f are *~ |
From: Frans S. <gu...@us...> - 2008-01-17 23:18:16
|
Update of /cvsroot/galaxyng/NG_Stable In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv9654 Added Files: COPYING COPYING_GD INSTALL UPGRADE history.txt install.sh makefile Log Message: baseline version as used at sifar.xs4all.nl --- NEW FILE: history.txt --- # $Id: history.txt,v 1.1 2008/01/17 23:18:18 gumpu Exp $ Release 6.4.8: January 2005 o By Ken Weinert (madcoder42) + finished work on Pax Galactica, allowing GM to enforce peace at the start of the game for a set number of turns o By Ken Weinert (madcoder42) and Chris Shaffer (christhecat) + added web submission of orders and report requests + added feature to allow GM to specify homeworld coordinates o By Chris Shaffer (christhecat) + modified GalaxyNG home page, which does not list individual games anymore, as it was too difficult to keep up-to-date o By Ken Weinert (madcoder42) and Jeff Frasca (jafrasca) + cleaned up mail headers Release 6.4.7: November 2004 o By Ken Weinert (madcoder42) + enabled compressed reports from a report request (it already worked from normal turns) + added code to include additional parameters to sendmail in order to "shape" the From line in the email so it looks like it comes from the server - this is especially useful for people with hosted sites. + changed a couple of emails so they came from the server instead of the GM + changed message so that race names specified incorrectly can be distinguished from badly formed email (1051567) + fixed bug that player's ships didn't get removed when a player was eliminated by the DropDead process (991269) + fix for bug 1051572 and 1051560 - invalid missing orders report going to GM and due time creeping forward by one interval every turn o By Chris Shaffer (christhecat) + standardized subject lines on email sent by server + updated server and player manuals + revised installation files to make cleaner examples (e.g. procmailrc) + added guides and example reports to web site Release 6.4.6: February 2004 o By Chris Shaffer (christhecat) and Bogdan Mincu (mincub) + major revision of GalaxyNG web site o By Chris Shaffer (christhecat) + updates to manuals, particularly to support changes listed below + updated text in ARE messages to players + modified sample galaxyngrc, procmail, and other files created during installation, particularly to support changes listed below + modified text of the mailing attached to reports and other items sent to players o By Ken Weinert (madcoder42) + added the -due command to email players who haven't yet sent in orders. (#889054) + removed upper casing of game name in report file (#886895) + changed "address" in option names to "anonymous" (#889198) + ensured ships with cargo space and no drive don't get sent on routes (#860007) + changed all occurances of "nation" to "race" to be consistent in all code and documentation. One side effect is that this engine can't be used with existing templates (.glx files) unless you edit it to change "nation_spacing" to "race_spacing" + changed the relay command so it will stop at a #END line added the ability to relay to everyone in the game by using the game name as the destination + added an optional turn number to the score command (#891475) + added a PaxGalactica - GM can specify the number of turns that Races won't be able to declare war on each other + added a new kind of map - "public". it's like location, but without colour coding + fixed bug where extra turn report file was getting created with the wrong name (#892931) + added code to replace the sending player's password with '*' characters in relayed messages. Release 6.4.5: January 2004 o By Ken Weinert (madcoder42) + changed CMD_create to load the config file to fix the problem of not finding fonts during initial map creation in this phase + added the -influence command to generate influence maps without running a turn. + changed the method of allocating memory to reduce the impact of map generation. + fixed an issue with having more players than colors defined. We can now comfortably fit 80 players on these types of maps. More than that and the names will run off the right side. + XML reporting temporarily turned off as the C command would cause TXT reports to be not be created and copies of orders were lost o By Chris Shaffer (christhecat) + Lots of minor updates to the manuals and web site. + Modified files created by install.sh script. Better documentation and examples for procmail and crontab. Release 6.4.4: January 2004 o By Ken Weinert (madcoder42) + added fontpath variable to the rc file to eliminate dependency on the environment variable + restored generating an influence map on turn 0 as the main impediment was the lack of an environment variable Release 6-4-3: January 2004 o By Ken Weinert (madcoder42) + added env variable GNG_LOG_LEVEL to dynamically change the log level - this replaces hard coded loglevels in the code + changed to not output map on turn 0 or game creation o By Chris Shaffer (christhecat) + ARE is documented in the server manual. + ARE makefile updated. NG/makefile now executes ARE makefile. + ARE procmailrc examples integrated into the procmailrc example created by install.sh Release 6-4-2: December 2003 o By Ken Weinert (madcoder42) + Updated version information + Made change to ensure the "to" field in the envelope is always valid + Game creation file now correctly creates all sub- directories. o By Chris Shaffer (christhecat) + Updates to server manual + Bugfixes and updated to galaxyngrc and procmailrc generated by install.sh Release 6-4-1: December 2003 o By Chris Shaffer (christhecat) + Bugfixes. Release 6-4-0: December 2003 o By Chris Shaffer (christhecat) + Rewrote all manuals, FAQs and help documents. Major changes to /NG/Doc/. Removed /WWW/. Sent Tiger score information to Hall of Fame maintainer. + Updated makefile, which no longer creates the Manuals. GMs should point to http://galaxyng.sourceforge.net/ now, rather than hosting the manuals and FAQ and such locally. Release 6-3-0: September 2003 o By Ken Weinert (madcoder42) + both text and xml reports are sent on turn 0 + new option: TXTReport to turn them off if necessary + now forecasts are returned in XML format if that option (XMLReport) has been enabled + further work on influence mapping. Works better, slower than it should be, gradation of influence not working correctly. + XML report has been brought up to current standards - note that this is *not* the interchange level with GalaxyExplorer. That goal was deemed to be proceeding too slowly (by both sides) and so we've temporarily delayed that effort and will compromise on an exchange dtd instead of attempting to have all engines put out the same dtd. Release 6-2: July 2003 o By Ken Weinert (madcoder42) + fixed bug that could cause the create process to hang + added code to ensure each planet is in a unique location this also accounts for the fact that planet coords are only kept to 2 decimal places + recommend that, for the moment, the .png option is not used. I'm rewriting that code and it isn't stable - it might not even compile. Release 6-1a: April 2003 o By Ken Weinert (madcoder42) + Added an option to generate a .png file when the turn is run. This is for GM use only as it shows all planets. It will probably be most useful when first setting up a game so the GM can get a visual indication of how things go together. It could also be useful when showing the history of the game. Release 6-1: July 2002 o By Steve Webb (scum-o) + Added gnuplot output + Added some command-line fixes to commands that weren't very well documented. + Fixed the 'fleet recall' bug. Release 6-0: May 2002 o By FS (gumpu) + Code is GPLed Release 5-1: March 2002 o By FS + the galaxyng executable is stripped before it is installed. + Added gameoptions pactch by CB Release 5-0g: March 2001 o By FS + Fixed a bug in the battle code that caused ships that were destroyed to fire one more shot. + Added a framework for a new version of WOPR based on the galaxyng source code (this is beta code). + Added a source file for globals. + Fixed a bug that caused the engine to complain about the order L 1 COL 1 AMOUT 1.1 on a group with shiptype 1 0 0 0 1 This was again due to a: return expression; which screws up a subsequent compare statment. it was solved by changing it to double res; res = expression; return res; see also the comments at Version 2.1g 6-Oct-1997 + Added house_rules.txt in Doc/ + Fixed a bug in ARE that allowed twice as many players to join a game than was specified. + -players switch also shows which players are inactive. + Using mmencode and zip to send out compressed reports. + updated the server manual. + added support for team games (Tiger) team field in the player structure reportTeam() to generate a report for a team captian. + Fixed a bug that caused the .galaxyngrc file to be ignored when a copy of a report was generated. + added -teaminfo command for team game support. Release 5-0: Aug 2000 o By FS + Changed the battle algorithm. The attacking ships are now selected randomly from all the ships that not fired their guns yet. + -score shows time it was created. + added plot.pl by Steve Webb (st...@ba...) to Tools/ Release 4-4b: Aug 2000 o By FS + The default production of home planet is now DRIVE. Release 4-4a: July 2000 o By FS + Fixed a bug that caused a wrong version of the highscore list to be included in a requested copy of a turn report. Release 4-4: June 2000 o By FS + The -hall command reported dead players, this is fixed. + Fixed spellings mistakes in ARE. + Fixed bug in ARE that let players select planets above the limit set by the GM. + Enables XML reports. Release 4-3a: May 2000 o By FS + Fixed the bug that caused the number of planets, ind, and pop to be zero in the nation station section in turn report 0 + Fixed a bug in the -mail0 command, that created file names that started with /tmp\ + Fixed a bug in the bombPlanet code that cause planets on rare occasions to have a negative industry. Release 4-3: March 2000 o By FS: + Dumbed-down all makefiles to make them work with less featurefull versions of make. + Added a "toall" command that creates a mail header that can be used to mail all players in a game a message. + Used checker to hunt down memory leaks and illegal memory access. (CMD_dump and CMD_run work now without violations). + Added bug fixes to report_xml by Byron Ellacott. + Created a number of function to hide OS dependencies: GOS_fopen(), GOS_mkdir(), GOS_delete(), GOS_copy() + Integrated the patches provided by Martijn van der Kooij to make the code compile under WIN32. Release 4-2patched: December 1999 o Fixed bug in the code that handles turn report copies requests. Release 4-2: December 1999 o By FS: + Fixed the newly introduced technology bug, which cause ships to have higher tech levels than expected. + Updated ARE. Players can now enroll in a game and at the same time specify the sizes of their home planets. + A report request with the subject "report" will retrieve the most recent report. It is no longer necessary specify the turn number. Release 4-1: December 1999 o By FS: + There is a now a check on the length of names. + The L order now recognized the keyword AMOUNT <amount>, which can be used to specify the amount of cargo to be uploaded. + mistake() now works like printf(). + Fixed a production bug. If a planet had slightly too few materials to produce a ship, the ship was still produced, and negative amount of materials showed up. + Split the producephase function in several parts. + Spell-checked install.sh, README. + Added -hall command, for automatic creation of Hall of Fame data. + Added '=' order with which players can set their real name. (Used for the Hall of Fame). + Removed the call to Create_Center_Planet() in createGame(). + Remove hardcoded use of "Game/" in install.sh + Added -template function, which creates a documented template .glx file. + Added key SaveReportCopy to .galaxyngrc file. When used a copy of each turn report is saved in reports/ + Added key starttime to .galaxyngrc file. It defines when a game is supposed to run. It is used for a sanity check to protect against cron errors. Release 4-0: November 1999 o By FS: + Added an UPGRADE file that tell how to upgrade existing games. + Added mail relay function, for in-game anonymous email. + Engine keeps track of how much ship mass is produced and loss and gives a short report about it to the players. + If players do not send in orders for turn 1, they are removed. + Modified run_game, it can now also be used to re-run a turn. + Added a rule to the example .procmailrc to filter the server respone to an email with orders. This prevents an infinite loop, when the GM sends orders from the same account as the server runs on. + Elements on the map are printed in the following order: *, o, +, ., - So if two elements are printed on the same spot the last one in the list is the one that is displayed. + Turn 0 does no longer include the list of addresses of the other players.... as they are all set to anonymous anyhow. + $GALAXYNGHOME or $HOME are used to determine the home directory of all data files. + The email address of the GM and the command used to send the turn reports are read from a configuration file .galaxyngrc Added an example configuration file in GalaxyNG/Doc + The specifications for a new game are now read from a file. After a game is created a map is printed to stdout. Added an example specification file in GalaxyNG/Doc + reports are directly send from the engine... saves another script file. Saves several megabytes of disk space, which used to be needed to store all the reports before they were send. Each game, even after many turns requires only 1 - 2 Mbytes. + galaxyng -check reads the orders directly from stdin. Saves a script file. + Cleaned up ARE. Now used stdin to read the incomming email. Saves having to copy the mail to a file first. + added a struct game, which holds all the defaults for a game. This gets rid of a lot of global variables. Code should be easier to read and maintain now. + Added a runProcmail.sh script for people whos system does not allow direct invocation of procmail on incomming email. + Cleaned-up the source code, added documentation to a number of functions. + Most strings are now dynamically allocated, prevents many buffer overflow errors. + Fixed a syntax error in run_game.sh, this showed up in a debian system. + Added a portable number generator to util.c. The engine should now give the same results on most platforms. + replaces all occurences of rand() % "range" with frand3(range). + The seeds of the random number generator (a table of unsigned integers) are saved to the end of the turn data file. They are read before the start of a turn. This way the random number used during each turn are different, but it is still possible to rerun all turns and get the same outcome at the end. + Added a selftest function. For now this tests the random number generator. But it should develop into a function that does an extensive diagnostic of all functions. + fixed 3 security holes. o By KW: + Added support for xml turn reports. + The order parser now recognizes cases parameters have a negative value and reports this as an error. Release 3-8 o By FS: Fixed the install.sh script. It did not conform to the bash syntax rules. Lots of missing ";" For some odd reason it did run on a slackware system. However it did not run on a Debian system. o Solved a bug in process.c. The send command allowed a negative number of ships to be send to a planet. o removed references to "cequal" from the unpackorders.tcl program so that it can run under plain tcl. o Improved the entry for the V command in the manual Added documentation for the O BattleProtocol and O MachineReport o Added a section on the Battle Protocol. Release 3-7b (April 1999) o By FS: make install now checks if the configuration files it creates already exist. If they do the new files are created under the name <file name>.new. This to ease upgrading existing version of galaxy. o Fixed a bug in the battle code. A shuffle routine to shuffle the players before a battle starts used the lower few bit of the random number generator for the suffle process. This resulted in non-random shuffling. o By CB: Added report version, and galaxy size. Groups record in battle now almost the same that in "normal situations" o When a new game is created, the machine report option is switched on by default. Release 3-7 (April 1999) o By CB: Changes to the machine report. Corrected a bug in number of uninhabited planets Replaced semi-colon delimitor with space (native separator in tcl/tk) Section header : Added a space before the "greater" sign, thus last record is no longer "polluted". Try to get a standard form for header of each section : <section-name(only one word) name(if any) number-of-elements > Try to get a (poor) standard form in groups record : each alien group begin with a 0 (for his number) Section format (groups, battles...) is now : <"section name" "battle or location name" quantity > Messages section is now : <messages "global or personnal" quantity > Release 3-6, o Orders are logged in log/orders_processed.txt Release 3-5, Jan 1999 o It is no longer allowed to upgrade ships at other nations planets. o Log files are now stored, per game, in a directory called log/ (If you don't have this directory create one! or run install.sh) o The checking of orders is not logged any more (procmail keeps a log of when orders came in). o It should now be possible to run more than one game at the same time. So you can start 5 games and let them all run at 23:00 on monday and wed and friday. All temporary files are unique, and should therefore no longer generate conflicts. Release 3-4 o Solved a bug in the battle code. It affected battles with more than 2 parties. The battle algorithm worked as follows: while "there are groups that have not shot" do { select the group that will attack randomly select one of the enemies of the owner of the attacking group randomly select one of the groups of this enemy fire on that group } In this each enemy has an equal change of being chosen. This produces some counter intuitive results. For instance, Players A and B attack player C. Player A sends 100 probes. Player B send a big gun. Then during the battle the big gun has still a 50% chance of being hit. Hence the code that selects the enemy batstat *selectTargetSide(batstat *attSide) now randomly selects an emeny based on the number of ships each enemy has left. So in the above case Player A has a 100 / 101 chance of being selected. Player B has a 1 / 101 chance of being selected. o The G+ reports now correctly show if a group was in or out of battle. o The G+ report fleet sections now correctly shows the number of groups in a fleet. Release 3-3b o The seed of the random number generator is now randomized (using time()). This to avoid that the first battle will follow the same pattern each time. Release 3-3 o Fixed a bug that prevented to break of the last ship of a group. o Added battle protocol. o Added compression support That is the option COMPRESS works now :) o Ran all source code through the indent program, the formatting of all code is now the same and should be more readable. Release-3-2 Nov-1998 o Added a section to the forecast that lists the status of the nation. o Modified the code to produce G+ compatible reports. Players can switch it on with O GPLUS o In orders the planet number can be used to specify a destination i.e S 50 #20 ; planet with '20' as name in turn 0 o Solved a bug that some orders to be missed because the last line of the order "#END" did not contain a '\n' o Included Tommy's circular galaxy construction. o Included Christophe's MachineReport code. o Removed the randomize home planet feature... there is again a relation between the home planet name and nation name. o Changed the removal of dead players rule. If the turn number < 10 and a player has been idle for ORDERGAP1 turns the player is removed. All his planets are reset to 0, and groups are destroyed. If the turn number >= 10, and a player has been idle for ORDERGAP2 turns the player is removed but all the nation's planets and groups will continue to exist. o If no turn number if given for the options -address, -planets, or -password, the current turn is used. o Fixed a bug in the incomming section of the G+ report... planets are listed by their number. *** by CB o added h command to halt a group and let it return to the planet of origin. o added a fleetspeed function in util.c *** by FS o added the -nodrop option. This will turn off the code that removes idle players o added the commands -sidea and -sideb. These list the number of idle turns of the even and uneven numbered players. (For the tiger project). o Fixed a bug in the incomming groups section. o In the groups section (G+) if a ships travels to an unidentified planet the planet is listed as #<number> o In the fleet section (G+) if a fleet travels to an unidentified planet the planet is listed as #<number> o Changes the code for the function isunidentified() Previously all planets that had an owner were listed as unidentified... now planets the player can see or that are owned by the player are excluded. o Added graphscore.tcl -- this creates graphs for all players that can be used for a WWW site. o galaxyng -create, and the install script now create the directory statistics and don't create nreports anymore. o Cargo technology now only needs 2500 industry points to increase by 1 unit. To emphasize the economic aspects of galaxy. o Added a section to the manual on the number of turns a player is allowed to miss and what happens else. Release-3-1 15-April-1998 o Made the output of -score -html option compatible with all browsers. o Fixed a 'move phase' bug. Ships that are within 0.01 ly now are considered to have arrived at the planet. This to avoid funny 'distance left: 0.00' values in the turn report. Release-3-0 13-April-1998 o Put the code under CVS version management. o Added documentation on how to use and configure the program o Added some syntax check to the D (design ship) order. o Randomized the home planet names. There is now no longer a relation between the nation name and home planet numbers. Version 2.1i 13-Dec-1997 o Bug fix in the intercept code. Bug fix thanks to Tommy. Version 2.1h 8-Dec-1997 o Bug fix in the joinphase code, ships that had different flags were still being joined. Bug fix thanks to Tommy. Version 2.1g 6-Oct-1997 (1) Made changes to all code in util.c that has the format double <name>() { return <expression>; } changed it to double <name>() { double res; res = <expression>; return res; } to circumvent some curious intel gcc bug. Version 2.1f 25-July-1997 (1) Changed the log levels, the log file should be much smaller now. (2) Highscore list now includes the address of players that do no play anonymous. Version 2.1e 25-June-1997 Updated the create game code: (1) It now generates a random password for each player. (2) The random number generator is initialized with the return value of time(). (3) Fixed the bug that caused the score list of turn 1 to be listed as that of turn 0. Version 2.1d Inserted a bug fix by Tommy, that prevents players to create feets that have a number as name. --- NEW FILE: UPGRADE --- # $Id: UPGRADE,v 1.1 2008/01/17 23:18:18 gumpu Exp $ How to upgrade your existing games: ==== UPGRADE To release-6.4.8 =============== If you want to allow submission of orders and report requests using web forms, see NG/web/README. There is a new Pax Galactica option for game creation. Details are in the .glx file created using the -template command. Graphical maps are turned on by default now. If you do not want them, edit NG/Source/Makefile. The relevant section is documented near the top of the file. IMPORTANT: The format of the .glx files has changed. You may specify the exact coordinates of each homeworld, if desired. This has caused a change in the .glx file format for players. The ARE has been updated to reflect this change. You should update your ARE and any scripts you use to add players to games. The new format is: start_player email so...@so... homeworld 1000 42 75 end_player ==== UPGRADE To release-6.4.6 =============== If you want the graphical maps, edit NG/Source/makefile cd NG; make; make install This will create the following files in Games/ run_game.new, are.new, galaxyng.new, procmailrc.new, and .galaxyngrc.new Carefully review run_game.new, procmailrc.new and .galaxyngrc.new, all of which have changed significantly. Note that old template files (.glx) will not work with the new galaxyng unless you change "nation" to "race". ==== UPGRADE To release-6.4.2 ================ Compile galaxyng and copy it to your Games/ directory. You may want to review NG/.galaxyngrc and NG/procmailrc which have been updated and are better documented. If you are running a mirror of the GalaxyNG web site, you should copy the contents of NG/Doc to your web site and verify that base_url.txt is still correct. ==== UPGRADE To release-6.4.0 ================ The entire GalaxyNG web site has been rewritten. You have two options: 1) Link to GalaxyNG SourceForge.net site (preferred) Delete most of your local site and point to files on: http://galaxyng.sourceforge.net/ 2) Maintain a mirror of the GalaxyNG SourceForge.net site Delete most of your local site. Copy the files in /Doc/ into your local site. Edit base_url.txt to set the base URL of your site. ==== UPGRADE To release-6.1a ================= Just compile galaxyng and copy it to your Games/ directory. If you don't want the graphical map then this release is not required as there are no other changes. ==== UPGRADE To release-6.1 ================= ==== UPGRADE To release-6.0 ================= ==== UPGRADE To release-5-1 ================= The turn data files are not compatible!! === UPGRADE To release-5-0g ================= The .galaxyngrc file changed, both the command to zip a file as well as to mime encode it has been changed. Best is to do a make install under some other account and copy the .galaxyngrc file that is created during the install. You can also create it by hand, mine looks like this: # cat $HOME/Games/.galaxyngrc sendmail {/usr/sbin/sendmail -t } GMemail gumpu@localhost encode {/usr/bin/mmencode } compress { /usr/bin/zip } savereportcopy ==== UPGRADE To release-5-0 ================= Just compile galaxyng and copy it to your Games/ directory. ==== UPGRADE To release-4-4a ================= Just compile galaxyng and copy it to your Games/ directory. ==== UPGRADE To release-4-4 ================= Just compile galaxyng and copy it to your Games/ directory. ==== UPGRADE To release-4-3a ================= Just compile galaxyng and copy it to your Games/ directory. ==== UPGRADE To release-4-3 ================= Just compile galaxyng and copy it to your Games/ directory. ==== UPGRADE To release-4-2 ================= Just compile galaxyng and copy it to your Games/ directory. ==== UPGRADE To release-4-1 ================= Just compile galaxyng and copy it to your Games/ directory. ==== UPGRADE TO release-4-0 ================= **** FILES THAT ARE OBSOLETE **** The following files can be removed: o Games/mail_report ; The engine directly sends the reports. o Games/check_orders ; Orders are read from stdin. o Games/send_<game name>.sh ; The engine directly sends the reports. **** FILES THAT CHANGED **** You will have to edit the following files, or use the copy created my "make install" o .procmailrc The rule for auto checking of orders changed from :0 rw :turno * ^Subject:.*Order |/usr/bin/formail -rkbt -s /home/galaxy/Games/check_orders to :0 rw :turno * ^Subject:.*Order |/usr/bin/formail -rkbt -s /home/galaxy/Games/galaxyng -check A special line is now needed for "report copy" requests :0 rw :turno * ^Subject:.*Report |/usr/bin/formail -rkbt -s /home/galaxy/Games/galaxyng -check If you want to allow message relaying between players add, :0 rw :turno * ^Subject:.*Relay |/usr/bin/formail -rkbt -s /home/galaxy/Games/galaxyng -relay Best is to copy these lines from the procmailrci.new file generated by "make install", you might also want to add the additonal rules to prevent mail loops. You probably also want to update your global.bulletin, and example can be found in the Doc/ directory. o Games/run_game Now takes an optional additional parameter to specify what turn is to be run. You can copy the run_game.new file generated by "make install" over your old run_game file. ***** NEW FILES ******** o Games/.galaxyngrc This file is essential, games will not run without it. It should contains atleast the following two parameters: sendmail {/usr/sbin/sendmail -t } ; the correct path to sendmail GMemail you@youraddress ; your email address If you allow compressed reports add: mutt /usr/local/bin/mutt ; this is optional encode {/usr/bin/uuencode test } compress { /bin/gzip -c } "make install" will create a one for you. Please also read the server manual. --- NEW FILE: COPYING --- GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the program's name and a brief idea of what it does.> Copyright (C) 19yy <name of author> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. <signature of Ty Coon>, 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. --- NEW FILE: COPYING_GD --- Portions copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 by Cold Spring Harbor Laboratory. Funded under Grant P41-RR02188 by the National Institutes of Health. Portions copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 by Boutell.Com, Inc. Portions relating to GD2 format copyright 1999, 2000, 2001, 2002 Philip Warner. Portions relating to PNG copyright 1999, 2000, 2001, 2002 Greg Roelofs. Portions relating to gdttf.c copyright 1999, 2000, 2001, 2002 John Ellson (el...@lu...). Portions relating to gdft.c copyright 2001, 2002 John Ellson (el...@lu...). Portions relating to JPEG and to color quantization copyright 2000, 2001, 2002, Doug Becker and copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, Thomas G. Lane. This software is based in part on the work of the Independent JPEG Group. See the file README-JPEG.TXT for more information. Portions relating to WBMP copyright 2000, 2001, 2002 Maurice Szmurlo and Johan Van den Brande. Permission has been granted to copy, distribute and modify gd in any context without fee, including a commercial application, provided that this notice is present in user-accessible supporting documentation. This does not affect your ownership of the derived work itself, and the intent is to assure proper credit for the authors of gd, not to interfere with your productive use of gd. If you have questions, ask. "Derived works" includes all programs that utilize the library. Credit must be given in user-accessible documentation. This software is provided "AS IS." The copyright holders disclaim all warranties, either express or implied, including but not limited to implied warranties of merchantability and fitness for a particular purpose, with respect to this code and accompanying documentation. Although their code does not appear in gd, the authors wish to thank David Koblas, David Rowley, and Hutchison Avenue Software Corporation for their prior contributions. --- NEW FILE: makefile --- # # $Id: makefile,v 1.1 2008/01/17 23:18:19 gumpu Exp $ # all : make -C lib make -C Source galaxyng make -C Util make -C ARE install: Source/galaxyng ./install.sh clean: make -C lib clean make -C Source clean make -C Util clean make -C ARE clean rm -f *~ *.bak depend: make -C lib depend make -C Source depend make -C Util depend make -C ARE depend --- NEW FILE: install.sh --- #!/bin/bash # $Id: install.sh,v 1.1 2008/01/17 23:18:18 gumpu Exp $ #=================================================== # If you want to install the server in a directory other than # $HOME/Games, change the following line, and add the line # export GALAXYNGHOME=<the dir you install it in> # to your .bash_profile file. #=================================================== GALAXY_HOME=$HOME/Games echo "*** GalaxyNG Install Script ***" echo "This script creates and installs all files necessary to" echo "run Galaxy Games. Files will be installed in" echo "$GALAXY_HOME" echo #=================================================== # Create directories, if necessary. #=================================================== if [ ! -d $GALAXY_HOME ]; then echo "Creating $GALAXY_HOME" mkdir -p $GALAXY_HOME fi for NAME in log orders notices data reports statistics forecasts ; do if [ ! -d $GALAXY_HOME/$NAME ]; then mkdir $GALAXY_HOME/$NAME fi done #=================================================== # Determine GM and server email addresses and password. #=================================================== echo "o What is the GM email address?" echo " (Email to the GM is sent to this address)" read GMEMAIL echo "o What is the GM name?" echo " (This is used on outgoing mail)" read GMNAME echo "o What is the server email address?" echo " (galaxyng commands are sent to this address)" read SERVEREMAIL echo "o What is the server name?" echo " (This is used on outgoing mail)" read SERVERNAME echo "o What is the GM password?" echo " (used for relay commands)" echo " DO NOT USE THE GM ACCOUNT PASSWORD. THIS PASSWORD" echo " IS NOT SECURE!" read PASSWORD #==================================================== # Try to find the sendmail command. #==================================================== echo "o Trying to locate the sendmail command..." # Check the usual locations, "which" does not work usually. for NAME in /bin /sbin /usr/sbin /usr/bin ; do echo " Checking: $NAME" if [ -x $NAME/sendmail ]; then SENDMAIL=$NAME/sendmail break fi done # If it was not found, ask the user where it is if [ -z "$SENDMAIL" ]; then echo " I can't seem to find the sendmail command." echo " Please enter the full path for sendmail:" read SENDMAIL fi echo " The full path for sendmail is:" echo " $SENDMAIL" # ========================================================= # Try to find the formail command # ========================================================= echo "o Trying to locate the formail command." # Check the usual locations for NAME in /bin /sbin /usr/sbin /usr/bin ; do echo " Checking: $NAME" if [ -x $NAME/formail ]; then FORMAIL=$NAME/formail break fi done # If it was not found, try which if [ -z "$FORMAIL" ]; then FORMAIL=`which formail` fi # If it was not found, ask the user if [ -z "$FORMAIL" ]; then echo " I can't seem to find the formail command." echo " This may mean you don't have procmail installed." echo " Please enter the full path to formail:" read FORMAIL fi echo " The full path for formail is:" echo " $FORMAIL" # ========================================================= # Find the compression utility # ========================================================= echo "o Trying to find the compression utility." COMPRESS=`which zip` if [ -z "$COMPRESS" ]; then echo " I can't seem to find the compression utility." echo " Please enter the full path for the compression utility:" read COMPRESS fi echo " The full path for the compression utility is:" echo " $COMPRESS" # ========================================================= # Find the mime encoder # ========================================================= echo "o Trying to find the mime encoder." for NAME in mmencode mimencode; do echo " Checking: $NAME" ENCODE=`which $NAME` if [ -n "$ENCODE" ]; then break; fi done if [ -z "$ENCODE" ]; then echo " I can't seem to find the mime encoder." echo " Please enter the full path for the mime encoder:" read ENCODE fi echo " The full path for the mime encoder is:" echo " $ENCODE" # =========================================================== # Try to find the location of the public web directory. # =========================================================== echo "o Trying to locate the web directory. GalaxyNG uses this" echo " directory to store the high score lists." for NAME in $HOME/public_html $HOME/web $HOME/www $HOME/WWW; do echo " Checking: $NAME" if [ -d $NAME ]; then WWW=$NAME break fi done if [ -z "$WWW" ]; then echo " I can't seem to find the your web directory," echo " Please enter the full path to your web directory:" read WWW if [ ! -d $WWW ]; then mkdir $WWW fi fi echo " The web directory is:" echo " $WWW" # ========================================================= # Check for a /tmp directory # ========================================================= echo "o Trying to locate a tmp directory." if [ -d /tmp ]; then TEMP=/tmp else TEMP=$GALAXY_HOME/tmp mkdir $GALAXY_HOME/tmp fi echo " The tmp directory is: $TEMP" # ========================================================= # Fonts for influence mapping # ========================================================= if [ -f Source/angostur.ttf ]; then cp Source/angostur.ttf $GALAXY_HOME/influence.ttf else cp Source/cranberr.ttf $GALAXY_HOME/influence.ttf fi # ======================================================== # Create run_game # ======================================================== RUN_GAME=$GALAXY_HOME/run_game echo "o Creating $RUN_GAME" #echo " The run_game script is used to run a turn." if [ -e $RUN_GAME ]; then echo " Found an existing version of $RUN_GAME" RUN_GAME=$GALAXY_HOME/run_game.new echo " Writing the new version to $RUN_GAME" fi echo "#!/bin/bash" > $RUN_GAME cat Util/run_game.header >> $RUN_GAME echo "BASE=$GALAXY_HOME" >> $RUN_GAME echo "WWWHOME=$WWW" >> $RUN_GAME echo "GALAXYNGHOME=$GALAXY_HOME" >> $RUN_GAME echo "declare -x GDFONTPATH=$GALAXY_HOME" >> $RUN_GAME cat Util/run_game.tail >> $RUN_GAME chmod +x $RUN_GAME # ========================================================= # Create example .procmailrc file # ========================================================= PROCRC=$GALAXY_HOME/procmailrc echo "o Creating $PROCRC" echo " You can use this file in combination with procmail" echo " to automatically check incoming orders." echo " To use it copy it to $HOME as $HOME/.procmailrc" echo " Note that is $HOME/[dot]procmailrc" if [ -e $PROCRC ]; then echo " Found an existing version of $PROCRC" PROCRC=$GALAXY_HOME/procmailrc.new echo " Writing the new version to $PROCRC" fi echo "PATH=\$HOME/bin:$GALAXY_HOME:/usr/bin:/bin:/usr/local/bin:." > $PROCRC echo "#" >> $PROCRC echo "# Make sure that your mail directory exists!" >> $PROCRC echo "MAILDIR=\$HOME/Mail" >> $PROCRC echo >> $PROCRC echo "DEFAULT=\$MAILDIR/mbox" >> $PROCRC echo "# For maildir delivery, mailboxes end in a /, so comment" >> $PROCRC echo "# out the above line and use this instead:" >> $PROCRC echo "# DEFAULT=\$MAILDIR/" >> $PROCRC echo >> $PROCRC echo "LOGFILE=\$HOME/procmail.log" >> $PROCRC echo "LOCKFILE=\$HOME/.lockmail" >> $PROCRC echo "LOGABSTRACT=all" >> $PROCRC echo "GALAXYNGHOME="$GALAXY_HOME >> $PROCRC echo >> $PROCRC echo "# Store GM reports in a folder called gmreport." >> $PROCRC echo ":0:" >> $PROCRC echo "* ^Subject:.*GM Report" >> $PROCRC echo "gmreport" >> $PROCRC echo "# Some IMAP servers prefix mailbox names with a dot." >> $PROCRC echo "# For example:" >> $PROCRC echo "# .gmreport" >> $PROCRC echo "# Combining this with maildir delivery would yield:" >> $PROCRC echo "# .gmreport/" >> $PROCRC echo "# Make sure to change the folders listed below to match" >> $PROCRC echo "# your configuration." >> $PROCRC echo >> $PROCRC echo "# Store orders due messages in a folder called due." >> $PROCRC echo ":0:" >> $PROCRC echo "* ^Subject:.*is about to run." >> $PROCRC echo "due" >> $PROCRC echo >> $PROCRC echo "# Don't reply to anything from a mail daemon, but store it" >> $PROCRC echo "# in a folder called postmaster." >> $PROCRC echo ":0:" >> $PROCRC echo "* ^FROM_MAILER" >> $PROCRC echo "postmaster" >> $PROCRC echo >> $PROCRC echo "# The following prevents mail loops. These happen when the" >> $PROCRC echo "# server starts replying to its own messages or messages" >> $PROCRC echo "# from another server. Mail loops usually annoy the heck" >> $PROCRC echo "# out of sysadmins." >> $PROCRC echo ":0:" >> $PROCRC echo "* ^Subject:.*(major trouble|message sent|message not sent|received for|report for|forecast for|report copy)" >> $PROCRC echo "loops" >> $PROCRC echo >> $PROCRC echo "# Received a message with the word order in the subject:" >> $PROCRC echo ":0" >> $PROCRC echo "* ^Subject:.*order" >> $PROCRC echo "{" >> $PROCRC echo " :0crw:order" >> $PROCRC echo " # Check the orders and send a forecast or an error message:" >> $PROCRC echo " |$FORMAIL -rkbt -s $GALAXY_HOME/galaxyng -check" >> $PROCRC echo " :0:orders" >> $PROCRC echo " # Save a copy of the orders message" >> $PROCRC echo " orders" >> $PROCRC echo "}" >> $PROCRC echo >> $PROCRC echo "# Received a message with the word report in the subject:" >> $PROCRC echo ":0" >> $PROCRC echo "* ^Subje... [truncated message content] |
From: Frans S. <gu...@us...> - 2008-01-17 23:12:53
|
Update of /cvsroot/galaxyng/NG_Stable/Util In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv7171/Util Log Message: Directory /cvsroot/galaxyng/NG_Stable/Util added to the repository |
From: Frans S. <gu...@us...> - 2008-01-17 23:12:37
|
Update of /cvsroot/galaxyng/NG_Stable/Source In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv7156/Source Log Message: Directory /cvsroot/galaxyng/NG_Stable/Source added to the repository |
From: Frans S. <gu...@us...> - 2008-01-17 23:12:25
|
Update of /cvsroot/galaxyng/NG_Stable/lib In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv7138/lib Log Message: Directory /cvsroot/galaxyng/NG_Stable/lib added to the repository |
From: Frans S. <gu...@us...> - 2008-01-17 23:12:15
|
Update of /cvsroot/galaxyng/NG_Stable/include In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv7083/include Log Message: Directory /cvsroot/galaxyng/NG_Stable/include added to the repository |
From: Frans S. <gu...@us...> - 2008-01-17 23:11:57
|
Update of /cvsroot/galaxyng/NG_Stable/ARE In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv6739/ARE Log Message: Directory /cvsroot/galaxyng/NG_Stable/ARE added to the repository |
From: Frans S. <gu...@us...> - 2008-01-17 23:11:48
|
Update of /cvsroot/galaxyng/NG_Stable/Doc In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv6720/Doc Log Message: Directory /cvsroot/galaxyng/NG_Stable/Doc added to the repository |
From: Frans S. <gu...@us...> - 2008-01-17 23:07:41
|
Update of /cvsroot/galaxyng/NG_Stable In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv5016/NG_Stable Log Message: Directory /cvsroot/galaxyng/NG_Stable added to the repository |
From: Frans S. <gu...@us...> - 2007-11-11 11:57:20
|
Update of /cvsroot/galaxyng/NG/include In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv11357/include Modified Files: Tag: Refactor_Baseline mail.h Log Message: baseline Index: mail.h =================================================================== RCS file: /cvsroot/galaxyng/NG/include/mail.h,v retrieving revision 1.11.2.1 retrieving revision 1.11.2.2 diff -C2 -d -r1.11.2.1 -r1.11.2.2 *** mail.h 22 Jun 2007 22:26:51 -0000 1.11.2.1 --- mail.h 11 Nov 2007 11:57:14 -0000 1.11.2.2 *************** *** 5,14 **** #include "util.h" - #ifdef WIN32 - #include <stdio.h> - #include <stdarg.h> - #include <TCHAR.H> - #endif - /****s* Mail/envelope * NAME --- 5,8 ---- |
From: Frans S. <gu...@us...> - 2007-11-11 11:56:54
|
Update of /cvsroot/galaxyng/NG/Source In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv10967 Modified Files: Tag: Refactor_Baseline cmd_report.c cmd_run.c process.c usage.c Log Message: baseline Index: cmd_report.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/cmd_report.c,v retrieving revision 1.21.2.3 retrieving revision 1.21.2.4 diff -C2 -d -r1.21.2.3 -r1.21.2.4 *** cmd_report.c 4 Jul 2007 23:12:42 -0000 1.21.2.3 --- cmd_report.c 11 Nov 2007 11:56:40 -0000 1.21.2.4 *************** *** 5,10 **** * CMD_report -- create a copy of a turn report. * SYNOPSIS * ./galaxyng -report <gamename> <player> <turnnumber> - * int CMD_report(int argc, char **argv) * FUNCTION * Recreate a turn report of a given turn. --- 5,13 ---- * CMD_report -- create a copy of a turn report. * SYNOPSIS + */ + int CMD_report(int argc, char **argv) + /* + * USAGE * ./galaxyng -report <gamename> <player> <turnnumber> * FUNCTION * Recreate a turn report of a given turn. *************** *** 15,20 **** */ - int - CMD_report( int argc, char **argv ) { char *logName = --- 18,21 ---- Index: process.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/process.c,v retrieving revision 1.68.2.3 retrieving revision 1.68.2.4 diff -C2 -d -r1.68.2.3 -r1.68.2.4 *** process.c 4 Jul 2007 23:12:42 -0000 1.68.2.3 --- process.c 11 Nov 2007 11:56:41 -0000 1.68.2.4 *************** *** 1909,1912 **** --- 1909,1913 ---- FILE *ordersFile; + #if 0 char *rm_notify; *************** *** 1916,1919 **** --- 1917,1921 ---- ssystem( rm_notify ); free( rm_notify ); + #endif plog( LPART, "Reading orders from file %s\n", ordersFileName ); Index: cmd_run.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/cmd_run.c,v retrieving revision 1.5.2.3 retrieving revision 1.5.2.4 diff -C2 -d -r1.5.2.3 -r1.5.2.4 *** cmd_run.c 4 Jul 2007 23:12:42 -0000 1.5.2.3 --- cmd_run.c 11 Nov 2007 11:56:40 -0000 1.5.2.4 *************** *** 5,9 **** * CMD_run -- run turn and send turn reports * SYNOPSIS ! * ./galaxyng -run <game name> <file with all orders> * FUNCTION * Run an turn, Compute the highscore list, and send the turn reports --- 5,14 ---- * CMD_run -- run turn and send turn reports * SYNOPSIS ! */ ! int ! CMD_run( int argc, char **argv ) ! /* ! * USAGE ! * ./galaxyng -run <game name> <file with all orders> [turn] * FUNCTION * Run an turn, Compute the highscore list, and send the turn reports *************** *** 30,35 **** */ - int - CMD_run( int argc, char **argv ) { int result; --- 35,38 ---- Index: usage.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/usage.c,v retrieving revision 1.10.2.1 retrieving revision 1.10.2.2 diff -C2 -d -r1.10.2.1 -r1.10.2.2 *** usage.c 21 Jun 2007 23:02:03 -0000 1.10.2.1 --- usage.c 11 Nov 2007 11:56:41 -0000 1.10.2.2 *************** *** 13,22 **** printf( "Usage: galaxyng <command> <parameters> <options>\n" "\nCommands Available:\n" ! " General Commands\n" ! " -template <game name> <number of players>\n" ! " -create <specifcation file>\n" ! " -mail0 <game name>\n" ! " -check\n" ! " -run <game name> <file with all orders> [turn]\n" " -score <game name> [turn]\n" " -toall <game name>\n" --- 13,36 ---- printf( "Usage: galaxyng <command> <parameters> <options>\n" "\nCommands Available:\n" ! " -template <game name> <number of players>\n" ! " -create <specifcation file>\n" ! " -mail0 <game name>\n" ! " -check <game name> <race name>\n" ! " -run <game name> <file with all orders> [turn]\n" ! " -report <game name> <race name> <turnnumber>\n" ! " -players <game name>\n" ! ); ! printf( "\nExplanation:\n" ! " -template - create a template .glx file for use with -create.\n" ! " -create - create a new game.\n" ! " -mail0 - store the turn-0-reports in reports/<game name>.\n" ! " -check - check incoming orders, orders are read from stdin.\n" ); ! printf( " -run - run a game and store the turn-reports to reports/<game name>.\n" ! " -score - creates highscore list in HTML format.\n" ! " -players - list address and password of all players.\n" ! " -report - creates a particular turn-report which is written to stdout.\n" ); ! ! /* TODO Re-enable once done */ ! #if 0 " -score <game name> [turn]\n" " -toall <game name>\n" *************** *** 75,77 **** --- 89,93 ---- " b) the GM specified amount of time has expired\n" " -players - list address and password of all players.\n" ); + #endif + } |
From: Frans S. <gu...@us...> - 2007-07-05 20:42:53
|
Update of /cvsroot/galaxyng/NG/Source In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv9574 Modified Files: Tag: Refactor_Baseline Makefile Log Message: Added tags target Index: Makefile =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/Makefile,v retrieving revision 1.8.2.4 retrieving revision 1.8.2.5 diff -C2 -d -r1.8.2.4 -r1.8.2.5 *** Makefile 4 Jul 2007 23:12:42 -0000 1.8.2.4 --- Makefile 5 Jul 2007 20:42:51 -0000 1.8.2.5 *************** *** 185,188 **** --- 185,191 ---- #========================================================= + tags: + ctags -R . + test: galaxyng cp galaxyng $(HOME)/Games/galaxyng |
From: Frans S. <gu...@us...> - 2007-07-04 23:13:15
|
Update of /cvsroot/galaxyng/NG/lib In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv22917 Modified Files: Tag: Refactor_Baseline Makefile mail.c Removed Files: Tag: Refactor_Baseline libgd.a Log Message: Added crosscompile linux -> win32 --- libgd.a DELETED --- Index: Makefile =================================================================== RCS file: /cvsroot/galaxyng/NG/lib/Makefile,v retrieving revision 1.9.2.1 retrieving revision 1.9.2.2 diff -C2 -d -r1.9.2.1 -r1.9.2.2 *** Makefile 23 Jun 2007 21:05:58 -0000 1.9.2.1 --- Makefile 4 Jul 2007 23:13:12 -0000 1.9.2.2 *************** *** 11,15 **** --- 11,20 ---- CFLAGS = -Wall -pedantic -I../include $(ADDTL_CFLAGS) + # For a cross compile. + MINGW_CC=/usr/local/bin/i386-mingw32-gcc + MINGW_AR=/usr/local/bin/i386-mingw32-ar + CC = gcc + AR = ar SOURCES=strutl.c logging.c list.c globals.c mail.c util.c loadNGConfig.c \ *************** *** 21,29 **** libgalaxyng.a: $(OBJECTS) ! ar cr libgalaxyng.a $(OBJECTS) clean: rm -f libgalaxyng.a $(OBJECTS) *~ $(DEPENDENCIES) # Make a copy of the master configuration # file. --- 26,37 ---- libgalaxyng.a: $(OBJECTS) ! $(AR) cr libgalaxyng.a $(OBJECTS) clean: rm -f libgalaxyng.a $(OBJECTS) *~ $(DEPENDENCIES) + xcompile: + $(MAKE) -f Makefile CC=$(MINGW_CC) AR=$(MINGW_AR) libgalaxyng.a + # Make a copy of the master configuration # file. Index: mail.c =================================================================== RCS file: /cvsroot/galaxyng/NG/lib/mail.c,v retrieving revision 1.18.2.1 retrieving revision 1.18.2.2 diff -C2 -d -r1.18.2.1 -r1.18.2.2 *** mail.c 22 Jun 2007 22:28:38 -0000 1.18.2.1 --- mail.c 4 Jul 2007 23:13:13 -0000 1.18.2.2 *************** *** 138,141 **** --- 138,142 ---- setHeader( envelope *e, int headerType, char *format, ... ) { + #if 0 int n; *************** *** 211,214 **** --- 212,216 ---- assert( 0 ); } + #endif } *************** *** 272,278 **** eMail( game *aGame, envelope *e, char *fileName ) { FILE *mailFile; char template[128]; ! int result; char command[4096]; --- 274,282 ---- eMail( game *aGame, envelope *e, char *fileName ) { + int result = 0; + #if 0 FILE *mailFile; char template[128]; ! char command[4096]; *************** *** 373,376 **** --- 377,381 ---- result |= ssystem( "rm %s", template ); #endif + #endif return result; } |
From: Frans S. <gu...@us...> - 2007-07-04 23:12:43
|
Update of /cvsroot/galaxyng/NG/Source In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv22540 Modified Files: Tag: Refactor_Baseline Makefile cmd_check.c cmd_report.c cmd_run.c create.c galaxyng.c loadgame.c process.c report.c Removed Files: Tag: Refactor_Baseline makefile.win32 Log Message: Add Crosscompile linux to win32 Index: process.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/process.c,v retrieving revision 1.68.2.2 retrieving revision 1.68.2.3 diff -C2 -d -r1.68.2.2 -r1.68.2.3 *** process.c 22 Jun 2007 22:25:29 -0000 1.68.2.2 --- process.c 4 Jul 2007 23:12:42 -0000 1.68.2.3 *************** *** 134,143 **** } - #ifdef WIN32 - vsprintf( lineBuffer, format, ap ); - #else n = vsnprintf( lineBuffer, LINE_BUFFER_SIZE, lformat, ap ); assert( n != -1 ); - #endif free( lformat ); --- 134,139 ---- *************** *** 2404,2407 **** /**********/ - - --- 2400,2401 ---- --- makefile.win32 DELETED --- Index: cmd_run.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/cmd_run.c,v retrieving revision 1.5.2.2 retrieving revision 1.5.2.3 diff -C2 -d -r1.5.2.2 -r1.5.2.3 *** cmd_run.c 22 Jun 2007 22:25:28 -0000 1.5.2.2 --- cmd_run.c 4 Jul 2007 23:12:42 -0000 1.5.2.3 *************** *** 72,77 **** } if ( aPlayer->flags & F_MACHINEREPORT ) { ! saveTurnReport( aGame, aPlayer, ! F_MACHINEREPORT ); } } --- 72,76 ---- } if ( aPlayer->flags & F_MACHINEREPORT ) { ! saveTurnReport( aGame, aPlayer, F_MACHINEREPORT ); } } Index: Makefile =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/Makefile,v retrieving revision 1.8.2.3 retrieving revision 1.8.2.4 diff -C2 -d -r1.8.2.3 -r1.8.2.4 *** Makefile 23 Jun 2007 20:55:52 -0000 1.8.2.3 --- Makefile 4 Jul 2007 23:12:42 -0000 1.8.2.4 *************** *** 45,48 **** --- 45,51 ---- LIBS = -L../lib -lgalaxyng -lm $(ADDTL_LIBS) + # For a cross compile. + MINGW_CC=/usr/local/bin/i386-mingw32-gcc + # Everybody has gcc CC=gcc *************** *** 153,157 **** $(GALAXYNG): $(GNG_OBJS) ../lib/libgalaxyng.a ! $(CC) $(GNG_OBJS) -o $(GALAXYNG) $(LIBS) $(WOPR): $(WOPR_OBJS) --- 156,160 ---- $(GALAXYNG): $(GNG_OBJS) ../lib/libgalaxyng.a ! $(CC) $(GNG_OBJS) -o $(GALAXYNG)$(EXE) $(LIBS) $(WOPR): $(WOPR_OBJS) *************** *** 171,174 **** --- 174,184 ---- rm -f masterindex.html + + # Cross compile for windows. + # + xcompile: + $(MAKE) -f Makefile CC=$(MINGW_CC) EXE=.exe galaxyng + + #========================================================= # For development Index: cmd_report.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/cmd_report.c,v retrieving revision 1.21.2.2 retrieving revision 1.21.2.3 diff -C2 -d -r1.21.2.2 -r1.21.2.3 *** cmd_report.c 22 Jun 2007 22:25:28 -0000 1.21.2.2 --- cmd_report.c 4 Jul 2007 23:12:42 -0000 1.21.2.3 *************** *** 18,22 **** CMD_report( int argc, char **argv ) { ! char *logName = createString( "%s/log/orders_processed.txt", galaxynghome ); openLog( logName, "a" ); --- 18,23 ---- CMD_report( int argc, char **argv ) { ! char *logName = ! createString( "%s/log/orders_processed.txt", galaxynghome ); openLog( logName, "a" ); *************** *** 29,36 **** return EXIT_FAILURE; } else { ! game* aGame = NULL; ! char *gameName = argv[ 2 ]; ! char *raceName = argv[ 3 ]; ! int theTurnNumber = atoi( argv[ 4 ] ); if ( ( aGame = loadgame( gameName, LG_CURRENT_TURN ) ) == NULL ) { --- 30,37 ---- return EXIT_FAILURE; } else { ! game *aGame = NULL; ! char *gameName = argv[2]; ! char *raceName = argv[3]; ! int theTurnNumber = atoi( argv[4] ); if ( ( aGame = loadgame( gameName, LG_CURRENT_TURN ) ) == NULL ) { *************** *** 38,43 **** return EXIT_FAILURE; } else { ! player* aPlayer = findElement( player, ( aGame )->players, raceName ); ! if ( aPlayer == NULL ) { /* Can't find player */ return EXIT_FAILURE; --- 39,45 ---- return EXIT_FAILURE; } else { ! player *aPlayer = ! findElement( player, ( aGame )->players, raceName ); ! if ( aPlayer == NULL ) { /* Can't find player */ return EXIT_FAILURE; *************** *** 61,71 **** loadNGConfig( aGame2 ); ! if ( theTurnNumber > 0 ) { /* Rerun the turn */ char *ordersName; ordersName = createString( "%s/orders/%s/%d.all", ! galaxynghome, aGame2->name, ! theTurnNumber ); runTurn( aGame2, ordersName ); free( ordersName ); --- 63,73 ---- loadNGConfig( aGame2 ); ! if ( theTurnNumber > 0 ) { /* Rerun the turn */ char *ordersName; ordersName = createString( "%s/orders/%s/%d.all", ! galaxynghome, aGame2->name, ! theTurnNumber ); runTurn( aGame2, ordersName ); free( ordersName ); *************** *** 73,77 **** /* Translate the current race name into the name used during the turn that is requested ! */ aPlayer = findElement( player, aGame->players, raceName ); --- 75,79 ---- /* Translate the current race name into the name used during the turn that is requested ! */ aPlayer = findElement( player, aGame->players, raceName ); *************** *** 94,97 **** return EXIT_SUCCESS; } - - --- 96,97 ---- Index: loadgame.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/loadgame.c,v retrieving revision 1.27.2.1 retrieving revision 1.27.2.2 diff -C2 -d -r1.27.2.1 -r1.27.2.2 *** loadgame.c 21 Jun 2007 23:02:02 -0000 1.27.2.1 --- loadgame.c 4 Jul 2007 23:12:42 -0000 1.27.2.2 *************** *** 4,8 **** #include <string.h> ! char *vloadgame = "$Id$"; /****h* GalaxyNG/LoadGame --- 4,9 ---- #include <string.h> ! char *vloadgame = ! "$Id$"; /****h* GalaxyNG/LoadGame *************** *** 486,491 **** aGroup->dist = getReadFloat( ); aGroup->ships = getReadInt( ); ! aGroup->thefleet = ! ( fleetname * ) getReadPointer( ( list * ) ( P->fleetnames ) ); addList( &P->groups, aGroup ); --- 487,491 ---- aGroup->dist = getReadFloat( ); aGroup->ships = getReadInt( ); ! aGroup->thefleet = ( fleetname * ) getReadPointer( ( list * ) ( P->fleetnames ) ); addList( &P->groups, aGroup ); Index: cmd_check.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/cmd_check.c,v retrieving revision 1.13.2.2 retrieving revision 1.13.2.3 diff -C2 -d -r1.13.2.2 -r1.13.2.3 *** cmd_check.c 22 Jun 2007 22:25:28 -0000 1.13.2.2 --- cmd_check.c 4 Jul 2007 23:12:42 -0000 1.13.2.3 *************** *** 32,38 **** return EXIT_FAILURE; } else { ! game* aGame = NULL; ! char *gameName = argv[ 2 ]; ! char *raceName = argv[ 3 ]; if ( ( aGame = loadgame( gameName, LG_CURRENT_TURN ) ) == NULL ) { --- 32,38 ---- return EXIT_FAILURE; } else { ! game *aGame = NULL; ! char *gameName = argv[2]; ! char *raceName = argv[3]; if ( ( aGame = loadgame( gameName, LG_CURRENT_TURN ) ) == NULL ) { *************** *** 40,45 **** return EXIT_FAILURE; } else { ! player* aPlayer = findElement( player, ( aGame )->players, raceName ); ! if ( aPlayer == NULL ) { /* Can't find player */ return EXIT_FAILURE; --- 40,46 ---- return EXIT_FAILURE; } else { ! player *aPlayer = ! findElement( player, ( aGame )->players, raceName ); ! if ( aPlayer == NULL ) { /* Can't find player */ return EXIT_FAILURE; *************** *** 63,65 **** return EXIT_SUCCESS; } - --- 64,65 ---- Index: create.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/create.c,v retrieving revision 1.17.2.1 retrieving revision 1.17.2.2 diff -C2 -d -r1.17.2.1 -r1.17.2.2 *** create.c 21 Jun 2007 23:02:02 -0000 1.17.2.1 --- create.c 4 Jul 2007 23:12:42 -0000 1.17.2.2 *************** *** 1246,1253 **** double alpha, beta, radius; - #ifdef WIN32 - float M_PI = 3.14159265358979; - #endif - found_location = TRUE; if ( num_players < 3 ) --- 1246,1249 ---- *************** *** 1589,1596 **** double result; - #ifdef WIN32 - float M_PI = 3.14159265358979; - - #endif result = dist / sin( M_PI / num ); --- 1585,1588 ---- Index: report.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/report.c,v retrieving revision 1.25.2.2 retrieving revision 1.25.2.3 diff -C2 -d -r1.25.2.2 -r1.25.2.3 *** report.c 22 Jun 2007 22:25:29 -0000 1.25.2.2 --- report.c 4 Jul 2007 23:12:43 -0000 1.25.2.3 *************** *** 125,129 **** * SYNOPSIS */ ! void saveGMReport( game *aGame, char *gameName ) /* * FUNCTION --- 125,130 ---- * SYNOPSIS */ ! void ! saveGMReport( game *aGame, char *gameName ) /* * FUNCTION *************** *** 132,136 **** ****** */ - { char *fileName; --- 133,136 ---- *************** *** 138,143 **** fileName = createString( "%s/reports/%s/%s_%d.txt", ! galaxynghome, aGame->name, "NG_GameMaster", ! aGame->turn ); if ( !( gmreport = GOS_fopen( fileName, "w" ) ) ) { fprintf( stderr, "Can't open %s\n", fileName ); --- 138,143 ---- fileName = createString( "%s/reports/%s/%s_%d.txt", ! galaxynghome, aGame->name, "NG_GameMaster", ! aGame->turn ); if ( !( gmreport = GOS_fopen( fileName, "w" ) ) ) { fprintf( stderr, "Can't open %s\n", fileName ); *************** *** 154,158 **** * SYNOPSIS */ ! void createGMReport( game *aGame, char *gameName, FILE* gmreport ) /* * FUNCTION --- 154,159 ---- * SYNOPSIS */ ! void ! createGMReport( game *aGame, char *gameName, FILE *gmreport ) /* * FUNCTION *************** *** 277,288 **** switch ( kind ) { ! case F_XMLREPORT: ! report_xml( aGame, aPlayer, reportfile, Report ); ! break; ! case F_MACHINEREPORT: ! report_m( aPlayer, aGame, reportfile ); ! break; ! default: ! report( aGame, aPlayer, reportfile ); } } --- 278,289 ---- switch ( kind ) { ! case F_XMLREPORT: ! report_xml( aGame, aPlayer, reportfile, Report ); ! break; ! case F_MACHINEREPORT: ! report_m( aPlayer, aGame, reportfile ); ! break; ! default: ! report( aGame, aPlayer, reportfile ); } } Index: galaxyng.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/galaxyng.c,v retrieving revision 1.65.2.3 retrieving revision 1.65.2.4 diff -C2 -d -r1.65.2.3 -r1.65.2.4 *** galaxyng.c 22 Jun 2007 22:25:28 -0000 1.65.2.3 --- galaxyng.c 4 Jul 2007 23:12:42 -0000 1.65.2.4 *************** *** 62,70 **** #include <unistd.h> - #ifdef WIN32 - /* Empty */ - #else #include <unistd.h> - #endif #include "galaxy.h" #include "util.h" --- 62,66 ---- *************** *** 79,84 **** ! char *galaxyng = ! "$Id$"; char vcid[128]; --- 75,79 ---- ! char *galaxyng = "$Id$"; char vcid[128]; |
From: Frans S. <gu...@us...> - 2007-06-23 21:06:03
|
Update of /cvsroot/galaxyng/NG/lib In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv6355 Modified Files: Tag: Refactor_Baseline Makefile Log Message: Added indentation target and a new depend target. Added some documentation. Index: Makefile =================================================================== RCS file: /cvsroot/galaxyng/NG/lib/Makefile,v retrieving revision 1.9 retrieving revision 1.9.2.1 diff -C2 -d -r1.9 -r1.9.2.1 *** Makefile 20 Mar 2006 14:32:13 -0000 1.9 --- Makefile 23 Jun 2007 21:05:58 -0000 1.9.2.1 *************** *** 2,5 **** --- 2,12 ---- # $Id$ # + # + # NOTE: + # If you use this makefile for regular development + # run a + # make depend + # to create a set of dependencies. + # CFLAGS = -Wall -pedantic -I../include $(ADDTL_CFLAGS) *************** *** 9,12 **** --- 16,20 ---- lockFile.c randomize.c OBJECTS=$(SOURCES:.c=.o) + DEPENDENCIES = $(OBJECTS:.o=.d) all : libgalaxyng.a *************** *** 16,35 **** clean: ! rm -f libgalaxyng.a $(OBJECTS) *~ ! depend: ! makedepend -- $(CFLAGS) -- $(SOURCES) ! # DO NOT DELETE THIS LINE -- make depend depends on it. - strutl.o: ../include/strutl.h ../include/cookies.h ../include/logging.h - logging.o: ../include/logging.h - list.o: ../include/list.h ../include/util.h ../include/galaxy.h - list.o: ../include/strutl.h ../include/cookies.h ../include/logging.h - globals.o: ../include/galaxy.h ../include/strutl.h ../include/cookies.h - globals.o: ../include/logging.h - mail.o: ../include/mail.h ../include/galaxy.h ../include/strutl.h - mail.o: ../include/logging.h ../include/util.h ../include/list.h - util.o: ../include/util.h ../include/galaxy.h ../include/strutl.h - util.o: ../include/logging.h ../include/list.h - util.o: ../include/create.h ../include/avl.h ../include/loadgame.h --- 24,46 ---- clean: ! rm -f libgalaxyng.a $(OBJECTS) *~ $(DEPENDENCIES) ! # Make a copy of the master configuration ! # file. ! .indent.pro : ../Source/.indent.pro ! cp ../Source/.indent.pro .indent.pro ! # Indent all source code. ! # It's good to have an uniform look. ! # The master configuration file is ! # in ../Source ! indent: .indent.pro ! indent *.c ! ! -include $(DEPENDENCIES) ! ! # Use gcc to create the dependencies for us. ! # This makes a set of .d files. ! depend: ! $(CC) -MMD -E -I../include $(SOURCES) > /dev/null |
From: Frans S. <gu...@us...> - 2007-06-23 20:55:52
|
Update of /cvsroot/galaxyng/NG/Source In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv2335 Modified Files: Tag: Refactor_Baseline Makefile Log Message: Added a indent target that indents all the source code. Added some documentation on dependency generation. Index: Makefile =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/Makefile,v retrieving revision 1.8.2.2 retrieving revision 1.8.2.3 diff -C2 -d -r1.8.2.2 -r1.8.2.3 *** Makefile 22 Jun 2007 22:23:00 -0000 1.8.2.2 --- Makefile 23 Jun 2007 20:55:52 -0000 1.8.2.3 *************** *** 16,20 **** # all versions of make. # ! # # Influence mapping: --- 16,24 ---- # all versions of make. # ! # If you use this makefile for regular developement, ! # use a ! # make depend ! # to update the dependencies. ! # # # Influence mapping: *************** *** 155,159 **** clean: ! rm -f $(GNG_OBJS) $(WOPR_OBJS) rm -f $(GALAXYNG) rm -f $(GALAXYNG).o --- 159,163 ---- clean: ! rm -f $(GNG_OBJS) $(WOPR_OBJS) $(DEPS) rm -f $(GALAXYNG) rm -f $(GALAXYNG).o *************** *** 177,180 **** --- 181,191 ---- egrep -v -G "^ \*" *.c *.h | egrep -v -G "/\*" | wc + # + # Indent all the .c files according to the settings + # in .indent.pro + # It is good to have a similar look for all sourcecode + # See man indent for more information. + indent: + indent *.c -include $(DEPS) |
Update of /cvsroot/galaxyng/NG/Source In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv17873 Removed Files: Tag: Refactor_Baseline cmd_immediate.c cmd_ordersdue.c cmd_relay.c cmd_relaymessage.c cmd_webcheck.c cmd_webreport.c Log Message: Removing dead code --- cmd_webreport.c DELETED --- --- cmd_relaymessage.c DELETED --- --- cmd_webcheck.c DELETED --- --- cmd_relay.c DELETED --- --- cmd_ordersdue.c DELETED --- --- cmd_immediate.c DELETED --- |
Update of /cvsroot/galaxyng/NG/lib In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv22013 Modified Files: Tag: Refactor_Baseline globals.c list.c loadNGConfig.c lockFile.c logging.c mail.c randomize.c strutl.c util.c Log Message: list.c works again. removed dead code. Index: loadNGConfig.c =================================================================== RCS file: /cvsroot/galaxyng/NG/lib/loadNGConfig.c,v retrieving revision 1.7 retrieving revision 1.7.2.1 diff -C2 -d -r1.7 -r1.7.2.1 *** loadNGConfig.c 20 Oct 2004 13:15:43 -0000 1.7 --- loadNGConfig.c 22 Jun 2007 22:28:38 -0000 1.7.2.1 *************** *** 16,147 **** void ! initServerOptions(game* aGame) { ! /* initialize values */ ! aGame->serverOptions.sendmail = NULL; ! aGame->serverOptions.encode = NULL; ! aGame->serverOptions.compress = NULL; ! aGame->serverOptions.GMemail = NULL; ! aGame->serverOptions.GMname = NULL; ! aGame->serverOptions.GMpassword = NULL; ! aGame->serverOptions.SERVERemail = NULL; ! aGame->serverOptions.SERVERname = NULL; ! aGame->serverOptions.ReplyTo = NULL; ! aGame->serverOptions.fontpath = NULL; ! aGame->serverOptions.due = NULL; ! aGame->serverOptions.tick_interval = NULL; } ! void readDefaults(game *aGame, FILE * f) { ! char* isRead; /* to check for EOF */ ! char* key; /* the key part of the name/value pair */ ! ! for (isRead = fgets(lineBuffer, LINE_BUFFER_SIZE, f); ! isRead; isRead = fgets(lineBuffer, LINE_BUFFER_SIZE, f)) { ! ! key = getstr(lineBuffer); ! if (key[0] != '\0') { ! if (noCaseStrcmp("GMemail", key) == 0) { ! if (aGame->serverOptions.GMemail) ! free(aGame->serverOptions.GMemail); ! aGame->serverOptions.GMemail = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("GMname", key) == 0) { ! if (aGame->serverOptions.GMname) ! free(aGame->serverOptions.GMname); ! aGame->serverOptions.GMname = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("GMpassword", key) == 0) { ! if (aGame->serverOptions.GMpassword) ! free(aGame->serverOptions.GMpassword); ! aGame->serverOptions.GMpassword = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("SERVERemail", key) == 0) { ! if (aGame->serverOptions.SERVERemail) ! free(aGame->serverOptions.SERVERemail); ! aGame->serverOptions.SERVERemail = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("SERVERname", key) == 0) { ! if (aGame->serverOptions.SERVERname) ! free(aGame->serverOptions.SERVERname); ! aGame->serverOptions.SERVERname = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("ReplyTo", key) == 0) { ! if (aGame->serverOptions.ReplyTo) ! free(aGame->serverOptions.ReplyTo); ! aGame->serverOptions.ReplyTo = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("compress", key) == 0) { ! if (aGame->serverOptions.compress) ! free(aGame->serverOptions.compress); ! aGame->serverOptions.compress = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("encode", key) == 0) { ! if (aGame->serverOptions.encode) ! free(aGame->serverOptions.encode); ! aGame->serverOptions.encode = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("sendmail", key) == 0) { ! if (aGame->serverOptions.sendmail) ! free(aGame->serverOptions.sendmail); ! aGame->serverOptions.sendmail = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("starttime", key) == 0) { ! if (aGame->starttime) ! free(aGame->starttime); ! aGame->starttime = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("fontpath", key) == 0) { ! if (aGame->serverOptions.fontpath) ! free(aGame->serverOptions.fontpath); ! aGame->serverOptions.fontpath = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("due", key) == 0) { ! if (aGame->serverOptions.due) ! free(aGame->serverOptions.due); ! aGame->serverOptions.due = strdup(getstr(0)); ! } ! else if (noCaseStrcmp("tick", key) == 0) { ! if (aGame->serverOptions.tick_interval) ! free(aGame->serverOptions.tick_interval); ! aGame->serverOptions.tick_interval = strdup(getstr(0)); ! } ! else { ! printf("Unknown key \"%s\"\n", key); ! } } - } - - if (aGame->serverOptions.due == NULL) - aGame->serverOptions.due = strdup("soon"); - - if (aGame->serverOptions.tick_interval == NULL) - aGame->serverOptions.tick_interval = strdup("48"); - - if (aGame->serverOptions.SERVERemail == NULL) { - char* logfile = createString("%s/Games/log/%s", galaxynghome, aGame->name); - FILE* logfp = fopen(logfile, "+w"); - fprintf(stderr, "SERVERemail is a required entry in your .galaxyngrc\n"); - fprintf(logfp, "SERVERemail is a required entry in your .galaxyngrc\n"); - fclose(logfp); - exit(EXIT_FAILURE); - } ! if (aGame->serverOptions.SERVERname == NULL) ! aGame->serverOptions.SERVERname = strdup("GalaxyNG Server"); ! if (aGame->serverOptions.GMemail == NULL) ! aGame->serverOptions.GMemail = ! strdup(aGame->serverOptions.SERVERemail); ! ! if (aGame->serverOptions.GMname == NULL) ! aGame->serverOptions.GMname = strdup("GalaxyNG GM"); ! if (aGame->serverOptions.ReplyTo == NULL) ! aGame->serverOptions.ReplyTo = ! strdup(aGame->serverOptions.SERVERemail); ! ! if (aGame->serverOptions.GMpassword == NULL) ! aGame->serverOptions.GMpassword = strdup(""); } --- 16,139 ---- void ! initServerOptions( game *aGame ) { ! /* initialize values */ ! aGame->serverOptions.sendmail = NULL; ! aGame->serverOptions.encode = NULL; ! aGame->serverOptions.compress = NULL; ! aGame->serverOptions.GMemail = NULL; ! aGame->serverOptions.GMname = NULL; ! aGame->serverOptions.GMpassword = NULL; ! aGame->serverOptions.SERVERemail = NULL; ! aGame->serverOptions.SERVERname = NULL; ! aGame->serverOptions.ReplyTo = NULL; ! aGame->serverOptions.fontpath = NULL; ! aGame->serverOptions.due = NULL; ! aGame->serverOptions.tick_interval = NULL; } ! void ! readDefaults( game *aGame, FILE *f ) ! { ! char *isRead; /* to check for EOF */ ! char *key; /* the key part of the name/value pair */ ! ! for ( isRead = fgets( lineBuffer, LINE_BUFFER_SIZE, f ); ! isRead; isRead = fgets( lineBuffer, LINE_BUFFER_SIZE, f ) ) { ! ! key = getstr( lineBuffer ); ! if ( key[0] != '\0' ) { ! if ( noCaseStrcmp( "GMemail", key ) == 0 ) { ! if ( aGame->serverOptions.GMemail ) ! free( aGame->serverOptions.GMemail ); ! aGame->serverOptions.GMemail = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "GMname", key ) == 0 ) { ! if ( aGame->serverOptions.GMname ) ! free( aGame->serverOptions.GMname ); ! aGame->serverOptions.GMname = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "GMpassword", key ) == 0 ) { ! if ( aGame->serverOptions.GMpassword ) ! free( aGame->serverOptions.GMpassword ); ! aGame->serverOptions.GMpassword = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "SERVERemail", key ) == 0 ) { ! if ( aGame->serverOptions.SERVERemail ) ! free( aGame->serverOptions.SERVERemail ); ! aGame->serverOptions.SERVERemail = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "SERVERname", key ) == 0 ) { ! if ( aGame->serverOptions.SERVERname ) ! free( aGame->serverOptions.SERVERname ); ! aGame->serverOptions.SERVERname = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "ReplyTo", key ) == 0 ) { ! if ( aGame->serverOptions.ReplyTo ) ! free( aGame->serverOptions.ReplyTo ); ! aGame->serverOptions.ReplyTo = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "compress", key ) == 0 ) { ! if ( aGame->serverOptions.compress ) ! free( aGame->serverOptions.compress ); ! aGame->serverOptions.compress = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "encode", key ) == 0 ) { ! if ( aGame->serverOptions.encode ) ! free( aGame->serverOptions.encode ); ! aGame->serverOptions.encode = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "sendmail", key ) == 0 ) { ! if ( aGame->serverOptions.sendmail ) ! free( aGame->serverOptions.sendmail ); ! aGame->serverOptions.sendmail = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "starttime", key ) == 0 ) { ! if ( aGame->starttime ) ! free( aGame->starttime ); ! aGame->starttime = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "fontpath", key ) == 0 ) { ! if ( aGame->serverOptions.fontpath ) ! free( aGame->serverOptions.fontpath ); ! aGame->serverOptions.fontpath = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "due", key ) == 0 ) { ! if ( aGame->serverOptions.due ) ! free( aGame->serverOptions.due ); ! aGame->serverOptions.due = strdup( getstr( 0 ) ); ! } else if ( noCaseStrcmp( "tick", key ) == 0 ) { ! if ( aGame->serverOptions.tick_interval ) ! free( aGame->serverOptions.tick_interval ); ! aGame->serverOptions.tick_interval = strdup( getstr( 0 ) ); ! } else { ! printf( "Unknown key \"%s\"\n", key ); ! } ! } } ! if ( aGame->serverOptions.due == NULL ) ! aGame->serverOptions.due = strdup( "soon" ); ! if ( aGame->serverOptions.tick_interval == NULL ) ! aGame->serverOptions.tick_interval = strdup( "48" ); ! if ( aGame->serverOptions.SERVERemail == NULL ) { ! char *logfile = ! createString( "%s/Games/log/%s", galaxynghome, aGame->name ); ! FILE *logfp = fopen( logfile, "+w" ); ! fprintf( stderr, ! "SERVERemail is a required entry in your .galaxyngrc\n" ); ! fprintf( logfp, ! "SERVERemail is a required entry in your .galaxyngrc\n" ); ! fclose( logfp ); ! exit( EXIT_FAILURE ); ! } ! ! if ( aGame->serverOptions.SERVERname == NULL ) ! aGame->serverOptions.SERVERname = strdup( "GalaxyNG Server" ); ! ! if ( aGame->serverOptions.GMemail == NULL ) ! aGame->serverOptions.GMemail = ! strdup( aGame->serverOptions.SERVERemail ); ! ! if ( aGame->serverOptions.GMname == NULL ) ! aGame->serverOptions.GMname = strdup( "GalaxyNG GM" ); ! ! if ( aGame->serverOptions.ReplyTo == NULL ) ! aGame->serverOptions.ReplyTo = ! strdup( aGame->serverOptions.SERVERemail ); ! ! if ( aGame->serverOptions.GMpassword == NULL ) ! aGame->serverOptions.GMpassword = strdup( "" ); } *************** *** 156,176 **** void ! loadNGConfig(game *aGame) { ! FILE *f; ! initServerOptions(aGame); ! sprintf(lineBuffer, "%s/.galaxyngrc", galaxynghome); ! if ((f = fopen(lineBuffer, "r"))) { ! readDefaults(aGame, f); ! fclose(f); ! } ! sprintf(lineBuffer, "%s/data/%s/.galaxyngrc", galaxynghome, aGame->name); ! if ((f = fopen(lineBuffer, "r"))) { ! readDefaults(aGame, f); ! fclose(f); ! } } - - --- 148,168 ---- void ! loadNGConfig( game *aGame ) ! { ! FILE *f; ! initServerOptions( aGame ); ! sprintf( lineBuffer, "%s/.galaxyngrc", galaxynghome ); ! if ( ( f = fopen( lineBuffer, "r" ) ) ) { ! readDefaults( aGame, f ); ! fclose( f ); ! } ! sprintf( lineBuffer, "%s/data/%s/.galaxyngrc", galaxynghome, ! aGame->name ); ! if ( ( f = fopen( lineBuffer, "r" ) ) ) { ! readDefaults( aGame, f ); ! fclose( f ); ! } } Index: strutl.c =================================================================== RCS file: /cvsroot/galaxyng/NG/lib/strutl.c,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -C2 -d -r1.4 -r1.4.2.1 *** strutl.c 5 Aug 2004 20:51:43 -0000 1.4 --- strutl.c 22 Jun 2007 22:28:39 -0000 1.4.2.1 *************** *** 134,157 **** */ ! strlist* makestrlist(char* ns) { ! strlist* s; ! strlist* cur; - char* tmp; - char* sPtr; - char* ePtr; - char* sep; - cur = NULL; ! sPtr = tmp = strdup(ns); ! sep = ePtr = strpbrk(sPtr, "\n\r"); - if (ePtr == NULL) { - cur = (strlist*)allocStruct(strlist); - cur->str = tmp; - return cur; - } - do { if ( cur ) { --- 134,159 ---- */ ! strlist * ! makestrlist( char *ns ) ! { ! strlist *s; ! strlist *cur; ! ! char *tmp; ! char *sPtr; ! char *ePtr; ! char *sep; cur = NULL; ! sPtr = tmp = strdup( ns ); ! sep = ePtr = strpbrk( sPtr, "\n\r" ); ! ! if ( ePtr == NULL ) { ! cur = ( strlist * ) allocStruct( strlist ); ! cur->str = tmp; ! return cur; ! } do { if ( cur ) { *************** *** 161,180 **** s = cur = ( strlist * ) allocStruct( strlist ); ! *ePtr = '\0'; cur->str = strdup( sPtr ); ! if (*sep == '\n' && *(ePtr+1) == '\r') ! sPtr = ePtr + 2; ! else ! sPtr = ePtr + 1; ! } while ((sep = ePtr = strpbrk(sPtr, "\n\r")) != NULL); - if (*sPtr != '\0') { - cur->next = ( strlist * ) allocStruct( strlist ); - cur = cur->next; - cur->str = strdup(sPtr); - } - free( tmp ); --- 163,182 ---- s = cur = ( strlist * ) allocStruct( strlist ); ! *ePtr = '\0'; cur->str = strdup( sPtr ); ! if ( *sep == '\n' && *( ePtr + 1 ) == '\r' ) ! sPtr = ePtr + 2; ! else ! sPtr = ePtr + 1; ! } while ( ( sep = ePtr = strpbrk( sPtr, "\n\r" ) ) != NULL ); ! ! if ( *sPtr != '\0' ) { ! cur->next = ( strlist * ) allocStruct( strlist ); ! cur = cur->next; ! cur->str = strdup( sPtr ); ! } free( tmp ); *************** *** 214,221 **** void ! dumpstrlist(strlist *aStrlist) { ! for (; aStrlist; aStrlist = aStrlist->next) { ! printf("%s\n", aStrlist->str); } } --- 216,223 ---- void ! dumpstrlist( strlist *aStrlist ) { ! for ( ; aStrlist; aStrlist = aStrlist->next ) { ! printf( "%s\n", aStrlist->str ); } } *************** *** 237,246 **** int ! noCaseStrcmp(const char *s, const char *t) { ! for (; tolower(*s) == tolower(*t); s++, t++) ! if (*s == '\0') ! return 0; ! return (int) (tolower(*s) - tolower(*t)); } --- 239,248 ---- int ! noCaseStrcmp( const char *s, const char *t ) { ! for ( ; tolower( *s ) == tolower( *t ); s++, t++ ) ! if ( *s == '\0' ) ! return 0; ! return ( int ) ( tolower( *s ) - tolower( *t ) ); } *************** *** 264,273 **** int ! noCaseStrncmp(const char *s, const char *t, int n) { ! for (n--; (tolower(*s) == tolower(*t)) && (n > 0); s++, t++, n--) ! if (*s == '\0') ! return 0; ! return (int) (tolower(*s) - tolower(*t)); } --- 266,276 ---- int ! noCaseStrncmp( const char *s, const char *t, int n ) { ! for ( n--; ( tolower( *s ) == tolower( *t ) ) && ( n > 0 ); ! s++, t++, n-- ) ! if ( *s == '\0' ) ! return 0; ! return ( int ) ( tolower( *s ) - tolower( *t ) ); } *************** *** 276,288 **** ! char* strlwr(char* str) { ! char* ptr = str; ! while (*ptr) { ! if (isupper(*ptr)) ! *ptr = tolower(*ptr); ! ptr++; ! } ! return str; } --- 279,293 ---- ! char * ! strlwr( char *str ) ! { ! char *ptr = str; ! while ( *ptr ) { ! if ( isupper( *ptr ) ) ! *ptr = tolower( *ptr ); ! ptr++; ! } ! return str; } Index: list.c =================================================================== RCS file: /cvsroot/galaxyng/NG/lib/list.c,v retrieving revision 1.8 retrieving revision 1.8.2.1 diff -C2 -d -r1.8 -r1.8.2.1 *** list.c 19 Jun 2007 08:00:10 -0000 1.8 --- list.c 22 Jun 2007 22:28:38 -0000 1.8.2.1 *************** *** 17,30 **** int ! numberOfElementsF(list *aList) { ! list *el; ! int noEl; ! noEl = 0; ! if (aList) ! for (el = aList; el; el = el->next) ! noEl++; ! return noEl; } --- 17,30 ---- int ! numberOfElementsF( list *aList ) { ! list *el; ! int noEl; ! noEl = 0; ! if ( aList ) ! for ( el = aList; el; el = el->next ) ! noEl++; ! return noEl; } *************** *** 36,43 **** void ! add2ListF(list **aList, list *anElement) { ! anElement->next = *aList; ! *aList = anElement; } --- 36,43 ---- void ! add2ListF( list **aList, list *anElement ) { ! anElement->next = *aList; ! *aList = anElement; } *************** *** 50,67 **** void ! freelist(void *base) { ! list *p, *p2; ! pdebug(DFULL2, "freelist"); ! p = base; ! while (p) { ! p2 = p->next; ! free(p->name); ! free(p); ! p = p2; ! pdebug(DFULL2, "."); ! } ! pdebug(DFULL2, "\n"); } --- 50,67 ---- void ! freelist( void *base ) { ! list *p, *p2; ! pdebug( DFULL2, "freelist" ); ! p = base; ! while ( p ) { ! p2 = p->next; ! free( p->name ); ! free( p ); ! p = p2; ! pdebug( DFULL2, "." ); ! } ! pdebug( DFULL2, "\n" ); } *************** *** 73,90 **** ****** */ ! void ! addListF(list **aList, list *anElement) { ! list *curElement; ! if (*aList == NULL) { ! *aList = anElement; ! } else { ! for (curElement = *aList; ! curElement->next; ! curElement = curElement->next); ! curElement->next = anElement; ! } } --- 73,89 ---- ****** */ ! void ! addListF( list **aList, list *anElement ) { ! list *curElement; ! if ( *aList == NULL ) { ! *aList = anElement; ! } else { ! for ( curElement = *aList; ! curElement->next; curElement = curElement->next ); ! curElement->next = anElement; ! } } *************** *** 95,123 **** ****** */ ! void ! insertListF(list **aList, list* where, list *anElement) { ! list *curElement; ! list *listEnd; ! if (*aList == NULL) { ! *aList = anElement; ! } ! else { ! for (curElement = *aList; curElement->next; ! curElement = curElement->next) { ! if (curElement == where) { ! break; ! } ! } ! for (listEnd = anElement; listEnd->next; listEnd = listEnd->next) ! ; ! listEnd->next = curElement->next; ! curElement->next = anElement; ! } } --- 94,120 ---- ****** */ ! void ! insertListF( list **aList, list *where, list *anElement ) { ! list *curElement; ! list *listEnd; ! if ( *aList == NULL ) { ! *aList = anElement; ! } else { ! for ( curElement = *aList; curElement->next; ! curElement = curElement->next ) { ! if ( curElement == where ) { ! break; ! } ! } ! for ( listEnd = anElement; listEnd->next; listEnd = listEnd->next ); ! listEnd->next = curElement->next; ! curElement->next = anElement; ! } } *************** *** 140,155 **** */ ! list* ! findElementF(list *aList, char *name) { ! list *anElement; ! for (anElement = aList; ! anElement; ! anElement = anElement->next) { ! if (!noCaseStrcmp(anElement->name, name)) ! break; ! } ! return anElement; } --- 137,150 ---- */ ! list * ! findElementF( list *aList, char *name ) { ! list *anElement; ! for ( anElement = aList; anElement; anElement = anElement->next ) { ! if ( !noCaseStrcmp( anElement->name, name ) ) ! break; ! } ! return anElement; } *************** *** 169,189 **** void ! removeListF(list **aList, list *anElement) { ! list *prevElement; ! assert(anElement != NULL); ! if (*aList == anElement) ! *aList = anElement->next; ! else { ! for (prevElement = *aList; ! prevElement->next != anElement; ! prevElement = prevElement->next) { ! assert(prevElement != NULL); } ! prevElement->next = anElement->next; ! } ! free(anElement); } --- 164,184 ---- void ! removeListF( list **aList, list *anElement ) { ! list *prevElement; ! assert( anElement != NULL ); ! if ( *aList == anElement ) ! *aList = anElement->next; ! else { ! for ( prevElement = *aList; ! prevElement->next != anElement; ! prevElement = prevElement->next ) { ! assert( prevElement != NULL ); ! } ! prevElement->next = anElement->next; } ! free( anElement ); } *************** *** 207,219 **** int ! ptonum(void *base, void *target) { ! list *p; ! int i; ! for (p = base, i = 1; p; p = p->next, i++) ! if (p == target) ! return i; ! return 0; } --- 202,214 ---- int ! ptonum( void *base, void *target ) { ! list *p; ! int i; ! for ( p = base, i = 1; p; p = p->next, i++ ) ! if ( p == target ) ! return i; ! return 0; } *************** *** 235,250 **** void * ! numtop(void *base, int n) { ! list *p; ! int i; ! i = 0; ! for (p = base; p; p = p->next) { ! i++; ! if (i == n) ! return p; ! } ! return 0; } --- 230,245 ---- void * ! numtop( void *base, int n ) { ! list *p; ! int i; ! i = 0; ! for ( p = base; p; p = p->next ) { ! i++; ! if ( i == n ) ! return p; ! } ! return 0; } *************** *** 265,283 **** void ! setNameF(list *anElement, const char *name) { ! free(anElement->name); ! anElement->name = strdup(name); } void ! dumpList(char* label, list* aList, void* callback(void*)) { ! list* curElement; ! fprintf(stderr, "*** %s ***\n", label); ! for (curElement = aList; curElement; curElement=curElement->next) { ! fprintf(stderr, "%lX: %s\n", curElement->cookie, curElement->name); ! callback((void*)curElement); } } --- 260,278 ---- void ! setNameF( list *anElement, const char *name ) { ! free( anElement->name ); ! anElement->name = strdup( name ); } void ! dumpList( char *label, list *aList, void *callback( void * ) ) { ! list *curElement; ! fprintf( stderr, "*** %s ***\n", label ); ! for ( curElement = aList; curElement; curElement = curElement->next ) { ! fprintf( stderr, "%lX: %s\n", curElement->cookie, curElement->name ); ! callback( ( void * ) curElement ); } } *************** *** 288,321 **** void ! dumpRandList(char* label, list* aList, void* callback(void*)) { ! list* curElement; /* TODO */ #if 0 ! fprintf(stderr, "*** %s ***\n", label); assert( 0 ); ! for (curElement = aList; curElement; curElement=curElement->randNext) { ! fprintf(stderr, "%lX: %s\n", curElement->cookie, curElement->name); ! callback((void*)curElement); } #endif } ! void* ! allocStructF(unsigned int n, long cookie) { ! list *p; ! ! p = calloc(1, n); ! if (p == 0) { ! pdebug(DERR, "Out of memory, aborting program.\n"); ! exit(1); ! } ! p->cookie = cookie; ! p->name = NULL; ! p->next = NULL; ! /* TODO p->randNext = NULL; */ ! return (void *) p; ! } --- 283,314 ---- void ! dumpRandList( char *label, list *aList, void *callback( void * ) ) { ! list *curElement; /* TODO */ #if 0 ! fprintf( stderr, "*** %s ***\n", label ); assert( 0 ); ! for ( curElement = aList; curElement; curElement = curElement->randNext ) { ! fprintf( stderr, "%lX: %s\n", curElement->cookie, curElement->name ); ! callback( ( void * ) curElement ); } #endif } ! void * ! allocStructF( unsigned int n, long cookie ) { ! list *p; ! p = calloc( 1, n ); ! if ( p == 0 ) { ! pdebug( DERR, "Out of memory, aborting program.\n" ); ! exit( 1 ); ! } ! p->cookie = cookie; ! p->name = NULL; ! p->next = NULL; + return ( void * ) p; + } Index: lockFile.c =================================================================== RCS file: /cvsroot/galaxyng/NG/lib/lockFile.c,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -C2 -d -r1.1 -r1.1.2.1 *** lockFile.c 25 Jun 2004 11:44:59 -0000 1.1 --- lockFile.c 22 Jun 2007 22:28:38 -0000 1.1.2.1 *************** *** 8,99 **** #include <signal.h> ! static int readData(int fd, void* buf, size_t nbrBytes) { ! size_t toRead; ! size_t nbrRead = 0; ! ssize_t result; ! do { ! if (nbrBytes - nbrRead > SSIZE_MAX) ! toRead = SSIZE_MAX; ! else ! toRead = nbrBytes - nbrRead; ! if ((result = read(fd, (char*)buf+nbrRead, toRead)) >= 0) ! nbrRead += result; ! else if (errno != EINTR) ! return 0; ! } while (nbrRead < nbrBytes); ! return 1; } ! static int writeData(int fd, const void* buf, size_t nbrBytes) { ! size_t toWrite; ! size_t written = 0; ! ssize_t result; ! do { ! if (nbrBytes - written > SSIZE_MAX) ! toWrite = SSIZE_MAX; ! else ! toWrite = nbrBytes - written; ! if ((result = write(fd, (const char*)buf + written, toWrite)) >= 0) ! written += result; ! else if (errno != EINTR) ! return 0; ! } while (written < nbrBytes); ! return 1; } ! int spcLockFile(const char* lfpath) { ! int attempt; ! int fd; ! int result; ! pid_t pid; ! /* try 3 times, if we fail, we lose */ ! for (attempt = 0; attempt < 3; attempt++) { ! if ((fd = open(lfpath, O_RDWR|O_CREAT|O_EXCL, S_IRWXU)) == -1) { ! if (errno != EEXIST) ! return -1; ! if ((fd = open(lfpath, O_RDONLY)) == -1) ! return -1; ! result = readData(fd, &pid, sizeof(pid)); ! close(fd); ! if (result) { ! if (pid == getpid()) ! return 1; ! if (kill(pid, 0) == -1) { ! if (errno != ESRCH) ! return -1; ! attempt--; ! unlink(lfpath); ! continue; ! } ! } ! sleep(1); ! continue; ! } ! pid = getpid(); ! if (!writeData(fd, &pid, sizeof(pid))) { ! close(fd); ! return -1; ! } ! close(fd); ! attempt--; ! } ! /* If we've made it to here, three attempts have been made and the ! * lock could not be obtained. Return an error code indicating ! * failure to obtain the requested lock. ! */ ! return 0; } --- 8,107 ---- #include <signal.h> ! static int ! readData( int fd, void *buf, size_t nbrBytes ) ! { ! size_t toRead; ! size_t nbrRead = 0; ! ssize_t result; ! do { ! if ( nbrBytes - nbrRead > SSIZE_MAX ) ! toRead = SSIZE_MAX; ! else ! toRead = nbrBytes - nbrRead; ! if ( ( result = read( fd, ( char * ) buf + nbrRead, toRead ) ) >= 0 ) ! nbrRead += result; ! else if ( errno != EINTR ) ! return 0; ! } while ( nbrRead < nbrBytes ); ! return 1; } ! static int ! writeData( int fd, const void *buf, size_t nbrBytes ) ! { ! size_t toWrite; ! size_t written = 0; ! ssize_t result; ! do { ! if ( nbrBytes - written > SSIZE_MAX ) ! toWrite = SSIZE_MAX; ! else ! toWrite = nbrBytes - written; ! if ( ( result = ! write( fd, ( const char * ) buf + written, toWrite ) ) >= 0 ) ! written += result; ! else if ( errno != EINTR ) ! return 0; ! } while ( written < nbrBytes ); ! return 1; } ! int ! spcLockFile( const char *lfpath ) ! { ! int attempt; ! int fd; ! int result; ! pid_t pid; ! /* try 3 times, if we fail, we lose */ ! for ( attempt = 0; attempt < 3; attempt++ ) { ! if ( ( fd = ! open( lfpath, O_RDWR | O_CREAT | O_EXCL, S_IRWXU ) ) == -1 ) { ! if ( errno != EEXIST ) ! return -1; ! if ( ( fd = open( lfpath, O_RDONLY ) ) == -1 ) ! return -1; ! result = readData( fd, &pid, sizeof( pid ) ); ! close( fd ); ! if ( result ) { ! if ( pid == getpid( ) ) ! return 1; ! if ( kill( pid, 0 ) == -1 ) { ! if ( errno != ESRCH ) ! return -1; ! attempt--; ! unlink( lfpath ); ! continue; ! } ! } ! sleep( 1 ); ! continue; ! } ! pid = getpid( ); ! if ( !writeData( fd, &pid, sizeof( pid ) ) ) { ! close( fd ); ! return -1; ! } ! close( fd ); ! attempt--; ! } ! /* If we've made it to here, three attempts have been made and the ! * lock could not be obtained. Return an error code indicating ! * failure to obtain the requested lock. ! */ ! return 0; } Index: mail.c =================================================================== RCS file: /cvsroot/galaxyng/NG/lib/mail.c,v retrieving revision 1.18 retrieving revision 1.18.2.1 diff -C2 -d -r1.18 -r1.18.2.1 *** mail.c 16 Jan 2005 19:39:26 -0000 1.18 --- mail.c 22 Jun 2007 22:28:38 -0000 1.18.2.1 *************** *** 15,44 **** ! void createMailToAllHeader(game *aGame) { ! player* aPlayer; ! int state; ! if (aGame->serverOptions.SERVERemail) { ! if (aGame->serverOptions.SERVERname) { ! printf("From: %s <%s>\n", aGame->serverOptions.SERVERname, aGame->serverOptions.SERVERemail); ! } else { ! printf("From: %s\n", aGame->serverOptions.SERVERemail); } ! } ! ! printf("To: %s\nBCC: ", aGame->serverOptions.GMemail); ! for (aPlayer = aGame->players, state = 0; ! aPlayer; ! aPlayer = aPlayer->next) { ! if (!(aPlayer->flags & F_DEAD)) { ! if (state == 0) { ! printf(" %s", aPlayer->addr); ! state = 1; ! } else { ! printf(",\n %s", aPlayer->addr); ! } } ! } ! printf("\nSubject:\n"); } --- 15,46 ---- ! void ! createMailToAllHeader( game *aGame ) ! { ! player *aPlayer; ! int state; ! if ( aGame->serverOptions.SERVERemail ) { ! if ( aGame->serverOptions.SERVERname ) { ! printf( "From: %s <%s>\n", aGame->serverOptions.SERVERname, ! aGame->serverOptions.SERVERemail ); ! } else { ! printf( "From: %s\n", aGame->serverOptions.SERVERemail ); ! } } ! ! printf( "To: %s\nBCC: ", aGame->serverOptions.GMemail ); ! for ( aPlayer = aGame->players, state = 0; ! aPlayer; aPlayer = aPlayer->next ) { ! if ( !( aPlayer->flags & F_DEAD ) ) { ! if ( state == 0 ) { ! printf( " %s", aPlayer->addr ); ! state = 1; ! } else { ! printf( ",\n %s", aPlayer->addr ); ! } ! } } ! printf( "\nSubject:\n" ); } *************** *** 51,71 **** */ ! envelope* createEnvelope() { ! envelope *e; ! e = malloc(sizeof(envelope)); ! assert(e != NULL); ! e->to = NULL; ! e->from = NULL; ! e->replyto = NULL; ! e->subject = NULL; ! e->from_address = NULL; ! e->from_name = NULL; ! e->bcc = NULL; ! e->cc = NULL; ! e->compress = FALSE; ! e->contentType = NULL; ! e->contentEncoding = NULL; ! e->contentDescription = NULL; ! return e; } --- 53,75 ---- */ ! envelope * ! createEnvelope( ) ! { ! envelope *e; ! e = malloc( sizeof( envelope ) ); ! assert( e != NULL ); ! e->to = NULL; ! e->from = NULL; ! e->replyto = NULL; ! e->subject = NULL; ! e->from_address = NULL; ! e->from_name = NULL; ! e->bcc = NULL; ! e->cc = NULL; ! e->compress = FALSE; ! e->contentType = NULL; ! e->contentEncoding = NULL; ! e->contentDescription = NULL; ! return e; } *************** *** 79,126 **** */ ! envelope* readEnvelope(FILE* fp) { ! envelope *e; ! char buffer[4096]; ! char* ptr; ! ! e = createEnvelope(); ! ! while (fgets(buffer, 4096, fp) != NULL) { ! *(strchr(buffer, '\n')) = '\0'; ! ! if (buffer[0] == '\0') ! break; /* end of headers */ ! ! if ((ptr = strchr(buffer, ':')) == NULL) ! continue; /* skip header, no : in it */ ! ! *ptr = '\0'; ! ! if (noCaseStrcmp(buffer, "from") == 0) { ! e->from = strdup(ptr+2); ! } ! else if (noCaseStrcmp(buffer, "to") == 0) { ! e->to = strdup(ptr+2); ! } ! else if (noCaseStrcmp(buffer, "subject") == 0) { ! e->subject = strdup(ptr+2); ! } ! else if (noCaseStrcmp(buffer, "cc") == 0) { ! e->cc = strdup(ptr+2); ! } ! else if (noCaseStrcmp(buffer, "content-type") == 0) { ! e->contentType = strdup(ptr+2); ! } ! else if (noCaseStrcmp(buffer, "content-transfer-encoding") == 0) { ! e->contentEncoding = strdup(ptr+2); ! } ! else if (noCaseStrcmp(buffer, "content-description") == 0) { ! e->contentDescription = strdup(ptr+2); } - else - continue; - } ! return e; } --- 83,125 ---- */ ! envelope * ! readEnvelope( FILE *fp ) ! { ! envelope *e; ! char buffer[4096]; ! char *ptr; ! ! e = createEnvelope( ); ! ! while ( fgets( buffer, 4096, fp ) != NULL ) { ! *( strchr( buffer, '\n' ) ) = '\0'; ! ! if ( buffer[0] == '\0' ) ! break; /* end of headers */ ! ! if ( ( ptr = strchr( buffer, ':' ) ) == NULL ) ! continue; /* skip header, no : in it */ ! ! *ptr = '\0'; ! ! if ( noCaseStrcmp( buffer, "from" ) == 0 ) { ! e->from = strdup( ptr + 2 ); ! } else if ( noCaseStrcmp( buffer, "to" ) == 0 ) { ! e->to = strdup( ptr + 2 ); ! } else if ( noCaseStrcmp( buffer, "subject" ) == 0 ) { ! e->subject = strdup( ptr + 2 ); ! } else if ( noCaseStrcmp( buffer, "cc" ) == 0 ) { ! e->cc = strdup( ptr + 2 ); ! } else if ( noCaseStrcmp( buffer, "content-type" ) == 0 ) { ! e->contentType = strdup( ptr + 2 ); ! } else if ( noCaseStrcmp( buffer, "content-transfer-encoding" ) == 0 ) { ! e->contentEncoding = strdup( ptr + 2 ); ! } else if ( noCaseStrcmp( buffer, "content-description" ) == 0 ) { ! e->contentDescription = strdup( ptr + 2 ); ! } else ! continue; } ! return e; } *************** *** 136,213 **** */ ! void setHeader(envelope *e, int headerType, char *format, ...) { ! int n; ! ! va_list ap; ! ! assert(e != NULL); ! ! va_start(ap, format); #ifdef WIN32 ! vsprintf(lineBuffer, format, ap); #else ! n = vsnprintf(lineBuffer, LINE_BUFFER_SIZE, format, ap); ! assert(n != -1); #endif ! va_end(ap); ! ! switch(headerType) { ! case MAILHEADER_TO: ! if (e->to) ! free(e->to); ! e->to = strdup(lineBuffer); ! break; ! ! case MAILHEADER_FROM: ! if (e->from) ! free(e->from); ! e->from = strdup(lineBuffer); ! break; ! ! case MAILHEADER_REPLYTO: ! if (e->replyto) ! free(e->replyto); ! e->replyto = strdup(lineBuffer); ! break; ! ! case MAILHEADER_SUBJECT: ! if (e->subject) ! free(e->subject); ! e->subject = strdup(lineBuffer); ! break; ! ! case MAILHEADER_BCC: ! if (e->bcc) ! free(e->bcc); ! e->bcc = strdup(lineBuffer); ! break; ! ! case MAILHEADER_CC: ! if (e->cc) ! free(e->cc); ! e->cc = strdup(lineBuffer); ! break; ! ! ! case MAILHEADER_CONTENTTYPE: ! if (e->contentType) ! free(e->contentType); ! e->contentType = strdup(lineBuffer); ! break; ! ! case MAILHEADER_CONTENTENCODING: ! if (e->contentEncoding) ! free(e->contentEncoding); ! e->contentEncoding = strdup(lineBuffer); ! break; ! ! case MAILHEADER_CONTENTDESCRIPTION: ! if (e->contentDescription) ! free(e->contentDescription); ! e->contentDescription = strdup(lineBuffer); ! ! default: ! assert(0); ! } } --- 135,214 ---- */ ! void ! setHeader( envelope *e, int headerType, char *format, ... ) ! { ! int n; ! ! va_list ap; ! ! assert( e != NULL ); ! ! va_start( ap, format ); #ifdef WIN32 ! vsprintf( lineBuffer, format, ap ); #else ! n = vsnprintf( lineBuffer, LINE_BUFFER_SIZE, format, ap ); ! assert( n != -1 ); #endif ! va_end( ap ); ! ! switch ( headerType ) { ! case MAILHEADER_TO: ! if ( e->to ) ! free( e->to ); ! e->to = strdup( lineBuffer ); ! break; ! ! case MAILHEADER_FROM: ! if ( e->from ) ! free( e->from ); ! e->from = strdup( lineBuffer ); ! break; ! ! case MAILHEADER_REPLYTO: ! if ( e->replyto ) ! free( e->replyto ); ! e->replyto = strdup( lineBuffer ); ! break; ! ! case MAILHEADER_SUBJECT: ! if ( e->subject ) ! free( e->subject ); ! e->subject = strdup( lineBuffer ); ! break; ! ! case MAILHEADER_BCC: ! if ( e->bcc ) ! free( e->bcc ); ! e->bcc = strdup( lineBuffer ); ! break; ! ! case MAILHEADER_CC: ! if ( e->cc ) ! free( e->cc ); ! e->cc = strdup( lineBuffer ); ! break; ! ! ! case MAILHEADER_CONTENTTYPE: ! if ( e->contentType ) ! free( e->contentType ); ! e->contentType = strdup( lineBuffer ); ! break; ! ! case MAILHEADER_CONTENTENCODING: ! if ( e->contentEncoding ) ! free( e->contentEncoding ); ! e->contentEncoding = strdup( lineBuffer ); ! break; ! ! case MAILHEADER_CONTENTDESCRIPTION: ! if ( e->contentDescription ) ! free( e->contentDescription ); ! e->contentDescription = strdup( lineBuffer ); ! ! default: ! assert( 0 ); ! } } *************** *** 220,249 **** */ ! void destroyEnvelope(envelope *e) { ! assert(e != NULL); ! if (e->to) ! free(e->to); ! if (e->from) ! free(e->from); ! if (e->from_address) ! free(e->from_address); ! if (e->from_name) ! free(e->from_name); ! if (e->replyto) ! free(e->replyto); ! if (e->subject) ! free(e->subject); ! if (e->bcc) ! free(e->bcc); ! if (e->cc) ! free(e->cc); ! if (e->contentType) ! free(e->contentType); ! if (e->contentEncoding) ! free(e->contentEncoding); ! if (e->contentDescription) ! free(e->contentDescription); ! ! free(e); } --- 221,252 ---- */ ! void ! destroyEnvelope( envelope *e ) ! { ! assert( e != NULL ); ! if ( e->to ) ! free( e->to ); ! if ( e->from ) ! free( e->from ); ! if ( e->from_address ) ! free( e->from_address ); ! if ( e->from_name ) ! free( e->from_name ); ! if ( e->replyto ) ! free( e->replyto ); ! if ( e->subject ) ! free( e->subject ); ! if ( e->bcc ) ! free( e->bcc ); ! if ( e->cc ) ! free( e->cc ); ! if ( e->contentType ) ! free( e->contentType ); ! if ( e->contentEncoding ) ! free( e->contentEncoding ); ! if ( e->contentDescription ) ! free( e->contentDescription ); ! ! free( e ); } *************** *** 266,376 **** */ ! int eMail(game *aGame, envelope *e, char *fileName) { ! FILE* mailFile; ! char template[128]; ! int result; ! char command[4096]; ! pdebug(DFULL, "eMail\n"); ! ! sprintf(template, "%s/galaxyXXXXXX", tempdir); ! ! assert(fileName != NULL); ! assert(aGame != NULL); ! ! mailFile = fdopen(mkstemp(template), "w"); ! result = 1; ! ! assert(e->to); ! assert(e->subject); - if (e->from_address && e->from_name) { - fprintf(mailFile, "From: %s <%s>\n", e->from_name, e->from_address); - } else if (e->from) { - fprintf(mailFile, "From: %s\n", e->from); - } - - fprintf(mailFile, "To: %s\n", e->to); - fprintf(mailFile, "Subject: %s\n", e->subject); - - if (e->replyto) - fprintf(mailFile, "Reply-To: %s\n", e->replyto); - - if (e->bcc) - fprintf(mailFile, "BCC: %s\n", e->bcc); - if (e->cc) - fprintf(mailFile, "CC: %s\n", e->cc); - if (e->contentType) - fprintf(mailFile, "Content-Type: %s\n", e->contentType); - if (e->contentEncoding) - fprintf(mailFile, "Content-tranfer-encoding: %s\n", - e->contentEncoding); - if (e->contentDescription) - fprintf(mailFile, "Content-description: %s\n", e->contentDescription); - #ifndef WIN32 ! if (e->compress && ! aGame->serverOptions.compress && ! aGame->serverOptions.encode) { ! addMimeHeader(mailFile); ! } ! fprintf(mailFile, "\n\n"); ! if (e->compress && ! aGame->serverOptions.compress && ! aGame->serverOptions.encode) { ! char *relative_path; ! char *ptr; ! char zipped_name[4096]; ! char encoded_name[4096]; ! addMimeText(mailFile); ! fprintf(mailFile, "Turn report is attached as .zip file.\n\n"); ! relative_path = strstr(fileName, "reports"); ! if (relative_path == NULL) { ! fprintf(stderr, ! "Reports are not in their standards position\n"); ! relative_path = fileName; } - strcpy(zipped_name, fileName); - if ((ptr = strrchr(zipped_name, '.')) != NULL) - *ptr = '_'; - strcat(zipped_name, ".zip"); - strcpy(encoded_name, fileName); - if ((ptr = strrchr(encoded_name, '.')) != NULL) - *ptr = '_'; - result = ssystem("%s %s %s > /dev/null 2>&1", - aGame->serverOptions.compress, - zipped_name, - relative_path); - result |= ssystem("%s < %s > %s 2> /dev/null", - aGame->serverOptions.encode, - zipped_name, - encoded_name); - addMimeZip(mailFile); - result |= appendToMail(encoded_name, mailFile); - addMimeEnd(mailFile); - result |= ssystem("rm %s %s", zipped_name, encoded_name); - } - else { - result = appendToMail(fileName, mailFile); - } #endif ! fclose(mailFile); #ifndef WIN32 ! sprintf(command, "%s", aGame->serverOptions.sendmail); ! if (e->from_address) { ! char tmpBuf[4096]; ! sprintf(tmpBuf, " -f \"%s\"", e->from_address); ! strcat(command, tmpBuf); ! } ! if (e->from_name) { ! char tmpBuf[4096]; ! sprintf(tmpBuf, " -F \"%s\"", e->from_name); ! strcat(command, tmpBuf); ! } ! result |= ssystem("%s < %s", command, template); ! result |= ssystem("rm %s", template); #endif ! return result; } --- 269,377 ---- */ ! int ! eMail( game *aGame, envelope *e, char *fileName ) ! { ! FILE *mailFile; ! char template[128]; ! int result; ! char command[4096]; ! pdebug( DFULL, "eMail\n" ); ! ! sprintf( template, "%s/galaxyXXXXXX", tempdir ); ! ! assert( fileName != NULL ); ! assert( aGame != NULL ); ! ! mailFile = fdopen( mkstemp( template ), "w" ); ! result = 1; ! ! assert( e->to ); ! assert( e->subject ); ! ! if ( e->from_address && e->from_name ) { ! fprintf( mailFile, "From: %s <%s>\n", e->from_name, e->from_address ); ! } else if ( e->from ) { ! fprintf( mailFile, "From: %s\n", e->from ); ! } ! ! fprintf( mailFile, "To: %s\n", e->to ); ! fprintf( mailFile, "Subject: %s\n", e->subject ); ! ! if ( e->replyto ) ! fprintf( mailFile, "Reply-To: %s\n", e->replyto ); ! ! if ( e->bcc ) ! fprintf( mailFile, "BCC: %s\n", e->bcc ); ! if ( e->cc ) ! fprintf( mailFile, "CC: %s\n", e->cc ); ! if ( e->contentType ) ! fprintf( mailFile, "Content-Type: %s\n", e->contentType ); ! if ( e->contentEncoding ) ! fprintf( mailFile, "Content-tranfer-encoding: %s\n", ! e->contentEncoding ); ! if ( e->contentDescription ) ! fprintf( mailFile, "Content-description: %s\n", ! e->contentDescription ); #ifndef WIN32 ! if ( e->compress && ! aGame->serverOptions.compress && aGame->serverOptions.encode ) { ! addMimeHeader( mailFile ); ! } ! fprintf( mailFile, "\n\n" ); ! if ( e->compress && ! aGame->serverOptions.compress && aGame->serverOptions.encode ) { ! char *relative_path; ! char *ptr; ! char zipped_name[4096]; ! char encoded_name[4096]; ! addMimeText( mailFile ); ! fprintf( mailFile, "Turn report is attached as .zip file.\n\n" ); ! relative_path = strstr( fileName, "reports" ); ! if ( relative_path == NULL ) { ! fprintf( stderr, ! "Reports are not in their standards position\n" ); ! relative_path = fileName; ! } ! strcpy( zipped_name, fileName ); ! if ( ( ptr = strrchr( zipped_name, '.' ) ) != NULL ) ! *ptr = '_'; ! strcat( zipped_name, ".zip" ); ! strcpy( encoded_name, fileName ); ! if ( ( ptr = strrchr( encoded_name, '.' ) ) != NULL ) ! *ptr = '_'; ! result = ssystem( "%s %s %s > /dev/null 2>&1", ! aGame->serverOptions.compress, ! zipped_name, relative_path ); ! result |= ssystem( "%s < %s > %s 2> /dev/null", ! aGame->serverOptions.encode, ! zipped_name, encoded_name ); ! addMimeZip( mailFile ); ! result |= appendToMail( encoded_name, mailFile ); ! addMimeEnd( mailFile ); ! result |= ssystem( "rm %s %s", zipped_name, encoded_name ); ! } else { ! result = appendToMail( fileName, mailFile ); } #endif ! fclose( mailFile ); #ifndef WIN32 ! sprintf( command, "%s", aGame->serverOptions.sendmail ); ! if ( e->from_address ) { ! char tmpBuf[4096]; ! sprintf( tmpBuf, " -f \"%s\"", e->from_address ); ! strcat( command, tmpBuf ); ! } ! if ( e->from_name ) { ! char tmpBuf[4096]; ! sprintf( tmpBuf, " -F \"%s\"", e->from_name ); ! strcat( command, tmpBuf ); ! } ! result |= ssystem( "%s < %s", command, template ); ! result |= ssystem( "rm %s", template ); #endif ! return result; } *************** *** 378,387 **** void ! addMimeHeader(FILE *mailFile) { ! fprintf(mailFile, "Mime-Version: 1.0\n"); ! fprintf(mailFile, ! "Content-Type: multipart/mixed; boundary=\"9jxsPFA5p3P2qPhR\"\n"); ! fprintf(mailFile, "Content-Disposition: inline\n"); } --- 379,388 ---- void ! addMimeHeader( FILE *mailFile ) { ! fprintf( mailFile, "Mime-Version: 1.0\n" ); ! fprintf( mailFile, ! "Content-Type: multipart/mixed; boundary=\"9jxsPFA5p3P2qPhR\"\n" ); ! fprintf( mailFile, "Content-Disposition: inline\n" ); } *************** *** 389,398 **** void ! addMimeText(FILE *mailFile) { ! fprintf(mailFile, "--9jxsPFA5p3P2qPhR\n"); ! fprintf(mailFile, "Content-Type: text/plain; charset=us-ascii\n"); ! fprintf(mailFile, "Content-Disposition: inline\n"); ! fprintf(mailFile, "\n"); } --- 390,399 ---- void ! addMimeText( FILE *mailFile ) { ! fprintf( mailFile, "--9jxsPFA5p3P2qPhR\n" ); ! fprintf( mailFile, "Content-Type: text/plain; charset=us-ascii\n" ); ! fprintf( mailFile, "Content-Disposition: inline\n" ); ! fprintf( mailFile, "\n" ); } *************** *** 400,420 **** void ! addMimeUUE(FILE *mailFile) { ! fprintf(mailFile, "--9jxsPFA5p3P2qPhR\n"); ! fprintf(mailFile, "Content-Type: application/zip\n"); ! fprintf(mailFile, "Content-Disposition: attachment; filename=\"turn.zip\"\n"); ! fprintf(mailFile, "Content-Transfer-Encoding: base64\n"); ! fprintf(mailFile, "\n"); } void ! addMimeZip(FILE *mailFile) { ! fprintf(mailFile, "--9jxsPFA5p3P2qPhR\n"); ! fprintf(mailFile, "Content-Type: application/zip\n"); ! fprintf(mailFile, "Content-Disposition: attachment; filename=\"turn.zip\"\n"); ! fprintf(mailFile, "Content-Transfer-Encoding: base64\n"); ! fprintf(mailFile, "\n"); } --- 401,423 ---- void ! addMimeUUE( FILE *mailFile ) { ! fprintf( mailFile, "--9jxsPFA5p3P2qPhR\n" ); ! fprintf( mailFile, "Content-Type: application/zip\n" ); ! fprintf( mailFile, ! "Content-Disposition: attachment; filename=\"turn.zip\"\n" ); ! fprintf( mailFile, "Content-Transfer-Encoding: base64\n" ); ! fprintf( mailFile, "\n" ); } void ! addMimeZip( FILE *mailFile ) { ! fprintf( mailFile, "--9jxsPFA5p3P2qPhR\n" ); ! fprintf( mailFile, "Content-Type: application/zip\n" ); ! fprintf( mailFile, ! "Content-Disposition: attachment; filename=\"turn.zip\"\n" ); ! fprintf( mailFile, "Content-Transfer-Encoding: base64\n" ); ! fprintf( mailFile, "\n" ); } *************** *** 422,428 **** void ! addMimeEnd(FILE *mailFile) { ! fprintf(mailFile, "\n--9jxsPFA5p3P2qPhR--\n"); } --- 425,431 ---- void ! addMimeEnd( FILE *mailFile ) { ! fprintf( mailFile, "\n--9jxsPFA5p3P2qPhR--\n" ); } *************** *** 430,449 **** int ! appendToMail(char *fileName, FILE *mailFile) { ! FILE *f; ! char *isRead; ! f = fopen(fileName, "r"); ! if (f) { ! for (isRead = fgets(lineBuffer, LINE_BUFFER_SIZE, f); ! isRead; ! isRead = fgets(lineBuffer, LINE_BUFFER_SIZE, f)) { ! fputs(lineBuffer, mailFile); } - fclose(f); - return FALSE; - } else { - return TRUE; - } } --- 433,451 ---- int ! appendToMail( char *fileName, FILE *mailFile ) { ! FILE *f; ! char *isRead; ! f = fopen( fileName, "r" ); ! if ( f ) { ! for ( isRead = fgets( lineBuffer, LINE_BUFFER_SIZE, f ); ! isRead; isRead = fgets( lineBuffer, LINE_BUFFER_SIZE, f ) ) { ! fputs( lineBuffer, mailFile ); ! } ! fclose( f ); ! return FALSE; ! } else { ! return TRUE; } } *************** *** 460,517 **** getReturnAddress( FILE *orders ) { ! char *isRead; ! char *c; ! ! for ( isRead = fgets( lineBuffer, LINE_BUFFER_SIZE, orders ); ! isRead; isRead = fgets( lineBuffer, LINE_BUFFER_SIZE, orders ) ) { ! /* WIN32 */ ! if ( noCaseStrncmp( string_mail_to, lineBuffer, 3 ) == 0 ) ! break; ! } ! assert( isRead != NULL ); ! for ( c = lineBuffer; *c; c++ ) { ! if ( *c == '\n' ) ! *c = '\0'; ! } ! ! return strdup( lineBuffer + 3 ); } ! void gmNotify(char* subject, char* filename, game* aGame) { ! envelope* env; ! env = createEnvelope(); ! if (aGame == NULL) { ! char buffer[4096]; ! FILE* tmpFP; ! aGame = (game*)malloc(sizeof(game)); ! ! loadNGConfig(aGame); ! if (aGame->serverOptions.GMemail == NULL) { ! fprintf(stderr, "**ERROR** Could not load game or config in " ! "gmNotify!!!\n"); ! fprintf(stderr, "This is the message that was trying to be " ! "delivered:\n"); ! fprintf(stderr, "Subject: %s\n", subject); ! tmpFP = fopen(filename, "r"); ! while (fgets(buffer, 4096, tmpFP) != NULL) ! fprintf(stderr, "%s", buffer); ! fclose(tmpFP); ! return; ! } ! } ! ! env->to = strdup(aGame->serverOptions.GMemail); ! env->from = strdup(aGame->serverOptions.SERVERemail); ! env->replyto = strdup(aGame->serverOptions.ReplyTo); ! env->subject = strdup(subject); ! eMail(aGame, env, filename); ! destroyEnvelope(env); ! ! return; } --- 462,521 ---- getReturnAddress( FILE *orders ) { ! char *isRead; ! char *c; ! ! for ( isRead = fgets( lineBuffer, LINE_BUFFER_SIZE, orders ); ! isRead; isRead = fgets( lineBuffer, LINE_BUFFER_SIZE, orders ) ) { ! /* WIN32 */ ! if ( noCaseStrncmp( string_mail_to, lineBuffer, 3 ) == 0 ) ! break; ! } ! assert( isRead != NULL ); ! for ( c = lineBuffer; *c; c++ ) { ! if ( *c == '\n' ) ! *c = '\0'; ! } ! ! return strdup( lineBuffer + 3 ); } ! void ! gmNotify( char *subject, char *filename, game *aGame ) ! { ! envelope *env; ! env = createEnvelope( ); ! if ( aGame == NULL ) { ! char buffer[4096]; ! FILE *tmpFP; ! aGame = ( game * ) malloc( sizeof( game ) ); ! loadNGConfig( aGame ); ! if ( aGame->serverOptions.GMemail == NULL ) { ! fprintf( stderr, "**ERROR** Could not load game or config in " ! "gmNotify!!!\n" ); ! fprintf( stderr, "This is the message that was trying to be " ! "delivered:\n" ); ! fprintf( stderr, "Subject: %s\n", subject ); ! tmpFP = fopen( filename, "r" ); ! while ( fgets( buffer, 4096, tmpFP ) != NULL ) ! fprintf( stderr, "%s", buffer ); ! fclose( tmpFP ); ! return; ! } ! } ! env->to = strdup( aGame->serverOptions.GMemail ); ! env->from = strdup( aGame->serverOptions.SERVERemail ); ! env->replyto = strdup( aGame->serverOptions.ReplyTo ); ! env->subject = strdup( subject ); ! ! eMail( aGame, env, filename ); ! ! destroyEnvelope( env ); ! ! return; } Index: util.c =================================================================== RCS file: /cvsroot/galaxyng/NG/lib/util.c,v retrieving revision 1.8 retrieving revision 1.8.2.1 diff -C2 -d -r1.8 -r1.8.2.1 *** util.c 19 Mar 2006 22:04:50 -0000 1.8 --- util.c 22 Jun 2007 22:28:39 -0000 1.8.2.1 *************** *** 52,66 **** */ ! FILE * ! Fopen(char *filename, char *mode) { ! FILE *f; ! f = fopen(filename, mode); ! if (f == 0) { ! fprintf(stderr, "Can't open file %s in mode %s\n", filename, mode); [...2112 lines suppressed...] ! rewind( inMail ); ! /* read all the header stuff which only goes until the first blank line */ ! while ( fgets( buffer, sizeof( char ) * 4096, inMail ) ) { ! if ( buffer[0] == '\n' ) ! break; ! } ! /* now copy everything up to the (optional) #end */ ! while ( fgets( buffer, sizeof( char ) * 4096, inMail ) ) { ! if ( noCaseStrncmp( buffer, "#end", 4 ) == 0 ) { ! fprintf( outMail, "%s", buffer ); ! break; ! } ! fprintf( outMail, "%s", buffer ); } ! return; } Index: randomize.c =================================================================== RCS file: /cvsroot/galaxyng/NG/lib/randomize.c,v retrieving revision 1.6 retrieving revision 1.6.2.1 diff -C2 -d -r1.6 -r1.6.2.1 *** randomize.c 19 Jun 2007 08:00:10 -0000 1.6 --- randomize.c 22 Jun 2007 22:28:38 -0000 1.6.2.1 *************** *** 11,70 **** #if 0 void ! randomizePlayers(game *aGame) { ! player *randList = NULL; ! player *curPlayer; ! player *randPlayer = NULL; ! int unlinkedPlayers; ! int nbrPlayers; ! int usedPlayers[1024]; ! memset((void*)usedPlayers, 0, sizeof(int)*1024); ! curPlayer = aGame->players; ! unlinkedPlayers = nbrPlayers = numberOfElements(aGame->players);; ! while(curPlayer != NULL) { ! curPlayer->randNext = NULL; ! curPlayer = curPlayer->next; ! } ! while (unlinkedPlayers > 0) { ! int idx = frand3(nbrPlayers); ! if (usedPlayers[idx] != 0) ! continue; ! usedPlayers[idx] = 1; ! curPlayer = aGame->players; ! while (idx--) { ! curPlayer = curPlayer->next; ! } ! /* first one chosen must be the root */ ! if (randPlayer == NULL) { ! randList = randPlayer = curPlayer; ! unlinkedPlayers--; ! } ! else { ! randPlayer->randNext = curPlayer; ! randPlayer = randPlayer->randNext; ! unlinkedPlayers--; } - } ! plog(LFULL, "Randomized players: "); ! for (randPlayer = randList; randPlayer; randPlayer = randPlayer->randNext) ! plog(LFULL, "%s / ", randPlayer->name); ! plog(LFULL, "\n"); ! aGame->randPlayers = randList; ! return; } --- 11,70 ---- #if 0 void ! randomizePlayers( game *aGame ) { ! player *randList = NULL; ! player *curPlayer; ! player *randPlayer = NULL; ! int unlinkedPlayers; ! int nbrPlayers; ! int usedPlayers[1024]; ! memset( ( void * ) usedPlayers, 0, sizeof( int ) * 1024 ); ! curPlayer = aGame->players; ! unlinkedPlayers = nbrPlayers = numberOfElements( aGame->players );; ! while ( curPlayer != NULL ) { ! curPlayer->randNext = NULL; ! curPlayer = curPlayer->next; ! } ! while ( unlinkedPlayers > 0 ) { ! int idx = frand3( nbrPlayers ); ! if ( usedPlayers[idx] != 0 ) ! continue; ! usedPlayers[idx] = 1; ! curPlayer = aGame->players; ! while ( idx-- ) { ! curPlayer = curPlayer->next; ! } ! /* first one chosen must be the root */ ! if ( randPlayer == NULL ) { ! randList = randPlayer = curPlayer; ! unlinkedPlayers--; ! } else { ! randPlayer->randNext = curPlayer; ! randPlayer = randPlayer->randNext; ! unlinkedPlayers--; ! } } ! plog( LFULL, "Randomized players: " ); ! for ( randPlayer = randList; randPlayer; ! randPlayer = randPlayer->randNext ) ! plog( LFULL, "%s / ", randPlayer->name ); ! plog( LFULL, "\n" ); ! aGame->randPlayers = randList; ! return; } *************** *** 76,132 **** planet * ! randomizePlanets(game *aGame) { ! planet *randList = NULL; ! planet *curPlanet; ! planet *randPlanet = NULL; ! int unlinkedPlanets; ! int nbrPlanets; ! int *usedPlanets = NULL; ! nbrPlanets = numberOfElements(aGame->planets); ! if (usedPlanets == 0) { ! usedPlanets = (int*)malloc(sizeof(int) * nbrPlanets); ! } ! memset((void*)usedPlanets, 0, sizeof(int)*nbrPlanets); ! curPlanet = aGame->planets; ! unlinkedPlanets = nbrPlanets; ! while(curPlanet != NULL) { ! curPlanet->randNext = NULL; ! curPlanet = curPlanet->next; ! } ! while (unlinkedPlanets > 0) { ! int idx = frand3(nbrPlanets); ! if (usedPlanets[idx] != 0) ! continue; ! usedPlanets[idx] = 1; ! curPlanet = aGame->planets; ! while (idx--) { ! curPlanet = curPlanet->next; ! } ! /* first one chosen must be the root */ ! if (randPlanet == NULL) { ! randList = randPlanet = curPlanet; ! unlinkedPlanets--; ! } ! else { ! randPlanet->randNext = curPlanet; ! randPlanet = randPlanet->randNext; ! unlinkedPlanets--; } - } ! return randList; } --- 76,131 ---- planet * ! randomizePlanets( game *aGame ) { ! planet *randList = NULL; ! planet *curPlanet; ! planet *randPlanet = NULL; ! int unlinkedPlanets; ! int nbrPlanets; ! int *usedPlanets = NULL; ! nbrPlanets = numberOfElements( aGame->planets ); ! if ( usedPlanets == 0 ) { ! usedPlanets = ( int * ) malloc( sizeof( int ) * nbrPlanets ); ! } ! memset( ( void * ) usedPlanets, 0, sizeof( int ) * nbrPlanets ); ! curPlanet = aGame->planets; ! unlinkedPlanets = nbrPlanets; ! while ( curPlanet != NULL ) { ! curPlanet->randNext = NULL; ! curPlanet = curPlanet->next; ! } ! while ( unlinkedPlanets > 0 ) { ! int idx = frand3( nbrPlanets ); ! if ( usedPlanets[idx] != 0 ) ! continue; ! usedPlanets[idx] = 1; ! curPlanet = aGame->planets; ! ... [truncated message content] |
Update of /cvsroot/galaxyng/NG/include In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv21295 Modified Files: Tag: Refactor_Baseline avl.h battle.h cookies.h create.h galaxy.h galaxyng.h influence.h list.h loadgame.h logging.h mail.h phase.h process.h report.h report_m.h report_xml.h savegame.h selftest.h strutl.h util.h Log Message: removed dead code. Index: influence.h =================================================================== RCS file: /cvsroot/galaxyng/NG/include/influence.h,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -C2 -d -r1.5 -r1.5.2.1 *** influence.h 6 Feb 2004 18:01:29 -0000 1.5 --- influence.h 22 Jun 2007 22:26:50 -0000 1.5.2.1 *************** *** 10,17 **** #include <avl.h> ! enum map_type { AllMaps = -1, ! FirstMap=0, ! EffIndMap=0, ShipAttMap, ShipDefMap, --- 10,18 ---- #include <avl.h> ! enum map_type ! { AllMaps = -1, ! FirstMap = 0, ! EffIndMap = 0, ShipAttMap, ShipDefMap, Index: savegame.h =================================================================== RCS file: /cvsroot/galaxyng/NG/include/savegame.h,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -C2 -d -r1.4 -r1.4.2.1 *** savegame.h 24 Sep 2003 19:34:21 -0000 1.4 --- savegame.h 22 Jun 2007 22:26:52 -0000 1.4.2.1 *************** *** 7,18 **** #if defined(DRAW_INFLUENCE_MAP) ! void draw_maps(game* aGame); #endif ! void writeString(char *s); ! void writeFloat(double f); ! void writeInt(int i); ! void writeLong(long l); ! void savegame(game *aGame); ! #endif /* GNG_SAVEGAME_H */ --- 7,18 ---- #if defined(DRAW_INFLUENCE_MAP) ! void draw_maps( game *aGame ); #endif ! void writeString( char *s ); ! void writeFloat( double f ); ! void writeInt( int i ); ! void writeLong( long l ); ! void savegame( game *aGame ); ! #endif /* GNG_SAVEGAME_H */ Index: cookies.h =================================================================== RCS file: /cvsroot/galaxyng/NG/include/cookies.h,v retrieving revision 1.7 retrieving revision 1.7.2.1 diff -C2 -d -r1.7 -r1.7.2.1 *** cookies.h 6 Sep 2004 12:03:39 -0000 1.7 --- cookies.h 22 Jun 2007 22:26:50 -0000 1.7.2.1 *************** *** 38,43 **** { printf("validateStruct Failed in line %d of %s\n", __LINE__ , __FILE__);exit(100); } ; ! void* allocStructF(unsigned int n, long cookie); #endif - --- 38,42 ---- { printf("validateStruct Failed in line %d of %s\n", __LINE__ , __FILE__);exit(100); } ; ! void *allocStructF( unsigned int n, long cookie ); #endif Index: avl.h =================================================================== RCS file: /cvsroot/galaxyng/NG/include/avl.h,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -C2 -d -r1.1 -r1.1.2.1 *** avl.h 31 Jul 2003 18:21:01 -0000 1.1 --- avl.h 22 Jun 2007 22:26:49 -0000 1.1.2.1 *************** *** 22,28 **** typedef struct avl { ! struct avl* left; ! struct avl* right; ! signed char balance; } avl; --- 22,28 ---- typedef struct avl { ! struct avl *left; ! struct avl *right; ! signed char balance; } avl; *************** *** 30,35 **** typedef struct avl_tree { ! avl* root; ! int(*compar)(void* a,void* b); } avl_tree; --- 30,35 ---- typedef struct avl_tree { ! avl *root; ! int ( *compar ) ( void *a, void *b ); } avl_tree; *************** *** 41,45 **** * Warning: do not insert elements already present */ ! int avl_insert(avl_tree* t,avl* a); /* Remove an element a from the AVL tree t --- 41,45 ---- * Warning: do not insert elements already present */ ! int avl_insert( avl_tree * t, avl * a ); /* Remove an element a from the AVL tree t *************** *** 48,57 **** * returns 0 as if it had been removed succesfully. */ ! int avl_remove(avl_tree* t, avl* a); /* Remove the root of the AVL tree t * Warning: dumps core if t is empty */ ! int avl_removeroot(avl_tree* t); /* Iterate through elements in t from a range between a and b (inclusive) --- 48,57 ---- * returns 0 as if it had been removed succesfully. */ ! int avl_remove( avl_tree * t, avl * a ); /* Remove the root of the AVL tree t * Warning: dumps core if t is empty */ ! int avl_removeroot( avl_tree * t ); /* Iterate through elements in t from a range between a and b (inclusive) *************** *** 60,64 **** * Warning: a<=b must hold */ ! int avl_range(avl_tree* t,avl* a,avl* b,int(*iter)(avl* a)); /* Iterate through elements in t equal to a --- 60,64 ---- * Warning: a<=b must hold */ ! int avl_range( avl_tree * t, avl * a, avl * b, int ( *iter ) ( avl * a ) ); /* Iterate through elements in t equal to a *************** *** 66,70 **** * returns the last value returned by iterator or 0 if there were no calls */ ! int avl_search(avl_tree* t, avl* a,int(*iter)(avl* a)); #endif /* avl.h */ --- 66,70 ---- * returns the last value returned by iterator or 0 if there were no calls */ ! int avl_search( avl_tree * t, avl * a, int ( *iter ) ( avl * a ) ); #endif /* avl.h */ Index: phase.h =================================================================== RCS file: /cvsroot/galaxyng/NG/include/phase.h,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** phase.h 31 Jul 2003 18:39:06 -0000 1.2 --- phase.h 22 Jun 2007 22:26:51 -0000 1.2.2.1 *************** *** 8,43 **** /* void giveposition(void); */ ! void convertcap(planet *p); ! void unloadcap(planet *p, double x); ! void unloadcol(planet *p, double x, player *P); ! void unloadgroup(group *g, player *P, double amount); ! int kill(group *attack, group *target); ! int mustBomb(player *P, group *g); ! player *determineOwnership(game *aGame, planet *targetPlanet, ! player *aPlayer); ! void bombPlanet(game *aGame, planet *p); ! void bombphase(game *aGame); ! void joinphase(game *aGame); ! void loadphase(game *aGame); ! void interceptphase(game *aGame); ! void fleetphase(game *aGame); ! void movephase(game *aGame); ! void unloadphase(game *aGame); ! void producephase(game *aGame); ! void produceShip(planet *aPlanet, double industry); ! void produceMatCap(planet *aPlanet, double industry); ! void produceTechnology(planet *aPlanet, double industry); ! void producePopulation(planet *aPlanet); ! void sortphase(game *aGame); ! double ftrunc2(double x); ! void cktech(group *g); ! int nametocargotype(char *s); ! #endif /* GNG_PHASE_H */ --- 8,42 ---- /* void giveposition(void); */ ! void convertcap( planet *p ); ! void unloadcap( planet *p, double x ); ! void unloadcol( planet *p, double x, player *P ); ! void unloadgroup( group *g, player *P, double amount ); ! int mustBomb( player *P, group *g ); ! player *determineOwnership( game *aGame, planet *targetPlanet, ! player *aPlayer ); ! void bombPlanet( game *aGame, planet *p ); ! void bombphase( game *aGame ); ! void joinphase( game *aGame ); ! void loadphase( game *aGame ); ! void interceptphase( game *aGame ); ! void fleetphase( game *aGame ); ! void movephase( game *aGame ); ! void unloadphase( game *aGame ); ! void producephase( game *aGame ); ! void produceShip( planet *aPlanet, double industry ); ! void produceMatCap( planet *aPlanet, double industry ); ! void produceTechnology( planet *aPlanet, double industry ); ! void producePopulation( planet *aPlanet ); ! void sortphase( game *aGame ); ! double ftrunc2( double x ); ! void cktech( group *g ); ! int nametocargotype( char *s ); ! #endif /* GNG_PHASE_H */ Index: mail.h =================================================================== RCS file: /cvsroot/galaxyng/NG/include/mail.h,v retrieving revision 1.11 retrieving revision 1.11.2.1 diff -C2 -d -r1.11 -r1.11.2.1 *** mail.h 15 Oct 2004 14:03:33 -0000 1.11 --- mail.h 22 Jun 2007 22:26:51 -0000 1.11.2.1 *************** *** 8,12 **** #include <stdio.h> #include <stdarg.h> ! #include <TCHAR.H> #endif --- 8,12 ---- #include <stdio.h> #include <stdarg.h> ! #include <TCHAR.H> #endif *************** *** 19,35 **** */ ! typedef struct envelope { ! int compress; /* Compress the body before sending */ ! char* to; /* destination */ ! char* from; /* Who sent it */ ! char* subject; ! char* replyto; ! char* cc; ! char* bcc; ! char* contentType; ! char* contentEncoding; ! char* contentDescription; ! char* from_address; ! char* from_name; } envelope; --- 19,36 ---- */ ! typedef struct envelope ! { ! int compress; /* Compress the body before sending */ ! char *to; /* destination */ ! char *from; /* Who sent it */ ! char *subject; ! char *replyto; ! char *cc; ! char *bcc; ! char *contentType; ! char *contentEncoding; ! char *contentDescription; ! char *from_address; ! char *from_name; } envelope; *************** *** 42,73 **** */ ! enum {MAILHEADER_TO = 1, ! MAILHEADER_FROM, ! MAILHEADER_SUBJECT, ! MAILHEADER_REPLYTO, ! MAILHEADER_CC, ! MAILHEADER_BCC, ! MAILHEADER_CONTENTTYPE, ! MAILHEADER_CONTENTENCODING, ! MAILHEADER_CONTENTDESCRIPTION }; /******/ ! void createMailToAllHeader(game *aGame); ! envelope* createEnvelope(void); ! envelope* readEnvelope(FILE* fp); ! void destroyEnvelope(envelope *e); ! void setHeader(envelope *e, int headerType, char *format, ...); ! int eMail(game *aGame, envelope *e, char *fileName); ! char* getReturnAddress(FILE * orders); ! void addMimeHeader(FILE *mailFile); ! void addMimeText(FILE *mailFile); ! void addMimeZip(FILE *mailFile); ! void addMimeEnd(FILE *mailFile); ! int appendToMail(char *fileName, FILE *mailFile); ! void gmNotify(char* subject, char* filename, game* aGame); ! #endif /* GNG_MAIL_H */ --- 43,75 ---- */ ! enum ! { MAILHEADER_TO = 1, ! MAILHEADER_FROM, ! MAILHEADER_SUBJECT, ! MAILHEADER_REPLYTO, ! MAILHEADER_CC, ! MAILHEADER_BCC, ! MAILHEADER_CONTENTTYPE, ! MAILHEADER_CONTENTENCODING, ! MAILHEADER_CONTENTDESCRIPTION }; /******/ ! void createMailToAllHeader( game *aGame ); ! envelope *createEnvelope( void ); ! envelope *readEnvelope( FILE *fp ); ! void destroyEnvelope( envelope *e ); ! void setHeader( envelope *e, int headerType, char *format, ... ); ! int eMail( game *aGame, envelope *e, char *fileName ); ! char *getReturnAddress( FILE *orders ); ! void addMimeHeader( FILE *mailFile ); ! void addMimeText( FILE *mailFile ); ! void addMimeZip( FILE *mailFile ); ! void addMimeEnd( FILE *mailFile ); ! int appendToMail( char *fileName, FILE *mailFile ); ! void gmNotify( char *subject, char *filename, game *aGame ); ! #endif /* GNG_MAIL_H */ Index: galaxyng.h =================================================================== RCS file: /cvsroot/galaxyng/NG/include/galaxyng.h,v retrieving revision 1.10 retrieving revision 1.10.2.1 diff -C2 -d -r1.10 -r1.10.2.1 *** galaxyng.h 22 Jan 2005 15:34:25 -0000 1.10 --- galaxyng.h 22 Jun 2007 22:26:50 -0000 1.10.2.1 *************** *** 29,48 **** void SetDirectoryVariables( void ); - int CMD_immediate(int argc, char** argv); int CMD_create( int argc, char **argv ); ! int CMD_mail0( int argc, char **argv, int kind ); ! int CMD_run( int argc, char **argv, int kind ); ! int CMD_webcheck( int argc, char **argv, int kind ); ! int CMD_check( int argc, char **argv, int kind ); ! #if 0 ! int CMD_checkFile( int argc, char **argv, int kind ); ! #endif int CMD_report( int argc, char **argv ); - int CMD_webreport( int argc, char **argv ); int CMD_score( int argc, char **argv ); - int CMD_graph( int argc, char **argv ); int CMD_dump( int argc, char **argv, int kind ); int CMD_test( int argc, char **argv ); - int CMD_relay( int argc, char **argv ); int CMD_template( int argc, char **argv ); int CMD_selftest( ); --- 29,40 ---- void SetDirectoryVariables( void ); int CMD_create( int argc, char **argv ); ! int CMD_mail0( int argc, char **argv ); ! int CMD_run( int argc, char **argv ); ! int CMD_check( int argc, char **argv ); int CMD_report( int argc, char **argv ); int CMD_score( int argc, char **argv ); int CMD_dump( int argc, char **argv, int kind ); int CMD_test( int argc, char **argv ); int CMD_template( int argc, char **argv ); int CMD_selftest( ); *************** *** 52,59 **** #endif int checkTime( game *aGame ); ! int relayMessage(game *aGame, envelope *anEnvelope, char *nationName, ! player *from, emailList *to ); ! int CMD_ordersdue(int argc, char** argv); ! int CMD_clean(int argc, char** argv); ! #endif /* GNG_GALAXYNG_H */ --- 44,48 ---- #endif int checkTime( game *aGame ); ! int CMD_clean( int argc, char **argv ); ! #endif /* GNG_GALAXYNG_H */ Index: strutl.h =================================================================== RCS file: /cvsroot/galaxyng/NG/include/strutl.h,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -C2 -d -r1.4 -r1.4.2.1 *** strutl.h 18 Jun 2007 21:39:06 -0000 1.4 --- strutl.h 22 Jun 2007 22:26:52 -0000 1.4.2.1 *************** *** 24,43 **** */ ! typedef struct strlist { ! struct strlist *next; ! long cookie; ! char *str; } strlist; /********/ ! char* getstr(char* s); ! strlist* makestrlist(char* ns); ! void freestrlist(strlist* s); ! void dumpstrlist(strlist* aStrlist); ! int noCaseStrncmp(const char *s, const char *t, int n); ! int noCaseStrcmp(const char *s, const char *t); ! char* strlwr(char* str); #endif - --- 24,43 ---- */ ! typedef struct strlist ! { ! struct strlist *next; ! long cookie; ! char *str; } strlist; /********/ ! char *getstr( char *s ); ! strlist *makestrlist( char *ns ); ! void freestrlist( strlist *s ); ! void dumpstrlist( strlist *aStrlist ); ! int noCaseStrncmp( const char *s, const char *t, int n ); ! int noCaseStrcmp( const char *s, const char *t ); ! char *strlwr( char *str ); #endif Index: report.h =================================================================== RCS file: /cvsroot/galaxyng/NG/include/report.h,v retrieving revision 1.7 retrieving revision 1.7.2.1 diff -C2 -d -r1.7 -r1.7.2.1 *** report.h 6 Sep 2004 12:03:39 -0000 1.7 --- report.h 22 Jun 2007 22:26:51 -0000 1.7.2.1 *************** *** 41,49 **** */ ! typedef struct fielddef { ! int fieldSizes[MAXNOFIELDS]; ! int fieldNumber; ! int format; ! FILE *destination; } fielddef; --- 41,50 ---- */ ! typedef struct fielddef ! { ! int fieldSizes[MAXNOFIELDS]; ! int fieldNumber; ! int format; ! FILE *destination; } fielddef; *************** *** 55,213 **** #define G_MODE_ALIEN 2 ! game *createDummyGame(void); ! ! void highScoreList(game *aGame); ! void mailGMReport(game *aGame, char *gameName); ! void createGMReport(game *aGame, char *gameName, ! FILE * gmreport); ! int mailTurnReport(game *aGame, player *aPlayer, long kind); ! void saveTurnReport(game *aGame, player *aPlayer, long kind); ! void createTurnReport(game *aGame, player *aPlayer, ! FILE * report, long kind); ! void createHeader(game *aGame, player *aPlayer, ! FILE * reportfile); ! void appendToFile(char *fileName, FILE * report); ! void report(game *aGame, player *P, FILE * report); ! void score(game *g1, game *g2, int html, FILE * dest); ! void rateRaces(player *playerList); ! void storeLength(fielddef *fields, int length); ! void formatReset(fielddef *fields); ! void formatString(char *s, fielddef *fields); ! void formatStringCenter(char *s, fielddef *fields); ! void formatStringMode(char *s, fielddef *fields, int mode); ! void formatFloat(double g, fielddef *fields); ! void formatInteger(int i, fielddef *fields); ! void GformatInteger(int i, fielddef *fields); ! void BformatInteger(int i, fielddef *fields, char *form); ! void formatReturn(fielddef *fields); ! void formatPrint(fielddef *fields); ! void formatLabels(char *labels, char *align, fielddef *fields); ! void dumpItem(fielddef *fields, int mode); ! int visibleShipTypes(game *aGame, player *P2, player *P); ! int canseeBombing(game *aGame, player *P); ! void formatChar(char c, fielddef *fields, int mode); ! void reportPlanet(planet *p, fielddef *fields); ! void GreportPlanet(planet *planets, planet *p, ! fielddef *fields); ! void reportProduction(planet *p, fielddef *fields); ! void GreportProduction(planet *planets, planet *p, ! fielddef *fields); ! void reportGroup(group *g, int n, fielddef *fields, int mode); ! void GreportGroup(planet *planets, player *P, group *g, int n, ! fielddef *fields, int mode, int phase); ! void reportMap(game *aGame, player *P, fielddef *fields); ! void reportMap_gnuplot(game *aGame, player *P, ! fielddef *fields); ! void reportGlobalMessages(strlist *messages, fielddef *fields); ! void reportMessages(player *P, fielddef *fields); ! void reportOrders(player *P, fielddef *fields); ! void reportMistakes(player *P, fielddef *fields); ! void reportLastOrders(player *players, fielddef *fields); ! void reportStatus(player *players, player *P, fielddef *fields); ! void reportYourShipTypes(player *P, fielddef *fields); ! void reportShipTypes(game *aGame, player *P, fielddef *fields); ! void reportShipType(shiptype *t, fielddef *fields); ! void GreportShipType(shiptype *t, fielddef *fields); ! void reportBattles(game *aGame, player *P, fielddef *fields); ! void reportBombings(game *aGame, player *P, fielddef *fields); ! void reportIncoming(game *aGame, player *P, fielddef *fields); ! void reportYourPlanets(planet *planets, player *P, ! fielddef *fields); ! void reportProdTable(planet *planets, player *P, ! fielddef *fields); ! void reportRoutes(planet *planets, player *P, fielddef *fields); ! void reportPlanetsSeen(game *aGame, player *P, ! fielddef *fields); ! void reportUnidentifiedPlanets(planet *planets, player *P, ! fielddef *fields); ! void reportUninhabitedPlanets(planet *planets, player *P, ! fielddef *fields); ! void reportYourGroups(planet *planets, player *P, ! fielddef *fields); ! void reportFleets(player *P, fielddef *fields); ! void GreportFleets(planet *planets, player *P, ! fielddef *fields); ! void reportGroupsSeen(game *aGame, player *P, fielddef *fields); ! void reportGameOptions(game *aGame, fielddef *fields); ! void reportOptions(game *aGame, player *P, fielddef *fields); ! void tagVisiblePlanets(planet *planets, player *P); ! void yourPlanetsForecast(planet *planets, player *P, ! fielddef *fields); ! void yourStatusForecast(planet *planets, player *P, ! fielddef *fields); ! void reportHall(game *aGame, fielddef *fields); ! void reportTeam(game *aGame, fielddef *fields, int team); ! void reportPlayers(player *players, fielddef *fields); ! void reportRaceProduction(player *players, fielddef *fields); ! void reportGMBombings(game *aGame, fielddef *fields); ! void scorePercent(game *g1, fielddef *fields); --- 56,199 ---- #define G_MODE_ALIEN 2 ! game *createDummyGame( void ); ! void highScoreList( game *aGame ); ! void saveGMReport( game *aGame, char *gameName ); ! void createGMReport( game *aGame, char *gameName, FILE* gmreport ); ! void saveTurnReport( game *aGame, player *aPlayer, long kind ); ! void createTurnReport( game *aGame, player *aPlayer, ! FILE *report, long kind ); ! void createHeader( game *aGame, player *aPlayer, FILE *reportfile ); ! void appendToFile( char *fileName, FILE *report ); ! void report( game *aGame, player *P, FILE *report ); ! void score( game *g1, game *g2, int html, FILE *dest ); ! void rateRaces( player *playerList ); ! void storeLength( fielddef *fields, int length ); ! void formatReset( fielddef *fields ); ! void formatString( char *s, fielddef *fields ); ! void formatStringCenter( char *s, fielddef *fields ); ! void formatStringMode( char *s, fielddef *fields, int mode ); ! void formatFloat( double g, fielddef *fields ); ! void formatInteger( int i, fielddef *fields ); ! void GformatInteger( int i, fielddef *fields ); ! void BformatInteger( int i, fielddef *fields, char *form ); ! void formatReturn( fielddef *fields ); ! void formatPrint( fielddef *fields ); ! void formatLabels( char *labels, char *align, fielddef *fields ); ! void dumpItem( fielddef *fields, int mode ); ! int visibleShipTypes( game *aGame, player *P2, player *P ); ! int canseeBombing( game *aGame, player *P ); ! void formatChar( char c, fielddef *fields, int mode ); ! void reportPlanet( planet *p, fielddef *fields ); ! void GreportPlanet( planet *planets, planet *p, fielddef *fields ); ! void reportProduction( planet *p, fielddef *fields ); ! void GreportProduction( planet *planets, planet *p, fielddef *fields ); ! void reportGroup( group *g, int n, fielddef *fields, int mode ); ! void GreportGroup( planet *planets, player *P, group *g, int n, ! fielddef *fields, int mode, int phase ); ! void reportMap( game *aGame, player *P, fielddef *fields ); ! void reportMap_gnuplot( game *aGame, player *P, fielddef *fields ); ! void reportGlobalMessages( strlist *messages, fielddef *fields ); ! void reportMessages( player *P, fielddef *fields ); ! void reportOrders( player *P, fielddef *fields ); ! void reportMistakes( player *P, fielddef *fields ); ! void reportLastOrders( player *players, fielddef *fields ); ! void reportStatus( player *players, player *P, fielddef *fields ); ! void reportYourShipTypes( player *P, fielddef *fields ); ! void reportShipTypes( game *aGame, player *P, fielddef *fields ); ! void reportShipType( shiptype *t, fielddef *fields ); ! void GreportShipType( shiptype *t, fielddef *fields ); ! void reportBattles( game *aGame, player *P, fielddef *fields ); ! void reportBombings( game *aGame, player *P, fielddef *fields ); ! void reportIncoming( game *aGame, player *P, fielddef *fields ); ! void reportYourPlanets( planet *planets, player *P, fielddef *fields ); ! void reportProdTable( planet *planets, player *P, fielddef *fields ); ! void reportRoutes( planet *planets, player *P, fielddef *fields ); ! void reportPlanetsSeen( game *aGame, player *P, fielddef *fields ); ! void reportUnidentifiedPlanets( planet *planets, player *P, ! fielddef *fields ); ! void reportUninhabitedPlanets( planet *planets, player *P, fielddef *fields ); ! void reportYourGroups( planet *planets, player *P, fielddef *fields ); ! void reportFleets( player *P, fielddef *fields ); ! void GreportFleets( planet *planets, player *P, fielddef *fields ); ! void reportGroupsSeen( game *aGame, player *P, fielddef *fields ); ! void reportGameOptions( game *aGame, fielddef *fields ); ! void reportOptions( game *aGame, player *P, fielddef *fields ); ! void tagVisiblePlanets( planet *planets, player *P ); ! void yourPlanetsForecast( planet *planets, player *P, fielddef *fields ); ! void yourStatusForecast( planet *planets, player *P, fielddef *fields ); ! void reportHall( game *aGame, fielddef *fields ); ! void reportTeam( game *aGame, fielddef *fields, int team ); ! void reportPlayers( player *players, fielddef *fields ); ! void reportRaceProduction( player *players, fielddef *fields ); ! void reportGMBombings( game *aGame, fielddef *fields ); ! void scorePercent( game *g1, fielddef *fields ); *************** *** 216,218 **** #endif ! #endif /* GNG_REPORT_H */ --- 202,204 ---- #endif ! #endif /* GNG_REPORT_H */ Index: list.h =================================================================== RCS file: /cvsroot/galaxyng/NG/include/list.h,v retrieving revision 1.12 retrieving revision 1.12.2.1 diff -C2 -d -r1.12 -r1.12.2.1 *** list.h 21 Jun 2007 21:06:40 -0000 1.12 --- list.h 22 Jun 2007 22:26:50 -0000 1.12.2.1 *************** *** 17,27 **** * * Base pointer First element Second element ! * +--+ +------------+ +------------+ ! * | *-------->| next | *---------->| next | *----------> * +--+ | cookie | | | cookie | | * | name | | | name | | * +------------+ +------------+ * | other data | | other data | ! * * The cookie is used to do sanity checks. Each kind of list * has its own unique cookie. This way we can check if the --- 17,27 ---- * * Base pointer First element Second element ! * +--+ +------------+ +------------+ ! * | *-------->| next | *---------->| next | *----------> * +--+ | cookie | | | cookie | | * | name | | | name | | * +------------+ +------------+ * | other data | | other data | ! * * The cookie is used to do sanity checks. Each kind of list * has its own unique cookie. This way we can check if the *************** *** 31,39 **** */ ! typedef struct list { ! struct list *next; ! struct list *randNext; ! long cookie; ! char *name; } list; --- 31,39 ---- */ ! typedef struct list ! { ! struct list *next; ! long cookie; ! char *name; } list; *************** *** 167,181 **** ! void add2ListF(list **aList, list *anElement); ! void freelist(void *base); ! void addListF(list **aList, list *anElement); ! void insertListF(list **aList, list* anchor, list *anElement); ! list *findElementF(list *aList, char *name); ! void removeListF(list **aList, list *anElement); ! void setNameF(list *anElement, const char *name); ! int numberOfElementsF(list *aList); ! int ptonum(void *base, void *target); ! void *numtop(void *base, int n); ! void dumpList(char* label, list* aList, void* callback(void*)); ! #endif /* GNG_LIST_H */ --- 167,181 ---- ! void add2ListF( list **aList, list *anElement ); ! void freelist( void *base ); ! void addListF( list **aList, list *anElement ); ! void insertListF( list **aList, list *anchor, list *anElement ); ! list *findElementF( list *aList, char *name ); ! void removeListF( list **aList, list *anElement ); ! void setNameF( list *anElement, const char *name ); ! int numberOfElementsF( list *aList ); ! int ptonum( void *base, void *target ); ! void *numtop( void *base, int n ); ! void dumpList( char *label, list *aList, void *callback( void * ) ); ! #endif /* GNG_LIST_H */ Index: galaxy.h =================================================================== RCS file: /cvsroot/galaxyng/NG/include/galaxy.h,v retrieving revision 1.37 retrieving revision 1.37.2.1 diff -C2 -d -r1.37 -r1.37.2.1 *** galaxy.h 18 Jun 2007 21:39:06 -0000 1.37 --- galaxy.h 22 Jun 2007 22:26:50 -0000 1.37.2.1 *************** *** 103,107 **** #define getLine(f) fgets(lineBuffer, LINE_BUFFER_SIZE, f) ! void usage(void); --- 103,107 ---- #define getLine(f) fgets(lineBuffer, LINE_BUFFER_SIZE, f) ! void usage( void ); *************** *** 112,123 **** */ ! enum { ! PR_CAP, ! PR_MAT, ! PR_SHIP, ! PR_DRIVE, ! PR_WEAPONS, ! PR_SHIELDS, ! PR_CARGO }; --- 112,124 ---- */ ! enum ! { ! PR_CAP, ! PR_MAT, ! PR_SHIP, ! PR_DRIVE, ! PR_WEAPONS, ! PR_SHIELDS, ! PR_CARGO }; *************** *** 130,139 **** */ ! enum { ! CG_CAP, ! CG_MAT, ! CG_COL, ! CG_EMPTY, ! MAXCARGO }; --- 131,141 ---- */ ! enum ! { ! CG_CAP, ! CG_MAT, ! CG_COL, ! CG_EMPTY, ! MAXCARGO }; *************** *** 146,160 **** */ ! enum error_type { ! INFO, ! WARNING, ! ERROR }; /*******/ ! typedef struct mapdimensions { ! double x1, y1; ! double x2, y2; } mapdimensions; --- 148,164 ---- */ ! enum error_type ! { ! INFO, ! WARNING, ! ERROR }; /*******/ ! typedef struct mapdimensions ! { ! double x1, y1; ! double x2, y2; } mapdimensions; *************** *** 177,187 **** */ ! typedef struct fleetname { ! /* basic list structure */ ! struct fleetname *next; ! long cookie; ! char *name; ! /* end basic list */ ! double fleetspeed; } fleetname; --- 181,192 ---- */ ! typedef struct fleetname ! { ! /* basic list structure */ ! struct fleetname *next; ! long cookie; ! char *name; ! /* end basic list */ ! double fleetspeed; } fleetname; *************** *** 198,213 **** */ ! typedef struct shiptype { ! /* basic list structure */ ! struct shiptype *next; ! long cookie; ! char *name; ! /* end basic list */ ! double drive; ! int attacks; ! double weapons; ! double shields; ! double cargo; ! int flag; } shiptype; --- 203,219 ---- */ ! typedef struct shiptype ! { ! /* basic list structure */ ! struct shiptype *next; ! long cookie; ! char *name; ! /* end basic list */ ! double drive; ! int attacks; ! double weapons; ! double shields; ! double cargo; ! int flag; } shiptype; *************** *** 244,268 **** */ ! typedef struct planet { ! /* basic list structure */ ! struct planet *next; ! long cookie; ! char *name; ! /* end basic list */ ! player *owner; ! double x, y; ! double size; ! double resources; ! double pop; ! double ind; ! int producing; ! shiptype *producingshiptype; ! double cap; ! double mat; ! double col; ! double inprogress; /* Production spent in the last turns */ ! double spent; ! struct planet *routes[MAXCARGO]; ! long flags; } planet; --- 250,275 ---- */ ! typedef struct planet ! { ! /* basic list structure */ ! struct planet *next; ! long cookie; ! char *name; ! /* end basic list */ ! player *owner; ! double x, y; ! double size; ! double resources; ! double pop; ! double ind; ! int producing; ! shiptype *producingshiptype; ! double cap; ! double mat; ! double col; ! double inprogress; /* Production spent in the last turns */ ! double spent; ! struct planet *routes[MAXCARGO]; ! long flags; } planet; *************** *** 316,345 **** */ ! typedef struct group { ! struct group *next; ! unsigned long cookie; ! char *name; ! int number; ! shiptype *type; ! double drive; ! double weapons; ! double shields; ! double cargo; ! int loadtype; ! double load; ! planet *from; ! planet *where; ! double dist; ! int ships; ! int left; ! long flags; ! fleetname *thefleet; ! double attack; ! double defense; ! int *canshoot; ! int *alive; ! int numberOfAttackers; ! int numberOfAttackersLeft; ! planet *location; } group; --- 323,353 ---- */ ! typedef struct group ! { ! struct group *next; ! unsigned long cookie; ! char *name; ! int number; ! shiptype *type; ! double drive; ! double weapons; ! double shields; ! double cargo; ! int loadtype; ! double load; ! planet *from; ! planet *where; ! double dist; ! int ships; ! int left; ! long flags; ! fleetname *thefleet; ! double attack; ! double defense; ! int *canshoot; ! int *alive; ! int numberOfAttackers; ! int numberOfAttackersLeft; ! planet *location; } group; *************** *** 356,364 **** */ ! typedef struct alliance { ! struct alliance *next; ! long cookie; ! char *name; ! player *who; } alliance; --- 364,373 ---- */ ! typedef struct alliance ! { ! struct alliance *next; ! long cookie; ! char *name; ! player *who; } alliance; *************** *** 375,384 **** */ ! typedef struct participant { ! struct participant *next; ! long cookie; ! char *name; ! player *who; ! group *groups; } participant; --- 384,394 ---- */ ! typedef struct participant ! { ! struct participant *next; ! long cookie; ! char *name; ! player *who; ! group *groups; } participant; *************** *** 394,403 **** */ ! typedef struct shot { ! player *attacker; ! shiptype *atype; ! player *target; ! shiptype *ttype; ! int result; } shot; --- 404,414 ---- */ ! typedef struct shot ! { ! player *attacker; ! shiptype *atype; ! player *target; ! shiptype *ttype; ! int result; } shot; *************** *** 413,420 **** */ ! typedef struct bprotocol { ! long size; /* maximum size */ ! long cur; /* current size */ ! shot *shots; /* Array of shots, grows when needed */ } bprotocol; --- 424,432 ---- */ ! typedef struct bprotocol ! { ! long size; /* maximum size */ ! long cur; /* current size */ ! shot *shots; /* Array of shots, grows when needed */ } bprotocol; *************** *** 432,443 **** */ ! typedef struct battle { ! struct battle *next; ! long cookie; ! char *name; ! planet *where; ! participant *participants; ! bprotocol *protocol; ! int phase; /* Either GF_INBATTLE1 or GF_INBATTLE2 */ } battle; --- 444,456 ---- */ ! typedef struct battle ! { ! struct battle *next; ! long cookie; ! char *name; ! planet *where; ! participant *participants; ! bprotocol *protocol; ! int phase; /* Either GF_INBATTLE1 or GF_INBATTLE2 */ } battle; *************** *** 455,473 **** */ ! typedef struct bombing { ! struct bombing *next; ! long cookie; ! char *name; ! planet *where; ! player *owner; ! double pop; ! double ind; ! int producing; ! shiptype *producingshiptype; ! double cap; ! double mat; ! double col; ! player *who; ! alliance *viewers; } bombing; --- 468,487 ---- */ ! typedef struct bombing ! { ! struct bombing *next; ! long cookie; ! char *name; ! planet *where; ! player *owner; ! double pop; ! double ind; ! int producing; ! shiptype *producingshiptype; ! double cap; ! double mat; ! double col; ! player *who; ! alliance *viewers; } bombing; *************** *** 484,492 **** */ ! typedef struct planet_claim { ! struct planet_claim *next; ! long cookie; ! char *name; ! struct planet *planet_claimed; } planet_claim; --- 498,507 ---- */ ! typedef struct planet_claim ! { ! struct planet_claim *next; ! long cookie; ! char *name; ! struct planet *planet_claimed; } planet_claim; *************** *** 502,508 **** */ ! typedef struct option { ! char *optionName; ! long optionMask; } option; --- 517,524 ---- */ ! typedef struct option ! { ! char *optionName; ! long optionMask; } option; *************** *** 528,567 **** */ ! struct player { ! player *next; ! long cookie; ! char *name; ! char *addr; ! char *pswd; ! int pswdstate; ! double drive; ! double weapons; ! double shields; ! double cargo; ! fleetname *fleetnames; ! shiptype *shiptypes; ! alliance *allies; ! group *groups; ! double mx, my, msize; ! char *realName; /* For in the Hall of Fame */ ! int team; ! int unused3; /* For future expansion */ ! int unused4; /* For future expansion */ ! int unused5; /* For future expansion */ ! double masslost; ! double massproduced; ! int lastorders; ! long flags; ! strlist *orders; ! strlist *messages; ! strlist *mistakes; ! planet_claim *claimed_planets; ! double totPop; /* Cache */ ! double totInd; /* Cache */ ! double totCap; /* Cache */ ! double totMat; /* Cache */ ! double totCol; /* Cache */ ! int numberOfPlanets; /* Cache */ ! int rating; /* Used for the high score list */ }; --- 544,584 ---- */ ! struct player ! { ! player *next; ! long cookie; ! char *name; ! char *addr; ! char *pswd; ! int pswdstate; ! double drive; ! double weapons; ! double shields; ! double cargo; ! fleetname *fleetnames; ! shiptype *shiptypes; ! alliance *allies; ! group *groups; ! double mx, my, msize; ! char *realName; /* For in the Hall of Fame */ ! int team; ! int unused3; /* For future expansion */ ! int unused4; /* For future expansion */ ! int unused5; /* For future expansion */ ! double masslost; ! double massproduced; ! int lastorders; ! long flags; ! strlist *orders; ! strlist *messages; ! strlist *mistakes; ! planet_claim *claimed_planets; ! double totPop; /* Cache */ ! double totInd; /* Cache */ ! double totCap; /* Cache */ ! double totMat; /* Cache */ ! double totCol; /* Cache */ ! int numberOfPlanets; /* Cache */ ! int rating; /* Used for the high score list */ }; *************** *** 615,632 **** */ ! typedef struct server { ! char* sendmail; /* the command to email a file */ ! char* GMemail; /* GM reports go to this address */ ! char* GMname; /* name the email should appear to be from */ ! char* GMpassword; /* GM password, for the relay command */ ! char* SERVERemail; /* Server email */ ! char* SERVERname; /* name the email should appear to be from */ ! char* ReplyTo; /* Server replyto */ ! char* compress; /* the command to compress the body of ! an email */ ! char* encode; /* the command to encode the compressed body */ ! char* fontpath; /* the directory where the fonts are located */ ! char* due; /* this is used for the -due command */ ! char* tick_interval; /* this is used for the -immediate command */ } server; --- 632,650 ---- */ ! typedef struct server ! { ! char *sendmail; /* the command to email a file */ ! char *GMemail; /* GM reports go to this address */ ! char *GMname; /* name the email should appear to be from */ ! char *GMpassword; /* GM password, for the relay command */ ! char *SERVERemail; /* Server email */ ! char *SERVERname; /* name the email should appear to be from */ ! char *ReplyTo; /* Server replyto */ ! char *compress; /* the command to compress the body of ! an email */ ! char *encode; /* the command to encode the compressed body */ ! char *fontpath; /* the directory where the fonts are located */ ! char *due; /* this is used for the -due command */ ! char *tick_interval; /* this is used for the -immediate command */ } server; *************** *** 642,652 **** */ ! typedef struct gameOpt { ! long gameOptions; ! int galactic_peace; ! double initial_drive; ! double initial_weapons; ! double initial_shields; ! double initial_cargo; } gameOpt; --- 660,671 ---- */ ! typedef struct gameOpt ! { ! long gameOptions; ! int galactic_peace; ! double initial_drive; ! double initial_weapons; ! double initial_shields; ! double initial_cargo; } gameOpt; *************** *** 661,691 **** */ ! typedef struct game { ! player *next; ! long cookie; ! char *name; ! server serverOptions; ! gameOpt gameOptions; ! /* the time at which a turn is started, used for sanity check. */ ! char *starttime; ! int turn; ! double galaxysize; /* CB-20010408 */ ! player *players; /* list with races */ ! planet *planets; /* list with planets */ ! battle *battles; /* list with battles */ ! bombing *bombings; /* list with bombings */ ! strlist *messages; /* list with messages */ } game; /*******/ ! typedef struct emailList { ! /* basic list structure */ ! struct emailList* next; ! long cookie; ! char* name; ! /* end basic list */ ! char* addr; ! char* pswd; } emailList; --- 680,712 ---- */ ! typedef struct game ! { ! player *next; ! long cookie; ! char *name; ! server serverOptions; ! gameOpt gameOptions; ! /* the time at which a turn is started, used for sanity check. */ ! char *starttime; ! int turn; ! double galaxysize; /* CB-20010408 */ ! player *players; /* list with races */ ! planet *planets; /* list with planets */ ! battle *battles; /* list with battles */ ! bombing *bombings; /* list with bombings */ ! strlist *messages; /* list with messages */ } game; /*******/ ! typedef struct emailList ! { ! /* basic list structure */ ! struct emailList *next; ! long cookie; ! char *name; ! /* end basic list */ ! char *addr; ! char *pswd; } emailList; *************** *** 715,744 **** ! extern char map[MAPWIDTH][MAPHEIGHT]; ! extern char buf[LINE_BUFFER_SIZE]; ! extern char lineBuffer[2 * LINE_BUFFER_SIZE]; ! extern char* galaxynghome; ! extern char* tempdir; ! extern char* productname[]; ! extern char* string_mail_to; ! extern char* string_mail_subject; ! extern char* string_mail_from; /* used in loadgame.c, should be a parameter */ ! extern FILE *turnFile; extern struct option options[]; ! extern char *vcreate; ! extern char vcid[]; ! extern char *vprocess; ! extern char *vphase; ! extern char *vreport; ! extern char *vbattle; ! extern char *vsavegame; ! extern char *vloadgame; ! extern int nbrProducts; ! void loadNGConfig(game* aGame); ! int spcLockFile(const char* lfpath); ! #endif /* GNG_GALAXY_H */ --- 736,765 ---- ! extern char map[MAPWIDTH][MAPHEIGHT]; ! extern char buf[LINE_BUFFER_SIZE]; ! extern char lineBuffer[2 * LINE_BUFFER_SIZE]; ! extern char *galaxynghome; ! extern char *tempdir; ! extern char *productname[]; ! extern char *string_mail_to; ! extern char *string_mail_subject; ! extern char *string_mail_from; /* used in loadgame.c, should be a parameter */ ! extern FILE *turnFile; extern struct option options[]; ! extern char *vcreate; ! extern char vcid[]; ! extern char *vprocess; ! extern char *vphase; ! extern char *vreport; ! extern char *vbattle; ! extern char *vsavegame; ! extern char *vloadgame; ! extern int nbrProducts; ! void loadNGConfig( game *aGame ); ! int spcLockFile( const char *lfpath ); ! #endif /* GNG_GALAXY_H */ Index: process.h =================================================================== RCS file: /cvsroot/galaxyng/NG/include/process.h,v retrieving revision 1.14 retrieving revision 1.14.2.1 diff -C2 -d -r1.14 -r1.14.2.1 *** process.h 18 Jun 2007 21:39:06 -0000 1.14 --- process.h 22 Jun 2007 22:26:51 -0000 1.14.2.1 *************** *** 31,37 **** typedef struct _orderinfo orderinfo; ! struct _orderinfo { ! char *name; ! void (*func) (game *aGame, player *, strlist **); }; --- 31,38 ---- typedef struct _orderinfo orderinfo; ! struct _orderinfo ! { ! char *name; ! void ( *func ) ( game *aGame, player *, strlist ** ); }; *************** *** 44,60 **** */ ! enum ResCodes { ! RES_OK, /* no error */ ! RES_NO_ORDERS, /* missing orders */ ! RES_ERR_GALAXY, /* no #GALAXY line */ ! RES_NO_GAME, /* can't find the game name */ ! RES_PASSWORD, /* password mismatch */ ! RES_PLAYER, /* player name doesn't exist */ ! RES_TURNRAN, /* orders sent in for a turnt that ran */ ! RES_DESTINATION, /* can't find the race sending email to */ ! RES_NODESTINATION, ! RES_NO_ORDERS_TURN_NBR, /* missing turn number in orders */ ! RES_NO_REPORT_TURN_NBR, /* missing turn number in a report request */ ! RES_DEAD_PLAYER /* tried to relay to a dead player */ }; --- 45,62 ---- */ ! enum ResCodes ! { ! RES_OK, /* no error */ ! RES_NO_ORDERS, /* missing orders */ ! RES_ERR_GALAXY, /* no #GALAXY line */ ! RES_NO_GAME, /* can't find the game name */ ! RES_PASSWORD, /* password mismatch */ ! RES_PLAYER, /* player name doesn't exist */ ! RES_TURNRAN, /* orders sent in for a turnt that ran */ ! RES_DESTINATION, /* can't find the race sending email to */ ! RES_NODESTINATION, ! RES_NO_ORDERS_TURN_NBR, /* missing turn number in orders */ ! RES_NO_REPORT_TURN_NBR, /* missing turn number in a report request */ ! RES_DEAD_PLAYER /* tried to relay to a dead player */ }; *************** *** 66,160 **** /* order functions */ ! void at_order(game *aGame, player *, strlist **); ! void eq_order(game *aGame, player *, strlist **); /* FS ! * ! * * * * ! * * * * ! * * * * * ! * * * * * ! * * * * * ! * * ! * 12/1999 ! * * * * * ! * * */ ! void a_order(game *aGame, player *, strlist **); ! void b_order(game *aGame, player *, strlist **); ! void c_order(game *aGame, player *, strlist **); ! void d_order(game *aGame, player *, strlist **); ! void e_order(game *aGame, player *, strlist **); ! void f_order(game *aGame, player *, strlist **); ! void g_order(game *aGame, player *, strlist **); ! void h_order(game *aGame, player *, strlist **); /* CB-1990923 ! * ! * * * * ! * * * * ! * * * * * ! * * * * ! * * */ ! void i_order(game *aGame, player *, strlist **); ! void j_order(game *aGame, player *, strlist **); /* free k */ ! void l_order(game *aGame, player *, strlist **); ! void m_order(game *aGame, player *, strlist **); ! void n_order(game *aGame, player *, strlist **); ! void o_order(game *aGame, player *, strlist **); ! void p_order(game *aGame, player *, strlist **); ! void q_order(game *aGame, player *, strlist **); ! void r_order(game *aGame, player *, strlist **); ! void s_order(game *aGame, player *, strlist **); ! void t_order(game *aGame, player *, strlist **); ! void u_order(game *aGame, player *, strlist **); ! void v_order(game *aGame, player *, strlist **); ! void w_order(game *aGame, player *, strlist **); ! void x_order(game *aGame, player *, strlist **); ! void y_order(game *aGame, player *, strlist **); ! void z_order(game *aGame, player *, strlist **); ! void mistake(player *P, enum error_type, strlist *s, char *format, ...); ! ! void ! copyOrders(game *aGame, FILE * orders, ! char *raceName, char *password, ! char* final_orders, int theTurnNumber); ! ! int ! areValidOrders(FILE * ordersFile, ! game **aGame, ! char **raceName, char **password, ! char** final_orders, int* theTurnNumber, ! char **galaxyline ); ! ! void ! preComputeGroupData(game *aGame); ! ! void ! removeDeadPlayer(game *aGame); ! int ! getTurnNumber(FILE * orders); ! char *getDestination(char* subject_line); void ! doOrders(game *aGame, ! player *aPlayer, orderinfo *orderInfo, int phase); ! int ! runTurn(game *aGame, char *ordersFileName); #if FS_NEW_FORECAST ! void checkOrders(game *aGame, char *raceName ); #else ! void ! checkOrders(game *aGame, ! char *raceName, FILE * forecast, int kind); #endif void ! generateErrorMessage(int resNumber, ! game *aGame, ! char *raceName, ! int theTurnNumber, FILE * forecast, ! char* galaxyline ); ! #endif /* GNG_PROCESS_H */ --- 68,138 ---- /* order functions */ ! void at_order( game *aGame, player *, strlist ** ); ! void eq_order( game *aGame, player *, strlist ** ); /* FS ! * ! * * * * ! * * * * ! * * * * * ! * * * * * ! * * * * * ! * * ! * 12/1999 ! * * * * * ! * * */ ! void a_order( game *aGame, player *, strlist ** ); ! void b_order( game *aGame, player *, strlist ** ); ! void c_order( game *aGame, player *, strlist ** ); ! void d_order( game *aGame, player *, strlist ** ); ! void e_order( game *aGame, player *, strlist ** ); ! void f_order( game *aGame, player *, strlist ** ); ! void g_order( game *aGame, player *, strlist ** ); ! void h_order( game *aGame, player *, strlist ** ); /* CB-1990923 ! * ! * * * * ! * * * * ! * * * * * ! * * * * ! * * */ ! void i_order( game *aGame, player *, strlist ** ); ! void j_order( game *aGame, player *, strlist ** ); /* free k */ ! void l_order( game *aGame, player *, strlist ** ); ! void m_order( game *aGame, player *, strlist ** ); ! void n_order( game *aGame, player *, strlist ** ); ! void o_order( game *aGame, player *, strlist ** ); ! void p_order( game *aGame, player *, strlist ** ); ! void q_order( game *aGame, player *, strlist ** ); ! void r_order( game *aGame, player *, strlist ** ); ! void s_order( game *aGame, player *, strlist ** ); ! void t_order( game *aGame, player *, strlist ** ); ! void u_order( game *aGame, player *, strlist ** ); ! void v_order( game *aGame, player *, strlist ** ); ! void w_order( game *aGame, player *, strlist ** ); ! void x_order( game *aGame, player *, strlist ** ); ! void y_order( game *aGame, player *, strlist ** ); ! void z_order( game *aGame, player *, strlist ** ); ! void mistake( player *P, enum error_type, strlist *s, char *format, ... ); ! void preComputeGroupData( game *aGame ); ! void removeDeadPlayer( game *aGame ); void ! doOrders( game *aGame, player *aPlayer, orderinfo *orderInfo, int phase ); ! int runTurn( game *aGame, char *ordersFileName ); #if FS_NEW_FORECAST ! void checkOrders( game *aGame, char *raceName ); #else ! void checkOrders( game *aGame, char *raceName, FILE *forecast, int kind ); #endif void ! generateErrorMessage( int resNumber, ! game *aGame, ! char *raceName, ! int theTurnNumber, FILE *forecast, char *galaxyline ); ! #endif /* GNG_PROCESS_H */ Index: report_xml.h =================================================================== RCS file: /cvsroot/galaxyng/NG/include/report_xml.h,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -C2 -d -r1.4 -r1.4.2.1 *** report_xml.h 6 Sep 2004 12:03:39 -0000 1.4 --- report_xml.h 22 Jun 2007 22:26:52 -0000 1.4.2.1 *************** *** 4,32 **** /* Needed for xml report */ ! void report_xml(game* aGame, player* P, FILE* report, int type); ! ! void rMR_XML(void); ! void rGZ_XML(void); ! void rPW_XML(game* aGame, player *P); ! void rMM_XML(game* aGame, player *P, strlist *messages, char *c); ! void rGO_XML(game* aGame); ! void rOP_XML(game* aGame, player *P); ! void rOD_XML(game* aGame, player *P); ! void rMK_XML(game* aGame, player *P); ! void rST_XML(game* aGame, player *P); ! void rSH_XML(game* aGame, player *P); ! void rBT_XML(game* aGame, player *P); ! void rBB_XML(game* aGame, player *P); ! void rGP_XML(group *g, int n, int mode); ! void rMP_XML(game* aGame, player *P); ! void rIC_XML(game* aGame, player *P); ! void rAP_XML(game* aGame, player *P); ! void rPL_XML(planet *p, char *owner); ! void rRT_XML(game* aGame, player *P); ! void rPT_XML(game* aGame, player *P); ! void rGG_XML(game* aGame, player *P); ! void rFL_XML(game* aGame, player *P); ! void rGS_XML(game* aGame, player *P); ! void rPD_XML(planet *p); ! void rEN_XML(void); --- 4,31 ---- /* Needed for xml report */ ! void report_xml( game *aGame, player *P, FILE *report, int type ); + void rMR_XML( void ); + void rGZ_XML( void ); + void rPW_XML( game *aGame, player *P ); + void rMM_XML( game *aGame, player *P, strlist *messages, char *c ); + void rGO_XML( game *aGame ); + void rOP_XML( game *aGame, player *P ); + void rOD_XML( game *aGame, player *P ); + void rMK_XML( game *aGame, player *P ); + void rST_XML( game *aGame, player *P ); + void rSH_XML( game *aGame, player *P ); + void rBT_XML( game *aGame, player *P ); + void rBB_XML( game *aGame, player *P ); + void rGP_XML( group *g, int n, int mode ); + void rMP_XML( game *aGame, player *P ); + void rIC_XML( game *aGame, player *P ); + void rAP_XML( game *aGame, player *P ); + void rPL_XML( planet *p, char *owner ); + void rRT_XML( game *aGame, player *P ); + void rPT_XML( game *aGame, player *P ); + void rGG_XML( game *aGame, player *P ); + void rFL_XML( game *aGame, player *P ); + void rGS_XML( game *aGame, player *P ); + void rPD_XML( planet *p ); + void rEN_XML( void ); Index: battle.h =================================================================== RCS file: /cvsroot/galaxyng/NG/include/battle.h,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** battle.h 31 Jul 2003 18:39:06 -0000 1.2 --- battle.h 22 Jun 2007 22:26:49 -0000 1.2.2.1 *************** *** 19,64 **** */ ! typedef struct batstat { ! struct batstat *next; ! long cookie; ! char *name; ! player *who; ! group *groups; ! double maxAttack; ! double minDefense; ! int numberOfTargets; ! int numberOfAttackers; ! int numberOfAttackersLeft; ! int noEnemies; ! struct batstat **enemies; } batstat; /***** END batstat ******/ ! int isWon(batstat *aBatstat); ! int isDraw(batstat *aBatstat); ! void fightphase(game *aGame, int phase); ! void attack(bprotocol *aProtocol, ! batstat *attackingSide, group *attackingGroup, ! int attackingShip, batstat *targetSide, ! group *targetGroup, int targetShip); ! battle *isBattle(player *players, planet *p); ! int mustBattle(participant *participants); ! int attackersLeft(batstat *aBatstat); ! void resetSides(batstat *aBatstat); ! int canShoot(group *g); ! void dumpBattle(battle *b); ! int shoot(group *attacker, group *defender); ! void allocEnemies(batstat *batstats); ! void doBattle(batstat *batstats,... [truncated message content] |
From: Frans S. <gu...@us...> - 2007-06-22 22:25:32
|
Update of /cvsroot/galaxyng/NG/Source In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv19248 Modified Files: Tag: Refactor_Baseline cmd_check.c cmd_mail0.c cmd_report.c cmd_run.c galaxyng.c phase.c process.c report.c Log Message: Rewrote cmd_check and cmd_report to work from stdin and to stdout. Nothing is emailed anymore. Removed dead code. Compiles under cygwin on windows. Index: cmd_report.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/cmd_report.c,v retrieving revision 1.21.2.1 retrieving revision 1.21.2.2 diff -C2 -d -r1.21.2.1 -r1.21.2.2 *** cmd_report.c 21 Jun 2007 23:02:02 -0000 1.21.2.1 --- cmd_report.c 22 Jun 2007 22:25:28 -0000 1.21.2.2 *************** *** 3,13 **** /****f* CLI/CMD_report * NAME ! * CMD_report -- send a copy of a turn report. * SYNOPSIS ! * ./galaxyng -check < file_with_email * int CMD_report(int argc, char **argv) * FUNCTION ! * Recreate a turn report of a given turn. Send it to the player ! * that requested it. * BUGS * Does not send XML nor machine reports. --- 3,13 ---- /****f* CLI/CMD_report * NAME ! * CMD_report -- create a copy of a turn report. * SYNOPSIS ! * ./galaxyng -report <gamename> <player> <turnnumber> * int CMD_report(int argc, char **argv) * FUNCTION ! * Recreate a turn report of a given turn. ! * Report is send to stdout. * BUGS * Does not send XML nor machine reports. *************** *** 18,162 **** CMD_report( int argc, char **argv ) { ! int result; ! char *logName; - logName = createString( "%s/log/orders_processed.txt", galaxynghome ); openLog( logName, "a" ); free( logName ); plogtime( LBRIEF ); - result = EXIT_FAILURE; - if ( argc >= 2 ) { - char *returnAddress; - char *raceName; - char *password; - char *galaxyline = NULL; - char *final_orders; - int resNumber, theTurnNumber; - game *aGame; - FILE *report; - char *reportName; - envelope *anEnvelope; ! anEnvelope = createEnvelope( ); ! returnAddress = getReturnAddress( stdin ); ! theTurnNumber = getTurnNumber( stdin ); ! plog( LBRIEF, "Report request from %s for turn %d.\n", ! returnAddress, theTurnNumber ); ! raceName = NULL; ! password = NULL; ! final_orders = NULL; ! aGame = NULL; ! resNumber = ! areValidOrders( stdin, &aGame, &raceName, &password, ! &final_orders, &theTurnNumber, &galaxyline ); ! reportName = createString( "%s/temp_report_copy_%d_%s", ! tempdir, theTurnNumber, returnAddress ); ! { ! char *ptr = strrchr( reportName, '/' ) + 1; ! while ( *ptr ) { ! if ( !isalnum( *ptr ) || isspace( *ptr ) ) ! *ptr = '_'; ! ptr++; ! } ! } ! plog( LBRIEF, "Report is in \"%s\"\n", reportName ); ! setHeader( anEnvelope, MAILHEADER_TO, "%s", returnAddress ); ! setHeader( anEnvelope, MAILHEADER_REPLYTO, ! aGame->serverOptions.ReplyTo ); ! anEnvelope->from_name = strdup( aGame->serverOptions.SERVERname ); ! anEnvelope->from_address = strdup( aGame->serverOptions.SERVERemail ); ! report = fopen( reportName, "w" ); ! if ( ( resNumber == RES_TURNRAN ) || ! ( ( resNumber == RES_OK ) && ! ( theTurnNumber == LG_CURRENT_TURN ) ) ) { ! game *aGame2; ! if ( theTurnNumber > 0 ) { ! aGame2 = loadgame( aGame->name, theTurnNumber - 1 ); ! } else if ( theTurnNumber == LG_CURRENT_TURN ) { ! theTurnNumber = aGame->turn; ! aGame2 = loadgame( aGame->name, theTurnNumber - 1 ); ! } else { ! aGame2 = loadgame( aGame->name, 0 ); ! } ! if ( aGame2 ) { ! player *aPlayer; ! int index; ! loadNGConfig( aGame2 ); ! setHeader( anEnvelope, MAILHEADER_SUBJECT, ! "[GNG] %s turn %d report copy for %s", ! aGame->name, theTurnNumber, raceName ); ! if ( theTurnNumber > 0 ) { /* Rerun the turn */ ! char *ordersName; ! ordersName = ! createString( "%s/orders/%s/%d.all", ! galaxynghome, aGame2->name, ! theTurnNumber ); ! runTurn( aGame2, ordersName ); ! free( ordersName ); } - /* Translate the current race name into the name used - during the turn that is requested - */ - aPlayer = findElement( player, aGame->players, raceName ); - - index = ptonum( aGame->players, aPlayer ); - aPlayer = numtop( aGame2->players, index ); - - if ( aPlayer->flags & F_COMPRESS ) - anEnvelope->compress = TRUE; - - if ( theTurnNumber == 0 ) - aPlayer->pswdstate = 1; - highScoreList( aGame2 ); - createTurnReport( aGame2, aPlayer, report, 0 ); - } else { - setHeader( anEnvelope, MAILHEADER_SUBJECT, - "[GNG] %s turn %d report copy for %s", - aGame->name, theTurnNumber, raceName ); - fprintf( report, - "\n\nThe turn you requested is no longer available...\n" ); } ! } else if ( resNumber == RES_OK ) { ! setHeader( anEnvelope, MAILHEADER_SUBJECT, ! "[GNG] Major Trouble" ); ! fprintf( report, "You can't request a %s report for turn %d.\n\n", ! aGame->name, theTurnNumber ); ! fprintf( report, "Turn %d hasn't happened yet. While I'm a good " ! "(some say great) server, I can't predict the future for " ! "you.\n\n", theTurnNumber ); ! } else { ! setHeader( anEnvelope, MAILHEADER_SUBJECT, ! "[GNG] Major Trouble" ); ! if ( resNumber == RES_NO_ORDERS_TURN_NBR ) ! resNumber = RES_NO_REPORT_TURN_NBR; ! ! generateErrorMessage( resNumber, aGame, raceName, ! theTurnNumber, report, galaxyline ); ! /*copyEmailBody(); */ } - - fclose( report ); - result = eMail( aGame, anEnvelope, reportName ); - destroyEnvelope( anEnvelope ); - result |= ssystem( "rm %s", reportName ); - result = ( result ) ? EXIT_FAILURE : EXIT_SUCCESS; - if ( raceName ) - free( raceName ); - if ( password ) - free( password ); } - closeLog( ); ! ! return result; } --- 18,97 ---- CMD_report( int argc, char **argv ) { ! char *logName = createString( "%s/log/orders_processed.txt", galaxynghome ); openLog( logName, "a" ); free( logName ); plogtime( LBRIEF ); ! if ( argc != 5 ) { ! /* Not enough parameters */ ! return EXIT_FAILURE; ! } else { ! game* aGame = NULL; ! char *gameName = argv[ 2 ]; ! char *raceName = argv[ 3 ]; ! int theTurnNumber = atoi( argv[ 4 ] ); ! if ( ( aGame = loadgame( gameName, LG_CURRENT_TURN ) ) == NULL ) { ! /* Can't load game */ ! return EXIT_FAILURE; ! } else { ! player* aPlayer = findElement( player, ( aGame )->players, raceName ); ! if ( aPlayer == NULL ) { ! /* Can't find player */ ! return EXIT_FAILURE; ! } else { ! /* Game loaded, player found, ready to check orders. */ ! game *aGame2; ! if ( theTurnNumber > 0 ) { ! aGame2 = loadgame( aGame->name, theTurnNumber - 1 ); ! } else { ! aGame2 = loadgame( aGame->name, 0 ); ! } ! if ( aGame2 == NULL ) { ! /* Turn does not load */ ! return EXIT_FAILURE; ! } else { ! player *aPlayer; ! int index; ! loadNGConfig( aGame2 ); ! if ( theTurnNumber > 0 ) { /* Rerun the turn */ ! char *ordersName; ! ordersName = ! createString( "%s/orders/%s/%d.all", ! galaxynghome, aGame2->name, ! theTurnNumber ); ! runTurn( aGame2, ordersName ); ! free( ordersName ); ! } ! /* Translate the current race name into the name used ! during the turn that is requested ! */ ! aPlayer = findElement( player, aGame->players, raceName ); ! index = ptonum( aGame->players, aPlayer ); ! aPlayer = numtop( aGame2->players, index ); ! if ( theTurnNumber == 0 ) { ! aPlayer->pswdstate = 1; ! } ! highScoreList( aGame2 ); ! createTurnReport( aGame2, aPlayer, stdout, 0 ); ! freegame( aGame2 ); } } ! freegame( aGame ); } } closeLog( ); ! return EXIT_SUCCESS; } + + Index: cmd_mail0.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/cmd_mail0.c,v retrieving revision 1.3.2.1 retrieving revision 1.3.2.2 diff -C2 -d -r1.3.2.1 -r1.3.2.2 *** cmd_mail0.c 21 Jun 2007 23:02:02 -0000 1.3.2.1 --- cmd_mail0.c 22 Jun 2007 22:25:28 -0000 1.3.2.2 *************** *** 14,18 **** int ! CMD_mail0( int argc, char **argv, int kind ) { game *aGame; --- 14,18 ---- int ! CMD_mail0( int argc, char **argv ) { game *aGame; *************** *** 29,63 **** aPlayer->pswdstate = 1; - if ( ( aGame->gameOptions.gameOptions & GAME_SAVECOPY ) | - ( kind == CMD_CHECK_DUMMY ) ) { - if ( aPlayer->flags & F_TXTREPORT ) - saveTurnReport( aGame, aPlayer, F_TXTREPORT ); - if ( aPlayer->flags & F_XMLREPORT ) - saveTurnReport( aGame, aPlayer, F_XMLREPORT ); - } - if ( aPlayer->flags & F_TXTREPORT ) { ! if ( kind == CMD_CHECK_DUMMY ) { ! saveTurnReport( aGame, aPlayer, F_TXTREPORT ); ! } else { ! mailTurnReport( aGame, aPlayer, F_TXTREPORT ); ! } ! } if ( aPlayer->flags & F_XMLREPORT ) { ! if ( kind == CMD_CHECK_DUMMY ) { ! saveTurnReport( aGame, aPlayer, F_XMLREPORT ); ! } else { ! mailTurnReport( aGame, aPlayer, F_XMLREPORT ); ! } } if ( aPlayer->flags & F_MACHINEREPORT ) { ! if ( kind == CMD_CHECK_DUMMY ) { ! saveTurnReport( aGame, aPlayer, F_MACHINEREPORT ); ! } else { ! mailTurnReport( aGame, aPlayer, F_MACHINEREPORT ); ! } } } --- 29,42 ---- aPlayer->pswdstate = 1; if ( aPlayer->flags & F_TXTREPORT ) { ! saveTurnReport( aGame, aPlayer, F_TXTREPORT ); } if ( aPlayer->flags & F_XMLREPORT ) { ! saveTurnReport( aGame, aPlayer, F_XMLREPORT ); } if ( aPlayer->flags & F_MACHINEREPORT ) { ! saveTurnReport( aGame, aPlayer, F_MACHINEREPORT ); } } Index: cmd_check.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/cmd_check.c,v retrieving revision 1.13.2.1 retrieving revision 1.13.2.2 diff -C2 -d -r1.13.2.1 -r1.13.2.2 *** cmd_check.c 21 Jun 2007 23:02:02 -0000 1.13.2.1 --- cmd_check.c 22 Jun 2007 22:25:28 -0000 1.13.2.2 *************** *** 8,276 **** * situation at the next turn. * INPUTS ! * Orders come in via stdin. The forecast is mailed directy to the player. ! * Orders are assumed to have a proper mailheader, that is start with: ! * To: <player>@theaddress ! * Subject: orders [turn number] ! * This header can be produced with formail (see .procmailrc file). * RESULTS ! * Orders are stored in ! * $GALAXYNGHOME/orders/<game name>/<race name>.<turn number> ! * Forecast is mailed to the player. * A log is kept of all order processing in log/orders_processed.txt * SOURCE */ - - #if FS_NEW_FORECAST - - enum EReportFormat - { REP_TXT, REP_XML }; - - FILE * - openForecast( char *forecastName ) - { - FILE *forecast; - - if ( ( forecast = GOS_fopen( forecastName, "w" ) ) == NULL ) { - plog( LBRIEF, "Could not open %s for forecasting\n", forecastName ); - fprintf( stderr, "Could not open %s for forecasting\n", - forecastName ); - return 0; - } - return forecast; - } - - int - mailForecast( char *forecastName, - char *tag, envelope *anEnvelope, game *aGame, int kind ) - { - int result = FALSE; - if ( kind == CMD_CHECK_REAL ) { - plog( LBRIEF, "mailing %s report %s to %s\n", - tag, forecastName, anEnvelope->to ); - fprintf( stderr, "mailing %s report %s to %s\n", - tag, forecastName, anEnvelope->to ); - result |= eMail( aGame, anEnvelope, forecastName ); - } else { - /* TODO Create a file copy */ - } - return result; - } - - - int - mail_AdvanceReport( game *aGame, - player *aPlayer, - envelope *anEnvelope, - char *raceName, - int kind, enum EReportFormat report_format ) - { - int result = FALSE; - /* TODO */ - return result; - } - - int - mail_Forecast( game *aGame, - player *aPlayer, - envelope *anEnvelope, - char *raceName, int kind, enum EReportFormat report_format ) - { - char *tag = 0; - int result = FALSE; - FILE *forecast; - char *forecastName; - - switch ( report_format ) { - case REP_TXT: - tag = "text"; - break; - case REP_XML: - tag = "XML"; - break; - default: - assert( 0 ); - } - - forecastName = createString( "%s/NG_%s_%d_forecast", - tempdir, tag, getpid( ) ); - forecast = openForecast( forecastName ); - if ( forecast ) { - /* OK */ - } else { - return EXIT_FAILURE; - } - - setHeader( anEnvelope, MAILHEADER_SUBJECT, - "[GNG] %s turn %d %s forecast for %s", - aGame->name, ( aGame->turn ) + 1, tag, raceName ); - - /* Create the report */ - ( aGame->turn )++; - fprintf( stderr, "Creating %s report, %s:%d\n", tag, raceName, kind ); - switch ( report_format ) { - case REP_TXT: - reportForecast( aGame, raceName, forecast ); - break; - case REP_XML: - report_xml( aGame, aPlayer, forecast, Forecast ); - break; - default: - assert( 0 ); - } - ( aGame->turn )--; - - /* Mail it */ - result |= mailForecast( forecastName, tag, anEnvelope, aGame, kind ); - result |= GOS_delete( forecastName ); - free( forecastName ); - fclose( forecast ); - return result; - } - - int - mail_TXT_Error( game *aGame, - envelope *anEnvelope, - char *raceName, int kind, int resNumber, int theTurnNumber ) - { - int result = FALSE; - FILE *forecast; - - char *forecastName = createString( "%s/NG_TXT_%d_errors", - tempdir, getpid( ) ); - forecast = openForecast( forecastName ); - if ( forecast ) { - /* OK */ - } else { - return TRUE; - } - - setHeader( anEnvelope, MAILHEADER_SUBJECT, "[GNG] Major Trouble" ); - plog( LBRIEF, "Major Trouble %d\n", resNumber ); - - generateErrorMessage( resNumber, aGame, raceName, theTurnNumber, - forecast ); - fclose( forecast ); - - result |= mailForecast( forecastName, "TXT", anEnvelope, aGame, kind ); - result |= GOS_delete( forecastName ); - free( forecastName ); - fclose( forecast ); - return result; - } - - int - CMD_check( int argc, char **argv, int kind ) - { - char *logName; - int result = FALSE; - - logName = createString( "%s/log/orders_processed.txt", galaxynghome ); - openLog( logName, "a" ); - free( logName ); - - plogtime( LBRIEF ); - if ( argc < 2 ) { - result = TRUE; - } else { - envelope *anEnvelope = createEnvelope( ); - char *returnAddress = getReturnAddress( stdin ); - int theTurnNumber = getTurnNumber( stdin ); - char *galaxyline = NULL; - char *raceName = NULL; - char *password = NULL; - char *final_orders = NULL; - game *aGame = NULL; - int resNumber = areValidOrders( stdin, &aGame, &raceName, - &password, &final_orders, - &theTurnNumber, &galaxyline ); - plog( LBRIEF, "game %s\n", aGame->name ); - - setHeader( anEnvelope, MAILHEADER_FROM, "%s", - aGame->serverOptions.SERVERemail ); - - setHeader( anEnvelope, MAILHEADER_TO, "%s", returnAddress ); - setHeader( anEnvelope, MAILHEADER_REPLYTO, - aGame->serverOptions.ReplyTo ); - anEnvelope->from_address = strdup( aGame->serverOptions.SERVERemail ); - anEnvelope->from_name = strdup( aGame->serverOptions.SERVERname ); - - if ( resNumber == RES_OK ) { - player *aPlayer = findElement( player, aGame->players, raceName ); - assert( aPlayer ); - aPlayer->orders = NULL; - plog( LBRIEF, "Orders from %s\n", returnAddress ); - - if ( ( theTurnNumber == LG_CURRENT_TURN ) || - ( theTurnNumber == ( aGame->turn ) + 1 ) ) { - /* They are orders for the coming turn, copy them. */ - copyOrders( aGame, stdin, raceName, password, - aGame->turn + 1 ); - /* Check them */ - checkOrders( aGame, raceName ); - /* Now mail the result */ - if ( aPlayer->flags & F_XMLREPORT ) { - result = - mail_Forecast( aGame, aPlayer, anEnvelope, raceName, - kind, REP_XML ); - } - if ( aPlayer->flags & F_TXTREPORT ) { - result = - mail_Forecast( aGame, aPlayer, anEnvelope, raceName, - kind, REP_TXT ); - } - } else if ( theTurnNumber > ( aGame->turn ) + 1 ) { - /* They are advance orders */ - copyOrders( aGame, stdin, raceName, password, theTurnNumber ); - setHeader( anEnvelope, MAILHEADER_SUBJECT, - "[GNG] %s turn %d advance orders received for %s.", - aGame->name, theTurnNumber, raceName ); - plog( LBRIEF, "%s turn %d advance orders received for %s.\n", - aGame->name, theTurnNumber, raceName ); - if ( aPlayer->flags & F_XMLREPORT ) { - result = - mail_AdvanceReport( aGame, aPlayer, anEnvelope, - raceName, kind, REP_XML ); - } - if ( aPlayer->flags & F_TXTREPORT ) { - result = - mail_AdvanceReport( aGame, aPlayer, anEnvelope, - raceName, kind, REP_TXT ); - } - } else { - /* Orders for a turn that already ran. - * Should be handled by areValidOrders() - */ - assert( 0 ); - } - } else { - /* Some major error */ - result |= mail_TXT_Error( aGame, anEnvelope, - raceName, kind, resNumber, - theTurnNumber ); - } - } - - result = ( result ) ? EXIT_FAILURE : EXIT_SUCCESS; - return result; - } - #else int ! CMD_check( int argc, char **argv, int kind ) { int result; char *logName; - envelope *anEnvelope; - char *forecastName; - char *returnAddress; - char *raceName; - char *password; - char *final_orders; - char *galaxyline = NULL; - game *aGame; - FILE *forecast; - player *aPlayer; - - int resNumber, theTurnNumber; result = FALSE; --- 8,23 ---- * situation at the next turn. * INPUTS ! * Orders come in via stdin. * RESULTS ! * Forecast is is send to stdout. * A log is kept of all order processing in log/orders_processed.txt * SOURCE */ int ! CMD_check( int argc, char **argv ) { int result; char *logName; result = FALSE; *************** *** 281,542 **** plogtime( LBRIEF ); ! if ( argc >= 2 ) { ! anEnvelope = createEnvelope( ); ! returnAddress = getReturnAddress( stdin ); ! raceName = NULL; ! password = NULL; ! final_orders = NULL; ! aGame = NULL; ! resNumber = areValidOrders( stdin, &aGame, &raceName, ! &password, &final_orders, &theTurnNumber, ! &galaxyline ); ! /* TODO FS Hack. */ ! if ( resNumber == RES_NO_REPORT_TURN_NBR ) { ! resNumber = RES_NO_ORDERS_TURN_NBR; ! } ! /* Should be fixed in areValidOrders. */ ! ! plog( LBRIEF, "game %s\n", aGame->name ); ! ! setHeader( anEnvelope, MAILHEADER_FROM, "%s", ! aGame->serverOptions.SERVERemail ); ! ! setHeader( anEnvelope, MAILHEADER_TO, "%s", returnAddress ); ! setHeader( anEnvelope, MAILHEADER_REPLYTO, ! aGame->serverOptions.ReplyTo ); ! anEnvelope->from_name = strdup( aGame->serverOptions.SERVERname ); ! anEnvelope->from_address = strdup( aGame->serverOptions.SERVERemail ); ! ! if ( resNumber == RES_OK ) { ! aPlayer = findElement( player, aGame->players, raceName ); ! aPlayer->orders = NULL; ! ! plog( LBRIEF, "Orders from %s\n", returnAddress ); ! ! /* produce an XML forecast */ ! if ( aPlayer->flags & F_XMLREPORT ) { ! if ( ( theTurnNumber == LG_CURRENT_TURN ) || ! ( theTurnNumber == ( aGame->turn ) + 1 ) ) { ! forecastName = createString( "%s/NG_XML_%d_forecast", ! tempdir, getpid( ) ); ! copyOrders( aGame, stdin, raceName, password, ! final_orders, aGame->turn + 1 ); ! if ( ( forecast = ! GOS_fopen( forecastName, "w" ) ) == NULL ) { ! plog( LBRIEF, "Could not open %s for forecasting\n", ! forecastName ); ! fprintf( stderr, ! "Could not open %s for forecasting\n", ! forecastName ); ! return EXIT_FAILURE; ! } ! ! if ( final_orders ) ! setHeader( anEnvelope, MAILHEADER_SUBJECT, ! "[GNG] %s turn %d XML finalorders forecast for %s", ! aGame->name, ( aGame->turn ) + 1, ! raceName ); ! else ! setHeader( anEnvelope, MAILHEADER_SUBJECT, ! "[GNG] %s turn %d XML forecast for %s", ! aGame->name, ( aGame->turn ) + 1, ! raceName ); ! ! checkOrders( aGame, raceName, forecast, F_XMLREPORT ); ! ! fclose( forecast ); ! if ( kind == CMD_CHECK_REAL ) { ! plog( LBRIEF, "mailing XML report %s to %s\n", ! forecastName, anEnvelope->to ); ! fprintf( stderr, "mailing XML report %s to %s\n", ! forecastName, anEnvelope->to ); ! result |= eMail( aGame, anEnvelope, forecastName ); ! } else { ! char *forecastFile; ! forecastFile = ! createString( "%s/forecasts/%s/%s_XML", ! galaxynghome, argv[2], ! returnAddress ); ! GOS_copy( forecastName, forecastFile ); ! } ! result |= GOS_delete( forecastName ); ! free( forecastName ); ! } ! } ! ! /* produce a text forecast */ ! if ( aPlayer->flags & F_TXTREPORT ) { ! if ( ( theTurnNumber == LG_CURRENT_TURN ) || ! ( theTurnNumber == ( aGame->turn ) + 1 ) ) { ! forecastName = createString( "%s/NG_TXT_%d_forecast", ! tempdir, getpid( ) ); ! if ( ( forecast = ! GOS_fopen( forecastName, "w" ) ) == NULL ) { ! plog( LBRIEF, "Could not open %s for forecasting\n", ! forecastName ); ! return EXIT_FAILURE; ! } ! ! if ( aPlayer->orders == NULL ) ! copyOrders( aGame, stdin, raceName, password, ! final_orders, aGame->turn + 1 ); ! ! if ( final_orders ) ! setHeader( anEnvelope, MAILHEADER_SUBJECT, ! "[GNG] %s turn %d text finalorders forecast for %s", ! aGame->name, ( aGame->turn ) + 1, ! raceName ); ! else ! setHeader( anEnvelope, MAILHEADER_SUBJECT, ! "[GNG] %s turn %d text forecast for %s", ! aGame->name, ( aGame->turn ) + 1, ! raceName ); ! ! checkOrders( aGame, raceName, forecast, F_TXTREPORT ); ! ! fclose( forecast ); ! ! if ( kind == CMD_CHECK_REAL ) { ! plog( LBRIEF, "mailing TXT report %s to %s\n", ! forecastName, anEnvelope->to ); ! fprintf( stderr, "mailing TXT report %s to %s\n", ! forecastName, anEnvelope->to ); ! ! result |= eMail( aGame, anEnvelope, forecastName ); ! } else { ! char *forecastFile; ! forecastFile = ! createString( "%s/forecasts/%s/%s_TXT", ! galaxynghome, argv[2], ! returnAddress ); ! GOS_copy( forecastName, forecastFile ); ! } ! result |= GOS_delete( forecastName ); ! free( forecastName ); ! } ! } } else { ! forecastName = createString( "%s/NG_TXT_%d_errors", ! tempdir, getpid( ) ); ! forecast = GOS_fopen( forecastName, "w" ); ! setHeader( anEnvelope, MAILHEADER_SUBJECT, ! "[GNG] Major Trouble" ); ! plog( LBRIEF, "Major Trouble %d\n", resNumber ); ! ! generateErrorMessage( resNumber, aGame, raceName, ! theTurnNumber, forecast, galaxyline ); ! fclose( forecast ); ! ! if ( kind == CMD_CHECK_REAL ) { ! plog( LBRIEF, "mailing error report %s to %s\n", forecastName, ! anEnvelope->to ); ! ! result |= eMail( aGame, anEnvelope, forecastName ); ! } else { ! char *forecastFile; ! forecastFile = ! createString( "%s/forecasts/%s/%s_ERR", ! galaxynghome, argv[2], returnAddress ); ! GOS_copy( forecastName, forecastFile ); ! } ! result |= GOS_delete( forecastName ); ! free( forecastName ); ! } ! ! /* code here for advanced orders, we need to see how to determine this */ ! if ( ( theTurnNumber > ( aGame->turn + 1 ) ) ! && ( resNumber == RES_OK ) ) { ! ! if ( aPlayer->orders == NULL ) ! copyOrders( aGame, stdin, raceName, password, final_orders, ! theTurnNumber ); ! ! if ( final_orders ) { ! setHeader( anEnvelope, MAILHEADER_SUBJECT, ! "[GNG] %s turn %d advance finalorders received for %s.", ! aGame->name, theTurnNumber, raceName ); ! plog( LBRIEF, ! "%s turn %d advance finalorders received for %s.\n", ! aGame->name, theTurnNumber, raceName ); } else { ! setHeader( anEnvelope, MAILHEADER_SUBJECT, ! "[GNG] %s turn %d advance orders received for %s.", ! aGame->name, theTurnNumber, raceName ); ! plog( LBRIEF, "%s turn %d advance orders received for %s.\n", ! aGame->name, theTurnNumber, raceName ); ! } ! ! if ( aPlayer->flags & F_XMLREPORT ) { ! forecastName = createString( "%s/NG_XML_forecast", tempdir ); ! forecast = GOS_fopen( forecastName, "w" ); ! ! fprintf( forecast, ! "<galaxy>\n <variant>GalaxyNG</variant>\n" ); ! fprintf( forecast, " <version>%d.%d.%d</version>\n", ! GNG_MAJOR, GNG_MINOR, GNG_RELEASE ); ! fprintf( forecast, " <game name=\"%s\">\n", aGame->name ); ! fprintf( forecast, " <turn num=\"%d\">\n", theTurnNumber ); ! fprintf( forecast, " <race name=\"%s\">\n", raceName ); ! fprintf( forecast, " <message>\n" ); ! fprintf( forecast, " <line num=\"1\">" ! "O wise leader, your orders for turn %d</line>", ! theTurnNumber ); ! fprintf( forecast, " <line num=\"2\">" ! "have been received and stored.</line>" ); ! fprintf( forecast, " </message>\n" ); ! fprintf( forecast, " </race>\n" ); ! fprintf( forecast, " </turn>\n" ); ! fprintf( forecast, " </game>\n" ); ! fprintf( forecast, "</galaxy>\n" ); ! fclose( forecast ); ! if ( kind == CMD_CHECK_REAL ) { ! result |= eMail( aGame, anEnvelope, forecastName ); ! } else { ! char *forecastFile; ! ! forecastFile = ! createString( "%s/forecasts/%s/%s_XML", ! galaxynghome, argv[2], returnAddress ); ! GOS_copy( forecastName, forecastFile ); ! } ! result |= GOS_delete( forecastName ); ! free( forecastName ); ! } ! ! if ( aPlayer->flags & F_TXTREPORT ) { ! if ( aPlayer->orders == NULL ) ! copyOrders( aGame, stdin, raceName, password, ! final_orders, theTurnNumber ); ! forecastName = createString( "%s/NG_TXT_forecast", tempdir ); ! forecast = GOS_fopen( forecastName, "w" ); ! fprintf( forecast, "O wise leader your orders for turn %d " ! "have been received and stored.\n", theTurnNumber ); ! fclose( forecast ); ! if ( kind == CMD_CHECK_REAL ) { ! result |= eMail( aGame, anEnvelope, forecastName ); ! } else { ! char *forecastFile; ! forecastFile = ! createString( "%s/forecasts/%s/%s_TXT", ! galaxynghome, argv[2], returnAddress ); ! GOS_copy( forecastName, forecastFile ); } ! result |= GOS_delete( forecastName ); ! free( forecastName ); } } } ! ! if ( raceName ) ! free( raceName ); ! if ( password ) ! free( password ); ! destroyEnvelope( anEnvelope ); ! result = ( result ) ? EXIT_FAILURE : EXIT_SUCCESS; ! ! return result; } ! #endif --- 28,65 ---- plogtime( LBRIEF ); ! if ( argc != 4 ) { ! /* Not enough parameters */ ! return EXIT_FAILURE; ! } else { ! game* aGame = NULL; ! char *gameName = argv[ 2 ]; ! char *raceName = argv[ 3 ]; + if ( ( aGame = loadgame( gameName, LG_CURRENT_TURN ) ) == NULL ) { + /* Can't load game */ + return EXIT_FAILURE; } else { ! player* aPlayer = findElement( player, ( aGame )->players, raceName ); ! if ( aPlayer == NULL ) { ! /* Can't find player */ ! return EXIT_FAILURE; } else { ! strlist *s; ! loadNGConfig( aGame ); ! /* Game loaded, player found, ready to check orders. */ ! getLine( stdin ); ! for ( ; !feof( stdin ); ) { ! s = makestrlist( lineBuffer ); ! addList( &( aPlayer->orders ), s ); ! getLine( stdin ); } ! checkOrders( aGame, raceName, stdout, F_TXTREPORT ); } + freegame( aGame ); } } ! return EXIT_SUCCESS; } ! Index: phase.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/phase.c,v retrieving revision 1.25.2.1 retrieving revision 1.25.2.2 diff -C2 -d -r1.25.2.1 -r1.25.2.2 *** phase.c 21 Jun 2007 23:02:02 -0000 1.25.2.1 --- phase.c 22 Jun 2007 22:25:28 -0000 1.25.2.2 *************** *** 183,211 **** } - - /****f* Phase/kill - * NAME - * kill -- - * NOTES - * Should be in battle.c I guess. - ***** - */ - - int - kill( group *attack, group *target ) - { - double defense, ratio; - - if ( !attack->type->attacks ) - return 0; - defense = calcdefense( target ); - if ( !defense ) - return 1; - ratio = attack->weapons * attack->type->weapons / defense; - return ratio > pow( 4.0, frand2( ) ); - } - - - /****f* Phase/bombphase * NAME --- 183,186 ---- Index: galaxyng.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/galaxyng.c,v retrieving revision 1.65.2.2 retrieving revision 1.65.2.3 diff -C2 -d -r1.65.2.2 -r1.65.2.3 *** galaxyng.c 22 Jun 2007 00:19:00 -0000 1.65.2.2 --- galaxyng.c 22 Jun 2007 22:25:28 -0000 1.65.2.3 *************** *** 136,145 **** } else if ( strstr( argv[1], "create" ) ) { result = CMD_create( argc, argv ); ! } else if ( strstr( argv[1], "dummymail0" ) ) { ! result = CMD_mail0( argc, argv, CMD_CHECK_DUMMY ); ! } else if ( strstr( argv[1], "dummycheck" ) ) { ! result = CMD_check( argc, argv, CMD_CHECK_DUMMY ); ! } else if ( strstr( argv[1], "dummyrun" ) ) { ! result = CMD_run( argc, argv, CMD_RUN_DUMMY ); } else if ( strstr( argv[1], "selftest" ) ) { /* experimental */ result = CMD_selftest( ); --- 136,145 ---- } else if ( strstr( argv[1], "create" ) ) { result = CMD_create( argc, argv ); ! } else if ( strstr( argv[1], "mail0" ) ) { ! result = CMD_mail0( argc, argv ); ! } else if ( strstr( argv[1], "check" ) ) { ! result = CMD_check( argc, argv ); ! } else if ( strstr( argv[1], "run" ) ) { ! result = CMD_run( argc, argv ); } else if ( strstr( argv[1], "selftest" ) ) { /* experimental */ result = CMD_selftest( ); Index: process.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/process.c,v retrieving revision 1.68.2.1 retrieving revision 1.68.2.2 diff -C2 -d -r1.68.2.1 -r1.68.2.2 *** process.c 21 Jun 2007 23:02:02 -0000 1.68.2.1 --- process.c 22 Jun 2007 22:25:29 -0000 1.68.2.2 *************** *** 2056,2090 **** - /****f* Process/checkOrders - * NAME - * checkOrders -- check orders - * SYNOPSIS - * int checkOrders(char *ordersFileName) - * resNumber = checkOrders(ordersFileName) - * FUNCTION - * Checks a file with orders and prints a report with a forecast and - * any errors found in the orders to stdout. - * It is checked that the orders contain a valid game name, race - * name and password. - * A copy of the orders is stored in the directory orders/<gameName>. - * - * If the orders start with #REPORT instead of #GALAXY a copy - * of the previous turn report is send to stdout. - * INPUTS - * ordersFileName - name of the file with the orders. - * RESULT - * resNumber -- return code: - * RES_NO_ORDERS - no line containing "#GALAXY" or #REPORT was found. - * RES_PASSWORD - password was incorrect. - * RES_PLAYER - no such player (Race) exists. - * RES_NO_GAME - no such game exists. - * RES_TURNRAN - orders are for a turn that already ran. - * RES_OK - everything was OK. - * BUGS - * Does not handle machine reports or xml reports. - * SEE ALSO - * areValidOrders(), copyOrders() - * SOURCE - */ #if FS_NEW_FORECAST --- 2056,2059 ---- *************** *** 2198,2533 **** - /****f* Process/copyOrders - * NAME - * copyOrders -- copy incoming orders to file. - * SYNOPSIS - * void copyOrders(game *aGame, FILE *orders, char *raceName, - * char *password, int theTurnNumber) - * FUNCTION - * Copy the orders to a file called - * GAMEHOME/orders/<game name>/<race name>.<turn number> - * If and #END line is missing one is generated. - * INPUTS - * orderFile - should point to the line after the #GALAXY line. - * aGame - * raceName - * password - * theTurnNumber - * SOURCE - */ - - void - copyOrders( game *aGame, FILE *orders, char *raceName, char *password, - char *final_orders, int theTurnNumber ) - { - strlist *s; - char *copyFileName; - FILE *copyFile; - player *aPlayer; - - aPlayer = findElement( player, aGame->players, raceName ); - - aPlayer->orders = NULL; - copyFileName = alloc( strlen( aGame->name ) + strlen( aPlayer->name ) + - strlen( galaxynghome ) + strlen( "/orders//" ) + - 20 ); - if ( final_orders ) { - sprintf( copyFileName, "%s/orders/%s/%s.%d", galaxynghome, - aGame->name, aPlayer->name, theTurnNumber ); - unlink( copyFileName ); - sprintf( copyFileName, "%s/orders/%s/%s_final.%d", galaxynghome, - aGame->name, aPlayer->name, theTurnNumber ); - } else { - sprintf( copyFileName, "%s/orders/%s/%s_final.%d", galaxynghome, - aGame->name, aPlayer->name, theTurnNumber ); - unlink( copyFileName ); - sprintf( copyFileName, "%s/orders/%s/%s.%d", galaxynghome, - aGame->name, aPlayer->name, theTurnNumber ); - } - - copyFile = Fopen( copyFileName, "w" ); - savefprintf( copyFile, "#GALAXY %s %s %s", - aGame->name, raceName, password ); - if ( final_orders ) - savefprintf( copyFile, " FinalOrders" ); - savefprintf( copyFile, "\n" ); - - getLine( orders ); - for ( ; !feof( orders ) && noCaseStrncmp( "#END", lineBuffer, 4 ); ) { - savefprintf( copyFile, "%s", lineBuffer ); - s = makestrlist( lineBuffer ); - addList( &( aPlayer->orders ), s ); - getLine( orders ); - } - if ( feof( orders ) ) - savefprintf( copyFile, "#END\n" ); - else - savefprintf( copyFile, "%s\n", lineBuffer ); - - free( copyFileName ); - } - - /*****************/ - - - /****f* Process/areValidOrders - * NAME - * areValidOrders -- check if orders are valid and load game. - * SYNOPSIS - * int areValidOrders(FILE *ordersFile, - * char **command, game **game, - * char **raceName, char** final_orders, - * char **password) - * FUNCTION - * Scans through a file with orders until a line that starts - * with "#" is found. The the rest of the line is then - * used to determine the name of the game, the race the orders - * are for, and the password for the race. - * The given game is loaded. It is checked that the given - * player exists in this game, and that the given password - * is equal to the stored password. - * INPUTS - * ordersFile - pointer to a opened file with orders. - * theTurnNumber - turn number the orders are supposed to be for. - * RESULT - * result - return code: - * RES_NO_ORDERS - no line containing "#GALAXY" was found. - * RES_PASSWORD - password was incorrect. - * RES_PLAYER - no such player (Race) exists. - * RES_NO_GAME - no such game exists. - * RES_TURNRAN - orders are for a turn that already ran. - * RES_OK - everything was OK. - * aGame - game Structure loaded from disk - * raceName - name of the race the orders are for. - * password - given password of the race. - * - * ordersFile - points to the line after the #GALAXY line. - * - * If the result is RES_OK then the game and its configuration - * file are loaded from disk. - * SEE ALSO - * CMD_report(), CMD_check(), CMD_relay() - * SOURCE - */ - - int - areValidOrders( FILE *ordersFile, game **aGame, char **raceName, - char **password, char **final_orders, int *theTurnNumber, - char **galaxyline ) - { - int resNumber; - int foundOrders; - char *gameName; - char *isRead; - - - gameName = NULL; - - foundOrders = FALSE; - for ( isRead = fgets( lineBuffer, LINE_BUFFER_SIZE, ordersFile ); - isRead; - isRead = fgets( lineBuffer, LINE_BUFFER_SIZE, ordersFile ) ) { - if ( noCaseStrncmp( "#GALAXY", lineBuffer, 7 ) == 0 ) { - foundOrders = TRUE; - break; - } - } - - *theTurnNumber = LG_CURRENT_TURN; - - if ( foundOrders ) { - char *ptr; - char *turnNumberString = NULL; - - getstr( lineBuffer ); - *galaxyline = strdup( lineBuffer ); - gameName = strdup( getstr( NULL ) ); - *raceName = strdup( getstr( NULL ) ); - *password = strdup( getstr( NULL ) ); - turnNumberString = getstr( NULL ); - - if ( noCaseStrcmp( *password, "" ) == 0 ) { - /* No password */ - } else { - if ( noCaseStrcmp( turnNumberString, "FinalOrders" ) != 0 ) { - if ( noCaseStrcmp( turnNumberString, "" ) != 0 ) { - *theTurnNumber = atoi( turnNumberString ); - if ( !isdigit( turnNumberString[0] ) ) { - *theTurnNumber = LG_CURRENT_TURN; - if ( ( *aGame = - loadgame( gameName, - LG_CURRENT_TURN ) ) != NULL ) - loadNGConfig( *aGame ); - else { - *aGame = allocStruct( game ); - - setName( *aGame, "UnknownGame" ); - loadNGConfig( *aGame ); - if ( gameName ) - setName( *aGame, gameName ); - return RES_NO_GAME; - } - return RES_NO_REPORT_TURN_NBR; - } - } - } else { - /* Case: #galaxy game race FinalOrders */ - *final_orders = strdup( turnNumberString ); - } - } - - if ( ( ptr = getstr( NULL ) ) != NULL ) { - if ( noCaseStrcmp( ptr, "FinalOrders" ) == 0 ) - *final_orders = strdup( ptr ); - } - - if ( ( *aGame = loadgame( gameName, LG_CURRENT_TURN ) ) ) { - player *aPlayer; - - loadNGConfig( *aGame ); - - if ( noCaseStrcmp( "GM", *raceName ) == 0 ) { - if ( strcmp( ( *aGame )->serverOptions.GMpassword, *password ) - == 0 ) { - resNumber = RES_OK; - } - } else { - aPlayer = findElement( player, ( *aGame )->players, - *raceName ); - - if ( aPlayer ) { - if ( noCaseStrcmp( aPlayer->pswd, *password ) eq 0 ) { - if ( ( *theTurnNumber >= ( *aGame )->turn + 1 ) || - ( *theTurnNumber == LG_CURRENT_TURN ) ) { - resNumber = RES_OK; - } else { - resNumber = RES_TURNRAN; - } - } else { - resNumber = RES_PASSWORD; - } - } else { - resNumber = RES_PLAYER; - } - } - } else { - resNumber = RES_NO_GAME; - } - } else { - resNumber = RES_NO_ORDERS; - } - - if ( ( resNumber == RES_NO_GAME ) || ( resNumber == RES_NO_ORDERS ) ) { - *aGame = allocStruct( game ); - - setName( *aGame, "UnknownGame" ); - loadNGConfig( *aGame ); - if ( gameName ) - setName( *aGame, gameName ); - } - - return resNumber; - } - - /*********/ - - - /****f* Process/getTurnNumber - * NAME - * getTurnNumber -- get the turn number - * FUNCTION - * Scans an incomming email for the From: line. - * If it is found it looks for the word "order" or "report" - * It then looks if there is a number after this word. - * If there is this number is returned. - * If no From: line was found the program aborts. - * RESULTS - * >= 0 -- the turn number - * LG_CURRENT_TURN -- no turn number was specified - ****/ - - int - getTurnNumber( FILE *orders ) - { - int theTurnNumber; - char *isRead; - - theTurnNumber = LG_CURRENT_TURN; - for ( isRead = fgets( lineBuffer, LINE_BUFFER_SIZE, orders ); - isRead; isRead = fgets( lineBuffer, LINE_BUFFER_SIZE, orders ) ) { - /* WIN32 */ - if ( noCaseStrncmp( string_mail_subject, lineBuffer, 8 ) == 0 ) { - int temp, nrRead; - char *c; - - for ( c = lineBuffer; *c; c++ ) - *c = ( char ) tolower( *c ); - c = strstr( lineBuffer, "order" ); - if ( c == NULL ) { - c = strstr( lineBuffer, "report" ); - } - if ( c == NULL ) { - c = strstr( lineBuffer, "shutdown" ); - } - if ( c != NULL ) { - nrRead = sscanf( c, "%*s%d", &temp ); - if ( nrRead == 1 ) - theTurnNumber = temp; - } else { - assert( 0 ); - } - break; - } - } - assert( isRead != NULL ); - - return theTurnNumber; - } - - - /****f* Process/getDestination - * NAME - * getDestination -- get Destination for the message - * FUNCTION - * Extract the destination of a relay message from a players - * email. - * NOTE - * The message should contain the line - * Subject: relay <race name> - ****** - */ - - char * - getDestination( char *subject ) - { - int theTurnNumber; - char *destination; - char *c; - - theTurnNumber = LG_CURRENT_TURN; - - /*plog(LBRIEF, ">getDestination(%s)\n", subject); */ - - c = strlwr( strdup( subject ) ); - - if ( ( destination = strstr( c, "relay" ) ) == NULL ) { - plog( LBRIEF, " subject does not have \"relay\" in it\n" ); - return NULL; /* can't be a relay subject */ - } else - destination += 5; - - while ( isspace( *destination ) ) - destination++; - - destination = strdup( destination ); - free( c ); - - /*plog(LBRIEF, "<getDestination(%s)\n", destination); */ - - return destination; - } - - - --- 2167,2170 ---- *************** *** 2769,2877 **** - /****f* Process/generateErrorMessage - * NAME - * generateErrorMessage -- create error message for faulty orders. - * FUNCTION - * - * INPUTS - * resNumber -- The kind of error. - * forecast -- file to write the message to. - * SOURCE - */ - - void - generateErrorMessage( int resNumber, game *aGame, - char *raceName, int theTurnNumber, - FILE *forecast, char *galaxyline ) - { - switch ( resNumber ) { - case RES_NO_ORDERS: - fprintf( forecast, "O Wise Leader, your mail did not contain any " - "orders.\nRemember orders start with\n\n" - "#GALAXY GameName RaceName Password [TurnNumber] " - "[FinalOrders]\n\nand end with\n\n#END\n" ); - break; - - case RES_ERR_GALAXY: - fprintf( forecast, "O Wise Leader, you must supply your race name " - "and galaxy name.\n Remember orders start with,\n\n" - "#GALAXY GameName RaceName Password [TurnNumber] " - "[FinalOrders]\n\nand end with\n\n#END\n" ); - if ( galaxyline ) { - fprintf( forecast, "\nThe first line you sent was:\n%s\n", - galaxyline ); - } - break; - - case RES_NO_GAME: - fprintf( forecast, "O Wise Leader, there is no galaxy called %s.\n" - "This probably means that you mispelled the galaxy name " - "in your orders\n", aGame->name ); - if ( galaxyline ) { - fprintf( forecast, "\nThe first line you sent was:\n%s\n", - galaxyline ); - } - break; - - case RES_PASSWORD: - fprintf( forecast, "O Wise Leader, the password you gave is " - "incorrect\n" ); - if ( galaxyline ) { - fprintf( forecast, "\nThe first line you sent was:\n%s\n", - galaxyline ); - } - break; - case RES_PLAYER: - fprintf( forecast, "O Wise Leader there is no race called %s.\n" - "This probably means that you mispelled your " - "race name.\n", raceName ); - if ( galaxyline ) { - fprintf( forecast, "\nThe first line you sent was:\n%s\n", - galaxyline ); - } - break; - - case RES_TURNRAN: - fprintf( forecast, "O Wise Leader, you sent in orders for turn %d " - "but that turn already ran.\nThe next turn is %d.", - theTurnNumber, aGame->turn + 1 ); - break; - - case RES_DESTINATION: - fprintf( forecast, "O Wise Leader, the recipient of the message " - "you sent does not exist.\n" ); - break; - - case RES_NODESTINATION: - fprintf( forecast, "O Wise Leader, you failed to give a " - "destination for your message.\n" ); - break; - - case RES_NO_ORDERS_TURN_NBR: - fprintf( forecast, "O Wise Leader, you didn't specify a proper turn " - "number.\nRemember that orders start with\n\n" - "#GALAXY GameName RaceName Password [TurnNumber] " - "[FinalOrders]\n\n" "and end with\n\n#END\n" ); - if ( galaxyline ) { - fprintf( forecast, "\nThe first line you sent was:\n%s\n", - galaxyline ); - } - break; - - case RES_NO_REPORT_TURN_NBR: - fprintf( forecast, "O Wise Leader, you didn't specify a proper turn " - "number.\nRemember that report requests start with\n\n" - "#GALAXY GameName RaceName Password [TurnNumber]\n\n" - "and end with\n\n#END\n" ); - if ( galaxyline ) { - fprintf( forecast, "\nThe first line you sent was:\n%s\n", - galaxyline ); - } - break; - } - fprintf( forecast, - "\nYour orders have been discarded!\n" - "Please correct the mistake and retransmit your orders.\n" ); - } - - /***********/ --- 2406,2407 ---- Index: cmd_run.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/cmd_run.c,v retrieving revision 1.5.2.1 retrieving revision 1.5.2.2 diff -C2 -d -r1.5.2.1 -r1.5.2.2 *** cmd_run.c 21 Jun 2007 23:02:02 -0000 1.5.2.1 --- cmd_run.c 22 Jun 2007 22:25:28 -0000 1.5.2.2 *************** *** 31,35 **** int ! CMD_run( int argc, char **argv, int kind ) { int result; --- 31,35 ---- int ! CMD_run( int argc, char **argv ) { int result; *************** *** 55,59 **** loadNGConfig( aGame ); ! if ( checkTime( aGame ) || ( kind == CMD_RUN_DUMMY ) ) { checkIntegrity( aGame ); --- 55,59 ---- loadNGConfig( aGame ); ! if ( checkTime( aGame ) ) { checkIntegrity( aGame ); *************** *** 65,111 **** aPlayer = aPlayer->next ) { if ( aPlayer->flags & F_TXTREPORT ) { ! if ( kind == CMD_RUN_REAL ) { ! result |= ! mailTurnReport( aGame, aPlayer, ! F_TXTREPORT ); ! if ( aGame->gameOptions. ! gameOptions & GAME_SAVECOPY ) { ! saveTurnReport( aGame, aPlayer, ! F_TXTREPORT ); ! } ! } else { ! saveTurnReport( aGame, aPlayer, F_TXTREPORT ); ! } } if ( aPlayer->flags & F_XMLREPORT ) { ! if ( kind == CMD_RUN_REAL ) { ! result |= ! mailTurnReport( aGame, aPlayer, ! F_XMLREPORT ); ! if ( aGame->gameOptions. ! gameOptions & GAME_SAVECOPY ) { ! saveTurnReport( aGame, aPlayer, ! F_XMLREPORT ); ! } ! } else { ! saveTurnReport( aGame, aPlayer, F_XMLREPORT ); ! } } - if ( aPlayer->flags & F_MACHINEREPORT ) { ! if ( kind == CMD_RUN_REAL ) { ! result |= ! mailTurnReport( aGame, aPlayer, ! F_MACHINEREPORT ); ! if ( aGame->gameOptions. ! gameOptions & GAME_SAVECOPY ) { ! saveTurnReport( aGame, aPlayer, ! F_MACHINEREPORT ); ! } ! } else { ! saveTurnReport( aGame, aPlayer, ! F_MACHINEREPORT ); ! } } } --- 65,77 ---- aPlayer = aPlayer->next ) { if ( aPlayer->flags & F_TXTREPORT ) { ! saveTurnReport( aGame, aPlayer, F_TXTREPORT ); } if ( aPlayer->flags & F_XMLREPORT ) { ! saveTurnReport( aGame, aPlayer, F_XMLREPORT ); } if ( aPlayer->flags & F_MACHINEREPORT ) { ! saveTurnReport( aGame, aPlayer, ! F_MACHINEREPORT ); } } *************** *** 115,119 **** "The server has detected an error in the game data structure. The run\n" "of the turn has been aborted. No turn reports have been sent. Please\n" ! "contact Ken Weinert at mc...@qu... for a solution to this\n" "problem.\n" ); result = 1; --- 81,85 ---- "The server has detected an error in the game data structure. The run\n" "of the turn has been aborted. No turn reports have been sent. Please\n" ! "contact Frans Slothouber at rf...@xs... for a solution to this\n" "problem.\n" ); result = 1; *************** *** 133,139 **** } closeLog( ); ! if ( kind == CMD_RUN_REAL ) { ! mailGMReport( aGame, argv[2] ); ! } freegame( aGame ); } --- 99,103 ---- } closeLog( ); ! saveGMReport( aGame, argv[2] ); freegame( aGame ); } Index: report.c =================================================================== RCS file: /cvsroot/galaxyng/NG/Source/report.c,v retrieving revisi... [truncated message content] |