From 5eb97ccbaffc671f05dd73bf0548c1666414017e Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Thu, 14 Jun 2018 08:38:19 +0200 Subject: [PATCH] added separate network info structure for network options and setup values --- src/events.c | 4 ++-- src/game.c | 28 ++++++++++++++-------------- src/init.c | 22 +++++++++++++++------- src/libgame/system.c | 12 ++++++++++++ src/libgame/system.h | 13 +++++++++++++ src/network.c | 2 +- src/screens.c | 6 +++--- src/tape.c | 4 ++-- src/tools.c | 8 ++++---- 9 files changed, 66 insertions(+), 33 deletions(-) diff --git a/src/events.c b/src/events.c index 0e899a5b..7972d1b5 100644 --- a/src/events.c +++ b/src/events.c @@ -2031,7 +2031,7 @@ void HandleKey(Key key, int key_status) if (game_status == GAME_MODE_MAIN && (key == setup.shortcut.toggle_pause || key == KSYM_space)) { - StartGameActions(options.network, setup.autorecord, level.random_seed); + StartGameActions(network.enabled, setup.autorecord, level.random_seed); return; } @@ -2223,7 +2223,7 @@ void HandleEventActions() } #if defined(NETWORK_AVALIABLE) - if (options.network) + if (network.enabled) HandleNetworking(); #endif diff --git a/src/game.c b/src/game.c index 96fa321f..efb18c36 100644 --- a/src/game.c +++ b/src/game.c @@ -1731,7 +1731,7 @@ static void InitPlayerField(int x, int y, int element, boolean init_game) if (game.use_block_last_field_bug) player->block_delay_adjustment = (player->block_last_field ? -1 : 1); - if (!options.network || player->connected_network) + if (!network.enabled || player->connected_network) { player->active = TRUE; @@ -3321,7 +3321,7 @@ void InitGame() InitGameControlValues(); /* don't play tapes over network */ - network_playing = (options.network && !tape.playing); + network_playing = (network.enabled && !tape.playing); for (i = 0; i < MAX_PLAYERS; i++) { @@ -3699,7 +3699,7 @@ void InitGame() local_player = &stored_player[i]; } - if (!options.network) + if (!network.enabled) local_player->connected = TRUE; if (tape.playing) @@ -3707,7 +3707,7 @@ void InitGame() for (i = 0; i < MAX_PLAYERS; i++) stored_player[i].connected = tape.player_participates[i]; } - else if (options.network) + else if (network.enabled) { /* add team mode players connected over the network (needed for correct assignment of player figures from level to locally playing players) */ @@ -3962,7 +3962,7 @@ void InitGame() } #endif } - else if (!options.network && !game.team_mode) /* && !tape.playing */ + else if (!network.enabled && !game.team_mode) /* && !tape.playing */ { /* when in single player mode, eliminate all but the first active player */ @@ -11333,7 +11333,7 @@ void GameActionsExt() } if (game.restart_level) - StartGameActions(options.network, setup.autorecord, level.random_seed); + StartGameActions(network.enabled, setup.autorecord, level.random_seed); /* !!! SAME CODE AS IN "CheckLevelTime()" -- FIX THIS !!! */ if (level.game_engine_type == GAME_ENGINE_TYPE_EM) @@ -11476,7 +11476,7 @@ void GameActionsExt() // summarize all actions at local players mapped input device position // (this allows using different input devices in single player mode) - if (!options.network && !game.team_mode) + if (!network.enabled && !game.team_mode) stored_player[map_player_action[local_player->index_nr]].effective_action = summarized_player_action; @@ -12386,7 +12386,7 @@ boolean MovePlayerOneStep(struct PlayerInfo *player, } } - if (!options.network && game.centered_player_nr == -1 && + if (!network.enabled && game.centered_player_nr == -1 && !AllPlayersInSight(player, new_jx, new_jy)) return MP_NO_ACTION; @@ -12573,7 +12573,7 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy) if (scroll_x != old_scroll_x || scroll_y != old_scroll_y) { - if (!options.network && game.centered_player_nr == -1 && + if (!network.enabled && game.centered_player_nr == -1 && !AllPlayersInVisibleScreen()) { scroll_x = old_scroll_x; @@ -14968,7 +14968,7 @@ void RequestQuitGameExt(boolean skip_request, boolean quick_quit, char *message) CloseDoor(DOOR_CLOSE_1); #if defined(NETWORK_AVALIABLE) - if (options.network) + if (network.enabled) SendToServer_StopPlaying(NETWORK_STOP_BY_PLAYER); else #endif @@ -15008,7 +15008,7 @@ void RequestRestartGame(char *message) if (Request(message, REQ_ASK | REQ_STAY_CLOSED)) { - StartGameActions(options.network, setup.autorecord, level.random_seed); + StartGameActions(network.enabled, setup.autorecord, level.random_seed); } else { @@ -15777,7 +15777,7 @@ static void HandleGameButtonsExt(int id, int button) case GAME_CTRL_ID_PAUSE: case GAME_CTRL_ID_PAUSE2: case GAME_CTRL_ID_PANEL_PAUSE: - if (options.network && game_status == GAME_MODE_PLAYING) + if (network.enabled && game_status == GAME_MODE_PLAYING) { #if defined(NETWORK_AVALIABLE) if (tape.pausing) @@ -15797,12 +15797,12 @@ static void HandleGameButtonsExt(int id, int button) case GAME_CTRL_ID_PANEL_PLAY: if (game_status == GAME_MODE_MAIN) { - StartGameActions(options.network, setup.autorecord, level.random_seed); + StartGameActions(network.enabled, setup.autorecord, level.random_seed); } else if (tape.pausing) { #if defined(NETWORK_AVALIABLE) - if (options.network) + if (network.enabled) SendToServer_ContinuePlaying(); else #endif diff --git a/src/init.c b/src/init.c index 88ffc38b..8dec0277 100644 --- a/src/init.c +++ b/src/init.c @@ -5605,16 +5605,22 @@ static void InitArtworkDone() InitGlobalAnimations(); } -void InitNetworkServer() +void InitNetworkSettings() { - if (setup.network_mode) - options.network = TRUE; + InitNetworkInfo(options.network || setup.network_mode, + FALSE, + options.serveronly, + options.server_host, + options.server_port); +} - if (!options.network) +void InitNetworkServer() +{ + if (!network.enabled) return; #if defined(NETWORK_AVALIABLE) - if (!ConnectToServer(options.server_host, options.server_port)) + if (!ConnectToServer(network.server_host, network.server_port)) Error(ERR_EXIT, "cannot connect to network game server"); SendToServer_PlayerName(setup.player_name); @@ -5993,10 +5999,12 @@ void OpenAll() if (options.execute_command) Execute_Command(options.execute_command); - if (options.serveronly) + InitNetworkSettings(); + + if (network.serveronly) { #if defined(PLATFORM_UNIX) - NetworkServer(options.server_port, options.serveronly); + NetworkServer(network.server_port, TRUE); #else Error(ERR_WARN, "networking only supported in Unix version"); #endif diff --git a/src/libgame/system.c b/src/libgame/system.c index 2d375e23..5888f344 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -29,6 +29,7 @@ /* ========================================================================= */ struct ProgramInfo program; +struct NetworkInfo network; struct OptionInfo options; struct VideoSystemInfo video; struct AudioSystemInfo audio; @@ -103,6 +104,17 @@ void InitProgramInfo(char *argv0, char *config_filename, char *userdata_subdir, program.headless = FALSE; } +void InitNetworkInfo(boolean enabled, boolean connected, boolean serveronly, + char *server_host, int server_port) +{ + network.enabled = enabled; + network.connected = connected; + network.serveronly = serveronly; + + network.server_host = server_host; + network.server_port = server_port; +} + void InitScoresInfo() { char *global_scores_dir = getPath2(getCommonDataDir(), SCORES_DIRECTORY); diff --git a/src/libgame/system.h b/src/libgame/system.h index 23bb94d4..d2a8d287 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -865,6 +865,17 @@ struct ProgramInfo boolean headless; }; +struct NetworkInfo +{ + boolean enabled; + boolean connected; + boolean serveronly; + + char *server_host; + int server_port; + +}; + struct OptionInfo { char *server_host; @@ -1559,6 +1570,7 @@ struct LevelStats /* ========================================================================= */ extern struct ProgramInfo program; +extern struct NetworkInfo network; extern struct OptionInfo options; extern struct VideoSystemInfo video; extern struct AudioSystemInfo audio; @@ -1597,6 +1609,7 @@ extern int FrameCounter; void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *, char *, int); +void InitNetworkInfo(boolean, boolean, boolean, char *, int); void InitScoresInfo(); void SetWindowTitle(); diff --git a/src/network.c b/src/network.c index b55e68e7..742cea57 100644 --- a/src/network.c +++ b/src/network.c @@ -56,7 +56,7 @@ static boolean stop_network_game = FALSE; static void SendBufferToServer(int size) { - if (!options.network) + if (!network.enabled) return; realbuffer[0] = realbuffer[1] = realbuffer[2] = 0; diff --git a/src/screens.c b/src/screens.c index 2b4539f9..9906b644 100644 --- a/src/screens.c +++ b/src/screens.c @@ -1087,7 +1087,7 @@ static boolean visibleTextPos(struct TextPosInfo *pos) static void InitializeMainControls() { - boolean local_team_mode = (!options.network && setup.team_mode); + boolean local_team_mode = (!network.enabled && setup.team_mode); int i; /* set main control text values to dynamically determined values */ @@ -2101,7 +2101,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) } else if (pos == MAIN_CONTROL_GAME) { - StartGameActions(options.network, setup.autorecord, level.random_seed); + StartGameActions(network.enabled, setup.autorecord, level.random_seed); } else if (pos == MAIN_CONTROL_SETUP) { @@ -6446,7 +6446,7 @@ static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx) if (si->value == &setup.network_mode && setup.network_mode && - !options.network) + !network.enabled) Request("Please restart game to enable network games!", REQ_CONFIRM); } diff --git a/src/tape.c b/src/tape.c index 1e072cd4..689f2bf2 100644 --- a/src/tape.c +++ b/src/tape.c @@ -600,7 +600,7 @@ void TapeStartRecording(int random_seed) static void TapeStartGameRecording() { - StartGameActions(options.network, TRUE, level.random_seed); + StartGameActions(network.enabled, TRUE, level.random_seed); } static void TapeAppendRecording() @@ -979,7 +979,7 @@ static void TapeStopWarpForward() static void TapeSingleStep() { - if (options.network) + if (network.enabled) return; if (!tape.pausing) diff --git a/src/tools.c b/src/tools.c index f06ddb8e..7e80c6f8 100644 --- a/src/tools.c +++ b/src/tools.c @@ -4394,7 +4394,7 @@ static boolean RequestDoor(char *text, unsigned int req_state) #if defined(NETWORK_AVALIABLE) /* pause network game while waiting for request to answer */ - if (options.network && + if (network.enabled && game_status == GAME_MODE_PLAYING && req_state & REQUEST_WAIT_FOR_INPUT) SendToServer_PausePlaying(); @@ -4536,7 +4536,7 @@ static boolean RequestDoor(char *text, unsigned int req_state) #if defined(NETWORK_AVALIABLE) /* continue network game after request */ - if (options.network && + if (network.enabled && game_status == GAME_MODE_PLAYING && req_state & REQUEST_WAIT_FOR_INPUT) SendToServer_ContinuePlaying(); @@ -4564,7 +4564,7 @@ static boolean RequestEnvelope(char *text, unsigned int req_state) #if defined(NETWORK_AVALIABLE) /* pause network game while waiting for request to answer */ - if (options.network && + if (network.enabled && game_status == GAME_MODE_PLAYING && req_state & REQUEST_WAIT_FOR_INPUT) SendToServer_PausePlaying(); @@ -4623,7 +4623,7 @@ static boolean RequestEnvelope(char *text, unsigned int req_state) #if defined(NETWORK_AVALIABLE) /* continue network game after request */ - if (options.network && + if (network.enabled && game_status == GAME_MODE_PLAYING && req_state & REQUEST_WAIT_FOR_INPUT) SendToServer_ContinuePlaying(); -- 2.34.1