aboutsummaryrefslogtreecommitdiffstats
path: root/scoretbl.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2003-03-28 05:00:09 +0000
committerH. Peter Anvin <hpa@zytor.com>2003-03-28 05:00:09 +0000
commit22c861e95c569911ed7398fe7fc64b69dcbb5dc4 (patch)
tree41ff2d545b1358d182be411a8115616d1aca9081 /scoretbl.c
parentc3aadb29c59e52d4a7cca3a1dc269a3c388695ff (diff)
downloadgrv-22c861e95c569911ed7398fe7fc64b69dcbb5dc4.tar.gz
grv-22c861e95c569911ed7398fe7fc64b69dcbb5dc4.tar.xz
grv-22c861e95c569911ed7398fe7fc64b69dcbb5dc4.zip
Try to fix broken Windows networking... *sigh*
Diffstat (limited to 'scoretbl.c')
-rw-r--r--scoretbl.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/scoretbl.c b/scoretbl.c
index 4ccfd3d..c9932b5 100644
--- a/scoretbl.c
+++ b/scoretbl.c
@@ -157,9 +157,11 @@ static char *quote(const unsigned char *i)
/*
* Parse an incoming high-score table. It can come either from the network
- * or from a file.
+ * or from a file. Because Windows is braindamaged and doesn't have any
+ * kind of sane way to use the stdio library with sockets, we have to abstract
+ * out the I/O function that is allowed to access this. Puke.
*/
-void highscore_parse(FILE *f)
+void highscore_parse(void *f, char (*mygets)(char *, int, void *))
{
char line[MAXLINE], pname[MAXLINE];
uint64_t gameid;
@@ -168,7 +170,7 @@ void highscore_parse(FILE *f)
int lvl;
unsigned char *pptr;
- while ( fgets(line, MAXLINE, f) ) {
+ while ( mygets(line, MAXLINE, f) ) {
if ( !strchr(line, '\n') )
return; /* Something bogus here... */
@@ -192,32 +194,39 @@ void highscore_parse(FILE *f)
/*
* Write out a high score file; return 0 on success, -1 on failure
*/
-int highscore_write(FILE *f)
+int highscore_write(void *f, int (*myputs)(char *, void *))
{
+ char buffer[MAXLINE];
int i, j;
- fprintf(f, "VC 1.0\n"); /* Version C 1.0 */
+ myputs("VC 1.0\n", f); /* Version C 1.0 */
for ( i = 0 ; i < MAX_BEST ; i++ ) {
if ( bests.total[i].score ) {
- fprintf(f, "TS %llx %lld %d %s\n", bests.total[i].gameid,
+ sprintf(buffer, "TS %llx %lld %d %s\n", bests.total[i].gameid,
bests.total[i].score, bests.total[i].endlvl+1,
quote(bests.total[i].player));
+ if ( myputs(buffer, f) )
+ return -1;
}
}
for ( i = 0 ; i < MAX_LEVEL ; i++ ) {
for ( j = 0 ; j < MAX_PER_LEVEL ; j++ ) {
if ( bests.level[i].score[j].score )
- fprintf(f, "LS %llx %d %lld\n", bests.level[i].score[j].gameid,
+ sprintf(buffer, "LS %llx %d %lld\n", bests.level[i].score[j].gameid,
i+1, bests.level[i].score[j].score);
+ if ( myputs(buffer, f) )
+ return -1;
}
for ( j = 0 ; j < MAX_PER_LEVEL ; j++ ) {
if ( bests.level[i].time_ms[j].time_ms != NO_TIME )
- fprintf(f, "LT %llx %d %d\n", bests.level[i].time_ms[j].gameid,
+ sprintf(f, "LT %llx %d %d\n", bests.level[i].time_ms[j].gameid,
i+1, bests.level[i].time_ms[j].time_ms);
+ if ( myputs(buffer, f) )
+ return -1;
}
}
- return ferror(f);
+ return 0;
}