public void Initialize(GameRoomMessagingHub messagingHub, NetworkServer networkServer, GameLiftServer gameLiftServer) { if (messagingHub == null || networkServer == null || gameLiftServer == null) { UnityEngine.Debug.LogError("GameRoomContext can not be initialized."); return; } _MessagingHub = messagingHub; _NetworkServer = networkServer; _GameLiftServer = gameLiftServer; _MessagingHub.OnReceivedSystemUserIdAsObservable() .Subscribe(networkClientUser => { bool contained = _NetworkClientUsers.ContainsKey(networkClientUser.UserId); bool accepted = true; if (!_IsLocalServer) { accepted = _GameLiftServer.AcceptPlayerSession(networkClientUser.UserId); } if (!contained && accepted) { _NetworkClientUsers.Add(networkClientUser.UserId, networkClientUser); } else { _NetworkServer.DisconnectClient(networkClientUser.ClientId, "Cannot accept system user id"); } }) .AddTo(this); _MessagingHub.OnReceivedPlayerEjectionAsObservable() .Subscribe(player => { string userId = player.UserId; if (_NetworkClientUsers.TryGetValue(userId, out NetworkClientUser networkClientUser)) { _NetworkClientUsers.Remove(userId); _GameLiftServer.RemovePlayerSession(networkClientUser.UserId); _NetworkServer.DisconnectClient(networkClientUser.ClientId, "PlayerEjection"); } }) .AddTo(this); _NetworkServer.OnClientDisconnectedAsObservable() .Subscribe(clientId => { var networkClientUser = _NetworkClientUsers.Select(kv => kv.Value).FirstOrDefault(v => v.ClientId == clientId); if (networkClientUser != null) { _NetworkClientUsers.Remove(networkClientUser.UserId); _GameLiftServer.RemovePlayerSession(networkClientUser.UserId); } }) .AddTo(this); }
private void Awake() { if (Singleton != null) { Destroy(gameObject); return; } DontDestroyOnLoad(gameObject); Singleton = this; GameLift = new GameLiftServer(); }
void Awake() { _playerSessions = new Dictionary <int, string>(); _gameLiftServer = GetComponent <GameLiftServer>(); Application.runInBackground = true; _server.OnConnected = OnConnected; _server.OnData = OnDataReceived; _server.OnDisconnected = OnDisonnected; }
public void Awake() { Debug.Log(":) GAMELIFT AWAKE"); // Allow Unity to validate HTTPS SSL certificates; http://stackoverflow.com/questions/4926676 ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback; #if SERVER Debug.Log(":) I AM SERVER"); server = new GameLiftServer(this); server.Awake(); #endif #if CLIENT Debug.Log(":) I AM CLIENT"); client = new GameLiftClient(this); #endif /*GameObject gamelogicObj = GameObject.Find("/GameLogicStatic"); * Debug.Assert(gamelogicObj != null); * gamelogic = gamelogicObj.GetComponent<GameLogic>(); * if (gamelogic == null) Debug.Log(":( GAMELOGIC CODE NOT AVAILABLE ON GAMELOGICSTATIC OBJECT"); */ }