From 07a16f9282d3b47af0ad8045497a57bab03fe26b Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 6 May 2009 22:21:32 +0000 Subject: [PATCH] (svn r16245) [0.7] -Backport from trunk: - Fix: Hardcoded (old sized) MAX_COMPANIES constant (r16182) - Fix: Do not try to reserve path for trains crashed in station [FS#2866] (r16178) - Fix: Forbid joining AI companies via the 'move' and 'join' console commands/multiplayer lobby (r16176, r16175) - Fix: The overflowsafe type did not like dividing by int64 larger than MAX_INT32 causing division by negative numbers and small anomolies when drawing graphs [FS#2855] (r16130) --- src/console_cmds.cpp | 10 ++++++++++ src/core/overflowsafe_type.hpp | 2 +- src/misc_gui.cpp | 2 +- src/network/core/config.h | 2 +- src/network/network_client.cpp | 1 + src/network/network_server.cpp | 4 ++++ src/vehicle.cpp | 2 +- 7 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 8396d56485..e15ec5ef6a 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -640,6 +640,11 @@ DEF_CONSOLE_CMD(ConJoinCompany) return true; } + if (company_id != COMPANY_SPECTATOR && GetCompany(company_id)->is_ai) { + IConsoleError("Cannot join AI company."); + return true; + } + /* Check if the company requires a password */ if (NetworkCompanyIsPassworded(company_id) && argc < 3) { IConsolePrintF(CC_ERROR, "Company %d requires a password to join.", company_id + 1); @@ -678,6 +683,11 @@ DEF_CONSOLE_CMD(ConMoveClient) return true; } + if (company_id != COMPANY_SPECTATOR && GetCompany(company_id)->is_ai) { + IConsoleError("You cannot move clients to AI companies."); + return true; + } + if (ci->client_id == CLIENT_ID_SERVER && _network_dedicated) { IConsoleError("Silly boy, you cannot move the server!"); return true; diff --git a/src/core/overflowsafe_type.hpp b/src/core/overflowsafe_type.hpp index 882363f1b7..26e36110fb 100644 --- a/src/core/overflowsafe_type.hpp +++ b/src/core/overflowsafe_type.hpp @@ -86,7 +86,7 @@ public: FORCEINLINE OverflowSafeInt operator * (const byte factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; } /* Operators for division */ - FORCEINLINE OverflowSafeInt& operator /= (const int divisor) { this->m_value /= divisor; return *this; } + FORCEINLINE OverflowSafeInt& operator /= (const int64 divisor) { this->m_value /= divisor; return *this; } FORCEINLINE OverflowSafeInt operator / (const OverflowSafeInt& divisor) const { OverflowSafeInt result = *this; result /= divisor.m_value; return result; } FORCEINLINE OverflowSafeInt operator / (const int divisor) const { OverflowSafeInt result = *this; result /= divisor; return result; } FORCEINLINE OverflowSafeInt operator / (const uint divisor) const { OverflowSafeInt result = *this; result /= (int)divisor; return result; } diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 8741a3d2e0..dce606e618 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -520,7 +520,7 @@ void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y) Point pt; const ViewPort *vp; - if (msg_1 != STR_013B_OWNED_BY || GetDParam(2) >= 8) { + if (msg_1 != STR_013B_OWNED_BY || GetDParam(2) >= MAX_COMPANIES) { if ((x | y) != 0) { pt = RemapCoords2(x, y); vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport; diff --git a/src/network/core/config.h b/src/network/core/config.h index e2fbb5e3a6..3f4c8a64bb 100644 --- a/src/network/core/config.h +++ b/src/network/core/config.h @@ -23,7 +23,7 @@ enum { SEND_MTU = 1460, ///< Number of bytes we can pack in a single packet NETWORK_GAME_INFO_VERSION = 4, ///< What version of game-info do we use? - NETWORK_COMPANY_INFO_VERSION = 5, ///< What version of company info is this? + NETWORK_COMPANY_INFO_VERSION = 6, ///< What version of company info is this? NETWORK_MASTER_SERVER_VERSION = 1, ///< What version of master-server-protocol do we use? NETWORK_NAME_LENGTH = 80, ///< The maximum length of the server name and map name, in bytes including '\0' diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 8b24b9849e..51e76c6e00 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -380,6 +380,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO) company_info->num_vehicle[i] = p->Recv_uint16(); for (int i = 0; i < NETWORK_STATION_TYPES; i++) company_info->num_station[i] = p->Recv_uint16(); + company_info->ai = p->Recv_bool(); p->Recv_string(company_info->clients, sizeof(company_info->clients)); diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 16695c46b6..b03a9f7958 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -1235,6 +1235,8 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_MOVE) /* Check if the company is valid */ if (!IsValidCompanyID(company_id) && company_id != COMPANY_SPECTATOR) return; + /* We don't allow moving to AI companies */ + if (company_id != COMPANY_SPECTATOR && GetCompany(company_id)->is_ai) return; /* Check if we require a password for this company */ if (company_id != COMPANY_SPECTATOR && !StrEmpty(_network_company_states[company_id].password)) { @@ -1344,6 +1346,8 @@ void NetworkSocketHandler::Send_CompanyInformation(Packet *p, const Company *c, for (int i = 0; i < NETWORK_STATION_TYPES; i++) { p->Send_uint16(stats->num_station[i]); } + + p->Send_bool(c->is_ai); } /** diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 877be02990..557048507f 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1531,7 +1531,7 @@ void Vehicle::LeaveStation() HideFillingPercent(&this->fill_percent_te_id); - if (this->type == VEH_TRAIN) { + if (this->type == VEH_TRAIN && !(this->vehstatus & VS_CRASHED)) { /* Trigger station animation (trains only) */ if (IsTileType(this->tile, MP_STATION)) StationAnimationTrigger(st, this->tile, STAT_ANIM_TRAIN_DEPARTS);