Пример #1
0
        public override void ConnectRequest(UdpEndPoint endpoint, IProtocolToken token)
        {
            BoltLog.Warn("Connect Request");

            //token should be ServerConnectToken
            if (token != null)
            {
                BoltLog.Warn(token.GetType().ToString());

                ServerConnectToken t = token as ServerConnectToken;
                BoltLog.Warn("Server Token: null? " + (t == null));
                BoltLog.Warn("Data: " + t.data);
            }
            else
            {
                BoltLog.Warn("Received token is null");
            }

            ServerAcceptToken acceptToken = new ServerAcceptToken
            {
                data = "Accepted"
            };

            BoltNetwork.Accept(endpoint, acceptToken);
        }
Пример #2
0
        public override void Connected(BoltConnection connection)
        {
            BoltLog.Warn("Connected");

            ServerAcceptToken acceptToken = connection.AcceptToken as ServerAcceptToken;

            if (acceptToken != null)
            {
                BoltConsole.Write("AcceptToken: " + acceptToken.GetType().ToString());
                BoltConsole.Write("AcceptToken: " + acceptToken.data);
            }
            else
            {
                BoltLog.Warn("AcceptToken is NULL");
            }

            ServerConnectToken connectToken = connection.ConnectToken as ServerConnectToken;

            if (connectToken != null)
            {
                BoltConsole.Write("ConnectToken: " + connectToken.GetType().ToString());
                BoltConsole.Write("ConnectToken: " + connectToken.data);
            }
            else
            {
                BoltLog.Warn("ConnectToken is NULL");
            }
        }
Пример #3
0
        void ShowSessionList(Dictionary <Guid, UdpSession> sessionList)
        {
            foreach (var session in sessionList)
            {
                UdpSession udpSession = session.Value as UdpSession;

                // Skip if is not a Photon session
                if (udpSession.Source != UdpSessionSource.Photon)
                {
                    BoltLog.Info("UdpSession with different Source: {0}", udpSession.Source);
                    continue;
                }

                PhotonSession photonSession = udpSession as PhotonSession;

                if (photonSession == null)
                {
                    continue;
                }

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

                IProtocolToken token = photonSession.GetProtocolToken();

                // Normal Token
                RoomProtocolToken roomToken = token as RoomProtocolToken;

                if (roomToken != null)
                {
                    sessionDescription += String.Format(" :: {0}", roomToken.ArbitraryData);
                }

                object prop_type = -1;
                object prop_map  = -1;

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

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

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

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

                    BoltNetwork.Connect(photonSession, connectToken);
                }
            }
        }
Пример #4
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);

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

                        BoltNetwork.SetServerInfo(matchName, token);
                        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");

                    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();
        }