Changeset - r16671:bbf8280610d0
[Not reviewed]
master
0 8 0
rubidium - 14 years ago 2010-12-05 22:24:50
rubidium@openttd.org
(svn r21412) -Codechange: limit company name by amount of characters, not bytes
8 files changed with 17 insertions and 15 deletions:
0 comments (0 inline, 0 general)
src/ai/api/ai_company.cpp
Show inline comments
 
@@ -38,7 +38,7 @@
 
/* static */ bool AICompany::SetName(const char *name)
 
{
 
	EnforcePrecondition(false, !::StrEmpty(name));
 
	EnforcePreconditionCustomError(false, ::strlen(name) < MAX_LENGTH_COMPANY_NAME_BYTES, AIError::ERR_PRECONDITION_STRING_TOO_LONG);
 
	EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_COMPANY_NAME_CHARS, AIError::ERR_PRECONDITION_STRING_TOO_LONG);
 

	
 
	return AIObject::DoCommand(0, 0, 0, CMD_RENAME_COMPANY, name);
 
}
src/company_cmd.cpp
Show inline comments
 
@@ -325,7 +325,7 @@ static void GenerateCompanyName(Company 
 
{
 
	/* Reserve space for extra unicode character. We need to do this to be able
 
	 * to detect too long company name. */
 
	char buffer[MAX_LENGTH_COMPANY_NAME_BYTES + MAX_CHAR_LENGTH];
 
	char buffer[(MAX_LENGTH_COMPANY_NAME_CHARS + 1) * MAX_CHAR_LENGTH];
 

	
 
	if (c->name_1 != STR_SV_UNNAMED) return;
 
	if (c->last_build_coordinate == 0) return;
 
@@ -346,7 +346,7 @@ verify_name:;
 
		}
 

	
 
		GetString(buffer, str, lastof(buffer));
 
		if (strlen(buffer) >= MAX_LENGTH_COMPANY_NAME_BYTES) goto bad_town_name;
 
		if (Utf8StringLength(buffer) >= MAX_LENGTH_COMPANY_NAME_CHARS) goto bad_town_name;
 

	
 
set_name:;
 
		c->name_1 = str;
 
@@ -1049,7 +1049,7 @@ CommandCost CmdRenameCompany(TileIndex t
 
	bool reset = StrEmpty(text);
 

	
 
	if (!reset) {
 
		if (strlen(text) >= MAX_LENGTH_COMPANY_NAME_BYTES) return CMD_ERROR;
 
		if (Utf8StringLength(text) >= MAX_LENGTH_COMPANY_NAME_CHARS) return CMD_ERROR;
 
		if (!IsUniqueCompanyName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
 
	}
 

	
src/company_gui.cpp
Show inline comments
 
@@ -1952,7 +1952,7 @@ struct CompanyWindow : Window
 
			case CW_WIDGET_COMPANY_NAME:
 
				this->query_widget = CW_WIDGET_COMPANY_NAME;
 
				SetDParam(0, this->window_number);
 
				ShowQueryString(STR_COMPANY_NAME, STR_COMPANY_VIEW_COMPANY_NAME_QUERY_CAPTION, MAX_LENGTH_COMPANY_NAME_BYTES, MAX_LENGTH_COMPANY_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT);
 
				ShowQueryString(STR_COMPANY_NAME, STR_COMPANY_VIEW_COMPANY_NAME_QUERY_CAPTION, MAX_LENGTH_COMPANY_NAME_CHARS, MAX_LENGTH_COMPANY_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS);
 
				break;
 

	
 
			case CW_WIDGET_VIEW_HQ: {
src/company_type.h
Show inline comments
 
@@ -39,7 +39,7 @@ DECLARE_POSTFIX_INCREMENT(Owner)
 

	
 
static const uint MAX_LENGTH_PRESIDENT_NAME_CHARS  =  31; ///< The maximum length of a president name in characters including '\0'
 
static const uint MAX_LENGTH_PRESIDENT_NAME_PIXELS =  94; ///< The maximum length of a president name in pixels
 
static const uint MAX_LENGTH_COMPANY_NAME_BYTES    =  31; ///< The maximum length of a company name in bytes including '\0'
 
static const uint MAX_LENGTH_COMPANY_NAME_CHARS    =  32; ///< The maximum length of a company name in characters including '\0'
 
static const uint MAX_LENGTH_COMPANY_NAME_PIXELS   = 150; ///< The maximum length of a company name in pixels
 

	
 
static const uint MAX_HISTORY_MONTHS               =  24; ///< The maximum number of months kept as performance's history
src/network/core/config.h
Show inline comments
 
@@ -40,7 +40,7 @@ static const byte NETWORK_COMPANY_INFO_V
 
static const byte NETWORK_MASTER_SERVER_VERSION   =    2; ///< What version of master-server-protocol do we use?
 

	
 
static const uint NETWORK_NAME_LENGTH             =   80; ///< The maximum length of the server name and map name, in bytes including '\0'
 
static const uint NETWORK_COMPANY_NAME_LENGTH     =   31; ///< The maximum length of the company name, in bytes including '\0'
 
static const uint NETWORK_COMPANY_NAME_LENGTH     =  128; ///< The maximum length of the company name, in bytes including '\0'
 
static const uint NETWORK_HOSTNAME_LENGTH         =   80; ///< The maximum length of the host name, in bytes including '\0'
 
static const uint NETWORK_SERVER_ID_LENGTH        =   33; ///< The maximum length of the network id of the servers, in bytes including '\0'
 
static const uint NETWORK_REVISION_LENGTH         =   15; ///< The maximum length of the revision, in bytes including '\0'
src/network/network.cpp
Show inline comments
 
@@ -82,7 +82,7 @@ CompanyMask _network_company_passworded;
 

	
 
/* 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_BYTES);
 
assert_compile((int)NETWORK_COMPANY_NAME_LENGTH == MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH);
 

	
 
extern NetworkUDPSocketHandler *_udp_client_socket; ///< udp client socket
 
extern NetworkUDPSocketHandler *_udp_server_socket; ///< udp server socket
src/subsidy.cpp
Show inline comments
 
@@ -40,20 +40,22 @@ void Subsidy::AwardTo(CompanyID company)
 
	this->awarded = company;
 
	this->remaining = SUBSIDY_CONTRACT_MONTHS;
 

	
 
	char *company_name = MallocT<char>(MAX_LENGTH_COMPANY_NAME_BYTES);
 
	SetDParam(0, company);
 
	GetString(company_name, STR_COMPANY_NAME, company_name + MAX_LENGTH_COMPANY_NAME_BYTES - 1);
 
	char company_name[MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH];
 
	SetDParam(0, _current_company);
 
	GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
 

	
 
	char *cn = strdup(company_name);
 

	
 
	/* Add a news item */
 
	Pair reftype = SetupSubsidyDecodeParam(this, false);
 
	InjectDParam(1);
 

	
 
	SetDParamStr(0, company_name);
 
	SetDParamStr(0, cn);
 
	AddNewsItem(
 
		STR_NEWS_SERVICE_SUBSIDY_AWARDED_HALF + _settings_game.difficulty.subsidy_multiplier,
 
		NS_SUBSIDIES,
 
		(NewsReferenceType)reftype.a, this->src, (NewsReferenceType)reftype.b, this->dst,
 
		company_name
 
		cn
 
	);
 
	AI::BroadcastNewEvent(new AIEventSubsidyAwarded(this->index));
 

	
src/town_cmd.cpp
Show inline comments
 
@@ -1596,7 +1596,7 @@ CommandCost CmdFoundTown(TileIndex tile,
 
		if (_game_mode != GM_EDITOR) {
 
			/* 't' can't be NULL since 'random' is false outside scenedit */
 
			assert(!random);
 
			char company_name[MAX_LENGTH_COMPANY_NAME_BYTES];
 
			char company_name[MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH];
 
			SetDParam(0, _current_company);
 
			GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
 

	
 
@@ -2466,7 +2466,7 @@ static CommandCost TownActionRoadRebuild
 
	if (flags & DC_EXEC) {
 
		t->road_build_months = 6;
 

	
 
		char company_name[MAX_LENGTH_COMPANY_NAME_BYTES];
 
		char company_name[MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH];
 
		SetDParam(0, _current_company);
 
		GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
 

	
0 comments (0 inline, 0 general)