Made chat messages send a GUID rather than a user name

This was SVN commit r7943.
This commit is contained in:
WhiteTreePaladin 2010-08-14 15:34:36 +00:00
parent 50bccd8720
commit 8967395da6
7 changed files with 22 additions and 32 deletions

View File

@ -13,7 +13,7 @@ var notificationsTimers = [];
// Notifications
function handleNotifications()
{
var notification = Engine.GuiInterfaceCall("PopNotification");
var notification = Engine.GuiInterfaceCall("GetNextNotification");
if (notification && notification.player == Engine.GetPlayerID())
{
@ -88,7 +88,7 @@ function handleNetMessage(message)
}
break;
case "chat":
addChatMessage({ "type": "message", "username": message.username, "text": message.text });
addChatMessage({ "type": "message", "guid": message.guid, "text": message.text });
break;
default:
error("Unrecognised net message type "+message.type);
@ -104,12 +104,10 @@ function submitChatInput()
if (g_IsNetworked)
Engine.SendNetworkChat(text);
else
addChatMessage({ "type": "message", "username": g_Players[1].name, "text": text });
addChatMessage({ "type": "message", "guid": 1, "text": text });
input.caption = "";
// Remove focus
input.blur();
input.caption = ""; // Clear chat input
input.blur(); // Remove focus
}
toggleChatWindow();
@ -120,22 +118,23 @@ function addChatMessage(msg)
// TODO: we ought to escape all values before displaying them,
// to prevent people inserting colours and newlines etc
//var n = msg.player;
//var playerColor = g_Players[n].color.r + " " + g_Players[n].color.g + " " + g_Players[n].color.b;
var playerColor = getColorByPlayerName(msg.username);
var n = msg.guid;
var username = g_Players[n].name;
var playerColor = g_Players[n].color.r + " " + g_Players[n].color.g + " " + g_Players[n].color.b;
var formatted;
switch (msg.type)
{
/*
case "disconnect":
formatted = "<[color=\"" + playerColor + "\"]" + msg.username + "[/color]> has left";
formatted = "<[color=\"" + playerColor + "\"]" + username + "[/color]> has left";
break;
*/
case "message":
console.write("<" + msg.username + "> " + msg.text);
formatted = "<[color=\"" + playerColor + "\"]" + msg.username + "[/color]> " + msg.text;
console.write("<" + username + "> " + msg.text);
formatted = "<[color=\"" + playerColor + "\"]" + username + "[/color]> " + msg.text;
break;
default:
error("Invalid chat message '" + uneval(msg) + "'");
return;
@ -159,12 +158,3 @@ function removeOldChatMessages()
chatMessages.shift();
getGUIObjectByName("chatText").caption = chatMessages.join("\n");
}
function getColorByPlayerName(playerName)
{
for (var i = 0; i < g_Players.length; i++)
if (playerName == g_Players[i].name)
return g_Players[i].color.r + " " + g_Players[i].color.g + " " + g_Players[i].color.b;
return "255 255 255";
}

View File

@ -23,7 +23,7 @@ var g_IsNetworked = false;
// Cache the basic player data (name, civ, color)
var g_Players = [];
var g_PlayerAssignments = {};
var g_PlayerAssignments = { "local": { "name": "You", "player": 1 } };
var g_PlayerID;
// Cache dev-mode settings that are frequently or widely used

View File

@ -181,7 +181,7 @@ GuiInterface.prototype.PushNotification = function(notification)
this.notifications.push(notification);
};
GuiInterface.prototype.PopNotification = function()
GuiInterface.prototype.GetNextNotification = function()
{
if (this.notifications.length)
return this.notifications.pop();
@ -387,7 +387,7 @@ var exposedFunctions = {
"GetSimulationState": 1,
"GetEntityState": 1,
"GetTemplateData": 1,
"PopNotification": 1,
"GetNextNotification": 1,
"SetSelectionHighlight": 1,
"DisplayRallyPoint": 1,

View File

@ -95,7 +95,7 @@ Player.prototype.TrySubtractResources = function(amounts)
// If we don't have enough resources, send a notification to the player
if (formattedAmountsNeeded.length)
{
var notification = {"player": this.playerID, "message": "Resources needed: " + formattedAmountsNeeded.join(", ")};
var notification = {"player": this.playerID, "message": "Insufficient resources - " + formattedAmountsNeeded.join(", ")};
var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
cmpGUIInterface.PushNotification(notification);
return false;
@ -104,7 +104,7 @@ Player.prototype.TrySubtractResources = function(amounts)
{
// Subtract the resources
for (var type in amounts)
this.resourceCount[type] -= amounts[type];
this.resourceCount[type] -= amounts[type];
}
return true;

View File

@ -292,7 +292,7 @@ bool CNetClient::OnChat(void* context, CFsmEvent* event)
CScriptValRooted msg;
client->GetScriptInterface().Eval("({'type':'chat'})", msg);
client->GetScriptInterface().SetProperty(msg.get(), "username", std::wstring(message->m_Sender), false);
client->GetScriptInterface().SetProperty(msg.get(), "guid", std::string(message->m_GUID), false);
client->GetScriptInterface().SetProperty(msg.get(), "text", std::wstring(message->m_Message), false);
client->PushGuiMessage(msg);

View File

@ -107,7 +107,7 @@ START_NMT_CLASS_(AuthenticateResult, NMT_AUTHENTICATE_RESULT)
END_NMT_CLASS()
START_NMT_CLASS_(Chat, NMT_CHAT)
NMT_FIELD(CStrW, m_Sender) // ignored when client->server, valid when server->client
NMT_FIELD(CStr8, m_GUID) // ignored when client->server, valid when server->client
NMT_FIELD(CStrW, m_Message)
END_NMT_CLASS()

View File

@ -484,7 +484,7 @@ bool CNetServer::OnChat(void* context, CFsmEvent* event)
CChatMessage* message = (CChatMessage*)event->GetParamRef();
message->m_Sender = session->GetUserName();
message->m_GUID = session->GetHostID();
server.Broadcast(message);