Пример #1
0
 protected virtual void OnPlayerUpdate(PlayerEntry player)
 {
     if (PlayerUpdate != null)
     {
         PlayerUpdate(player);
     }
 }
Пример #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);
        }
Пример #3
0
		public EditPlayerForm(PlayerEntry entry)
			: this()
		{
			if (entry == null)
				return;
			NoteText.Text = entry.Note ?? "";
			ColorBox.SelectedIndex = ColorBox.Items.IndexOf(entry.NoteColor.ToKnownColor().ToString());
		}
Пример #4
0
        /// <summary>
        /// Records/Commits the player to the database. Locking the database lock.
        /// </summary>
        /// <param name="entry">Player to record</param>
        /// <returns>The PlayerEntry from the database</returns>
        public void CommitPlayer(PlayerEntry entry)
        {
            Stopwatch sw;

            lock (DatabaseLock)
            {
                sw = Stopwatch.StartNew();

                RecordPlayer(entry, true);
                Database.Commit();
            }
            sw.Stop();
            StaticLogger.Debug(string.Format("PlayerEntry committed in {0}ms", sw.ElapsedMilliseconds));
        }
Пример #5
0
        /// <summary>
        /// Checks the database for the player and if it does not exist then it adds it.
        /// Does not lock the database or commit
        /// </summary>
        /// <param name="entry">Player to record</param>
        /// <param name="overwrite">Overwrite an existing entry</param>
        /// <returns>Returns true if the player was recorded, otherwise false</returns>
        public bool RecordPlayer(PlayerEntry entry, bool overwrite)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            lock (_lobbycache)
            {
                //Return if the player has been cached and we are not overwriting.
                if (_lobbycache.Find(p => p.Id == entry.Id) != null && !overwrite)
                {
                    return(false);
                }
            }

            var match = Database.Query <PlayerEntry>().FirstOrDefault(m => m.Id == entry.Id);

            if (match == null || overwrite)
            {
                entry = entry.CloneT();

                if (match != null)
                {
                    Database.Delete(match);
                }
                Database.Store(entry);

                lock (_lobbycache)
                {
                    var idx = _lobbycache.FindIndex(p => p.Id == entry.Id);
                    if (idx != -1)
                    {
                        _lobbycache[idx] = entry;
                    }
                    else
                    {
                        _lobbycache.Add(entry);
                    }
                }
            }
            else
            {
                return(false);
            }
            OnPlayerUpdate(entry);
            return(true);
        }
Пример #6
0
 void SetTitle(PlayerEntry ply)
 {
     SetName(ply.Name);
     NameLabel.Links.Add(0, ply.Name.Length, Tuple.Create(ply.Id, ply.Name));
 }
Пример #7
0
        public void SetPlayer(PlayerEntry plr)
        {
            if (InvokeRequired)
            {
                Invoke(new Action<PlayerEntry>(SetPlayer), plr);
                return;
            }
            Player = plr;
            SetTitle(plr);

            RemoveAll(p => (p.Tag as string) == "Note");

            if (!string.IsNullOrWhiteSpace(plr.Note))
            {
                SuspendLayout();

                var tab = new TabPage("Note")
                {
                    Tag = "Note",
                    BackColor = this.BackColor
                };
                var lbl = new Label
                {
                    Font = new Font(Font.FontFamily, Font.SizeInPoints, FontStyle.Bold),
                    Text = plr.Note
                };
                tab.Controls.Add(lbl);
                InfoTabs.TabPages.Add(tab);

                ResumeLayout();
            }

            Invalidate(); //Forces the color change
        }
Пример #8
0
 public void SetParticipant(Participant part)
 {
     if (InvokeRequired)
     {
         Invoke(new Action<Participant>(SetParticipant), part);
         return;
     }
     Player = null;
     SetTitle(part);
 }
Пример #9
0
 public void SetEmpty()
 {
     if (InvokeRequired)
     {
         Invoke(new Action(SetEmpty));
         return;
     }
     Player = null;
     InfoTabs.TabPages.Clear();
     SetLevel(30);
     SetTeam(0);
     Invalidate(); //Force the border to redraw.
 }
Пример #10
0
 protected virtual void OnPlayerUpdate(PlayerEntry player)
 {
     if (PlayerUpdate != null)
         PlayerUpdate(player);
 }
Пример #11
0
        /// <summary>
        /// Checks the database for the player and if it does not exist then it adds it.
        /// Does not lock the database or commit
        /// </summary>
        /// <param name="entry">Player to record</param>
        /// <param name="overwrite">Overwrite an existing entry</param>
        /// <returns>Returns true if the player was recorded, otherwise false</returns>
        public bool RecordPlayer(PlayerEntry entry, bool overwrite)
        {
            if (entry == null)
                throw new ArgumentNullException("entry");

            lock (_lobbycache)
            {
                //Return if the player has been cached and we are not overwriting.
                if (_lobbycache.Find(p => p.Id == entry.Id) != null && !overwrite)
                    return false;
            }

            var match = Database.Query<PlayerEntry>().FirstOrDefault(m => m.Id == entry.Id);
            if (match == null || overwrite)
            {
                entry = entry.CloneT();

                if (match != null)
                    Database.Delete(match);
                Database.Store(entry);

                lock (_lobbycache)
                {
                    var idx = _lobbycache.FindIndex(p => p.Id == entry.Id);
                    if (idx != -1)
                    {
                        _lobbycache[idx] = entry;
                    }
                    else
                    {
                        _lobbycache.Add(entry);
                    }
                }
            }
            else
            {
                return false;
            }
            OnPlayerUpdate(entry);
            return true;
        }
Пример #12
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;
        }
Пример #13
0
        /// <summary>
        /// Records/Commits the player to the database. Locking the database lock.
        /// </summary>
        /// <param name="entry">Player to record</param>
        /// <returns>The PlayerEntry from the database</returns>
        public void CommitPlayer(PlayerEntry entry)
        {
            Stopwatch sw;
            lock (DatabaseLock)
            {
                sw = Stopwatch.StartNew();

                RecordPlayer(entry, true);
                Database.Commit();
            }
            sw.Stop();
            StaticLogger.Debug(string.Format("PlayerEntry committed in {0}ms", sw.ElapsedMilliseconds));
        }