/* Copyright 2000, 2009, 2011, 2012 Neil Edelman, distributed under the terms
of the GNU General Public License, see copying.txt */
/* it's the OSS game, by Neil Edelman (Dec. 2000) */
/* let's make it playable on the web (Dec 2009) */
#include %s
%s: %s(%c)
\n\n", RoomName(oss.room), h, *h); printoss(&oss); #endif (*fn)(&oss, *h, 0); } return &oss; } /** compares the oss games, returns 0 if they're equal */ static int osscomp(const struct Oss *a, const struct Oss *b) { if(!a || !b) return 1; if(a->room != b->room) return -1; if(a->points != b->points) return -2; if(a->friends != b->friends) return -3; if(a->enemies != b->enemies) return -4; if(a->education != b->education) return -5; if(a->trouble != b->trouble) return -6; if(a->flags != b->flags) return -7; return 0; } /** get the query string */ static char *query(void) { /*'mac=[64]&room=xx&flags=xxxx&points=xxx&friends=xxx&ememies=xxx&education=xxx&trouble=xxx&choice=xx'*/ /*'mac=[64]&room=xx&flags=xxxx&points=xxx&friends=xxx&ememies=xxx&education=xxx&trouble=xxx&name=xxxxxxx'*/ static char post[192]; char *query = 0, *method; if(!(method = getenv("REQUEST_METHOD"))) return 0; if(!strcmp("POST", method)) { fgets(post, sizeof(post), stdin); query = post; } else if(!strcmp("GET", method)) { query = getenv("QUERY_STRING"); } else { printf("Undefined request method, "%s."
\n\n", method); } return query; } /** gets a query string "want" and advances the queryPtr, or does nothing if "want" is not arg */ static char *get_next(char **queryp, const char *want) { char *thing = 0, *query; /* paranoid */ if(!queryp || !(query = *queryp) || !want) return 0; /* thing is at '=', make sure the 'want' is actually what we have */ if(!(thing = strpbrk(query, "="))) return 0; if(strncmp(query, want, thing - query)) return 0; thing++; /* move to the next arg, return it and advance the query */ if((query = strpbrk(thing, "&"))) { *query = '\0'; query++; *queryp = query; } else { *queryp = 0; } return thing; } /** for MAC */ static char *status(const struct Oss *o) { static char status[64]; /* rXXfXXpXXfXXeXXeXXtXX */ snprintf(status, 64, "r%df%dp%df%de%de%dt%d", o->room, o->flags, o->points, o->friends, o->enemies, o->education, o->trouble); return status; } /** load game */ static char load(struct Oss *oss) { char *env, *q; char *sRoom, *sFlags, *sPoints, *sFriends, *sEnemies, *sEducation; char *sTrouble, *sChoice, *sHistory, choice; char *sMac, *cMac, *sName; int histSize; struct Oss *check; /* initial game state */ Oss(oss); /* check env vars */ if(!(env = getenv("REQUEST_METHOD")) || strcmp(env, "POST")) return 0; /* not valid referrer, show the hi-scores */ #ifdef NEIL if(!(env = getenv("HTTP_REFERER")) || strncmp(env, valid, strlen(valid))) { struct Hi hi; if(Hi(&hi)) HiPrint(&hi); else printf("Error loading high scores.
\n\n"); printf("Go back to the start of OSS game.
", start); printf("