(svn r2291) - Fix (regression): When a client joined it changed the server-player's name. Funny effect; but not desired. Thanks for pointing it out Tron. It needed a bit of hacking, but is not less of a hack than the one used before :)

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
Darkvater 19 years ago
parent 5e6923e936
commit 6cdb9580e2

@ -126,7 +126,7 @@ int32 CmdDecreaseLoan(int x, int y, uint32 flags, uint32 p1, uint32 p2)
*/ */
int32 CmdChangeCompanyName(int x, int y, uint32 flags, uint32 p1, uint32 p2) int32 CmdChangeCompanyName(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{ {
StringID str,old_str; StringID str;
Player *p; Player *p;
str = AllocateNameUnique((const char*)_decode_parameters, 4); str = AllocateNameUnique((const char*)_decode_parameters, 4);
@ -134,13 +134,11 @@ int32 CmdChangeCompanyName(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
p = DEREF_PLAYER(_current_player); p = DEREF_PLAYER(_current_player);
old_str = p->name_1; DeleteName(p->name_1);
p->name_1 = str; p->name_1 = str;
DeleteName(old_str);
MarkWholeScreenDirty(); MarkWholeScreenDirty();
} else { } else
DeleteName(str); DeleteName(str);
}
return 0; return 0;
} }
@ -152,7 +150,7 @@ int32 CmdChangeCompanyName(int x, int y, uint32 flags, uint32 p1, uint32 p2)
*/ */
int32 CmdChangePresidentName(int x, int y, uint32 flags, uint32 p1, uint32 p2) int32 CmdChangePresidentName(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{ {
StringID str,old_str; StringID str;
Player *p; Player *p;
str = AllocateNameUnique((const char*)_decode_parameters, 4); str = AllocateNameUnique((const char*)_decode_parameters, 4);
@ -160,18 +158,16 @@ int32 CmdChangePresidentName(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
p = DEREF_PLAYER(_current_player); p = DEREF_PLAYER(_current_player);
old_str = p->president_name_1; DeleteName(p->president_name_1);
p->president_name_1 = str; p->president_name_1 = str;
DeleteName(old_str);
if (p->name_1 == STR_SV_UNNAMED) { if (p->name_1 == STR_SV_UNNAMED) {
ttd_strlcat((char*)_decode_parameters, " Transport", sizeof(_decode_parameters)); ttd_strlcat((char*)_decode_parameters, " Transport", sizeof(_decode_parameters));
DoCommandByTile(0, p1, 0, DC_EXEC, CMD_CHANGE_COMPANY_NAME); DoCommandByTile(0, 0, 0, DC_EXEC, CMD_CHANGE_COMPANY_NAME);
} }
MarkWholeScreenDirty(); MarkWholeScreenDirty();
} else { } else
DeleteName(str); DeleteName(str);
}
return 0; return 0;
} }

@ -672,12 +672,22 @@ int32 CmdPlayerCtrl(int x, int y, uint32 flags, uint32 p1, uint32 p2)
NetworkUpdateClientInfo(ci->client_index); NetworkUpdateClientInfo(ci->client_index);
if (ci->client_playas != 0 && ci->client_playas <= MAX_PLAYERS) { if (ci->client_playas != 0 && ci->client_playas <= MAX_PLAYERS) {
PlayerID player_backup = _local_player;
_network_player_info[p->index].months_empty = 0; _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); memcpy(_decode_parameters, ci->client_name, 32);
/* XXX - What are the consequents of this? It is needed, but is it bad? */ _local_player = ci->client_playas - 1;
_docommand_recursive = 0; NetworkSend_Command(0, 0, 0, CMD_CHANGE_PRESIDENT_NAME, NULL);
DoCommandP(0, ci->client_playas-1, 0, NULL, CMD_CHANGE_PRESIDENT_NAME | CMD_MSG(STR_700D_CAN_T_CHANGE_PRESIDENT)); _local_player = player_backup;
} }
} }
} else { } else {

@ -279,7 +279,7 @@ VARDEF bool _is_ai_player; // current player is an AI player? - Can be removed i
VARDEF bool _do_autosave; VARDEF bool _do_autosave;
VARDEF int _autosave_ctr; VARDEF int _autosave_ctr;
VARDEF byte _local_player; VARDEF PlayerID _local_player;
VARDEF byte _display_opt; VARDEF byte _display_opt;
VARDEF byte _pause; VARDEF byte _pause;
VARDEF int _caret_timer; VARDEF int _caret_timer;
@ -292,7 +292,7 @@ VARDEF StringID _error_message_2;
VARDEF int32 _additional_cash_required; VARDEF int32 _additional_cash_required;
VARDEF uint32 _decode_parameters[20]; VARDEF uint32 _decode_parameters[20];
VARDEF byte _current_player; VARDEF PlayerID _current_player;
VARDEF int _docommand_recursive; VARDEF int _docommand_recursive;

Loading…
Cancel
Save