X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fnetwork.c;h=1a0feda699008b9eaf90d9b937f7ed447e8f2f49;hb=852a8eef1e8858a40da0be4093eba3deaf468f51;hp=104b83f9bb2df69b3e36c2f83107fe37d0bd6772;hpb=37a06df577bbfd00f4b361f92cacb0d97036ba93;p=rocksndiamonds.git diff --git a/src/network.c b/src/network.c index 104b83f9..1a0feda6 100644 --- a/src/network.c +++ b/src/network.c @@ -1,7 +1,7 @@ /*********************************************************** * Rocks'n'Diamonds -- McDuffin Strikes Back! * *----------------------------------------------------------* -* (c) 1995-2002 Artsoft Entertainment * +* (c) 1995-2006 Artsoft Entertainment * * Holger Schemel * * Detmolder Strasse 189 * * 33604 Bielefeld * @@ -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,11 @@ static void Handle_OP_NUMBER_WANTED() } else if (old_client_nr == first_player.nr) /* failed -- local player? */ { - char *color[] = { "yellow", "red", "green", "blue" }; char request[100]; - sprintf(request, "Sorry ! %s player still exists ! You are %s player !", - color[index_nr_wanted], color[new_index_nr]); + sprintf(request, "Sorry ! Player %d already exists ! You are player %d !", + index_nr_wanted + 1, new_index_nr + 1); + Request(request, REQ_CONFIRM); Error(ERR_NETWORK_CLIENT, "cannot switch -- you keep client # %d", @@ -532,20 +534,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 +557,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 +585,21 @@ 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); - Error(ERR_EXIT, "this should not happen -- please debug"); + Error(ERR_INFO, "client and servers frame counters out of sync"); + Error(ERR_INFO, "frame counter of client is %d", FrameCounter); + Error(ERR_INFO, "frame counter of server is %d", server_frame_counter); + Error(ERR_INFO, "this should not happen -- please debug"); + + stop_network_game = TRUE; + + return; } /* copy valid player actions */ @@ -606,6 +614,8 @@ static void HandleNetworkingMessages() { unsigned int message_length; + stop_network_game = FALSE; + while (nread >= 4 && nread >= 4 + readbuffer[3]) { message_length = readbuffer[3]; @@ -616,7 +626,7 @@ static void HandleNetworkingMessages() nread -= 4 + message_length; memmove(readbuffer, readbuffer + 4 + message_length, nread); - switch(buffer[1]) + switch (buffer[1]) { case OP_BAD_PROTOCOL_VERSION: Handle_OP_BAD_PROTOCOL_VERSION(); @@ -670,6 +680,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 */