X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fnetwork.c;h=1733aba93441a77d164937e9bccee05a7257f0d5;hb=f7704e2d22e9499efe6380e0c916c2bd4918e4be;hp=104b83f9bb2df69b3e36c2f83107fe37d0bd6772;hpb=cdc3c940197937b0508a1eb7dcf44874951908b7;p=rocksndiamonds.git diff --git a/src/network.c b/src/network.c index 104b83f9..1733aba9 100644 --- a/src/network.c +++ b/src/network.c @@ -66,6 +66,7 @@ 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 boolean stop_network_game = FALSE; static void SendBufferToServer(int size) { @@ -342,11 +343,12 @@ void SendToServer_ContinuePlaying() SendBufferToServer(2); } -void SendToServer_StopPlaying() +void SendToServer_StopPlaying(int cause_for_stopping) { buffer[1] = OP_STOP_PLAYING; + buffer[2] = cause_for_stopping; - SendBufferToServer(2); + SendBufferToServer(3); } void SendToServer_MovePlayer(byte player_action) @@ -429,11 +431,18 @@ static void Handle_OP_NUMBER_WANTED() } else if (old_client_nr == first_player.nr) /* failed -- local player? */ { +#if 0 char *color[] = { "yellow", "red", "green", "blue" }; +#endif char request[100]; +#if 1 + sprintf(request, "Sorry ! Player %d already exists ! You are player %d !", + index_nr_wanted + 1, new_index_nr + 1); +#else sprintf(request, "Sorry ! %s player still exists ! You are %s player !", color[index_nr_wanted], color[new_index_nr]); +#endif Request(request, REQ_CONFIRM); Error(ERR_NETWORK_CLIENT, "cannot switch -- you keep client # %d", @@ -532,20 +541,7 @@ static void Handle_OP_START_PLAYING() LoadTape(level_nr); LoadLevel(level_nr); -#if 1 StartGameActions(FALSE, setup.autorecord, new_random_seed); -#else - if (setup.autorecord) - TapeStartRecording(); - - if (tape.recording) - tape.random_seed = new_random_seed; - - InitRND(new_random_seed); - - game_status = GAME_MODE_PLAYING; - InitGame(); -#endif } static void Handle_OP_PAUSE_PLAYING() @@ -568,8 +564,18 @@ static void Handle_OP_CONTINUE_PLAYING() static void Handle_OP_STOP_PLAYING() { - printf("OP_STOP_PLAYING: %d\n", buffer[0]); - Error(ERR_NETWORK_CLIENT, "client %d stops game", buffer[0]); + printf("OP_STOP_PLAYING: %d [%d]\n", buffer[0], buffer[2]); + Error(ERR_NETWORK_CLIENT, "client %d stops game [%d]", buffer[0], buffer[2]); + + if (game_status == GAME_MODE_PLAYING) + { + if (buffer[2] == NETWORK_STOP_BY_PLAYER) + Request("Network game stopped by player!", REQ_CONFIRM); + else if (buffer[2] == NETWORK_STOP_BY_ERROR) + Request("Network game stopped due to internal error!", REQ_CONFIRM); + else + Request("Network game stopped !", REQ_CONFIRM); + } game_status = GAME_MODE_MAIN; DrawMainMenu(); @@ -586,12 +592,26 @@ static void Handle_OP_MOVE_PLAYER(unsigned int len) server_frame_counter = (buffer[2] << 24) | (buffer[3] << 16) | (buffer[4] << 8) | (buffer[5]); +#if 0 + Error(ERR_NETWORK_CLIENT, "receiving server frame counter value %d [%d]", + server_frame_counter, FrameCounter); +#endif + 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", server_frame_counter); + +#if 1 + Error(ERR_RETURN, "this should not happen -- please debug"); + + stop_network_game = TRUE; + + return; +#else Error(ERR_EXIT, "this should not happen -- please debug"); +#endif } /* copy valid player actions */ @@ -606,6 +626,8 @@ static void HandleNetworkingMessages() { unsigned int message_length; + stop_network_game = FALSE; + while (nread >= 4 && nread >= 4 + readbuffer[3]) { message_length = readbuffer[3]; @@ -670,6 +692,10 @@ static void HandleNetworkingMessages() } fflush(stdout); + + /* in case of internal error, stop network game */ + if (stop_network_game) + SendToServer_StopPlaying(NETWORK_STOP_BY_ERROR); } /* TODO */