Example #1
0
 // This constructor is used to create dummy players (such as Console and /dummy)
 // It will soon be replaced by a generic Entity class
 internal Player( World world, string name ) {
     if( name == null ) throw new ArgumentNullException( "name" );
     World = world;
     Info = new PlayerInfo( name, RankManager.HighestRank, true, RankChangeType.AutoPromoted );
     spamBlockLog = new Queue<DateTime>( Info.Rank.AntiGriefBlocks );
     ResetAllBinds();
 }
Example #2
0
 public void Create( BoundingBox bounds, PlayerInfo createdBy ) {
     if( bounds == null ) throw new ArgumentNullException( "bounds" );
     if( createdBy == null ) throw new ArgumentNullException( "createdBy" );
     CreatedDate = DateTime.UtcNow;
     Bounds = bounds;
     CreatedBy = createdBy;
 }
Example #3
0
 // This constructor is used to create dummy players (such as Console and /dummy)
 // It will soon be replaced by a generic Entity class
 internal Player( World _world, string _name )
 {
     world = _world;
     name = _name;
     nick = name;
     info = new PlayerInfo( _name, ClassList.highestClass );
 }
 /// <summary> Adds a new PlayerInfo entry for a player who has never been online, by name. </summary>
 /// <returns> A newly-created PlayerInfo entry. </returns>
 public PlayerInfo AddUnrecognizedPlayer( string name, Rank startingRank, RankChangeType rankChangeType ) {
     if( name == null ) throw new ArgumentNullException( "name" );
     if( startingRank == null ) throw new ArgumentNullException( "startingRank" );
     int id = GetNextID();
     PlayerInfo info = new PlayerInfo( id, name, startingRank, rankChangeType, false );
     trie.Add( name, info );
     return info;
 }
 /// <summary> Adds a new PlayerInfo entry for an actual, logged-in player. </summary>
 /// <returns> A newly-created PlayerInfo entry. </returns>
 public PlayerInfo AddPlayer( string name, Rank startingRank, RankChangeType rankChangeType, IPAddress address ) {
     if( name == null ) throw new ArgumentNullException( "name" );
     if( address == null ) throw new ArgumentNullException( "address" );
     int id = GetNextID();
     PlayerInfo info = new PlayerInfo( id, name, startingRank, rankChangeType, address );
     trie.Add( name, info );
     return info;
 }
Example #6
0
 // Normal constructor
 internal Player( World _world, string _name, Session _session, Position _pos ) {
     world = _world;
     name = _name;
     nick = name;
     session = _session;
     pos = _pos;
     info = world.db.FindPlayerInfo( this );
 }
Example #7
0
 public bool CanRevoke( PlayerInfo player ) {
     PermissionLimits limits = GetLimit( player );
     if( limits == null ) {
         return false;
     } else {
         return limits.CanRevoke;
     }
 }
Example #8
0
 internal static PlayerInfo AddSuperPlayer( ReservedPlayerID id, [NotNull] string name, [NotNull] Rank rank ) {
     if( name == null ) throw new ArgumentNullException( "name" );
     CheckIfLoaded();
     PlayerInfo newInfo = new PlayerInfo( (int)id, name, rank, RankChangeType.AutoPromoted, true ) {
         RaisePropertyChangedEvents = true
     };
     return newInfo;
 }
Example #9
0
 // Throws a PlayerOpException if reason is required but missing.
 internal static void CheckKickReason( [CanBeNull] string reason, [NotNull] Player player, PlayerInfo targetInfo ) {
     if( player == null ) throw new ArgumentNullException( "player" );
     if( ConfigKey.RequireKickReason.Enabled() && String.IsNullOrEmpty( reason ) ) {
         const string msg = "Please specify a kick reason.";
         const string colorMsg = "&S" + msg;
         throw new PlayerOpException( player, targetInfo, PlayerOpExceptionCode.ReasonRequired, msg, colorMsg );
     }
 }
Example #10
0
 // Normal constructor
 internal Player( World world, string name, Session session, Position position ) {
     if( name == null ) throw new ArgumentNullException( "name" );
     if( session == null ) throw new ArgumentNullException( "session" );
     World = world;
     Session = session;
     Position = position;
     Info = PlayerDB.FindOrCreateInfoForPlayer( name, session.IP );
     spamBlockLog = new Queue<DateTime>( Info.Rank.AntiGriefBlocks );
     ResetAllBinds();
 }
Example #11
0
 PermissionLimits GetPlayerLimit( PlayerInfo player ) {
     PermissionLimits limiter;
     if( playerInclusions.TryGetValue( player.Name, out limiter ) ) {
         return limiter;
     } else if( Parent != null ) {
         return Parent.GetPlayerLimit( player );
     } else {
         return null;
     }
 }
Example #12
0
 public bool Can( PlayerInfo player, int quantity ) {
     if( ( Node.Flags & PermissionFlags.NeedsQuantity ) == 0 ) {
         throw new PermissionCheckException( "Quantity limit is not applicable to " + Node.Name );
     }
     PermissionLimits limits = GetLimit( player );
     if( limits == null ) {
         return false;
     } else {
         return ( limits.MaxQuantity <= quantity );
     }
 }
Example #13
0
 //Function to format and return a player's score entry. Returns null if no score found
 public static String GetPlayerScoreEntry( PlayerInfo player )
 {
     string toReturn = null;
     foreach ( String s in PlayerKillScores ) {
         if ( s.Contains( '$' ) ) {
             if ( s.Split( '$' )[0] == player.Name ) {
                 toReturn = s;
             }
         }
     }
     return toReturn;
 }
Example #14
0
 public PlayerOpException( [NotNull] Player player, PlayerInfo target,
                           PlayerOpExceptionCode errorCode,
                           [NotNull] string message, [NotNull] string messageColored )
     : base( message ) {
     if( player == null ) throw new ArgumentNullException( "player" );
     if( message == null ) throw new ArgumentNullException( "message" );
     if( messageColored == null ) throw new ArgumentNullException( "messageColored" );
     Player = player;
     Target = target;
     ErrorCode = errorCode;
     MessageColored = messageColored;
 }
Example #15
0
 // Throws a PlayerOpException if reason is required but missing.
 internal static void CheckRankChangeReason( [CanBeNull] string reason, [NotNull] Player player, PlayerInfo targetInfo, bool promoting ) {
     if( player == null ) throw new ArgumentNullException( "player" );
     if( ConfigKey.RequireRankChangeReason.Enabled() && String.IsNullOrEmpty( reason ) ) {
         string msg;
         if( promoting ) {
             msg = "Please specify a promotion reason.";
         } else {
             msg = "Please specify a demotion reason.";
         }
         string colorMsg = "&S" + msg;
         throw new PlayerOpException( player, targetInfo, PlayerOpExceptionCode.ReasonRequired, msg, colorMsg );
     }
 }
Example #16
0
 public PlayerInfo FindPlayerInfo( Player player ) {
     if( player == null ) return null;
     
     locker.EnterWriteLock();
     PlayerInfo info = tree.Get( player.name );
     if( info == null ) {
         info = new PlayerInfo( world, player );
         tree.Add( player.name, info );
         list.Add( info );
     }
     locker.ExitWriteLock();
     return info;
 }
Example #17
0
        public static bool FindPlayerInfo( string name, out PlayerInfo info )
        {
            if( name == null ) {
                info = null;
                return false;
            }

            bool noDupe;
            locker.EnterWriteLock();
            noDupe = tree.Get( name, out info );
            locker.ExitWriteLock();

            return noDupe;
        }
Example #18
0
 // returns the PREVIOUS state of the player
 public PermissionOverride Include( PlayerInfo info ) {
     if( info == null ) throw new ArgumentNullException( "info" );
     lock( playerPermissionListLock ) {
         if( includedPlayers.ContainsValue( info ) ) {
             UpdatePlayerListCache();
             return PermissionOverride.Allow;
         } else if( excludedPlayers.ContainsValue( info ) ) {
             excludedPlayers.Remove( info.Name.ToLower() );
             UpdatePlayerListCache();
             return PermissionOverride.Deny;
         } else {
             includedPlayers.Add( info.Name.ToLower(), info );
             UpdatePlayerListCache();
             return PermissionOverride.None;
         }
     }
 }
Example #19
0
 // Adds a name to the tree.
 public bool Add( string name, PlayerInfo payload ) {
     StringNode temp = root;
     int code;
     for( int i = 0; i < name.Length; i++ ) {
         code = CharCode( name[i] );
         if( temp.children[code] == null ) {
             temp.children[code] = new StringNode();
         }
         if( temp.tag == EMPTY ) {
             temp.tag = (byte)code;
         } else {
             temp.tag = MULTI;
         }
         temp = temp.children[code];
     }
     if( temp.payload != null )
         return false;
     temp.payload = payload;
     count++;
     return true;
 }
Example #20
0
        public static PlayerInfo AddFakeEntry( string name, RankChangeType rankChangeType ) {
            if( name == null ) throw new ArgumentNullException( "name" );

            PlayerInfo info;
            lock( AddLocker ) {
                info = Trie.Get( name );
                if( info != null ) throw new ArgumentException( "A PlayerDB entry already exists for this name." );

                var e = new PlayerInfoCreatingEventArgs( name, IPAddress.None, RankManager.DefaultRank, true );
                Server.RaisePlayerInfoCreatingEvent( e );
                if( e.Cancel ) throw new OperationCanceledException( "Cancelled by a plugin." );

                info = new PlayerInfo( name, e.StartingRank, false, rankChangeType );

                List.Add( info );
                Trie.Add( info.Name, info );
                UpdateCache();
            }
            Server.RaisePlayerInfoCreatedEvent( info, false );
            return info;
        }
Example #21
0
        // Searches for players starting with namePart.
        //     Returns false if more than one name matched.
        //     Returns true and sets info to null if no names matched.
        public bool Get( string namePart, out PlayerInfo info ) {
            StringNode temp = root;
            int code;
            for( int i = 0; i < namePart.Length; i++ ) {
                code = CharCode( namePart[i] );
                if( temp.children[code] == null ) {
                    info = null;
                    return true; // early detection of no matches
                }
                temp = temp.children[code];
            }

            if( temp.payload != null ) {
                info = temp.payload;
                return true; // exact match
            } else if( temp.tag == MULTI ) {
                info = null;
                return false; // multiple matches
            }
            for( ; temp.tag < MULTI; temp = temp.children[temp.tag] ) ;
            info = temp.payload;
            return true; // one autocompleted match
        }
Example #22
0
 public void Load() {
     if( File.Exists( FileName ) ) {
         using( StreamReader reader = File.OpenText( FileName ) ) {
             reader.ReadLine(); // header
             while( !reader.EndOfStream ) {
                 string[] fields = reader.ReadLine().Split( ',' );
                 if( fields.Length == PlayerInfo.fieldCount ) {
                     try {
                         PlayerInfo info = new PlayerInfo(world, fields );
                         tree.Add( info.name, info );
                         list.Add( info );
                     } catch( FormatException ex ) {
                         world.log.Log( "PlayerDB.Load: Could not parse a record: {0}.", LogType.Error, ex.Message );
                     } catch( IOException ex ) {
                         world.log.Log( "PlayerDB.Load: Error while trying to read from file: {0}.", LogType.Error, ex.Message );
                     }
                 }
             }
         }
         world.log.Log( "PlayerDB.Load: Done loading player DB ({0} records).", LogType.Debug, tree.Count() );
     } else {
         world.log.Log( "PlayerDB.Load: No player DB file found.", LogType.Warning );
     }
 }
Example #23
0
 // warn player if others are still online from target's IP
 static void WarnIfOtherPlayersOnIP( Player player, PlayerInfo targetInfo, Player except ) {
     Player[] otherPlayers = Server.Players.FromIP( targetInfo.LastIP )
                                           .Except( except )
                                           .ToArray();
     if( otherPlayers.Length > 0 ) {
         player.Message( "&WWarning: Other player(s) share IP with {0}&W: {1}",
                         targetInfo.ClassyName,
                         otherPlayers.JoinToClassyString() );
     }
 }
Example #24
0
 // freeze target if player is allowed to do so
 static void FreezeIfAllowed( Player player, PlayerInfo targetInfo ) {
     if( targetInfo.IsOnline && !targetInfo.IsFrozen && player.Can( Permission.Freeze, targetInfo.Rank ) ) {
         try {
             targetInfo.Freeze( player, true, true );
             player.Message( "Player {0}&S has been frozen while you retry.", targetInfo.ClassyName );
         } catch( PlayerOpException ) { }
     }
 }
Example #25
0
 public bool Unignore( PlayerInfo other ) {
     lock( ignoreLock ) {
         if( ignoreList.Contains( other ) ) {
             ignoreList.Remove( other );
             return true;
         } else {
             return false;
         }
     }
 }
Example #26
0
 public bool Ignore( PlayerInfo other ) {
     lock( ignoreLock ) {
         if( !ignoreList.Contains( other ) ) {
             ignoreList.Add( other );
             return true;
         } else {
             return false;
         }
     }
 }
Example #27
0
 public bool IsIgnoring( PlayerInfo other ) {
     lock( ignoreLock ) {
         return ignoreList.Contains( other );
     }
 }
Example #28
0
 public void Edit( PlayerInfo editedBy ) {
     if( editedBy == null ) throw new ArgumentNullException( "editedBy" );
     EditedDate = DateTime.UtcNow;
     EditedBy = editedBy;
 }
Example #29
0
        public Zone( string raw, World world ) {
            string[] parts = raw.Split( ',' );

            string[] header = parts[0].Split( ' ' );
            Name = header[0];
            Bounds = new BoundingBox( Int32.Parse( header[1] ), Int32.Parse( header[2] ), Int32.Parse( header[3] ),
                                      Int32.Parse( header[4] ), Int32.Parse( header[5] ), Int32.Parse( header[6] ) );

            Rank buildRank = RankManager.ParseRank( header[7] );
            // if all else fails, fall back to lowest class
            if( buildRank == null ) {
                if( world != null ) {
                    Controller.MinRank = world.BuildSecurity.MinRank;
                } else {
                    Controller.MinRank = null;
                }
                Logger.Log( "Zone: Error parsing zone definition: unknown rank \"{0}\". Permission reset to default ({1}).", LogType.Error,
                            header[7], Controller.MinRank.Name );
            } else {
                Controller.MinRank = buildRank;
            }


            // Part 2:
            foreach( string player in parts[1].Split( ' ' ) ) {
                if( !Player.IsValidName( player ) ) continue;
                PlayerInfo info = PlayerDB.FindPlayerInfoExact( player );
                if( info == null ) continue; // player name not found in the DB (discarded)
                Controller.Include( info );
            }

            // Part 3: excluded list
            foreach( string player in parts[2].Split( ' ' ) ) {
                if( !Player.IsValidName( player ) ) continue;
                PlayerInfo info = PlayerDB.FindPlayerInfoExact( player );
                if( info == null ) continue; // player name not found in the DB (discarded)
                Controller.Exclude( info );
            }

            Controller.UpdatePlayerListCache();

            // Part 4: extended header
            if( parts.Length > 3 ) {
                string[] xheader = parts[3].Split( ' ' );
                CreatedBy = PlayerDB.FindPlayerInfoExact( xheader[0] );
                if( CreatedBy != null ) CreatedDate = DateTime.Parse( xheader[1] );
                EditedBy = PlayerDB.FindPlayerInfoExact( xheader[2] );
                if( EditedBy != null ) EditedDate = DateTime.Parse( xheader[3] );
            }
        }
 public static void Untempban(Player player, PlayerInfo target)
 {
     if (!target.IsBanned) return;
     else
         target.Unban(player, "Tempban Expired", true, true);
 }