Print "Oldname → Newname" instead of "Oldname: -> Newname".

master
Cyp 2010-08-13 13:44:17 +02:00
parent 18307a7fc1
commit fcd0b6fe46
4 changed files with 29 additions and 6 deletions

View File

@ -1415,11 +1415,14 @@ static BOOL NETprocessSystemMessage(void)
}
for (n = 0; n < indexLen; ++n)
{
bool wasAllocated = false;
char oldName[sizeof(NetPlay.players[index].name)];
// Retrieve the player's ID
NETuint32_t(&index);
// Bail out if the given ID number is out of range
if (index >= MAX_CONNECTED_PLAYERS || (NetMsg.source != NetPlay.hostPlayer && NetMsg.source != index))
if (index >= MAX_CONNECTED_PLAYERS || (NetMsg.source != NetPlay.hostPlayer && (NetMsg.source != index || !NetPlay.players[index].allocated)))
{
debug(LOG_ERROR, "MSG_PLAYER_INFO: Player ID (%u) out of range (max %u)", index, (unsigned int)MAX_CONNECTED_PLAYERS);
NETend();
@ -1428,9 +1431,11 @@ static BOOL NETprocessSystemMessage(void)
}
// Retrieve the rest of the data
wasAllocated = NetPlay.players[index].allocated;
NETbool(&NetPlay.players[index].allocated);
NETbool(&NetPlay.players[index].heartbeat);
NETbool(&NetPlay.players[index].kick);
strncpy(oldName, NetPlay.players[index].name, sizeof(NetPlay.players[index].name));
NETstring(NetPlay.players[index].name, sizeof(NetPlay.players[index].name));
NETuint32_t(&NetPlay.players[index].heartattacktime);
NETint32_t(&colour);
@ -1450,6 +1455,11 @@ static BOOL NETprocessSystemMessage(void)
debug(LOG_NET, "%s for player %u (%s)", n == 0? "Receiving MSG_PLAYER_INFO" : " and", (unsigned int)index, NetPlay.players[index].allocated ? "human" : "AI");
// update the color to the local array
setPlayerColour(index, NetPlay.players[index].colour);
if (wasAllocated && NetPlay.players[index].allocated && strncmp(oldName, NetPlay.players[index].name, sizeof(NetPlay.players[index].name)) != 0)
{
printConsoleNameChange(oldName, NetPlay.players[index].name);
}
}
NETuint32_t(&hostPlayer);
NETend();

View File

@ -2499,8 +2499,7 @@ static void processMultiopWidgets(UDWORD id)
removeWildcards((char*)sPlayer);
ssprintf(tmp, "-> %s", sPlayer);
sendTextMessage(tmp,true);
printConsoleNameChange(NetPlay.players[selectedPlayer].name, sPlayer);
NETchangePlayerName(selectedPlayer, (char*)sPlayer); // update if joined.
loadMultiStats((char*)sPlayer,&playerStats);
@ -3094,8 +3093,9 @@ void runMultiOptions(void)
sstrcpy(sPlayer, sTemp);
widgSetString(psWScreen,MULTIOP_PNAME,sTemp);
ssprintf(sTemp, " -> %s", sPlayer);
sendTextMessage(sTemp,true);
removeWildcards((char*)sPlayer);
printConsoleNameChange(NetPlay.players[selectedPlayer].name, sPlayer);
NETchangePlayerName(selectedPlayer, (char*)sPlayer);
loadMultiStats((char*)sPlayer,&playerStats);

View File

@ -1033,7 +1033,6 @@ BOOL recvResearchStatus()
return true;
}
// ////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////
// Text Messaging between players. proceed string with players to send to.
@ -1180,6 +1179,19 @@ BOOL sendTextMessage(const char *pStr, BOOL all)
return true;
}
void printConsoleNameChange(const char *oldName, const char *newName)
{
char msg[MAX_CONSOLE_STRING_LENGTH];
// Player changed name.
sstrcpy(msg, oldName); // Old name.
sstrcat(msg, ""); // Separator
sstrcat(msg, newName); // New name.
addConsoleMessage(msg, DEFAULT_JUSTIFY, selectedPlayer); // display
}
//AI multiplayer message, send from a certain player index to another player index
BOOL sendAIMessage(char *pStr, UDWORD player, UDWORD to)
{

View File

@ -150,6 +150,7 @@ extern BOOL SendResearch(uint8_t player, uint32_t index, bool trigger);
extern BOOL SendDestroyFeature (FEATURE *pF); // send a destruct feature message.
extern BOOL sendTextMessage (const char *pStr,BOOL cast); // send a text message
extern BOOL sendAIMessage (char *pStr, UDWORD player, UDWORD to); //send AI message
void printConsoleNameChange(const char *oldName, const char *newName); ///< Print message to console saying a name changed.
extern void turnOffMultiMsg (BOOL bDoit);