Example #1
1
 internal static void CModeWater(Player player, Command cmd)
 {
     if (!player.Can(Permissions.ControlPhysics))
     {
         player.NoAccessMessage(Permissions.ControlPhysics);
         return;
     }
     string blockpar = cmd.Next();
     string wmt = "";
     int BlockAddr = -1;
     try { BlockAddr = Convert.ToInt32(blockpar); }
     catch
     {
         player.Message("Incorrect parameter!"); return;
     }
     if (BlockAddr < 3 && BlockAddr >= 0)
     {
         player.world.map.modeWater = BlockAddr;
         switch (BlockAddr)
         {
             case 0: wmt = "'none'"; break;
             case 1: wmt = "'infinite'"; break;
             case 2: wmt = "'finite'"; break;
         }
         player.Message("Water mode set to " + wmt + ".");
     }
 }
Example #2
0
        internal static void Say(Player player, Command cmd)
        {
            if (player.Info.IsMuted)
            {
                player.MutedMessage();
                return;
            }

            if (player.Can(Permission.Say))
            {
                string msg = cmd.NextAll();
                if (player.Can(Permission.UseColorCodes) && msg.Contains("%"))
                {
                    msg = Color.ReplacePercentCodes(msg);
                }
                if (msg != null && msg.Trim().Length > 0)
                {
                    player.Info.LinesWritten++;
                    Server.SendToAllExceptIgnored(player, "&Y{0}", null, msg.Trim());
                    IRC.SendAction(String.Format("&Y{0}", msg.Trim()));
                }
                else
                {
                    cdSay.PrintUsage(player);
                }
            }
            else
            {
                player.NoAccessMessage(Permission.Say);
            }
        }
Example #3
0
        internal static void Help(Player player, Command cmd)
        {
            string commandName = cmd.Next();

            if (commandName == "commands")
            {
                cdCommands.Handler(player, cmd);
            }
            else if (commandName != null)
            {
                CommandDescriptor descriptor = CommandManager.GetDescriptor(commandName);
                if (descriptor == null)
                {
                    player.Message("Unknown command: \"{0}\"", commandName);
                    return;
                }
                StringBuilder sb = new StringBuilder(Color.Help);
                sb.Append(descriptor.Usage).Append("&N");

                if (descriptor.Aliases != null)
                {
                    sb.Append("Aliases: &H");
                    sb.Append(descriptor.Aliases.JoinToString("&S, &H"));
                    sb.Append("&N");
                }

                if (descriptor.HelpHandler != null)
                {
                    sb.Append(descriptor.HelpHandler(player));
                }
                else if (descriptor.Help != null)
                {
                    sb.Append(descriptor.Help);
                }
                else
                {
                    sb.Append("No help is available for this command.");
                }

                player.MessagePrefixed(HelpPrefix, sb.ToString());

                if (descriptor.Permissions != null && descriptor.Permissions.Length > 0)
                {
                    player.NoAccessMessage(descriptor.Permissions);
                }
            }
            else
            {
                player.Message("To see a list of all commands, write &H/help commands");
                player.Message("To see detailed help for a command, write &H/help CommandName");
                if (player != Player.Console)
                {
                    player.Message("To see your stats, write &H/info");
                }
                player.Message("To list available worlds, write &H/worlds");
                player.Message("To send private messages, write &H@PlayerName Message");
                player.Message("To message all players of a rank, write &H@@Rank Message");
            }
        }
Example #4
0
 internal static void Hardened(Player player, Command cmd)
 {
     if (player.hardenedMode == BlockPlacementMode.Hardened) {
         player.hardenedMode = BlockPlacementMode.Normal;
         player.Message("Hardened blocks: OFF");
     } else if (player.Can(Permissions.PlaceHardenedBlocks)) {
         player.hardenedMode = BlockPlacementMode.Hardened;
         player.Message("Hardened blocks: ON");
     } else {
         player.NoAccessMessage( Permissions.PlaceHardenedBlocks );
     }
 }
Example #5
0
 internal static void Grass( Player player, Command cmd )
 {
     if( player.mode == BlockPlacementMode.Grass ) {
         player.mode = BlockPlacementMode.Normal;
         player.Message( "Grass: OFF" );
     } else if( player.Can( Permissions.PlaceGrass ) ) {
         player.mode = BlockPlacementMode.Grass;
         player.Message( "Grass: ON. Dirt blocks are replaced with grass." );
     } else {
         player.NoAccessMessage( Permissions.PlaceGrass );
     }
 }
Example #6
0
 internal static void Bring( Player player, Command cmd )
 {
     if( player.Can( Permissions.Bring ) ) {
         string name = cmd.Next();
         Player target = player.world.FindPlayer( name );
         if( target != null ) {
             Position pos = player.pos;
             pos.x += 1;
             pos.y += 1;
             pos.h += 1;
             target.Send( PacketWriter.MakeTeleport( 255, pos ) );
         } else {
             player.NoPlayerMessage( name );
         }
     } else {
         player.NoAccessMessage( Permissions.Bring );
     }
 }
Example #7
0
        /// <summary> Parses and calls a specified command. </summary>
        /// <param name="player"> Player who issued the command. </param>
        /// <param name="cmd"> Command to be parsed and executed. </param>
        /// <param name="fromConsole"> Whether this command is being called from a non-player (e.g. Console). </param>
        public static void ParseCommand(Player player, Command cmd, bool fromConsole)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }
            CommandDescriptor descriptor = GetDescriptor(cmd.Name);

            if (descriptor == null)
            {
                player.Message("Unknown command \"{0}\". See &H/help commands", cmd.Name);
                return;
            }

            if (!descriptor.IsConsoleSafe && fromConsole)
            {
                player.Message("You cannot use this command from console.");
            }
            else
            {
                if (descriptor.Permissions != null)
                {
                    if (player.Can(descriptor.Permissions))
                    {
                        descriptor.Call(player, cmd, true);
                    }
                    else
                    {
                        player.NoAccessMessage(descriptor.Permissions);
                    }
                }
                else
                {
                    descriptor.Call(player, cmd, true);
                }
            }
        }
Example #8
0
        internal static void Say( Player player, Command cmd ) {
            if( player.Info.IsMuted ) {
                player.MutedMessage();
                return;
            }

            if( player.Can( Permission.Say ) ) {
                string msg = cmd.NextAll();
                if( player.Can( Permission.UseColorCodes ) && msg.Contains( "%" ) ) {
                    msg = Color.ReplacePercentCodes( msg );
                }
                if( msg != null && msg.Trim().Length > 0 ) {
                    player.Info.LinesWritten++;
                    Server.SendToAllExceptIgnored( player, "&Y{0}", null, msg.Trim() );
                    IRC.SendAction( String.Format( "&Y{0}", msg.Trim() ) );
                } else {
                    cdSay.PrintUsage( player );
                }
            } else {
                player.NoAccessMessage( Permission.Say );
            }
        }
Example #9
0
        internal static void DoBan( Player player, Command cmd, bool banIP, bool banAll, bool unban )
        {
            if( !player.Can( Permissions.Ban ) ) {
                player.NoAccessMessage( Permissions.Ban );
                return;
            } else if( banIP && !player.Can( Permissions.BanIP ) ) {
                player.NoAccessMessage( Permissions.BanIP );
                return;
            } else if( banAll && !player.Can( Permissions.BanAll ) ) {
                player.NoAccessMessage( Permissions.BanAll );
                return;
            }

            string arg = cmd.Next();
            string reason = cmd.NextAll();
            IPAddress address;
            Player offender = Server.FindPlayer( arg );
            PlayerInfo info = PlayerDB.FindPlayerInfoExact( arg );

            // ban by IP address
            if( banIP && IPAddress.TryParse( arg, out address ) ) {
                DoIPBan( player, address, reason, null, banAll, unban );

                // ban online players
            } else if( !unban && offender != null ) {

                // check permissions
                if( !player.info.playerClass.CanBan( offender.info.playerClass ) ) {
                    player.Message( "You can only ban players ranked " + player.info.playerClass.maxBan.color + player.info.playerClass.maxBan.name + Color.Sys + " or lower." );
                    player.Message( offender.GetLogName() + " is ranked " + offender.info.playerClass.name + "." );
                } else {
                    address = offender.info.lastIP;
                    if( banIP ) DoIPBan( player, address, reason, offender.name, banAll, unban );
                    if( offender.info.ProcessBan( player.name, reason ) ) {
                        Logger.Log( "{0} was banned by {1}.", LogType.UserActivity, offender.info.name, player.GetLogName() );
                        Server.SendToAll( Color.Red + offender.name + " was banned by " + player.nick, offender );
                        offender.session.Kick( "You were just banned by " + player.GetLogName() );
                    } else {
                        player.Message( offender.name + " is already banned." );
                    }
                }

                // ban offline players
            } else if( info != null ) {
                if( !player.info.playerClass.CanBan( info.playerClass ) ) {
                    PlayerClass maxRank = player.info.playerClass.maxBan;
                    if( maxRank == null ) {
                        player.Message( "You can only ban players ranked " + player.info.playerClass.color + player.info.playerClass.name + Color.Sys + " or lower." );
                    } else {
                        player.Message( "You can only ban players ranked " + maxRank.color + maxRank.name + Color.Sys + " or lower." );
                    }
                    player.Message( info.name + " is ranked " + info.playerClass.name + "." );
                } else {
                    address = info.lastIP;
                    if( banIP ) DoIPBan( player, address, reason, info.name, banAll, unban );
                    if( unban ) {
                        if( info.ProcessUnBan( player.name, reason ) ) {
                            Logger.Log( "{0} (offline) was unbanned by {1}", LogType.UserActivity, info.name, player.GetLogName() );
                            Server.SendToAll( Color.Red + info.name + " (offline) was unbanned by " + player.nick );
                        } else {
                            player.Message( info.name + " (offline) is not currenty banned." );
                        }
                    } else {
                        if( info.ProcessBan( player.name, reason ) ) {
                            Logger.Log( "{0} (offline) was banned by {1}.", LogType.UserActivity, info.name, player.GetLogName() );
                            Server.SendToAll( Color.Red + info.name + " (offline) was banned by " + player.nick );
                        } else {
                            player.Message( info.name + " (offline) is already banned." );
                        }
                    }
                }
            } else {
                player.NoPlayerMessage( arg );
                player.Message( "Use the FULL player name for ban/unban commands." );
            }
        }
Example #10
0
 internal static void Phyrem(Player player, Command cmd)
 {
     if (!player.Can(Permissions.ControlPhysics))
     {
         player.NoAccessMessage(Permissions.ControlPhysics);
         return;
     }
     string blockpar = cmd.Next();
     int BlockAddr = -1;
     try { BlockAddr = Convert.ToInt32(blockpar); }
     catch
     {
         try { BlockAddr = (int)Map.GetBlockByName(blockpar); }
         catch { player.Message("Incorrect parameter!"); return; }
     }
     if (BlockAddr < 0 || BlockAddr > 49) { player.Message("Incorrect parameter!"); return; }
     player.world.map.blockFlag[BlockAddr] &= 254;
     player.Message("Block '" + blockpar + "' is now un-hpysicsized!");
 }
Example #11
0
 internal static void Unhide( Player player, Command cmd )
 {
     if( player.Can( Permissions.Hide ) ) {
         if( player.isHidden ) {
             player.Message( Color.Gray, "You are no longer hidden." );
             if( player.nick != player.name ) {
                 player.nick = player.name;
                 player.Message( "For security reasons, your nick was reset." );
             }
             player.world.SendToAll( PacketWriter.MakeAddEntity( player, player.pos ), player );
             Server.SendToAll( String.Format( "{0}{1} ({2}{3}{0}) has joined the server.",
                                              Color.Sys,
                                              player.name,
                                              player.info.playerClass.color,
                                              player.info.playerClass.name ),
                               player );
             player.isHidden = false;
         } else {
             player.Message( "You are not currently hidden." );
         }
     } else {
         player.NoAccessMessage( Permissions.Hide );
     }
 }
Example #12
0
        // Change player class
        internal static 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 = Server.FindPlayer( name );
            if( target == null ) {
                player.NoPlayerMessage( name );
                return;
            }

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

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

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

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

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

            if( promote && target.info.playerClass.rank < newClass.rank ||
                target.info.playerClass.rank > newClass.rank ) {
                PlayerClass oldClass = target.info.playerClass;
                if( !Server.FirePlayerClassChange( target, player, oldClass, newClass ) ) return;

                Logger.Log( "{0} changed the class of {1} from {2} to {3}.", LogType.UserActivity,
                            player.GetLogName(), target.GetLogName(), target.info.playerClass.name, newClass.name );
                target.info.playerClass = newClass;
                target.info.classChangeDate = DateTime.Now;
                target.info.classChangedBy = player.name;

                Server.FirePlayerListChangedEvent();

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

                target.mode = BlockPlacementMode.Normal;
                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.nick );
                } 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.nick );
                }
                if( Config.GetBool( ConfigKey.ClassPrefixesInList ) || Config.GetBool( ConfigKey.ClassColorsInChat ) ) {
                    target.world.UpdatePlayer( target );
                }
            } else {
                if( promote ) {
                    player.Message( target.GetLogName() + " is already same or lower rank than " + newClass.name );
                } else {
                    player.Message( target.GetLogName() + " is already same or higher rank than " + newClass.name );
                }
            }
        }
Example #13
0
 internal static void SetSpawn( Player player, Command cmd )
 {
     if( player.Can( Permissions.SetSpawn ) ) {
         player.world.map.spawn = player.pos;
         player.world.map.changesSinceSave++;
         player.Send( PacketWriter.MakeTeleport( 255, player.world.map.spawn ), true );
         player.Message( "New spawn point saved." );
         Logger.Log( "{0} changed the spawned point.", LogType.UserActivity, player.GetLogName() );
     } else {
         player.NoAccessMessage( Permissions.SetSpawn );
     }
 }
Example #14
0
        internal static void Nick( Player player, Command cmd )
        {
            if( !player.Can( Permissions.ChangeName ) ) {
                player.NoAccessMessage( Permissions.ChangeName );
                return;
            }

            string name = cmd.Next();
            if( name == null ) {
                if( player.nick != player.name ) {
                    Server.SendToAll( Color.Sys + player.nick + " reset their name back to \"" + player.name + "\"", player );
                    player.Message( "You name is reset back to \"" + player.name + "\"" );
                    player.nick = player.name;
                    if( player.world != null ) player.world.UpdatePlayer( player );
                } else {
                    player.Message( "You do not have a nickname set." );
                }
            } else if( Player.IsValidName( name ) ) {
                Server.SendToAll( Color.Sys + player.nick + " is now known as " + name, player );
                player.Message( "You are now known as " + name + ". Use " + Color.Help + "/nick" + Color.Sys + " again to reset." );
                player.nick = name;
                if( player.world != null ) player.world.UpdatePlayer( player );
            } else {
                player.Message( "Invalid player name." );
            }
        }
Example #15
0
        internal static void Info(Player player, Command cmd)
        {
            string name = cmd.Next();

            if (name == null)
            {
                name = player.Name;
            }
            else if (!player.Can(Permission.ViewOthersInfo))
            {
                player.NoAccessMessage(Permission.ViewOthersInfo);
                return;
            }

            IPAddress ip;

            PlayerInfo[] infos;
            if (Server.IsIP(name) && IPAddress.TryParse(name, out ip))
            {
                // find players by IP
                infos = PlayerDB.FindPlayers(ip, PlayerDB.NumberOfMatchesToPrint);
            }
            else if (name.Contains("*") || name.Contains("."))
            {
                // find players by regex/wildcard
                string regexString = "^" + RegexNonNameChars.Replace(name, "").Replace("*", ".*") + "$";
                Regex  regex       = new Regex(regexString, RegexOptions.IgnoreCase | RegexOptions.Compiled);
                infos = PlayerDB.FindPlayers(regex, PlayerDB.NumberOfMatchesToPrint);
            }
            else
            {
                // find players by partial matching
                PlayerInfo tempInfo;
                if (!PlayerDB.FindPlayerInfo(name, out tempInfo))
                {
                    infos = PlayerDB.FindPlayers(name, PlayerDB.NumberOfMatchesToPrint);
                }
                else if (tempInfo == null)
                {
                    player.NoPlayerMessage(name);
                    return;
                }
                else
                {
                    infos = new[] { tempInfo };
                }
            }

            if (infos.Length == 1)
            {
                PrintPlayerInfo(player, infos[0]);
            }
            else if (infos.Length > 1)
            {
                player.ManyMatchesMessage("player", infos);
                if (infos.Length == PlayerDB.NumberOfMatchesToPrint)
                {
                    player.Message("NOTE: Only first {0} matches are shown.", PlayerDB.NumberOfMatchesToPrint);
                }
            }
            else
            {
                player.NoPlayerMessage(name);
            }
        }
Example #16
0
        internal static void WorldBuild( Player player, Command cmd )
        {
            string worldName = cmd.Next();
            string className = cmd.Next();

            if( worldName == null ) {
                if( player.world != null ) {
                    if( player.world.classBuild == ClassList.lowestClass ) {
                        player.Message( "This world (" + player.world.name + ") can be modified by anyone." );
                    } else {
                        player.Message( "This world (" + player.world.name + ") can only be modified by " + player.world.classBuild.color + player.world.classBuild.name + "+" );
                    }
                } else {
                    player.Message( "When calling /waccess from console, you must specify the world name." );
                }
                return;
            }

            World world = Server.FindWorld( worldName );
            if( world == null ) {
                player.Message( "No world \"" + worldName + "\" found." );
            } else if( className == null ) {
                if( world.classBuild == ClassList.lowestClass ) {
                    player.Message( "World \"" + world.name + "\" can be modified by anyone." );
                } else {
                    player.Message( "World \"" + world.name + "\" can be only modified by " + world.classBuild.color + world.classBuild.name + "+" );
                }
            } else if( player.Can( Permissions.ManageWorlds ) ) {
                PlayerClass playerClass = ClassList.FindClass( className );
                if( playerClass == null ) {
                    player.Message( "No class \"" + className + "\" found." );
                } else{
                    world.classBuild = playerClass;
                    Server.SaveWorldList();
                    if( world.classBuild == ClassList.lowestClass ) {
                        Server.SendToAll( Color.Sys + player.nick + " made the world \"" + world.name + "\" modifiable by anyone." );
                    } else {
                        Server.SendToAll( Color.Sys + player.nick + " made the world \"" + world.name + "\" modifiable only by " + world.classBuild.color + world.classBuild.name + "+" );
                    }
                    Logger.Log( player.GetLogName() + " made the world \"" + world.name + "\" modifiable by " + world.classBuild.name + "+", LogType.UserActivity );
                }
            } else {
                player.NoAccessMessage( Permissions.ManageWorlds );
            }
        }
Example #17
0
 internal static void UnlockAll( Player player, Command cmd )
 {
     if( !player.Can( Permissions.Lock ) ) {
         player.NoAccessMessage( Permissions.Lock );
         return;
     } else {
         lock( Server.worldListLock ) {
             foreach( World world in Server.worlds.Values ) {
                 world.Unlock();
             }
         }
         player.Message( "All worlds are now unlocked." );
     }
 }
Example #18
0
 internal static void Unlock( Player player, Command cmd )
 {
     if( !player.Can( Permissions.Lock ) ) {
         player.NoAccessMessage( Permissions.Lock );
         return;
     }
     string worldName = cmd.Next();
     World world = player.world;
     if( worldName != null ) {
         world = Server.FindWorld( worldName );
         if( world == null ) {
             player.Message( "No world found with the name \"" + worldName + "\"." );
             return;
         }
     }
     if( !world.isLocked ) {
         player.Message( "The world is already unlocked." );
     } else {
         world.Unlock();
     }
 }
Example #19
0
 internal static void S_Physics(Player player, Command cmd)
 {
     if (player.Can(Permissions.ControlPhysics))
     {
         if (player.world.map.physicsOn == true)
         {
             player.world.map.physicsOn = false;
             Server.SendToAll(player.name + " set physics to OFF.");
             player.world.map.ClearUpdateQueue();
         }
         else
         {
             player.world.map.physicsOn = true;
             Server.SendToAll(player.name + " set physics to ON.");
         }
     }
     else
     {
         player.NoAccessMessage(Permissions.ControlPhysics);
     }
 }
Example #20
0
 internal static void SwitchLogic3d(Player player, Command cmd)
 {
     if (player.Can(Permissions.SwitchLogic))
     {
         if (player.world.map.logicOn3D == true)
         {
             player.world.map.logicOn3D = false;
             Server.SendToAll(player.name + " set 3D logic mode to OFF.");
         }
         else
         {
             player.world.map.logicOn3D = true;
             Server.SendToAll(player.name + " set 3D logic mode to ON.");
         }
     }
     else
     {
         player.NoAccessMessage(Permissions.SwitchLogic);
     }
 }
Example #21
0
 internal static void SwitchLogic(Player player, Command cmd)
 {
     if (player.Can(Permissions.SwitchLogic))
     {
         if (player.world.map.logicOn == true)
         {
             player.world.map.logicOn = false;
             Server.SendToAll(player.name + " set logic features to OFF.");
             player.world.map.ClearUpdateQueue();
         }
         else
         {
             player.world.map.logicOn = true;
             Server.SendToAll(player.name + " set logic features to ON.");
         }
     }
     else
     {
         player.NoAccessMessage(Permissions.SwitchLogic);
     }
 }
Example #22
0
        internal static void Save( Player player, Command cmd )
        {
            if( !player.Can( Permissions.ManageWorlds ) ) {
                player.NoAccessMessage( Permissions.ManageWorlds );
                return;
            }

            string mapName = cmd.Next();
            if( mapName == null ) {
                player.Message( "Syntax: " + Color.Help + "/save mapName" );
                return;
            }

            string mapFileName = Path.GetFileName( mapName ) + ".fcm";
            player.Message( "Saving map to \"" + mapFileName + "\"..." );
            if( player.world.map.Save( mapFileName ) ) {
                player.Message( "Map saved succesfully." );
            } else {
                player.Message( "Map saving failed. See server logs for details." );
            }
        }
Example #23
0
 internal static void Freeze( Player player, Command cmd )
 {
     if( player.Can( Permissions.Freeze ) ) {
         string name = cmd.Next();
         Player target = Server.FindPlayer( name );
         if( target != null ) {
             if( !target.isFrozen ) {
                 Server.SendToAll( Color.Sys + target.nick + " has been frozen by " + player.nick );
                 target.isFrozen = true;
             } else {
                 player.Message( target.GetLogName() + " is already frozen." );
             }
         } else {
             player.NoPlayerMessage( name );
         }
     } else {
         player.NoAccessMessage( Permissions.Freeze );
     }
 }
Example #24
0
 internal static void Hide( Player player, Command cmd )
 {
     if( player.Can( Permissions.Hide ) ) {
         if( !player.isHidden ) {
             Server.SendToAll( PacketWriter.MakeRemoveEntity( player.id ), null );
             Server.SendToAll( Color.Sys + player.nick + " left the server." );
             player.isHidden = true;
             player.Message( Color.Gray, "You are now hidden." );
             player.nick = player.name;
         } else {
             player.Message( "You are already hidden." );
         }
     } else {
         player.NoAccessMessage( Permissions.Hide );
     }
 }
Example #25
0
        internal static void WorldLoad( Player player, Command cmd )
        {
            if( !player.Can( Permissions.ManageWorlds ) ) {
                player.NoAccessMessage( Permissions.ManageWorlds );
                return;
            }

            string fileName = cmd.Next();
            string worldName = cmd.Next();

            if( worldName == null && player.world == null ) {
                player.Message( "When using /wload from console, you must specify the world name." );
                return;
            }

            if( fileName == null ) {
                // No params given at all
                player.Message( "See " + Color.Help + "/help wload" + Color.Sys + " for usage syntax." );
                return;
            }

            Logger.Log( "Player {0} is attempting to load map \"{1}\"...", LogType.UserActivity,
                        player.GetLogName(),
                        fileName );
            player.Message( "Attempting to load " + fileName + "..." );

            Map map = Map.Load( player.world, fileName );
            if( map == null ) {
                player.Message( "Could not load specified file." );
                return;
            }

            if( worldName == null ) {
                // Loading to current world
                player.world.ChangeMap( map );
                player.world.SendToAll( Color.Sys + player.nick + " loaded a new map for the world \"" + player.world.name + "\".", player );
                player.Message( "New map for the world \"" + player.world.name + "\" has been loaded." );

                Logger.Log( player.GetLogName() + " loaded new map for " + player.world.name + " from " + fileName, LogType.UserActivity );

            } else {
                // Loading to some other (or new) world
                if( !Player.IsValidName( worldName ) ) {
                    player.Message( "Invalid world name: \"" + worldName + "\"." );
                    return;
                }

                lock( Server.worldListLock ) {
                    World world = Server.FindWorld( worldName );
                    if( world != null ) {
                        // Replacing existing world's map
                        world.ChangeMap( map );
                        world.SendToAll( Color.Sys + player.nick + " loaded a new map for the world \"" + world.name + "\".", player );
                        player.Message( "New map for the world \"" + world.name + "\" has been loaded." );
                        Logger.Log( player.GetLogName() + " loaded new map for world \"" + world.name + "\" from " + fileName, LogType.UserActivity );

                    } else {
                        // Adding a new world
                        if( Server.AddWorld( worldName, map, false ) != null ) {
                            Server.SendToAll( Color.Sys + player.nick + " created a new world named \"" + worldName + "\"." );
                            Logger.Log( player.GetLogName() + " created a new world named \"" + worldName + "\".", LogType.UserActivity );
                            Server.SaveWorldList();
                        } else {
                            player.Message( "Error occured while trying to create a new world." );
                        }
                    }
                }
            }

            GC.Collect( GC.MaxGeneration, GCCollectionMode.Optimized );
        }
Example #26
0
        // Kick a player. One argument (mandatory) - player name (can be partial).
        internal static void Kick( Player player, Command cmd )
        {
            if( !player.Can( Permissions.Kick ) ) {
                player.NoAccessMessage( Permissions.Kick );
                return;
            }

            string name = cmd.Next();
            if( name != null ) {
                string msg = cmd.NextAll();
                Player offender = Server.FindPlayer( name );
                if( offender != null ) {
                    if( !player.info.playerClass.CanKick( offender.info.playerClass ) ) {
                        player.Message( "You can only kick players ranked " + player.info.playerClass.maxKick.color + player.info.playerClass.maxKick.name + Color.Sys + " or lower." );
                        player.Message( offender.GetLogName() + " is ranked " + offender.info.playerClass.name + "." );
                    } else {
                        Server.SendToAll( Color.Red + offender.nick + " was kicked by " + player.nick );
                        if( msg != null && msg != "" ) {
                            Logger.Log( "{0} was kicked by {1}. Memo: {2}", LogType.UserActivity, offender.GetLogName(), player.GetLogName(), msg );
                            offender.session.Kick( "Kicked by " + player.GetLogName() + ": " + msg );
                        } else {
                            Logger.Log( "{0} was kicked by {1}", LogType.UserActivity, offender.GetLogName(), player.GetLogName() );
                            offender.session.Kick( "You have been kicked by " + player.GetLogName() );
                        }
                    }
                } else {
                    player.NoPlayerMessage( name );
                }
            } else {
                player.Message( "Usage: " + Color.Help + "/kick PlayerName [Message]" +
                                   Color.Sys + " or " + Color.Help + "/k PlayerName [Message]" );
            }
        }
Example #27
0
        internal static void BanInfo(Player player, Command cmd)
        {
            string    name = cmd.Next();
            IPAddress address;

            if (name == null)
            {
                name = player.Name;
            }
            else if (!player.Can(Permission.ViewOthersInfo))
            {
                player.NoAccessMessage(Permission.ViewOthersInfo);
                return;
            }

            if (Server.IsIP(name) && IPAddress.TryParse(name, out address))
            {
                IPBanInfo info = IPBanList.Get(address);
                if (info != null)
                {
                    player.Message("{0} was banned by {1} on {2:dd MMM yyyy}.",
                                   info.Address,
                                   info.BannedBy,
                                   info.BanDate);
                    if (!String.IsNullOrEmpty(info.PlayerName))
                    {
                        player.Message("  IP ban was banned by association with {0}",
                                       info.PlayerName);
                    }
                    if (info.Attempts > 0)
                    {
                        player.Message("  There have been {0} attempts to log in, most recently", info.Attempts);
                        player.Message("  on {0:dd MMM yyyy} by {1}.",
                                       info.LastAttemptDate,
                                       info.LastAttemptName);
                    }
                    if (info.BanReason.Length > 0)
                    {
                        player.Message("  Ban reason: {0}", info.BanReason);
                    }
                }
                else
                {
                    player.Message("{0} is currently NOT banned.", address);
                }
            }
            else
            {
                PlayerInfo info;
                if (!PlayerDB.FindPlayerInfo(name, out info))
                {
                    player.Message("More than one player found matching \"{0}\"", name);
                }
                else if (info != null)
                {
                    if (info.Banned)
                    {
                        player.Message("Player {0}&S is &WBANNED", info.GetClassyName());
                    }
                    else
                    {
                        player.Message("Player {0}&S is NOT banned.", info.GetClassyName());
                    }
                    if (!String.IsNullOrEmpty(info.BannedBy))
                    {
                        player.Message("  Last ban by {0} on {1:dd MMM yyyy} ({2} ago).",
                                       info.BannedBy,
                                       info.BanDate,
                                       info.TimeSinceBan.ToMiniString());
                        if (info.BanReason.Length > 0)
                        {
                            player.Message("  Last ban reason: {0}", info.BanReason);
                        }
                    }
                    if (!String.IsNullOrEmpty(info.UnbannedBy))
                    {
                        player.Message("  Unbanned by {0} on {1:dd MMM yyyy} ({2} ago).",
                                       info.UnbannedBy,
                                       info.UnbanDate,
                                       info.TimeSinceUnban.ToMiniString());
                        if (info.UnbanReason.Length > 0)
                        {
                            player.Message("  Last unban reason: {0}", info.UnbanReason);
                        }
                    }
                    if (info.BanDate != DateTime.MinValue)
                    {
                        TimeSpan banDuration;
                        if (info.Banned)
                        {
                            banDuration = info.TimeSinceBan;
                        }
                        else
                        {
                            banDuration = info.UnbanDate.Subtract(info.BanDate);
                        }
                        player.Message("  Last ban duration: {0} days and {1:F1} hours.",
                                       (int)banDuration.TotalDays,
                                       banDuration.TotalHours);
                    }
                }
                else
                {
                    player.NoPlayerMessage(name);
                }
            }
        }
Example #28
0
 internal static void Say( Player player, Command cmd )
 {
     if( player.Can( Permissions.Say ) ) {
         string msg = cmd.NextAll();
         if( msg != null && msg.Trim().Length > 0 ) {
             Server.SendToAll( Color.Say + msg.Trim() );
         } else {
             player.Message( "Usage: " + Color.Help + "/say message" );
         }
     } else {
         player.NoAccessMessage( Permissions.Say );
     }
 }
Example #29
0
        internal static void WorldRemove( Player player, Command cmd )
        {
            if( !player.Can( Permissions.ManageWorlds ) ) {
                player.NoAccessMessage( Permissions.ManageWorlds );
                return;
            }

            string worldName = cmd.Next();
            if( worldName == null ) {
                player.Message( "Syntax: " + Color.Help + "/wremove WorldName" );
                return;
            }

            lock( Server.worldListLock ) {
                World world = Server.FindWorld( worldName );
                if( world == null ) {
                    player.Message( "World not found: " + worldName );
                } else if( world == Server.mainWorld ) {
                    player.Message( "Deleting the main world is not allowed. Assign a new main first." );
                } else{
                    Server.RemoveWorld( worldName );
                    Server.SendToAll( Color.Sys + player.nick + " deleted the world \"" + world.name + "\"", player );
                    player.Message( "Removed \"" + world.name + "\" from the world list." );
                    player.Message( "You can now delete the map file (" + world.name + ".fcm) manually." );
                }
            }

            GC.Collect( GC.MaxGeneration, GCCollectionMode.Optimized );
        }
Example #30
0
 internal static void TP( Player player, Command cmd )
 {
     if( player.Can( Permissions.Teleport ) ) {
         string name = cmd.Next();
         if( name == null ) {
             player.Send( PacketWriter.MakeTeleport( 255, player.world.map.spawn ) );
         } else {
             Player target = player.world.FindPlayer( name );
             if( target != null ) {
                 Position pos = target.pos;
                 pos.x += 1;
                 pos.y += 1;
                 pos.h += 1;
                 player.Send( PacketWriter.MakeTeleport( 255, pos ) );
             } else if( cmd.Next() == null ) {
                 player.NoPlayerMessage( name );
             } else {
                 cmd.Rewind();
                 int x, y, h;
                 if( cmd.NextInt( out x ) && cmd.NextInt( out y ) && cmd.NextInt( out h ) ) {
                     if( x < 0 || x > player.world.map.widthX ||
                          y < 0 || y > player.world.map.widthY ||
                          y < 0 || y > player.world.map.height ) {
                         player.Message( "Specified coordinates are outside the map!" );
                     } else {
                         player.pos.Set( x * 32 + 16, y * 32 + 16, h * 32 + 16, player.pos.r, player.pos.l );
                         player.Send( PacketWriter.MakeTeleport( 255, player.pos ) );
                     }
                 } else {
                     player.Message( "See " + Color.Help + "/help tp" + Color.Sys + " for information on using /tp" );
                 }
             }
         }
     } else {
         player.NoAccessMessage( Permissions.Teleport );
     }
 }
Example #31
0
        internal static void WorldRename( Player player, Command cmd )
        {
            if( !player.Can( Permissions.ManageWorlds ) ) {
                player.NoAccessMessage( Permissions.ManageWorlds );
                return;
            }

            string oldName = cmd.Next();
            string newName = cmd.Next();
            if( oldName == null || newName == null ) {
                player.Message( "Syntax: " + Color.Help + "/wrename OldName NewName" );
                return;
            }

            lock( Server.worldListLock ) {
                World oldWorld = Server.FindWorld( oldName );
                World newWorld = Server.FindWorld( newName );

                if( oldWorld == null ) {
                    player.Message( "No world found with the specified name: " + oldName );
                } else if( newWorld != null ) {
                    player.Message( "A world with the specified name already exists: " + newName );
                } else {
                    oldName = oldWorld.name;
                    Server.RenameWorld( oldName, newName );
                    File.Move( oldName + ".fcm", newName + ".fcm" );
                    Server.SaveWorldList();
                    Server.SendToAll( Color.Sys + player.nick + " renamed the world \"" + oldName + "\" to \"" + newName + "\"." );
                    Logger.Log( player.GetLogName() + " renamed the world \"" + oldName + "\" to \"" + newName + "\".", LogType.UserActivity );
                }
            }
        }
Example #32
0
 internal static void Unfreeze( Player player, Command cmd )
 {
     if( player.Can( Permissions.Freeze ) ) {
         string name = cmd.Next();
         Player target = Server.FindPlayer( name );
         if( target != null ) {
             if( target.isFrozen ) {
                 Server.SendToAll( Color.Sys + target.nick + " is no longer frozen." );
                 target.isFrozen = false;
             } else {
                 player.Message( target.GetLogName() + " is currently not frozen." );
             }
         } else {
             player.NoPlayerMessage( name );
         }
     } else {
         player.NoAccessMessage( Permissions.Freeze );
     }
 }
Example #33
0
        internal static void ZoneAdd( Player player, Command cmd )
        {
            //TODO: better method names & documentation
            if( !player.Can( Permissions.ManageZones ) ) {
                player.NoAccessMessage( Permissions.ManageZones );
                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[] zones = player.world.map.ListZones();
            if( zones.Length > 0 ) {
                foreach (Zone zonel in zones)
                {
                    if (zonel.name == name)
                    {
                        player.Message("Zone '" + name + "' already exists!");
                        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 = ClassList.ParseClass( property );

            if( minRank != null ) {
                zone.buildRank = minRank.rank;
                player.tag = zone;
                player.marksExpected = 2;
                player.marks.Clear();
                player.markCount = 0;
                player.selectionCallback = ZoneAddCallback;
                player.Message( "Zone: Place a block or type /mark to use your location." );
            } else {
                player.Message( "Unknown player class: " + property );
            }
        }
Example #34
0
        internal static void WorldMain( Player player, Command cmd )
        {
            string worldName = cmd.Next();
            if( worldName == null ) {
                player.Message( "Usage: " + Color.Help + "/wmain WorldName" );
                return;
            }
            World world = Server.FindWorld( worldName );
            if( world == null ) {
                player.Message( "No world \"" + worldName + "\" found." );
            } else if( world == Server.mainWorld ) {
                player.Message( "World \"" + world.name + "\" is already set as main." );
            } else if( player.Can( Permissions.ManageWorlds ) ) {
                if( world.classAccess != ClassList.lowestClass ) {
                    world.classAccess = ClassList.lowestClass;
                    player.Message( "The main world cannot have access restrictions." );
                    player.Message( "Access restrictions were removed from world \"" + world.name + "\"" );
                }
                world.neverUnload = false;
                world.LoadMap();
                Server.mainWorld.neverUnload = true;
                Server.mainWorld = world;
                Server.SaveWorldList();

                Server.SendToAll( Color.Sys + player.nick + " set \"" + world.name + "\" to be the main world." );
                Logger.Log( player.GetLogName() + " set \"" + world.name + "\" to be the main world.", LogType.UserActivity );
            } else {
                player.NoAccessMessage( Permissions.ManageWorlds );
            }
        }
Example #35
0
 internal static void ZoneRemove( Player player, Command cmd )
 {
     if( !player.Can( Permissions.ManageZones ) ) {
         player.NoAccessMessage( Permissions.ManageZones );
         return;
     }
     string zoneName = cmd.Next();
     if( zoneName == null ) {
         player.Message( "Usage: " + Color.Help + "/zremove ZoneName" );
         return;
     }
     if( player.world.map.RemoveZone( zoneName ) ) {
         player.Message( "Zone \"" + zoneName + "\" removed." );
     } else {
         player.Message( "No zone with the name \"" + zoneName + "\" was found." );
     }
 }