Beispiel #1
0
        /// <summary>
        /// Adds a new player to the database chat list
        /// </summary>
        public void newPlayer(Zone.Player player)
        {
            if (player == null)
            {
                Log.write(TLog.Error, "Chat.newPlayer(): Called with null player.");
                return;
            }

            if (hasPlayer(player))
            {
                Log.write(TLog.Warning, "Player '{0}' already exists in chat '{1}'.", player, _name);
                return;
            }

            _players.Add(player);
            player.chats.Add(_name);

            SC_JoinChat <Zone> join = new SC_JoinChat <Zone>();

            join.from  = player.alias;
            join.chat  = _name;
            join.users = List();

            foreach (Zone z in _server._zones)
            {
                if (z == null)
                {
                    continue;
                }

                z._client.send(join);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Removes a player from the database chat list
        /// </summary>
        public void lostPlayer(Zone.Player player)
        {
            if (!_players.Remove(player))
            {
                Log.write(TLog.Warning, "Lost player '{0}' that wasn't in chat '{1}'.", player, _name);
                return;
            }

            SC_LeaveChat <Zone> leave = new SC_LeaveChat <Zone>();

            leave.from  = player.alias;
            leave.chat  = _name;
            leave.users = List();

            foreach (Zone z in _server._zones)
            {
                if (z == null)
                {
                    continue;
                }

                z._client.send(leave);
            }

            //Do we still have a raison d'etre?
            if (_players.Count() == 0)
            {
                //Abandon ourselves to die
                if (!_server._chats.Remove(_name))
                {
                    Log.write(TLog.Error, "Attempted to remove chat '{0}' not present in chats list.", _name);
                    return;
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Does this chat have a specific player?
        /// </summary>
        /// <returns>Returns true if found</returns>
        public bool hasPlayer(Zone.Player player)
        {
            if (player == null)
            {
                return(false);
            }

            return(_players.Contains(player));
        }
Beispiel #4
0
        public void lostPlayer(Zone.Player player)
        {
            if (player == null)
            {
                Log.write(TLog.Error, "DBServer.lostPlayer(): Called with null player.");
                return;
            }

            //Remove him from any chats
            foreach (Chat c in _chats.Values.ToList())
            {
                if (c == null)
                {
                    continue;
                }

                if (c.hasPlayer(player))
                {
                    c.lostPlayer(player);
                }
            }

            //Remove him from the DB server master player list
            if (!_players.Remove(player.alias))
            {
                if (_players.ContainsValue(player))
                {
                    Log.write(TLog.Error, "Failed removing player '{0}' by name.", player.alias);
                }
                else
                {
                    Log.write(TLog.Error, "Lost player not in the list '{0}'.", player.alias);
                }

                return;
            }
        }
Beispiel #5
0
        public bool newPlayer(Zone.Player player)
        {
            if (player == null)
            {
                Log.write(TLog.Error, "DBServer.newPlayer(): Called with null player.");
                return(false);
            }
            if (String.IsNullOrWhiteSpace(player.alias))
            {
                Log.write(TLog.Error, "DBServer.newPlayer(): Player has no alias.");
                return(false);
            }
            if (_players.ContainsValue(player))
            {
                Log.write(TLog.Error, "DBServer.newPlayer(): Player for '{0}' is already present.", player.alias);
                return(false);
            }

            //Give it a go
            try
            {
                _players.Add(player.alias, player);
            }
            catch
            {
                Log.write(TLog.Error, "DBServer.newPlayer(): Key '{0}' already exists.", player.alias);
                return(false);
            }

            if (_players.Count() > playerPeak)
            {
                playerPeak = _players.Count();
            }

            return(true);
        }