public override void SessionListUpdated(Map <Guid, UdpSession> sessionList) { if (_timerRoutine != null) { StopCoroutine(_timerRoutine); _timerRoutine = null; } Debug.LogFormat("Session list updated: {0} total sessions", sessionList.Count); foreach (var session in sessionList) { PhotonSession photonSession = session.Value as PhotonSession; if (photonSession != null && photonSession.Source == UdpSessionSource.Photon) { object value; if (photonSession.Properties.TryGetValue("type", out value)) { BoltLog.Info("Room with type: {0}", value); } if (photonSession.Properties.TryGetValue("map", out value)) { BoltLog.Info("Room with map: {0}", value); } BoltMatchmaking.JoinSession(photonSession); } } }
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); } } }
Map <Guid, UdpSession> FetchSessionListFromPhoton() { var map = new Map <Guid, UdpSession>(); foreach (var r in LoadBalancerClient.RoomInfoList) { if (r.Value.IsOpen) { try { PhotonSession session = new PhotonSession(); session._roomName = r.Key; session._id = new Guid((r.Value.CustomProperties["UdpSessionId"] as String) ?? ""); session._hostData = r.Value.CustomProperties["UserToken"] as Byte[]; if (_config.UsePunchThrough) { try { session._socketPeerId = new Guid((r.Value.CustomProperties["SocketPeerId"] as String) ?? ""); } #if DEVELOPMENT_BUILD || UNITY_EDITOR catch (Exception exn) { BoltLog.Exception(exn); } #else catch { } #endif } session._playerCount = r.Value.PlayerCount; session._playerLimit = r.Value.MaxPlayers; map = map.Add(session.Id, session); } catch (Exception exn) { BoltLog.Exception(exn); } } } return(map); }
public override void SessionListUpdated(Map <Guid, UdpSession> sessionList) { ClearRooms(); int i = 0; foreach (var session in sessionList) { PhotonSession photonSession = session.Value as PhotonSession; GameObject room = Instantiate(roomPrefab, roomListContent.transform); room.gameObject.SetActive(true); room.transform.position = new Vector3(room.transform.position.x, room.transform.position.y - i * 100, room.transform.position.z); room.GetComponentInChildren <TextMeshProUGUI>().text = photonSession.Properties["roomName"] as string; room.GetComponentInChildren <Button>().onClick.AddListener(() => OnClickJoinGame(photonSession)); roomList.Add(room); i++; } }
public override void SessionListUpdated(Map <Guid, UdpSession> sessionList) { Debug.LogFormat("Session list updated: {0} total sessions", sessionList.Count); var shuffled = sessionList.OrderBy(a => Guid.NewGuid()).ToList(); if (connecting == false) { foreach (var session in shuffled) { UdpSession udpSession = session.Value as UdpSession; PhotonSession photonSession = udpSession as PhotonSession; if (photonSession.Source == UdpSessionSource.Photon) { if (photonSession.Properties.ContainsKey("t")) { if (redTeam) { if ((int)photonSession.Properties["t"] == 1) { BoltNetwork.Connect(photonSession); connecting = true; } } else if (blueTeam) { if ((int)photonSession.Properties["t"] == 2) { BoltNetwork.Connect(photonSession); connecting = true; } } } } } } }
Map <Guid, UdpSession> FetchSessionListFromPhoton() { var map = new Map <Guid, UdpSession>(); foreach (var r in LoadBalancerClient.RoomInfoList) { if (r.Value.IsOpen && r.Value.IsVisible) { try { if (!r.Value.CustomProperties.ContainsKey("UdpSessionId")) { continue; } PhotonSession session = new PhotonSession { _roomName = r.Key, _id = new Guid((r.Value.CustomProperties["UdpSessionId"] as String) ?? ""), _hostData = r.Value.CustomProperties["UserToken"] as Byte[], _playerCount = r.Value.PlayerCount, _playerLimit = r.Value.MaxPlayers, _customProperties = r.Value.CustomProperties }; map = map.Add(session.Id, session); } catch (Exception exn) { BoltLog.Exception(exn); } } } return(map); }
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(); }
private void OnClickJoinGame(PhotonSession photonSession) { BoltMatchmaking.JoinSession(photonSession); }