Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/gamesetup_mp/gamesetup_mp.js
Show First 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | |||||
function confirmSetup() | function confirmSetup() | ||||
{ | { | ||||
if (!Engine.GetGUIObjectByName("pageJoin").hidden) | if (!Engine.GetGUIObjectByName("pageJoin").hidden) | ||||
{ | { | ||||
let joinPlayerName = Engine.GetGUIObjectByName("joinPlayerName").caption; | let joinPlayerName = Engine.GetGUIObjectByName("joinPlayerName").caption; | ||||
let joinServer = Engine.GetGUIObjectByName("joinServer").caption; | let joinServer = Engine.GetGUIObjectByName("joinServer").caption; | ||||
let joinPort = Engine.GetGUIObjectByName("joinPort").caption; | let joinPort = Engine.GetGUIObjectByName("joinPort").caption; | ||||
if (startJoin(joinPlayerName, joinServer, getValidPort(joinPort), false, "")) | if (startJoin(joinPlayerName, joinServer, getValidPort(joinPort))) | ||||
switchSetupPage("pageConnecting"); | switchSetupPage("pageConnecting"); | ||||
} | } | ||||
else if (!Engine.GetGUIObjectByName("pageHost").hidden) | else if (!Engine.GetGUIObjectByName("pageHost").hidden) | ||||
{ | { | ||||
let hostServerName = Engine.GetGUIObjectByName("hostServerName").caption; | let hostServerName = Engine.GetGUIObjectByName("hostServerName").caption; | ||||
if (!hostServerName) | if (!hostServerName) | ||||
{ | { | ||||
Engine.GetGUIObjectByName("hostFeedback").caption = translate("Please enter a valid server name."); | Engine.GetGUIObjectByName("hostFeedback").caption = translate("Please enter a valid server name."); | ||||
▲ Show 20 Lines • Show All 236 Lines • ▼ Show 20 Lines | if (Engine.HasXmppClient() && | ||||
hostFeedback.caption = translate("Game name already in use."); | hostFeedback.caption = translate("Game name already in use."); | ||||
return false; | return false; | ||||
} | } | ||||
let useSTUN = Engine.HasXmppClient() && Engine.GetGUIObjectByName("useSTUN").checked; | let useSTUN = Engine.HasXmppClient() && Engine.GetGUIObjectByName("useSTUN").checked; | ||||
try | try | ||||
{ | { | ||||
Engine.StartNetworkHost(playername + (g_UserRating ? " (" + g_UserRating + ")" : ""), port, playername, useSTUN, password); | Engine.StartNetworkHost(playername + (g_UserRating ? " (" + g_UserRating + ")" : ""), port, useSTUN, password); | ||||
} | } | ||||
catch (e) | catch (e) | ||||
{ | { | ||||
cancelSetup(); | cancelSetup(); | ||||
messageBox( | messageBox( | ||||
400, 200, | 400, 200, | ||||
sprintf(translate("Cannot host game: %(message)s."), { "message": e.message }), | sprintf(translate("Cannot host game: %(message)s."), { "message": e.message }), | ||||
translate("Error") | translate("Error") | ||||
); | ); | ||||
return false; | return false; | ||||
} | } | ||||
g_ServerName = servername; | g_ServerName = servername; | ||||
g_ServerHasPassword = !!password; | g_ServerHasPassword = !!password; | ||||
if (Engine.HasXmppClient()) | if (Engine.HasXmppClient()) | ||||
Engine.LobbySetPlayerPresence("playing"); | Engine.LobbySetPlayerPresence("playing"); | ||||
return true; | return true; | ||||
} | } | ||||
/** | /** | ||||
* Connects via STUN if the hostJID is given. | * Connect via direct IP (used by the 'simple' MP screen) | ||||
*/ | */ | ||||
function startJoin(playername, ip, port, useSTUN, hostJID) | function startJoin(playername, ip, port) | ||||
{ | { | ||||
try | try | ||||
{ | { | ||||
Engine.StartNetworkJoin(playername + (g_UserRating ? " (" + g_UserRating + ")" : ""), ip, port, useSTUN, hostJID); | Engine.StartNetworkJoin(playername, ip, port); | ||||
} | } | ||||
catch (e) | catch (e) | ||||
{ | { | ||||
cancelSetup(); | cancelSetup(); | ||||
messageBox( | messageBox( | ||||
400, 200, | 400, 200, | ||||
sprintf(translate("Cannot join game: %(message)s."), { "message": e.message }), | sprintf(translate("Cannot join game: %(message)s."), { "message": e.message }), | ||||
translate("Error") | translate("Error") | ||||
); | ); | ||||
return false; | return false; | ||||
} | } | ||||
startConnectionStatus("client"); | startConnectionStatus("client"); | ||||
// Future-proofing: there could be an XMPP client even if we join a game directly. | |||||
if (Engine.HasXmppClient()) | if (Engine.HasXmppClient()) | ||||
Engine.LobbySetPlayerPresence("playing"); | Engine.LobbySetPlayerPresence("playing"); | ||||
else | |||||
{ | // Only save the player name and host address if they're valid. | ||||
// Only save the player name and host address if they're valid and we're not in the lobby | |||||
Engine.ConfigDB_CreateAndWriteValueToFile("user", "playername.multiplayer", playername, "config/user.cfg"); | Engine.ConfigDB_CreateAndWriteValueToFile("user", "playername.multiplayer", playername, "config/user.cfg"); | ||||
Engine.ConfigDB_CreateAndWriteValueToFile("user", "multiplayerserver", ip, "config/user.cfg"); | Engine.ConfigDB_CreateAndWriteValueToFile("user", "multiplayerserver", ip, "config/user.cfg"); | ||||
Engine.ConfigDB_CreateAndWriteValueToFile("user", "multiplayerjoining.port", port, "config/user.cfg"); | Engine.ConfigDB_CreateAndWriteValueToFile("user", "multiplayerjoining.port", port, "config/user.cfg"); | ||||
} | |||||
return true; | return true; | ||||
} | } | ||||
/** | |||||
* Connect via the lobby. | |||||
*/ | |||||
function startJoinFromLobby(playername, hostJID, password) | function startJoinFromLobby(playername, hostJID, password) | ||||
{ | { | ||||
if (!Engine.HasXmppClient()) | if (!Engine.HasXmppClient()) | ||||
{ | { | ||||
cancelSetup(); | cancelSetup(); | ||||
messageBox( | messageBox( | ||||
400, 200, | 400, 200, | ||||
sprintf("You cannot join a lobby game without logging in to the lobby."), | sprintf("You cannot join a lobby game without logging in to the lobby."), | ||||
Show All 38 Lines |
Wildfire Games · Phabricator