public bool JoinGameServer(string userPuid, string userToken, out ECode ec) { ec = ECode.None; bool success = false; IGameServerController_Callback callbackChannel // Get player callback object to store = OperationContext.Current.GetCallbackChannel <IGameServerController_Callback>(); try { if (PlayerRegistry.GetCount() >= MAX_PLAYERS) { ec = ECode.ServerFull; Console.WriteLine("> Rejected Player Join: @username:{" + userPuid + "} token:{" + userToken + "}"); } else if (PlayerRegistry.IsClientRegistered(userToken)) { ((PlayerSession)PlayerRegistry.GetClientSession(userToken)).CallbackChannel = callbackChannel; // update callback channel success = true; Console.WriteLine("> Old Player Join: @username:{" + userPuid + "} token:{" + userToken + "}"); } else if (GPSConnection.IsUserTokenVaild(userToken)) { // Register Player // PlayerSession ps = new PlayerSession(userPuid, "", PLAYER_LIFESPAN, callbackChannel, null); PlayerRegistry.RegisterClient(userToken, ps); success = true; Console.WriteLine("> New Player Join: @username:{" + userPuid + "} token:{" + userToken + "}"); // Notify others of event // AdvertiseToPortal_UserJoin(userPuid); //BroadcastToPlayers_PlayerStatus(userPuid); if (Game != null && Game.HasGameStarted() == false) { // Notify players if this will change game state BroadcastToPlayers_GameReady(Game.ArePlayersAllowedToEnterGame()); } } else { Console.WriteLine("> Invalid Player Join: @username:{" + userPuid + "} token:{" + userToken + "}"); } } catch (ServerConnectionException ex) { ec = ex.ErrorCode; Console.WriteLine("> Failed Player Join: @username:{" + userPuid + "} token:{" + userToken + "}"); } return(success); }
public bool IsEnoughPlayers() { return(PlayerRegistry.GetCount() >= MinPlayers); }