Beispiel #1
0
 void LobbyRead(GameDTO lobby)
 {
     Task.Factory.StartNew(() => CommitLobby(lobby));
 }
Beispiel #2
0
        /// <summary>
        /// Checks the database for the lobby and if it does not exist then it adds it.
        /// Does not lock the database or commit
        /// </summary>
        /// <param name="lobby"></param>
        /// <returns>True if players need to be committed</returns>
        public bool RecordLobby(GameDTO lobby)
        {
            if (lobby == null)
                throw new ArgumentNullException("lobby");

            lock (_lobbycache)
            {
                //Lets clear the cache if it somehow hits 1k people.
                //That way people who afk in lobbies don't complain about a memory leak.
                if (_currentlobby == 0 || _currentlobby != lobby.Id || _lobbycache.Count > 1000)
                {
                    _currentlobby = lobby.Id;
                    _lobbycache.Clear();
                }
            }

            bool commit = false;

            foreach (PlayerParticipant plr in lobby.TeamOne.Union(lobby.TeamTwo).Where(p => p is PlayerParticipant).ToList())
            {
                var entry = new PlayerEntry(plr);
                if (RecordPlayer(entry, false))
                {
                    commit = true;
                }
            }

            return commit;
        }
Beispiel #3
0
        /// <summary>
        /// Records/Commits the lobby to the database. Locking the database lock.
        /// </summary>
        /// <param name="lobby"></param>
        public void CommitLobby(GameDTO lobby)
        {
            bool committed = false;
            Stopwatch sw;
            lock (DatabaseLock)
            {
                sw = Stopwatch.StartNew();

                committed = RecordLobby(lobby);
                if (committed)
                    Database.Commit();
            }
            sw.Stop();

            if (committed)
                StaticLogger.Debug(string.Format("Lobby committed in {0}ms", sw.ElapsedMilliseconds));
        }
        void Reader_ObjectRead(object obj)
        {
            if (obj is GameDTO)
            {
                CurrentGame = (GameDTO)obj;

                string team = "";

                foreach (PlayerParticipant p in CurrentGame.TeamOne)
                {
                    team += p.Name + ", ";
                }

                if (team != "")
                    team = team.Remove(team.Length - 3);

                UpdateTeam(team, 1);

                // Keep it DRY ya'll
                team = "";

                foreach (PlayerParticipant p in CurrentGame.TeamTwo)
                {
                    team += p.Name + ", ";
                }

                if (team != "")
                    team = team.Remove(team.Length - 3);

                UpdateTeam(team, 2);

                UpdateMap(CurrentGame.MapId);
            }
            else if (obj is EndOfGameStats)
            {
                return;
            }
            else if (obj is List<ChampionDTO>)
            {
                Champions = (List<ChampionDTO>)obj;
            }
            else if (obj is LoginDataPacket)
            {
                SelfSummoner = ((LoginDataPacket)obj).AllSummonerData.Summoner;
            }
        }
		void LobbyRead(GameDTO lobby)
		{
			Task.Factory.StartNew(() => CommitLobby(lobby), TaskCreationOptions.LongRunning);
		}
Beispiel #6
0
        void Reader_ObjectRead(object obj)
        {
            if (obj is GameDTO)
            {
                CurrentGame = (GameDTO)obj;

                List<GgPlayer> team1 = new List<GgPlayer>();

                foreach (PlayerParticipant p in CurrentGame.TeamOne)
                {
                    team1.Add(new GgPlayer() { Name = p.Name, SummonerId = p.SummonerId, AccountId = p.AccountId });
                }

                UpdateTeam(team1, 1);

                List<GgPlayer> team2 = new List<GgPlayer>();

                foreach (PlayerParticipant p in CurrentGame.TeamTwo)
                {
                    team2.Add(new GgPlayer() { Name = p.Name, SummonerId = p.SummonerId, AccountId = p.AccountId });
                }

                UpdateTeam(team2, 2);

                UpdateMap(CurrentGame.MapId);
            }
            else if (obj is EndOfGameStats)
            {
                return;
            }
            else if (obj is List<ChampionDTO>)
            {
                Champions = (List<ChampionDTO>)obj;
            }
            else if (obj is LoginDataPacket)
            {
                SelfSummoner = ((LoginDataPacket)obj).AllSummonerData.Summoner;
            }
        }