Esempio n. 1
0
 internal PlayerInfoRankChangingEventArgs([NotNull] PlayerInfo playerInfo, [NotNull] Player rankChanger,
                                          [NotNull] Rank newRank, [CanBeNull] string reason,
                                          RankChangeType rankChangeType, bool announce)
     : base(playerInfo, rankChanger, playerInfo.Rank, reason, rankChangeType, announce)
 {
     NewRank = newRank;
 }
Esempio n. 2
0
        /// <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");
            }
            using (PlayerDB.GetWriteLock()) {
                using (MySqlTransaction transaction = connection.BeginTransaction()) {
                    preInsertCommand.Transaction = transaction;
                    preInsertCommand.ExecuteNonQuery();
                    int id = (int)preInsertCommand.InsertId;

                    PlayerInfo info = new PlayerInfo(id, name, startingRank, rankChangeType, false);

                    MySqlCommand updateCmd = GetUpdateCommand(info);
                    updateCmd.Transaction = transaction;
                    updateCmd.ExecuteNonQuery();

                    transaction.Commit();

                    preInsertCommand.Transaction = null;
                    updateCmd.Transaction        = null;
                    return(info);
                }
            }
        }
Esempio n. 3
0
        public static PlayerInfo AddUnrecognizedPlayer( [NotNull] string name, RankChangeType rankChangeType ) {
            if( name == null ) throw new ArgumentNullException( "name" );
            CheckIfLoaded();

            PlayerInfo newInfo;
            using( GetWriteLock() ) {
                newInfo = provider.FindExact( name );
                if( newInfo != null ) {
                    throw new ArgumentException( "A PlayerDB entry already exists for this name.", "name" );
                }

                var e = new PlayerInfoBeingCreatedEventArgs( name, IPAddress.None, RankManager.DefaultRank, true );
                PlayerInfo.RaiseBeingCreatedEvent( e );
                if( e.Cancel ) {
                    throw new OperationCanceledException( "Canceled by a plugin." );
                }

                newInfo = provider.AddUnrecognizedPlayer( name, e.StartingRank, rankChangeType );
                newInfo.RaisePropertyChangedEvents = true;

                List.Add( newInfo );
            }
            PlayerInfo.RaiseCreatedEvent( newInfo, false );
            return newInfo;
        }
Esempio n. 4
0
 void GuessRankChangeType()
 {
     if (PreviousRank != null)
     {
         if (RankChangeReason == "~AutoRank" || RankChangeReason == "~AutoRankAll" || RankChangeReason == "~MassRank")
         {
             if (PreviousRank > Rank)
             {
                 RankChangeType = RankChangeType.AutoDemoted;
             }
             else if (PreviousRank < Rank)
             {
                 RankChangeType = RankChangeType.AutoPromoted;
             }
         }
         else
         {
             if (PreviousRank > Rank)
             {
                 RankChangeType = RankChangeType.Demoted;
             }
             else if (PreviousRank < Rank)
             {
                 RankChangeType = RankChangeType.Promoted;
             }
         }
     }
     else
     {
         RankChangeType = RankChangeType.Default;
     }
 }
Esempio n. 5
0
 internal PlayerInfoRankChangingEventArgs([NotNull] PlayerInfo target, [NotNull] Player rankChanger,
                                          [NotNull] Rank newRank, [CanBeNull] string reason,
                                          RankChangeType rankChangeType, bool announce)
 {
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     if (rankChanger == null)
     {
         throw new ArgumentNullException("rankChanger");
     }
     if (newRank == null)
     {
         throw new ArgumentNullException("newRank");
     }
     PlayerInfo     = target;
     RankChanger    = rankChanger;
     OldRank        = target.Rank;
     NewRank        = newRank;
     Reason         = reason;
     RankChangeType = rankChangeType;
     Announce       = announce;
     NewRank        = newRank;
 }
Esempio n. 6
0
        public static PlayerInfo AddFakeEntry([NotNull] string name, RankChangeType rankChangeType)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            CheckIfLoaded();

            PlayerInfo info;

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

                var e = new PlayerInfoCreatingEventArgs(name, IPAddress.None, RankManager.DefaultRank, true);
                PlayerInfo.RaiseCreatingEvent(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();
            }
            PlayerInfo.RaiseCreatedEvent(info, false);
            return(info);
        }
Esempio n. 7
0
 /// <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;
 }
Esempio n. 8
0
 public ConditionRankChangeType([NotNull] XElement el)
 {
     if (el == null)
     {
         throw new ArgumentNullException("el");
     }
     Type = (RankChangeType)Enum.Parse(typeof(RankChangeType), el.Attribute("val").Value, true);
 }
Esempio n. 9
0
 static bool RaiseRankChangingEvent( [NotNull] PlayerInfo playerInfo, [NotNull] Player rankChanger, [NotNull] Rank newRank,
                                     [CanBeNull] string reason, RankChangeType rankChangeType, bool announce ) {
     var h = RankChanging;
     if( h == null ) return false;
     var e = new PlayerInfoRankChangingEventArgs( playerInfo, rankChanger, newRank, reason, rankChangeType, announce );
     h( null, e );
     return e.Cancel;
 }
Esempio n. 10
0
 /// <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;
 }
Esempio n. 11
0
 public PlayerInfoRankChangedEventArgs(PlayerInfo playerInfo, Player rankChanger, Rank oldRank, string reason, RankChangeType rankChangeType)
     : base(playerInfo)
 {
     RankChanger    = rankChanger;
     OldRank        = oldRank;
     NewRank        = playerInfo.Rank;
     Reason         = reason;
     RankChangeType = rankChangeType;
 }
Esempio n. 12
0
 public void ProcessRankChange(Rank newRank, Player changer, string reason, RankChangeType type)
 {
     PreviousRank     = Rank;
     Rank             = newRank;
     RankChangeDate   = DateTime.UtcNow;
     RankChangedBy    = changer.Name;
     RankChangeReason = reason;
     RankChangeType   = type;
 }
Esempio n. 13
0
 public ConditionRankChangeType([NotNull] XElement el)
 {
     if (el == null)
     {
         throw new ArgumentNullException("el");
     }
     // ReSharper disable PossibleNullReferenceException
     Type = (RankChangeType)Enum.Parse(typeof(RankChangeType), el.Attribute("val").Value, true);
     // ReSharper restore PossibleNullReferenceException
 }
Esempio n. 14
0
        static void RaiseRankChangedEvent([NotNull] PlayerInfo playerInfo, [NotNull] Player rankChanger, [NotNull] Rank oldRank,
                                          [CanBeNull] string reason, RankChangeType rankChangeType, bool announce)
        {
            var h = RankChanged;

            if (h != null)
            {
                h(null, new PlayerInfoRankChangedEventArgs(playerInfo, rankChanger, oldRank, reason, rankChangeType, announce));
            }
        }
Esempio n. 15
0
 static void RaiseRankChangedEvent([NotNull] PlayerInfo playerInfo, [NotNull] Player rankChanger,
                                   [NotNull] Rank oldRank,
                                   [CanBeNull] string reason, RankChangeType rankChangeType, bool announce) {
     var h = RankChanged;
     if (h != null)
         h(null,
           new PlayerInfoRankChangedEventArgs(playerInfo,
                                              rankChanger,
                                              oldRank,
                                              reason,
                                              rankChangeType,
                                              announce));
 }
Esempio n. 16
0
 // fabricate info for an unrecognized player
 public PlayerInfo(string name, Rank rank, bool setLoginDate, RankChangeType rankChangeType)
     : this()
 {
     Name = name;
     Rank = rank;
     if (setLoginDate)
     {
         FirstLoginDate = DateTime.UtcNow;
         LastLoginDate  = FirstLoginDate;
         LastSeen       = FirstLoginDate;
         TimesVisited   = 1;
     }
     RankChangeType = rankChangeType;
 }
Esempio n. 17
0
        static bool RaiseRankChangingEvent([NotNull] PlayerInfo playerInfo, [NotNull] Player rankChanger, [NotNull] Rank newRank,
                                           [CanBeNull] string reason, RankChangeType rankChangeType, bool announce)
        {
            var h = RankChanging;

            if (h == null)
            {
                return(false);
            }
            var e = new PlayerInfoRankChangingEventArgs(playerInfo, rankChanger, newRank, reason, rankChangeType, announce);

            h(null, e);
            return(e.Cancel);
        }
        /// <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);
        }
Esempio n. 20
0
 // create a record for an unrecognized or a super player
 public PlayerInfo(int id, [NotNull] string name, [NotNull] Rank startingRank,
                   RankChangeType rankChangeType, bool isSuper)
     : this( id ) {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (startingRank == null)
     {
         throw new ArgumentNullException("startingRank");
     }
     this.name           = name;
     rank                = startingRank;
     this.rankChangeType = rankChangeType;
     LastModified        = DateTime.UtcNow;
     IsSuper             = isSuper;
 }
Esempio n. 21
0
        public void ProcessRankChange([NotNull] Rank newRank, [NotNull] string changer, [CanBeNull] string reason, RankChangeType type)
        {
            if (newRank == null)
            {
                throw new ArgumentNullException("newRank");
            }
            if (changer == null)
            {
                throw new ArgumentNullException("changer");
            }
            PreviousRank   = Rank;
            Rank           = newRank;
            RankChangeDate = DateTime.UtcNow;

            RankChangedBy    = changer;
            RankChangeReason = reason;
            RankChangeType   = type;
            LastModified     = DateTime.UtcNow;
        }
Esempio n. 22
0
 internal PlayerInfoRankChangedEventArgs([NotNull] PlayerInfo playerInfo, [NotNull] Player rankChanger,
                                         [NotNull] Rank oldRank, [CanBeNull] string reason,
                                         RankChangeType rankChangeType, bool announce)
     : base(playerInfo)
 {
     if (rankChanger == null)
     {
         throw new ArgumentNullException("rankChanger");
     }
     if (oldRank == null)
     {
         throw new ArgumentNullException("oldRank");
     }
     RankChanger    = rankChanger;
     OldRank        = oldRank;
     NewRank        = playerInfo.Rank;
     Reason         = reason;
     RankChangeType = rankChangeType;
     Announce       = announce;
 }
Esempio n. 23
0
 PlayerInfo()
 {
     // reset everything to defaults
     LastIP              = IPAddress.None;
     RankChangeDate      = DateTime.MinValue;
     BanDate             = DateTime.MinValue;
     UnbanDate           = DateTime.MinValue;
     LastFailedLoginDate = DateTime.MinValue;
     FirstLoginDate      = DateTime.MinValue;
     LastLoginDate       = DateTime.MinValue;
     TotalTime           = TimeSpan.Zero;
     RankChangeType      = RankChangeType.Default;
     LastKickDate        = DateTime.MinValue;
     LastSeen            = DateTime.MinValue;
     BannedUntil         = DateTime.MinValue;
     FrozenOn            = DateTime.MinValue;
     MutedUntil          = DateTime.MinValue;
     BandwidthUseMode    = BandwidthUseMode.Default;
     LastModified        = DateTime.UtcNow;
 }
Esempio n. 24
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;
        }
Esempio n. 25
0
        /// <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" );
            using( PlayerDB.GetWriteLock() ) {
                using( MySqlTransaction transaction = connection.BeginTransaction() ) {
                    preInsertCommand.Transaction = transaction;
                    preInsertCommand.ExecuteNonQuery();
                    int id = (int)preInsertCommand.InsertId;

                    PlayerInfo info = new PlayerInfo( id, name, startingRank, rankChangeType, false );

                    MySqlCommand updateCmd = GetUpdateCommand( info );
                    updateCmd.Transaction = transaction;
                    updateCmd.ExecuteNonQuery();

                    transaction.Commit();

                    preInsertCommand.Transaction = null;
                    updateCmd.Transaction = null;
                    return info;
                }
            }
        }
Esempio n. 26
0
 // fabricate info for an unrecognized player
 public PlayerInfo([NotNull] string name, [NotNull] Rank rank,
                   bool setLoginDate, RankChangeType rankChangeType)
     : this()
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (rank == null)
     {
         throw new ArgumentNullException("rank");
     }
     Name = name;
     Rank = rank;
     if (setLoginDate)
     {
         FirstLoginDate = DateTime.UtcNow;
         LastLoginDate  = FirstLoginDate;
         LastSeen       = FirstLoginDate;
         TimesVisited   = 1;
     }
     RankChangeType = rankChangeType;
 }
Esempio n. 27
0
 // create a record for a newly logged-in player
 public PlayerInfo(int id, [NotNull] string name, [NotNull] Rank startingRank,
                   RankChangeType rankChangeType, [NotNull] IPAddress address)
     : this( id ) {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (startingRank == null)
     {
         throw new ArgumentNullException("startingRank");
     }
     if (address == null)
     {
         throw new ArgumentNullException("address");
     }
     this.name           = name;
     rank                = startingRank;
     this.rankChangeType = rankChangeType;
     lastIP              = address;
     firstLoginDate      = DateTime.UtcNow;
     lastSeen            = DateTime.UtcNow;
     lastLoginDate       = DateTime.UtcNow;
     LastModified        = DateTime.UtcNow;
 }
Esempio n. 28
0
 internal static bool RaisePlayerInfoRankChangingEvent( PlayerInfo playerInfo, Player rankChanger, Rank newRank, string reason, RankChangeType rankChangeType ) {
     var h = PlayerInfoRankChanging;
     if( h == null ) return false;
     var e = new PlayerInfoRankChangingEventArgs( playerInfo, rankChanger, newRank, reason, rankChangeType );
     h( null, e );
     return e.Cancel;
 }
Esempio n. 29
0
 internal static void RaisePlayerInfoRankChangedEvent( PlayerInfo playerInfo, Player rankChanger, Rank oldRank, string reason, RankChangeType rankChangeType ) {
     var h = PlayerInfoRankChanged;
     if( h != null ) h( null, new PlayerInfoRankChangedEventArgs( playerInfo, rankChanger, oldRank, reason, rankChangeType ) );
 }
Esempio n. 30
0
 // fabricate info for an unrecognized player
 public PlayerInfo( string name, Rank rank, bool setLoginDate, RankChangeType rankChangeType )
     : this() {
     Name = name;
     Rank = rank;
     if( setLoginDate ) {
         FirstLoginDate = DateTime.UtcNow;
         LastLoginDate = FirstLoginDate;
         LastSeen = FirstLoginDate;
         TimesVisited = 1;
     }
     RankChangeType = rankChangeType;
 }
Esempio n. 31
0
 public PlayerInfoRankChangingEventArgs(PlayerInfo playerInfo, Player rankChanger, Rank newRank, string reason, RankChangeType rankChangeType)
     : base(playerInfo, rankChanger, playerInfo.Rank, reason, rankChangeType)
 {
     NewRank = newRank;
 }
Esempio n. 32
0
 public void ProcessRankChange( Rank newRank, Player changer, string reason, RankChangeType type ) {
     PreviousRank = Rank;
     Rank = newRank;
     RankChangeDate = DateTime.UtcNow;
     RankChangedBy = changer.Name;
     RankChangeReason = reason;
     RankChangeType = type;
 }
Esempio n. 33
0
 public ConditionRankChangeType(RankChangeType type)
 {
     Type = type;
 }
Esempio n. 34
0
 public ConditionRankChangeType( RankChangeType type )
 {
     Type = type;
 }
Esempio n. 35
0
 PlayerInfo() {
     // reset everything to defaults
     LastIP = IPAddress.None;
     RankChangeDate = DateTime.MinValue;
     BanDate = DateTime.MinValue;
     UnbanDate = DateTime.MinValue;
     LastFailedLoginDate = DateTime.MinValue;
     LastFailedLoginIP = IPAddress.None;
     FirstLoginDate = DateTime.MinValue;
     LastLoginDate = DateTime.MinValue;
     TotalTime = TimeSpan.Zero;
     RankChangeType = RankChangeType.Default;
     LastKickDate = DateTime.MinValue;
     LastSeen = DateTime.MinValue;
     BannedUntil = DateTime.MinValue;
     FrozenOn = DateTime.MinValue;
     MutedUntil = DateTime.MinValue;
     BandwidthUseMode = BandwidthUseMode.Default;
 }
Esempio n. 36
0
 internal PlayerInfoRankChangedEventArgs( [NotNull] PlayerInfo target, [NotNull] Player rankChanger,
                                          [NotNull] Rank oldRank, [CanBeNull] string reason,
                                          RankChangeType rankChangeType, bool announce ) {
     if( target == null ) throw new ArgumentNullException( "target" );
     if( rankChanger == null ) throw new ArgumentNullException( "rankChanger" );
     if( oldRank == null ) throw new ArgumentNullException( "oldRank" );
     PlayerInfo = target;
     RankChanger = rankChanger;
     OldRank = oldRank;
     NewRank = target.Rank;
     Reason = reason;
     RankChangeType = rankChangeType;
     Announce = announce;
 }
Esempio n. 37
0
 void GuessRankChangeType() {
     if( PreviousRank != null ) {
         if( RankChangeReason == "~AutoRank" || RankChangeReason == "~AutoRankAll" || RankChangeReason == "~MassRank" ) {
             if( PreviousRank > Rank ) {
                 RankChangeType = RankChangeType.AutoDemoted;
             } else if( PreviousRank < Rank ) {
                 RankChangeType = RankChangeType.AutoPromoted;
             }
         } else {
             if( PreviousRank > Rank ) {
                 RankChangeType = RankChangeType.Demoted;
             } else if( PreviousRank < Rank ) {
                 RankChangeType = RankChangeType.Promoted;
             }
         }
     } else {
         RankChangeType = RankChangeType.Default;
     }
 }
Esempio n. 38
0
 public ConditionRankChangeType( [NotNull] XElement el ) {
     if( el == null ) throw new ArgumentNullException( "el" );
     Type = (RankChangeType)Enum.Parse( typeof( RankChangeType ), el.Attribute( "val" ).Value, true );
 }
Esempio n. 39
0
        internal static void RaisePlayerInfoRankChangedEvent(PlayerInfo playerInfo, Player rankChanger, Rank oldRank, string reason, RankChangeType rankChangeType)
        {
            var h = PlayerInfoRankChanged;

            if (h != null)
            {
                h(null, new PlayerInfoRankChangedEventArgs(playerInfo, rankChanger, oldRank, reason, rankChangeType));
            }
        }
Esempio n. 40
0
 internal PlayerInfoRankChangingEventArgs( [NotNull] PlayerInfo playerInfo, [NotNull] Player rankChanger,
                                           [NotNull] Rank newRank, [CanBeNull] string reason,
                                           RankChangeType rankChangeType, bool announce )
     : base(playerInfo, rankChanger, playerInfo.Rank, reason, rankChangeType, announce)
 {
     NewRank = newRank;
 }
Esempio n. 41
0
 public ConditionRankChangeType( [NotNull] XElement el ) {
     if( el == null ) throw new ArgumentNullException( "el" );
     // ReSharper disable PossibleNullReferenceException
     Type = (RankChangeType)Enum.Parse( typeof( RankChangeType ), el.Attribute( "val" ).Value, true );
     // ReSharper restore PossibleNullReferenceException
 }
Esempio n. 42
0
 public PlayerInfoRankChangedEventArgs( PlayerInfo playerInfo, Player rankChanger, Rank oldRank, string reason, RankChangeType rankChangeType )
     :base(playerInfo){
     RankChanger=rankChanger;
     OldRank =oldRank;
     NewRank = playerInfo.Rank;
     Reason=reason;
     RankChangeType=rankChangeType;
 }
Esempio n. 43
0
        static void SetInfoHandler(Player player, CommandReader cmd)
        {
            string targetName   = cmd.Next();
            string propertyName = cmd.Next();
            string valName      = cmd.NextAll();

            if (targetName == null || propertyName == null)
            {
                CdSetInfo.PrintUsage(player);
                return;
            }

            PlayerInfo info = PlayerDB.FindByPartialNameOrPrintMatches(player, targetName);

            if (info == null)
            {
                return;
            }

            switch (propertyName.ToLower())
            {
            case "banreason":
                if (valName.Length == 0)
                {
                    valName = null;
                }
                if (SetPlayerInfoField(player, "BanReason", info, info.BanReason, valName))
                {
                    info.BanReason = valName;
                }
                break;

            case "displayedname":
                string oldDisplayedName = info.DisplayedName;
                if (valName.Length == 0)
                {
                    valName = null;
                }
                if (valName == info.DisplayedName)
                {
                    if (valName == null)
                    {
                        player.Message("SetInfo: DisplayedName for {0} is not set.",
                                       info.Name);
                    }
                    else
                    {
                        player.Message("SetInfo: DisplayedName for {0} is already set to \"{1}&S\"",
                                       info.Name,
                                       valName);
                    }
                    break;
                }
                info.DisplayedName = valName;

                if (oldDisplayedName == null)
                {
                    player.Message("SetInfo: DisplayedName for {0} set to \"{1}&S\"",
                                   info.Name,
                                   valName);
                }
                else if (valName == null)
                {
                    player.Message("SetInfo: DisplayedName for {0} was reset (was \"{1}&S\")",
                                   info.Name,
                                   oldDisplayedName);
                }
                else
                {
                    player.Message("SetInfo: DisplayedName for {0} changed from \"{1}&S\" to \"{2}&S\"",
                                   info.Name,
                                   oldDisplayedName,
                                   valName);
                }
                break;

            case "kickreason":
                if (valName.Length == 0)
                {
                    valName = null;
                }
                if (SetPlayerInfoField(player, "KickReason", info, info.LastKickReason, valName))
                {
                    info.LastKickReason = valName;
                }
                break;

            case "name":
                if (valName.Equals(info.Name, StringComparison.OrdinalIgnoreCase))
                {
                    player.Message("SetInfo: You may change capitalization of player's real name. " +
                                   "If you'd like to make other changes to the way player's name is displayed, " +
                                   "use &H/SetInfo <Name> DisplayedName <NewName>");
                    break;
                }
                string oldName = info.Name;
                if (oldName != valName)
                {
                    info.Name = valName;
                    player.Message("Name capitalization changed from \"{0}\" to \"{1}\"",
                                   oldName, valName);
                }
                else
                {
                    player.Message("Name capitalization is already \"{0}\"", oldName);
                }
                break;

            case "previousrank":
                Rank newPreviousRank;
                if (valName.Length > 0)
                {
                    newPreviousRank = RankManager.FindRank(valName);
                    if (newPreviousRank == null)
                    {
                        player.MessageNoRank(valName);
                        break;
                    }
                }
                else
                {
                    newPreviousRank = null;
                }

                Rank oldPreviousRank = info.PreviousRank;

                if (newPreviousRank == oldPreviousRank)
                {
                    if (newPreviousRank == null)
                    {
                        player.Message("SetInfo: PreviousRank for {0}&S is not set.",
                                       info.ClassyName);
                    }
                    else
                    {
                        player.Message("SetInfo: PreviousRank for {0}&S is already set to {1}",
                                       info.ClassyName,
                                       newPreviousRank.ClassyName);
                    }
                    break;
                }
                info.PreviousRank = newPreviousRank;

                if (oldPreviousRank == null)
                {
                    player.Message("SetInfo: PreviousRank for {0}&S set to {1}&",
                                   info.ClassyName,
                                   newPreviousRank.ClassyName);
                }
                else if (newPreviousRank == null)
                {
                    player.Message("SetInfo: PreviousRank for {0}&S was reset (was {1}&S)",
                                   info.ClassyName,
                                   oldPreviousRank.ClassyName);
                }
                else
                {
                    player.Message("SetInfo: PreviousRank for {0}&S changed from {1}&S to {2}",
                                   info.ClassyName,
                                   oldPreviousRank.ClassyName,
                                   newPreviousRank.ClassyName);
                }
                break;

            case "rankchangetype":
                RankChangeType oldType = info.RankChangeType;
                try {
                    info.RankChangeType = (RankChangeType)Enum.Parse(typeof(RankChangeType), valName, true);
                } catch (ArgumentException) {
                    player.Message("SetInfo: Could not parse RankChangeType. Allowed values: {0}",
                                   String.Join(", ", Enum.GetNames(typeof(RankChangeType))));
                    break;
                }
                player.Message("SetInfo: RankChangeType for {0}&S changed from {1} to {2}",
                               info.ClassyName,
                               oldType,
                               info.RankChangeType);
                break;

            case "rankreason":
                if (valName.Length == 0)
                {
                    valName = null;
                }
                if (SetPlayerInfoField(player, "RankReason", info, info.RankChangeReason, valName))
                {
                    info.RankChangeReason = valName;
                }
                break;

            case "timeskicked":
                int oldTimesKicked = info.TimesKicked;
                if (ValidateInt(valName, 0, 9999))
                {
                    info.TimesKicked = Int32.Parse(valName);
                    player.Message("SetInfo: TimesKicked for {0}&S changed from {1} to {2}",
                                   info.ClassyName,
                                   oldTimesKicked,
                                   info.TimesKicked);
                }
                else
                {
                    player.Message("SetInfo: TimesKicked value out of range (Acceptable value range: 0-9999)");
                }
                break;

            case "totaltime":
                TimeSpan newTotalTime;
                TimeSpan oldTotalTime = info.TotalTime;
                if (valName.TryParseMiniTimespan(out newTotalTime))
                {
                    if (newTotalTime > DateTimeUtil.MaxTimeSpan)
                    {
                        player.MessageMaxTimeSpan();
                        break;
                    }
                    info.TotalTime = newTotalTime;
                    player.Message("SetInfo: TotalTime for {0}&S changed from {1} ({2}) to {3} ({4})",
                                   info.ClassyName,
                                   oldTotalTime.ToMiniString(),
                                   oldTotalTime.ToCompactString(),
                                   info.TotalTime.ToMiniString(),
                                   info.TotalTime.ToCompactString());
                }
                else
                {
                    player.Message("SetInfo: Could not parse value given for TotalTime.");
                }
                break;

            case "unbanreason":
                if (valName.Length == 0)
                {
                    valName = null;
                }
                if (SetPlayerInfoField(player, "UnbanReason", info, info.UnbanReason, valName))
                {
                    info.UnbanReason = valName;
                }
                break;

            default:
                player.Message("Only the following properties are editable: " +
                               "TimesKicked, PreviousRank, TotalTime, RankChangeType, " +
                               "BanReason, UnbanReason, RankReason, KickReason, DisplayedName");
                return;
            }
        }
Esempio n. 44
0
 public PlayerInfoRankChangingEventArgs( PlayerInfo playerInfo, Player rankChanger, Rank newRank, string reason, RankChangeType rankChangeType )
     : base( playerInfo, rankChanger, playerInfo.Rank, reason, rankChangeType ) {
     NewRank = newRank;
 }
Esempio n. 45
0
        internal static bool RaisePlayerInfoRankChangingEvent(PlayerInfo playerInfo, Player rankChanger, Rank newRank, string reason, RankChangeType rankChangeType)
        {
            var h = PlayerInfoRankChanging;

            if (h == null)
            {
                return(false);
            }
            var e = new PlayerInfoRankChangingEventArgs(playerInfo, rankChanger, newRank, reason, rankChangeType);

            h(null, e);
            return(e.Cancel);
        }