mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
(svn r21412) -Codechange: limit company name by amount of characters, not bytes
This commit is contained in:
parent
768da4b48f
commit
cf61c2f11f
@ -38,7 +38,7 @@
|
|||||||
/* static */ bool AICompany::SetName(const char *name)
|
/* static */ bool AICompany::SetName(const char *name)
|
||||||
{
|
{
|
||||||
EnforcePrecondition(false, !::StrEmpty(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);
|
return AIObject::DoCommand(0, 0, 0, CMD_RENAME_COMPANY, name);
|
||||||
}
|
}
|
||||||
|
@ -325,7 +325,7 @@ static void GenerateCompanyName(Company *c)
|
|||||||
{
|
{
|
||||||
/* Reserve space for extra unicode character. We need to do this to be able
|
/* Reserve space for extra unicode character. We need to do this to be able
|
||||||
* to detect too long company name. */
|
* 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->name_1 != STR_SV_UNNAMED) return;
|
||||||
if (c->last_build_coordinate == 0) return;
|
if (c->last_build_coordinate == 0) return;
|
||||||
@ -346,7 +346,7 @@ verify_name:;
|
|||||||
}
|
}
|
||||||
|
|
||||||
GetString(buffer, str, lastof(buffer));
|
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:;
|
set_name:;
|
||||||
c->name_1 = str;
|
c->name_1 = str;
|
||||||
@ -1049,7 +1049,7 @@ CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
|||||||
bool reset = StrEmpty(text);
|
bool reset = StrEmpty(text);
|
||||||
|
|
||||||
if (!reset) {
|
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);
|
if (!IsUniqueCompanyName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1952,7 +1952,7 @@ struct CompanyWindow : Window
|
|||||||
case CW_WIDGET_COMPANY_NAME:
|
case CW_WIDGET_COMPANY_NAME:
|
||||||
this->query_widget = CW_WIDGET_COMPANY_NAME;
|
this->query_widget = CW_WIDGET_COMPANY_NAME;
|
||||||
SetDParam(0, this->window_number);
|
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;
|
break;
|
||||||
|
|
||||||
case CW_WIDGET_VIEW_HQ: {
|
case CW_WIDGET_VIEW_HQ: {
|
||||||
|
@ -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_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_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_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
|
static const uint MAX_HISTORY_MONTHS = 24; ///< The maximum number of months kept as performance's history
|
||||||
|
@ -40,7 +40,7 @@ static const byte NETWORK_COMPANY_INFO_VERSION = 6; ///< What version of c
|
|||||||
static const byte NETWORK_MASTER_SERVER_VERSION = 2; ///< What version of master-server-protocol do we use?
|
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_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_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_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'
|
static const uint NETWORK_REVISION_LENGTH = 15; ///< The maximum length of the revision, in bytes including '\0'
|
||||||
|
@ -82,7 +82,7 @@ CompanyMask _network_company_passworded; ///< Bitmask of the password status of
|
|||||||
|
|
||||||
/* Check whether NETWORK_NUM_LANDSCAPES is still in sync with NUM_LANDSCAPE */
|
/* 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_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_client_socket; ///< udp client socket
|
||||||
extern NetworkUDPSocketHandler *_udp_server_socket; ///< udp server socket
|
extern NetworkUDPSocketHandler *_udp_server_socket; ///< udp server socket
|
||||||
|
@ -40,20 +40,22 @@ void Subsidy::AwardTo(CompanyID company)
|
|||||||
this->awarded = company;
|
this->awarded = company;
|
||||||
this->remaining = SUBSIDY_CONTRACT_MONTHS;
|
this->remaining = SUBSIDY_CONTRACT_MONTHS;
|
||||||
|
|
||||||
char *company_name = MallocT<char>(MAX_LENGTH_COMPANY_NAME_BYTES);
|
char company_name[MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH];
|
||||||
SetDParam(0, company);
|
SetDParam(0, _current_company);
|
||||||
GetString(company_name, STR_COMPANY_NAME, company_name + MAX_LENGTH_COMPANY_NAME_BYTES - 1);
|
GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
|
||||||
|
|
||||||
|
char *cn = strdup(company_name);
|
||||||
|
|
||||||
/* Add a news item */
|
/* Add a news item */
|
||||||
Pair reftype = SetupSubsidyDecodeParam(this, false);
|
Pair reftype = SetupSubsidyDecodeParam(this, false);
|
||||||
InjectDParam(1);
|
InjectDParam(1);
|
||||||
|
|
||||||
SetDParamStr(0, company_name);
|
SetDParamStr(0, cn);
|
||||||
AddNewsItem(
|
AddNewsItem(
|
||||||
STR_NEWS_SERVICE_SUBSIDY_AWARDED_HALF + _settings_game.difficulty.subsidy_multiplier,
|
STR_NEWS_SERVICE_SUBSIDY_AWARDED_HALF + _settings_game.difficulty.subsidy_multiplier,
|
||||||
NS_SUBSIDIES,
|
NS_SUBSIDIES,
|
||||||
(NewsReferenceType)reftype.a, this->src, (NewsReferenceType)reftype.b, this->dst,
|
(NewsReferenceType)reftype.a, this->src, (NewsReferenceType)reftype.b, this->dst,
|
||||||
company_name
|
cn
|
||||||
);
|
);
|
||||||
AI::BroadcastNewEvent(new AIEventSubsidyAwarded(this->index));
|
AI::BroadcastNewEvent(new AIEventSubsidyAwarded(this->index));
|
||||||
|
|
||||||
|
@ -1596,7 +1596,7 @@ CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
|||||||
if (_game_mode != GM_EDITOR) {
|
if (_game_mode != GM_EDITOR) {
|
||||||
/* 't' can't be NULL since 'random' is false outside scenedit */
|
/* 't' can't be NULL since 'random' is false outside scenedit */
|
||||||
assert(!random);
|
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);
|
SetDParam(0, _current_company);
|
||||||
GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
|
GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
|
||||||
|
|
||||||
@ -2466,7 +2466,7 @@ static CommandCost TownActionRoadRebuild(Town *t, DoCommandFlag flags)
|
|||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
t->road_build_months = 6;
|
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);
|
SetDParam(0, _current_company);
|
||||||
GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
|
GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user