From: Holger Schemel Date: Mon, 23 Nov 1998 21:20:33 +0000 (+0100) Subject: rnd-19981123-5 X-Git-Tag: 1.2.0^2~11 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=c020bbb83dd5b52a353fa867d7746a43eb5e6ffc;p=rocksndiamonds.git rnd-19981123-5 --- diff --git a/src/files.c b/src/files.c index b3a37e61..d28c1f48 100644 --- a/src/files.c +++ b/src/files.c @@ -212,6 +212,7 @@ static void InitUserDataDirectory() static void InitTapeDirectory(char *level_subdir) { + createDirectory(getUserDataDir(), "user data"); createDirectory(getTapeDir(""), "main tape"); createDirectory(getTapeDir(level_subdir), "level tape"); } @@ -226,6 +227,7 @@ static void InitUserLevelDirectory(char *level_subdir) { if (access(getUserLevelDir(level_subdir), F_OK) != 0) { + createDirectory(getUserDataDir(), "user data"); createDirectory(getUserLevelDir(""), "main user level"); createDirectory(getUserLevelDir(level_subdir), "user level"); @@ -599,11 +601,9 @@ void SaveTape(int level_nr) InitTapeDirectory(leveldir[leveldir_nr].filename); /* if a tape still exists, ask to overwrite it */ - if ((file = fopen(filename, "r"))) + if (access(filename, F_OK) == 0) { new_tape = FALSE; - fclose(file); - if (!Request("Replace old tape ?", REQ_ASK)) return; } @@ -1029,7 +1029,7 @@ static struct SetupFileList *loadSetupFileList(char *filename) if (!(file = fopen(filename, "r"))) { - Error(ERR_WARN, "cannot open setup/info file '%s'", filename); + Error(ERR_WARN, "cannot open configuration file '%s'", filename); return NULL; } @@ -1098,7 +1098,7 @@ static struct SetupFileList *loadSetupFileList(char *filename) freeSetupFileList(setup_file_list); if (first_valid_list_entry == NULL) - Error(ERR_WARN, "setup/info file '%s' is empty", filename); + Error(ERR_WARN, "configuration file '%s' is empty", filename); return first_valid_list_entry; } @@ -1113,7 +1113,7 @@ static void checkSetupFileListIdentifier(struct SetupFileList *setup_file_list, { if (strcmp(setup_file_list->value, identifier) != 0) { - Error(ERR_WARN, "setup/info file has wrong version"); + Error(ERR_WARN, "configuration file has wrong version"); return; } else @@ -1124,7 +1124,7 @@ static void checkSetupFileListIdentifier(struct SetupFileList *setup_file_list, checkSetupFileListIdentifier(setup_file_list->next, identifier); else { - Error(ERR_WARN, "setup/info file has no version information"); + Error(ERR_WARN, "configuration file has no version information"); return; } } @@ -1317,7 +1317,10 @@ static int LoadLevelInfoFromLevelDir(char *level_directory, int start_entry) int i, current_entry = start_entry; if ((dir = opendir(level_directory)) == NULL) - Error(ERR_EXIT, "cannot read level directory '%s'", level_directory); + { + Error(ERR_WARN, "cannot read level directory '%s'", level_directory); + return current_entry; + } while (current_entry < MAX_LEVDIR_ENTRIES) { @@ -1371,8 +1374,8 @@ static int LoadLevelInfoFromLevelDir(char *level_directory, int start_entry) closedir(dir); - if (current_entry == start_entry && start_entry != -1) - Error(ERR_EXIT, "cannot find any valid level series in directory '%s'", + if (current_entry == start_entry) + Error(ERR_WARN, "cannot find any valid level series in directory '%s'", level_directory); return current_entry; @@ -1389,6 +1392,10 @@ void LoadLevelInfo() num_leveldirs); num_leveldirs = LoadLevelInfoFromLevelDir(getUserLevelDir(""), num_leveldirs); + + if (num_leveldirs == 0) + Error(ERR_EXIT, "cannot find any valid level series in any directory"); + if (num_leveldirs > 1) qsort(leveldir, num_leveldirs, sizeof(struct LevelDirInfo), compareLevelDirInfoEntries); diff --git a/src/netserv.c b/src/netserv.c index 0417b80f..f29a19c8 100644 --- a/src/netserv.c +++ b/src/netserv.c @@ -30,13 +30,8 @@ #include "misc.h" static int clients = 0; -static int bots = 0; static int onceonly = 0; -static int timetoplay = 0; static int is_daemon = 0; -static int levelnr = 5; -static int mode = -1; -static int paused = 0; struct user { @@ -51,7 +46,6 @@ struct user unsigned char writbuf[MAX_BUFFER_SIZE]; int nwrite; char playing; - char isbot; int lines; unsigned int games; unsigned char action; @@ -162,13 +156,10 @@ static void dropuser(struct user *u) } } - if (u->isbot) - bots--; - free(u); clients--; - if (onceonly && clients == bots) + if (onceonly && clients == 0) { if (options.verbose) { @@ -177,13 +168,6 @@ static void dropuser(struct user *u) } exit(0); } - - if (clients == 0) - { - mode = -1; - levelnr = 5; - timetoplay = 0; - } } static void new_connect(int fd) @@ -201,7 +185,6 @@ static void new_connect(int fd) u->nread = 0; u->nwrite = 0; u->playing = 0; - u->isbot = 0; u->introduced = 0; u->games = 0; u->action = 0; @@ -354,19 +337,6 @@ static void Handle_OP_NICKNAME(struct user *u, unsigned int len) sendtoone(u, 2+strlen(v->nick)); } } - if (levelnr != 5) - { - buf[0] = 0; - buf[1] = OP_LEVEL; - buf[2] = levelnr; - sendtoone(u, 3); - } - if (mode >= 0) - { - buf[1] = OP_MODE; - buf[2] = mode; - sendtoone(u, 3); - } } u->introduced = 1; @@ -382,7 +352,6 @@ static void Handle_OP_START_PLAYING(struct user *u) (buf[2] << 8) + buf[3], (buf[4] << 8) + buf[5], &buf[6]); - timetoplay = 0; for (w=user0; w; w=w->next) { @@ -403,17 +372,6 @@ static void Handle_OP_START_PLAYING(struct user *u) } } - /* - if (paused) - { - paused = 0; - buf[1] = OP_CONT; - broadcast(NULL, 2, 0); - } - buf[1] = OP_START_PLAYING; - broadcast(NULL, 2, 0); - */ - /* reset frame counter */ frame_counter = 0; @@ -432,7 +390,6 @@ static void Handle_OP_PAUSE_PLAYING(struct user *u) if (options.verbose) printf("RND_SERVER: client %d (%s) pauses game\n", u->number, u->nick); broadcast(NULL, 2, 0); - paused = 1; } static void Handle_OP_CONTINUE_PLAYING(struct user *u) @@ -440,7 +397,6 @@ static void Handle_OP_CONTINUE_PLAYING(struct user *u) if (options.verbose) printf("RND_SERVER: client %d (%s) continues game\n", u->number, u->nick); broadcast(NULL, 2, 0); - paused = 0; } static void Handle_OP_STOP_PLAYING(struct user *u) @@ -508,7 +464,7 @@ static void Handle_OP_MOVE_FIGURE(struct user *u) void NetworkServer(int port, int serveronly) { int i, sl, on; - struct user *u, *v, *w; + struct user *u; int mfd; int r; unsigned int len; @@ -589,17 +545,6 @@ void NetworkServer(int port, int serveronly) { interrupt = 0; - /* - if (timetoplay && time(NULL) >= timetoplay) - { - buf[0] = 0; - do_play(); - if (options.verbose) - printf("RND_SERVER: everyone lost... restarting game\n"); - timetoplay = 0; - } - */ - for (u=user0; u; u=u->next) flushuser(u); @@ -626,15 +571,6 @@ void NetworkServer(int port, int serveronly) if (sl < 0) continue; - - if (clients > 0 && clients == bots) - { - if (options.verbose) - printf("RND_SERVER: only bots left... dropping all bots\n"); - while (user0) - dropuser(user0); - continue; - } if (sl == 0) continue; @@ -739,155 +675,12 @@ void NetworkServer(int port, int serveronly) Handle_OP_MOVE_FIGURE(u); break; - case OP_KILL: - for (v=user0; v; v=v->next) - { - if (v->number == buf[2]) - break; - } - if (v) - { - if (v->isbot) - { - if (options.verbose) - printf("RND_SERVER: client %d (%s) kills bot %d (%s)\n", u->number, u->nick, v->number, v->nick); - - dropuser(v); - interrupt = 1; - break; - } - else - { - if (options.verbose) - printf("RND_SERVER: client %d (%s) attempting to kill non-bot %d (%s)\n", u->number, u->nick, v->number, v->nick); - } - } - break; - - case OP_MODE: - mode = buf[2]; - if (options.verbose) - printf("RND_SERVER: client %d (%s) sets mode %d (%s)\n", u->number, u->nick, buf[2], buf[2] == 0 ? "normal" : (buf[2] == 1 ? "fun" : "unknown")); - broadcast(NULL, 3, 0); - break; - - case OP_BOT: - if (!u->isbot) - bots++; - u->isbot = 1; - if (options.verbose) - printf("RND_SERVER: client %d (%s) declares itself to be a bot\n", u->number, u->nick); - break; - - case OP_LEVEL: - levelnr = buf[2]; - if (options.verbose) - printf("RND_SERVER: client %d (%s) sets level %d\n", u->number, u->nick, buf[2]); - broadcast(NULL, 3, 0); - break; - - case OP_LOST: - { - struct user *won = NULL; - - if (options.verbose) - printf("RND_SERVER: client %d (%s) has lost\n", u->number, u->nick); - u->playing = 0; - broadcast(u, 2, 1); - i = 0; - for (v=user0; v; v=v->next) - { - if (v->nextvictim == u) - { - for (w=NEXT(v); w!=v; w=NEXT(w)) - { - if (w->active && w->playing) - { - v->nextvictim = w; - break; - } - } - if (v->nextvictim == u) - v->nextvictim = NULL; - } - } - for (v=user0; v; v=v->next) - { - if (v->playing) - { - i++; - won = v; - } - } - if (i == 1) - { - buf[0] = won->number; - buf[1] = OP_WON; - won->games++; - broadcast(NULL, 2, 0); - } - else if (i == 0) - { - buf[0] = u->number; - buf[1] = OP_WON; - u->games++; - broadcast(NULL, 2, 0); - } - if (i < 2 && clients > 1) - timetoplay = time(NULL) + 4; - } - break; - - case OP_ZERO: - broadcast(NULL, 2, 0); - if (options.verbose) - printf("RND_SERVER: client %d (%s) resets the game counters\n", u->number, u->nick); - for (v=user0; v; v=v->next) - v->games = 0; - break; - - case OP_CLEAR: - case OP_GROW: - broadcast(u, 2, 1); - break; - case OP_MSG: buf[len] = '\0'; if (options.verbose) printf("RND_SERVER: client %d (%s) sends message: %s\n", u->number, u->nick, &buf[2]); broadcast(u, len, 0); break; - - case OP_LINES: - if (len != 3) - { - if (options.verbose) - printf("RND_SERVER: client %d (%s) sends crap for an OP_LINES\n", u->number, u->nick); - - dropuser(u); - interrupt = 1; - break; - } - if (u->nextvictim) - { - if (options.verbose) - printf("RND_SERVER: client %d (%s) sends %d %s to client %d (%s)\n", u->number, u->nick, (int)buf[2], buf[2] == 1 ? "line" : "lines", u->nextvictim->number, u->nextvictim->nick); - sendtoone(u->nextvictim, 3); - buf[3] = u->nextvictim->number; - buf[1] = OP_LINESTO; - broadcast(u->nextvictim, 4, 1); - for (v=NEXT(u->nextvictim); v!=u->nextvictim; v=NEXT(v)) - { - if (v->active && v != u && v->playing) - { - u->nextvictim = v; - break; - } - } - } - else if (options.verbose) - printf("RND_SERVER: client %d (%s) makes %d %s but has no victim\n", u->number, u->nick, (int)buf[2], buf[2] == 1 ? "line" : "lines"); - break; default: if (options.verbose) diff --git a/src/network.c b/src/network.c index 8af73075..2bf2346f 100644 --- a/src/network.c +++ b/src/network.c @@ -660,26 +660,10 @@ static void HandleNetworkingMessages() sysmsg(msgbuf); break; - case OP_ZERO: - printf("OP_ZERO: %d\n", buf[0]); - sprintf(msgbuf, "client %d resets game counters", buf[0]); - sysmsg(msgbuf); - break; - case OP_MSG: printf("OP_MSG: %d\n", buf[0]); sprintf(msgbuf, "client %d sends message", buf[0]); break; - - case OP_LOST: - printf("OP_MSG: %d\n", buf[0]); - sprintf(msgbuf, "client %d has lost", buf[0]); - break; - - case OP_LEVEL: - printf("OP_MSG: %d\n", buf[0]); - sprintf(msgbuf, "client %d sets level to %d", buf[0], buf[2]); - break; } }