From e7b58b737541d02457e637b02f824f005c07b83f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Thu, 12 Nov 2015 10:55:47 +0100 Subject: [PATCH 1/3] Skip closing network if already closed Fixes #2203 --- src/network/network.cpp | 11 +++++++++-- src/network/network.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/network/network.cpp b/src/network/network.cpp index 8c566d4ff1..2c0f55047e 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -438,11 +438,18 @@ bool Network::Init() wsa_initialized = true; } #endif + status = NETWORK_STATUS_READY; return true; } void Network::Close() { + if (status == NETWORK_STATUS_NONE) + { + // Already closed. This prevents a call in ~Network() to gfx_invalidate_screen() + // which may no longer be valid on Linux and would cause a segfault. + return; + } if (mode == NETWORK_MODE_CLIENT) { closesocket(server_connection.socket); } else @@ -1398,7 +1405,7 @@ int Network::Server_Handle_GAMECMD(NetworkConnection& connection, NetworkPacket& packet >> tick >> args[0] >> args[1] >> args[2] >> args[3] >> args[4] >> args[5] >> args[6] >> callback; int commandCommand = args[4]; - + // Don't let clients send pause or quit if (commandCommand != GAME_COMMAND_TOGGLE_PAUSE && commandCommand != GAME_COMMAND_LOAD_OR_QUIT @@ -1406,7 +1413,7 @@ int Network::Server_Handle_GAMECMD(NetworkConnection& connection, NetworkPacket& Server_Send_GAMECMD(args[0], args[1], args[2], args[3], args[4], args[5], args[6], playerid, callback); game_do_command(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); } - + return 1; } diff --git a/src/network/network.h b/src/network/network.h index 0c092fa1f7..e8c4809bfb 100644 --- a/src/network/network.h +++ b/src/network/network.h @@ -44,6 +44,7 @@ enum { enum { NETWORK_STATUS_NONE, + NETWORK_STATUS_READY, NETWORK_STATUS_RESOLVING, NETWORK_STATUS_CONNECTING, NETWORK_STATUS_CONNECTED From e885056229e7bd2a152dd860f05db65157d32a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Sat, 14 Nov 2015 17:36:32 +0100 Subject: [PATCH 2/3] Fix exit code handling, sprite generation Make sprite generation not start UI --- src/cmdline.c | 5 ++++- src/cmdline_sprite.c | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/cmdline.c b/src/cmdline.c index 9f7a45427d..0b0eb4b232 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -121,7 +121,10 @@ int cmdline_run(const char **argv, int argc) if (argc != 0) { gExitCode = cmdline_call_action(argv, argc); - if (gExitCode != 0) { + if (gExitCode < 0) { + return 0; + } else if (gExitCode > 0) { + gExitCode = 0; return 0; } } diff --git a/src/cmdline_sprite.c b/src/cmdline_sprite.c index 0e8f84a83a..789a86fa0a 100644 --- a/src/cmdline_sprite.c +++ b/src/cmdline_sprite.c @@ -1,8 +1,29 @@ +/***************************************************************************** + * Copyright (c) 2015 Ted John + * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. + * + * This file is part of OpenRCT2. + * + * OpenRCT2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *****************************************************************************/ + #include #include "cmdline.h" #include "drawing/drawing.h" #include "platform/platform.h" #include "util/util.h" +#include "openrct2.h" #define MODE_DEFAULT 0 #define MODE_CLOSEST 1 @@ -397,6 +418,7 @@ bool sprite_file_import(const char *path, rct_g1_element *outElement, uint8 **ou int cmdline_for_sprite(const char **argv, int argc) { + gOpenRCT2Headless = true; if (argc == 0) return -1; From d3329b74a5604196f7c4c0baa026cef1928afa78 Mon Sep 17 00:00:00 2001 From: janisozaur Date: Mon, 16 Nov 2015 13:59:01 +0100 Subject: [PATCH 3/3] Comment expected cmdline_call_action results --- src/cmdline.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/cmdline.c b/src/cmdline.c index 0b0eb4b232..58b233db03 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -120,13 +120,19 @@ int cmdline_run(const char **argv, int argc) #endif // DISABLE_NETWORK if (argc != 0) { + // see comment next to cmdline_call_action for expected return codes gExitCode = cmdline_call_action(argv, argc); if (gExitCode < 0) { + // action failed, don't change exit code + // and don't start the game return 0; } else if (gExitCode > 0) { + // action successful, but don't start the game + // change exit code to success gExitCode = 0; return 0; } + // start the game, so far exit code means success. } // Headless mode requires a park to open @@ -202,6 +208,7 @@ static int cmdline_for_none(const char **argv, int argc) } } +// see comment next to cmdline_call_action for expected return codes struct { const char *firstArg; cmdline_action action; } cmdline_table[] = { { "intro", cmdline_for_intro }, { "edit", cmdline_for_edit }, @@ -215,6 +222,19 @@ struct { const char *firstArg; cmdline_action action; } cmdline_table[] = { #endif }; +/** + * This function delegates starting the game to different handlers, if found. + * + * Three cases of return values are supported: + * - result < 0 means failure, will exit with error code + * This case is useful when user provided wrong arguments or the requested + * action failed + * - result > 0 means success, won't start game, will exit program with success code + * This case is useful when you want to do some batch action and signalize + * success to the user. + * - result == 0 means success, will launch the game. + * This is default when ran with no arguments. + */ static int cmdline_call_action(const char **argv, int argc) { for (int i = 0; i < countof(cmdline_table); i++) {