1
0
forked from 0ad/0ad

Fix 3171 by moving some logic to C++. These changes do not optimize the presence buffer and only fix the state bug.

This was SVN commit r16961.
This commit is contained in:
JoshuaJB 2015-08-30 12:56:48 +00:00
parent 2aef62d65f
commit 45a39e7dfd
4 changed files with 23 additions and 27 deletions

View File

@ -14,7 +14,6 @@ const g_mapTypesText = [translateWithContext("map", "Skirmish"), translateWithCo
const g_mapTypes = ["skirmish", "random", "scenario"];
var g_userRating = ""; // Rating of user, defaults to Unrated
var g_modPrefix = "@";
var g_joined = false;
// Block spammers for 30 seconds.
var SPAM_BLOCK_LENGTH = 30;
@ -699,17 +698,6 @@ function onTick()
switch(message.level)
{
case "join":
if (nick == g_Name)
{
// We just joined, we need to get the full player list
[playerList, presenceList, nickList, ratingList] = updatePlayerList();
// Don't display any joins until our join request bounces back
// Our join message should be the last one as we just got added to the stack
g_joined = true;
break;
}
else if (g_joined)
{
var [name, status, rating] = formatPlayerListEntry(nick, presence, "-");
playerList.push(name);
presenceList.push(status);
@ -717,7 +705,6 @@ function onTick()
ratingList.push(String(rating));
Engine.SendGetRatingList();
addChatMessage({ "text": "/special " + sprintf(translate("%(nick)s has joined."), { nick: nick }), "key": g_specialKey });
}
break;
case "leave":
if (nickIndex == -1) // Left, but not present (TODO: warn about this?)
@ -729,7 +716,7 @@ function onTick()
addChatMessage({ "text": "/special " + sprintf(translate("%(nick)s has left."), { nick: nick }), "key": g_specialKey });
break;
case "nick":
if (nickIndex == -1) // This shouldn't ever happen
if (nickIndex == -1) // Changed nick, but not present (shouldn't ever happen)
break;
if (!isValidNick(message.data))
{
@ -744,7 +731,7 @@ function onTick()
Engine.SendGetRatingList();
break;
case "presence":
if (nickIndex == -1) // This shouldn't ever happen
if (nickIndex == -1) // Changed presence, but not online (shouldn't ever happen)
break;
var [name, status, rating] = formatPlayerListEntry(nick, presence, stripColorCodes(ratingList[nickIndex]));
presenceList[nickIndex] = status;

View File

@ -169,7 +169,7 @@ function onTick()
if (!message)
break;
if (message.type == "muc" && message.level == "join")
if (message.type == "system" && message.text == "connected")
{
// We are connected, switch to the lobby page
Engine.PopGuiPage();
@ -186,8 +186,6 @@ function onTick()
g_EncrytedPassword = Engine.EncryptPassword(password, username);
Engine.ConfigDB_CreateValue("user", "lobby.password", g_EncrytedPassword);
Engine.ConfigDB_WriteFile("user", "config/user.cfg");
return;
}
else if (message.type == "system" && message.text == "registered")
{

View File

@ -156,6 +156,7 @@ XmppClient::~XmppClient()
/// Network
void XmppClient::connect()
{
m_initialLoadComplete = false;
m_client->connect(false);
}
@ -802,7 +803,16 @@ void XmppClient::handleMUCParticipantPresence(glooxwrapper::MUCRoom*, const gloo
}
else
{
if (m_PlayerMap.find(nick) == m_PlayerMap.end())
/* During the initialization process, we recieve join messages for everyone
* currently in the room. We don't want to display these, so we filter them
* out. We will always be the last to join during initialization.
*/
if (!m_initialLoadComplete)
{
if (m_mucRoom->nick().to_string() == nick)
m_initialLoadComplete = true;
}
else if (m_PlayerMap.find(nick) == m_PlayerMap.end())
CreateSimpleMessage("muc", nick, "join");
else
CreateSimpleMessage("muc", nick, "presence");

View File

@ -48,7 +48,8 @@ private:
std::string m_password;
std::string m_nick;
std::string m_xpartamuppId;
// State
bool m_initialLoadComplete = false;
public:
//Basic
XmppClient(const std::string& sUsername, const std::string& sPassword, const std::string& sRoom, const std::string& sNick, const int historyRequestSize = 0, const bool regOpt = false);