Ejemplo n.º 1
0
    public void RegisterRoomAndFinalize(NetworkManager networkManager, SpawnTaskController controller)
    {
        // Create room options
        var options = new RoomOptions()
        {
            IsPublic   = true,
            Properties = new Dictionary <string, string>(),
            RoomPort   = networkManager.networkPort, // or Msf.Args.AssignedPort
            RoomIp     = Msf.Args.MachineIp          // Spawner should have passed us his own IP
        };

        var prop = controller.Properties;

        if (prop.ContainsKey(MsfDictKeys.RoomName))
        {
            options.Name = prop[MsfDictKeys.RoomName];
        }

        if (prop.ContainsKey(MsfDictKeys.MaxPlayers))
        {
            options.MaxPlayers = int.Parse(prop[MsfDictKeys.MaxPlayers]);
        }

        options.Properties[MsfDictKeys.SceneName] = SceneManager.GetActiveScene().name;

        Msf.Server.Rooms.RegisterRoom(options, (roomController, error) =>
        {
            controller.FinalizeTask(new Dictionary <string, string>()
            {
                { MsfDictKeys.RoomId, roomController.RoomId.ToString() }
            });
        });
    }
    public void RegisterRoomAndFinalize(NetworkManager networkManager, SpawnTaskController controller)
    {
        // Create room options
        var options = new RoomOptions()
        {
            IsPublic   = true,
            Properties = new Dictionary <string, string>(),
            RoomPort   = networkManager.networkPort, // or Msf.Args.AssignedPort
            RoomIp     = Msf.Args.MachineIp          // Spawner should have passed us his own IP
        };

        // We can read some of the options from what player provided
        // when he sent a request
        var prop = controller.Properties;

        if (prop.ContainsKey(MsfDictKeys.RoomName))
        {
            options.Name = prop[MsfDictKeys.RoomName];
        }

        if (prop.ContainsKey(MsfDictKeys.MaxPlayers))
        {
            options.MaxPlayers = int.Parse(prop[MsfDictKeys.MaxPlayers]);
        }

        if (prop.ContainsKey(MsfDictKeys.RoomPassword))
        {
            options.Password = prop[MsfDictKeys.RoomPassword];
        }

        if (prop.ContainsKey(MsfDictKeys.MapName))
        {
            options.Properties[MsfDictKeys.MapName] = prop[MsfDictKeys.MapName];
        }

        // Also, add the scene name
        options.Properties[MsfDictKeys.SceneName] = SceneManager.GetActiveScene().name;

        // Register the room to master server
        Msf.Server.Rooms.RegisterRoom(options, (roomController, error) =>
        {
            if (roomController == null)
            {
                Debug.LogError(error);
                return;
            }

            // So the room was registered successfully, we can now finalize the
            // spawn request
            controller.FinalizeTask(new Dictionary <string, string>()
            {
                // Add our room id to finalization data
                { MsfDictKeys.RoomId, roomController.RoomId.ToString() }
            });
        });
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Called when room is registered to the "master server"
    /// </summary>
    /// <param name="roomController"></param>
    public void OnRoomRegistered(RoomController roomController)
    {
        IsRoomRegistered = true;

        // Set access provider (Optional)
        roomController.SetAccessProvider(CreateAccess);
        // If this room was spawned
        if (SpawnTaskController != null)
        {
            SpawnTaskController.FinalizeTask(CreateSpawnFinalizationData());
        }
    }