|
@@ -27,7 +27,7 @@
|
|
|
// anything else will be sent back as an error to the client.
|
|
|
// All the connect args are passed also to onConnectRequest
|
|
|
//
|
|
|
-function GameConnection::onConnectRequest( %client, %netAddress, %name )
|
|
|
+function GameConnection::onConnectRequest( %this, %netAddress, %name )
|
|
|
{
|
|
|
echo("Connect request from: " @ %netAddress);
|
|
|
if($Server::PlayerCount >= $pref::Server::MaxPlayers)
|
|
@@ -47,11 +47,11 @@ function GameConnection::onConnect( %this, %clientData )
|
|
|
sendLoadInfoToClient(%this);
|
|
|
|
|
|
// Simulated client lag for testing...
|
|
|
- // %client.setSimulatedNetParams(0.1, 30);
|
|
|
+ // %this.setSimulatedNetParams(0.1, 30);
|
|
|
|
|
|
// Get the client's unique id:
|
|
|
- // %authInfo = %client.getAuthInfo();
|
|
|
- // %client.guid = getField(%authInfo, 3);
|
|
|
+ // %authInfo = %this.getAuthInfo();
|
|
|
+ // %this.guid = getField(%authInfo, 3);
|
|
|
%this.guid = 0;
|
|
|
addToServerGuidList(%this.guid);
|
|
|
|
|
@@ -81,19 +81,194 @@ function GameConnection::onConnect( %this, %clientData )
|
|
|
|
|
|
%this.connectData = %clientData;
|
|
|
|
|
|
+ //Signal and listener logic for the spawn config/processing here
|
|
|
+ %this.GetEventManager().registerEvent("setSpawnObjectTypeComplete");
|
|
|
+ %this.GetEventManager().registerEvent("setSpawnObjectTypeFailed");
|
|
|
+ %this.GetEventManager().registerEvent("setSpawnPointComplete");
|
|
|
+ %this.GetEventManager().registerEvent("setSpawnPointFailed");
|
|
|
+ %this.GetEventManager().registerEvent("postSpawnComplete");
|
|
|
+
|
|
|
+ %this.listener = new ScriptMsgListener() {
|
|
|
+ class = GameConnectionListener;
|
|
|
+ };
|
|
|
+ %this.GetEventManager().subscribe( %this.listener, "setSpawnObjectTypeComplete" );
|
|
|
+ %this.GetEventManager().subscribe( %this.listener, "setSpawnObjectTypeFailed" );
|
|
|
+ %this.GetEventManager().subscribe( %this.listener, "setSpawnPointComplete" );
|
|
|
+ %this.GetEventManager().subscribe( %this.listener, "setSpawnPointFailed" );
|
|
|
+ %this.GetEventManager().subscribe( %this.listener, "postSpawnComplete" );
|
|
|
+
|
|
|
callGamemodeFunction("onClientConnect", %this);
|
|
|
|
|
|
$Server::PlayerCount++;
|
|
|
}
|
|
|
|
|
|
+function GameConnection::GetEventManager(%this)
|
|
|
+{
|
|
|
+ if( !isObject( %this.eventManager ) )
|
|
|
+ %this.eventManager = new EventManager() {
|
|
|
+ queue = "GameConnectionEventManager";
|
|
|
+ };
|
|
|
+
|
|
|
+ return %this.eventManager;
|
|
|
+}
|
|
|
+
|
|
|
+function GameConnection::spawnControlObject( %this )
|
|
|
+{
|
|
|
+ //baseline controlObject spawn type with extention points
|
|
|
+ %this.spawnClass = "Camera";
|
|
|
+ %this.spawnDBType = "CameraData";
|
|
|
+ %this.spawnDataBlock = "Observer";
|
|
|
+
|
|
|
+ %this.numModsNeedingLoaded = 0;
|
|
|
+ %this.moduleLoadedDone = 0;
|
|
|
+ %modulesIDList = getModulesAndGameModesList(true, "Game");
|
|
|
+
|
|
|
+ %this.numModsNeedingLoaded = getNumCanCallOnObjectList("setSpawnObjectType", %modulesIDList);
|
|
|
+
|
|
|
+ if (%this.numModsNeedingLoaded)
|
|
|
+ callOnObjectList("setSpawnObjectType", %modulesIdList, %this);
|
|
|
+ else
|
|
|
+ %this.GetEventManager().onSetSpawnObjectTypeComplete(); //just jump to progress
|
|
|
+}
|
|
|
+
|
|
|
+function GameConnectionListener::onSetSpawnObjectTypeComplete( %this, %client )
|
|
|
+{
|
|
|
+ %client.moduleLoadedDone++;
|
|
|
+
|
|
|
+ if (%client.moduleLoadedDone < %client.numModsNeedingLoaded)
|
|
|
+ return; //continue to wait
|
|
|
+
|
|
|
+ if (isObject(%client.player))
|
|
|
+ {
|
|
|
+ // The client should not already have a player. Assigning
|
|
|
+ // a new one could result in an uncontrolled player object.
|
|
|
+ error("Attempting to create a player for a client that already has one!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // Spawn with the engine's Sim::spawnObject() function
|
|
|
+ %client.player = spawnObject(%client.spawnClass, %client.spawnDataBlock);
|
|
|
+
|
|
|
+ if (!%client.player.isMemberOfClass(%client.spawnClass))
|
|
|
+ warn("Trying to spawn a class that does not derive from "@ %client.spawnClass);
|
|
|
+
|
|
|
+ // Add the player object to MissionCleanup so that it
|
|
|
+ // won't get saved into the level files and will get
|
|
|
+ // cleaned up properly
|
|
|
+ MissionCleanup.add(%client.player);
|
|
|
+
|
|
|
+ // Store the client object on the player object for
|
|
|
+ // future reference
|
|
|
+ %client.player.client = %client;
|
|
|
+
|
|
|
+ %client.setSpawnPoint();
|
|
|
+
|
|
|
+ // Give the client control of the camera if in the editor
|
|
|
+ if( $startWorldEditor )
|
|
|
+ {
|
|
|
+ %control = %client.camera;
|
|
|
+ %control.mode = "Fly";
|
|
|
+ EditorGui.syncCameraGui();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ %control = %client.player;
|
|
|
+
|
|
|
+ // Allow the player/camera to receive move data from the GameConnection. Without this
|
|
|
+ // the user is unable to control the player/camera.
|
|
|
+ if (!isDefined("%noControl"))
|
|
|
+ %client.setControlObject(%control);
|
|
|
+}
|
|
|
+
|
|
|
+function GameConnectionListener::onSetSpawnObjectTypeFailed( %this, %client, %canContinueOnFail )
|
|
|
+{
|
|
|
+ errorf("Failed to properly set Spawn Object Type for client: " @ %client);
|
|
|
+}
|
|
|
+
|
|
|
+function GameConnection::setSpawnPoint( %this )
|
|
|
+{
|
|
|
+ //baseline spawn point config rules with extention points
|
|
|
+ %this.playerSpawnGroups = "PlayerSpawnPoints PlayerDropPoints";
|
|
|
+ %this.spawnPoint = "";
|
|
|
+ %this.spawnLocation = "0 0 0";
|
|
|
+
|
|
|
+ %this.numModsNeedingLoaded = 0;
|
|
|
+ %this.moduleLoadedDone = 0;
|
|
|
+ %modulesIDList = getModulesAndGameModesList(true, "Game");
|
|
|
+
|
|
|
+ %this.numModsNeedingLoaded = getNumCanCallOnObjectList("setSpawnPoint", %modulesIDList);
|
|
|
+
|
|
|
+ if (%this.numModsNeedingLoaded)
|
|
|
+ callOnObjectList("setSpawnPoint", %modulesIdList, %this);
|
|
|
+ else
|
|
|
+ %this.GetEventManager().onSetSpawnPointComplete();
|
|
|
+}
|
|
|
+
|
|
|
+function GameConnectionListener::onSetSpawnPointComplete( %this, %client )
|
|
|
+{
|
|
|
+ %client.moduleLoadedDone++;
|
|
|
+ if (%client.moduleLoadedDone < %client.numModsNeedingLoaded)
|
|
|
+ return; //continue to wait
|
|
|
+
|
|
|
+ if (isObject(%client.player))
|
|
|
+ %client.player.setTransform(%client.spawnLocation);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // If we weren't able to create the player object then warn the user
|
|
|
+ // When the player clicks OK in one of these message boxes, we will fall through
|
|
|
+ // to the "if (!isObject(%player))" check below.
|
|
|
+ if (isDefined("%this.spawnDataBlock"))
|
|
|
+ {
|
|
|
+ MessageBoxOK("Spawn Failed",
|
|
|
+ "Unable to create a player with class " @ %client.spawnClass @
|
|
|
+ " and datablock " @ %client.spawnDataBlock @ ".\n\nStarting as an Observer instead.",
|
|
|
+ "");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageBoxOK("Spawn Failed",
|
|
|
+ "Unable to create a player with class " @ %client.spawnClass @
|
|
|
+ ".\n\nStarting as an Observer instead.",
|
|
|
+ "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ %client.onPostSpawn();
|
|
|
+}
|
|
|
+
|
|
|
+function GameConnectionListener::onSetSpawnPointFailed( %this, %client, %canContinueOnFail )
|
|
|
+{
|
|
|
+ errorf("Failed to properly set Spawn Object Type for client: " @ %client);
|
|
|
+}
|
|
|
+
|
|
|
+function GameConnection::onPostSpawn( %this )
|
|
|
+{
|
|
|
+ %this.numModsNeedingLoaded = 0;
|
|
|
+ %this.moduleLoadedDone = 0;
|
|
|
+ %modulesIDList = getModulesAndGameModesList(true, "Game");
|
|
|
+
|
|
|
+ %this.numModsNeedingLoaded = getNumCanCallOnObjectList("onPostSpawn", %modulesIDList);
|
|
|
+
|
|
|
+ if (%this.numModsNeedingLoaded)
|
|
|
+ callOnObjectList("onPostSpawn", %modulesIdList, %this);
|
|
|
+ else
|
|
|
+ %this.GetEventManager().onPostSpawnComplete();
|
|
|
+}
|
|
|
+
|
|
|
+function GameConnectionListener::onPostSpawnComplete(%this, %client)
|
|
|
+{
|
|
|
+ %client.moduleLoadedDone++;
|
|
|
+ if (%client.moduleLoadedDone < %client.numModsNeedingLoaded)
|
|
|
+ return; //continue to wait
|
|
|
+
|
|
|
+ //Continue on. Room for special handling here if needbe but not expressly required
|
|
|
+}
|
|
|
+
|
|
|
//-----------------------------------------------------------------------------
|
|
|
// A player's name could be obtained from the auth server, but for
|
|
|
// now we use the one passed from the client.
|
|
|
// %realName = getField( %authInfo, 0 );
|
|
|
//
|
|
|
-function GameConnection::setPlayerName(%client,%name)
|
|
|
+function GameConnection::setPlayerName(%this,%name)
|
|
|
{
|
|
|
- %client.sendGuid = 0;
|
|
|
+ %this.sendGuid = 0;
|
|
|
|
|
|
// Minimum length requirements
|
|
|
%name = trim( strToPlayerName( %name ) );
|
|
@@ -112,8 +287,8 @@ function GameConnection::setPlayerName(%client,%name)
|
|
|
}
|
|
|
|
|
|
// Tag the name with the "smurf" color:
|
|
|
- %client.nameBase = %name;
|
|
|
- %client.playerName = addTaggedString("\cp\c8" @ %name @ "\co");
|
|
|
+ %this.nameBase = %name;
|
|
|
+ %this.playerName = addTaggedString("\cp\c8" @ %name @ "\co");
|
|
|
}
|
|
|
|
|
|
function isNameUnique(%name)
|
|
@@ -132,7 +307,7 @@ function isNameUnique(%name)
|
|
|
//-----------------------------------------------------------------------------
|
|
|
// This function is called when a client drops for any reason
|
|
|
//
|
|
|
-function GameConnection::onDrop(%client, %reason)
|
|
|
+function GameConnection::onDrop(%this, %reason)
|
|
|
{
|
|
|
%entityIds = parseMissionGroupForIds("Entity", "");
|
|
|
%entityCount = getWordCount(%entityIds);
|
|
@@ -148,15 +323,15 @@ function GameConnection::onDrop(%client, %reason)
|
|
|
%entityIds = %entityIds SPC %child.getID();
|
|
|
}
|
|
|
|
|
|
- %entity.notify("onClientDisconnect", %client);
|
|
|
+ %entity.notify("onClientDisconnect", %this);
|
|
|
}
|
|
|
|
|
|
if($missionRunning)
|
|
|
{
|
|
|
- %hasGameMode = callGamemodeFunction("onClientLeaveGame", %client);
|
|
|
+ %hasGameMode = callGamemodeFunction("onClientLeaveGame", %this);
|
|
|
}
|
|
|
|
|
|
- removeFromServerGuidList( %client.guid );
|
|
|
+ removeFromServerGuidList( %this.guid );
|
|
|
|
|
|
$Server::PlayerCount--;
|
|
|
}
|