added separate network info structure for network options and setup values
authorHolger Schemel <info@artsoft.org>
Thu, 14 Jun 2018 06:38:19 +0000 (08:38 +0200)
committerHolger Schemel <info@artsoft.org>
Mon, 18 Jun 2018 17:47:32 +0000 (19:47 +0200)
src/events.c
src/game.c
src/init.c
src/libgame/system.c
src/libgame/system.h
src/network.c
src/screens.c
src/tape.c
src/tools.c

index 0e899a5b8f6f9836eff53d7117c8bbe8545b5aec..7972d1b53e0ddf37bd1973383675e25b414cd3ae 100644 (file)
@@ -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
 
index 96fa321fb09a10f26898014f98dfd79846f3a7fa..efb18c36f18b708f955f7d702bd7e49974ae7bba 100644 (file)
@@ -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
index 88ffc38bfca24941a3a051b2381723b2567f1078..8dec027785859377910914d56630c8a05aeeadd9 100644 (file)
@@ -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
index 2d375e23e7f67dc4ce6598a84380511468020144..5888f344a81c9cbd4585fdadff54f0a27b89d1fb 100644 (file)
@@ -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);
index 23bb94d41042398ac7353fcafd954c3946d89f4d..d2a8d2874234b5c605632c845cb22fb77ad2bc61 100644 (file)
@@ -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();
index b55e68e7a584d5a017cd97c4faa0fe8feb99a67d..742cea5792e6a0cd639b851b12a4c92f2916c329 100644 (file)
@@ -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;
index 2b4539f990d2aa12547abbadc627ca7e7e9874c0..9906b6441289415c54f5fb38c6af82f5bbf2be32 100644 (file)
@@ -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);
 }
 
index 1e072cd4ffa567c9543e5999d10db07c52ce3eaf..689f2bf2e0dfbae9fdeacaed1392a639da5c282a 100644 (file)
@@ -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)
index f06ddb8efbb5333c0359667199131c4c6c443c29..7e80c6f8a97183964dd159c66507f922221d8773 100644 (file)
@@ -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();