protected virtual void Awake()
    {
        Logger.LogLevel = LogLevel;

        MasterServerObject = MasterServerObject ?? FindObjectOfType <MasterServerBehaviour>();
        NetworkManager     = NetworkManager ?? FindObjectOfType <NetworkManager>();

        var connection = GetConnection();

        // Listen to the connected event
        connection.AddConnectionListener(OnConnectedToMaster, true);

        if (WarnIfNoConnectionObject && FindObjectOfType <ConnectionToMaster>() == null)
        {
            Logger.Warn("No connection object was found in the scene. Ignore the warning, if you're connecting " +
                        "to server manually.");
        }

        // Listen to when a room is registered
        Msf.Server.Rooms.RoomRegistered += OnRoomRegistered;
    }
        public override void StartServer(int port)
        {
            if (IsRunning)
            {
                return;
            }

            Logger.Debug("Starting on port: " + port + "...");

            base.StartServer(port);

            Logger.Info("Started on port: " + port);

            // Notify about uninitialized modules
            var uninitializedModules = GetUninitializedModules();

            if (uninitializedModules.Count > 0)
            {
                Logger.Warn("Some of the Master Server modules failed to initialize: \n" +
                            string.Join(" \n", uninitializedModules.Select(m => m.GetType().ToString()).ToArray()));
            }

            // Notify about initialized modules
            if (Logger.IsLogging(LogLevel.Debug))
            {
                Logger.Warn("Successfully initialized modules: \n" +
                            string.Join(" \n", GetInitializedModules().Select(m => m.GetType().ToString()).ToArray()));
            }

            OnStarted();

            IsMasterRunning = IsRunning;

            // Invoke the event
            if (MasterStarted != null)
            {
                MasterStarted.Invoke(this);
            }
        }
示例#3
0
        public void AddFactory(ILobbyFactory factory)
        {
            // In case the module has not been initialized yet
            if (Factories == null)
            {
                Factories = new Dictionary <string, ILobbyFactory>();
            }

            if (Factories.ContainsKey(factory.Id))
            {
                Logger.Warn("You are overriding a factory with same id");
            }

            Factories[factory.Id] = factory;
        }
    public IEnumerator WaitForConnection(RoomAccessPacket access)
    {
        NetworkManager = NetworkManager ?? FindObjectOfType <NetworkManager>();

        Logger.Debug("Connecting to game server... " + NetworkManager.networkAddress + ":" +
                     NetworkManager.networkPort);

        var timeUntilTimeout = ConnectionTimeout;

        // Wait until we connect
        while (!NetworkManager.IsClientConnected())
        {
            yield return(null);

            timeUntilTimeout -= Time.deltaTime;

            if (timeUntilTimeout < 0)
            {
                Logger.Warn("Client failed to connect to game server: " + access);
                OnFailedToConnect();
                yield break;
            }
        }

        Logger.Info("Connected to game server, about to send access");

        // Connected, send the token
        //NetworkManager.client.connection.Send(UnetGameRoom.AccessMsgType, new StringMessage(access.Token));
        NetworkManager.client.connection.Send(0, UnetGameRoom.AccessMsgType, 0);


        // While connected
        while (NetworkManager.IsClientConnected())
        {
            yield return(null);
        }

        // At this point, we're no longer connected
        if (DisconnectedScene.IsSet())
        {
            SceneManager.LoadScene(DisconnectedScene.SceneName);
        }
    }
示例#5
0
        protected virtual void OnMessageReceived(IIncommingMessage message)
        {
            try {
                IPacketHandler handler;
                Handlers.TryGetValue(message.OpCode, out handler);

                if (handler == null)
                {
                    Logger.Warn(string.Format("Handler for OpCode {0} does not exist", message.OpCode));

                    if (message.IsExpectingResponse)
                    {
                        message.Respond(InternalServerErrorMessage, ResponseStatus.NotHandled);
                        return;
                    }

                    return;
                }

                handler.Handle(message);
            }
            catch (Exception e) {
                if (Msf.Runtime.IsEditor)
                {
                    throw;
                }

                Logger.Error("Error while handling a message from Client. OpCode: " + message.OpCode);
                Logger.Error(e);

                if (!message.IsExpectingResponse)
                {
                    return;
                }

                try {
                    message.Respond(InternalServerErrorMessage, ResponseStatus.Error);
                }
                catch (Exception exception) {
                    Logs.Error(exception);
                }
            }
        }
示例#6
0
    public IEnumerator WaitForConnection(RoomAccessPacket access)
    {
        NetworkManager = NetworkManager ?? FindObjectOfType <NetworkManager>();
        //	Debug.LogError("Connecting to game server... " + NetworkManager.networkAddress + ":" + NetworkManager.networkPort);

        var timeUntilTimeout = ConnectionTimeout;

        // Wait until we connect
        while (!NetworkManager.IsClientConnected())
        {
            yield return(null);

            timeUntilTimeout -= Time.deltaTime;

            if (timeUntilTimeout < 0)
            {
                Logger.Warn("Client failed to connect to game server: " + access);
                OnFailedToConnect();
                yield break;
            }
        }

        Logger.Info("Connected to game server, about to send access");
        // Connected, send the token
        showDissconnectMsg = true;
        NetworkManager.client.connection.Send(AlbotGameRoom.AccessMsgType, new StringMessage(access.Token));

        // While connected
        while (NetworkManager.IsClientConnected())
        {
            yield return(null);
        }
        // At this point, we're no longer connected
        if (DisconnectedScene.IsSet() && showDissconnectMsg)
        {
            AlbotDialogBox.activateButton(() => { ClientUIStateManager.requestGotoState(ClientUIStates.GameLobby); },
                                          DialogBoxType.GameServerConnLost, "Connection to the gameserver was lost!", "Return to lobby");
        }
    }
示例#7
0
        public virtual SpawnTask Spawn(Dictionary <string, string> properties, string region, string customArgs)
        {
            var spawners = GetFilteredSpawners(properties, region);

            if (spawners.Count < 0)
            {
                Logger.Warn("No spawner was returned after filtering. " +
                            (string.IsNullOrEmpty(region) ? "" : "Region: " + region));
                return(null);
            }

            // Order from least busy server
            var orderedSpawners  = spawners.OrderByDescending(s => s.CalculateFreeSlotsCount());
            var availableSpawner = orderedSpawners.FirstOrDefault(s => s.CanSpawnAnotherProcess());

            // Ignore, if all of the spawners are busy
            if (availableSpawner == null)
            {
                return(null);
            }

            return(Spawn(properties, customArgs, availableSpawner));
        }