summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-05-15 18:50:55 +0000
committertron <tron@openttd.org>2005-05-15 18:50:55 +0000
commitfea596567944fba8d9d4ead62d948db14690fdf1 (patch)
treead6dc27f46725e511e93e061f51683311027ec65
parent6cd410afbb3cedff9f6d86fc30dbd4e67817ebc9 (diff)
downloadopenttd-fea596567944fba8d9d4ead62d948db14690fdf1.tar.xz
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
-rw-r--r--aircraft_gui.c20
-rw-r--r--command.c20
-rw-r--r--command.h2
-rw-r--r--engine.c2
-rw-r--r--main_gui.c3
-rw-r--r--misc_cmd.c9
-rw-r--r--network_client.c25
-rw-r--r--network_data.c12
-rw-r--r--network_data.h2
-rw-r--r--network_server.c26
-rw-r--r--order_cmd.c2
-rw-r--r--player_gui.c2
-rw-r--r--players.c22
-rw-r--r--roadveh_gui.c20
-rw-r--r--ship_gui.c20
-rw-r--r--signs.c2
-rw-r--r--station_cmd.c2
-rw-r--r--station_gui.c15
-rw-r--r--town_cmd.c2
-rw-r--r--town_gui.c10
-rw-r--r--train_gui.c21
-rw-r--r--vehicle.c2
-rw-r--r--waypoint.c4
23 files changed, 111 insertions, 134 deletions
diff --git a/aircraft_gui.c b/aircraft_gui.c
index a263813be..8f9c89e22 100644
--- a/aircraft_gui.c
+++ b/aircraft_gui.c
@@ -151,11 +151,11 @@ static void NewAircraftWndProc(Window *w, WindowEvent *e)
break;
case WE_ON_EDIT_TEXT: {
- const char *b = e->edittext.str;
- if (*b == 0)
- return;
- memcpy(_decode_parameters, b, 32);
- DoCommandP(0, WP(w,buildtrain_d).rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(STR_A03A_CAN_T_RENAME_AIRCRAFT_TYPE));
+ if (e->edittext.str[0] != '\0') {
+ _cmd_text = e->edittext.str;
+ DoCommandP(0, WP(w, buildtrain_d).rename_engine, 0, NULL,
+ CMD_RENAME_ENGINE | CMD_MSG(STR_A03A_CAN_T_RENAME_AIRCRAFT_TYPE));
+ }
} break;
case WE_RESIZE:
@@ -410,11 +410,11 @@ do_change_service_int:
break;
case WE_ON_EDIT_TEXT: {
- const char *b = e->edittext.str;
- if (*b == 0)
- return;
- memcpy(_decode_parameters, b, 32);
- DoCommandP(0, w->window_number, 0, NULL, CMD_NAME_VEHICLE | CMD_MSG(STR_A031_CAN_T_NAME_AIRCRAFT));
+ if (e->edittext.str[0] != '\0') {
+ _cmd_text = e->edittext.str;
+ DoCommandP(0, w->window_number, 0, NULL,
+ CMD_NAME_VEHICLE | CMD_MSG(STR_A031_CAN_T_NAME_AIRCRAFT));
+ }
} break;
}
diff --git a/command.c b/command.c
index 7d9e2460b..24f6817e1 100644
--- a/command.c
+++ b/command.c
@@ -7,6 +7,8 @@
#include "player.h"
#include "network.h"
+const char* _cmd_text = NULL;
+
#define DEF_COMMAND(yyyy) int32 yyyy(int x, int y, uint32 flags, uint32 p1, uint32 p2)
DEF_COMMAND(CmdBuildRailroadTrack);
@@ -323,7 +325,10 @@ int32 DoCommand(int x, int y, uint32 p1, uint32 p2, uint32 flags, uint procc)
CommandProc *proc;
/* Do not even think about executing out-of-bounds tile-commands */
- if (TILE_FROM_XY(x,y) > MapSize()) return CMD_ERROR;
+ if (TILE_FROM_XY(x,y) > MapSize()) {
+ _cmd_text = NULL;
+ return CMD_ERROR;
+ }
proc = _command_proc_table[procc].proc;
@@ -352,6 +357,7 @@ int32 DoCommand(int x, int y, uint32 p1, uint32 p2, uint32 flags, uint procc)
if (!(flags & DC_EXEC)) {
_docommand_recursive--;
+ _cmd_text = NULL;
return res;
}
}
@@ -363,6 +369,7 @@ int32 DoCommand(int x, int y, uint32 p1, uint32 p2, uint32 flags, uint procc)
if (res & 0xFFFF) _error_message = res & 0xFFFF;
error:
_docommand_recursive--;
+ _cmd_text = NULL;
return CMD_ERROR;
}
@@ -371,6 +378,7 @@ error:
SubtractMoneyFromPlayer(res);
}
+ _cmd_text = NULL;
return res;
}
@@ -394,7 +402,10 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
int y = TileY(tile) * 16;
/* Do not even think about executing out-of-bounds tile-commands */
- if (tile > MapSize()) return false;
+ if (tile > MapSize()) {
+ _cmd_text = NULL;
+ return false;
+ }
assert(_docommand_recursive == 0);
@@ -405,6 +416,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
// spectator has no rights.
if (_current_player == OWNER_SPECTATOR) {
ShowErrorMessage(_error_message, _error_message_2, x, y);
+ _cmd_text = NULL;
return false;
}
@@ -446,6 +458,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
}
_docommand_recursive = 0;
+ _cmd_text = NULL;
return false;
}
@@ -467,6 +480,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
if (_networking && !(cmd & CMD_NETWORK_COMMAND)) {
NetworkSend_Command(tile, p1, p2, cmd, callback);
_docommand_recursive = 0;
+ _cmd_text = NULL;
return true;
}
#endif /* ENABLE_NETWORK */
@@ -505,6 +519,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
_docommand_recursive = 0;
if (callback) callback(true, tile, p1, p2);
+ _cmd_text = NULL;
return true;
show_error:
@@ -516,5 +531,6 @@ callb_err:
_docommand_recursive = 0;
if (callback) callback(false, tile, p1, p2);
+ _cmd_text = NULL;
return false;
}
diff --git a/command.h b/command.h
index 8bb649d28..21b15fb23 100644
--- a/command.h
+++ b/command.h
@@ -190,6 +190,8 @@ static inline bool CmdFailed(int32 res)
int32 DoCommand(int x, int y, uint32 p1, uint32 p2, uint32 flags, uint procc);
int32 DoCommandByTile(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
+extern const char* _cmd_text; // Text, which gets sent with a command
+
bool IsValidCommand(uint cmd);
byte GetCommandFlags(uint cmd);
int32 GetAvailableMoneyForCommand(void);
diff --git a/engine.c b/engine.c
index bcbb87438..11746e747 100644
--- a/engine.c
+++ b/engine.c
@@ -889,7 +889,7 @@ int32 CmdRenameEngine(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (!IsEngineIndex(p1)) return CMD_ERROR;
- str = AllocateNameUnique((const char*)_decode_parameters, 0);
+ str = AllocateNameUnique(_cmd_text, 0);
if (str == 0) return CMD_ERROR;
if (flags & DC_EXEC) {
diff --git a/main_gui.c b/main_gui.c
index 25a050246..4fcc64f11 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -63,7 +63,8 @@ void HandleOnEditText(WindowEvent *e)
{
const char *b = e->edittext.str;
int id;
- memcpy(_decode_parameters, b, 32);
+
+ _cmd_text = b;
id = _rename_id;
diff --git a/misc_cmd.c b/misc_cmd.c
index 576e2e8bf..eca0eba6c 100644
--- a/misc_cmd.c
+++ b/misc_cmd.c
@@ -129,7 +129,7 @@ int32 CmdChangeCompanyName(int x, int y, uint32 flags, uint32 p1, uint32 p2)
StringID str;
Player *p;
- str = AllocateNameUnique((const char*)_decode_parameters, 4);
+ str = AllocateNameUnique(_cmd_text, 4);
if (str == 0) return CMD_ERROR;
if (flags & DC_EXEC) {
@@ -153,7 +153,7 @@ int32 CmdChangePresidentName(int x, int y, uint32 flags, uint32 p1, uint32 p2)
StringID str;
Player *p;
- str = AllocateNameUnique((const char*)_decode_parameters, 4);
+ str = AllocateNameUnique(_cmd_text, 4);
if (str == 0) return CMD_ERROR;
if (flags & DC_EXEC) {
@@ -162,7 +162,10 @@ int32 CmdChangePresidentName(int x, int y, uint32 flags, uint32 p1, uint32 p2)
p->president_name_1 = str;
if (p->name_1 == STR_SV_UNNAMED) {
- ttd_strlcat((char*)_decode_parameters, " Transport", sizeof(_decode_parameters));
+ char buf[80];
+
+ snprintf(buf, lengthof(buf), "%s Transport", _cmd_text);
+ _cmd_text = buf;
DoCommandByTile(0, 0, 0, DC_EXEC, CMD_CHANGE_COMPANY_NAME);
}
MarkWholeScreenDirty();
diff --git a/network_client.c b/network_client.c
index 6f4cebe01..b4d2583c7 100644
--- a/network_client.c
+++ b/network_client.c
@@ -143,13 +143,10 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMMAND)(CommandPacket *cp)
// uint32: P1 (free variables used in DoCommand)
// uint32: P2
// uint32: Tile
- // uint32: decode_params
- // 10 times the last one (lengthof(cp->dp))
+ // string: text
// uint8: CallBackID (see callback_table.c)
//
- uint i;
- char *dparam_char;
Packet *p = NetworkSend_Init(PACKET_CLIENT_COMMAND);
NetworkSend_uint8(p, cp->player);
@@ -157,14 +154,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMMAND)(CommandPacket *cp)
NetworkSend_uint32(p, cp->p1);
NetworkSend_uint32(p, cp->p2);
NetworkSend_uint32(p, (uint32)cp->tile);
- /* We are going to send them byte by byte, because dparam is misused
- for chars (if it is used), and else we have a BigEndian / LittleEndian
- problem.. we should fix the misuse of dparam... -- TrueLight */
- dparam_char = (char *)&cp->dp[0];
- for (i = 0; i < lengthof(cp->dp) * 4; i++) {
- NetworkSend_uint8(p, *dparam_char);
- dparam_char++;
- }
+ NetworkSend_string(p, cp->text);
NetworkSend_uint8(p, cp->callback);
NetworkSend_Packet(p, MY_CLIENT);
@@ -587,22 +577,13 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_SYNC)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMMAND)
{
- uint i;
- char *dparam_char;
CommandPacket *cp = malloc(sizeof(CommandPacket));
cp->player = NetworkRecv_uint8(MY_CLIENT, p);
cp->cmd = NetworkRecv_uint32(MY_CLIENT, p);
cp->p1 = NetworkRecv_uint32(MY_CLIENT, p);
cp->p2 = NetworkRecv_uint32(MY_CLIENT, p);
cp->tile = NetworkRecv_uint32(MY_CLIENT, p);
- /* We are going to send them byte by byte, because dparam is misused
- for chars (if it is used), and else we have a BigEndian / LittleEndian
- problem.. we should fix the misuse of dparam... -- TrueLight */
- dparam_char = (char *)&cp->dp[0];
- for (i = 0; i < lengthof(cp->dp) * 4; i++) {
- *dparam_char = NetworkRecv_uint8(MY_CLIENT, p);
- dparam_char++;
- }
+ NetworkRecv_string(MY_CLIENT, p, cp->text, sizeof(cp->text));
cp->callback = NetworkRecv_uint8(MY_CLIENT, p);
cp->frame = NetworkRecv_uint32(MY_CLIENT, p);
cp->next = NULL;
diff --git a/network_data.c b/network_data.c
index 9de3d4005..b31407790 100644
--- a/network_data.c
+++ b/network_data.c
@@ -5,6 +5,7 @@
// Is the network enabled?
#ifdef ENABLE_NETWORK
+#include "string.h"
#include "table/strings.h"
#include "network_client.h"
#include "command.h"
@@ -394,12 +395,6 @@ void NetworkAddCommandQueue(NetworkClientState *cs, CommandPacket *cp)
}
}
-// If this fails, make sure you change the following line below:
-// 'memcpy(qp->dp, _decode_parameters, 10 * sizeof(uint32));'
-// Also, in network_data.h, change the size of CommandPacket->dp!
-// (this protection is there to make sure in network.h dp is of the right size!)
-assert_compile(sizeof(_decode_parameters) == 20 * sizeof(uint32));
-
// Prepare a DoCommand to be send over the network
void NetworkSend_Command(uint32 tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback)
{
@@ -430,8 +425,7 @@ void NetworkSend_Command(uint32 tile, uint32 p1, uint32 p2, uint32 cmd, CommandC
c->frame = 0; // The client can't tell which frame, so just make it 0
}
- // Copy the _decode_parameters to dp
- memcpy(c->dp, _decode_parameters, 20 * sizeof(uint32));
+ ttd_strlcpy(c->text, (_cmd_text != NULL) ? _cmd_text : "", lengthof(c->text));
if (_network_server) {
// If we are the server, we queue the command in our 'special' queue.
@@ -471,7 +465,7 @@ void NetworkSend_Command(uint32 tile, uint32 p1, uint32 p2, uint32 cmd, CommandC
void NetworkExecuteCommand(CommandPacket *cp)
{
_current_player = cp->player;
- memcpy(_decode_parameters, cp->dp, sizeof(cp->dp));
+ _cmd_text = cp->text;
/* cp->callback is unsigned. so we don't need to do lower bounds checking. */
if (cp->callback > _callback_table_count) {
DEBUG(net,0) ("[NET] Received out-of-bounds callback! (%d)", cp->callback);
diff --git a/network_data.h b/network_data.h
index 8550cd632..48e1cf19e 100644
--- a/network_data.h
+++ b/network_data.h
@@ -38,7 +38,7 @@ typedef struct CommandPacket {
uint32 p1; /// parameter p1
uint32 p2; /// parameter p2
uint32 tile; /// tile command being executed on ; always make it uint32, so it is bigmap compatible (TileIndex)
- uint32 dp[20]; /// _decode_parameters (for sending strings, etc.)
+ char text[80];
uint32 frame; /// the frame in which this packet is executed
byte callback; /// any callback function executed upon successful completion of the command
} CommandPacket;
diff --git a/network_server.c b/network_server.c
index c5614bb33..89e4c4c00 100644
--- a/network_server.c
+++ b/network_server.c
@@ -458,14 +458,11 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMMAND)(NetworkClientState *cs, Com
// uint32: P1 (free variables used in DoCommand)
// uint32: P2
// uint32: Tile
- // uint32: decode_params
- // 10 times the last one (lengthof(cp->dp))
+ // string: text
// uint8: CallBackID (see callback_table.c)
// uint32: Frame of execution
//
- uint i;
- char *dparam_char;
Packet *p = NetworkSend_Init(PACKET_SERVER_COMMAND);
NetworkSend_uint8(p, cp->player);
@@ -473,14 +470,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMMAND)(NetworkClientState *cs, Com
NetworkSend_uint32(p, cp->p1);
NetworkSend_uint32(p, cp->p2);
NetworkSend_uint32(p, cp->tile);
- /* We are going to send them byte by byte, because dparam is misused
- for chars (if it is used), and else we have a BigEndian / LittleEndian
- problem.. we should fix the misuse of dparam... -- TrueLight */
- dparam_char = (char *)&cp->dp[0];
- for (i = 0; i < lengthof(cp->dp) * 4; i++) {
- NetworkSend_uint8(p, *dparam_char);
- dparam_char++;
- }
+ NetworkSend_string(p, cp->text);
NetworkSend_uint8(p, cp->callback);
NetworkSend_uint32(p, cp->frame);
@@ -806,8 +796,6 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
{
NetworkClientState *new_cs;
const NetworkClientInfo *ci;
- char *dparam_char;
- uint i;
byte callback;
CommandPacket *cp = malloc(sizeof(CommandPacket));
@@ -824,15 +812,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
cp->p1 = NetworkRecv_uint32(cs, p);
cp->p2 = NetworkRecv_uint32(cs, p);
cp->tile = NetworkRecv_uint32(cs, p);
- /** @todo We are going to send dparams byte by byte, because dparam is misused
- * for charstrings (if it is used), and else we have a Big/Little Endian
- * problem.. we should fix the misuse of dparam... -- TrueLight
- */
- dparam_char = (char *)&cp->dp[0];
- for (i = 0; i < lengthof(cp->dp) * 4; i++) {
- *dparam_char = NetworkRecv_uint8(cs, p);
- dparam_char++;
- }
+ NetworkRecv_string(cs, p, cp->text, lengthof(cp->text));
callback = NetworkRecv_uint8(cs, p);
diff --git a/order_cmd.c b/order_cmd.c
index 1a214a302..188c210be 100644
--- a/order_cmd.c
+++ b/order_cmd.c
@@ -758,7 +758,7 @@ void RestoreVehicleOrders(Vehicle *v, BackuppedOrders *bak)
/* If we have a custom name, process that */
if (bak->name[0] != 0) {
- strcpy((char*)_decode_parameters, bak->name);
+ _cmd_text = bak->name;
DoCommandP(0, v->index, 0, NULL, CMD_NAME_VEHICLE);
}
diff --git a/player_gui.c b/player_gui.c
index 33d51dd63..6bc47700e 100644
--- a/player_gui.c
+++ b/player_gui.c
@@ -650,7 +650,7 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
if (*b == 0 && WP(w,def_d).byte_1 != 2) // empty string is allowed for password
return;
- memcpy(_decode_parameters, b, 32);
+ _cmd_text = b;
switch (WP(w,def_d).byte_1) {
case 0: /* Change president name */
DoCommandP(0, w->window_number, 0, NULL, CMD_CHANGE_PRESIDENT_NAME | CMD_MSG(STR_700D_CAN_T_CHANGE_PRESIDENT));
diff --git a/players.c b/players.c
index e196fbc13..01770c0b5 100644
--- a/players.c
+++ b/players.c
@@ -691,16 +691,18 @@ int32 CmdPlayerCtrl(int x, int y, uint32 flags, uint32 p1, uint32 p2)
PlayerID player_backup = _local_player;
_network_player_info[p->index].months_empty = 0;
- /* XXX - When a client joins, we automatically set it's name to the player's
- * name (for some reason). As it stands now only the server knows the client's
- * name, so it needs to send out a "broadcast" to do this. To achieve this we send
- * a network command. However, it uses _local_player to execute the command as.
- * To prevent abuse (eg. only yourself can change your name/company), we 'cheat'
- * by impersonation _local_player as the server. Not the best solution; but it
- * works.
- * TODO: Perhaps this could be improved by when the client is ready with joining
- * to let it send itself the command, and not the server? For example in network_client.c:534? */
- memcpy(_decode_parameters, ci->client_name, 32);
+ /* XXX - When a client joins, we automatically set its name to the
+ * player's name (for some reason). As it stands now only the server
+ * knows the client's name, so it needs to send out a "broadcast" to
+ * do this. To achieve this we send a network command. However, it
+ * uses _local_player to execute the command as. To prevent abuse
+ * (eg. only yourself can change your name/company), we 'cheat' by
+ * impersonation _local_player as the server. Not the best solution;
+ * but it works.
+ * TODO: Perhaps this could be improved by when the client is ready
+ * with joining to let it send itself the command, and not the server?
+ * For example in network_client.c:534? */
+ _cmd_text = ci->client_name;
_local_player = ci->client_playas - 1;
NetworkSend_Command(0, 0, 0, CMD_CHANGE_PRESIDENT_NAME, NULL);
_local_player = player_backup;
diff --git a/roadveh_gui.c b/roadveh_gui.c
index dcff9c803..96faab074 100644
--- a/roadveh_gui.c
+++ b/roadveh_gui.c
@@ -159,11 +159,11 @@ do_change_service_int:
break;
case WE_ON_EDIT_TEXT: {
- const char *b = e->edittext.str;
- if (*b == 0)
- return;
- memcpy(_decode_parameters, b, 32);
- DoCommandP(0, w->window_number, 0, NULL, CMD_NAME_VEHICLE | CMD_MSG(STR_902D_CAN_T_NAME_ROAD_VEHICLE));
+ if (e->edittext.str[0] != '\0') {
+ _cmd_text = e->edittext.str;
+ DoCommandP(0, w->window_number, 0, NULL,
+ CMD_NAME_VEHICLE | CMD_MSG(STR_902D_CAN_T_NAME_ROAD_VEHICLE));
+ }
} break;
}
@@ -441,11 +441,11 @@ static void NewRoadVehWndProc(Window *w, WindowEvent *e)
break;
case WE_ON_EDIT_TEXT: {
- const char *b = e->edittext.str;
- if (*b == 0)
- return;
- memcpy(_decode_parameters, b, 32);
- DoCommandP(0, WP(w,buildtrain_d).rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(STR_9037_CAN_T_RENAME_ROAD_VEHICLE));
+ if (e->edittext.str[0] != '\0') {
+ _cmd_text = e->edittext.str;
+ DoCommandP(0, WP(w, buildtrain_d).rename_engine, 0, NULL,
+ CMD_RENAME_ENGINE | CMD_MSG(STR_9037_CAN_T_RENAME_ROAD_VEHICLE));
+ }
} break;
case WE_RESIZE: {
diff --git a/ship_gui.c b/ship_gui.c
index 1e1428de2..70e39c49e 100644
--- a/ship_gui.c
+++ b/ship_gui.c
@@ -236,11 +236,11 @@ do_change_service_int:
break;
case WE_ON_EDIT_TEXT: {
- const char *b = e->edittext.str;
- if (*b == 0)
- return;
- memcpy(_decode_parameters, b, 32);
- DoCommandP(0, w->window_number, 0, NULL, CMD_NAME_VEHICLE | CMD_MSG(STR_9832_CAN_T_NAME_SHIP));
+ if (e->edittext.str[0] != '\0') {
+ _cmd_text = e->edittext.str;
+ DoCommandP(0, w->window_number, 0, NULL,
+ CMD_NAME_VEHICLE | CMD_MSG(STR_9832_CAN_T_NAME_SHIP));
+ }
} break;
}
@@ -378,11 +378,11 @@ static void NewShipWndProc(Window *w, WindowEvent *e)
break;
case WE_ON_EDIT_TEXT: {
- const char *b = e->edittext.str;
- if (*b == 0)
- return;
- memcpy(_decode_parameters, b, 32);
- DoCommandP(0, WP(w,buildtrain_d).rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(STR_9839_CAN_T_RENAME_SHIP_TYPE));
+ if (e->edittext.str[0] != '\0') {
+ _cmd_text = e->edittext.str;
+ DoCommandP(0, WP(w, buildtrain_d).rename_engine, 0, NULL,
+ CMD_RENAME_ENGINE | CMD_MSG(STR_9839_CAN_T_RENAME_SHIP_TYPE));
+ }
} break;
case WE_RESIZE:
diff --git a/signs.c b/signs.c
index fe7166098..c8f82404e 100644
--- a/signs.c
+++ b/signs.c
@@ -142,7 +142,7 @@ int32 CmdRenameSign(int x, int y, uint32 flags, uint32 p1, uint32 p2)
* So rename the sign. If it is empty, it has no name, so delete it */
if (GetDParam(0) != 0) {
/* Create the name */
- StringID str = AllocateName((const char*)_decode_parameters, 0);
+ StringID str = AllocateName(_cmd_text, 0);
if (str == 0) return CMD_ERROR;
if (flags & DC_EXEC) {
diff --git a/station_cmd.c b/station_cmd.c
index f279dd5c4..79ea2ce84 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -2658,7 +2658,7 @@ int32 CmdRenameStation(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (!IsValidStation(st) || !CheckOwnership(st->owner)) return CMD_ERROR;
- str = AllocateNameUnique((const char*)_decode_parameters, 6);
+ str = AllocateNameUnique(_cmd_text, 6);
if (str == 0) return CMD_ERROR;
if (flags & DC_EXEC) {
diff --git a/station_gui.c b/station_gui.c
index 608e292e7..046b580ec 100644
--- a/station_gui.c
+++ b/station_gui.c
@@ -503,14 +503,13 @@ static void StationViewWndProc(Window *w, WindowEvent *e)
break;
case WE_ON_EDIT_TEXT: {
- Station *st;
- const char *b = e->edittext.str;
- if (*b == 0)
- return;
- memcpy(_decode_parameters, b, 32);
-
- st = GetStation(w->window_number);
- DoCommandP(st->xy, w->window_number, 0, NULL, CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION));
+ if (e->edittext.str[0] != '\0') {
+ Station* st = GetStation(w->window_number);
+
+ _cmd_text = e->edittext.str;
+ DoCommandP(st->xy, w->window_number, 0, NULL,
+ CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION));
+ }
} break;
case WE_DESTROY: {
diff --git a/town_cmd.c b/town_cmd.c
index 10f797876..8eb782d9e 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -1451,7 +1451,7 @@ int32 CmdRenameTown(int x, int y, uint32 flags, uint32 p1, uint32 p2)
t = GetTown(p1);
- str = AllocateNameUnique((const char*)_decode_parameters, 4);
+ str = AllocateNameUnique(_cmd_text, 4);
if (str == 0) return CMD_ERROR;
if (flags & DC_EXEC) {
diff --git a/town_gui.c b/town_gui.c
index 58e258357..17c98fd20 100644
--- a/town_gui.c
+++ b/town_gui.c
@@ -276,11 +276,11 @@ static void TownViewWndProc(Window *w, WindowEvent *e)
break;
case WE_ON_EDIT_TEXT: {
- const char *b = e->edittext.str;
- if (*b == 0)
- return;
- memcpy(_decode_parameters, b, 32);
- DoCommandP(0, w->window_number, 0, NULL, CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN));
+ if (e->edittext.str[0] != '\0') {
+ _cmd_text = e->edittext.str;
+ DoCommandP(0, w->window_number, 0, NULL,
+ CMD_RENAME_TOWN | CMD_MSG(STR_2008_CAN_T_RENAME_TOWN));
+ }
} break;
}
}
diff --git a/train_gui.c b/train_gui.c
index 3cc68811f..1e8ce749c 100644
--- a/train_gui.c
+++ b/train_gui.c
@@ -219,12 +219,11 @@ static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
break;
case WE_ON_EDIT_TEXT: {
- const char *b = e->edittext.str;
- if (*b == 0)
- return;
-
- memcpy(_decode_parameters, b, 32);
- DoCommandP(0, WP(w,buildtrain_d).rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(STR_886B_CAN_T_RENAME_TRAIN_VEHICLE));
+ if (e->edittext.str[0] != '\0') {
+ _cmd_text = e->edittext.str;
+ DoCommandP(0, WP(w,buildtrain_d).rename_engine, 0, NULL,
+ CMD_RENAME_ENGINE | CMD_MSG(STR_886B_CAN_T_RENAME_TRAIN_VEHICLE));
+ }
} break;
case WE_RESIZE: {
@@ -1144,11 +1143,11 @@ do_change_service_int:
break;
case WE_ON_EDIT_TEXT: {
- const char *b = e->edittext.str;
- if (*b == 0)
- return;
- memcpy(_decode_parameters, b, 32);
- DoCommandP(0, w->window_number, 0, NULL, CMD_NAME_VEHICLE | CMD_MSG(STR_8866_CAN_T_NAME_TRAIN));
+ if (e->edittext.str[0] != '\0') {
+ _cmd_text = e->edittext.str;
+ DoCommandP(0, w->window_number, 0, NULL,
+ CMD_NAME_VEHICLE | CMD_MSG(STR_8866_CAN_T_NAME_TRAIN));
+ }
} break;
}
}
diff --git a/vehicle.c b/vehicle.c
index a705ed93b..82a2bf719 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -1660,7 +1660,7 @@ int32 CmdNameVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (!CheckOwnership(v->owner)) return CMD_ERROR;
- str = AllocateNameUnique((const char*)_decode_parameters, 2);
+ str = AllocateNameUnique(_cmd_text, 2);
if (str == 0) return CMD_ERROR;
if (flags & DC_EXEC) {
diff --git a/waypoint.c b/waypoint.c
index dd6750fe1..f2c502b32 100644
--- a/waypoint.c
+++ b/waypoint.c
@@ -302,8 +302,8 @@ int32 CmdRenameWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (!IsWaypointIndex(p1)) return CMD_ERROR;
- if (_decode_parameters[0] != 0) {
- str = AllocateNameUnique((const char*)_decode_parameters, 0);
+ if (_cmd_text[0] != '\0') {
+ str = AllocateNameUnique(_cmd_text, 0);
if (str == 0)
return CMD_ERROR;