/// <summary>
        /// Legt das Level für diese Simulation fest. Darf nur im gestoppten Modus genutzt werden.
        /// </summary>
        /// <param name="level">Level Infos mit AssemblyFile und TypeName</param>
        /// <param name="result">Eventuelle Fehlermeldung</param>
        /// <returns>Erfolgsmeldung</returns>
        public bool UploadLevel(TypeInfo level)
        {
            // Sicher stellen, dass der Modus stimmt.
            if (ServerState != SimulationState.Stopped)
            {
                throw new Exception("Simulation already started");
            }

            if (level == null)
            {
                // Level leeren
                this.level = null;
                ResetSlots();

                // Event werfen
                if (OnLevelChanged != null)
                {
                    OnLevelChanged(this, null);
                }

                return(true);
            }
            else
            {
                // Prüfen, ob eine Datei angehängt wurde
                if (level.AssemblyFile == null)
                {
                    throw new Exception("There is no Assembly File");
                }

                // Prüfen, ob ein Typ angegeben wurde
                if (string.IsNullOrEmpty(level.TypeName))
                {
                    throw new Exception("There is no Level Type");
                }

                // Level analysieren
                LevelInfo info = ExtensionLoader.SecureFindLevel(extensionPaths, level.AssemblyFile, level.TypeName);
                if (info != null)
                {
                    info.Type.AssemblyFile = level.AssemblyFile;
                    this.level             = info;
                    ResetSlots();
                }

                // Event werfen
                if (OnLevelChanged != null)
                {
                    OnLevelChanged(this, this.level);
                }

                return(true);
            }
        }
        private void callback_OnLevelChanged(TypeInfo level)
        {
            LevelInfo levelInfo = null;

            if (level != null)
            {
                levelInfo = ExtensionLoader.SecureFindLevel(extensionPaths, level.AssemblyFile, level.TypeName);
            }

            _level = levelInfo;

            if (OnLevelChanged != null)
            {
                OnLevelChanged(this, levelInfo);
            }
        }
Exemple #3
0
        /// <summary>
        /// Uploads a new Level to the System.
        /// </summary>
        /// <param name="service"></param>
        /// <param name="levelType">TypeInfo of the new level</param>
        internal void UploadLevel(ISimulationService service, TypeInfo levelType)
        {
            // Check File Size
            if (levelType != null && levelType.AssemblyFile.Length > SimulationServer.MAXLEVELSIZE)
            {
                throw new ArgumentException("File is too large");
            }

            ClientInfo client;

            if (clients.TryGetValue(service, out client))
            {
                // Analyse Level
                LevelInfo levelInfo = null;
                if (levelType != null)
                {
                    levelInfo = ExtensionLoader.SecureFindLevel(extensionPaths, levelType.AssemblyFile, levelType.TypeName);
                }

                lock (simulationLock)
                {
                    // Check for Master
                    if (master != client.UserProfile)
                    {
                        throw new InvalidOperationException("You are not the master");
                    }

                    // Check for running Simualtions
                    if (simulation != null)
                    {
                        throw new InvalidOperationException("Simulation is already running");
                    }

                    // Replace Level
                    if (levelInfo == null)
                    {
                        // Reset Level
                        this.levelInfo = null;
                        this.levelType = null;
                    }
                    else
                    {
                        // Load New Level
                        this.levelInfo = levelInfo;
                        this.levelType = levelType;
                    }

                    // Reset Slots
                    for (byte i = 0; i < Level.MAX_SLOTS; i++)
                    {
                        slots[i].Profile    = null;
                        playerInfos[i]      = null;
                        playerTypes[i]      = null;
                        slots[i].ColorKey   = (PlayerColor)i;
                        slots[i].PlayerInfo = false;
                        slots[i].ReadyState = false;
                        slots[i].Team       = i;
                    }
                }

                // Inform everybody about the Level Change
                SendLevelChanged(levelType);

                // Inform everybody about the Slot Reset
                SendPlayerReset(slots);
            }
            else
            {
                throw new InvalidOperationException("Client not registered");
            }
        }