Esempio n. 1
0
 public bool CanBan( PlayerClass other ) {
     if( maxBan == null ) {
         return rank >= other.rank;
     } else {
         return maxBan.rank >= other.rank;
     }
 }
Esempio n. 2
0
 public bool CanDemote( PlayerClass other ) {
     if( maxDemote == null ) {
         return rank >= other.rank;
     } else {
         return maxDemote.rank >= other.rank;
     }
 }
Esempio n. 3
0
 public bool CanKick( PlayerClass other ) {
     if( maxKick == null ) {
         return rank >= other.rank;
     } else {
         return maxKick.rank >= other.rank;
     }
 }
Esempio n. 4
0
        public bool AddClass( PlayerClass playerClass ) {
            // check for duplicate class names
            if( classes.ContainsKey( playerClass.name.ToLowerInvariant() ) ) {
                if( world != null ) {
                    world.log.Log( "PlayerClass.AddClass: Duplicate definition for \"{0}\" (rank {1}) class ignored.", LogType.Error,
                                    playerClass.name, playerClass.rank );
                }
                return false;
            }
            // check for duplicate ranks
            foreach( PlayerClass pc in classes.Values ) {
                if( pc.rank == playerClass.rank ) {
                    if( world != null ) {
                        world.log.Log( "PlayerClass.AddClass: Class definition was ignored because \"{0}\" has the same rank ({1}) as \"{2}\". Each class must have a unique rank number.", LogType.Error,
                                        playerClass.name, playerClass.rank, pc.name );
                    }
                    return false;
                }
            }

            // determine class's index based on its rank
            classes[playerClass.name.ToLowerInvariant()] = playerClass;
            RebuildIndex();

            if( world != null ) {
                world.log.Log( "PlayerClass.AddClass: Added \"{0}\" (rank {1}) to the class list.", LogType.Debug,
                               playerClass.name, playerClass.rank );
            }
            return true;
        }
Esempio n. 5
0
        // === Serialization & Defaults =======================================
        // fabricate info for a player
        public PlayerInfo( string _name, PlayerClass _playerClass ){
            name = _name;
            lastIP = IPAddress.None;

            playerClass = _playerClass;
            classChangeDate = DateTime.MinValue;
            classChangedBy = "-";

            banned = false;
            banDate = DateTime.MinValue;
            bannedBy = "-";
            unbanDate = DateTime.MinValue;
            unbannedBy = "-";
            banReason = "-";
            unbanReason = "-";

            firstLoginDate = DateTime.Now;
            lastLoginDate = DateTime.Now;

            lastFailedLoginDate = DateTime.MinValue;
            lastFailedLoginIP = IPAddress.None;
            failedLoginCount = 0;

            totalTimeOnServer = new TimeSpan( 0 );
            blocksBuilt = 0;
            blocksDeleted = 0;
            timesVisited = 1;
            linesWritten = 0;
            thanksReceived = 0;
            warningsReceived = 0;
        }
Esempio n. 6
0
        // generate info for a new player
        public PlayerInfo( World world, Player player ) {
            name = player.name;
            lastIP = player.session.GetIP();

            playerClass = world.classes.defaultClass;
            classChangeDate = DateTime.MinValue;
            classChangedBy = "-";

            banned = false;
            banDate = DateTime.MinValue;
            bannedBy = "-";
            unbanDate = DateTime.MinValue;
            unbannedBy = "-";
            banReason = "-";
            unbanReason = "-";

            lastFailedLoginDate = DateTime.MinValue;
            lastFailedLoginIP = IPAddress.None;
            failedLoginCount = 0;

            firstLoginDate = DateTime.Now;
            lastLoginDate = firstLoginDate;

            totalTimeOnServer = new TimeSpan( 0 );
            blocksBuilt = 0;
            blocksDeleted = 0;
            timesVisited = 1;

            linesWritten = 0;
            thanksReceived = 0;
            warningsReceived = 0;
        }
Esempio n. 7
0
 public World( string _name )
 {
     name = _name;
     classAccess = ClassList.lowestClass;
     classBuild = ClassList.lowestClass;
     thread = new Thread( WorldLoop );
     thread.IsBackground = true;
 }
Esempio n. 8
0
 public static bool CanChangeRank( PlayerClass pc, byte newRank )
 {
     if( pc.rank == newRank ) return true;
     foreach( PlayerClass pc2 in classesByIndex ) {
         if( pc2.rank == newRank ) {
             return false;
         }
     }
     return true;
 }
Esempio n. 9
0
 public bool CanChangeRank(PlayerClass pc, byte newRank)
 {
     if (pc.rank == newRank)
     {
         return(true);
     }
     foreach (PlayerClass pc2 in classesByIndex)
     {
         if (pc2.rank == newRank)
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 10
0
        public PlayerClass ParseRank(int maxRank)
        {
            PlayerClass temp = lowestClass;

            if (temp.rank > maxRank)
            {
                return(null);
            }
            foreach (PlayerClass c in classes.Values)
            {
                if (c.rank > temp.rank && c.rank <= maxRank)
                {
                    temp = c;
                }
            }
            return(temp);
        }
Esempio n. 11
0
        void DoZone(Player player, Command cmd)
        {
            if (!player.Can(Permissions.SetSpawn))
            {
                world.NoAccessMessage(player);
                return;
            }

            string name = cmd.Next();

            if (name == null)
            {
                player.Message("No zone name specified. See " + Color.Help + "/help zone");
                return;
            }
            if (!Player.IsValidName(name))
            {
                player.Message("\"" + name + "\" is not a valid zone name");
                return;
            }
            Zone zone = new Zone();

            zone.name = name;

            string property = cmd.Next();

            if (property == null)
            {
                player.Message("No zone rank/whitelist/blacklist specified. See " + Color.Help + "/help zone");
                return;
            }
            PlayerClass minRank = world.classes.ParseClass(property);

            if (minRank != null)
            {
                zone.buildRank       = minRank.rank;
                player.tag           = zone;
                player.marksExpected = 2;
                player.marks.Clear();
                player.markCount         = 0;
                player.selectionCallback = MakeZone;
            }
        }
Esempio n. 12
0
        public bool ParseClassLimits(PlayerClass pc)
        {
            bool ok = true;

            if (pc.maxKickVal == "")
            {
                pc.maxKick = null;
            }
            else
            {
                pc.maxKick = ParseClass(pc.maxKickVal);
                ok        &= (pc.maxKick != null);
            }
            if (pc.maxBanVal == "")
            {
                pc.maxBan = null;
            }
            else
            {
                pc.maxBan = ParseClass(pc.maxBanVal);
                ok       &= (pc.maxBan != null);
            }
            if (pc.maxPromoteVal == "")
            {
                pc.maxPromote = null;
            }
            else
            {
                pc.maxPromote = ParseClass(pc.maxPromoteVal);
                ok           &= (pc.maxPromote != null);
            }
            if (pc.maxDemoteVal == "")
            {
                pc.maxDemote = null;
            }
            else
            {
                pc.maxDemote = ParseClass(pc.maxDemoteVal);
                ok          &= (pc.maxDemote != null);
            }
            return(ok);
        }
Esempio n. 13
0
        // Shows general information about a particular class.
        void ClassInfo(Player player, Command cmd)
        {
            PlayerClass playerClass = world.classes.FindClass(cmd.Next());

            if (playerClass != null)
            {
                player.Message("Players of class \"" + playerClass.name + "\" can do the following:");
                string line = "";
                for (int i = 0; i < playerClass.permissions.Length; i++)
                {
                    if (playerClass.permissions[i])
                    {
                        string addition = Enum.GetName(typeof(Permissions), (Permissions)i).ToLower();
                        if (line.Length + addition.Length > 62)
                        {
                            player.Message(line.Substring(0, line.Length - 2));
                            line = addition + ", ";
                        }
                        else
                        {
                            line += addition + ", ";
                        }
                    }
                }
                if (line.Length > 2)
                {
                    player.Message(line.Substring(0, line.Length - 2));
                }
            }
            else
            {
                player.Message("Below is a list of classes. For detail see " + Color.Help + "/class classname");
                foreach (PlayerClass classListEntry in world.classes.classesByIndex)
                {
                    player.Message(classListEntry.color, "    " + classListEntry.name + " (rank " + classListEntry.rank + ")");
                }
            }
        }
Esempio n. 14
0
        public bool AddClass(PlayerClass playerClass)
        {
            // check for duplicate class names
            if (classes.ContainsKey(playerClass.name.ToLowerInvariant()))
            {
                if (world != null)
                {
                    world.log.Log("PlayerClass.AddClass: Duplicate definition for \"{0}\" (rank {1}) class ignored.", LogType.Error,
                                  playerClass.name, playerClass.rank);
                }
                return(false);
            }
            // check for duplicate ranks
            foreach (PlayerClass pc in classes.Values)
            {
                if (pc.rank == playerClass.rank)
                {
                    if (world != null)
                    {
                        world.log.Log("PlayerClass.AddClass: Class definition was ignored because \"{0}\" has the same rank ({1}) as \"{2}\". Each class must have a unique rank number.", LogType.Error,
                                      playerClass.name, playerClass.rank, pc.name);
                    }
                    return(false);
                }
            }

            // determine class's index based on its rank
            classes[playerClass.name.ToLowerInvariant()] = playerClass;
            RebuildIndex();

            if (world != null)
            {
                world.log.Log("PlayerClass.AddClass: Added \"{0}\" (rank {1}) to the class list.", LogType.Debug,
                              playerClass.name, playerClass.rank);
            }
            return(true);
        }
Esempio n. 15
0
 public void ChangeName(PlayerClass pc, string newName)
 {
     classes.Remove(pc.name.ToLowerInvariant());
     pc.name = newName;
     classes.Add(pc.name.ToLowerInvariant(), pc);
 }
Esempio n. 16
0
 public bool CanKick( PlayerClass other )
 {
     return maxKick.rank >= other.rank;
 }
Esempio n. 17
0
 public bool CanBan( PlayerClass other )
 {
     return maxBan.rank >= other.rank;
 }
Esempio n. 18
0
 // Broadcast to a specific class
 public void SendToClass( Packet packet, PlayerClass playerClass ) {
     Player player;
     for( int i = 1; i < players.Length; i++ ) {
         player = players[i];
         if( player != null && player.info.playerClass == playerClass ) {
             player.Send( packet, true );
         }
     }
 }
Esempio n. 19
0
 public bool CanPromote( PlayerClass other )
 {
     return maxPromote.rank >= other.rank;
 }
Esempio n. 20
0
 void DisableClassOptions() {
     selectedClass = null;
     bRemoveClass.Enabled = false;
     tClassName.Text = "";
     nRank.Value = 0;
     bColorClass.Text = "";
     tPrefix.Text = "";
     FillClassList( cPromoteLimit, "(own class)" );
     FillClassList( cDemoteLimit, "(own class)" );
     FillClassList( cKickLimit, "(own class)" );
     FillClassList( cBanLimit, "(own class)" );
     cPromoteLimit.SelectedIndex = 0;
     cDemoteLimit.SelectedIndex = 0;
     cKickLimit.SelectedIndex = 0;
     cBanLimit.SelectedIndex = 0;
     xReserveSlot.Checked = false;
     xIdleKick.Checked = false;
     nKickIdle.Value = 0;
     xKickOn.Checked = false;
     nKickOn.Value = 0;
     xBanOn.Checked = false;
     nBanOn.Value = 0;
     foreach( ListViewItem item in vPermissions.Items ) {
         item.Checked = false;
         item.Font = vPermissions.Font;
     }
     gClassOptions.Enabled = false;
     lPermissions.Enabled = false;
     vPermissions.Enabled = false;
 }
Esempio n. 21
0
 internal static bool FirePlayerClassChange( Player target, Player player, PlayerClass oldClass, PlayerClass newClass )
 {
     bool cancel = false;
     if( OnPlayerClassChanged != null ) OnPlayerClassChanged( target, player, oldClass, newClass, ref cancel );
     return !cancel;
 }
Esempio n. 22
0
        static bool DefineClass( XElement el )
        {
            PlayerClass playerClass = new PlayerClass();

            // read required attributes
            XAttribute attr = el.Attribute( "name" );
            if( attr == null ) {
                Log( "Config.DefineClass: Class definition with no name was ignored.", LogType.Warning );
                return false;
            }
            if( !PlayerClass.IsValidClassName( attr.Value.Trim() ) ) {
                Log( "Config.DefineClass: Invalid name specified for class \"{0}\". Class name can only contain letters, digits, and underscores.",
                     LogType.Warning, playerClass.name );
                return false;
            }
            playerClass.name = attr.Value.Trim();

            if( ClassList.classes.ContainsKey( playerClass.name ) ) {
                Log( "Config.DefineClass: Duplicate class definition for \"{0}\" was ignored.", LogType.Warning, playerClass.name );
                return true;
            }

            if( (attr = el.Attribute( "rank" )) == null ) {
                Log( "Config.DefineClass: No rank specified for {0}. Class definition was ignored.", LogType.Warning, playerClass.name );
                return false;
            }
            if( !Byte.TryParse( attr.Value, out playerClass.rank ) ) {
                Log( "Config.DefineClass: Cannot parse rank for {0}. Class definition was ignored.", LogType.Warning, playerClass.name );
                return false;
            }

            attr = el.Attribute( "color" );
            if( attr == null || Color.Parse( attr.Value ) == null ) {
                playerClass.color = "";
            } else {
                playerClass.color = Color.Parse( attr.Value );
            }

            // read optional attributes
            if( (attr = el.Attribute( "prefix" )) != null ) {
                if( PlayerClass.IsValidPrefix( attr.Value ) ) {
                    playerClass.prefix = attr.Value;
                } else {
                    Log( "Config.DefineClass: Invalid prefix specified for {0}.", LogType.Warning, playerClass.name );
                    playerClass.prefix = "";
                }
            }

            if( (attr = el.Attribute( "spamKickAt" )) != null ) {
                if( !Int32.TryParse( attr.Value, out playerClass.spamKickThreshold ) ) {
                    Log( "Config.DefineClass: Could not parse the value for spamKickAt for {0}. Assuming 0 (never).", LogType.Warning, playerClass.name );
                    playerClass.spamKickThreshold = 0;
                }
            } else {
                playerClass.spamKickThreshold = 0;
            }

            if( (attr = el.Attribute( "spamBanAt" )) != null ) {
                if( !Int32.TryParse( attr.Value, out playerClass.spamBanThreshold ) ) {
                    Log( "Config.DefineClass: Could not parse the value for spamBanAt for {0}. Assuming 0 (never).", LogType.Warning, playerClass.name );
                    playerClass.spamBanThreshold = 0;
                }
            } else {
                playerClass.spamBanThreshold = 0;
            }

            if( (attr = el.Attribute( "idleKickAfter" )) != null ) {
                if( !Int32.TryParse( attr.Value, out playerClass.idleKickTimer ) ) {
                    Log( "Config.DefineClass: Could not parse the value for idleKickAfter for {0}. Assuming 0 (never).", LogType.Warning, playerClass.name );
                    playerClass.idleKickTimer = 0;
                }
            } else {
                playerClass.idleKickTimer = 0;
            }

            if( (attr = el.Attribute( "reserveSlot" )) != null ) {
                if( !Boolean.TryParse( attr.Value, out playerClass.reservedSlot ) ) {
                    Log( "Config.DefineClass: Could not parse the value for reserveSlot for {0}. Assuming \"false\".", LogType.Warning, playerClass.name );
                    playerClass.reservedSlot = false;
                }
            } else {
                playerClass.reservedSlot = false;
            }

            // read permissions
            XElement temp;
            for( int i = 0; i < Enum.GetValues( typeof( Permissions ) ).Length; i++ ) {
                string permission = ((Permissions)i).ToString();
                if( (temp = el.Element( permission )) != null ) {
                    playerClass.permissions[i] = true;
                    if( i == (int)Permissions.Promote ) {
                        if( (attr = temp.Attribute( "max" )) != null ) {
                            playerClass.maxPromoteVal = attr.Value;
                        } else {
                            playerClass.maxPromoteVal = "";
                        }
                    } else if( i == (int)Permissions.Demote ) {
                        if( (attr = temp.Attribute( "max" )) != null ) {
                            playerClass.maxDemoteVal = attr.Value;
                        } else {
                            playerClass.maxDemoteVal = "";
                        }
                    } else if( i == (int)Permissions.Kick ) {
                        if( (attr = temp.Attribute( "max" )) != null ) {
                            playerClass.maxKickVal = attr.Value;
                        } else {
                            playerClass.maxKickVal = "";
                        }
                    } else if( i == (int)Permissions.Ban ) {
                        if( (attr = temp.Attribute( "max" )) != null ) {
                            playerClass.maxBanVal = attr.Value;
                        } else {
                            playerClass.maxBanVal = "";
                        }
                    }
                }
            }

            // check for consistency in ban permissions
            if( !playerClass.Can( Permissions.Ban ) &&
                (playerClass.Can( Permissions.BanAll ) || playerClass.Can( Permissions.BanIP )) ) {
                Log( "Class \"{0}\" is allowed to BanIP and/or BanAll but not allowed to Ban.\n" +
                    "Assuming that all ban permissions were ment to be off.", LogType.Warning, playerClass.name );
                playerClass.permissions[(int)Permissions.BanIP] = false;
                playerClass.permissions[(int)Permissions.BanAll] = false;
            }

            ClassList.AddClass( playerClass );
            return true;
        }
Esempio n. 23
0
        // Change player class
        void ChangeClass(Player player, Command cmd)
        {
            string name         = cmd.Next();
            string newClassName = cmd.Next();

            if (name == null || newClassName == null)
            {
                player.Message("Usage: " + Color.Help + "/user PlayerName ClassName");
                player.Message("To see a list of classes and permissions, use " + Color.Help + "/class");
                return;
            }

            Player target = world.FindPlayer(name);

            if (target == null)
            {
                world.NoPlayerMessage(player, name);
                return;
            }

            PlayerClass newClass = world.classes.FindClass(newClassName);

            if (newClass == null)
            {
                player.Message("Unrecognized player class: " + newClassName);
                return;
            }

            if (target.info.playerClass == newClass)
            {
                player.Message(target.name + "'s class is already " + newClass.color + newClass.name);
                return;
            }

            bool promote = target.info.playerClass.rank < newClass.rank;

            if ((promote && !player.Can(Permissions.Promote)) || !promote && !player.Can(Permissions.Demote))
            {
                world.NoAccessMessage(player);
                return;
            }

            if (promote && !player.info.playerClass.CanPromote(newClass))
            {
                PlayerClass maxRank = player.info.playerClass.maxPromote;
                if (maxRank == null)
                {
                    player.Message("You can only promote players up to " + player.info.playerClass.color + player.info.playerClass.name);
                }
                else
                {
                    player.Message("You can only promote players up to " + maxRank.color + maxRank.name);
                }
                return;
            }
            else if (!promote && !player.info.playerClass.CanDemote(target.info.playerClass))
            {
                PlayerClass maxRank = player.info.playerClass.maxDemote;
                if (maxRank == null)
                {
                    player.Message("You can only demote players that are " + player.info.playerClass.color + player.info.playerClass.name + Color.Sys + " or lower.");
                }
                else
                {
                    player.Message("You can only demote players that are " + maxRank.color + maxRank.name + Color.Sys + " or lower.");
                }
                return;
            }

            if (promote && target.info.playerClass.rank < newClass.rank ||
                target.info.playerClass.rank > newClass.rank)
            {
                world.log.Log("{0} changed the class of {1} from {2} to {3}.", LogType.UserActivity,
                              player.name, target.info.name, target.info.playerClass.name, newClass.name);
                target.info.playerClass     = newClass;
                target.info.classChangeDate = DateTime.Now;
                target.info.classChangedBy  = player.name;

                target.Send(PacketWriter.MakeSetPermission(target));

                if (promote)
                {
                    player.Message("You promoted " + target.name + " to " + newClass.color + newClass.name + ".");
                    target.Message("You have been promoted to " + newClass.color + newClass.name + Color.Sys + " by " + player.name + "!");
                }
                else
                {
                    player.Message("You demoted " + target.name + " to " + newClass.color + newClass.name + ".");
                    target.Message("You have been demoted to " + newClass.color + newClass.name + Color.Sys + " by " + player.name + "!");
                }
                if (world.config.GetBool("ClassPrefixesInList") || world.config.GetBool("ClassColorsInChat"))       // TODO: colors in player names
                {
                    world.UpdatePlayer(target);
                }
                target.mode = BlockPlacementMode.Normal;
            }
            else
            {
                if (promote)
                {
                    player.Message(target.name + " is already same or lower rank than " + newClass.name);
                }
                else
                {
                    player.Message(target.name + " is already same or higher rank than " + newClass.name);
                }
            }
        }
Esempio n. 24
0
        bool DefineClass(XElement el)
        {
            PlayerClass playerClass = new PlayerClass();

            // read required attributes
            XAttribute attr = el.Attribute("name");

            if (attr == null)
            {
                Log("Config.DefineClass: Class definition with no name was ignored.", LogType.Warning);
                return(false);
            }
            if (!PlayerClass.IsValidClassName(attr.Value.Trim()))
            {
                Log("Config.DefineClass: Invalid name specified for class \"{0}\". Class name can only contain letters, digits, and underscores.",
                    LogType.Warning, playerClass.name);
                return(false);
            }
            playerClass.name = attr.Value.Trim();

            if (classes.classes.ContainsKey(playerClass.name))
            {
                Log("Config.DefineClass: Duplicate class definition for \"{0}\" was ignored.", LogType.Warning, playerClass.name);
                return(true);
            }


            if ((attr = el.Attribute("rank")) == null)
            {
                Log("Config.DefineClass: No rank specified for {0}. Class definition was ignored.", LogType.Warning, playerClass.name);
                return(false);
            }
            if (!Byte.TryParse(attr.Value, out playerClass.rank))
            {
                Log("Config.DefineClass: Cannot parse rank for {0}. Class definition was ignored.", LogType.Warning, playerClass.name);
                return(false);
            }

            attr = el.Attribute("color");
            if (attr == null || Color.Parse(attr.Value) == null)
            {
                playerClass.color = "";
            }
            else
            {
                playerClass.color = Color.Parse(attr.Value);
            }

            // read optional attributes
            if ((attr = el.Attribute("prefix")) != null)
            {
                if (PlayerClass.IsValidPrefix(attr.Value))
                {
                    playerClass.prefix = attr.Value;
                }
                else
                {
                    Log("Config.DefineClass: Invalid prefix specified for {0}.", LogType.Warning, playerClass.name);
                    playerClass.prefix = "";
                }
            }

            if ((attr = el.Attribute("spamKickAt")) != null)
            {
                if (!Int32.TryParse(attr.Value, out playerClass.spamKickThreshold))
                {
                    Log("Config.DefineClass: Could not parse the value for spamKickAt for {0}. Assuming 0 (never).", LogType.Warning, playerClass.name);
                    playerClass.spamKickThreshold = 0;
                }
            }
            else
            {
                playerClass.spamKickThreshold = 0;
            }

            if ((attr = el.Attribute("spamBanAt")) != null)
            {
                if (!Int32.TryParse(attr.Value, out playerClass.spamBanThreshold))
                {
                    Log("Config.DefineClass: Could not parse the value for spamBanAt for {0}. Assuming 0 (never).", LogType.Warning, playerClass.name);
                    playerClass.spamBanThreshold = 0;
                }
            }
            else
            {
                playerClass.spamBanThreshold = 0;
            }

            if ((attr = el.Attribute("idleKickAfter")) != null)
            {
                if (!Int32.TryParse(attr.Value, out playerClass.idleKickTimer))
                {
                    Log("Config.DefineClass: Could not parse the value for idleKickAfter for {0}. Assuming 0 (never).", LogType.Warning, playerClass.name);
                    playerClass.idleKickTimer = 0;
                }
            }
            else
            {
                playerClass.idleKickTimer = 0;
            }

            if ((attr = el.Attribute("reserveSlot")) != null)
            {
                if (!Boolean.TryParse(attr.Value, out playerClass.reservedSlot))
                {
                    Log("Config.DefineClass: Could not parse the value for reserveSlot for {0}. Assuming \"false\".", LogType.Warning, playerClass.name);
                    playerClass.reservedSlot = false;
                }
            }
            else
            {
                playerClass.reservedSlot = false;
            }

            // read permissions
            XElement temp;

            for (int i = 0; i < Enum.GetValues(typeof(Permissions)).Length; i++)
            {
                string permission = ((Permissions)i).ToString();
                if ((temp = el.Element(permission)) != null)
                {
                    playerClass.permissions[i] = true;
                    if (i == (int)Permissions.Promote)
                    {
                        if ((attr = temp.Attribute("max")) != null)
                        {
                            playerClass.maxPromoteVal = attr.Value;
                        }
                        else
                        {
                            playerClass.maxPromoteVal = "";
                        }
                    }
                    else if (i == (int)Permissions.Demote)
                    {
                        if ((attr = temp.Attribute("max")) != null)
                        {
                            playerClass.maxDemoteVal = attr.Value;
                        }
                        else
                        {
                            playerClass.maxDemoteVal = "";
                        }
                    }
                    else if (i == (int)Permissions.Kick)
                    {
                        if ((attr = temp.Attribute("max")) != null)
                        {
                            playerClass.maxKickVal = attr.Value;
                        }
                        else
                        {
                            playerClass.maxKickVal = "";
                        }
                    }
                    else if (i == (int)Permissions.Ban)
                    {
                        if ((attr = temp.Attribute("max")) != null)
                        {
                            playerClass.maxBanVal = attr.Value;
                        }
                        else
                        {
                            playerClass.maxBanVal = "";
                        }
                    }
                }
            }

            // check for consistency in ban permissions
            if (!playerClass.Can(Permissions.Ban) &&
                (playerClass.Can(Permissions.BanAll) || playerClass.Can(Permissions.BanIP)))
            {
                Log("Class \"{0}\" is allowed to BanIP and/or BanAll but not allowed to Ban.\n" +
                    "Assuming that all ban permissions were ment to be off.", LogType.Warning, playerClass.name);
                playerClass.permissions[(int)Permissions.BanIP]  = false;
                playerClass.permissions[(int)Permissions.BanAll] = false;
            }

            classes.AddClass(playerClass);
            return(true);
        }
Esempio n. 25
0
 public void ChangeRank(PlayerClass pc, byte newRank)
 {
     pc.rank = newRank;
     RebuildIndex();
 }
Esempio n. 26
0
 public int GetIndex( PlayerClass pc ) {
     if( pc == null ) return 0;
     else return pc.index + 1;
 }
Esempio n. 27
0
 // Broadcast to a specific class
 public static void SendToClass( Packet packet, PlayerClass playerClass, Player srcPlayer )
 {
     Player[] tempList = playerList;
     for( int i = 0; i < tempList.Length; i++ ) {
         if ((tempList[i].info.playerClass == playerClass) || ((tempList[i].Can(Permissions.SeeLowerClassChat) && (tempList[i].info.playerClass.rank > playerClass.rank)) && tempList[i].info.name != srcPlayer.name))
         {
             tempList[i].Send(packet);
         }
     }
 }
Esempio n. 28
0
        private void bRemoveClass_Click( object sender, EventArgs e ) {
            if( vClasses.SelectedItem != null ) {
                selectedClass = null;
                int index = vClasses.SelectedIndex;

                PlayerClass defaultClass = config.classes.ParseIndex( cDefaultClass.SelectedIndex - 1 );
                if( defaultClass != null && index == defaultClass.index ) {
                    defaultClass = null;
                    MessageBox.Show( "DefaultClass has been reset to \"(lowest class)\"", "Warning" );
                }

                if( config.classes.DeleteClass( index ) ) {
                    MessageBox.Show( "Some of the rank limits for kick, ban, promote, and/or demote have been reset.", "Warning" );
                }
                vClasses.Items.RemoveAt( index );

                RebuildClassList();

                if( index < vClasses.Items.Count ) {
                    vClasses.SelectedIndex = index;
                }
            }
        }
Esempio n. 29
0
 static void LoadWorldClassRestriction( World world, ref PlayerClass field, string fieldType, XElement element )
 {
     XAttribute temp;
     PlayerClass playerClass;
     if( (temp = element.Attribute( fieldType )) != null ) {
         if( (playerClass = ClassList.FindClass( temp.Value )) != null ) {
             field = playerClass;
         } else {
             Logger.Log( "Server.ParseWorldListXML: Could not parse the specified {0} class for world \"{1}\": \"{2}\". No access limit was set.", LogType.Error,
                         fieldType,
                         world.name,
                         temp.Value );
             field = ClassList.lowestClass;
         }
     } else {
         field = ClassList.lowestClass;
     }
 }
Esempio n. 30
0
 private void tPrefix_Validating( object sender, CancelEventArgs e ) {
     if( selectedClass == null ) return;
     if( tPrefix.Text.Length > 0 && !PlayerClass.IsValidPrefix( tPrefix.Text ) ) {
         MessageBox.Show( "Invalid prefix character!\n"+
             "Prefixes may only contain characters that are allowed in chat (except space).", "Warning" );
         e.Cancel = true;
     }
     defaultClass = config.classes.ParseIndex( cDefaultClass.SelectedIndex - 1 );
     selectedClass.prefix = tPrefix.Text;
     RebuildClassList();
 }
Esempio n. 31
0
        void SelectClass( PlayerClass pc ) {
            if( pc == null ) {
                DisableClassOptions();
                return;
            }
            selectedClass = pc;
            tClassName.Text = pc.name;
            nRank.Value = pc.rank;

            ApplyColor( bColorClass, fCraft.Color.ParseToIndex( pc.color ) );

            tPrefix.Text = pc.prefix;
            cKickLimit.SelectedIndex = pc.GetMaxKickIndex();
            cBanLimit.SelectedIndex = pc.GetMaxBanIndex();
            cPromoteLimit.SelectedIndex = pc.GetMaxPromoteIndex();
            cDemoteLimit.SelectedIndex = pc.GetMaxDemoteIndex();
            xReserveSlot.Checked = pc.reservedSlot;
            xIdleKick.Checked = pc.idleKickTimer > 0;
            nKickIdle.Value = pc.idleKickTimer;
            nKickIdle.Enabled = xIdleKick.Checked;
            xKickOn.Checked = pc.spamKickThreshold > 0;
            nKickOn.Value = pc.spamKickThreshold;
            nKickOn.Enabled = xKickOn.Checked;
            xBanOn.Checked = pc.spamBanThreshold > 0;
            nBanOn.Value = pc.spamBanThreshold;
            nBanOn.Enabled = xBanOn.Checked;

            foreach( ListViewItem item in vPermissions.Items ) {
                item.Checked = pc.permissions[item.Index];
                if( item.Checked ) {
                    item.Font = bold;
                } else {
                    item.Font = vPermissions.Font;
                }
            }

            cKickLimit.Enabled = pc.Can( Permissions.Kick );
            cBanLimit.Enabled = pc.Can( Permissions.Ban );
            cPromoteLimit.Enabled = pc.Can( Permissions.Promote );
            cDemoteLimit.Enabled = pc.Can( Permissions.Demote );

            gClassOptions.Enabled = true;
            lPermissions.Enabled = true;
            vPermissions.Enabled = true;
        }
Esempio n. 32
0
        // load info from file
        public PlayerInfo( World world, string[] fields ) {
            name = fields[0];
            lastIP = IPAddress.Parse( fields[1] );

            playerClass = world.classes.ParseClass( fields[2] );
            if( playerClass == null ) {
                playerClass = world.classes.defaultClass;
                world.log.Log( "PlayerInfo: Could not parse class for player {0}. Setting to default ({1}).", LogType.Error, name, playerClass.name );
            }
            if( fields[3] != "-" ) classChangeDate = DateTime.Parse( fields[3] );
            else classChangeDate = DateTime.MinValue;
            classChangedBy = fields[4];

            banned = (fields[5] == "b");

            if( fields[6] != "-" ) banDate = DateTime.Parse( fields[6] );
            else banDate = DateTime.MinValue;
            bannedBy = fields[7];
            if( fields[8] != "-" ) unbanDate = DateTime.Parse( fields[8] );
            else unbanDate = DateTime.MinValue;
            unbannedBy = fields[9];
            banReason = UnEscape(fields[10]);
            unbanReason = UnEscape(fields[11]);

            if( fields[12] != "-" ) lastFailedLoginDate = DateTime.Parse( fields[12] );
            else lastFailedLoginDate = DateTime.MinValue;
            if( fields[13] != "-" ) lastFailedLoginIP = IPAddress.Parse( fields[13] );
            else lastFailedLoginIP = IPAddress.None;
            failedLoginCount = Int16.Parse( fields[14] );

            firstLoginDate = DateTime.Parse( fields[15] );
            lastLoginDate = DateTime.Parse( fields[16] );
            totalTimeOnServer = TimeSpan.Parse( fields[17] );

            blocksBuilt = Int32.Parse( fields[18] );
            blocksDeleted = Int32.Parse( fields[19] );
            timesVisited = Int16.Parse( fields[20] );
            linesWritten = Int32.Parse( fields[21] );
            thanksReceived = Int16.Parse( fields[22] );
            warningsReceived = Int16.Parse( fields[23] );
        }
Esempio n. 33
0
        private void bAddClass_Click( object sender, EventArgs e ) {
            if( vClasses.Items.Count == 255 ) {
                MessageBox.Show( "Maximum number of classes (255) reached!", "Warning" );
                return;
            }
            int number = 1;
            byte rank = 0;
            while( config.classes.classes.ContainsKey( "class" + number ) ) number++;
            while( config.classes.ContainsRank( rank ) ) rank++;
            PlayerClass pc = new PlayerClass();
            pc.name = "class" + number;
            pc.rank = rank;
            for( int i = 0; i < pc.permissions.Length; i++ ) pc.permissions[i] = false;
            pc.prefix = "";
            pc.reservedSlot = false;
            pc.color = "";

            defaultClass = config.classes.ParseIndex( cDefaultClass.SelectedIndex - 1 );

            config.classes.AddClass( pc );
            RebuildClassList();
        }
Esempio n. 34
0
 public bool CanChangeName( PlayerClass pc, string newName ) {
     if( pc.name.ToLowerInvariant() == newName.ToLowerInvariant() ) return true;
     if( classes.ContainsKey( newName.ToLowerInvariant() ) ) return false;
     return true;
 }
Esempio n. 35
0
 private void bResetTab_Click( object sender, EventArgs e ) {
     if( MessageBox.Show( "Are you sure you want to reset this tab to defaults?", "Warning", MessageBoxButtons.OKCancel ) == DialogResult.OK ) {
         switch( tabs.SelectedIndex ) {
             case 0:// General
                 config.LoadDefaultsGeneral();
                 ApplyTabGeneral();
                 break;
             case 1:// Security
                 config.LoadDefaultsSecurity();
                 ApplyTabSecurity();
                 break;
             case 2:// Classes
                 config.ResetClasses();
                 ApplyTabClasses();
                 defaultClass = null;
                 RebuildClassList();
                 break;
             case 3:// TODO: Physics
                 break;
             case 4:// Saving and Backup
                 config.LoadDefaultsSavingAndBackup();
                 ApplyTabSavingAndBackup();
                 break;
             case 5:// Logging
                 config.LoadDefaultsLogging();
                 ApplyTabLogging();
                 break;
             case 6:// Advanced
                 config.LoadDefaultsAdvanced();
                 ApplyTabAdvanced();
                 break;
         }
     }
 }
Esempio n. 36
0
 public void ChangeName( PlayerClass pc, string newName ) {
     classes.Remove( pc.name.ToLowerInvariant() );
     pc.name = newName;
     classes.Add( pc.name.ToLowerInvariant(), pc );
 }
Esempio n. 37
0
 public void ChangeRank( PlayerClass pc, byte newRank ) {
     pc.rank = newRank;
     RebuildIndex();
 }
Esempio n. 38
0
 public bool ParseClassLimits( PlayerClass pc ) {
     bool ok = true;
     if( pc.maxKickVal == "" ) {
         pc.maxKick = null;
     } else {
         pc.maxKick = ParseClass( pc.maxKickVal );
         ok &= (pc.maxKick != null);
     }
     if( pc.maxBanVal == "" ) {
         pc.maxBan = null;
     } else {
         pc.maxBan = ParseClass( pc.maxBanVal );
         ok &= (pc.maxBan != null);
     }
     if( pc.maxPromoteVal == "" ) {
         pc.maxPromote = null;
     } else {
         pc.maxPromote = ParseClass( pc.maxPromoteVal );
         ok &= (pc.maxPromote != null);
     }
     if( pc.maxDemoteVal == "" ) {
         pc.maxDemote = null;
     } else {
         pc.maxDemote = ParseClass( pc.maxDemoteVal );
         ok &= (pc.maxDemote != null);
     }
     return ok;
 }
Esempio n. 39
0
        // load info from file
        public PlayerInfo(World world, string[] fields)
        {
            name   = fields[0];
            lastIP = IPAddress.Parse(fields[1]);

            playerClass = world.classes.ParseClass(fields[2]);
            if (playerClass == null)
            {
                playerClass = world.classes.defaultClass;
                world.log.Log("PlayerInfo: Could not parse class for player {0}. Setting to default ({1}).", LogType.Error, name, playerClass.name);
            }
            if (fields[3] != "-")
            {
                classChangeDate = DateTime.Parse(fields[3]);
            }
            else
            {
                classChangeDate = DateTime.MinValue;
            }
            classChangedBy = fields[4];

            banned = (fields[5] == "b");

            if (fields[6] != "-")
            {
                banDate = DateTime.Parse(fields[6]);
            }
            else
            {
                banDate = DateTime.MinValue;
            }
            bannedBy = fields[7];
            if (fields[8] != "-")
            {
                unbanDate = DateTime.Parse(fields[8]);
            }
            else
            {
                unbanDate = DateTime.MinValue;
            }
            unbannedBy  = fields[9];
            banReason   = UnEscape(fields[10]);
            unbanReason = UnEscape(fields[11]);

            if (fields[12] != "-")
            {
                lastFailedLoginDate = DateTime.Parse(fields[12]);
            }
            else
            {
                lastFailedLoginDate = DateTime.MinValue;
            }
            if (fields[13] != "-")
            {
                lastFailedLoginIP = IPAddress.Parse(fields[13]);
            }
            else
            {
                lastFailedLoginIP = IPAddress.None;
            }
            failedLoginCount = Int16.Parse(fields[14]);

            firstLoginDate    = DateTime.Parse(fields[15]);
            lastLoginDate     = DateTime.Parse(fields[16]);
            totalTimeOnServer = TimeSpan.Parse(fields[17]);

            blocksBuilt      = Int32.Parse(fields[18]);
            blocksDeleted    = Int32.Parse(fields[19]);
            timesVisited     = Int16.Parse(fields[20]);
            linesWritten     = Int32.Parse(fields[21]);
            thanksReceived   = Int16.Parse(fields[22]);
            warningsReceived = Int16.Parse(fields[23]);
        }
Esempio n. 40
0
        // Parses message incoming from the player
        public void ParseMessage(string message, bool fromConsole)
        {
            if (DateTime.Now < mutedUntil)
            {
                return;
            }
            switch (Commands.GetMessageType(message))
            {
            case MessageType.Chat:
                if (CheckChatSpam())
                {
                    return;
                }
                info.linesWritten++;
                string displayedName = nick;
                if (world.config.GetBool("ClassPrefixesInChat"))
                {
                    displayedName = info.playerClass.prefix + displayedName;
                }
                if (world.config.GetBool("ClassColorsInChat") && info.playerClass.color != "" && info.playerClass.color != Color.White)
                {
                    displayedName = info.playerClass.color + displayedName + Color.White;
                }
                world.SendToAll(PacketWriter.MakeMessage(displayedName + ": " + message), null);
                world.log.Log("{0}: {1}", LogType.Chat, name, message);
                break;

            case MessageType.Command:
                world.log.Log("{0}: {1}", LogType.UserCommand, name, message);
                world.cmd.ParseCommand(this, message, fromConsole);
                break;

            case MessageType.PrivateChat:
                if (CheckChatSpam())
                {
                    return;
                }
                string otherPlayerName = message.Substring(1, message.IndexOf(' ') - 1);
                Player otherPlayer     = world.FindPlayer(otherPlayerName);
                if (otherPlayer != null)
                {
                    world.log.Log("{0} to {1}: {2}", LogType.Chat, name, otherPlayer.name, message);
                    otherPlayer.Send(PacketWriter.MakeMessage(Color.Gray + "from " + name + ": " + message.Substring(message.IndexOf(' ') + 1)));
                    Send(PacketWriter.MakeMessage(Color.Gray + "to " + otherPlayer.name + ": " + message.Substring(message.IndexOf(' ') + 1)));
                }
                else
                {
                    world.NoPlayerMessage(this, otherPlayerName);
                }
                break;

            case MessageType.ClassChat:
                if (CheckChatSpam())
                {
                    return;
                }
                string      className   = message.Substring(2, message.IndexOf(' ') - 2);
                PlayerClass playerClass = world.classes.FindClass(className);
                if (playerClass != null)
                {
                    world.log.Log("{0} to {1}: {2}", LogType.ClassChat, name, playerClass.name, message);
                    Packet classMsg = PacketWriter.MakeMessage(Color.Gray + "[" + playerClass.color + playerClass.name + Color.Gray + "]" + name + ": " + message.Substring(message.IndexOf(' ') + 1));
                    world.SendToClass(classMsg, playerClass);
                    if (info.playerClass != playerClass)
                    {
                        Send(classMsg);
                    }
                }
                else
                {
                    Message("No such class: \"" + className.Substring(1) + "\"");
                }
                break;
            }
        }