public override void BoltStartDone()
        {
            if (BoltNetwork.IsServer)
            {
                // Create some room custom properties
                PhotonRoomProperties roomProperties = new PhotonRoomProperties();

                roomProperties.AddRoomProperty("t", GameType); // ex: game type
                roomProperties.AddRoomProperty("m", Map);      // ex: map id

                roomProperties.IsOpen    = true;
                roomProperties.IsVisible = true;

                // If RoomID was not set, create a random one
                if (RoomID.Length == 0)
                {
                    RoomID = Guid.NewGuid().ToString();
                }

                // Create the Photon Room
                BoltMatchmaking.CreateSession(
                    sessionID: RoomID,
                    token: roomProperties,
                    sceneToLoad: Map
                    );

                // BoltNetwork.SetServerInfo(RoomID, roomProperties);
                // BoltNetwork.LoadScene(Map);
            }
        }
Ejemplo n.º 2
0
        public override void CreateSession(string sessionName, OperationResultDelegate onComplete)
        {
            if (State != NetworkState.Running)
            {
                Log.Info(LogChannel, "[PhotonNetworkInterface] Cannot create session if not in running state");
                return;
            }

            if (!BoltNetwork.IsServer)
            {
                Log.Info(LogChannel, "[PhotonNetworkInterface] Cannot create session if not of type server");
                return;
            }

            _operationCallbackSessionCreated = onComplete;

            // Create some room custom properties
            PhotonRoomProperties roomProperties = new PhotonRoomProperties();

            roomProperties.IsOpen    = true;
            roomProperties.IsVisible = true;

            // Create the Photon Room
            BoltMatchmaking.CreateSession(sessionName, roomProperties);

            Log.Info(LogChannel, "[PhotonNetworkInterface] Session creation begun...");
        }
Ejemplo n.º 3
0
        public override void BoltStartDone()
        {
            if (BoltNetwork.IsServer)
            {
                string matchName = Guid.NewGuid().ToString();

                var props = new PhotonRoomProperties();

                props.IsOpen    = true;
                props.IsVisible = true;

                props["type"] = "game01";
                props["map"]  = "Tutorial1";

                BoltMatchmaking.CreateSession(
                    sessionID: matchName,
                    sceneToLoad: "Tutorial1",
                    token: props
                    );
            }

            if (BoltNetwork.IsClient)
            {
                // This will start a server after 10secs of wait
                // if no server was found
                _timerRoutine = StartCoroutine(ShutdownAndStartServer());
            }
        }
Ejemplo n.º 4
0
        public override void ConnectRequest(UdpEndPoint endpoint, IProtocolToken token)
        {
            if (BoltNetwork.IsServer)
            {
                if (full == false)
                {
                    full = true;

                    PhotonRoomProperties roomProperties = new PhotonRoomProperties
                    {
                        IsOpen    = false,
                        IsVisible = true
                    };

                    var matchName = Guid.NewGuid().ToString();

                    BoltNetwork.SetServerInfo(matchName, roomProperties);
                    BoltNetwork.Accept(endpoint);

                    Debug.Log("Accept Client");
                }
                else
                {
                    BoltNetwork.Refuse(endpoint);

                    Debug.Log("Refuse Client");
                }
            }
        }
Ejemplo n.º 5
0
        public override void ConnectRequest(UdpEndPoint endpoint, IProtocolToken token)
        {
            if (BoltNetwork.IsServer)
            {
                if (full == false)
                {
                    full = true;

                    PhotonRoomProperties roomProperties = new PhotonRoomProperties
                    {
                        IsOpen    = false,
                        IsVisible = true
                    };

                    BoltMatchmaking.UpdateSession(roomProperties);

                    BoltNetwork.Accept(endpoint);

                    Debug.Log("Accept Client");
                }
                else
                {
                    BoltNetwork.Refuse(endpoint);

                    Debug.Log("Refuse Client");
                }
            }
        }
Ejemplo n.º 6
0
    public override void BoltStartDone()
    {
        if (BoltNetwork.isServer)
        {
            // Create some room custom properties
            PhotonRoomProperties roomProperties = new PhotonRoomProperties();

            roomProperties.AddRoomProperty("t", GameType); // ex: game type
            roomProperties.AddRoomProperty("m", Map);      // ex: map id

            roomProperties.IsOpen    = true;
            roomProperties.IsVisible = true;

            // If RoomID was not set, create a random one
            if (RoomID.Length == 0)
            {
                RoomID = new Guid().ToString();
            }

            // Create the Photon Room
            BoltNetwork.SetServerInfo(RoomID, roomProperties);

            // Load the requested Level
            BoltNetwork.LoadScene(Map);
        }
    }
Ejemplo n.º 7
0
    IEnumerator UpdateSessionInfo()
    {
        while (true)
        {
            IProtocolToken token = null;

            switch (Random.Range(1, 3))
            {
            case 1:
                token = new RoomProtocolToken()
                {
                    ArbitraryData = string.Format("My DATA :: {0}", Random.Range(1, 100)),
                    password      = "******"
                };

                break;

            case 2:
                token = new PhotonRoomProperties();

                ((PhotonRoomProperties)token).AddRoomProperty("t", Random.Range(1, 100));
                ((PhotonRoomProperties)token).AddRoomProperty("m", Random.Range(1, 100));

                break;
            }

            if (token != null)
            {
                BoltNetwork.SetServerInfo(null, token);
            }

            yield return(new WaitForSeconds(30));
        }
    }
Ejemplo n.º 8
0
    public override void ConnectRequest(UdpEndPoint endpoint, IProtocolToken token)
    {
        if (BoltNetwork.IsServer)
        {
            if (full == false)
            {
                full = true;
                PhotonRoomProperties myToken = new PhotonRoomProperties
                {
                    IsOpen    = false,
                    IsVisible = false,
                };

                myToken.AddRoomProperty("t", 3);

                var matchName = staticData.lobbyName;

                BoltNetwork.SetServerInfo(matchName, myToken);

                BoltNetwork.Accept(endpoint);
            }
            else
            {
                BoltNetwork.Refuse(endpoint);
            }
        }
    }
Ejemplo n.º 9
0
 public override void BoltStartDone()
 {
     if (BoltNetwork.IsServer)
     {
         BoltNetwork.RegisterTokenClass <PhotonRoomProperties>();
         PhotonRoomProperties token = new PhotonRoomProperties();
         token.AddRoomProperty("roomName", GameObject.FindWithTag("NewRoomNameInputField").GetComponent <TMP_InputField>().text);
         BoltMatchmaking.CreateSession(sessionID: Guid.NewGuid().ToString(), sceneToLoad: "Game", token: token);
     }
 }
Ejemplo n.º 10
0
        public override void Disconnected(BoltConnection connection)
        {
            if (full == true)
            {
                full = false;

                PhotonRoomProperties roomProperties = new PhotonRoomProperties
                {
                    IsOpen = true, IsVisible = true
                };

                BoltMatchmaking.UpdateSession(roomProperties);
            }
        }
Ejemplo n.º 11
0
        public override void BoltStartDone()
        {
            if (BoltNetwork.IsServer)
            {
                PhotonRoomProperties token = new PhotonRoomProperties();
                token.IsOpen    = true;
                token.IsVisible = true;

                var matchName = Guid.NewGuid().ToString();

                BoltNetwork.SetServerInfo(matchName, token);
                BoltNetwork.LoadScene("Game");
            }
        }
Ejemplo n.º 12
0
        public override void Disconnected(BoltConnection connection)
        {
            if (full == true)
            {
                full = false;

                PhotonRoomProperties roomProperties = new PhotonRoomProperties
                {
                    IsOpen = true, IsVisible = true
                };

                var matchName = Guid.NewGuid().ToString();

                BoltNetwork.SetServerInfo(matchName, roomProperties);
            }
        }
Ejemplo n.º 13
0
        public override void BoltStartDone()
        {
            if (BoltNetwork.IsServer)
            {
                PhotonRoomProperties token = new PhotonRoomProperties();
                token.IsOpen    = true;
                token.IsVisible = true;

                var matchName = Guid.NewGuid().ToString();

                BoltMatchmaking.CreateSession(
                    sessionID: matchName,
                    token: token,
                    sceneToLoad: "Game"
                    );
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// If running as Server, creates the session and load the Game scene
        /// </summary>
        public override void BoltStartDone()
        {
            if (BoltNetwork.IsServer)
            {
                _connectedPlayers = new List <ConnectedPlayer>();

                // Create some room custom properties
                PhotonRoomProperties roomProperties = new PhotonRoomProperties();

                roomProperties.AddRoomProperty("m", config.Map);
                roomProperties.IsOpen    = true;
                roomProperties.IsVisible = true;

                // Create the Photon Room
                BoltMatchmaking.CreateSession(
                    sessionID: Guid.NewGuid().ToString(),
                    token: roomProperties,
                    sceneToLoad: config.Map
                    );
            }
        }
Ejemplo n.º 15
0
        private void CreateSession()
        {
            if (!BoltNetwork.IsServer)
            {
                return;
            }

            var photonRoomProperties = new PhotonRoomProperties();

            photonRoomProperties.AddRoomProperty("Use Player Amount Settings", _usePlayerAmountSettings);
            photonRoomProperties.AddRoomProperty("Max Players", _maxPlayers);
            photonRoomProperties.AddRoomProperty("Min Players", _minPlayers);

            if (_requirePassword)
            {
                photonRoomProperties.AddRoomProperty("RP", true);
                BoltMatchmaking.CreateSession(_gameName, photonRoomProperties);
            }
            else
            {
                photonRoomProperties.AddRoomProperty("RP", false);
                BoltMatchmaking.CreateSession(_gameName, photonRoomProperties);
            }
        }
Ejemplo n.º 16
0
    public override void BoltStartDone()
    {
        if (BoltNetwork.IsServer)
        {
            string matchName = Guid.NewGuid().ToString();

            var props = new PhotonRoomProperties();

            props.IsOpen    = true;
            props.IsVisible = false;             // Make the session invisible

            props["type"] = "game01";
            props["map"]  = "Tutorial1";

            BoltMatchmaking.CreateSession(
                sessionID: matchName,
                sceneToLoad: "Tutorial1",
                token: props
                );
        }

        // Broadcast and Listen for LAN Sessions
        BoltNetwork.EnableLanBroadcast();
    }
Ejemplo n.º 17
0
    public override void BoltStartDone()
    {
        if (BoltNetwork.IsServer)
        {
            PhotonRoomProperties token = new PhotonRoomProperties();
            token.IsOpen    = true;
            token.IsVisible = true;

            if (blueTeam == true)
            {
                token.AddRoomProperty("t", 1);
            }

            if (redTeam == true)
            {
                token.AddRoomProperty("t", 2);
            }
            staticData.lobbyName = Guid.NewGuid().ToString();
            var matchName = staticData.lobbyName;

            BoltNetwork.SetServerInfo(matchName, token);
            BoltNetwork.LoadScene("game");
        }
    }
Ejemplo n.º 18
0
        void OnGUI()
        {
            GUILayout.BeginArea(new Rect(10, 10, Screen.width - 20, Screen.height - 20));

            switch (_state)
            {
            // starting Bolt is the same regardless of the transport layer
            case State.SelectMode:
                if (GUILayout.Button("Start Server", GUILayout.ExpandWidth(true)))
                {
                    BoltLauncher.StartServer();
                    _state = State.ModeServer;
                }

                if (GUILayout.Button("Start Client", GUILayout.ExpandWidth(true)))
                {
                    BoltLauncher.StartClient();
                    _state = State.ModeClient;
                }

                break;

            // Publishing a session into the matchmaking server
            case State.ModeServer:
                if (BoltNetwork.isRunning && BoltNetwork.isServer)
                {
                    if (GUILayout.Button("Publish HostInfo And Load Map", GUILayout.ExpandWidth(true)))
                    {
                        // Normal Token
                        //RoomProtocolToken token = new RoomProtocolToken()
                        //{
                        //    ArbitraryData = "My DATA",
                        //    password = "******"
                        //};

                        // Use to pass custom properties to your room
                        PhotonRoomProperties roomProperties = new PhotonRoomProperties();

                        roomProperties.AddRoomProperty("t", 1);     // ex: game type
                        roomProperties.AddRoomProperty("m", 4);     // ex: map id

                        roomProperties.IsOpen    = true;
                        roomProperties.IsVisible = true;

                        string matchName = "MyPhotonGame #" + UnityEngine.Random.Range(1, 100);

                        BoltNetwork.SetServerInfo(matchName, roomProperties);
                        BoltNetwork.LoadScene("Level1");
                    }
                }
                break;

            // for the client, after Bolt is innitialized, we should see the list
            // of available sessions and join one of them
            case State.ModeClient:

                if (BoltNetwork.isRunning && BoltNetwork.isClient)
                {
                    GUILayout.Label("Session List");

                    var oldList = (from item in internalSessionList
                                   where (DateTime.Now - item.Value.receivedAt).TotalSeconds > SessionTimeout
                                   select item);

                    foreach (var item in oldList)
                    {
                        internalSessionList.Remove(item.Key);
                    }

                    ShowSessionList(internalSessionList);
                }
                break;
            }

            GUILayout.EndArea();
        }
Ejemplo n.º 19
0
        void OnGUI()
        {
            GUILayout.BeginArea(new Rect(10, 10, Screen.width - 20, Screen.height - 20));

            switch (_state)
            {
            // starting Bolt is the same regardless of the transport layer
            case State.SelectMode:
                if (GUILayout.Button("Start Server", GUILayout.ExpandWidth(true)))
                {
                    BoltLauncher.StartServer();
                    _state = State.ModeServer;
                }

                if (GUILayout.Button("Start Client", GUILayout.ExpandWidth(true)))
                {
                    BoltLauncher.StartClient();
                    _state = State.ModeClient;
                }

                break;

            // Publishing a session into the matchmaking server
            case State.ModeServer:
                if (BoltNetwork.IsRunning && BoltNetwork.IsServer)
                {
                    if (GUILayout.Button("Publish HostInfo And Load Map", GUILayout.ExpandWidth(true)))
                    {
                        // RoomProtocolToken token = new RoomProtocolToken()
                        // {
                        //  ArbitraryData = "My DATA",
                        //  password = "******"
                        // };

                        // Uncomment if you want to pass custom properties into your room
                        // This is just an example data
                        //PhotonCloudRoomProperties token = new PhotonCloudRoomProperties();
                        //properties.AddRoomProperty("t", 1);
                        //properties.AddRoomProperty("m", 4);

                        PhotonRoomProperties token = new PhotonRoomProperties();
                        token.IsOpen    = true;
                        token.IsVisible = true;

                        token.AddRoomProperty("t", 1);
                        token.AddRoomProperty("m", 2);

                        string matchName = "MyPhotonGame #" + UnityEngine.Random.Range(1, 100);

                        BoltMatchmaking.CreateSession(
                            sessionID: matchName,
                            token: token,
                            sceneToLoad: "PhotonGame"
                            );

                        // BoltNetwork.SetServerInfo(matchName, token);
                        // BoltNetwork.LoadScene("PhotonGame");
                    }
                }
                break;

            // for the client, after Bolt is innitialized, we should see the list
            // of available sessions and join one of them
            case State.ModeClient:

                if (BoltNetwork.IsRunning && BoltNetwork.IsClient)
                {
                    GUILayout.Label("Session List");

                    foreach (var session in BoltNetwork.SessionList)
                    {
                        // Simple session
                        UdpSession udpSession = session.Value as UdpSession;

                        // Skip if is not a Photon session
                        if (udpSession.Source != UdpSessionSource.Photon)
                        {
                            continue;
                        }

                        // Photon Session
                        PhotonSession photonSession = udpSession as PhotonSession;

                        string sessionDescription = String.Format("{0} / {1} ({2})",
                                                                  photonSession.Source, photonSession.HostName, photonSession.Id);

                        RoomProtocolToken token = photonSession.GetProtocolToken() as RoomProtocolToken;

                        if (token != null)
                        {
                            sessionDescription += String.Format(" :: {0}", token.ArbitraryData);
                        }
                        else
                        {
                            object value_t = -1;
                            object value_m = -1;

                            if (photonSession.Properties.ContainsKey("t"))
                            {
                                value_t = photonSession.Properties["t"];
                            }

                            if (photonSession.Properties.ContainsKey("m"))
                            {
                                value_t = photonSession.Properties["m"];
                            }

                            sessionDescription += String.Format(" :: {0}/{1}", value_t, value_m);
                        }

                        if (GUILayout.Button(sessionDescription, GUILayout.ExpandWidth(true)))
                        {
                            ServerConnectToken connectToken = new ServerConnectToken
                            {
                                data = "ConnectTokenData"
                            };

                            BoltNetwork.Connect(photonSession, connectToken);
                        }
                    }
                }
                break;
            }

            GUILayout.EndArea();
        }