2010-06-30 23:41:04 +02:00
|
|
|
var g_IsConnecting = false;
|
|
|
|
var g_GameType; // "server" or "client"
|
|
|
|
|
|
|
|
function init()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-06 21:54:17 +02:00
|
|
|
function cancelSetup()
|
|
|
|
{
|
|
|
|
if (g_IsConnecting)
|
|
|
|
Engine.DisconnectNetworkGame();
|
|
|
|
Engine.PopGuiPage();
|
|
|
|
}
|
|
|
|
|
2010-06-30 23:41:04 +02:00
|
|
|
function startConnectionStatus(type)
|
|
|
|
{
|
|
|
|
g_GameType = type;
|
|
|
|
g_IsConnecting = true;
|
|
|
|
getGUIObjectByName("connectionStatus").caption = "Connecting to server...";
|
|
|
|
}
|
|
|
|
|
|
|
|
function onTick()
|
|
|
|
{
|
|
|
|
if (!g_IsConnecting)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
var message = Engine.PollNetworkClient();
|
|
|
|
if (!message)
|
|
|
|
break;
|
|
|
|
|
2010-07-06 22:31:05 +02:00
|
|
|
log("Net message: "+uneval(message));
|
2010-06-30 23:41:04 +02:00
|
|
|
|
|
|
|
switch (message.type)
|
|
|
|
{
|
|
|
|
case "netstatus":
|
|
|
|
switch (message.status)
|
|
|
|
{
|
|
|
|
case "connected":
|
|
|
|
getGUIObjectByName("connectionStatus").caption = "Registering with server...";
|
|
|
|
break;
|
2010-07-06 21:54:17 +02:00
|
|
|
|
2010-06-30 23:41:04 +02:00
|
|
|
case "authenticated":
|
|
|
|
Engine.PopGuiPage();
|
|
|
|
Engine.PushGuiPage("page_gamesetup.xml", { "type": g_GameType });
|
2010-07-06 21:54:17 +02:00
|
|
|
return; // don't process any more messages - leave them for the game GUI loop
|
|
|
|
|
|
|
|
case "disconnected":
|
|
|
|
cancelSetup();
|
|
|
|
reportDisconnect(message.reason);
|
|
|
|
return;
|
|
|
|
|
2010-06-30 23:41:04 +02:00
|
|
|
default:
|
|
|
|
error("Unrecognised netstatus type "+message.status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Unrecognised net message type "+message.type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function switchSetupPage(oldpage, newpage)
|
|
|
|
{
|
|
|
|
getGUIObjectByName(oldpage).hidden = true;
|
|
|
|
getGUIObjectByName(newpage).hidden = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function startHost(playername, servername)
|
|
|
|
{
|
|
|
|
Engine.StartNetworkHost(playername);
|
|
|
|
startConnectionStatus("server");
|
|
|
|
// TODO: ought to do something(?) with servername
|
|
|
|
}
|
|
|
|
|
|
|
|
function startJoin(playername, ip)
|
|
|
|
{
|
|
|
|
Engine.StartNetworkJoin(playername, ip);
|
|
|
|
startConnectionStatus("client");
|
|
|
|
}
|