Example #1
0
        // only returns true
        public bool GetOrCreateAppLobby(string lobbyName, AppLobbyType lobbyType , out AppLobby lobby)
        {
            if (string.IsNullOrEmpty(lobbyName))
            {
                lobby = this.defaultLobby;
                return true;
            }

            var key = new KeyValuePair<string, AppLobbyType>(lobbyName, lobbyType);

            lock (this.lobbyDict)
            {
                if (this.lobbyDict.TryGetValue(key, out lobby))
                {
                    return true;
                }

                lobby = this.CreateAppLobby(lobbyName, lobbyType);
                this.lobbyDict.Add(key, lobby);
            }

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Created lobby: name={0}, type={1}", lobbyName, lobbyType);
            }

            return true;
        }
Example #2
0
        public bool GetOrCreateAppLobby(string lobbyName, AppLobbyType lobbyType, out AppLobby lobby)
        {
            if (string.IsNullOrEmpty(lobbyName))
            {
                lobby = this.defaultLobby;
                return(true);
            }

            var key = new KeyValuePair <string, AppLobbyType>(lobbyName, lobbyType);

            lock (this.lobbyDict)
            {
                if (this.lobbyDict.TryGetValue(key, out lobby))
                {
                    return(true);
                }

                lobby = new AppLobby(this.application, lobbyName, lobbyType);
                this.lobbyDict.Add(key, lobby);
            }

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Created lobby: name={0}, type={1}", lobbyName, lobbyType);
            }

            return(true);
        }
Example #3
0
 protected GameListBase(AppLobby lobby)
 {
     this.Lobby = lobby;
     this.gameDict = new LinkedListDictionary<string, GameState>();
     this.changedGames = new Dictionary<string, GameState>();
     this.removedGames = new HashSet<string>();
 }
Example #4
0
 protected GameListBase(AppLobby lobby)
 {
     this.Lobby        = lobby;
     this.gameDict     = new LinkedListDictionary <string, GameState>();
     this.changedGames = new Dictionary <string, GameState>();
     this.removedGames = new HashSet <string>();
 }
Example #5
0
 public SqlGameList(AppLobby lobby)
     : base(lobby)
 {
     if (log.IsDebugEnabled)
     {
         log.DebugFormat("Creating new SqlGameList");
     }
 }
Example #6
0
        public void Initialize()
        {
            this.defaultLobby = this.CreateAppLobby(string.Empty, defaultLobbyType);

            var defaultLobbyKey = new KeyValuePair <string, AppLobbyType>(string.Empty, defaultLobbyType);

            this.lobbyDict.Add(defaultLobbyKey, this.defaultLobby);
        }
 public GameChannelList(AppLobby lobby)
     : base(lobby)
 {
     if (log.IsDebugEnabled)
     {
         log.DebugFormat("Creating new GameChannelList");
     }
 }
Example #8
0
 public GameList(AppLobby lobby)
     : base(lobby)
 {
     if (log.IsDebugEnabled)
     {
         log.DebugFormat("Creating new GameList");
     }
 }
Example #9
0
//        private int _limitSqlFilterResults;

        #endregion

        public SqlFilterGameList(AppLobby lobby, bool?useLegacyLobbies, int?limitSqlFilterResults, string matchmakingStoredProcedure) : base(lobby, limitSqlFilterResults, matchmakingStoredProcedure)
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Creating new SqlFilterGameList");
            }

            _useLegacyLobbies = useLegacyLobbies ?? MasterServerSettings.Default.UseLegacyLobbies;
        }
        public GameChannelList(AppLobby lobby)
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Creating new GameChannelList");
            }

            this.Lobby = lobby;
            this.GameDict = new Dictionary<string, GameState>();
        }
Example #11
0
        public MasterClientPeer(InitRequest initRequest, AppLobby lobby)
            : base(initRequest.Protocol, initRequest.PhotonPeer)
        {
            this.lobby = lobby;

            if (MasterApplication.AppStats != null)
            {
                MasterApplication.AppStats.IncrementMasterPeerCount();
                MasterApplication.AppStats.AddSubscriber(this);
            }
        }
Example #12
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "GameState" /> class.
 /// </summary>
 /// <param name="lobby">
 /// The lobby to which the game belongs.
 /// </param>
 /// <param name = "id">
 ///   The game id.
 /// </param>
 /// <param name = "maxPlayer">
 ///   The maximum number of player who can join the game.
 /// </param>
 /// <param name = "gameServerPeer">
 ///   The game server peer.
 /// </param>
 public GameState(AppLobby lobby, string id, byte maxPlayer, IncomingGameServerPeer gameServerPeer)
 {
     this.Lobby                 = lobby;
     this.Id                    = id;
     this.MaxPlayer             = maxPlayer;
     this.IsOpen                = true;
     this.IsVisible             = true;
     this.IsCreatedOnGameServer = false;
     this.GameServerPlayerCount = 0;
     this.gameServer            = gameServerPeer;
 }
Example #13
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "GameState" /> class.
 /// </summary>
 /// <param name="lobby">
 /// The lobby to which the game belongs.
 /// </param>
 /// <param name = "id">
 ///   The game id.
 /// </param>
 /// <param name = "maxPlayer">
 ///   The maximum number of player who can join the game.
 /// </param>
 /// <param name = "gameServerPeer">
 ///   The game server peer.
 /// </param>
 public GameState(AppLobby lobby, string id, byte maxPlayer, IncomingGameServerPeer gameServerPeer)
 {
     this.Lobby = lobby;
     this.Id = id;
     this.MaxPlayer = maxPlayer;
     this.IsOpen = true;
     this.IsVisible = true;
     this.IsCreatedOnGameServer = false;
     this.GameServerPlayerCount = 0;
     this.gameServer = gameServerPeer;
 }
Example #14
0
        public GameList(AppLobby lobby)
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Creating new GameList");
            }

            this.Lobby        = lobby;
            this.gameDict     = new LinkedListDictionary <string, GameState>();
            this.changedGames = new Dictionary <string, GameState>();
            this.removedGames = new HashSet <string>();
        }
Example #15
0
        public SqlGameList(AppLobby lobby)
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Creating new GameList");
            }

            this.Lobby = lobby;
            this.gameDict = new LinkedListDictionary<string, GameState>();
            this.changedGames = new Dictionary<string, GameState>();
            this.removedGames = new HashSet<string>();
        }
        public LimitedGameList(AppLobby lobby, bool?useLegacyLobbies, int?limitGameList, int?limitGameListUpdate)
            : base(lobby)
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Creating new LimitedGameList");
            }

            _useLegacyLobbies    = useLegacyLobbies ?? MasterServerSettings.Default.UseLegacyLobbies;
            _limitGameList       = limitGameList ?? MasterServerSettings.Default.LimitGameList;
            _limitGameListUpdate = limitGameListUpdate ?? MasterServerSettings.Default.LimitGameListUpdate;
        }
        public bool GetOrCreateGame(string gameId, AppLobby lobby, IGameList gameList, byte maxPlayer, IncomingGameServerPeer gameServerPeer, out GameState gameState)
        {
            lock (this.gameDict)
            {
                if (this.gameDict.TryGetValue(gameId, out gameState))
                {
                    return false;
                }

                gameState = new GameState(lobby, gameId, maxPlayer, gameServerPeer);
                this.gameDict.Add(gameId, gameState);
                return true;
            }
        }
Example #18
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "GameState" /> class.
 /// </summary>
 /// <param name="lobby">
 /// The lobby to which the game belongs.
 /// </param>
 /// <param name = "id">
 ///   The game id.
 /// </param>
 /// <param name = "maxPlayer">
 ///   The maximum number of player who can join the game.
 /// </param>
 /// <param name = "gsContext">
 ///   The game server peer.
 /// </param>
 public GameState(AppLobby lobby, string id, byte maxPlayer, GameServerContext gsContext)
 {
     this.Lobby     = lobby;
     this.Id        = id;
     this.MaxPlayer = maxPlayer;
     this.IsOpen    = true;
     this.IsVisible = true;
     this.HasBeenCreatedOnGameServer = false;
     this.GameServerPlayerCount      = 0;
     this.gameServerContext          = gsContext;
     this.IsJoinable         = this.CheckIsGameJoinable();
     this.activeUserIdList   = new List <string>(maxPlayer > 0 ? maxPlayer : 5);
     this.inactiveUserIdList = new List <string>(maxPlayer > 0 ? maxPlayer : 5);
     this.expectedUsersList  = new List <string>(maxPlayer > 0 ? maxPlayer : 5);
     this.excludedActors     = new List <ExcludedActorInfo>();
 }
Example #19
0
        public SqlGameList(AppLobby lobby, int?limitSqlFilterResults, string matchmakingStoredProcedure = null)
            : base(lobby)
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Creating new SqlGameList");
            }

            _limitSqlFilterResults          = limitSqlFilterResults ?? MasterServerSettings.Default.LimitSqlFilterResults;
            this.matchmakingStoredProcedure = matchmakingStoredProcedure;

            //do this in the AppLobby and pass dictionary to here?
//            TryLoadStoredProceduresFromFile();

            TryLoadStoredProcedures(matchmakingStoredProcedure);
        }
        private static GetLobbyStatsResponse LobbyListToLobbyStatsData(AppLobby[] lobbyList)
        {
            var lobbyStats = new GetLobbyStatsResponse();

            var count = lobbyList.Length;
            lobbyStats.LobbyNames = new string[count];
            lobbyStats.LobbyTypes = new byte[count];
            lobbyStats.PeerCount = new int[count];
            lobbyStats.GameCount = new int[count];

            for (int i = 0; i < lobbyList.Length; i++)
            {
                var item = lobbyList[i];
                lobbyStats.LobbyNames[i] = item.LobbyName;
                lobbyStats.LobbyTypes[i] = (byte)item.LobbyType;
                lobbyStats.PeerCount[i] = item.PeerCount + item.PlayerCount;
                lobbyStats.GameCount[i] = item.GameCount;
            }

            return lobbyStats;
        }
Example #21
0
        public GameState(AppLobby lobby, Hashtable data)
        {
            this.Lobby     = lobby;
            this.Id        = (string)data[GameId];
            this.MaxPlayer = (byte)data[MaxPlayerId];
            this.IsOpen    = (bool)data[IsOpenId];
            this.IsVisible = (bool)data[IsVisibleId];

            this.InactivePlayerCount = (int)data[InactiveCountId];
            this.createDateUtc       = DateTime.FromBinary((long)data[CreateDateId]);
            this.activeUserIdList    = new List <string>((string[])data[UserListId]);
            this.inactiveUserIdList  = new List <string>((string[])data[InactiveUsersId]);
            this.expectedUsersList   = new List <string>((string[])data[ExpectedUsersId]);
            this.excludedActors      = new List <ExcludedActorInfo>((ExcludedActorInfo[])data[ExcludedUsersId]);
            this.properties          = (Dictionary <object, object>)data[PropertiesId];

            this.HasBeenCreatedOnGameServer = true;
            this.GameServerPlayerCount      = 0;
            this.gameServerContext          = null;
            this.IsJoinable = this.CheckIsGameJoinable();
        }
Example #22
0
        public AppLobby[] GetLobbies(string[] lobbyNames, byte[] lobbyTypes)
        {
            if (lobbyNames.Length == 0)
            {
                return new AppLobby[0];
            }

            var  appLobbies = new AppLobby[lobbyNames.Length];

            lock (this.lobbyDict)
            {
                for (int i = 0; i < lobbyNames.Length; i++)
                {
                    var key = new KeyValuePair<string, AppLobbyType>(lobbyNames[i], (AppLobbyType)lobbyTypes[i]);
                    AppLobby lobby;
                    this.lobbyDict.TryGetValue(key, out lobby);
                    appLobbies[i] = lobby;
                }
            }

            return appLobbies;
        }
Example #23
0
        public AppLobby[] GetLobbies(string[] lobbyNames, byte[] lobbyTypes)
        {
            if (lobbyNames.Length == 0)
            {
                return(new AppLobby[0]);
            }

            var appLobbies = new AppLobby[lobbyNames.Length];

            lock (this.lobbyDict)
            {
                for (int i = 0; i < lobbyNames.Length; i++)
                {
                    var      key = new KeyValuePair <string, AppLobbyType>(lobbyNames[i], (AppLobbyType)lobbyTypes[i]);
                    AppLobby lobby;
                    this.lobbyDict.TryGetValue(key, out lobby);
                    appLobbies[i] = lobby;
                }
            }

            return(appLobbies);
        }
Example #24
0
        // only returns true
        public bool GetOrCreateAppLobby(string lobbyName, AppLobbyType lobbyType, out AppLobby lobby, out string errorMsg)
        {
            if (string.IsNullOrEmpty(lobbyName))
            {
                lobby    = this.defaultLobby;
                errorMsg = string.Empty;
                return(true);
            }

            var key = new KeyValuePair <string, AppLobbyType>(lobbyName, lobbyType);

            lock (this.lobbyDict)
            {
                if (this.lobbyDict.TryGetValue(key, out lobby))
                {
                    errorMsg = string.Empty;
                    return(true);
                }

                if (this.application.LobbiesCount >= MasterServerSettings.Default.LobbiesCountLimit)
                {
                    lobby    = null;
                    errorMsg = LBErrorMessages.LobbiesLimitReached;
                    return(false);
                }
                lobby = this.CreateAppLobby(lobbyName, lobbyType);
                this.lobbyDict.Add(key, lobby);
            }

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Created lobby: name={0}, type={1}", lobbyName, lobbyType);
            }

            errorMsg = string.Empty;
            return(true);
        }
        public bool TryCreateGame(string gameId, AppLobby lobby, IGameList gameList, byte maxPlayer, IncomingGameServerPeer gameServerPeer, out GameState gameState)
        {
            bool result = false;

            lock (this.gameDict)
            {
                if (this.gameDict.TryGetValue(gameId, out gameState) == false)
                {
                    gameState = new GameState(lobby, gameId, maxPlayer, gameServerPeer);
                    this.gameDict.Add(gameId, gameState);
                    result = true;
                }
            }

            if (result)
            {
                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("Created game: gameId={0}, appId={1}", gameId, this.ApplicationId);
                }
            }

            return result;
        }
        private OperationResponse TryGetLobby(string lobbyName, byte lobbyType, byte operationCode, out AppLobby lobby)
        {
            if (string.IsNullOrEmpty(lobbyName) && this.AppLobby != null)
            {
                lobby = this.AppLobby;
                return null;
            }

            if (!this.Application.LobbyFactory.GetOrCreateAppLobby(lobbyName, (AppLobbyType) lobbyType, out lobby))
            {
                // getting here should never happen
                if (log.IsWarnEnabled)
                {
                    log.WarnFormat("Could not get or create lobby: name={0}, type={1}", lobbyName, lobbyType);
                }

                return new OperationResponse
                {
                    OperationCode = operationCode,
                    ReturnCode = (short)ErrorCode.InternalServerError,
                    DebugMessage = LBErrorMessages.LobbyNotExist,
                };

            }

            return null;
        }
 public AsyncRandomGameList(AppLobby lobby)
     : base(lobby)
 {
 }
Example #28
0
 public LobbyFactory(GameApplication application, AppLobbyType defaultLobbyType)
 {
     this.application  = application;
     this.defaultLobby = new AppLobby(this.application, string.Empty, defaultLobbyType);
 }
 public AsyncRandomGameList(AppLobby lobby)
     : base(lobby)
 {
 }
Example #30
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "GameState" /> class.
 /// </summary>
 /// <param name="lobby">
 /// The lobby to which the game belongs.
 /// </param>
 /// <param name = "id">
 ///   The game id.
 /// </param>
 /// <param name = "maxPlayer">
 ///   The maximum number of player who can join the game.
 /// </param>
 /// <param name = "gameServerPeer">
 ///   The game server peer.
 /// </param>
 public GameState(AppLobby lobby, string id, byte maxPlayer, IncomingGameServerPeer gameServerPeer)
 {
     this.Lobby = lobby;
     this.Id = id;
     this.MaxPlayer = maxPlayer;
     this.IsOpen = true;
     this.IsVisible = true;
     this.HasBeenCreatedOnGameServer = false;
     this.GameServerPlayerCount = 0;
     this.gameServer = gameServerPeer;
     this.IsJoinable = this.CheckIsGameJoinable();
     this.activeUserIdList = new List<string>(maxPlayer > 0 ? maxPlayer : 5);
     this.inactiveUserIdList = new List<string>(maxPlayer > 0 ? maxPlayer : 5);
     this.expectedUsersList = new List<string>(maxPlayer > 0 ? maxPlayer : 5);
     this.excludedActors = new List<ExcludedActorInfo>();
 }
Example #31
0
        public GameState(AppLobby lobby, Hashtable data)
        {
            this.Lobby = lobby;
            this.Id = (string)data[GameId];
            this.MaxPlayer = (int)data[MaxPlayerId];
            this.IsOpen = (bool)data[IsOpenId];
            this.IsVisible = (bool)data[IsVisibleId];

            this.InactivePlayerCount = (int)data[InactiveCountId];
            this.createDateUtc = DateTime.FromBinary((long)data[CreateDateId]);
            this.activeUserIdList = new List<string>((string[])data[UserListId]);
            this.inactiveUserIdList = new List<string>((string[])data[InactiveUsersId]);
            this.expectedUsersList = new List<string>((string[])data[ExpectedUsersId]);
            this.excludedActors = new List<ExcludedActorInfo>((ExcludedActorInfo[])data[ExcludedUsersId]);
            this.properties = (Dictionary<object, object>)data[PropertiesId];

            this.HasBeenCreatedOnGameServer = true;
            this.GameServerPlayerCount = 0;
            this.gameServer = null;
            this.IsJoinable = this.CheckIsGameJoinable();
        }
 public LobbyFactory(GameApplication application, AppLobbyType defaultLobbyType)
 {
     this.application = application;
     this.defaultLobby = new AppLobby(this.application, string.Empty, defaultLobbyType);
 }
Example #33
0
        public void Initialize()
        {
            this.defaultLobby = this.CreateAppLobby(string.Empty, defaultLobbyType);

            var defaultLobbyKey = new KeyValuePair<string, AppLobbyType>(string.Empty, defaultLobbyType);
            this.lobbyDict.Add(defaultLobbyKey, this.defaultLobby);
        }
 public MasterClientPeer(InitRequest initRequest, AppLobby lobby)
     : base(initRequest.Protocol, initRequest.PhotonPeer)
 {
     this.lobby = lobby;
 }