forked from 0ad/0ad
70 lines
1.4 KiB
JavaScript
70 lines
1.4 KiB
JavaScript
|
var g_IsConnecting = false;
|
||
|
var g_GameType; // "server" or "client"
|
||
|
|
||
|
function init()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
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;
|
||
|
|
||
|
warn("Net message: "+uneval(message));
|
||
|
|
||
|
switch (message.type)
|
||
|
{
|
||
|
case "netstatus":
|
||
|
switch (message.status)
|
||
|
{
|
||
|
case "connected":
|
||
|
getGUIObjectByName("connectionStatus").caption = "Registering with server...";
|
||
|
break;
|
||
|
case "authenticated":
|
||
|
Engine.PopGuiPage();
|
||
|
Engine.PushGuiPage("page_gamesetup.xml", { "type": g_GameType });
|
||
|
return; // don't process any more messages
|
||
|
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");
|
||
|
}
|