Example #1
0
        protected virtual void HandleCreateLobby(IIncommingMessage message)
        {
            if (!CheckIfHasPermissionToCreate(message.Peer))
            {
                message.Respond("Insufficient permissions", ResponseStatus.Unauthorized);
                return;
            }

            var lobbiesExt = GetOrCreateLobbiesExtension(message.Peer);

            if (DontAllowCreatingIfJoined && lobbiesExt.CurrentLobby != null)
            {
                // If peer is already in a lobby
                message.Respond("You are already in a lobby", ResponseStatus.Failed);
                return;
            }

            // Deserialize properties of the lobby
            var properties = new Dictionary <string, string>().FromBytes(message.AsBytes());

            if (!properties.ContainsKey(MsfDictKeys.LobbyFactoryId))
            {
                message.Respond("Invalid request (undefined factory)", ResponseStatus.Failed);
                return;
            }

            // Get the lobby factory
            ILobbyFactory factory;

            Factories.TryGetValue(properties[MsfDictKeys.LobbyFactoryId], out factory);

            if (factory == null)
            {
                message.Respond("Unavailable lobby factory", ResponseStatus.Failed);
                return;
            }

            var newLobby = factory.CreateLobby(properties, message.Peer);

            if (!AddLobby(newLobby))
            {
                message.Respond("Lobby registration failed", ResponseStatus.Error);
                return;
            }

            Logger.Info("Lobby created: " + newLobby.Id);

            // Respond with success and lobby id
            message.Respond(newLobby.Id, ResponseStatus.Success);
        }
Example #2
0
    public void ConnectToMasterServer()
    {
        Status = string.Empty;

        // connect to the master server
        Msf.Connection.Connected    += OnMasterServerConnected;
        Msf.Connection.Disconnected += OnMasterServerDisconnected;

        backgroundCoroutine = CoroutineUtils.StartWaiting(connectToMasterTimeout,
                                                          () => { OnMasterServerConnectionFailed("Timed out"); },
                                                          1f,
                                                          (time) => { Status = string.Format("Trying to connect {0}s", time); });
        StartCoroutine(backgroundCoroutine);

        Logger.Info(string.Format("Connecting to master on {0}:{1}", masterIp, masterPort));
        Msf.Connection.Connect(masterIp, masterPort);
    }
    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);
        }
    }
        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);
            }
        }
Example #5
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");
        }
    }
Example #6
0
 private void Connected()
 {
     TimeToConnect = MinTimeToConnect;
     Logger.Info("Connected to: " + ServerIp + ":" + ServerPort);
 }
Example #7
0
    public virtual void StartSpawner()
    {
        // In case we went from one scene to another, but we've already started the spawner
        if (IsSpawnerStarted)
        {
            return;
        }

        if (DontDestroyIfStarted)
        {
            // Move to hierarchy root, so that we can't destroy it
            if (transform.parent != null)
            {
                transform.SetParent(null, false);
            }

            // Make sure this object is not destroyed
            DontDestroyOnLoad(gameObject);
        }

        IsSpawnerStarted = true;

        var spawnerOptions = new SpawnerOptions();

        spawnerOptions.MaxProcesses = MaxSpawnedProcesses;
        if (Msf.Args.IsProvided(Msf.Args.Names.MaxProcesses))
        {
            spawnerOptions.MaxProcesses = Msf.Args.MaxProcesses;
        }

        // If we're running in editor, and we want to override the executable path
        if (Msf.Runtime.IsEditor && OverrideExePathInEditor)
        {
            DefaultExePath = ExePathFromEditor;
        }

        Logger.Info("Registering as a spawner with options: \n" + spawnerOptions);

        // 1. Register the spawner
        Msf.Server.Spawners.RegisterSpawner(spawnerOptions, (spawner, error) =>
        {
            if (error != null)
            {
                Logger.Error("Failed to create spawner: " + error);
                return;
            }

            SpawnerController = spawner;

            spawner.DefaultSpawnerSettings.AddWebGlFlag = Msf.Args.IsProvided(Msf.Args.Names.WebGl)
                ? Msf.Args.WebGl
                : SpawnWebglServers;

            // Set to run in batchmode
            spawner.DefaultSpawnerSettings.RunInBatchmode = Msf.Args.IsProvided(Msf.Args.Names.SpawnInBatchmode)
                ? Msf.Args.SpawnInBatchmode
                : DefaultSpawnInBatchmode;

            // 2. Set the default executable path
            spawner.DefaultSpawnerSettings.ExecutablePath = Msf.Args.IsProvided(Msf.Args.Names.ExecutablePath) ?
                                                            Msf.Args.ExecutablePath : DefaultExePath;

            // 3. Set the machine IP
            spawner.DefaultSpawnerSettings.MachineIp = Msf.Args.IsProvided(Msf.Args.Names.MachineIp) ?
                                                       Msf.Args.MachineIp : DefaultMachineIp;

            // 4. (Optional) Set the method which does the spawning, if you want to
            // fully control how processes are spawned
            spawner.SetSpawnRequestHandler(HandleSpawnRequest);

            // 5. (Optional) Set the method, which kills processes when kill request is received
            spawner.SetKillRequestHandler(HandleKillRequest);

            Logger.Info("Spawner successfully created. Id: " + spawner.SpawnerId);
        });
    }
 private void Connected()
 {
     TimeToConnect = MinTimeToConnect;
     Logger.Info("Connected to: " + ServerIp + ":" + ServerPort);
     GetConnection().SetHandler((short)ServerCommProtocl.CheckCurrentVersion, handleCurrentVersionMsg);
 }