From 19e168a132d1c0543a13cbf9495f579c137dea94 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Wed, 25 Nov 1998 13:08:27 +0100 Subject: [PATCH] rnd-19981124-1 --- src/files.c | 2 +- src/game.c | 4 +- src/init.c | 4 +- src/main.c | 1 - src/main.h | 5 +- src/misc.c | 6 +- src/misc.h | 8 +- src/netserv.c | 247 +++++++++++-------------- src/netserv.h | 22 +-- src/network.c | 504 ++++++++++++++++++++------------------------------ src/network.h | 2 +- src/sound.c | 8 +- 12 files changed, 338 insertions(+), 475 deletions(-) diff --git a/src/files.c b/src/files.c index dfd9c85f..daaaaa72 100644 --- a/src/files.c +++ b/src/files.c @@ -698,7 +698,7 @@ void LoadScore(int level_nr) /* always start with reliable default values */ for(i=0; iscore < highscore[MAX_SCORE_ENTRIES-1].Score) + if (strcmp(setup.player_name, EMPTY_PLAYER_NAME) == 0 || + local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score) return -1; for (k=0; k #include #include -#include #include #include +#include #ifndef MSDOS #define XK_MISCELLANY @@ -433,7 +433,6 @@ extern int FrameCounter, TimeFrames, TimeLeft; extern int MampferNr, SiebAktiv; extern boolean network_player_action_received; -extern int TestPlayer; extern struct LevelDirInfo leveldir[]; extern struct LevelInfo level; @@ -1065,7 +1064,7 @@ extern int num_bg_loops; #define COPYRIGHT_STRING "Copyright ^1995-98 by Holger Schemel" /* default name for empty highscore entry */ -#define EMPTY_ALIAS "NO_NAME" +#define EMPTY_PLAYER_NAME "no name" /* values for button_status */ #define MB_NOT_PRESSED FALSE diff --git a/src/misc.c b/src/misc.c index f17c52d3..5da20e36 100644 --- a/src/misc.c +++ b/src/misc.c @@ -421,8 +421,12 @@ void Error(int mode, char *format, ...) FILE *output_stream = stderr; char *process_name = ""; - if (mode & ERR_SOUNDSERVER) + if (mode & ERR_SOUND_SERVER) process_name = " sound server"; + else if (mode & ERR_NETWORK_SERVER) + process_name = " network server"; + else if (mode & ERR_NETWORK_CLIENT) + process_name = " network client **"; if (format) { diff --git a/src/misc.h b/src/misc.h index 83aa074f..f48bf346 100644 --- a/src/misc.h +++ b/src/misc.h @@ -25,9 +25,13 @@ #define ERR_WARN (1 << 0) #define ERR_EXIT (1 << 1) #define ERR_HELP (1 << 2) -#define ERR_SOUNDSERVER (1 << 3) +#define ERR_SOUND_SERVER (1 << 3) +#define ERR_NETWORK_SERVER (1 << 4) +#define ERR_NETWORK_CLIENT (1 << 5) #define ERR_EXIT_HELP (ERR_EXIT | ERR_HELP) -#define ERR_EXIT_SOUNDSERVER (ERR_EXIT | ERR_SOUNDSERVER) +#define ERR_EXIT_SOUND_SERVER (ERR_EXIT | ERR_SOUND_SERVER) +#define ERR_EXIT_NETWORK_SERVER (ERR_EXIT | ERR_NETWORK_SERVER) +#define ERR_EXIT_NETWORK_CLIENT (ERR_EXIT | ERR_NETWORK_CLIENT) void InitCounter(void); unsigned long Counter(void); diff --git a/src/netserv.c b/src/netserv.c index 49bc51e7..6f5a9a4c 100644 --- a/src/netserv.c +++ b/src/netserv.c @@ -11,11 +11,8 @@ * network.c * ***********************************************************/ -#include -#include #include #include -#include #include #include #include @@ -33,25 +30,22 @@ static int clients = 0; static int onceonly = 0; static int is_daemon = 0; -struct user +struct NetworkServerPlayerInfo { int fd; - unsigned char nick[16]; + unsigned char player_name[16]; unsigned char number; - struct user *next, *nextvictim; + struct NetworkServerPlayerInfo *next; char active; char introduced; unsigned char readbuf[MAX_BUFFER_SIZE]; - int nread; unsigned char writbuf[MAX_BUFFER_SIZE]; - int nwrite; - char playing; - unsigned int games; - unsigned char action; - int action_received; + int nread, nwrite; + byte action; + boolean action_received; }; -static struct user *user0 = NULL; +static struct NetworkServerPlayerInfo *user0 = NULL; #define NEXT(u) ((u)->next ? (u)->next : user0) @@ -62,7 +56,7 @@ static unsigned char realbuf[512], *buf = realbuf + 4; static int interrupt; static int tcp = -1; -static unsigned long frame_counter = 0; +static unsigned long ServerFrameCounter = 0; static fd_set fds; @@ -73,7 +67,8 @@ static void syserr(char *s) exit(1); } -static void addtobuffer(struct user *u, unsigned char *b, int len) +static void addtobuffer(struct NetworkServerPlayerInfo *u, + unsigned char *b, int len) { if (u->nwrite + len >= MAX_BUFFER_SIZE) Error(ERR_EXIT, "internal error: network send buffer overflow"); @@ -82,7 +77,7 @@ static void addtobuffer(struct user *u, unsigned char *b, int len) u->nwrite += len; } -static void flushuser(struct user *u) +static void flushuser(struct NetworkServerPlayerInfo *u) { if (u->nwrite) { @@ -91,9 +86,10 @@ static void flushuser(struct user *u) } } -static void broadcast(struct user *except, int len, int activeonly) +static void broadcast(struct NetworkServerPlayerInfo *except, + int len, int activeonly) { - struct user *u; + struct NetworkServerPlayerInfo *u; realbuf[0] = realbuf[1] = realbuf[2] = 0; realbuf[3] = (unsigned char)len; @@ -102,19 +98,20 @@ static void broadcast(struct user *except, int len, int activeonly) addtobuffer(u, realbuf, 4 + len); } -static void sendtoone(struct user *to, int len) +static void sendtoone(struct NetworkServerPlayerInfo *to, int len) { realbuf[0] = realbuf[1] = realbuf[2] = 0; realbuf[3] = (unsigned char)len; addtobuffer(to, realbuf, 4 + len); } -static void dropuser(struct user *u) +static void dropuser(struct NetworkServerPlayerInfo *u) { - struct user *v, *w; + struct NetworkServerPlayerInfo *v; if (options.verbose) - printf("RND_SERVER: dropping client %d (%s)\n", u->number, u->nick); + Error(ERR_NETWORK_SERVER, "dropping client %d (%s)", + u->number, u->player_name); if (u == user0) user0 = u->next; @@ -138,23 +135,6 @@ static void dropuser(struct user *u) broadcast(u, 2, 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; - } - } - free(u); clients--; @@ -162,8 +142,8 @@ static void dropuser(struct user *u) { if (options.verbose) { - printf("RND_SERVER: no clients left\n"); - printf("RND_SERVER: aborting\n"); + Error(ERR_NETWORK_SERVER, "no clients left"); + Error(ERR_NETWORK_SERVER, "aborting"); } exit(0); } @@ -171,23 +151,20 @@ static void dropuser(struct user *u) static void new_connect(int fd) { - struct user *u, *v; + struct NetworkServerPlayerInfo *u, *v; unsigned char nxn; - u = checked_malloc(sizeof (struct user)); + u = checked_malloc(sizeof (struct NetworkServerPlayerInfo)); u->fd = fd; - u->nick[0] = 0; + u->player_name[0] = 0; u->next = user0; - u->nextvictim = NULL; u->active = 0; u->nread = 0; u->nwrite = 0; - u->playing = 0; u->introduced = 0; - u->games = 0; u->action = 0; - u->action_received = 0; + u->action_received = FALSE; user0 = u; @@ -207,7 +184,8 @@ static void new_connect(int fd) u->number = nxn; if (options.verbose) - printf("RND_SERVER: client %d connecting from %s\n", nxn, inet_ntoa(saddr.sin_addr)); + Error(ERR_NETWORK_SERVER, "client %d connecting from %s", + nxn, inet_ntoa(saddr.sin_addr)); clients++; buf[0] = 0; @@ -216,15 +194,18 @@ static void new_connect(int fd) sendtoone(u, 3); } -static void Handle_OP_PROTOCOL_VERSION(struct user *u, unsigned int len) +static void Handle_OP_PROTOCOL_VERSION(struct NetworkServerPlayerInfo *u, + unsigned int len) { if (len != 5 || buf[2] != PROTOCOL_VERSION_1 || buf[3] != PROTOCOL_VERSION_2) { if (options.verbose) - printf("RND_SERVER: client %d (%s) has wrong protocol version %d.%d.%d\n", u->number, u->nick, buf[2], buf[3], buf[4]); + Error(ERR_NETWORK_SERVER, + "client %d (%s) has wrong protocol version %d.%d.%d", + u->number, u->player_name, buf[2], buf[3], buf[4]); buf[0] = 0; - buf[1] = OP_BADVERS; + buf[1] = OP_BAD_PROTOCOL_VERSION; buf[2] = PROTOCOL_VERSION_1; buf[3] = PROTOCOL_VERSION_2; buf[4] = PROTOCOL_VERSION_3; @@ -237,20 +218,22 @@ static void Handle_OP_PROTOCOL_VERSION(struct user *u, unsigned int len) else { if (options.verbose) - printf("RND_SERVER: client %d (%s) uses protocol version %d.%d.%d\n", u->number, u->nick, buf[2], buf[3], buf[4]); + Error(ERR_NETWORK_SERVER, + "client %d (%s) uses protocol version %d.%d.%d", + u->number, u->player_name, buf[2], buf[3], buf[4]); } } -static void Handle_OP_NUMBER_WANTED(struct user *u) +static void Handle_OP_NUMBER_WANTED(struct NetworkServerPlayerInfo *u) { - struct user *v; + struct NetworkServerPlayerInfo *v; int client_nr = u->number; int nr_wanted = buf[2]; int nr_is_free = 1; if (options.verbose) - printf("RND_SERVER: client %d (%s) wants to switch to # %d\n", - u->number, u->nick, nr_wanted); + Error(ERR_NETWORK_SERVER, "client %d (%s) wants to switch to # %d", + u->number, u->player_name, nr_wanted); for (v=user0; v; v=v->next) { @@ -264,14 +247,15 @@ static void Handle_OP_NUMBER_WANTED(struct user *u) if (options.verbose) { if (nr_is_free) - printf("RND_SERVER: client %d (%s) switches to # %d\n", - u->number, u->nick, nr_wanted); + Error(ERR_NETWORK_SERVER, "client %d (%s) switches to # %d", + u->number, u->player_name, nr_wanted); else if (u->number == nr_wanted) - printf("RND_SERVER: client %d (%s) still has # %d\n", - u->number, u->nick, nr_wanted); + Error(ERR_NETWORK_SERVER, "client %d (%s) still has # %d", + u->number, u->player_name, nr_wanted); else - printf("RND_SERVER: client %d (%s) cannot switch (client %d still exists)\n", - u->number, u->nick, nr_wanted); + Error(ERR_NETWORK_SERVER, + "client %d (%s) cannot switch (client %d still exists)", + u->number, u->player_name, nr_wanted); } if (nr_is_free) @@ -289,21 +273,22 @@ static void Handle_OP_NUMBER_WANTED(struct user *u) broadcast(NULL, 4, 0); } -static void Handle_OP_NICKNAME(struct user *u, unsigned int len) +static void Handle_OP_PLAYER_NAME(struct NetworkServerPlayerInfo *u, + unsigned int len) { - struct user *v; + struct NetworkServerPlayerInfo *v; int i; if (len>16) len=16; - memcpy(u->nick, &buf[2], len-2); - u->nick[len-2] = 0; + memcpy(u->player_name, &buf[2], len-2); + u->player_name[len-2] = 0; for (i=0; inick[i] < ' ' || - (u->nick[i] > 0x7e && u->nick[i] <= 0xa0)) + if (u->player_name[i] < ' ' || + (u->player_name[i] > 0x7e && u->player_name[i] <= 0xa0)) { - u->nick[i] = 0; + u->player_name[i] = 0; break; } } @@ -316,8 +301,9 @@ static void Handle_OP_NICKNAME(struct user *u, unsigned int len) } if (options.verbose) - printf("RND_SERVER: client %d calls itself \"%s\"\n", u->number, u->nick); - buf[1] = OP_NICKNAME; + Error(ERR_NETWORK_SERVER, "client %d calls itself \"%s\"", + u->number, u->player_name); + buf[1] = OP_PLAYER_NAME; broadcast(u, len, 0); if (!u->introduced) @@ -328,12 +314,10 @@ static void Handle_OP_NICKNAME(struct user *u, unsigned int len) { buf[0] = v->number; buf[1] = OP_PLAYER_CONNECTED; - buf[2] = (v->games >> 8); - buf[3] = (v->games & 0xff); - sendtoone(u, 4); - buf[1] = OP_NICKNAME; - memcpy(&buf[2], v->nick, 14); - sendtoone(u, 2+strlen(v->nick)); + sendtoone(u, 2); + buf[1] = OP_PLAYER_NAME; + memcpy(&buf[2], v->player_name, 14); + sendtoone(u, 2+strlen(v->player_name)); } } } @@ -341,72 +325,62 @@ static void Handle_OP_NICKNAME(struct user *u, unsigned int len) u->introduced = 1; } -static void Handle_OP_START_PLAYING(struct user *u) +static void Handle_OP_START_PLAYING(struct NetworkServerPlayerInfo *u) { - struct user *v, *w; + struct NetworkServerPlayerInfo *v, *w; if (options.verbose) - printf("RND_SERVER: client %d (%s) starts game [level %d from levedir %d (%s)]\n", - u->number, u->nick, - (buf[2] << 8) + buf[3], - (buf[4] << 8) + buf[5], - &buf[6]); + Error(ERR_NETWORK_SERVER, + "client %d (%s) starts game [level %d from levedir %d (%s)]", + u->number, u->player_name, + (buf[2] << 8) + buf[3], + (buf[4] << 8) + buf[5], + &buf[6]); for (w=user0; w; w=w->next) - { if (w->introduced) - { w->active = 1; - w->playing = 1; - w->nextvictim = NULL; - for (v=NEXT(w); v!=w; v=NEXT(v)) - { - if (v->introduced) - { - w->nextvictim = v; - break; - } - } - } - } /* reset frame counter */ - frame_counter = 0; + ServerFrameCounter = 0; /* reset player actions */ for (v=user0; v; v=v->next) { v->action = 0; - v->action_received = 0; + v->action_received = FALSE; } broadcast(NULL, 10 + strlen(&buf[10])+1, 0); } -static void Handle_OP_PAUSE_PLAYING(struct user *u) +static void Handle_OP_PAUSE_PLAYING(struct NetworkServerPlayerInfo *u) { if (options.verbose) - printf("RND_SERVER: client %d (%s) pauses game\n", u->number, u->nick); + Error(ERR_NETWORK_SERVER, "client %d (%s) pauses game", + u->number, u->player_name); broadcast(NULL, 2, 0); } -static void Handle_OP_CONTINUE_PLAYING(struct user *u) +static void Handle_OP_CONTINUE_PLAYING(struct NetworkServerPlayerInfo *u) { if (options.verbose) - printf("RND_SERVER: client %d (%s) continues game\n", u->number, u->nick); + Error(ERR_NETWORK_SERVER, "client %d (%s) continues game", + u->number, u->player_name); broadcast(NULL, 2, 0); } -static void Handle_OP_STOP_PLAYING(struct user *u) +static void Handle_OP_STOP_PLAYING(struct NetworkServerPlayerInfo *u) { if (options.verbose) - printf("RND_SERVER: client %d (%s) stops game\n", u->number, u->nick); + Error(ERR_NETWORK_SERVER, "client %d (%s) stops game", + u->number, u->player_name); broadcast(NULL, 2, 0); } -static void Handle_OP_MOVE_FIGURE(struct user *u) +static void Handle_OP_MOVE_FIGURE(struct NetworkServerPlayerInfo *u) { - struct user *v; + struct NetworkServerPlayerInfo *v; int last_client_nr = 0; int i; @@ -416,7 +390,7 @@ static void Handle_OP_MOVE_FIGURE(struct user *u) if (v->number == u->number) { v->action = buf[2]; - v->action_received = 1; + v->action_received = TRUE; } } @@ -439,30 +413,23 @@ static void Handle_OP_MOVE_FIGURE(struct user *u) { buf[6 + v->number-1] = v->action; v->action = 0; - v->action_received = 0; + v->action_received = FALSE; } - buf[2] = (unsigned char)((frame_counter >> 24) & 0xff); - buf[3] = (unsigned char)((frame_counter >> 16) & 0xff); - buf[4] = (unsigned char)((frame_counter >> 8) & 0xff); - buf[5] = (unsigned char)((frame_counter >> 0) & 0xff); + buf[2] = (unsigned char)((ServerFrameCounter >> 24) & 0xff); + buf[3] = (unsigned char)((ServerFrameCounter >> 16) & 0xff); + buf[4] = (unsigned char)((ServerFrameCounter >> 8) & 0xff); + buf[5] = (unsigned char)((ServerFrameCounter >> 0) & 0xff); broadcast(NULL, 6 + last_client_nr, 0); - frame_counter++; - - /* - if (verbose) - printf("RND_SERVER: frame %d: client %d (%s) moves player [0x%02x]\n", - frame_counter, - u->number, u->nick, buf[2]); - */ + ServerFrameCounter++; } void NetworkServer(int port, int serveronly) { int i, sl, on; - struct user *u; + struct NetworkServerPlayerInfo *u; int mfd; int r; unsigned int len; @@ -475,7 +442,7 @@ void NetworkServer(int port, int serveronly) #endif if (port == 0) - port = DEFAULTPORT; + port = DEFAULT_SERVER_PORT; if (!serveronly) onceonly = 1; @@ -533,10 +500,9 @@ void NetworkServer(int port, int serveronly) if (options.verbose) { - printf("rocksndiamonds network server: started up, listening on port %d\n", - port); - printf("rocksndiamonds network server: using protocol version %d.%d.%d\n", - PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, PROTOCOL_VERSION_3); + Error(ERR_NETWORK_SERVER, "started up, listening on port %d", port); + Error(ERR_NETWORK_SERVER, "using protocol version %d.%d.%d", + PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, PROTOCOL_VERSION_3); } while(1) @@ -606,7 +572,8 @@ void NetworkServer(int port, int serveronly) if (r <= 0) { if (options.verbose) - printf("RND_SERVER: EOF from client %d (%s)\n", u->number, u->nick); + Error(ERR_NETWORK_SERVER, "EOF from client %d (%s)", + u->number, u->player_name); dropuser(u); interrupt = 1; break; @@ -618,7 +585,8 @@ void NetworkServer(int port, int serveronly) if (u->readbuf[0] || u->readbuf[1] || u->readbuf[2]) { if (options.verbose) - printf("RND_SERVER: crap from client %d (%s)\n", u->number, u->nick); + Error(ERR_NETWORK_SERVER, "crap from client %d (%s)", + u->number, u->player_name); write(u->fd, "\033]50;kanji24\007\033#8\033(0", 19); dropuser(u); interrupt = 1; @@ -629,10 +597,10 @@ void NetworkServer(int port, int serveronly) memmove(u->readbuf, u->readbuf + 4 + len, u->nread); buf[0] = u->number; - if (!u->introduced && buf[1] != OP_NICKNAME) + if (!u->introduced && buf[1] != OP_PLAYER_NAME) { if (options.verbose) - printf("RND_SERVER: !(client %d)->introduced && buf[1]==%d (expected OP_NICKNAME)\n", buf[0], buf[1]); + Error(ERR_NETWORK_SERVER, "!(client %d)->introduced && buf[1]==%d (expected OP_PLAYER_NAME)", buf[0], buf[1]); dropuser(u); interrupt = 1; @@ -641,8 +609,8 @@ void NetworkServer(int port, int serveronly) switch(buf[1]) { - case OP_NICKNAME: - Handle_OP_NICKNAME(u, len); + case OP_PLAYER_NAME: + Handle_OP_PLAYER_NAME(u, len); break; case OP_PROTOCOL_VERSION: @@ -673,16 +641,19 @@ void NetworkServer(int port, int serveronly) Handle_OP_MOVE_FIGURE(u); break; - case OP_MSG: + case OP_BROADCAST_MESSAGE: buf[len] = '\0'; if (options.verbose) - printf("RND_SERVER: client %d (%s) sends message: %s\n", u->number, u->nick, &buf[2]); + Error(ERR_NETWORK_SERVER, "client %d (%s) sends message: %s", + u->number, u->player_name, &buf[2]); broadcast(u, len, 0); break; default: if (options.verbose) - printf("RND_SERVER: opcode %d from client %d (%s) not understood\n", buf[0], u->number, u->nick); + Error(ERR_NETWORK_SERVER, + "unknown opcode %d from client %d (%s)", + buf[0], u->number, u->player_name); } } } diff --git a/src/netserv.h b/src/netserv.h index 69d24202..5177fb4a 100644 --- a/src/netserv.h +++ b/src/netserv.h @@ -14,7 +14,9 @@ #ifndef NETSERV_H #define NETSERV_H -#define DEFAULTPORT 19504 +#include "main.h" + +#define DEFAULT_SERVER_PORT 19504 #define PROTOCOL_VERSION_1 1 #define PROTOCOL_VERSION_2 2 @@ -24,7 +26,7 @@ #define OP_BAD_PROTOCOL_VERSION 2 #define OP_YOUR_NUMBER 3 #define OP_NUMBER_WANTED 4 -#define OP_NICKNAME 5 +#define OP_PLAYER_NAME 5 #define OP_PLAYER_CONNECTED 6 #define OP_PLAYER_DISCONNECTED 7 #define OP_START_PLAYING 8 @@ -32,21 +34,7 @@ #define OP_CONTINUE_PLAYING 10 #define OP_STOP_PLAYING 11 #define OP_MOVE_FIGURE 12 - -#define OP_LOST 13 -#define OP_CLEAR 14 -#define OP_LINES 15 -#define OP_GROW 16 -#define OP_MODE 17 -#define OP_LEVEL 18 -#define OP_BOT 19 -#define OP_KILL 20 -#define OP_BADVERS 21 -#define OP_MSG 22 -#define OP_YOUARE 23 -#define OP_LINESTO 24 -#define OP_WON 25 -#define OP_ZERO 26 +#define OP_BROADCAST_MESSAGE 13 #define MAX_BUFFER_SIZE 4096 diff --git a/src/network.c b/src/network.c index 2bf2346f..9a58a7df 100644 --- a/src/network.c +++ b/src/network.c @@ -11,11 +11,8 @@ * network.c * ***********************************************************/ -#include -#include #include #include -#include #include #include #include @@ -23,7 +20,6 @@ #include #include #include -#include #include "network.h" #include "netserv.h" @@ -35,103 +31,79 @@ #include "screens.h" #include "misc.h" -#define MAXNICKLEN 14 +#define MAX_PLAYER_NAME_LEN 14 -struct user +struct NetworkClientPlayerInfo { byte nr; - char name[MAXNICKLEN+2]; - struct user *next; + char name[MAX_PLAYER_NAME_LEN + 2]; + struct NetworkClientPlayerInfo *next; }; -struct user me = +static struct NetworkClientPlayerInfo first_player = { 0, - "no name", + EMPTY_PLAYER_NAME, NULL }; -static char msgbuf[300]; - /* server stuff */ -int sfd; -unsigned char realbuf[512], readbuf[MAX_BUFFER_SIZE], writbuf[MAX_BUFFER_SIZE]; -unsigned char *buf = realbuf + 4; -int nread = 0, nwrite = 0; - -static void sysmsg(char *s) -{ - if (options.verbose) - { - printf("** %s\n", s); - fflush(stdout); - } -} - -static void u_sleep(int i) -{ - struct timeval tm; - tm.tv_sec = i / 1000000; - tm.tv_usec = i % 1000000; - select(0, NULL, NULL, NULL, &tm); -} - -static void flushbuf() -{ - if (nwrite) - { - write(sfd, writbuf, nwrite); - nwrite = 0; - } -} +static int sfd; +static byte realbuffer[512]; +static byte readbuffer[MAX_BUFFER_SIZE], writbuffer[MAX_BUFFER_SIZE]; +static byte *buffer = realbuffer + 4; +static int nread = 0, nwrite = 0; -static void sendbuf(int len) +static void SendBufferToServer(int size) { - if (options.network) - { - realbuf[0] = realbuf[1] = realbuf[2] = 0; - realbuf[3] = (unsigned char)len; - buf[0] = 0; - if (nwrite + 4 + len >= MAX_BUFFER_SIZE) - Error(ERR_EXIT, "internal error: network send buffer overflow"); - memcpy(writbuf + nwrite, realbuf, 4 + len); - nwrite += 4 + len; + if (!options.network) + return; + realbuffer[0] = realbuffer[1] = realbuffer[2] = 0; + realbuffer[3] = (byte)size; + buffer[0] = 0; - flushbuf(); + if (nwrite + 4 + size >= MAX_BUFFER_SIZE) + Error(ERR_EXIT, "internal error: network send buffer overflow"); + memcpy(writbuffer + nwrite, realbuffer, 4 + size); + nwrite += 4 + size; - } + /* directly send the buffer to the network server */ + write(sfd, writbuffer, nwrite); + nwrite = 0; } -struct user *finduser(unsigned char c) +struct NetworkClientPlayerInfo *getNetworkPlayer(int player_nr) { - struct user *u; + struct NetworkClientPlayerInfo *player = NULL; + + for (player = &first_player; player; player = player->next) + if (player->nr == player_nr) + break; - for (u = &me; u; u = u->next) - if (u->nr == c) - return u; - - Error(ERR_EXIT, "protocol error: reference to non-existing user %d", c); + if (player == NULL) /* should not happen */ + Error(ERR_EXIT, "protocol error: reference to non-existing player %d", + player_nr); - return NULL; /* so that gcc -Wall doesn't complain */ + return player; } -char *get_user_name(unsigned char c) +char *getNetworkPlayerName(int player_nr) { - struct user *u; + struct NetworkClientPlayerInfo *player; - if (c == 0) - return("the server"); - else if (c == me.nr) + if (player_nr == 0) + return("the network game server"); + else if (player_nr == first_player.nr) return("you"); else - for (u = &me; u; u = u->next) - if (u->nr == c && u->name && strlen(u->name)) - return(u->name); + for (player=&first_player; player; player=player->next) + if (player->nr == player_nr && player->name && strlen(player->name)) + return(player->name); - return("no name"); + return(EMPTY_PLAYER_NAME); } static void StartNetworkServer(int port) @@ -146,7 +118,7 @@ static void StartNetworkServer(int port) case -1: Error(ERR_WARN, - "cannot create network server process - no network games"); + "cannot create network server process - no network playing"); options.network = FALSE; return; @@ -156,29 +128,29 @@ static void StartNetworkServer(int port) } } -boolean ConnectToServer(char *host, int port) +boolean ConnectToServer(char *hostname, int port) { - struct hostent *hp; struct sockaddr_in s; struct protoent *tcpproto; int on = 1, i; - if (host) + if (hostname) { - if ((s.sin_addr.s_addr = inet_addr(host)) == -1) + if ((s.sin_addr.s_addr = inet_addr(hostname)) == -1) { - hp = gethostbyname(host); - if (!hp) - Error(ERR_EXIT, "cannot locate host '%s'", host); + struct hostent *host; - s.sin_addr = *(struct in_addr *)(hp->h_addr_list[0]); + if ((host = gethostbyname(hostname)) == NULL) + Error(ERR_EXIT, "cannot locate host '%s'", hostname); + + s.sin_addr = *(struct in_addr *)(host->h_addr_list[0]); } } else - s.sin_addr.s_addr = inet_addr("127.0.0.1"); + s.sin_addr.s_addr = inet_addr("127.0.0.1"); /* localhost */ if (port == 0) - port = DEFAULTPORT; + port = DEFAULT_SERVER_PORT; s.sin_port = htons(port); s.sin_family = AF_INET; @@ -190,135 +162,129 @@ boolean ConnectToServer(char *host, int port) if ((tcpproto = getprotobyname("tcp")) != NULL) setsockopt(sfd, tcpproto->p_proto, TCP_NODELAY, (char *)&on, sizeof(int)); - if (connect(sfd, (struct sockaddr *)&s, sizeof(s)) < 0) - { - if (!host) - { - printf("No rocksndiamonds server on localhost - starting up one ...\n"); + if (connect(sfd, (struct sockaddr *)&s, sizeof(s)) == 0) /* connected */ + return TRUE; - StartNetworkServer(port); + if (hostname) /* connect to specified server failed */ + return FALSE; - for (i=0; i<6; i++) - { - u_sleep(500000); - close(sfd); + printf("No rocksndiamonds server on localhost - starting up one ...\n"); + StartNetworkServer(port); - sfd = socket(PF_INET, SOCK_STREAM, 0); - if (sfd < 0) - Error(ERR_EXIT, "out of file descriptors"); + /* wait for server to start up and try connecting several times */ + for (i=0; i<6; i++) + { + Delay(500); /* wait 500 ms == 0.5 seconds */ + close(sfd); - setsockopt(sfd, tcpproto->p_proto, TCP_NODELAY, - (char *)&on, sizeof(int)); + sfd = socket(PF_INET, SOCK_STREAM, 0); + if (sfd < 0) + Error(ERR_EXIT, "out of file descriptors"); - if (connect(sfd, (struct sockaddr *)&s, sizeof(s)) >= 0) - break; - } - if (i==6) - Error(ERR_EXIT, "cannot connect to server"); - } - else - Error(ERR_EXIT, "cannot connect to server"); + setsockopt(sfd, tcpproto->p_proto, TCP_NODELAY, (char *)&on, sizeof(int)); + + if (connect(sfd, (struct sockaddr *)&s, sizeof(s)) >= 0) /* connected */ + return TRUE; } - return(TRUE); + /* when reaching this point, connect to newly started server has failed */ + return FALSE; } -void SendToServer_Nickname(char *nickname) +void SendToServer_PlayerName(char *player_name) { - static char msgbuf[300]; - int len_nickname = strlen(nickname); - - buf[1] = OP_NICKNAME; - memcpy(&buf[2], nickname, len_nickname); - sendbuf(2 + len_nickname); - sprintf(msgbuf, "you set your nick to \"%s\"", nickname); - sysmsg(msgbuf); + int len_player_name = strlen(player_name); + + buffer[1] = OP_PLAYER_NAME; + memcpy(&buffer[2], player_name, len_player_name); + SendBufferToServer(2 + len_player_name); + Error(ERR_NETWORK_CLIENT, "you set your player name to \"%s\"", player_name); } void SendToServer_ProtocolVersion() { - buf[1] = OP_PROTOCOL_VERSION; - buf[2] = PROTOCOL_VERSION_1; - buf[3] = PROTOCOL_VERSION_2; - buf[4] = PROTOCOL_VERSION_3; + buffer[1] = OP_PROTOCOL_VERSION; + buffer[2] = PROTOCOL_VERSION_1; + buffer[3] = PROTOCOL_VERSION_2; + buffer[4] = PROTOCOL_VERSION_3; - sendbuf(5); + SendBufferToServer(5); } void SendToServer_NrWanted(int nr_wanted) { - buf[1] = OP_NUMBER_WANTED; - buf[2] = nr_wanted; + buffer[1] = OP_NUMBER_WANTED; + buffer[2] = nr_wanted; - sendbuf(3); + SendBufferToServer(3); } void SendToServer_StartPlaying() { unsigned long new_random_seed = InitRND(NEW_RANDOMIZE); - buf[1] = OP_START_PLAYING; - buf[2] = (byte)(level_nr >> 8); - buf[3] = (byte)(level_nr & 0xff); - buf[4] = (byte)(leveldir_nr >> 8); - buf[5] = (byte)(leveldir_nr & 0xff); + buffer[1] = OP_START_PLAYING; + buffer[2] = (byte)(level_nr >> 8); + buffer[3] = (byte)(level_nr & 0xff); + buffer[4] = (byte)(leveldir_nr >> 8); + buffer[5] = (byte)(leveldir_nr & 0xff); - buf[6] = (unsigned char)((new_random_seed >> 24) & 0xff); - buf[7] = (unsigned char)((new_random_seed >> 16) & 0xff); - buf[8] = (unsigned char)((new_random_seed >> 8) & 0xff); - buf[9] = (unsigned char)((new_random_seed >> 0) & 0xff); + buffer[6] = (unsigned char)((new_random_seed >> 24) & 0xff); + buffer[7] = (unsigned char)((new_random_seed >> 16) & 0xff); + buffer[8] = (unsigned char)((new_random_seed >> 8) & 0xff); + buffer[9] = (unsigned char)((new_random_seed >> 0) & 0xff); - strcpy(&buf[10], leveldir[leveldir_nr].name); + strcpy(&buffer[10], leveldir[leveldir_nr].name); - sendbuf(10 + strlen(leveldir[leveldir_nr].name)+1); + SendBufferToServer(10 + strlen(leveldir[leveldir_nr].name)+1); } void SendToServer_PausePlaying() { - buf[1] = OP_PAUSE_PLAYING; + buffer[1] = OP_PAUSE_PLAYING; - sendbuf(2); + SendBufferToServer(2); } void SendToServer_ContinuePlaying() { - buf[1] = OP_CONTINUE_PLAYING; + buffer[1] = OP_CONTINUE_PLAYING; - sendbuf(2); + SendBufferToServer(2); } void SendToServer_StopPlaying() { - buf[1] = OP_STOP_PLAYING; + buffer[1] = OP_STOP_PLAYING; - sendbuf(2); + SendBufferToServer(2); } void SendToServer_MovePlayer(byte player_action) { - buf[1] = OP_MOVE_FIGURE; - buf[2] = player_action; + buffer[1] = OP_MOVE_FIGURE; + buffer[2] = player_action; - sendbuf(3); + SendBufferToServer(3); } static void Handle_OP_BAD_PROTOCOL_VERSION() { Error(ERR_WARN, "protocol version mismatch"); Error(ERR_EXIT, "server expects %d.%d.x instead of %d.%d.%d", - buf[2], buf[3], + buffer[2], buffer[3], PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, PROTOCOL_VERSION_3); } static void Handle_OP_YOUR_NUMBER() { - int new_client_nr = buf[2]; + int new_client_nr = buffer[2]; int new_index_nr = new_client_nr - 1; struct PlayerInfo *old_local_player = local_player; struct PlayerInfo *new_local_player = &stored_player[new_index_nr]; - printf("OP_YOUR_NUMBER: %d\n", buf[0]); - me.nr = new_client_nr; + printf("OP_YOUR_NUMBER: %d\n", buffer[0]); + first_player.nr = new_client_nr; if (old_local_player != new_local_player) { @@ -326,47 +292,37 @@ static void Handle_OP_YOUR_NUMBER() *new_local_player = *old_local_player; old_local_player->connected = FALSE; - local_player = new_local_player; } - TestPlayer = new_index_nr; - - if (me.nr > MAX_PLAYERS) + if (first_player.nr > MAX_PLAYERS) Error(ERR_EXIT, "sorry - no more than %d players", MAX_PLAYERS); - sprintf(msgbuf, "you get client # %d", new_client_nr); - sysmsg(msgbuf); + Error(ERR_NETWORK_CLIENT, "you get client # %d", new_client_nr); } static void Handle_OP_NUMBER_WANTED() { - int client_nr_wanted = buf[2]; - int old_client_nr = buf[0]; - int new_client_nr = buf[3]; + int client_nr_wanted = buffer[2]; + int old_client_nr = buffer[0]; + int new_client_nr = buffer[3]; int old_index_nr = old_client_nr - 1; int new_index_nr = new_client_nr - 1; int index_nr_wanted = client_nr_wanted - 1; struct PlayerInfo *old_player = &stored_player[old_index_nr]; struct PlayerInfo *new_player = &stored_player[new_index_nr]; - printf("OP_NUMBER_WANTED: %d\n", buf[0]); + printf("OP_NUMBER_WANTED: %d\n", buffer[0]); if (new_client_nr == client_nr_wanted) /* switching succeeded */ { - struct user *u; + struct NetworkClientPlayerInfo *player; if (old_client_nr != client_nr_wanted) /* client's nr has changed */ - { - sprintf(msgbuf, "client %d switches to # %d", - old_client_nr, new_client_nr); - sysmsg(msgbuf); - } - else if (old_client_nr == me.nr) /* local player keeps his nr */ - { - sprintf(msgbuf, "keeping client # %d", new_client_nr); - sysmsg(msgbuf); - } + Error(ERR_NETWORK_CLIENT, "client %d switches to # %d", + old_client_nr, new_client_nr); + else if (old_client_nr == first_player.nr) /* local player keeps his nr */ + Error(ERR_NETWORK_CLIENT, "keeping client # %d", new_client_nr); if (old_client_nr != new_client_nr) { @@ -376,81 +332,79 @@ static void Handle_OP_NUMBER_WANTED() old_player->connected = FALSE; } - u = finduser(old_client_nr); - u->nr = new_client_nr; + player = getNetworkPlayer(old_client_nr); + player->nr = new_client_nr; if (old_player == local_player) /* local player switched */ local_player = new_player; - - - TestPlayer = new_index_nr; } - else if (old_client_nr == me.nr) /* failed -- local player? */ + else if (old_client_nr == first_player.nr) /* failed -- local player? */ { char *color[] = { "yellow", "red", "green", "blue" }; + char request[100]; - sprintf(msgbuf, "Sorry ! %s player still exists ! You are %s player !", + sprintf(request, "Sorry ! %s player still exists ! You are %s player !", color[index_nr_wanted], color[new_index_nr]); - Request(msgbuf, REQ_CONFIRM); + Request(request, REQ_CONFIRM); - sprintf(msgbuf, "cannot switch -- you keep client # %d", - new_client_nr); - sysmsg(msgbuf); + Error(ERR_NETWORK_CLIENT, "cannot switch -- you keep client # %d", + new_client_nr); } } -static void Handle_OP_NICKNAME(unsigned int len) +static void Handle_OP_PLAYER_NAME(unsigned int len) { - struct user *u; - - printf("OP_NICKNAME: %d\n", buf[0]); - u = finduser(buf[0]); - buf[len] = 0; - sprintf(msgbuf, "client %d calls itself \"%s\"", buf[0], &buf[2]); - sysmsg(msgbuf); - strncpy(u->name, &buf[2], MAXNICKLEN); + struct NetworkClientPlayerInfo *player; + int player_nr = (int)buffer[0]; + + printf("OP_PLAYER_NAME: %d\n", player_nr); + player = getNetworkPlayer(player_nr); + buffer[len] = 0; + Error(ERR_NETWORK_CLIENT, "client %d calls itself \"%s\"", + buffer[0], &buffer[2]); + strncpy(player->name, &buffer[2], MAX_PLAYER_NAME_LEN); } static void Handle_OP_PLAYER_CONNECTED() { - struct user *u, *v = NULL; - int new_client_nr = buf[0]; + struct NetworkClientPlayerInfo *player, *last_player = NULL; + int new_client_nr = (int)buffer[0]; int new_index_nr = new_client_nr - 1; printf("OP_PLAYER_CONNECTED: %d\n", new_client_nr); - sprintf(msgbuf, "new client %d connected", new_client_nr); - sysmsg(msgbuf); + Error(ERR_NETWORK_CLIENT, "new client %d connected", new_client_nr); - for (u = &me; u; u = u->next) + for (player=&first_player; player; player=player->next) { - if (u->nr == new_client_nr) + if (player->nr == new_client_nr) Error(ERR_EXIT, "multiplayer server sent duplicate player id"); - else - v = u; + + last_player = player; } - v->next = u = checked_malloc(sizeof(struct user)); - u->nr = new_client_nr; - u->name[0] = '\0'; - u->next = NULL; + last_player->next = player = + checked_malloc(sizeof(struct NetworkClientPlayerInfo)); + player->nr = new_client_nr; + player->name[0] = '\0'; + player->next = NULL; stored_player[new_index_nr].connected = TRUE; } static void Handle_OP_PLAYER_DISCONNECTED() { - struct user *u, *v; - - printf("OP_PLAYER_DISCONNECTED: %d\n", buf[0]); - u = finduser(buf[0]); - sprintf(msgbuf, "client %d (%s) disconnected", - buf[0], get_user_name(buf[0])); - sysmsg(msgbuf); - - for (v = &me; v; v = v->next) - if (v->next == u) - v->next = u->next; - free(u); + struct NetworkClientPlayerInfo *player, *player_disconnected; + int player_nr = (int)buffer[0]; + + printf("OP_PLAYER_DISCONNECTED: %d\n", player_nr); + player_disconnected = getNetworkPlayer(player_nr); + Error(ERR_NETWORK_CLIENT, "client %d (%s) disconnected", + player_nr, getNetworkPlayerName(buffer[0])); + + for (player=&first_player; player; player=player->next) + if (player->next == player_disconnected) + player->next = player_disconnected->next; + free(player_disconnected); } static void Handle_OP_START_PLAYING() @@ -459,83 +413,43 @@ static void Handle_OP_START_PLAYING() unsigned long new_random_seed; unsigned char *new_leveldir_name; - /* - if (game_status == PLAYING) - break; - */ - - new_level_nr = (buf[2] << 8) + buf[3]; - new_leveldir_nr = (buf[4] << 8) + buf[5]; + new_level_nr = (buffer[2] << 8) + buffer[3]; + new_leveldir_nr = (buffer[4] << 8) + buffer[5]; new_random_seed = - (buf[6] << 24) | (buf[7] << 16) | (buf[8] << 8) | (buf[9]); - new_leveldir_name = &buf[10]; - - printf("OP_START_PLAYING: %d\n", buf[0]); - sprintf(msgbuf, "client %d starts game [level %d from levedir %d (%s)]\n", - buf[0], - new_level_nr, - new_leveldir_nr, - new_leveldir_name); - sysmsg(msgbuf); + (buffer[6] << 24) | (buffer[7] << 16) | (buffer[8] << 8) | (buffer[9]); + new_leveldir_name = &buffer[10]; + printf("OP_START_PLAYING: %d\n", buffer[0]); + Error(ERR_NETWORK_CLIENT, + "client %d starts game [level %d from levedir %d (%s)]\n", + buffer[0], new_level_nr, new_leveldir_nr, new_leveldir_name); if (strcmp(leveldir[new_leveldir_nr].name, new_leveldir_name) != 0) Error(ERR_WARN, "no such level directory: '%s'",new_leveldir_name); leveldir_nr = new_leveldir_nr; - - /* - local_player->leveldir_nr = leveldir_nr; - */ - - - /* - SaveLevelSetup(); - */ - - /* - LoadPlayerInfo(PLAYER_LEVEL); - SavePlayerInfo(PLAYER_SETUP); - */ - - level_nr = new_level_nr; TapeErase(); LoadTape(level_nr); - - /* - GetPlayerConfig(); - */ - LoadLevel(level_nr); - - if (setup.autorecord) TapeStartRecording(); - - if (tape.recording) tape.random_seed = new_random_seed; InitRND(new_random_seed); - - /* - printf("tape.random_seed == %d\n", tape.random_seed); - */ - game_status = PLAYING; InitGame(); } static void Handle_OP_PAUSE_PLAYING() { - printf("OP_PAUSE_PLAYING: %d\n", buf[0]); - sprintf(msgbuf, "client %d pauses game", buf[0]); - sysmsg(msgbuf); + printf("OP_PAUSE_PLAYING: %d\n", buffer[0]); + Error(ERR_NETWORK_CLIENT, "client %d pauses game", buffer[0]); tape.pausing = TRUE; DrawVideoDisplay(VIDEO_STATE_PAUSE_ON,0); @@ -543,9 +457,8 @@ static void Handle_OP_PAUSE_PLAYING() static void Handle_OP_CONTINUE_PLAYING() { - printf("OP_CONTINUE_PLAYING: %d\n", buf[0]); - sprintf(msgbuf, "client %d continues game", buf[0]); - sysmsg(msgbuf); + printf("OP_CONTINUE_PLAYING: %d\n", buffer[0]); + Error(ERR_NETWORK_CLIENT, "client %d continues game", buffer[0]); tape.pausing = FALSE; DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0); @@ -553,9 +466,8 @@ static void Handle_OP_CONTINUE_PLAYING() static void Handle_OP_STOP_PLAYING() { - printf("OP_STOP_PLAYING: %d\n", buf[0]); - sprintf(msgbuf, "client %d stops game", buf[0]); - sysmsg(msgbuf); + printf("OP_STOP_PLAYING: %d\n", buffer[0]); + Error(ERR_NETWORK_CLIENT, "client %d stops game", buffer[0]); game_status = MAINMENU; DrawMainMenu(); @@ -563,52 +475,46 @@ static void Handle_OP_STOP_PLAYING() static void Handle_OP_MOVE_FIGURE(unsigned int len) { - int frame_nr; + int server_frame_counter; int i; if (!network_playing) return; - frame_nr = - (buf[2] << 24) | (buf[3] << 16) | (buf[4] << 8) | (buf[5]); + server_frame_counter = + (buffer[2] << 24) | (buffer[3] << 16) | (buffer[4] << 8) | (buffer[5]); - if (frame_nr != FrameCounter) + if (server_frame_counter != FrameCounter) { Error(ERR_RETURN, "client and servers frame counters out of sync"); Error(ERR_RETURN, "frame counter of client is %d", FrameCounter); - Error(ERR_RETURN, "frame counter of server is %d", frame_nr); + Error(ERR_RETURN, "frame counter of server is %d", server_frame_counter); Error(ERR_EXIT, "this should not happen -- please debug"); } /* copy valid player actions */ for (i=0; i= 4 && nread >= 4 + readbuf[3]) + while (nread >= 4 && nread >= 4 + readbuffer[3]) { - len = readbuf[3]; - if (readbuf[0] || readbuf[1] || readbuf[2]) + message_length = readbuffer[3]; + if (readbuffer[0] || readbuffer[1] || readbuffer[2]) Error(ERR_EXIT, "wrong network server line length"); - memcpy(buf, &readbuf[4], len); - nread -= 4 + len; - memmove(readbuf, readbuf + 4 + len, nread); + memcpy(buffer, &readbuffer[4], message_length); + nread -= 4 + message_length; + memmove(readbuffer, readbuffer + 4 + message_length, nread); - switch(buf[1]) + switch(buffer[1]) { case OP_BAD_PROTOCOL_VERSION: Handle_OP_BAD_PROTOCOL_VERSION(); @@ -622,8 +528,8 @@ static void HandleNetworkingMessages() Handle_OP_NUMBER_WANTED(); break; - case OP_NICKNAME: - Handle_OP_NICKNAME(len); + case OP_PLAYER_NAME: + Handle_OP_PLAYER_NAME(message_length); break; case OP_PLAYER_CONNECTED: @@ -651,18 +557,12 @@ static void HandleNetworkingMessages() break; case OP_MOVE_FIGURE: - Handle_OP_MOVE_FIGURE(len); + Handle_OP_MOVE_FIGURE(message_length); break; - case OP_WON: - printf("OP_WON: %d\n", buf[0]); - sprintf(msgbuf, "client %d wins the game", buf[0]); - sysmsg(msgbuf); - break; - - case OP_MSG: - printf("OP_MSG: %d\n", buf[0]); - sprintf(msgbuf, "client %d sends message", buf[0]); + case OP_BROADCAST_MESSAGE: + printf("OP_BROADCAST_MESSAGE: %d\n", buffer[0]); + Error(ERR_NETWORK_CLIENT, "client %d sends message", buffer[0]); break; } } @@ -676,8 +576,6 @@ void HandleNetworking() fd_set rfds; int r = 0; - flushbuf(); - FD_ZERO(&rfds); FD_SET(sfd, &rfds); @@ -693,7 +591,7 @@ void HandleNetworking() { int r; - r = read(sfd, readbuf + nread, MAX_BUFFER_SIZE - nread); + r = read(sfd, readbuffer + nread, MAX_BUFFER_SIZE - nread); if (r < 0) Error(ERR_EXIT, "error reading from network server"); diff --git a/src/network.h b/src/network.h index 036b8975..162f0f7d 100644 --- a/src/network.h +++ b/src/network.h @@ -17,7 +17,7 @@ #include "main.h" boolean ConnectToServer(char *, int); -void SendToServer_Nickname(char *); +void SendToServer_PlayerName(char *); void SendToServer_ProtocolVersion(void); void SendToServer_NrWanted(int); void SendToServer_StartPlaying(void); diff --git a/src/sound.c b/src/sound.c index 2bf6c1a0..b3818acb 100644 --- a/src/sound.c +++ b/src/sound.c @@ -75,7 +75,7 @@ void SoundServer() if (!FD_ISSET(sound_pipe[0], &sound_fdset)) continue; if (read(sound_pipe[0], &snd_ctrl, sizeof(snd_ctrl)) != sizeof(snd_ctrl)) - Error(ERR_EXIT_SOUNDSERVER, "broken pipe - no sounds"); + Error(ERR_EXIT_SOUND_SERVER, "broken pipe - no sounds"); #ifdef VOXWARE @@ -485,13 +485,13 @@ void HPUX_Audio_Control() audio_ctl = open("/dev/audioCtl", O_WRONLY | O_NDELAY); if (audio_ctl == -1) - Error(ERR_EXIT_SOUNDSERVER, "cannot open /dev/audioCtl - no sounds"); + Error(ERR_EXIT_SOUND_SERVER, "cannot open /dev/audioCtl - no sounds"); if (ioctl(audio_ctl, AUDIO_DESCRIBE, &ainfo) == -1) - Error(ERR_EXIT_SOUNDSERVER, "no audio info - no sounds"); + Error(ERR_EXIT_SOUND_SERVER, "no audio info - no sounds"); if (ioctl(audio_ctl, AUDIO_SET_DATA_FORMAT, AUDIO_FORMAT_ULAW) == -1) - Error(ERR_EXIT_SOUNDSERVER, "ulaw audio not available - no sounds"); + Error(ERR_EXIT_SOUND_SERVER, "ulaw audio not available - no sounds"); ioctl(audio_ctl, AUDIO_SET_CHANNELS, 1); ioctl(audio_ctl, AUDIO_SET_SAMPLE_RATE, 8000); -- 2.34.1