Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/lobby/LobbyPage/ConnectionHandler.js
- This file was added.
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | native \ No newline at end of property |
/** | |||||
* This class will ask the player to rejoin the lobby after having been disconnected. | |||||
*/ | |||||
class ConnectionHandler | |||||
{ | |||||
constructor(xmppMessages) | |||||
{ | |||||
/** | |||||
* Whether the player was already asked to reconnect to the lobby. | |||||
* Ensures that no more than one message box is opened at a time. | |||||
*/ | |||||
this.askedReconnect = false; | |||||
/** | |||||
* Whether the current user has been kicked or banned. | |||||
*/ | |||||
this.kicked = false; | |||||
xmppMessages.registerHandler("system", "connected", this.onConnected.bind(this)); | |||||
xmppMessages.registerHandler("system", "disconnected", this.onDisconnected.bind(this)); | |||||
xmppMessages.registerHandler("chat", "leave", this.onClientLeave.bind(this)); | |||||
xmppMessages.registerHandler("chat", "kicked", this.onClientKicked.bind(this, false)); | |||||
xmppMessages.registerHandler("chat", "banned", this.onClientKicked.bind(this, true)); | |||||
// Ask to reconnect to the lobby if the player opened the lobby from a running match | |||||
if (!Engine.IsXmppClientConnected()) | |||||
Freagarach: +`.` | |||||
this.reconnectMessageBox(); | |||||
} | |||||
onConnected() | |||||
{ | |||||
this.askedReconnect = false; | |||||
} | |||||
onClientLeave(message) | |||||
{ | |||||
if (message.nick == g_Username) | |||||
Engine.DisconnectXmppClient(); | |||||
} | |||||
onClientKicked(banned, message) | |||||
{ | |||||
if (message.nick != g_Username) | |||||
return; | |||||
this.kicked = true; | |||||
// The current player has been kicked from the room, not from the server | |||||
Engine.DisconnectXmppClient(); | |||||
Not Done Inline Actions+. Freagarach: +`.` | |||||
messageBox( | |||||
400, 250, | |||||
new KickStrings().get(banned, message), | |||||
banned ? translate("BANNED") : translate("KICKED")); | |||||
} | |||||
onDisconnected() | |||||
{ | |||||
if (!this.kicked) | |||||
this.reconnectMessageBox(); | |||||
} | |||||
reconnectMessageBox() | |||||
{ | |||||
if (this.askedReconnect) | |||||
return; | |||||
this.askedReconnect = true; | |||||
messageBox( | |||||
400, 200, | |||||
translate("You have been disconnected from the lobby. Do you want to reconnect?"), | |||||
translate("Confirmation"), | |||||
[translate("No"), translate("Yes")], | |||||
[null, Engine.ConnectXmppClient]); | |||||
} | |||||
} |
Wildfire Games · Phabricator
+.