(svn r13712) -Fix: enforce the length restrictions of company and president name in the commands too.
authorrubidium
Thu, 17 Jul 2008 11:19:20 +0000
changeset 11153 cee0888d135a
parent 11149 f3ff534dded8
child 11154 3ea6a520b475
(svn r13712) -Fix: enforce the length restrictions of company and president name in the commands too.
src/misc_cmd.cpp
src/network/core/config.h
src/network/network.cpp
src/network/network_type.h
src/player_gui.cpp
src/player_type.h
--- a/src/misc_cmd.cpp	Tue Jul 15 23:27:28 2008 +0000
+++ b/src/misc_cmd.cpp	Thu Jul 17 11:19:20 2008 +0000
@@ -225,7 +225,7 @@
  */
 CommandCost CmdChangeCompanyName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
-	if (StrEmpty(_cmd_text)) return CMD_ERROR;
+	if (StrEmpty(_cmd_text) || strlen(_cmd_text) > MAX_LENGTH_COMPANY_NAME) return CMD_ERROR;
 
 	if (!IsUniqueCompanyName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
@@ -262,7 +262,7 @@
  */
 CommandCost CmdChangePresidentName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
-	if (StrEmpty(_cmd_text)) return CMD_ERROR;
+	if (StrEmpty(_cmd_text) || strlen(_cmd_text) > MAX_LENGTH_PRESIDENT_NAME) return CMD_ERROR;
 
 	if (!IsUniquePresidentName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 
--- a/src/network/core/config.h	Tue Jul 15 23:27:28 2008 +0000
+++ b/src/network/core/config.h	Thu Jul 17 11:19:20 2008 +0000
@@ -24,6 +24,7 @@
 	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'
+	NETWORK_COMPANY_NAME_LENGTH   =   32, ///< The maximum length of the company name, in bytes including '\0'
 	NETWORK_HOSTNAME_LENGTH       =   80, ///< The maximum length of the host name, in bytes including '\0'
 	NETWORK_UNIQUE_ID_LENGTH      =   33, ///< The maximum length of the unique id of the clients, in bytes including '\0'
 	NETWORK_REVISION_LENGTH       =   15, ///< The maximum length of the revision, in bytes including '\0'
--- a/src/network/network.cpp	Tue Jul 15 23:27:28 2008 +0000
+++ b/src/network/network.cpp	Thu Jul 17 11:19:20 2008 +0000
@@ -70,6 +70,7 @@
 
 /* Check whether NETWORK_NUM_LANDSCAPES is still in sync with NUM_LANDSCAPE */
 assert_compile((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE);
+assert_compile((int)NETWORK_COMPANY_NAME_LENGTH == MAX_LENGTH_COMPANY_NAME + 1);
 
 // global variables (declared in network_data.h)
 CommandPacket *_local_command_queue;
--- a/src/network/network_type.h	Tue Jul 15 23:27:28 2008 +0000
+++ b/src/network/network_type.h	Thu Jul 17 11:19:20 2008 +0000
@@ -35,7 +35,7 @@
 };
 
 struct NetworkPlayerInfo {
-	char company_name[NETWORK_NAME_LENGTH];         ///< Company name
+	char company_name[NETWORK_COMPANY_NAME_LENGTH]; ///< Company name
 	char password[NETWORK_PASSWORD_LENGTH];         ///< The password for the player
 	Year inaugurated_year;                          ///< What year the company started in
 	Money company_value;                            ///< The company value
--- a/src/player_gui.cpp	Tue Jul 15 23:27:28 2008 +0000
+++ b/src/player_gui.cpp	Thu Jul 17 11:19:20 2008 +0000
@@ -1252,13 +1252,13 @@
 			case PCW_WIDGET_PRESIDENT_NAME:
 				this->query_widget = PCW_WIDGET_PRESIDENT_NAME;
 				SetDParam(0, this->window_number);
-				ShowQueryString(STR_PLAYER_NAME, STR_700B_PRESIDENT_S_NAME, 31, 94, this, CS_ALPHANUMERAL);
+				ShowQueryString(STR_PLAYER_NAME, STR_700B_PRESIDENT_S_NAME, MAX_LENGTH_PRESIDENT_NAME, 94, this, CS_ALPHANUMERAL);
 				break;
 
 			case PCW_WIDGET_COMPANY_NAME:
 				this->query_widget = PCW_WIDGET_COMPANY_NAME;
 				SetDParam(0, this->window_number);
-				ShowQueryString(STR_COMPANY_NAME, STR_700A_COMPANY_NAME, 31, 150, this, CS_ALPHANUMERAL);
+				ShowQueryString(STR_COMPANY_NAME, STR_700A_COMPANY_NAME, MAX_LENGTH_COMPANY_NAME, 150, this, CS_ALPHANUMERAL);
 				break;
 
 			case PCW_WIDGET_BUILD_VIEW_HQ: {
--- a/src/player_type.h	Tue Jul 15 23:27:28 2008 +0000
+++ b/src/player_type.h	Thu Jul 17 11:19:20 2008 +0000
@@ -30,6 +30,11 @@
 };
 DECLARE_POSTFIX_INCREMENT(Owner);
 
+enum {
+	MAX_LENGTH_PRESIDENT_NAME = 31, ///< The maximum length for a president's name
+	MAX_LENGTH_COMPANY_NAME   = 31, ///< The maximum length for a company's name
+};
+
 /** Define basic enum properties */
 template <> struct EnumPropsT<Owner> : MakeEnumPropsT<Owner, byte, OWNER_BEGIN, OWNER_END, INVALID_OWNER> {};
 typedef TinyEnumT<Owner> OwnerByte;