// public GameNetworkServer( string serverName, string serverVersion, int maxConnections, bool entitySystemServiceEnabled) : base(serverName, serverVersion, maxConnections) { if (instance != null) Log.Fatal("GameNetworkServer.GameNetworkServer: instance != null."); instance = this; //register network services //register user management service userManagementService = new UserManagementServerNetworkService(); RegisterService(userManagementService); //register custom messages service customMessagesService = new CustomMessagesServerNetworkService(); RegisterService(customMessagesService); //register chat service chatService = new ChatServerNetworkService(userManagementService); RegisterService(chatService); //register entity system service if (entitySystemServiceEnabled) { entitySystemService = new EntitySystemServerNetworkService(userManagementService); RegisterService(entitySystemService); } }
// public GameNetworkServer(string serverName, string serverVersion, int maxConnections, bool entitySystemServiceEnabled) : base(serverName, serverVersion, maxConnections) { if (instance != null) { Log.Fatal("GameNetworkServer.GameNetworkServer: instance != null."); } instance = this; //register network services //register user management service userManagementService = new UserManagementServerNetworkService(); RegisterService(userManagementService); //register custom messages service customMessagesService = new CustomMessagesServerNetworkService(); RegisterService(customMessagesService); //register chat service chatService = new ChatServerNetworkService(userManagementService); RegisterService(chatService); //register entity system service if (entitySystemServiceEnabled) { entitySystemService = new EntitySystemServerNetworkService(userManagementService); RegisterService(entitySystemService); } }
void CustomMessagesService_ReceiveMessage( CustomMessagesServerNetworkService sender, NetworkNode.ConnectedNode source, string message, string data ) { //Warning! Messages must be checked by security reasons. //Modified client application can send any message with any data. if( allowCustomClientCommands ) { //load map if( message == "Example_MapLoad" ) { string mapName = data; MapDestroy( true ); if( !MapLoad( mapName ) ) return; return; } //create map object if( message == "Example_CreateMapObject" ) { string[] parameters = data.Split( ';' ); string typeName = parameters[ 0 ]; Vec3 position = Vec3.Parse( parameters[ 1 ] ); Quat rotation = Quat.Parse( parameters[ 2 ] ); if( Map.Instance != null ) { MapObject entity = (MapObject)Entities.Instance.Create( typeName, Map.Instance ); entity.Position = position; entity.Rotation = rotation; entity.PostCreate(); } return; } } }
//public Unit AKServerOrSingle_CreatePlayerUnit(PlayerManager.ServerOrSingle_Player player, // MapObject spawnPoint, string faction) //{ // string unitTypeName; // FactionType AKFaction; // //PlayerIntellect intellect = player.Intellect as PlayerIntellect; //invalid // if (faction.ToString().Equals("AssaultKnights") || faction.ToString().Equals("AssaultKnights (Faction)")) // AKFaction = (FactionType)Entities.Instance.Create("AssaultKnights", Map.Instance).Type; // else // AKFaction = (FactionType)Entities.Instance.Create("Omni", Map.Instance).Type; // if (GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights) // { // if (player.Intellect.Faction == null) // player.Intellect.Faction = AKFaction; // else if (player.Intellect.Faction != AKFaction) // player.Intellect.Faction = AKFaction; // else // player.Intellect.Faction = AKFaction; // } // if (!player.Bot) // { // if (player.Intellect.Faction.Name == "AssaultKnights" && GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights) // unitTypeName = "AKSoldier"; // else if (player.Intellect.Faction.Name == "Omni" && GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights) // unitTypeName = "OmniSoldier"; // else if (GameMap.Instance.PlayerUnitType != null) // unitTypeName = GameMap.Instance.PlayerUnitType.Name; // else // unitTypeName = "Girl"; // } // else if (player.Bot) // unitTypeName = player.Name; // else // unitTypeName = "Rabbit"; // Unit unit = (Unit)Entities.Instance.Create(unitTypeName, Map.Instance); // Vec3 posOffset = new Vec3(0, 0, 1.5f); // unit.Position = spawnPoint.Position + posOffset; // unit.Rotation = spawnPoint.Rotation; // if (GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights) // unit.InitialFaction = AKFaction;//player.Intellect.Faction; // unit.PostCreate(); // if (player.Intellect != null) // { // player.Intellect.Faction = AKFaction;//player.Intellect.Faction; // player.Intellect.ControlledObject = unit; // unit.SetIntellect(player.Intellect, false); // } // Teleporter teleporter = spawnPoint as Teleporter; // if (teleporter != null) // teleporter.ReceiveObject(unit, null); // BoxTeleporter boxteleporter = spawnPoint as BoxTeleporter; // if (boxteleporter != null) // boxteleporter.ReceiveObject(unit, null); // return unit; //} public static void SpawnInfo( CustomMessagesServerNetworkService sender, NetworkNode.ConnectedNode info, string message, string data ) { if( message == "SpawnInfoToServer" ) { string[] parameters = data.Split( ';' ); string userid = parameters[ 0 ]; string selectedspawnid = parameters[ 1 ]; string selectedfaction = parameters[ 2 ]; //SpawnPoint target = null; var user = GameNetworkServer.Instance.UserManagementService.GetUser( uint.Parse( userid ) ); user.SpawnId = uint.Parse( selectedspawnid ); var player = PlayerManager.Instance.ServerOrSingle_GetPlayer( user ); player.Intellect.Faction = EntityTypes.Instance.GetByName( selectedfaction ) as FactionType; } }
public static void SpawnInfo(CustomMessagesServerNetworkService sender, NetworkNode.ConnectedNode info, string message, string data) { if (message == "spawnInfoToServer") { string[] parameters = data.Split(';'); string userid = parameters[0]; string selectedspawnid = parameters[1]; string selectedfaction = parameters[2]; foreach (ProjectCommon.UserManagementServerNetworkService.UserInfo info2 in GameNetworkServer.Instance.UserManagementService.Users) { if (info2.Name.Equals(userid)) { GameWorld.Instance.AKServerOrSingle_CreatePlayerUnit(PlayerManager.Instance.ServerOrSingle_GetPlayer(userid), target, selectedfaction); GameNetworkServer.Instance.CustomMessagesService.SendToClient(info, message, data); //GameEngineApp.Instance.CreateGameWindowForMap(); } } } }