/// <summary> /// Uploads a Player File into a Slot /// </summary> /// <param name="service"></param> /// <param name="slot">Target Slot</param> /// <param name="playerType">Player File</param> internal void UploadMaster(ISimulationService service, byte slot, TypeInfo playerType) { // Check Slot if (slot < 0 || slot > 7) { throw new ArgumentOutOfRangeException("Slot must be between 0 and 7"); } // Check File Size if (playerType != null && playerType.AssemblyFile.Length > SimulationServer.MAXPLAYERSIZE) { throw new ArgumentException("File is too large"); } // Check for an existing Level if (levelInfo == null) { throw new InvalidOperationException("No level is set yet"); } ClientInfo client; if (clients.TryGetValue(service, out client)) { PlayerInfo playerInfo = null; if (playerType != null) { playerInfo = ExtensionLoader.SecureFindPlayer(extensionPaths, playerType.AssemblyFile, playerType.TypeName); } lock (simulationLock) { // Check for Master if (master != client.UserProfile) { throw new InvalidOperationException("You are not the master"); } // Set File if (playerInfo == null) { // Remove Master Blocker if (slots[slot].Profile == master) { slots[slot].Profile = null; } playerInfos[slot] = null; playerTypes[slot] = null; slots[slot].PlayerInfo = false; slots[slot].ReadyState = false; } else { // TODO: Faction-Matching slots[slot].Profile = master; playerInfos[slot] = playerInfo; playerTypes[slot] = playerType; slots[slot].PlayerInfo = true; } } // Inform everybody about the Slot Change SendPlayerChanged(slots[slot]); } else { throw new InvalidOperationException("Client not registered"); } }
/// <summary> /// Legt die zu verwendende KI für einen beliebigen Slot fest. /// </summary> /// <param name="slot">Slot (0...7)</param> /// <param name="player">KI</param> /// <param name="result">Eventuelle Fehlermeldung</param> /// <returns>Erfolgsmeldung</returns> public bool UploadMaster(byte slot, TypeInfo player) { // Sicher stellen, dass der Modus stimmt. if (ServerState != SimulationState.Stopped) { throw new Exception("Simulation already started"); } // Prüfen, ob überhaupt schon ein Level feststeht. if (this.level == null) { throw new Exception("There is no Level set"); } // Slot Grenzbereiche prüfen if (slot < 0 || slot >= this.level.LevelDescription.MaxPlayerCount) { throw new Exception("Slot Value is out of List"); } if (player == null) { // Player entfernen players[slot] = null; // Event werfen if (OnPlayerChanged != null) { OnPlayerChanged(this, slot); } return(true); } else { // Prüfen, ob eine Datei angehängt wurde if (player.AssemblyFile == null) { throw new Exception("There is no Assembly File"); } // Prüfen, ob ein Typ angegeben wurde if (string.IsNullOrEmpty(player.TypeName)) { throw new Exception("There is no Player Type"); } // Level analysieren PlayerInfo info = ExtensionLoader.SecureFindPlayer(extensionPaths, player.AssemblyFile, player.TypeName); if (info != null) { info.Type.AssemblyFile = player.AssemblyFile; players[slot] = info; } // Event werfen if (OnPlayerChanged != null) { OnPlayerChanged(this, slot); } return(true); } }
/// <summary> /// Uploads a Client related Player File. /// </summary> /// <param name="service"></param> /// <param name="playerType">Player File</param> internal void UploadPlayer(ISimulationService service, TypeInfo playerType) { // Check File Size if (playerType != null && playerType.AssemblyFile.Length > MAXPLAYERSIZE) { throw new ArgumentException("File is too large"); } ClientInfo client; if (clients.TryGetValue(service, out client)) { // Analyse File PlayerInfo playerInfo = null; if (playerType != null) { playerInfo = ExtensionLoader.SecureFindPlayer(extensionPaths, playerType.AssemblyFile, playerType.TypeName); } // Save Player Infos if (playerInfo == null) { client.PlayerType = null; client.PlayerInfo = null; } else { client.PlayerType = playerType; client.PlayerInfo = playerInfo; } // Apply to Used Slot Slot affectedSlot = null; lock (simulationLock) { for (int i = 0; i < slots.Length; i++) { if (slots[i].Profile == client.UserProfile) { affectedSlot = slots[i]; // Set new Parameter if (playerInfo != null) { playerInfos[i] = playerInfo; playerTypes[i] = playerType; affectedSlot.PlayerInfo = true; } else { playerInfos[i] = null; playerTypes[i] = null; affectedSlot.PlayerInfo = false; } break; } } } // Inform others if (affectedSlot != null) { SendPlayerChanged(affectedSlot); } } else { throw new InvalidOperationException("Client not registered"); } }