0ad/binaries/data/mods/public/gui/gamesetup/gamesetup_mp.js
Ykkrosh 1c0536bf08 # Refactored the networking code, and redesigned the game setup screen.
Major updates to most network classes.
Simplify CNetServer so it doesn't duplicate any client behaviour; all
players now run CNetClient.
Remove most player/slot management from networking code.
Wait for all players to finish loading before starting the simulation.
Remove CGameAttributes; attributes are now just a JS object.
Remove CPlayer; they are now just simulation entities.
Handle player colours via simulation system.
Add a default map for Atlas, so it always has something to load.
Move network documentation to Doxygen.
Remove lots of now-unused code.

This was SVN commit r7653.
2010-06-30 21:41:04 +00:00

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");
}