Пример #1
0
        static void MassRankHandler(Player player, CommandReader cmd)
        {
            string fromRankName = cmd.Next();
            string toRankName   = cmd.Next();
            string reason       = cmd.NextAll();

            if (fromRankName == null || toRankName == null)
            {
                CdMassRank.PrintUsage(player);
                return;
            }

            Rank fromRank = RankManager.FindRank(fromRankName);

            if (fromRank == null)
            {
                player.MessageNoRank(fromRankName);
                return;
            }

            Rank toRank = RankManager.FindRank(toRankName);

            if (toRank == null)
            {
                player.MessageNoRank(toRankName);
                return;
            }

            if (fromRank == toRank)
            {
                player.Message("Ranks must be different");
                return;
            }

            int playerCount;

            using (PlayerDB.GetReadLock()) {
                playerCount = PlayerDB.List.Count(t => t.Rank == fromRank);
            }
            string verb = (fromRank > toRank ? "demot" : "promot");

            if (!cmd.IsConfirmed)
            {
                player.Confirm(cmd, "MassRank: {0}e {1} players?", verb.UppercaseFirst(), playerCount);
                return;
            }

            player.Message("MassRank: {0}ing {1} players...",
                           verb, playerCount);

            int affected = PlayerDB.MassRankChange(player, fromRank, toRank, reason);

            player.Message("MassRank: done, {0} records affected.", affected);
        }
Пример #2
0
        static void InfoSwapHandler(Player player, CommandReader cmd)
        {
            string p1Name = cmd.Next();
            string p2Name = cmd.Next();

            if (p1Name == null || p2Name == null)
            {
                CdInfoSwap.PrintUsage(player);
                return;
            }

            PlayerInfo p1 = PlayerDB.FindByPartialNameOrPrintMatches(player, p1Name);

            if (p1 == null)
            {
                return;
            }
            PlayerInfo p2 = PlayerDB.FindByPartialNameOrPrintMatches(player, p2Name);

            if (p2 == null)
            {
                return;
            }

            if (p1 == p2)
            {
                player.Message("InfoSwap: Please specify 2 different players.");
                return;
            }

            if (p1.IsOnline || p2.IsOnline)
            {
                player.Message("InfoSwap: Both players must be offline to swap info.");
                return;
            }

            if (!cmd.IsConfirmed)
            {
                player.Confirm(cmd, "InfoSwap: Swap stats of players {0}&S and {1}&S?", p1.ClassyName, p2.ClassyName);
            }
            else
            {
                PlayerDB.SwapPlayerInfo(p1, p2);
                player.Message("InfoSwap: Stats of {0}&S and {1}&S have been swapped.",
                               p1.ClassyName, p2.ClassyName);
            }
        }
Пример #3
0
        private static void ZoneRemoveHandler(Player player, Command cmd)
        {
            string zoneName = cmd.Next();

            if (zoneName == null)
            {
                CdZoneRemove.PrintUsage(player);
                return;
            }

            ZoneCollection zones = player.WorldMap.Zones;
            Zone           zone  = zones.Find(zoneName);

            if (zone != null)
            {
                if (!player.Info.Rank.AllowSecurityCircumvention)
                {
                    switch (zone.Controller.CheckDetailed(player.Info))
                    {
                    case SecurityCheckResult.BlackListed:
                        player.Message("You are not allowed to remove zone {0}: you are blacklisted.",
                                       zone.ClassyName);
                        return;

                    case SecurityCheckResult.RankTooLow:
                        player.Message("You are not allowed to remove zone {0}.", zone.ClassyName);
                        return;
                    }
                }
                if (!cmd.IsConfirmed)
                {
                    player.Confirm(cmd, "Remove zone {0}&S?", zone.ClassyName);
                    return;
                }

                if (zones.Remove(zone.Name))
                {
                    player.Message("Zone \"{0}\" removed.", zone.Name);
                }
            }
            else
            {
                player.MessageNoZone(zoneName);
            }
        }
Пример #4
0
        static void RankHandler( Player player, CommandReader cmd ) {
            string name = cmd.Next();
            string newRankName = cmd.Next();

            // Check arguments
            if( name == null || newRankName == null ) {
                CdRank.PrintUsage( player );
                player.Message( "See &H/Ranks&S for list of ranks." );
                return;
            }

            // Parse rank name
            Rank newRank = RankManager.FindRank( newRankName );
            if( newRank == null ) {
                player.MessageNoRank( newRankName );
                return;
            }

            if( name == "-" ) {
                if( player.LastUsedPlayerName != null ) {
                    name = player.LastUsedPlayerName;
                } else {
                    player.Message( "Cannot repeat player name: you haven't used any names yet." );
                    return;
                }
            }
            PlayerInfo targetInfo;

            // Find player by name
            if( name.StartsWith( "!" ) ) {
                name = name.Substring( 1 );
                Player target = Server.FindPlayerExact( player, name, false );
                if( target == null ) {
                    player.MessageNoPlayer( name );
                    return;
                }
                targetInfo = target.Info;
            } else {
                targetInfo = PlayerDB.FindPlayerInfoExact( name );
            }

            // Handle non-existent players
            if( targetInfo == null ) {
                if( !player.Can( Permission.EditPlayerDB ) ) {
                    player.MessageNoPlayer( name );
                    return;
                }
                if( !Player.IsValidName( name ) ) {
                    player.MessageInvalidPlayerName( name );
                    CdRank.PrintUsage( player );
                    return;
                }
                if( cmd.IsConfirmed ) {
                    if( newRank > RankManager.DefaultRank ) {
                        targetInfo = PlayerDB.AddFakeEntry( name, RankChangeType.Promoted );
                    } else {
                        targetInfo = PlayerDB.AddFakeEntry( name, RankChangeType.Demoted );
                    }
                } else {
                    Logger.Log( LogType.UserActivity,
                                "Rank: Asked {0} to confirm adding unrecognized name \"{1}\" to the database.",
                                player.Name, name );
                    player.Confirm( cmd,
                                    "Warning: Player \"{0}\" is not in the database (possible typo). Type the full name or",
                                    name );
                    return;
                }
            }

            try {
                player.LastUsedPlayerName = targetInfo.Name;
                targetInfo.ChangeRank( player, newRank, cmd.NextAll(), true, true, false );
            } catch( PlayerOpException ex ) {
                player.Message( ex.MessageColored );
            }
        }
Пример #5
0
        static void UndoAreaTimeSelectionCallback( Player player, Vector3I[] marks, object tag )
        {
            World playerWorld = player.World;
            if( playerWorld == null ) PlayerOpException.ThrowNoWorld( player );

            UndoAreaTimeArgs args = (UndoAreaTimeArgs)tag;
            args.World = playerWorld;
            args.Area = new BoundingBox( marks[0], marks[1] );
            BlockDBEntry[] changes = playerWorld.BlockDB.Lookup( args.Target, args.Area, args.Time );
            if( changes.Length > 0 ) {
                player.Confirm( UndoAreaTimeConfirmCallback, args, "Undo changes ({0}) made by {1}&S in this area in the last {2}?",
                                changes.Length, args.Target.ClassyName, args.Time.ToMiniString() );
            } else {
                player.Message( "UndoArea: Nothing to undo in this area." );
            }
        }
Пример #6
0
        static void ZoneRemoveHandler( Player player, Command cmd )
        {
            string zoneName = cmd.Next();
            if( zoneName == null ) {
                CdZoneRemove.PrintUsage( player );
                return;
            }

            ZoneCollection zones = player.WorldMap.Zones;
            Zone zone = zones.Find( zoneName );
            if( zone != null ) {
                if( !player.Info.Rank.AllowSecurityCircumvention ) {
                    switch( zone.Controller.CheckDetailed( player.Info ) ) {
                        case SecurityCheckResult.BlackListed:
                            player.Message( "You are not allowed to remove zone {0}: you are blacklisted.", zone.ClassyName );
                            return;
                        case SecurityCheckResult.RankTooLow:
                            player.Message( "You are not allowed to remove zone {0}.", zone.ClassyName );
                            return;
                    }
                }
                if( !cmd.IsConfirmed ) {
                    player.Confirm( cmd, "You are about to remove zone {0}&S.", zone.ClassyName );
                    return;
                }

                if( zones.Remove( zone.Name ) ) {
                    player.Message( "Zone \"{0}\" removed.", zone.Name );
                }

            } else {
                player.MessageNoZone( zoneName );
            }
        }
Пример #7
0
        private static void GuildHandler( Player player, Command cmd )
        {
            string Param = cmd.Next();
            if ( Param == null ) {
                CdGuild.PrintUsage( player );
                return;
            }

            Param = Param.ToLower();

            PlayerInfo target; //used to store a targetplayer in the switch case

            //this is for stuff which someone without a guild CAN do
            switch ( Param ) {
                case "create":
                    string Name = cmd.NextAll();
                    if ( string.IsNullOrEmpty( Name ) ) {
                        player.Message( "&WGuild name cannot be null: &H/Guild create Name" );
                        return;
                    }
                    if ( Cache.ForbiddenNames.Contains( Name.ToLower() ) ) {
                        player.Message( "&WName is forbidden: You cannot create a guild with this name" );
                        return;
                    }
                    GuildManager.CreateGuild( Name, player );
                    return;

                case "who":
                case "player":
                    string pp = cmd.Next();
                    if ( string.IsNullOrEmpty( pp ) ) {
                        player.Message( "&WPlayer name cannot be null: &h/Guild who playername" );
                        return;
                    }
                    target = PlayerDB.FindPlayerInfoOrPrintMatches( player, pp );
                    if ( target == null )
                        return;
                    player.Message( "{0}&s belongs to {1}", target.Name,
                        GuildManager.PlayersGuild( target ) == null ?
                        "no guild" :
                        "guild \"" + GuildManager.PlayersGuild( target ).Name + "\"" );
                    return;

                case "list":
                    string pro = cmd.Next();
                    if ( pro != null ) {
                        if ( pro.ToLower() == "provisional" ) {
                            player.Message( "Available provisional guilds:" );
                            player.Message( Cache.Guilds.Where( gg => gg.Provisional ).JoinToString() );
                            return;
                        }
                    }
                    player.Message( "Available guilds:" );
                    player.Message( Cache.Guilds.Where( gg => !gg.Provisional ).JoinToString() );
                    return;

                case "info":
                    string gstring = cmd.NextAll();
                    if ( string.IsNullOrEmpty( gstring ) ) {
                        if ( GuildManager.PlayerHasGuild( player.Info ) ) {
                            gstring = GuildManager.PlayersGuild( player.Info ).Name;
                        } else {
                            player.Message( "Guild name cannot be null: &H/Guild Info [GuildName]" );
                            return;
                        }
                    }
                    Guild gui = GuildManager.FindGuildOrPrintResults( player, gstring );
                    if ( gui == null ) {
                        return;
                    }
                    string[] Members = gui.Members.Where( p => gui.GuildMaster != p && !gui.Admins.Contains( p ) ).ToArray();
                    player.Message( "&hGuild \"{0}&h\" ({1}&h): &S\n" +
                        "{2}" +
                        "Guildmaster: {3}&S\n" +
                        "Admins: {4}\n" +
                        "Members: {5}\n" +
                        "Level: {6}\n" +
                        "PvP: {7}",
                        gui.Name,
                        !string.IsNullOrEmpty( gui.Tag ) ? gui.Tag : "No Tag",
                        gui.Open ? "This guild is open for anyone to join\n" : "",
                        gui.GuildMaster,
                        gui.Admins == null || gui.Admins.Length == 0 ? "(No Admins)" : gui.Admins.JoinToString(),
                        Members == null || Members.Length == 0 ? "(No Members)" : Members.JoinToString(),
                        gui.Level,
                        gui.PvP ? "&COn" : "&AOff" );
                    return;

                case "find":
                case "search":
                    string searchterm = cmd.NextAll(); {
                        if ( string.IsNullOrEmpty( searchterm ) ) {
                            player.Message( "&WSearch term cannot be null: &H/Guild search [search term]" );
                            return;
                        }
                        Guild[] FoundGuilds = GuildManager.FindGuilds( searchterm );
                        player.Message( "Guilds found matching {0}: {1}", searchterm, FoundGuilds.JoinToString() );
                    }
                    return;

                case "join":
                    if ( GuildManager.PlayerHasGuild( player.Info ) ) {
                        player.Message( "&HYou already have guild" );
                        return;
                    }
                    string s = cmd.NextAll();
                    if ( string.IsNullOrEmpty( s ) ) {
                        player.Message( "&WGuild to join cannot be null: &H/Guild join [GuildName]" );
                        return;
                    }
                    Guild g = GuildManager.FindGuildOrPrintResults( player, s );
                    if ( g == null )
                        return;
                    g.AcceptInvitationAndJoinGuild( player );
                    return;
            }
            if ( !GuildManager.PlayerHasGuild( player.Info ) ) {
                player.Message( "&HYou do not have a guild. Ask a guildmaster or guild admin to join their guild" );
                return;
            }
            //This is for stuff you NEED a guild for (provisional or not)
            Guild guild = GuildManager.PlayersGuild( player.Info );
            switch ( Param ) {
                case "open":
                    if ( !GuildManager.IsPlayerAnAdmin( player, guild ) ) {
                        player.Message( "&WYou need to be a guildmaster or admin to use this command" );
                        return;
                    }
                    string OpenParam = cmd.Next();
                    if ( string.IsNullOrEmpty( OpenParam ) ) {
                        player.Message( "&WCannot parse toggle: &H/Guild Open [True/False]" );
                        return;
                    }
                    bool OpenStatus;
                    if ( !bool.TryParse( OpenParam, out OpenStatus ) ) {
                        player.Message( "&WCannot parse toggle: &H/Guild Open [True/False]" );
                        return;
                    }
                    if ( guild.Open == OpenStatus )
                        player.Message( "Guild invitation status not changed, currently {0}",
                            OpenStatus == true ? "open" : "closed" );
                    else if ( guild.Open == true )
                        player.Message( "Guild invitation status changed to \"closed\"" );
                    else
                        player.Message( "Guild invitation status changed to \"open for anyone\"" );

                    guild.Open = OpenStatus;
                    return;

                case "pvp":
                    if ( !GuildManager.IsPlayerAnAdmin( player, guild ) ) {
                        player.Message( "&WYou need to be a guildmaster or admin to use this command" );
                        return;
                    }
                    PvP_Perk prk = ( PvP_Perk )GuildManager.FindPerkOrPrintResults( player, "pvp" );
                    if ( prk == null )
                        return;
                    Guild g = guild;
                    if ( g.Level < prk.LevelNeeded ) {
                        player.Message( "You cannot use this perk: Your guild needs level {0}", prk.LevelNeeded );
                        return;
                    }
                    if ( g.PvP ) {
                        prk.StopPerk();
                        guild.SendGuildNotification( "&HGuild PvP has been " + Color.Green + "disabled" );
                    } else {
                        if ( string.IsNullOrEmpty( g.Tag ) ) {
                            player.Message( "&WGuild tag must be set before pvp can be enabled" );
                            return;
                        }
                        prk.StartPerk();
                        guild.SendGuildNotification( "&HGuild PvP has been &Wenabled" );
                    }
                    return;

                case "invite":
                    if ( !GuildManager.IsPlayerAnAdmin( player, guild ) ) {
                        player.Message( "&WYou need to be a guildmaster or admin to use this command" );
                        return;
                    }
                    string playerstr = cmd.Next();
                    if ( String.IsNullOrEmpty( playerstr ) ) {
                        player.Message( "You need to use a name for someone to join your guild: &H/Guild invite PlayerName" );
                        return;
                    }
                    target = PlayerDB.FindPlayerInfoOrPrintMatches( player, playerstr );
                    if ( target == null )
                        return;
                    List<String> lst = guild.PlayersInvited.ToList();
                    if ( GuildManager.PlayerHasGuild( target ) ) {
                        player.Message( "&WThis player is already in a guild! ({0})", GuildManager.PlayersGuild(target));
                        return;
                    }
                    if ( lst.Contains( target.Name ) ) {
                        player.Message( "&WThis player has already been invited to your guild" );
                        return;
                    }
                    lst.Add( target.Name );
                    guild.PlayersInvited = lst.ToArray();
                    player.Message( "Player {0} has been invited to your guild", target.Name );
                    if ( target.IsOnline ) {
                        target.PlayerObject.Message( "&H{0} has invited you to join their guild {1}! Join now, using /Guild Join {1}", player.Name, guild.Name );
                    }
                    return;

                case "exp":
                case "xp":
                case "experience":
                    player.Message( "&HCurrent XP: {0}. Xp needed for next level ({1}): {2}",
                        guild.XP,
                        guild.Level + 1,
                        guild.XPNeededForNextLevel() );
                    return;

                case "leave":
                case "quit":
                    if ( !cmd.IsConfirmed ) {
                        player.Confirm( cmd, "Remove yourself from {0}&S?", GuildManager.PlayersGuild( player.Info ).Name );
                        return;
                    }
                    guild.RemoveMember( player.Info );
                    return;

                case "message":
                case "msg":
                    string msg = cmd.NextAll();
                    if ( string.IsNullOrEmpty( msg ) ) {
                        player.Message( "&WMessage cannot be null: &H/Guild message [message to send]" );
                        return;
                    }
                    guild.SendGuildMessage( player, msg );
                    return;
            }
            if ( guild.Provisional ) {
                GuildManager.MessageProvisionalGuild( player );
                return;
            }
            //this is for stuff a provisional guild cannot do
            switch ( Param ) {
                case "admin":
                case "admins":
                    string s1 = cmd.Next();
                    if ( string.IsNullOrEmpty( s1 ) ) {
                        player.Message( "Guild admins: {0}",
                            guild.Admins.Length == 0 ?
                            "&WThis guild has no admins!" :
                            "(Guildmaster)" + guild.GuildMaster + ", " + guild.Admins.JoinToString() );

                        if ( player.Name == guild.GuildMaster ) {
                            player.Message( "&HYou can add admins using &H/Guild admin [add/remove] [playerName]" );
                        }
                        return;
                    }
                    if ( player.Name != guild.GuildMaster ) {
                        player.Message( "&WOnly the guildmaster ({0}) can manage admins", guild.GuildMaster );
                        return;
                    }
                    string s2 = cmd.Next();
                    if ( string.IsNullOrEmpty( s2 ) ) {
                        player.Message( "Player name cannot be null" );
                        return;
                    }
                    target = PlayerDB.FindPlayerInfoOrPrintMatches( player, s2 );
                    if ( target == null )
                        return;
                    string Name = target.Name;
                    if ( !guild.Members.Contains( Name ) ) {
                        player.Message( "This player is not a member of your guild" );
                        return;
                    }
                    if ( s1.ToLower() == "add" ) {
                        List<string> lst = guild.Admins.ToList();
                        if ( Name == player.Name ) {
                            player.Message( "&WCannot add yourself" );
                            return;
                        }
                        if ( lst.Contains( Name ) ) {
                            player.Message( "{0} is already an admin", Name );
                            return;
                        }
                        lst.Add( Name );
                        guild.Admins = lst.ToArray();
                        player.Message( "Added {0} as an admin", Name );
                        if ( target.IsOnline ) {
                            target.PlayerObject.Message( "&WYou are now an admin of {0}", guild.Name );
                        }
                    }
                    if ( s1.ToLower() == "remove" ) {
                        List<string> lst = guild.Admins.ToList();
                        if ( Name == player.Name ) {
                            player.Message( "&WCannot remove yourself" );
                            return;
                        }
                        if ( !lst.Contains( Name ) ) {
                            player.Message( "&W{0} is not an admin", Name );
                            return;
                        }
                        lst.Remove( Name );
                        guild.Admins = lst.ToArray();
                        player.Message( "Removed {0} as an admin", Name );
                        if ( target.IsOnline ) {
                            target.PlayerObject.Message( "&WYou are no longer an admin of {0}", guild.Name );
                        }
                    }
                    return;

                case "kick":
                    if ( !GuildManager.IsPlayerAnAdmin( player, guild ) ) {
                        player.Message( "&WYou need to be an Admin+ of the guild to use this command" );
                        return;
                    }
                    string TargetName = cmd.Next();
                    if ( string.IsNullOrEmpty( TargetName ) ) {
                        player.Message( "&WPlayer name cannot be null" );
                        return;
                    }
                    target = PlayerDB.FindPlayerInfoOrPrintMatches( player, TargetName );
                    if ( target == null )
                        return;
                    if ( target.Name == guild.GuildMaster ) {
                        player.Message( "&WUnable to kick this player" );
                        return;
                    }
                    if ( !guild.Members.Contains( target.Name ) ) {
                        player.Message( "&WPlayer is not a member of your guild" );
                        return;
                    }
                    guild.RemoveMember( target );
                    guild.SendGuildNotification( target.Name + " was kicked from the guild by " + player.Name );
                    return;

                case "bug":
                case "eb":
                case "explodingbug":
                    ExplodingBugPerk p1 = ( ExplodingBugPerk )GuildManager.FindPerkOrPrintResults( player, "explodingbug" );
                    if ( p1 == null )
                        return;
                    if ( guild.Level < p1.LevelNeeded ) {
                        player.Message( "You cannot use this perk: Your guild needs level {0}", p1.LevelNeeded );
                        return;
                    }
                    string bParam = cmd.Next();
                    if ( string.IsNullOrEmpty( bParam ) ) {
                        object o;
                        if ( player.PublicAuxStateObjects.TryGetValue( "bug", out o ) ) {
                            player.Message( "&WYou already have an exploding bug alive" );
                            return;
                        }
                        if ( Events.IsInRangeOfSpawnpoint( player.World, player.Position ) ) {
                            player.Message( "&WCannot place a bug this close to a spawn point" );
                            return;
                        }
                        p1.SpawnBug( player );
                    } else if ( bParam.ToLower() == "stop" || bParam.ToLower() == "remove" ) {
                        object o;
                        if ( player.PublicAuxStateObjects.TryGetValue( "bug", out o ) ) {
                            ExplodingBug b = ( ExplodingBug )o;
                            b.Stop();
                        } else {
                            player.Message( "&WYou do not have an exploding bug to remove" );
                        }
                    }
                    return;

                case "turret":
                    string tParam = cmd.Next();
                    TurretPerk p2 = ( TurretPerk )GuildManager.FindPerkOrPrintResults( player, "turretperk" );
                    if ( p2 == null )
                        return;
                    if ( guild.Level < p2.LevelNeeded ) {
                        player.Message( "You cannot use this perk: Your guild needs level {0}", p2.LevelNeeded );
                        return;
                    }
                    if ( string.IsNullOrEmpty( tParam ) ) {
                        if ( p2.turret != null ) {
                            player.Message( "&WA turret in your guild already exists: {0} - {1}", p2.turret.world.Name, p2.turret.blocks[0].ToString() );
                            return;
                        }
                        if ( Events.IsInRangeOfSpawnpoint( player.World, player.Position ) ) {
                            player.Message( "&WCannot place a turret this close to a spawn point" );
                            return;
                        }
                        p2.AddTurret( player );
                        return;
                    } else if ( tParam.ToLower() == "stop" || tParam.ToLower() == "remove" ) {
                        if ( p2.turret == null ) {
                            player.Message( "&WA turret in your guild does not exist" );
                            return;
                        }
                        p2.StopPerk();
                        p2.turret = null;
                        player.Message( "Stopping turret..." );
                    }
                    return;

                case "tag":
                    if ( !GuildManager.PlayerHasGuild( player.Info ) ) {
                        player.Message( "You are not in a guild. Create one, or ask someone to join theirs" );
                        return;
                    }
                    if ( !GuildManager.IsPlayerAnAdmin( player, guild ) ) {
                        player.Message( "&WYou need to be a guildmaster or admin to use this command" );
                        return;
                    }
                    string Tag = cmd.NextAll();
                    if ( string.IsNullOrEmpty( Tag ) ) {
                        if ( guild.PvP ) {
                            if ( !cmd.IsConfirmed ) {
                                player.Confirm( cmd, "&WTag cannot be removed when PVP is enabled\n&SDisable PVP?" );
                                return;
                            }
                            guild.PvP = false;
                            guild.SendGuildNotification( "&HGuild PvP has been disabled" );
                            guild.ChangeTagName( player, Tag );
                            return;
                        }
                    }
                    guild.ChangeTagName( player, Tag );
                    return;

                case "bat":
                    TheBatPerk tbp = ( TheBatPerk )GuildManager.FindPerkOrPrintResults( player, "TheBat" );
                    if ( guild.Level < tbp.LevelNeeded ) {
                        player.Message( "Your guild needs to be level {0} to use this perk (Current level: {1})",
                            tbp.LevelNeeded,
                            guild.Level );
                        return;
                    }
                    if ( player.PublicAuxStateObjects.ContainsKey( "bat" ) ) {
                        player.Message( "Bat off" );
                        player.PublicAuxStateObjects.Remove( "bat" );
                    } else {
                        player.Message( "Bat on" );
                        player.PublicAuxStateObjects.Add( "bat", true );
                        Bat b = new Bat( player );
                        b.Start();
                    }
                    return;

                case "reroll":
                    if ( string.IsNullOrEmpty( guild.GuildMaster ) ) {
                        Random rand = new Random();
                        player.Message( "Attempting to reroll guildmaster" );
                        if ( guild.Admins.Length > 0 ) {
                            guild.GuildMaster = guild.Admins[rand.Next(0, guild.Admins.Length )];
                        } else {
                            guild.GuildMaster = guild.Members[rand.Next(0, guild.Members.Length )];
                        }
                        if ( string.IsNullOrEmpty( guild.GuildMaster ) )
                            guild.GuildMaster = player.Name;
                        player.Message( "New guildmaster is: " + guild.GuildMaster );
                    }
                    return;

                case "slapall":
                    if ( !GuildManager.IsPlayerAnAdmin( player, guild ) ) {
                        player.Message( "&WYou need to be a guildmaster or admin to use this command" );
                        return;
                    }
                    SlapAllPerk p = ( SlapAllPerk )GuildManager.FindPerkOrPrintResults( player, "SlapAllPerk" );
                    if ( !Perk.GuildHasPerk( guild, p ) ) {
                        player.Message( "&WYou are unable to use this command: You need the \"SlapAll\" perk" );
                        return;
                    }
                    DateTime now = DateTime.UtcNow;
                    DateTime yesterday = now.AddDays( -1 );
                    if ( p.start != null ) {
                        if ( p.start > yesterday && p.start <= now ) {
                            string op = cmd.NextAll();
                            if ( string.IsNullOrEmpty( op ) ) {
                                player.Message( "&WGuild cannot be null: &H/Guild SlapAll [GuildName]" );
                                return;
                            }
                            Guild gd = GuildManager.FindGuildOrPrintResults( player, op );
                            if ( gd == null )
                                return;
                            int i = 0;
                            foreach ( string s in gd.Members ) {
                                PlayerInfo pla = PlayerDB.FindPlayerInfoExact( s );
                                if ( pla != null ) {
                                    Player pl = pla.PlayerObject;
                                    if ( pl != null ) {
                                        i++;
                                        pl.TeleportTo( new Position( pl.Position.X, pl.Position.Y, pl.World.Map.Height * 32 ) );
                                        pl.Message( "You were slapped sky high from {0}'s guild", guild.GuildMaster );
                                    }
                                }
                            }
                            player.Message( "You slapped {0} members of guild {1} sky high", i, gd.Name );
                        } else
                            player.Message( "&WUnable to slap another guild: The perk is still on cooldown since it was last used (24 hour cooldown)" );
                    }
                    return;

                case "perk":
                case "perks":
                    string str = cmd.NextAll();
                    if ( string.IsNullOrEmpty( str ) ) {
                        player.Message( "Perks your guild currently has: {0}",
                            guild.AvailablePerks().JoinToString() );
                        player.Message( "&HUse /Guild Perk [Name] for info on that perk" );
                    } else {
                        if ( str.ToLower() == "all" ) {
                            player.Message( "All perks: {0}",
                            guild.Perks.JoinToString() );
                            player.Message( "&HUse /Guild Perk [Name] for info on that perk" );
                            return;
                        }
                        Perk perk = GuildManager.FindPerkOrPrintResults( player, str );
                        if ( perk == null )
                            return;
                        player.Message( "Help info on Perk {0}: ", perk.PerkName );
                        player.Message( Perk.GetHelpSection( perk ) );
                    }
                    return;

                default:
                    player.Message( "Unknown param for /Guild: Try {0}",
                        "/Guild [Create | List | Info | Find | Join | Invite | Perks | Xp | SlapAll | Tag | Quit | Message | Bat | Turret | Bug ]" );
                    return;
            }
        }
Пример #8
0
        public static void RealmCreate(Player player, Command cmd, string themeName, string templateName)
        {
            MapGenTemplate template;
            MapGenTheme    theme;

            int wx, wy, height = 128;

            if (!(cmd.NextInt(out wx) && cmd.NextInt(out wy) && cmd.NextInt(out height)))
            {
                if (player.World != null)
                {
                    wx     = 128;
                    wy     = 128;
                    height = 128;
                }
                else
                {
                    player.Message("When used from console, /gen requires map dimensions.");

                    return;
                }
                cmd.Rewind();
                cmd.Next();
                cmd.Next();
            }

            if (!Map.IsValidDimension(wx))
            {
                player.Message("Cannot make map with width {0}: dimensions must be multiples of 16.", wx);
                return;
            }
            else if (!Map.IsValidDimension(wy))
            {
                player.Message("Cannot make map with length {0}: dimensions must be multiples of 16.", wy);
                return;
            }
            else if (!Map.IsValidDimension(height))
            {
                player.Message("Cannot make map with height {0}: dimensions must be multiples of 16.", height);
                return;
            }

            string fileName     = player.Name;
            string fullFileName = null;

            if (fileName == null)
            {
                if (player.World == null)
                {
                    player.Message("When used from console, /gen requires FileName.");

                    return;
                }
                if (!cmd.IsConfirmed)
                {
                    player.Confirm(cmd, "Replace this realm's map with a generated one?");
                    return;
                }
            }
            else
            {
                fileName = fileName.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
                if (!fileName.EndsWith(".fcm", StringComparison.OrdinalIgnoreCase))
                {
                    fileName += ".fcm";
                }
                fullFileName = Path.Combine(Paths.MapPath, fileName);
                if (!Paths.IsValidPath(fullFileName))
                {
                    player.Message("Invalid filename.");
                    return;
                }
                if (!Paths.Contains(Paths.MapPath, fullFileName))
                {
                    player.MessageUnsafePath();
                    return;
                }
                string dirName = fullFileName.Substring(0, fullFileName.LastIndexOf(Path.DirectorySeparatorChar));
                if (!Directory.Exists(dirName))
                {
                    Directory.CreateDirectory(dirName);
                }
                if (!cmd.IsConfirmed && File.Exists(fullFileName))
                {
                    player.Confirm(cmd, "The mapfile \"{0}\" already exists. Overwrite?", fileName);
                    return;
                }
            }

            bool noTrees;

            if (themeName.Equals("grass", StringComparison.OrdinalIgnoreCase))
            {
                theme   = MapGenTheme.Forest;
                noTrees = true;
            }
            else
            {
                try
                {
                    theme   = (MapGenTheme)Enum.Parse(typeof(MapGenTheme), themeName, true);
                    noTrees = (theme != MapGenTheme.Forest);
                }
                catch (Exception)
                {
                    player.MessageNow("Unrecognized theme \"{0}\". Available themes are: Grass, {1}",
                                      themeName,
                                      String.Join(", ", Enum.GetNames(typeof(MapGenTheme))));
                    return;
                }
            }

            try
            {
                template = (MapGenTemplate)Enum.Parse(typeof(MapGenTemplate), templateName, true);
            }
            catch (Exception)
            {
                player.Message("Unrecognized template \"{0}\". Available templates are: {1}",
                               templateName,
                               String.Join(", ", Enum.GetNames(typeof(MapGenTemplate))));
                return;
            }

            if (!Enum.IsDefined(typeof(MapGenTheme), theme) || !Enum.IsDefined(typeof(MapGenTemplate), template))
            {
                return;
            }

            MapGeneratorArgs args = MapGenerator.MakeTemplate(template);

            args.MapWidth  = wx;
            args.MapLength = wy;
            args.MapHeight = height;
            args.MaxHeight = (int)(args.MaxHeight / 80d * height);
            args.MaxDepth  = (int)(args.MaxDepth / 80d * height);
            args.Theme     = theme;
            args.AddTrees  = !noTrees;

            Map map;

            try
            {
                if (theme == MapGenTheme.Forest && noTrees)
                {
                    player.MessageNow("Generating Grass {0}...", template);
                }
                else
                {
                    player.MessageNow("Generating {0} {1}...", theme, template);
                }
                if (theme == MapGenTheme.Forest && noTrees && template == MapGenTemplate.Flat)
                {
                    map = MapGenerator.GenerateFlatgrass(args.MapWidth, args.MapLength, args.MapHeight);
                }
                else
                {
                    MapGenerator generator = new MapGenerator(args);
                    map = generator.Generate();
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogType.Error, "MapGenerator: Generation failed: {0}",
                           ex);
                player.MessageNow("&WAn error occured while generating the map.");
                return;
            }

            if (fileName != null)
            {
                if (map.Save(fullFileName))
                {
                    player.MessageNow("Generation done. Saved to {0}", fileName);
                }
                else
                {
                    player.Message("&WAn error occured while saving generated map to {0}", fileName);
                }
            }
            else
            {
                player.MessageNow("Generation done. Changing map...");
                player.World.ChangeMap(map);
            }
        }
        static void ImportBans( Player player, Command cmd )
        {
            string serverName = cmd.Next();
            string file = cmd.Next();

            // Make sure all parameters are specified
            if( serverName == null || file == null ) {
                CdImport.PrintUsage( player );
                return;
            }

            // Check if file exists
            if( !File.Exists( file ) ) {
                player.Message( "File not found: {0}", file );
                return;
            }

            string[] names;

            switch( serverName.ToLower() ) {
                case "mcsharp":
                case "mczall":
                case "mclawl":
                    try {
                        names = File.ReadAllLines( file );
                    } catch( Exception ex ) {
                        Logger.Log( LogType.Error,
                                    "Could not open \"{0}\" to import bans: {1}",
                                    file, ex );
                        return;
                    }
                    break;
                default:
                    player.Message( "fCraft does not support importing from {0}", serverName );
                    return;
            }

            if( !cmd.IsConfirmed ) {
                player.Confirm( cmd, "You are about to import {0} bans.", names.Length );
                return;
            }

            string reason = "(import from " + serverName + ")";
            foreach( string name in names ) {
                if( Player.IsValidName( name ) ) {
                    PlayerInfo info = PlayerDB.FindPlayerInfoExact( name ) ??
                                      PlayerDB.AddFakeEntry( name, RankChangeType.Default );
                    info.Ban( player, reason, true, true );

                } else {
                    IPAddress ip;
                    if( Server.IsIP( name ) && IPAddress.TryParse( name, out ip ) ) {
                        ip.BanIP( player, reason, true, true );
                    } else {
                        player.Message( "Could not parse \"{0}\" as either name or IP. Skipping.", name );
                    }
                }
            }

            PlayerDB.Save();
            IPBanList.Save();
        }
Пример #10
0
        static void WorldBringHandler( Player player, CommandReader cmd ) {
            string playerName = cmd.Next();
            string worldName = cmd.Next();
            if( playerName == null || worldName == null ) {
                CdWorldBring.PrintUsage( player );
                return;
            }

            Player target = Server.FindPlayerOrPrintMatches(player, playerName, SearchOptions.Default);
            World world = WorldManager.FindWorldOrPrintMatches( player, worldName );

            if( target == null || world == null ) return;

            if (target == player)
            {
                player.Message( "&WYou cannot &H/WBring&W yourself." );
                return;
            }

            if( !player.Can( Permission.Bring, target.Info.Rank ) ) {
                player.Message( "You may only bring players ranked {0}&S or lower.",
                                player.Info.Rank.GetLimit( Permission.Bring ).ClassyName );
                player.Message( "{0}&S is ranked {1}",
                                target.ClassyName, target.Info.Rank.ClassyName );
                return;
            }

            if( world == target.World ) {
                player.Message( "{0}&S is already in world {1}&S. They were brought to spawn.",
								target.ClassyName, world.ClassyName);

				if (target.World != null) {
					target.LastWorld = target.World;
					target.LastPosition = target.Position;
				}
                target.TeleportTo( target.WorldMap.Spawn );
                return;
            }

            SecurityCheckResult check = world.AccessSecurity.CheckDetailed( target.Info );
            if( check == SecurityCheckResult.RankTooLow ) {
                if( player.CanJoin( world ) ) {
                    if( cmd.IsConfirmed ) {
                        BringPlayerToWorld( player, target, world, true, false );
                    } else {
                        //Allow banned players to be moved about...
                        if (target.Info.Rank.Name == "Banned")
                        {
                            player.Message("&sYou CAN move banned players about... It is considered bad form though...");
                        }
                        Logger.Log( LogType.UserActivity,
                                    "WBring: Asked {0} to confirm overriding world permissions to bring player {1} to world {2}",
                                    player.Name, target.Name, world.Name );
                        player.Confirm( cmd,
                                        "{0} {1}&S is ranked too low to join {2}&S. Override world permissions?",
                                        target.Info.Rank.ClassyName,
                                        target.ClassyName,
                                        world.ClassyName );
                    }
                } else {
                    player.Message( "Neither you nor {0}&S are allowed to join world {1}",
                                    target.ClassyName, world.ClassyName );
                }
            } else {
                //Allow banned players to be moved about...
                if (target.Info.Rank.Name == "Banned")
                {
                    player.Message("&sYou CAN move banned players about... It is considered bad form though...");
                }
                BringPlayerToWorld( player, target, world, false, false );
            }
        }
Пример #11
0
        static void ZoneRemoveHandler( Player player, CommandReader cmd ) {
            if( player.World == null ) PlayerOpException.ThrowNoWorld( player );

            string zoneName = cmd.Next();
            if( zoneName == null || cmd.HasNext ) {
                CdZoneRemove.PrintUsage( player );
                return;
            }

            if( zoneName == "*" ) {
                if( !cmd.IsConfirmed ) {
                    Logger.Log( LogType.UserActivity,
                                "ZRemove: Asked {0} to confirm removing all zones on world {1}",
                                player.Name, player.World.Name );
                    player.Confirm( cmd,
                                    "&WRemove ALL zones on this world ({0}&W)? This cannot be undone.&S",
                                    player.World.ClassyName );
                    return;
                }
                player.WorldMap.Zones.Clear();
                Logger.Log( LogType.UserActivity,
                            "Player {0} removed all zones on world {1}",
                            player.Name, player.World.Name );
                Server.Message( "Player {0}&S removed all zones on world {1}",
                                player.ClassyName, player.World.ClassyName );
                return;
            }

            ZoneCollection zones = player.WorldMap.Zones;
            Zone zone = zones.Find( zoneName );
            if( zone != null ) {
                if( !player.Info.Rank.AllowSecurityCircumvention ) {
                    switch( zone.Controller.CheckDetailed( player.Info ) ) {
                        case SecurityCheckResult.BlackListed:
                            player.Message( "You are not allowed to remove zone {0}: you are blacklisted.", zone.ClassyName );
                            return;
                        case SecurityCheckResult.RankTooLow:
                            player.Message( "You are not allowed to remove zone {0}.", zone.ClassyName );
                            return;
                    }
                }
                if( !cmd.IsConfirmed ) {
                    Logger.Log( LogType.UserActivity,
                                "ZRemove: Asked {0} to confirm removing zone {1} from world {2}",
                                player.Name, zone.Name, player.World.Name );
                    player.Confirm( cmd, "Remove zone {0}&S?", zone.ClassyName );
                    return;
                }

                if( zones.Remove( zone.Name ) ) {
                    Logger.Log( LogType.UserActivity,
                                "Player {0} removed zone {1} from world {2}",
                                player.Name, zone.Name, player.World.Name );
                    player.Message( "Zone \"{0}\" removed.", zone.Name );
                }

            } else {
                player.MessageNoZone( zoneName );
            }
        }
Пример #12
0
        /// <summary> Parses an unknown command as a /Join [command] command. </summary>
        /// <param name="player"> Player who issued the command. </param>
        /// <param name="cmd"> Command to be parsed as a worldname. </param>
        /// <returns> True if the command was a world and the user was able to join it, false if world doesn't exist, or user is unable to join the world. </returns>
        public static bool ParseUnknownCommand(Player player, CommandReader cmd)
        {
            //joinworld or tp to player
            if (cmd.RawMessage.IndexOf(' ') == -1 && player != Player.Console)
            {
                string cmdString  = cmd.RawMessage.Substring(1);
                bool   wasWorldTP = false;
                if (cmdString == "-")
                {
                    if (player.LastUsedWorldName != null)
                    {
                        cmdString = player.LastUsedWorldName;
                    }
                    else
                    {
                        return(false);
                    }
                }
                World[] worlds = WorldManager.FindWorlds(player, cmdString);

                if (worlds.Length == 1)
                {
                    World world = worlds[0];
                    if (world.Name.StartsWith("PW_"))
                    {
                        return(false);
                    }
                    player.LastUsedWorldName = world.Name;
                    switch (world.AccessSecurity.CheckDetailed(player.Info))
                    {
                    case SecurityCheckResult.Allowed:
                    case SecurityCheckResult.WhiteListed:
                        if (world.IsFull)
                        {
                            break;
                        }
                        if (cmd.IsConfirmed)
                        {
                            if (player.JoinWorldNow(world, true, WorldChangeReason.ManualJoin))
                            {
                                wasWorldTP = true;
                            }
                            break;
                        }
                        if (player.World.Name.CaselessEquals("tutorial") && !player.Info.HasRTR)
                        {
                            player.Confirm(cmd,
                                           "&SYou are choosing to skip the rules, if you continue you will spawn here the next time you log in.");
                            return(true);
                        }
                        player.StopSpectating();
                        if (player.JoinWorldNow(world, true, WorldChangeReason.ManualJoin))
                        {
                            wasWorldTP = true;
                            break;
                        }
                        break;

                    case SecurityCheckResult.BlackListed:
                        break;

                    case SecurityCheckResult.RankTooLow:
                        break;
                    }
                    if (wasWorldTP)
                    {
                        player.Message("&H{0}&S is not a command, but it part of a world name, so you have been teleported to {1}&S instead", cmd.RawMessage, world.ClassyName);
                        player.SendToSpectators(cmd.RawMessage + " -> /Join {0}", world.Name);
                        Logger.Log(LogType.UserCommand, "{0}: /Join {1}", player.Name, world.Name);
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #13
0
        static void ImportRanks(Player player, CommandReader cmd)
        {
            string serverName = cmd.Next();
            string fileName   = cmd.Next();
            string rankName   = cmd.Next();
            bool   silent     = (cmd.Next() != null);


            // Make sure all parameters are specified
            if (serverName == null || fileName == null || rankName == null)
            {
                CdImport.PrintUsage(player);
                return;
            }

            // Check if file exists
            if (!File.Exists(fileName))
            {
                player.Message("File not found: {0}", fileName);
                return;
            }

            Rank targetRank = RankManager.FindRank(rankName);

            if (targetRank == null)
            {
                player.MessageNoRank(rankName);
                return;
            }

            string[] names;

            switch (serverName.ToLower())
            {
            case "mcsharp":
            case "mczall":
            case "mclawl":
                try {
                    names = File.ReadAllLines(fileName);
                } catch (Exception ex) {
                    Logger.Log(LogType.Error,
                               "Could not open \"{0}\" to import ranks: {1}",
                               fileName, ex);
                    return;
                }
                break;

            default:
                player.Message("fCraft does not support importing from {0}", serverName);
                return;
            }

            if (!cmd.IsConfirmed)
            {
                player.Confirm(cmd, "Import {0} player ranks from \"{1}\"?",
                               names.Length, Path.GetFileName(fileName));
                return;
            }

            string reason = "(Import from " + serverName + ")";

            foreach (string name in names)
            {
                PlayerInfo info = PlayerDB.FindExact(name) ??
                                  PlayerDB.AddUnrecognizedPlayer(name, RankChangeType.Promoted);
                try {
                    info.ChangeRank(player, targetRank, reason, !silent, true, false);
                } catch (PlayerOpException ex) {
                    player.Message(ex.MessageColored);
                }
            }

            PlayerDB.Save();
        }
Пример #14
0
        static void WorldBringHandler( Player player, CommandReader cmd ) {
            string playerName = cmd.Next();
            string worldName = cmd.Next();
            if( playerName == null || worldName == null ) {
                CdWorldBring.PrintUsage( player );
                return;
            }

            Player target = Server.FindPlayerOrPrintMatches( player, playerName, false, false, true );
            World world = WorldManager.FindWorldOrPrintMatches( player, worldName );

            if( target == null || world == null ) return;

            if( !player.Can( Permission.Bring, target.Info.Rank ) ) {
                player.Message( "You may only bring players ranked {0}&S or lower.",
                                player.Info.Rank.GetLimit( Permission.Bring ).ClassyName );
                player.Message( "{0}&S is ranked {1}",
                                target.ClassyName, target.Info.Rank.ClassyName );
                return;
            }

            if( world == target.World ) {
                player.Message( "Player {0}&S is already in world {1}&S. They were brought to spawn.",
                                target.ClassyName, world.ClassyName );
                target.TeleportTo( target.WorldMap.Spawn );
                return;
            }

            SecurityCheckResult check = world.AccessSecurity.CheckDetailed( target.Info );
            if( check == SecurityCheckResult.RankTooLow ) {
                if( player.CanJoin( world ) ) {
                    if( cmd.IsConfirmed ) {
                        BringPlayerToWorld( player, target, world, true, false );
                    } else {
                        Logger.Log( LogType.UserActivity,
                                    "WBring: Asked {0} to confirm overriding world permissions to bring player {1} to world {2}",
                                    player.Name, target.Name, world.Name );
                        player.Confirm( cmd,
                                        "Player {0}&S is ranked too low to join {1}&S. Override world permissions?",
                                        target.ClassyName,
                                        world.ClassyName );
                    }
                } else {
                    player.Message( "Neither you nor {0}&S are allowed to join world {1}",
                                    target.ClassyName, world.ClassyName );
                }
            } else {
                BringPlayerToWorld( player, target, world, false, false );
            }
        }
Пример #15
0
        static void EnvHandler( Player player, Command cmd ) {
            if( !ConfigKey.WoMEnableEnvExtensions.Enabled() ) {
                player.Message( "Env command is disabled on this server." );
                return;
            }
            string worldName = cmd.Next();
            World world;
            if( worldName == null ) {
                world = player.World;
                if( world == null ) {
                    player.Message( "When used from console, /Env requires a world name." );
                    return;
                }
            } else {
                world = WorldManager.FindWorldOrPrintMatches( player, worldName );
                if( world == null ) return;
            }

            string variable = cmd.Next();
            string valueText = cmd.Next();
            if( variable == null ) {
                player.Message( "Environment settings for world {0}&S:", world.ClassyName );
                player.Message( "  Cloud: {0}   Fog: {1}   Sky: {2}",
                                world.CloudColor == -1 ? "normal" : '#' + world.CloudColor.ToString( "X6" ),
                                world.FogColor == -1 ? "normal" : '#' + world.FogColor.ToString( "X6" ),
                                world.SkyColor == -1 ? "normal" : '#' + world.SkyColor.ToString( "X6" ) );
                player.Message( "  Edge level: {0}  Edge texture: {1}",
                                world.EdgeLevel == -1 ? "normal" : world.EdgeLevel + " blocks",
                                world.EdgeBlock );
                if( !player.IsUsingWoM ) {
                    player.Message( "  You need WoM client to see the changes." );
                }
                return;
            }

            if( variable.Equals( "normal", StringComparison.OrdinalIgnoreCase ) ) {
                if( cmd.IsConfirmed ) {
                    world.FogColor = -1;
                    world.CloudColor = -1;
                    world.SkyColor = -1;
                    world.EdgeLevel = -1;
                    world.EdgeBlock = Block.Water;
                    player.Message( "Reset enviroment settings for world {0}", world.ClassyName );
                    WorldManager.SaveWorldList();
                } else {
                    player.Confirm( cmd, "Reset enviroment settings for world {0}&S?", world.ClassyName );
                }
                return;
            }

            if( valueText == null ) {
                CdEnv.PrintUsage( player );
                return;
            }

            int value = 0;
            if( valueText.Equals( "normal", StringComparison.OrdinalIgnoreCase ) ) {
                value = -1;
            }

            switch( variable.ToLower() ) {
                case "fog":
                    if( value == -1 ) {
                        player.Message( "Reset fog color for {0}&S to normal", world.ClassyName );
                    } else {
                        try {
                            value = ParseHexColor( valueText );
                        } catch( FormatException ) {
                            player.Message( "Env: \"{0}\" is not a valid RGB color code.", valueText );
                            return;
                        }
                        player.Message( "Set fog color for {0}&S to #{1:X6}", world.ClassyName, value );
                    }
                    world.FogColor = value;
                    break;

                case "cloud":
                case "clouds":
                    if( value == -1 ) {
                        player.Message( "Reset cloud color for {0}&S to normal", world.ClassyName );
                    } else {
                        try {
                            value = ParseHexColor( valueText );
                        } catch( FormatException ) {
                            player.Message( "Env: \"{0}\" is not a valid RGB color code.", valueText );
                            return;
                        }
                        player.Message( "Set cloud color for {0}&S to #{1:X6}", world.ClassyName, value );
                    }
                    world.CloudColor = value;
                    break;

                case "sky":
                    if( value == -1 ) {
                        player.Message( "Reset sky color for {0}&S to normal", world.ClassyName );
                    } else {
                        try {
                            value = ParseHexColor( valueText );
                        } catch( FormatException ) {
                            player.Message( "Env: \"{0}\" is not a valid RGB color code.", valueText );
                            return;
                        }
                        player.Message( "Set sky color for {0}&S to #{1:X6}", world.ClassyName, value );
                    }
                    world.SkyColor = value;
                    break;

                case "level":
                    if( value == -1 ) {
                        player.Message( "Reset edge level for {0}&S to normal", world.ClassyName );
                    } else {
                        try {
                            value = UInt16.Parse( valueText );
                        } catch( OverflowException ) {
                            CdEnv.PrintUsage( player );
                            return;
                        } catch( FormatException ) {
                            CdEnv.PrintUsage( player );
                            return;
                        }
                        player.Message( "Set edge level for {0}&S to {1}", world.ClassyName, value );
                    }
                    world.EdgeLevel = value;
                    break;

                case "edge":
                    Block block = Map.GetBlockByName( valueText );
                    if( block == Block.Undefined ) {
                        CdEnv.PrintUsage( player );
                        return;
                    }
                    if( block == Block.Water || valueText.Equals( "normal", StringComparison.OrdinalIgnoreCase ) ) {
                        player.Message( "Reset edge block for {0}&S to normal (water)", world.ClassyName );
                        world.EdgeBlock = Block.Water;
                    } else {
                        string textName = Map.GetEdgeTexture( block );
                        if( textName == null ) {
                            player.Message( "Env: Cannot use {0} for edge textures.", block );
                            return;
                        } else {
                            world.EdgeBlock = block;
                        }
                    }
                    break;

                default:
                    CdEnv.PrintUsage( player );
                    return;
            }

            WorldManager.SaveWorldList();
            if( player.World == world ) {
                if( player.IsUsingWoM ) {
                    player.Message( "Env: Rejoin the world to see the changes." );
                } else {
                    player.Message( "Env: You need WoM client to see the changes." );
                }
            }
        }
        static void DoPlayerDB( Player player, Command cmd )
        {
            string p1Name = cmd.Next();
            string p2Name = cmd.Next();
            if( p1Name == null || p2Name == null ) {
                CdInfoSwap.PrintUsage( player );
                return;
            }

            PlayerInfo p1 = PlayerDB.FindPlayerInfoOrPrintMatches( player, p1Name );
            if( p1 == null ) return;
            PlayerInfo p2 = PlayerDB.FindPlayerInfoOrPrintMatches( player, p2Name );
            if( p2 == null ) return;

            if( p1 == p2 ) {
                player.Message( "InfoSwap: Please specify 2 different players." );
                return;
            }

            if( p1.IsOnline || p2.IsOnline ) {
                player.Message( "InfoSwap: Both players must be offline to swap info." );
                return;
            }

            if( !cmd.IsConfirmed ) {
                player.Confirm( cmd, "InfoSwap: Swap stats of players {0}&S and {1}&S?", p1.ClassyName, p2.ClassyName );
                return;
            } else {
                PlayerDB.SwapPlayerInfo( p1, p2 );
                player.Message( "InfoSwap: Stats of {0}&S and {1}&S have been swapped.",
                                p1.ClassyName, p2.ClassyName );
            }
        }
Пример #17
0
        static void ZoneRemoveHandler(Player player, CommandReader cmd)
        {
            if (player.World == null)
            {
                PlayerOpException.ThrowNoWorld(player);
            }

            string zoneName = cmd.Next();

            if (zoneName == null || cmd.HasNext)
            {
                CdZoneRemove.PrintUsage(player);
                return;
            }

            if (zoneName == "*")
            {
                if (!cmd.IsConfirmed)
                {
                    Logger.Log(LogType.UserActivity,
                               "ZRemove: Asked {0} to confirm removing all zones on world {1}",
                               player.Name, player.World.Name);
                    player.Confirm(cmd,
                                   "&WRemove ALL zones on this world ({0}&W)? This cannot be undone.&S",
                                   player.World.ClassyName);
                    return;
                }
                player.WorldMap.Zones.Clear();
                Logger.Log(LogType.UserActivity,
                           "Player {0} removed all zones on world {1}",
                           player.Name, player.World.Name);
                Server.Message("Player {0}&S removed all zones on world {1}",
                               player.ClassyName, player.World.ClassyName);
                return;
            }

            ZoneCollection zones = player.WorldMap.Zones;
            Zone           zone  = zones.Find(zoneName);

            if (zone != null)
            {
                if (!player.Info.Rank.AllowSecurityCircumvention)
                {
                    switch (zone.Controller.CheckDetailed(player.Info))
                    {
                    case SecurityCheckResult.BlackListed:
                        player.Message("You are not allowed to remove zone {0}: you are blacklisted.", zone.ClassyName);
                        return;

                    case SecurityCheckResult.RankTooLow:
                        player.Message("You are not allowed to remove zone {0}.", zone.ClassyName);
                        return;
                    }
                }
                if (!cmd.IsConfirmed)
                {
                    Logger.Log(LogType.UserActivity,
                               "ZRemove: Asked {0} to confirm removing zone {1} from world {2}",
                               player.Name, zone.Name, player.World.Name);
                    player.Confirm(cmd, "Remove zone {0}&S?", zone.ClassyName);
                    return;
                }

                if (zones.Remove(zone.Name))
                {
                    Logger.Log(LogType.UserActivity,
                               "Player {0} removed zone {1} from world {2}",
                               player.Name, zone.Name, player.World.Name);
                    player.Message("Zone \"{0}\" removed.", zone.Name);
                }
            }
            else
            {
                player.MessageNoZone(zoneName);
            }
        }
        static void MassRankHandler( Player player, Command cmd )
        {
            string fromRankName = cmd.Next();
            string toRankName = cmd.Next();
            string reason = cmd.NextAll();
            if( fromRankName == null || toRankName == null ) {
                CdMassRank.PrintUsage( player );
                return;
            }

            Rank fromRank = RankManager.FindRank( fromRankName );
            if( fromRank == null ) {
                player.MessageNoRank( fromRankName );
                return;
            }

            Rank toRank = RankManager.FindRank( toRankName );
            if( toRank == null ) {
                player.MessageNoRank( toRankName );
                return;
            }

            if( fromRank == toRank ) {
                player.Message( "Ranks must be different" );
                return;
            }

            int playerCount = fromRank.PlayerCount;
            string verb = (fromRank > toRank ? "demot" : "promot");

            if( !cmd.IsConfirmed ) {
                player.Confirm( cmd, "About to {0}e {1} players.", verb, playerCount );
                return;
            }

            player.Message( "MassRank: {0}ing {1} players...",
                            verb, playerCount );

            int affected = PlayerDB.MassRankChange( player, fromRank, toRank, reason );
            player.Message( "MassRank: done, {0} records affected.", affected );
        }
Пример #19
0
        public static void RealmCreate(Player player, Command cmd, string themeName, string templateName)
        {
            MapGenTemplate template;
            MapGenTheme theme;

            int wx, wy, height = 128;
            if (!(cmd.NextInt(out wx) && cmd.NextInt(out wy) && cmd.NextInt(out height)))
            {
                if (player.World != null)
                {
                    wx = 128;
                    wy = 128;
                    height = 128;
                }
                else
                {
                    player.Message("When used from console, /gen requires map dimensions.");

                    return;
                }
                cmd.Rewind();
                cmd.Next();
                cmd.Next();
            }

            if (!Map.IsValidDimension(wx))
            {
                player.Message("Cannot make map with width {0}: dimensions must be multiples of 16.", wx);
                return;
            }
            else if (!Map.IsValidDimension(wy))
            {
                player.Message("Cannot make map with length {0}: dimensions must be multiples of 16.", wy);
                return;
            }
            else if (!Map.IsValidDimension(height))
            {
                player.Message("Cannot make map with height {0}: dimensions must be multiples of 16.", height);
                return;
            }

            string fileName = player.Name;
            string fullFileName = null;

            if (fileName == null)
            {
                if (player.World == null)
                {
                    player.Message("When used from console, /gen requires FileName.");

                    return;
                }
                if (!cmd.IsConfirmed)
                {
                    player.Confirm(cmd, "Replace this realm's map with a generated one?");
                    return;
                }
            }
            else
            {
                fileName = fileName.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
                if (!fileName.EndsWith(".fcm", StringComparison.OrdinalIgnoreCase))
                {
                    fileName += ".fcm";
                }
                fullFileName = Path.Combine(Paths.MapPath, fileName);
                if (!Paths.IsValidPath(fullFileName))
                {
                    player.Message("Invalid filename.");
                    return;
                }
                if (!Paths.Contains(Paths.MapPath, fullFileName))
                {
                    player.MessageUnsafePath();
                    return;
                }
                string dirName = fullFileName.Substring(0, fullFileName.LastIndexOf(Path.DirectorySeparatorChar));
                if (!Directory.Exists(dirName))
                {
                    Directory.CreateDirectory(dirName);
                }
                if (!cmd.IsConfirmed && File.Exists(fullFileName))
                {
                    player.Confirm(cmd, "The mapfile \"{0}\" already exists. Overwrite?", fileName);
                    return;
                }
            }

            bool noTrees;
            if (themeName.Equals("grass", StringComparison.OrdinalIgnoreCase))
            {
                theme = MapGenTheme.Forest;
                noTrees = true;
            }
            else
            {
                try
                {
                    theme = (MapGenTheme)Enum.Parse(typeof(MapGenTheme), themeName, true);
                    noTrees = (theme != MapGenTheme.Forest);
                }
                catch (Exception)
                {
                    player.MessageNow("Unrecognized theme \"{0}\". Available themes are: Grass, {1}",
                                       themeName,
                                       String.Join(", ", Enum.GetNames(typeof(MapGenTheme))));
                    return;
                }
            }

            try
            {
                template = (MapGenTemplate)Enum.Parse(typeof(MapGenTemplate), templateName, true);
            }
            catch (Exception)
            {
                player.Message("Unrecognized template \"{0}\". Available templates are: {1}",
                                templateName,
                                String.Join(", ", Enum.GetNames(typeof(MapGenTemplate))));
                return;
            }

            if (!Enum.IsDefined(typeof(MapGenTheme), theme) || !Enum.IsDefined(typeof(MapGenTemplate), template))
            {

                return;
            }

            MapGeneratorArgs args = MapGenerator.MakeTemplate(template);
            args.MapWidth = wx;
            args.MapLength = wy;
            args.MapHeight = height;
            args.MaxHeight = (int)(args.MaxHeight / 80d * height);
            args.MaxDepth = (int)(args.MaxDepth / 80d * height);
            args.Theme = theme;
            args.AddTrees = !noTrees;

            Map map;
            try
            {
                if (theme == MapGenTheme.Forest && noTrees)
                {
                    player.MessageNow("Generating Grass {0}...", template);
                }
                else
                {
                    player.MessageNow("Generating {0} {1}...", theme, template);
                }
                if (theme == MapGenTheme.Forest && noTrees && template == MapGenTemplate.Flat)
                {
                    map = MapGenerator.GenerateFlatgrass(args.MapWidth, args.MapLength, args.MapHeight);
                }
                else
                {
                    MapGenerator generator = new MapGenerator(args);
                    map = generator.Generate();
                }

            }
            catch (Exception ex)
            {
                Logger.Log(LogType.Error, "MapGenerator: Generation failed: {0}",
                            ex);
                player.MessageNow("&WAn error occured while generating the map.");
                return;
            }

            if (fileName != null)
            {
                if (map.Save(fullFileName))
                {
                    player.MessageNow("Generation done. Saved to {0}", fileName);
                }
                else
                {
                    player.Message("&WAn error occured while saving generated map to {0}", fileName);
                }
            }
            else
            {
                player.MessageNow("Generation done. Changing map...");
                player.World.ChangeMap(map);
            }
        }
Пример #20
0
        static void WorldSaveHandler(Player player, Command cmd)
        {
            string p1 = cmd.Next(), p2 = cmd.Next();
            if (p1 == null)
            {
                CdWorldSave.PrintUsage(player);
                return;
            }

            World world = player.World;
            string fileName;
            if (p2 == null)
            {
                fileName = p1;
                if (world == null)
                {
                    player.Message("When called from console, /wsave requires WorldName. See \"/Help save\" for details.");
                    return;
                }
            }
            else
            {
                world = WorldManager.FindWorldOrPrintMatches(player, p1);
                if (world == null) return;
                fileName = p2;
            }

            // normalize the path
            fileName = fileName.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
            if (fileName.EndsWith("/") && fileName.EndsWith(@"\"))
            {
                fileName += world.Name + ".fcm";
            }
            else if (!fileName.ToLower().EndsWith(".fcm", StringComparison.OrdinalIgnoreCase))
            {
                fileName += ".fcm";
            }
            if (!Paths.IsValidPath(fileName))
            {
                player.Message("Invalid filename.");
                return;
            }
            string fullFileName = Path.Combine(Paths.MapPath, fileName);
            if (!Paths.Contains(Paths.MapPath, fullFileName))
            {
                player.MessageUnsafePath();
                return;
            }

            // Ask for confirmation if overwriting
            if (File.Exists(fullFileName))
            {
                FileInfo targetFile = new FileInfo(fullFileName);
                FileInfo sourceFile = new FileInfo(world.MapFileName);
                if (!targetFile.FullName.Equals(sourceFile.FullName, StringComparison.OrdinalIgnoreCase))
                {
                    if (!cmd.IsConfirmed)
                    {
                        player.Confirm(cmd, "Target file \"{0}\" already exists, and will be overwritten.", targetFile.Name);
                        return;
                    }
                }
            }

            // Create the target directory if it does not exist
            string dirName = fullFileName.Substring(0, fullFileName.LastIndexOf(Path.DirectorySeparatorChar));
            if (!Directory.Exists(dirName))
            {
                Directory.CreateDirectory(dirName);
            }

            player.MessageNow("Saving map to {0}", fileName);

            const string mapSavingErrorMessage = "Map saving failed. See server logs for details.";
            Map map = world.Map;
            if (map == null)
            {
                if (File.Exists(world.MapFileName))
                {
                    try
                    {
                        File.Copy(world.MapFileName, fullFileName, true);
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(LogType.Error,
                                    "WorldCommands.WorldSave: Error occured while trying to copy an unloaded map: {0}", ex);
                        player.Message(mapSavingErrorMessage);
                    }
                }
                else
                {
                    Logger.Log(LogType.Error,
                                "WorldCommands.WorldSave: Map for world \"{0}\" is unloaded, and file does not exist.",
                                world.Name);
                    player.Message(mapSavingErrorMessage);
                }
            }
            else if (map.Save(fullFileName))
            {
                player.Message("Map saved succesfully.");
            }
            else
            {
                Logger.Log(LogType.Error,
                            "WorldCommands.WorldSave: Saving world \"{0}\" failed.", world.Name);
                player.Message(mapSavingErrorMessage);
            }
        }
Пример #21
0
        static void EconomyHandler(Player player, Command cmd)
        {
            try
            {
                string option = cmd.Next();
                string targetName = cmd.Next();
                string amount = cmd.Next();
                int amountnum;
                if (option == null)
                {
                    CdEconomy.PrintUsage(player);
                }
                if (option == "give")
                {
                    Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
                    if (!player.Can(Permission.ManageEconomy))
                    {
                        player.Message("&cYou do not have permission to use that command!");
                        return;
                    }

                    if (targetName == null)
                    {
                        player.Message("&ePlease type in a player's name to give " + ConfigKey.CurrencyKeyPl.GetString() + " to.");
                        return;
                    }


                    if (target == null)
                    {
                        return;
                    }
                    else
                    {
                        if ((player.Can(Permission.GiveSelf)) && (target == player)) //Giving yourself da monai
                        {
                            if (!int.TryParse(amount, out amountnum))
                            {
                                player.Message("&eThe amount must be a number without any decimals!");
                                return;
                            }
                            if (cmd.IsConfirmed)
                            {
                                //actually give the player the money
                                int tNewMoney = target.Info.Money + amountnum;

                                if (amountnum == 1)
                                {
                                    player.Message("&eYou have given {0} &C" + ConfigKey.CurrencyKeySl.GetString() + " &ecoin.", target.ClassyName, amountnum);
                                    target.Message("&e{0} &ehas given you {1} &e" + ConfigKey.CurrencyKeySl.GetString(), player.ClassyName, amountnum);
                                    Server.Players.Except(target).Except(player).Message("&e{0} &ewas given {1} &e" + ConfigKey.CurrencyKeySl.GetString() + " by {2}&e.", target.ClassyName, amountnum, player.ClassyName);
                                }
                                else
                                {
                                    player.Message("&eYou have given {0} &C{1} &e" + ConfigKey.CurrencyKeyPl.GetString(), target.ClassyName, amountnum);
                                    target.Message("&e{0} &ehas given you {1} &e" + ConfigKey.CurrencyKeyPl.GetString(), player.ClassyName, amountnum);
                                    Server.Players.Except(target).Except(player).Message("&e{0} &ewas given {1} &e" + ConfigKey.CurrencyKeyPl.GetString() + " by {2}&e.", target.ClassyName, amountnum, player.ClassyName);
                                }

                                target.Info.Money = tNewMoney;
                                return;
                            }
                            else
                            {
                                if (amountnum == 1)
                                {
                                    player.Confirm(cmd, "&eAre you sure you want to give {0} &C{1} &e " + ConfigKey.CurrencyKeySl.GetString() + "?", target.ClassyName, amountnum);
                                    return;
                                }
                                else
                                {
                                    player.Confirm(cmd, "&eAre you sure you want to give {0} &C{1} &e " + ConfigKey.CurrencyKeyPl.GetString() + "?", target.ClassyName, amountnum);
                                    return;
                                }
                            }

                        } //der
                        else if ((!player.Can(Permission.GiveSelf)) && (target == player)) //Not letting dat scum give himslef da monai
                        {
                            player.Message("&eYou cannot give yourself " + ConfigKey.CurrencyKeyPl.GetString());
                            return;
                        }

                        else if (!int.TryParse(amount, out amountnum))
                        {
                            player.Message("&eThe amount must be a number without any decimals!");
                            return;
                        }
                        if (cmd.IsConfirmed)
                        {
                            //actually give the player the money
                            int tNewMoney = target.Info.Money + amountnum;

                            if (amountnum == 1)
                            {
                                player.Message("&eYou have given {0} &C" + ConfigKey.CurrencyKeySl.GetString() + " &ecoin.", target.ClassyName, amountnum);
                                target.Message("&e{0} &ehas given you {1} &e" + ConfigKey.CurrencyKeySl.GetString(), player.ClassyName, amountnum);
                                Server.Players.Except(target).Except(player).Message("&e{0} &ewas given {1} &e" + ConfigKey.CurrencyKeySl.GetString() + " by {2}&e.", target.ClassyName, amountnum, player.ClassyName);
                            }
                            else
                            {
                                player.Message("&eYou have given {0} &C{1} &e" + ConfigKey.CurrencyKeyPl.GetString(), target.ClassyName, amountnum);
                                target.Message("&e{0} &ehas given you {1} &e" + ConfigKey.CurrencyKeyPl.GetString(), player.ClassyName, amountnum);
                                Server.Players.Except(target).Except(player).Message("&e{0} &ewas given {1} &e" + ConfigKey.CurrencyKeyPl.GetString() + " by {2}&e.", target.ClassyName, amountnum, player.ClassyName);
                            }

                            target.Info.Money = tNewMoney;
                            return;
                        }
                        else
                        {
                            if (amountnum == 1)
                            {
                                player.Confirm(cmd, "&eAre you sure you want to give {0} &C{1} &e " + ConfigKey.CurrencyKeySl.GetString() + "?", target.ClassyName, amountnum);
                                return;
                            }
                            else
                            {
                                player.Confirm(cmd, "&eAre you sure you want to give {0} &C{1} &e " + ConfigKey.CurrencyKeyPl.GetString() + "?", target.ClassyName, amountnum);
                                return;
                            }
                        }

                    }
                }
                if (option == "take")
                {
                    Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
                    if (!player.Can(Permission.ManageEconomy))
                    {
                        player.Message("&cYou do not have permission to use that command.");
                        return;
                    }

                    if (target == player)
                    {
                        player.Message("&eYou cannot take take " + ConfigKey.CurrencyKeyPl.GetString() + " from yourself.");
                        return;
                    }
                    if (targetName == null)
                    {
                        player.Message("&ePlease type in a player's name to take " + ConfigKey.CurrencyKeyPl.GetString() + " away from.");
                        return;
                    }

                    if (target == null)
                    {
                        return;
                    }
                    else
                    {
                        if (!int.TryParse(amount, out amountnum))
                        {
                            player.Message("&eThe amount must be a number!");
                            return;
                        }

                        if (cmd.IsConfirmed)
                        {
                            if (amountnum > target.Info.Money)
                            {
                                player.Message("{0}&e doesn't have that many " + ConfigKey.CurrencyKeyPl.GetString() + "!", target.ClassyName);
                                return;
                            }
                            else
                            {
                                //actually give the player the money
                                int tNewMoney = target.Info.Money - amountnum;
                                if (amountnum == 1)
                                {
                                    player.Message("&eYou have taken &c{1}&e " + ConfigKey.CurrencyKeySl.GetString() + " from {0}.", target.ClassyName, amountnum);
                                    target.Message("&e{0} &ehas taken {1} &e" + ConfigKey.CurrencyKeySl.GetString() + " from you.", player.ClassyName, amountnum);
                                    Server.Players.Except(target).Except(player).Message("&e{0} &etook {1} &e" + ConfigKey.CurrencyKeySl.GetString() + " from {2}&e.", player.ClassyName, amountnum, target.ClassyName);
                                }
                                else
                                {
                                    player.Message("&eYou have taken &c{1}&e " + ConfigKey.CurrencyKeyPl.GetString() + " from {0}.", target.ClassyName, amountnum);
                                    target.Message("&e{0} &ehas taken {1} &e" + ConfigKey.CurrencyKeyPl.GetString() + " from you.", player.ClassyName, amountnum);
                                    Server.Players.Except(target).Except(player).Message("&e{0} &etook {1} &e" + ConfigKey.CurrencyKeyPl.GetString() + " from {2}&e.", player.ClassyName, amountnum, target.ClassyName);
                                }
                                target.Info.Money = tNewMoney;
                                return;
                            }
                        }
                        else
                        {
                            player.Confirm(cmd, "&eAre you sure you want to take &c{1} &e" + ConfigKey.CurrencyKeyPl.GetString() + " from {0}?", target.ClassyName, amountnum);
                            return;
                        }

                    }


                }
                if (option == "pay")
                {

                    if (targetName == null)
                    {
                        player.Message("&ePlease type in a player's name to pay.");
                        return;
                    }
                    Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
                    if (target == player)
                    {
                        player.Message("You cannot pay youself.");
                        return;
                    }

                    if (target == null)
                    {
                        return;
                    }
                    else
                    {
                        if (!int.TryParse(amount, out amountnum))
                        {
                            player.Message("&eThe amount must be a number!");
                            return;
                        }

                        if (cmd.IsConfirmed)
                        {
                            if (amountnum > player.Info.Money)
                            {
                                player.Message("You don't have enough " + ConfigKey.CurrencyKeyPl.GetString() + "!");
                                return;
                            }
                            else
                            {
                                //show him da monai
                                int pNewMoney = player.Info.Money - amountnum;
                                int tNewMoney = target.Info.Money + amountnum;
                                if (amountnum == 1)
                                {
                                    player.Message("&eYou have paid &C{1}&e " + ConfigKey.CurrencyKeySl.GetString() + " to {0}.", target.ClassyName, amountnum);
                                    target.Message("&e{0} &ehas paid you {1} &e" + ConfigKey.CurrencyKeySl.GetString() + ".", player.ClassyName, amountnum);
                                    Server.Players.Except(target).Except(player).Message("&e{0} &ewas paid {1} &e" + ConfigKey.CurrencyKeySl.GetString() + " from {2}&e.", target.ClassyName, amountnum, player.ClassyName);
                                }
                                else
                                {
                                    player.Message("&eYou have paid &C{1}&e " + ConfigKey.CurrencyKeyPl.GetString() + " to {0}.", target.ClassyName, amountnum);
                                    target.Message("&e{0} &ehas paid you {1} &e" + ConfigKey.CurrencyKeyPl.GetString() + ".", player.ClassyName, amountnum);
                                    Server.Players.Except(target).Except(player).Message("&e{0} &ewas paid {1} &e" + ConfigKey.CurrencyKeyPl.GetString() + " from {2}&e.", target.ClassyName, amountnum, player.ClassyName);
                                }
                                player.Info.Money = pNewMoney;
                                target.Info.Money = tNewMoney;
                                return;
                            }
                        }
                        else
                        {
                            player.Confirm(cmd, "&eAre you sure you want to pay {0}&e {1} &e" + ConfigKey.CurrencyKeyPl.GetString() + "? Type /ok to continue.", target.ClassyName, amountnum);
                            return;
                        }


                    }
                }


                else if (option == "show")
                {

                    if (targetName == null)
                    {
                        player.Message("&ePlease type in a player's name to see how many " + ConfigKey.CurrencyKeyPl.GetString() + " they have.");
                        return;
                    }
                    Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
                    if (target == null)
                    {
                        player.Message("&eYou have &C{1} &e" + ConfigKey.CurrencyKeyPl.GetString() + ".", player.Info.Money);
                        return;
                    }

                    if (target == null)
                    {
                        return;
                    }
                    else
                    {
                        //actually show how much money that person has
                        player.Message("&e{0}&e has &C{1} &e" + ConfigKey.CurrencyKeyPl.GetString() + ".", target.ClassyName, target.Info.Money);
                    }

                }
            }
            catch (ArgumentNullException)
            {
                CdEconomy.PrintUsage(player);
            }
        }
Пример #22
0
        public static void RealmLoad(Player player, Command cmd, string fileName, string worldName, string buildRankName, string accessRankName)
        {
            if (worldName == null && player.World == null)
            {
                player.Message("When using /realm from console, you must specify the realm name.");
                return;
            }

            if (fileName == null)
            {
                // No params given at all

                return;
            }

            string fullFileName = WorldManager.FindMapFile(player, fileName);

            if (fullFileName == null)
            {
                return;
            }

            // Loading map into current realm
            if (worldName == null)
            {
                if (!cmd.IsConfirmed)
                {
                    player.Confirm(cmd, "About to replace THIS REALM with \"{0}\".", fileName);
                    return;
                }
                Map map;
                try
                {
                    map = MapUtility.Load(fullFileName);
                }
                catch (Exception ex)
                {
                    player.MessageNow("Could not load specified file: {0}: {1}", ex.GetType().Name, ex.Message);
                    return;
                }
                World realm = player.World;

                // Loading to current realm
                realm.MapChangedBy = player.Name;
                realm.ChangeMap(map);

                realm.Players.Message(player, "{0}&S loaded a new map for this realm.",
                                      player.ClassyName);
                player.MessageNow("New map loaded for the realm {0}", realm.ClassyName);

                Logger.Log(LogType.UserActivity,
                           "{0} loaded new map for realm \"{1}\" from {2}",
                           player.Name, realm.Name, fileName);
                realm.IsHidden = false;
                realm.IsRealm  = true;
                WorldManager.SaveWorldList();
            }
            else
            {
                // Loading to some other (or new) realm
                if (!World.IsValidName(worldName))
                {
                    player.MessageInvalidWorldName(worldName);
                    return;
                }

                Rank buildRank  = RankManager.DefaultBuildRank;
                Rank accessRank = null;
                if (buildRankName != null)
                {
                    buildRank = RankManager.FindRank(buildRankName);
                    if (buildRank == null)
                    {
                        player.MessageNoRank(buildRankName);
                        return;
                    }
                    if (accessRankName != null)
                    {
                        accessRank = RankManager.FindRank(accessRankName);
                        if (accessRank == null)
                        {
                            player.MessageNoRank(accessRankName);
                            return;
                        }
                    }
                }

                // Retype realm name, if needed
                if (worldName == "-")
                {
                    if (player.LastUsedWorldName != null)
                    {
                        worldName = player.LastUsedWorldName;
                    }
                    else
                    {
                        player.Message("Cannot repeat realm name: you haven't used any names yet.");
                        return;
                    }
                }

                lock (WorldManager.SyncRoot)
                {
                    World realm = WorldManager.FindWorldExact(worldName);
                    if (realm != null)
                    {
                        player.LastUsedWorldName = realm.Name;
                        // Replacing existing realm's map
                        if (!cmd.IsConfirmed)
                        {
                            player.Confirm(cmd, "About to replace realm map for {0}&S with \"{1}\".",
                                           realm.ClassyName, fileName);
                            return;
                        }

                        Map map;
                        try
                        {
                            map            = MapUtility.Load(fullFileName);
                            realm.IsHidden = false;
                            realm.IsRealm  = true;
                            WorldManager.SaveWorldList();
                        }
                        catch (Exception ex)
                        {
                            player.MessageNow("Could not load specified file: {0}: {1}", ex.GetType().Name, ex.Message);
                            return;
                        }

                        try
                        {
                            realm.MapChangedBy = player.Name;
                            realm.ChangeMap(map);
                            realm.IsHidden = false;
                            realm.IsRealm  = true;
                            WorldManager.SaveWorldList();
                        }
                        catch (WorldOpException ex)
                        {
                            Logger.Log(LogType.Error,
                                       "Could not complete RealmLoad operation: {0}", ex.Message);
                            player.Message("&WRealmLoad: {0}", ex.Message);
                            return;
                        }

                        realm.Players.Message(player, "{0}&S loaded a new map for the realm {1}",
                                              player.ClassyName, realm.ClassyName);
                        player.MessageNow("New map for the realm {0}&S has been loaded.", realm.ClassyName);
                        Logger.Log(LogType.UserActivity,
                                   "{0} loaded new map for realm \"{1}\" from {2}",
                                   player.Name, realm.Name, fullFileName);
                    }
                    else
                    {
                        // Adding a new realm
                        string targetFullFileName = Path.Combine(Paths.MapPath, worldName + ".fcm");
                        if (!cmd.IsConfirmed &&
                            File.Exists(targetFullFileName) && // target file already exists
                            !Paths.Compare(targetFullFileName, fullFileName))
                        {
                            // and is different from sourceFile
                            player.Confirm(cmd,
                                           "A map named \"{0}\" already exists, and will be overwritten with \"{1}\".",
                                           Path.GetFileName(targetFullFileName), Path.GetFileName(fullFileName));
                            return;
                        }

                        Map map;
                        try
                        {
                            map = MapUtility.Load(fullFileName);
                            //realm.IsHidden = false;
                            //realm.IsRealm = true;
                            //WorldManager.SaveWorldList();
                        }
                        catch (Exception ex)
                        {
                            player.MessageNow("Could not load \"{0}\": {1}: {2}",
                                              fileName, ex.GetType().Name, ex.Message);
                            return;
                        }

                        World newWorld;
                        try
                        {
                            newWorld = WorldManager.AddWorld(player, worldName, map, false);
                        }
                        catch (WorldOpException ex)
                        {
                            player.Message("RealmLoad: {0}", ex.Message);
                            return;
                        }

                        player.LastUsedWorldName       = worldName;
                        newWorld.BuildSecurity.MinRank = buildRank;
                        if (accessRank == null)
                        {
                            newWorld.AccessSecurity.ResetMinRank();
                        }
                        else
                        {
                            newWorld.AccessSecurity.MinRank = accessRank;
                        }
                        newWorld.BlockDB.AutoToggleIfNeeded();
                        if (BlockDB.IsEnabledGlobally && newWorld.BlockDB.IsEnabled)
                        {
                            player.Message("BlockDB is now auto-enabled on realm {0}", newWorld.ClassyName);
                        }
                        newWorld.LoadedBy = player.Name;
                        newWorld.LoadedOn = DateTime.UtcNow;
                        Server.Message("{0}&S created a new realm named {1}",
                                       player.ClassyName, newWorld.ClassyName);
                        Logger.Log(LogType.UserActivity,
                                   "{0} created a new realm named \"{1}\" (loaded from \"{2}\")",
                                   player.Name, worldName, fileName);
                        newWorld.IsHidden = false;
                        newWorld.IsRealm  = true;
                        WorldManager.SaveWorldList();
                        player.MessageNow("Access permission is {0}+&S, and build permission is {1}+",
                                          newWorld.AccessSecurity.MinRank.ClassyName,
                                          newWorld.BuildSecurity.MinRank.ClassyName);
                    }
                }
            }

            Server.RequestGC();
        }
Пример #23
0
        static void EconomyHandler(Player player, Command cmd)
        {
            try
            {
                string option = cmd.Next();
                string targetName = cmd.Next();
                string amount = cmd.Next();
                int amountnum;
                if (option == null)
                {
                    CdEconomy.PrintUsage(player);
                }
                if (option == "give")
                {
                    if (!player.Can(Permission.ManageEconomy))
                    {
                        player.Message("You do not have the required permisions to use that command!");
                        return;
                    }
                    Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
                    if (targetName == null)
                    {
                        player.Message("&ePlease type in a player's name to give bits towards.");
                        return;
                    }
                    if (target == null)
                    {
                        return;
                    }
                    else
                    {
                        if (!int.TryParse(amount, out amountnum))
                        {
                            player.Message("&ePlease select from a whole number.");
                            return;
                        }
                        if (cmd.IsConfirmed)
                        {
                            //actually give the player the money
                            int tNewMoney = target.Info.Money + amountnum;
                            player.Message("&eYou have given {0} &C{1} &ebit(s).", target.ClassyName, amountnum);
                            target.Message("&e{0} &ehas given you {1} &ebit(s).", player.ClassyName, amountnum);
                            Server.Players.Except(target).Except(player).Message("&e{0} &ewas given {1} &ebit(s) from {2}&e.", target.ClassyName, amountnum, player.ClassyName);
                            target.Info.Money = tNewMoney;
                            return;
                        }
                        else
                        {
                            player.Confirm(cmd, "&eAre you sure you want to give {0} &C{1} &ebits?&s", target.ClassyName, amountnum);
                            return;
                        }

                    }
                }
                if (option == "take")
                {
                    if (!player.Can(Permission.ManageEconomy))
                    {
                        player.Message("You do not have the required permisions to use that command!");
                        return;
                    }
                    Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
                    if (targetName == null)
                    {
                        player.Message("&ePlease type in a player's name to take bits away from.");
                        return;
                    }
                    if (target == null)
                    {
                        return;
                    }
                    else
                    {
                        if (!int.TryParse(amount, out amountnum))
                        {
                            player.Message("&eThe amount must be a number!");
                            return;
                        }

                        if (cmd.IsConfirmed)
                        {
                            if (amountnum > target.Info.Money)
                            {
                                player.Message("{0}&e doesn't have that many bits!", target.ClassyName);
                                return;
                            }
                            else
                            {
                                //actually give the player the money
                                int tNewMoney = target.Info.Money - amountnum;
                                player.Message("&eYou have taken &c{1}&e from {0}.", target.ClassyName, amountnum);
                                target.Message("&e{0} &ehas taken {1} &ebit(s) from you.", player.ClassyName, amountnum);
                                Server.Players.Except(target).Except(player).Message("&e{0} &etook {1} &ebit(s) from {2}&e.", player.ClassyName, amountnum, target.ClassyName);
                                target.Info.Money = tNewMoney;
                                return;
                            }
                        }
                        else
                        {
                            player.Confirm(cmd, "&eAre you sure you want to take &c{1} &ebits from {0}&e?&s", target.ClassyName, amountnum);
                            return;
                        }

                    }

                }

                if (option == "pay")
                {
                    //lotsa idiot proofing in this one ^.^

                    if (targetName == null)
                    {
                        player.Message("&ePlease type in a player's name to pay bits towards.");
                        return;
                    }
                    Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
                    if (target == player)
                    {
                        player.Message("You can't pay yourself >.> Doesn't work like that.");
                        return;
                    }

                    if (target == null)
                    {
                        return;
                    }
                    else
                    {
                        if (!int.TryParse(amount, out amountnum))
                        {
                            player.Message("&eThe amount must be a positive whole number!");
                            return;
                        }
                        if (amountnum < 1)
                        {
                            player.Message("&eThe amount must be a positive whole number!");
                            return;
                        }

                        if (cmd.IsConfirmed)
                        {
                            if (amountnum > player.Info.Money)
                            {
                                player.Message("You don't have that many bits!");
                                return;
                            }
                            else
                            {
                                //show him da monai
                                int pNewMoney = player.Info.Money - amountnum;
                                int tNewMoney = target.Info.Money + amountnum;
                                player.Message("&eYou have paid &C{1}&e to {0}&e.", target.ClassyName, amountnum);
                                target.Message("&e{0} &ehas paid you {1} &ebit(s).", player.ClassyName, amountnum);
                                Server.Players.Except(target).Except(player).Message("&e{0} &ewas paid {1} &ebit(s) from {2}&e.", target.ClassyName, amountnum, player.ClassyName);
                                player.Info.Money = pNewMoney;
                                target.Info.Money = tNewMoney;
                                return;
                            }
                        }
                        else
                        {
                            player.Confirm(cmd, "&eAre you sure you want to pay {0}&e {1} &ebits?&s", target.ClassyName, amountnum);
                            return;
                        }

                    }
                }

                else if (option == "show")
                {
                    Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
                    if (targetName == null)
                    {
                        player.Message("&ePlease type in a player's name to see how many bits they have.");
                        return;
                    }

                    if (target == null)
                    {
                        return;
                    }
                    else
                    {
                        //actually show how much money that person has
                        player.Message("&e{0}&e has &C{1}&e bits currently!", target.ClassyName, target.Info.Money);
                    }

                }
                else
                {
                    player.Message("&eValid choices are '/economy take', '/economy give', '/economy show' and '/econ pay'.");
                    return;
                }
            }
            catch (ArgumentNullException)
            {
                CdEconomy.PrintUsage(player);
            }
        }
Пример #24
0
        static void EconomyHandler(Player player, Command cmd)
        {
            try
            {
                string option = cmd.Next();
                string targetName = cmd.Next();
                string amount = cmd.Next();
                int amountnum;
                if (option == null)
                {
                    CdEconomy.PrintUsage(player);
                }
                if (option == "give")
                {
                    if (!player.Can(Permission.ManageEconomy))
                    {
                        player.Message("&cYou do not have permission to use that command!");
                        return;
                    }
                    if (targetName == null)
                    {
                        player.Message("&ePlease type in a player's name to give coins to.");
                        return;
                    }
                    Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);

                    if (target == null)
                    {
                        return;
                    }
                    else
                    {
                        if (!int.TryParse(amount, out amountnum))
                        {
                            player.Message("&eThe amount must be a number without any decimals!");
                            return;
                        }
                        if (cmd.IsConfirmed)
                        {
                            //actually give the player the money
                            int tNewMoney = target.Info.Money + amountnum;

                            if (amountnum == 1)
                            {
                                player.Message("&eYou have given {0} &C{1} &ecoin.", target.ClassyName, amountnum);
                                target.Message("&e{0} &ehas given you {1} &ecoin.", player.ClassyName, amountnum);
                                Server.Players.Except(target).Except(player).Message("&e{0} &ewas given {1} &ecoin by {2}&e.", target.ClassyName, amountnum, player.ClassyName);
                            }
                            else
                            {
                                player.Message("&eYou have given {0} &C{1} &ecoins.", target.ClassyName, amountnum);
                                target.Message("&e{0} &ehas given you {1} &ecoins.", player.ClassyName, amountnum);
                                Server.Players.Except(target).Except(player).Message("&e{0} &ewas given {1} &ecoins by {2}&e.", target.ClassyName, amountnum, player.ClassyName);
                            }

                            target.Info.Money = tNewMoney;
                            return;
                        }
                        else
                        {
                            if (amountnum == 1) {
                            player.Confirm(cmd, "&eAre you sure you want to give {0} &C{1} &ecoin?", target.ClassyName, amountnum);
                            return;
                        }
                        else {
                            player.Confirm(cmd, "&eAre you sure you want to give {0} &C{1} &ecoins?", target.ClassyName, amountnum);
                            return;
                        }
                        }

                    }
                }
                if (option == "take")
                {
                    if (!player.Can(Permission.ManageEconomy))
                    {
                        player.Message("&cYou do not have permission to use that command.");
                        return;
                    }
                    if (targetName == null)
                    {
                        player.Message("&ePlease type in a player's name to take coins away from.");
                        return;
                    }
                    Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);

                    if (target == null)
                    {
                        return;
                    }
                    else
                    {
                        if (!int.TryParse(amount, out amountnum))
                        {
                            player.Message("&eThe amount must be a number!");
                            return;
                        }

                        if (cmd.IsConfirmed)
                        {
                            if (amountnum > target.Info.Money)
                            {
                                player.Message("{0}&e doesn't have that many coins!", target.ClassyName);
                                return;
                            }
                            else
                            {
                                //actually give the player the money
                                int tNewMoney = target.Info.Money - amountnum;
                                if (amountnum == 1)
                                {
                                    player.Message("&eYou have taken &c{1}&e coin from {0}.", target.ClassyName, amountnum);
                                    target.Message("&e{0} &ehas taken {1} &ecoin from you.", player.ClassyName, amountnum);
                                    Server.Players.Except(target).Except(player).Message("&e{0} &etook {1} &ecoin from {2}&e.", player.ClassyName, amountnum, target.ClassyName);
                                }
                                else
                                {
                                    player.Message("&eYou have taken &c{1}&e coins from {0}.", target.ClassyName, amountnum);
                                    target.Message("&e{0} &ehas taken {1} &ecoins from you.", player.ClassyName, amountnum);
                                    Server.Players.Except(target).Except(player).Message("&e{0} &etook {1} &ecoins from {2}&e.", player.ClassyName, amountnum, target.ClassyName);
                                }
                                target.Info.Money = tNewMoney;
                                return;
                            }
                        }
                        else
                        {
                            player.Confirm(cmd, "&eAre you sure you want to take &c{1} &ecoins from {0}?", target.ClassyName, amountnum);
                            return;
                        }

                    }


                }
                if (option == "pay")
                {
                    //lotsa idiot proofing in this one ^.^

                    if (targetName == null)
                    {
                        player.Message("&ePlease type in a player's name to pay.");
                        return;
                    }
                    Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
                    if (target == player)
                    {
                        player.Message("You cannot pay youself.");
                        return;
                    }

                    if (target == null)
                    {
                        return;
                    }
                    else
                    {
                        if (!int.TryParse(amount, out amountnum))
                        {
                            player.Message("&eThe amount must be a number!");
                            return;
                        }

                        if (cmd.IsConfirmed)
                        {
                            if (amountnum > player.Info.Money)
                            {
                                player.Message("You don't have enough coins!");
                                return;
                            }
                            else
                            {
                                //show him da monai
                                int pNewMoney = player.Info.Money - amountnum;
                                int tNewMoney = target.Info.Money + amountnum;
                                if (amountnum == 1)
                                {
                                    player.Message("&eYou have paid &C{1}&e coin to {0}.", target.ClassyName, amountnum);
                                    target.Message("&e{0} &ehas paid you {1} &ecoin.", player.ClassyName, amountnum);
                                    Server.Players.Except(target).Except(player).Message("&e{0} &ewas paid {1} &ecoin from {2}&e.", target.ClassyName, amountnum, player.ClassyName);
                                }
                                else
                                {
                                    player.Message("&eYou have paid &C{1}&e coins to {0}.", target.ClassyName, amountnum);
                                    target.Message("&e{0} &ehas paid you {1} &ecoins.", player.ClassyName, amountnum);
                                    Server.Players.Except(target).Except(player).Message("&e{0} &ewas paid {1} &ecoins from {2}&e.", target.ClassyName, amountnum, player.ClassyName);
                                }
                                player.Info.Money = pNewMoney;
                                target.Info.Money = tNewMoney;
                                return;
                            }
                        }
                        else
                        {
                            player.Confirm(cmd, "&eAre you sure you want to pay {0}&e {1} &ecoins? Type /ok to continue.", target.ClassyName, amountnum);
                            return;
                        }


                    }
                }


                else if (option == "show")
                {

                    if (targetName == null)
                    {
                        player.Message("&ePlease type in a player's name to see how many coins they have.");
                        return;
                    }
                    Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);

                    if (target == null)
                    {
                        return;
                    }
                    else
                    {
                        //actually show how much money that person has
                        player.Message("&e{0} has &C{1} &ecoins!", target.ClassyName, target.Info.Money);
                    }

                }
                else
                {
                    player.Message("&eOptions are &a/Economy pay&e, &a/Economy take&e, &a/Economy give&e, and &a/Economy show&e.");
                    return;
                }
            }
            catch (ArgumentNullException)
            {
                CdEconomy.PrintUsage(player);
            }
        }
Пример #25
0
        static void PayHandler(Player player, Command cmd)
        {
            string targetName = cmd.Next();
            string amount = cmd.Next();
            int amountnum;
            //lotsa idiot proofing in this one ^.^

            if (targetName == null)
            {
                player.Message("&ePlease type in a player's name to pay bits towards.");
                return;
            }
            Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
            if (target == player)
            {
                player.Message("You can't pay yourself >.> Doesn't work like that.");
                return;
            }

            if (target == null)
            {
                return;
            }
            else
            {
                if (!int.TryParse(amount, out amountnum))
                {
                    player.Message("&eThe amount must be a positive whole number!");
                    return;
                }
                if (amountnum < 1)
                {
                    player.Message("&eThe amount must be a positive whole number!");
                    return;
                }

                if (cmd.IsConfirmed)
                {
                    if (amountnum > player.Info.Money)
                    {
                        player.Message("You don't have that many bits!");
                        return;
                    }
                    else
                    {
                        //show him da monai
                        int pNewMoney = player.Info.Money - amountnum;
                        int tNewMoney = target.Info.Money + amountnum;
                        player.Message("&eYou have paid &C{1}&e to {0}&e.", target.ClassyName, amountnum);
                        target.Message("&e{0} &ehas paid you {1} &ebit(s).", player.ClassyName, amountnum);
                        Server.Players.Except(target).Except(player).Message("&e{0} &ewas paid {1} &ebit(s) from {2}&e.", target.ClassyName, amountnum, player.ClassyName);
                        player.Info.Money = pNewMoney;
                        target.Info.Money = tNewMoney;
                        return;
                    }
                }
                else
                {
                    player.Confirm(cmd, "&eAre you sure you want to pay {0}&e {1} &ebits?", target.ClassyName, amountnum);
                    return;
                }

            }
        }
Пример #26
0
 static void Fill2DCallback( Player player, Vector3I[] marks, object tag )
 {
     DrawOperation op = (DrawOperation)tag;
     if( !op.Prepare( marks ) ) return;
     if( player.WorldMap.GetBlock( marks[0] ) == Block.Air ) {
         player.Confirm( Fill2DConfirmCallback, op, "{0}: Replace air?", op.Description );
     } else {
         Fill2DConfirmCallback( player, op, false );
     }
 }
Пример #27
0
        public static void RankHandler( Player player, Command cmd )
        {
            string name = cmd.Next();
            string newRankName = cmd.Next();

            // Check arguments
            if( name == null || newRankName == null ) {
                CdRank.PrintUsage( player );
                player.Message( "See &H/Ranks&S for list of ranks." );
                return;
            }

            // Parse rank name
            Rank newRank = RankManager.FindRank( newRankName );
            if( newRank == null ) {
                player.MessageNoRank( newRankName );
                return;
            }

            // Parse player name
            if( name == "-" ) {
                if( player.LastUsedPlayerName != null ) {
                    name = player.LastUsedPlayerName;
                } else {
                    player.Message( "Cannot repeat player name: you haven't used any names yet." );
                    return;
                }
            }
            PlayerInfo targetInfo = PlayerDB.FindPlayerInfoExact( name );

            if( targetInfo == null ) {
                if( !player.Can( Permission.EditPlayerDB ) ) {
                    player.MessageNoPlayer( name );
                    return;
                }
                if( !Player.IsValidName( name ) ) {
                    player.MessageInvalidPlayerName( name );
                    CdRank.PrintUsage( player );
                    return;
                }
                if( cmd.IsConfirmed ) {
                    if( newRank > RankManager.DefaultRank ) {
                        targetInfo = PlayerDB.AddFakeEntry( name, RankChangeType.Promoted );
                    } else {
                        targetInfo = PlayerDB.AddFakeEntry( name, RankChangeType.Demoted );
                    }
                } else {
                    player.Confirm( cmd,
                                    "Warning: Player \"{0}\" is not in the database (possible typo). Type the full name or",
                                    name );
                    return;
                }
            }

            try {
                player.LastUsedPlayerName = targetInfo.Name;

                //reset temprank values
                if (targetInfo.isTempRanked)
                {
                    targetInfo.isTempRanked = false;
                    targetInfo.tempRankTime = TimeSpan.FromSeconds(0);
                }
                targetInfo.ChangeRank( player, newRank, cmd.NextAll(), true, true, false );
            } catch( PlayerOpException ex ) {
                player.Message( ex.MessageColored );
            }
        }
Пример #28
0
        static void UndoPlayerHandler2(Player player, Command cmd)
        {
            if (player.World == null) PlayerOpException.ThrowNoWorld(player);

            if (!BlockDB.IsEnabledGlobally)
            {
                player.Message("&WBlockDB is disabled on this server.\nThe undo of the player's blocks failed.");
                return;
            }

            World world = player.World;
            if (!world.BlockDB.IsEnabled)
            {
                player.Message("&WBlockDB is disabled in this world.\nThe undo of the player's blocks failed.");
                return;
            }

            string name = cmd.Next();
            string range = cmd.Next();
            if (name == null || range == null)
            {
                CdUndoPlayer.PrintUsage(player);
                return;
            }

            PlayerInfo target = PlayerDB.FindPlayerInfoOrPrintMatches(player, name);
            if (target == null) return;

            if (player.Info != target && !player.Can(Permission.UndoOthersActions, target.Rank))
            {
                player.Message("You may only undo actions of players ranked {0}&S or lower.",
                                player.Info.Rank.GetLimit(Permission.UndoOthersActions).ClassyName);
                player.Message("Player {0}&S is ranked {1}", target.ClassyName, target.Rank.ClassyName);
                return;
            }

            int count;
            TimeSpan span;
            BlockDBEntry[] changes;
            if (Int32.TryParse(range, out count))
            {
                changes = world.BlockDB.Lookup(target, count);
                if (changes.Length > 0)
                {
                    player.Confirm(cmd, "Undo last {0} changes made by player {1}&S?",
                                    changes.Length, target.ClassyName);
                    return;
                }

            }
            else if (range.TryParseMiniTimespan(out span))
            {
                changes = world.BlockDB.Lookup(target, span);
                if (changes.Length > 0)
                {
                    player.Confirm(cmd, "Undo changes ({0}) made by {1}&S in the last {2}?",
                                    changes.Length, target.ClassyName, span.ToMiniString());
                    return;
                }
            }
            else
            {
                CdBanx.PrintUsage(player);
                return;
            }

            if (changes.Length == 0)
            {
                player.Message("BanX: Found nothing to undo.");
                return;
            }

            BlockChangeContext context = BlockChangeContext.Drawn;
            if (player.Info == target)
            {
                context |= BlockChangeContext.UndoneSelf;
            }
            else
            {
                context |= BlockChangeContext.UndoneOther;
            }

            int blocks = 0,
                blocksDenied = 0;

            UndoState undoState = player.DrawBegin(null);
            Map map = player.World.Map;

            for (int i = 0; i < changes.Length; i++)
            {
                DrawOneBlock(player, map, changes[i].OldBlock,
                              changes[i].Coord, context,
                              ref blocks, ref blocksDenied, undoState);
            }

            Logger.Log(LogType.UserActivity,
                        "{0} undid {1} blocks changed by player {2} (on world {3})",
                        player.Name,
                        blocks,
                        target.Name,
                        player.World.Name);

            DrawingFinished(player, "UndoPlayer'ed", blocks, blocksDenied);
        }
Пример #29
0
        static void BlockDBHandler(Player player, Command cmd)
        {
            if (!BlockDB.IsEnabledGlobally)
            {
                player.Message("&WBlockDB is disabled on this server.");
                return;
            }

            string worldName = cmd.Next();
            if (worldName == null)
            {
                int total = 0;
                World[] autoEnabledWorlds = WorldManager.Worlds.Where(w => (w.BlockDB.EnabledState == YesNoAuto.Auto) && w.BlockDB.IsEnabled).ToArray();
                if (autoEnabledWorlds.Length > 0)
                {
                    total += autoEnabledWorlds.Length;
                    player.Message("BlockDB is auto-enabled on: {0}",
                                    autoEnabledWorlds.JoinToClassyString());
                }

                World[] manuallyEnabledWorlds = WorldManager.Worlds.Where(w => w.BlockDB.EnabledState == YesNoAuto.Yes).ToArray();
                if (manuallyEnabledWorlds.Length > 0)
                {
                    total += manuallyEnabledWorlds.Length;
                    player.Message("BlockDB is manually enabled on: {0}",
                                    manuallyEnabledWorlds.JoinToClassyString());
                }

                World[] manuallyDisabledWorlds = WorldManager.Worlds.Where(w => w.BlockDB.EnabledState == YesNoAuto.No).ToArray();
                if (manuallyDisabledWorlds.Length > 0)
                {
                    player.Message("BlockDB is manually disabled on: {0}",
                                    manuallyDisabledWorlds.JoinToClassyString());
                }

                if (total == 0)
                {
                    player.Message("BlockDB is not enabled on any world.");
                }
                return;
            }

            World world = WorldManager.FindWorldOrPrintMatches(player, worldName);
            if (world == null) return;
            BlockDB db = world.BlockDB;

            lock (db.SyncRoot)
            {
                string op = cmd.Next();
                if (op == null)
                {
                    if (!db.IsEnabled)
                    {
                        if (db.EnabledState == YesNoAuto.Auto)
                        {
                            player.Message("BlockDB is disabled (auto) on world {0}", world.ClassyName);
                        }
                        else
                        {
                            player.Message("BlockDB is disabled on world {0}", world.ClassyName);
                        }
                    }
                    else
                    {
                        if (db.IsPreloaded)
                        {
                            if (db.EnabledState == YesNoAuto.Auto)
                            {
                                player.Message("BlockDB is enabled (auto) and preloaded on world {0}", world.ClassyName);
                            }
                            else
                            {
                                player.Message("BlockDB is enabled and preloaded on world {0}", world.ClassyName);
                            }
                        }
                        else
                        {
                            if (db.EnabledState == YesNoAuto.Auto)
                            {
                                player.Message("BlockDB is enabled (auto) on world {0}", world.ClassyName);
                            }
                            else
                            {
                                player.Message("BlockDB is enabled on world {0}", world.ClassyName);
                            }
                        }
                        player.Message("    Change limit: {0}    Time limit: {1}",
                                        db.Limit == 0 ? "none" : db.Limit.ToString(),
                                        db.TimeLimit == TimeSpan.Zero ? "none" : db.TimeLimit.ToMiniString());
                    }
                    return;
                }

                switch (op.ToLower())
                {
                    case "on":
                        // enables BlockDB
                        if (db.EnabledState == YesNoAuto.Yes)
                        {
                            player.Message("BlockDB is already manually enabled on world {0}", world.ClassyName);

                        }
                        else if (db.EnabledState == YesNoAuto.Auto && db.IsEnabled)
                        {
                            db.EnabledState = YesNoAuto.Yes;
                            WorldManager.SaveWorldList();
                            player.Message("BlockDB was auto-enabled, and is now manually enabled on world {0}", world.ClassyName);

                        }
                        else
                        {
                            db.EnabledState = YesNoAuto.Yes;
                            WorldManager.SaveWorldList();
                            player.Message("BlockDB is now manually enabled on world {0}", world.ClassyName);
                        }
                        break;

                    case "off":
                        // disables BlockDB
                        if (db.EnabledState == YesNoAuto.No)
                        {
                            player.Message("BlockDB is already manually disabled on world {0}", world.ClassyName);

                        }
                        else if (db.IsEnabled)
                        {
                            if (cmd.IsConfirmed)
                            {
                                db.EnabledState = YesNoAuto.No;
                                WorldManager.SaveWorldList();
                                player.Message("BlockDB is now manually disabled on world {0}&S. Use &H/BlockDB {1} clear&S to delete all the data.",
                                                world.ClassyName, world.Name);
                            }
                            else
                            {
                                player.Confirm(cmd,
                                                "Disable BlockDB on world {0}&S? Block changes will stop being recorded.",
                                                world.ClassyName);
                            }
                        }
                        else
                        {
                            db.EnabledState = YesNoAuto.No;
                            WorldManager.SaveWorldList();
                            player.Message("BlockDB was auto-disabled, and is now manually disabled on world {0}&S.",
                                            world.ClassyName);
                        }
                        break;

                    case "auto":
                        if (db.EnabledState == YesNoAuto.Auto)
                        {
                            player.Message("BlockDB is already set to automatically enable/disable itself on world {0}", world.ClassyName);
                        }
                        else
                        {
                            db.EnabledState = YesNoAuto.Auto;
                            WorldManager.SaveWorldList();
                            if (db.IsEnabled)
                            {
                                player.Message("BlockDB is now auto-enabled on world {0}",
                                                world.ClassyName);
                            }
                            else
                            {
                                player.Message("BlockDB is now auto-disabled on world {0}",
                                                world.ClassyName);
                            }
                        }
                        break;

                    case "limit":
                        // sets or resets limit on the number of changes to store
                        if (db.IsEnabled)
                        {
                            string limitString = cmd.Next();
                            int limitNumber;

                            if (limitString == null)
                            {
                                player.Message("BlockDB: Limit for world {0}&S is {1}",
                                                world.ClassyName,
                                                (db.Limit == 0 ? "none" : db.Limit.ToString()));
                                return;
                            }

                            if (limitString.Equals("none", StringComparison.OrdinalIgnoreCase))
                            {
                                limitNumber = 0;

                            }
                            else if (!Int32.TryParse(limitString, out limitNumber))
                            {
                                CdBlockDB.PrintUsage(player);
                                return;

                            }
                            else if (limitNumber < 0)
                            {
                                player.Message("BlockDB: Limit must be non-negative.");
                                return;
                            }

                            if (!cmd.IsConfirmed && limitNumber != 0)
                            {
                                player.Confirm(cmd, "BlockDB: Change limit? Some old data for world {0}&S may be discarded.", world.ClassyName);

                            }
                            else
                            {
                                string limitDisplayString = (limitNumber == 0 ? "none" : limitNumber.ToString());
                                if (db.Limit == limitNumber)
                                {
                                    player.Message("BlockDB: Limit for world {0}&S is already set to {1}",
                                                   world.ClassyName, limitDisplayString);

                                }
                                else
                                {
                                    db.Limit = limitNumber;
                                    WorldManager.SaveWorldList();
                                    player.Message("BlockDB: Limit for world {0}&S set to {1}",
                                                   world.ClassyName, limitDisplayString);
                                }
                            }

                        }
                        else
                        {
                            player.Message("Block tracking is disabled on world {0}", world.ClassyName);
                        }
                        break;

                    case "timelimit":
                        // sets or resets limit on the age of changes to store
                        if (db.IsEnabled)
                        {
                            string limitString = cmd.Next();

                            if (limitString == null)
                            {
                                if (db.TimeLimit == TimeSpan.Zero)
                                {
                                    player.Message("BlockDB: There is no time limit for world {0}",
                                                    world.ClassyName);
                                }
                                else
                                {
                                    player.Message("BlockDB: Time limit for world {0}&S is {1}",
                                                    world.ClassyName, db.TimeLimit.ToMiniString());
                                }
                                return;
                            }

                            TimeSpan limit;
                            if (limitString.Equals("none", StringComparison.OrdinalIgnoreCase))
                            {
                                limit = TimeSpan.Zero;

                            }
                            else if (!limitString.TryParseMiniTimespan(out limit))
                            {
                                CdBlockDB.PrintUsage(player);
                                return;
                            }
                            if (limit > DateTimeUtil.MaxTimeSpan)
                            {
                                player.MessageMaxTimeSpan();
                                return;
                            }

                            if (!cmd.IsConfirmed && limit != TimeSpan.Zero)
                            {
                                player.Confirm(cmd, "BlockDB: Change time limit? Some old data for world {0}&S may be discarded.", world.ClassyName);

                            }
                            else
                            {

                                if (db.TimeLimit == limit)
                                {
                                    if (db.TimeLimit == TimeSpan.Zero)
                                    {
                                        player.Message("BlockDB: There is already no time limit for world {0}",
                                                        world.ClassyName);
                                    }
                                    else
                                    {
                                        player.Message("BlockDB: Time limit for world {0}&S is already set to {1}",
                                                        world.ClassyName, db.TimeLimit.ToMiniString());
                                    }
                                }
                                else
                                {
                                    db.TimeLimit = limit;
                                    WorldManager.SaveWorldList();
                                    if (db.TimeLimit == TimeSpan.Zero)
                                    {
                                        player.Message("BlockDB: Time limit removed for world {0}",
                                                        world.ClassyName);
                                    }
                                    else
                                    {
                                        player.Message("BlockDB: Time limit for world {0}&S set to {1}",
                                                        world.ClassyName, db.TimeLimit.ToMiniString());
                                    }
                                }
                            }

                        }
                        else
                        {
                            player.Message("Block tracking is disabled on world {0}", world.ClassyName);
                        }
                        break;

                    case "clear":
                        // wipes BlockDB data
                        bool hasData = (db.IsEnabled || File.Exists(db.FileName));
                        if (hasData)
                        {
                            if (cmd.IsConfirmed)
                            {
                                db.Clear();
                                player.Message("BlockDB: Cleared all data for {0}", world.ClassyName);
                            }
                            else
                            {
                                player.Confirm(cmd, "Clear BlockDB data for world {0}&S? This cannot be undone.",
                                                world.ClassyName);
                            }
                        }
                        else
                        {
                            player.Message("BlockDB: No data to clear for world {0}", world.ClassyName);
                        }
                        break;

                    case "preload":
                        // enables/disables BlockDB preloading
                        if (db.IsEnabled)
                        {
                            string param = cmd.Next();
                            if (param == null)
                            {
                                // shows current preload setting
                                player.Message("BlockDB preloading is {0} for world {1}",
                                                (db.IsPreloaded ? "ON" : "OFF"),
                                                world.ClassyName);

                            }
                            else if (param.Equals("on", StringComparison.OrdinalIgnoreCase))
                            {
                                // turns preload on
                                if (db.IsPreloaded)
                                {
                                    player.Message("BlockDB preloading is already enabled on world {0}", world.ClassyName);
                                }
                                else
                                {
                                    db.IsPreloaded = true;
                                    WorldManager.SaveWorldList();
                                    player.Message("BlockDB preloading is now enabled on world {0}", world.ClassyName);
                                }

                            }
                            else if (param.Equals("off", StringComparison.OrdinalIgnoreCase))
                            {
                                // turns preload off
                                if (!db.IsPreloaded)
                                {
                                    player.Message("BlockDB preloading is already disabled on world {0}", world.ClassyName);
                                }
                                else
                                {
                                    db.IsPreloaded = false;
                                    WorldManager.SaveWorldList();
                                    player.Message("BlockDB preloading is now disabled on world {0}", world.ClassyName);
                                }

                            }
                            else
                            {
                                CdBlockDB.PrintUsage(player);
                            }
                        }
                        else
                        {
                            player.Message("Block tracking is disabled on world {0}", world.ClassyName);
                        }
                        break;

                    default:
                        // unknown operand
                        CdBlockDB.PrintUsage(player);
                        return;
                }
            }
        }
Пример #30
0
        static void BringHandler( Player player, CommandReader cmd ) {
            string name = cmd.Next();
            if( name == null ) {
                CdBring.PrintUsage( player );
                return;
            }

            // bringing someone to another player (instead of to self)
            string toName = cmd.Next();
            Player toPlayer = player;
            if( toName != null ) {
                toPlayer = Server.FindPlayerOrPrintMatches( player, toName, true, false, true );
                if( toPlayer == null ) return;
            } else if( toPlayer.World == null ) {
                player.Message( "When used from console, /Bring requires both names to be given." );
                return;
            }

            World world = toPlayer.World;
            if( world == null ) PlayerOpException.ThrowNoWorld( toPlayer );

            Player target = Server.FindPlayerOrPrintMatches( player, name, true, false, true );
            if( target == null ) return;

            if( !player.Can( Permission.Bring, target.Info.Rank ) ) {
                player.Message( "You may only bring players ranked {0}&S or lower.",
                                player.Info.Rank.GetLimit( Permission.Bring ).ClassyName );
                player.Message( "{0}&S is ranked {1}",
                                target.ClassyName, target.Info.Rank.ClassyName );
                return;
            }

            if( target.World == world ) {
                // teleport within the same world
                target.TeleportTo( toPlayer.Position );

            } else {
                // teleport to a different world
                SecurityCheckResult check = world.AccessSecurity.CheckDetailed( target.Info );
                if( check == SecurityCheckResult.RankTooLow ) {
                    if( player.CanJoin( world ) ) {
                        if( cmd.IsConfirmed ) {
                            BringPlayerToWorld( player, target, world, true, true );
                        } else {
                            Logger.Log( LogType.UserActivity,
                                        "Bring: Asked {0} to confirm overriding world permissions to bring player {1} to world {2}",
                                        player.Name, target.Name, world.Name );
                            player.Confirm( cmd,
                                            "Player {0}&S is ranked too low to join {1}&S. Override world permissions?",
                                            target.ClassyName,
                                            world.ClassyName );
                        }
                    } else {
                        player.Message( "Neither you nor {0}&S are allowed to join world {1}",
                                        target.ClassyName, world.ClassyName );
                    }
                } else {
                    BringPlayerToWorld( player, target, world, false, true );
                }
            }
        }
Пример #31
0
        static void EnvHandler(Player player, Command cmd)
        {
            if (Heartbeat.ClassiCube() || player.ClassiCube)
            {
                player.Message("/Env is a Minecraft.net only command.");//add reference /mapedit here once it works.
                return;
            }
            if (!ConfigKey.WoMEnableEnvExtensions.Enabled())
            {
                player.Message("Env command is disabled on this server.");
                return;
            }
            string worldName = cmd.Next();
            World world;
            if (worldName == null)
            {
                world = player.World;
                if (world == null)
                {
                    player.Message("When used from console, /Env requires a world name.");
                    return;
                }
            }
            else
            {
                world = WorldManager.FindWorldOrPrintMatches(player, worldName);
                if (world == null) return;
            }

            string variable = cmd.Next();
            string valueText = cmd.Next();
            if (variable == null)
            {
                player.Message("Environment settings for world {0}&S:", world.ClassyName);
                player.Message("  Cloud: {0}   Fog: {1}   Sky: {2}",
                                world.CloudColor == -1 ? "normal" : '#' + world.CloudColor.ToString("X6"),
                                world.FogColor == -1 ? "normal" : '#' + world.FogColor.ToString("X6"),
                                world.SkyColor == -1 ? "normal" : '#' + world.SkyColor.ToString("X6"));
                player.Message("  Edge level: {0}  Edge texture: {1}",
                                world.EdgeLevel == -1 ? "normal" : world.EdgeLevel + " blocks",
                                world.EdgeBlock);
                if (!player.IsUsingWoM)
                {
                    player.Message("  You need WoM client to see the changes.");
                }
                return;
            }
            #region 800Craft
            //Copyright (C) <2012> <Jon Baker>
            if (variable.ToLower() == "terrain")
            {
                if (valueText == null)
                {
                    player.Message("&A/Env [WorldName] terrain [Normal, arbot, cool, deadly, shroom, prometheus, woodpunk, fall, snow, tron, " +
                    "mario, highres, 8bit, simple, indev, messa, portal, dokucraft, doomcraft, hexeretic, zelda ");
                    return;
                }
                switch (valueText.ToLower())
                {
                    case "normal":
                        world.Terrain = "bc4acee575474f5266105430c3cc628b8b3948a2";
                        break;
                    case "arbot":
                        world.Terrain = "1e3eb03d8efaa862679d36c9044ce47e861ea25e";
                        break;
                    case "cool":
                        world.Terrain = "165917066357092a2e7f6b0ec358c05b36b0efa7";
                        break;
                    case "deadly":
                        world.Terrain = "cb45307db4addbaac1504529fef79d773a6e31f5";
                        break;
                    case "shroom":
                        world.Terrain = "f31b086dbae92cc1741476a3697506192b8f5814";
                        break;
                    case "prometheus":
                        world.Terrain = "f66479f2d6c812806c3e768442d45a08a868ad16";
                        break;
                    case "woodpunk":
                        world.Terrain = "dff99c37e4a792e10c3b775e6bded725f18ed6fe";
                        break;
                    case "simple":
                        world.Terrain = "85f783c3a70c0c9d523eb39e080c2ed95f45bfc2";
                        break;
                    case "highres":
                        world.Terrain = "f3dac271d7bce9954baad46e183a6a910a30d13b";
                        break;
                    case "hexeretic":
                        world.Terrain = "d8e75476281087c8482ac636a8b8e4a59fadd525";
                        break;
                    case "tron":
                        world.Terrain = "ba851c9544ba5e4eed3a8fc9b8b5bf25a4dd45e0";
                        break;
                    case "8bit":
                        world.Terrain = "5a3fb1994e2ae526815ceaaca3a4dac0051aa890";
                        break;
                    case "mario":
                        world.Terrain = "e98a37ddccbc6144306bd08f41248324965c4e5a";
                        break;
                    case "fall":
                        world.Terrain = "b7c6dcb7a858639077f95ef94e8e2d51bedc3307";
                        break;
                    case "dokucraft":
                        world.Terrain = "a101cadafd02019e14d727d3329a923a40ef040b";
                        break;
                    case "indev":
                        world.Terrain = "73d1ef4441725bdcc9ac3616205faa3dff46e12a";
                        break;
                    case "doomcraft":
                        world.Terrain = "8b72beb6fea6ed1e01c1e32e08edf5f784bc919c";
                        break;
                    case "messa":
                        world.Terrain = "db0feeac8702704a3146a71365622db55fb5a4c4";
                        break;
                    case "portal":
                        world.Terrain = "d4b455134394763296994d0c819b0ac0ea338457";
                        break;
                    case "snow":
                        world.Terrain = "0b18fb3b41874ac5fbcb43532d62e6b742adc25e";
                        break;
                    case "zelda":
                        world.Terrain = "b25e3bffe57c4f6a35ae42bb6116fcb21c50fa6f";
                        break;
                    default:
                        player.Message("&A/Env [WorldName] terrain [Normal, arbot, cool, deadly, shroom, prometheus, woodpunk, fall, snow, tron, " +
                    "mario, highres, 8bit, simple, indev, messa, portal, dokucraft, doomcraft, hexeretic, zelda ");
                        return;
                }
                player.Message("Terrain Changed for {0}", world.ClassyName);
                WorldManager.UpdateWorldList();
                return;
            }

            if (variable.ToLower() == "realistic")
            {
                if (!world.RealisticEnv)
                {
                    world.RealisticEnv = true;
                    player.Message("Realistic Environment has been turned ON for world {0}", world.ClassyName);
                    return;
                }
                else
                {
                    world.RealisticEnv = false;
                    player.Message("Realistic Environment has been turned OFF for world {0}", player.World.ClassyName);
                    return;
                }
            }
            #endregion

            if (variable.Equals("normal", StringComparison.OrdinalIgnoreCase))
            {
                if (cmd.IsConfirmed)
                {
                    world.FogColor = -1;
                    world.CloudColor = -1;
                    world.SkyColor = -1;
                    world.EdgeLevel = -1;
                    world.EdgeBlock = Block.Water;
                    player.Message("Reset enviroment settings for world {0}", world.ClassyName);
                    WorldManager.SaveWorldList();
                }
                else
                {
                    player.Confirm(cmd, "Reset enviroment settings for world {0}&S?", world.ClassyName);
                }
                return;
            }

            if (valueText == null)
            {
                CdEnv.PrintUsage(player);
                return;
            }

            int value = 0;
            if (valueText.Equals("normal", StringComparison.OrdinalIgnoreCase))
            {
                value = -1;
            }

            switch (variable.ToLower())
            {
                case "fog":
                    if (value == -1)
                    {
                        player.Message("Reset fog color for {0}&S to normal", world.ClassyName);
                    }
                    else
                    {
                        try
                        {
                            value = ParseHexColor(valueText);
                        }
                        catch (FormatException)
                        {
                            CdEnv.PrintUsage(player);
                            return;
                        }
                        player.Message("Set fog color for {0}&S to #{1:X6}", world.ClassyName, value);
                    }
                    world.FogColor = value;
                    break;

                case "cloud":
                case "clouds":
                    if (value == -1)
                    {
                        player.Message("Reset cloud color for {0}&S to normal", world.ClassyName);
                    }
                    else
                    {
                        try
                        {
                            value = ParseHexColor(valueText);
                        }
                        catch (FormatException)
                        {
                            CdEnv.PrintUsage(player);
                            return;
                        }
                        player.Message("Set cloud color for {0}&S to #{1:X6}", world.ClassyName, value);
                    }
                    world.CloudColor = value;
                    break;

                case "sky":
                    if (value == -1)
                    {
                        player.Message("Reset sky color for {0}&S to normal", world.ClassyName);
                    }
                    else
                    {
                        try
                        {
                            value = ParseHexColor(valueText);
                        }
                        catch (FormatException)
                        {
                            CdEnv.PrintUsage(player);
                            return;
                        }
                        player.Message("Set sky color for {0}&S to #{1:X6}", world.ClassyName, value);
                    }
                    world.SkyColor = value;
                    break;

                case "level":
                    if (value == -1)
                    {
                        player.Message("Reset edge level for {0}&S to normal", world.ClassyName);
                    }
                    else
                    {
                        try
                        {
                            value = UInt16.Parse(valueText);
                        }
                        catch (OverflowException)
                        {
                            CdEnv.PrintUsage(player);
                            return;
                        }
                        catch (FormatException)
                        {
                            CdEnv.PrintUsage(player);
                            return;
                        }
                        player.Message("Set edge level for {0}&S to {1}", world.ClassyName, value);
                    }
                    world.EdgeLevel = value;
                    break;

                case "edge":
                    Block block = Map.GetBlockByName(valueText);
                    if (block == Block.Undefined)
                    {
                        CdEnv.PrintUsage(player);
                        return;
                    }
                    if (block == Block.Water || valueText.Equals("normal", StringComparison.OrdinalIgnoreCase))
                    {
                        player.Message("Reset edge block for {0}&S to normal (water)", world.ClassyName);
                        world.EdgeBlock = Block.Water;
                    }
                    else
                    {
                        string textName = Map.GetEdgeTexture(block);
                        if (textName == null)
                        {
                            player.Message("Cannot use {0} for edge textures.", block);
                            return;
                        }
                        else
                        {
                            world.EdgeBlock = block;
                        }
                    }
                    break;

                case "side":
                case "sides":
                    if (valueText.ToLower() == "on")
                    {
                        if (world.SideBlock != Block.Admincrete)
                        {
                            world.SideBlock = Block.Admincrete;
                            player.Message("The sides of the world have been restored");
                        }
                    }
                    else
                    {
                        if (valueText.ToLower() == "off")
                        {
                            world.SideBlock = Block.Air;
                            player.Message("The sides of the world have been removed");
                        }
                    }
                    break;

                default:
                    CdEnv.PrintUsage(player);
                    return;
            }

            WorldManager.SaveWorldList();
            if (player.World == world)
            {
                if (player.IsUsingWoM)
                {
                    player.Message("Rejoin the world to see the changes.");
                }
                else
                {
                    player.Message("You need WoM client to see the changes.");
                }
            }
        }
Пример #32
0
 static void Fill2DCallback( Player player, Vector3I[] marks, object tag ) {
     DrawOperation op = (DrawOperation)tag;
     if( !op.Prepare( marks ) ) return;
     if( player.WorldMap.GetBlock( marks[0] ) == Block.Air ) {
         Logger.Log( LogType.UserActivity,
                     "Fill2D: Asked {0} to confirm replacing air on world {1}",
                     player.Name,
                     // ReSharper disable PossibleNullReferenceException
                     player.World.Name );
                     // ReSharper restore PossibleNullReferenceException
         player.Confirm( Fill2DConfirmCallback, op, "{0}: Replace air?", op.Description );
     } else {
         Fill2DConfirmCallback( player, op, false );
     }
 }
Пример #33
0
        static void GenHandler(Player player, Command cmd)
        {
            World playerWorld = player.World;
            string themeName = cmd.Next();
            string templateName;
            bool genOcean = false;
            bool genEmpty = false;
            bool noTrees = false;

            if (themeName == null)
            {
                CdGenerate.PrintUsage(player);
                return;
            }
            MapGenTheme theme = MapGenTheme.Forest;
            MapGenTemplate template = MapGenTemplate.Flat;

            // parse special template names (which do not need a theme)
            if (themeName.Equals("ocean"))
            {
                genOcean = true;

            }
            else if (themeName.Equals("empty"))
            {
                genEmpty = true;

            }
            else
            {
                templateName = cmd.Next();
                if (templateName == null)
                {
                    CdGenerate.PrintUsage(player);
                    return;
                }

                // parse theme
                bool swapThemeAndTemplate = false;
                if (themeName.Equals("grass", StringComparison.OrdinalIgnoreCase))
                {
                    theme = MapGenTheme.Forest;
                    noTrees = true;

                }
                else if (templateName.Equals("grass", StringComparison.OrdinalIgnoreCase))
                {
                    theme = MapGenTheme.Forest;
                    noTrees = true;
                    swapThemeAndTemplate = true;

                }
                else if (EnumUtil.TryParse(themeName, out theme, true))
                {
                    noTrees = (theme != MapGenTheme.Forest);

                }
                else if (EnumUtil.TryParse(templateName, out theme, true))
                {
                    noTrees = (theme != MapGenTheme.Forest);
                    swapThemeAndTemplate = true;

                }
                else
                {
                    player.Message("Gen: Unrecognized theme \"{0}\". Available themes are: Grass, {1}",
                                    themeName,
                                    Enum.GetNames(typeof(MapGenTheme)).JoinToString());
                    return;
                }

                // parse template
                if (swapThemeAndTemplate)
                {
                    if (!EnumUtil.TryParse(themeName, out template, true))
                    {
                        player.Message("Unrecognized template \"{0}\". Available terrain types: Empty, Ocean, {1}",
                                        themeName,
                                        Enum.GetNames(typeof(MapGenTemplate)).JoinToString());
                        return;
                    }
                }
                else
                {
                    if (!EnumUtil.TryParse(templateName, out template, true))
                    {
                        player.Message("Unrecognized template \"{0}\". Available terrain types: Empty, Ocean, {1}",
                                        templateName,
                                        Enum.GetNames(typeof(MapGenTemplate)).JoinToString());
                        return;
                    }
                }
            }

            // parse map dimensions
            int mapWidth, mapLength, mapHeight;
            if (cmd.HasNext)
            {
                int offset = cmd.Offset;
                if (!(cmd.NextInt(out mapWidth) && cmd.NextInt(out mapLength) && cmd.NextInt(out mapHeight)))
                {
                    if (playerWorld != null)
                    {
                        Map oldMap = player.WorldMap;
                        // If map dimensions were not given, use current map's dimensions
                        mapWidth = oldMap.Width;
                        mapLength = oldMap.Length;
                        mapHeight = oldMap.Height;
                    }
                    else
                    {
                        player.Message("When used from console, /Gen requires map dimensions.");
                        CdGenerate.PrintUsage(player);
                        return;
                    }
                    cmd.Offset = offset;
                }
            }
            else if (playerWorld != null)
            {
                Map oldMap = player.WorldMap;
                // If map dimensions were not given, use current map's dimensions
                mapWidth = oldMap.Width;
                mapLength = oldMap.Length;
                mapHeight = oldMap.Height;
            }
            else
            {
                player.Message("When used from console, /Gen requires map dimensions.");
                CdGenerate.PrintUsage(player);
                return;
            }

            // Check map dimensions
            const string dimensionRecommendation = "Dimensions must be between 16 and 2047. " +
                                                   "Recommended values: 16, 32, 64, 128, 256, 512, and 1024.";
            if (!Map.IsValidDimension(mapWidth))
            {
                player.Message("Cannot make map with width {0}. {1}", mapWidth, dimensionRecommendation);
                return;
            }
            else if (!Map.IsValidDimension(mapLength))
            {
                player.Message("Cannot make map with length {0}. {1}", mapLength, dimensionRecommendation);
                return;
            }
            else if (!Map.IsValidDimension(mapHeight))
            {
                player.Message("Cannot make map with height {0}. {1}", mapHeight, dimensionRecommendation);
                return;
            }
            long volume = (long)mapWidth * (long)mapLength * (long)mapHeight;
            if (volume > Int32.MaxValue)
            {
                player.Message("Map volume may not exceed {0}", Int32.MaxValue);
                return;
            }

            if (!cmd.IsConfirmed && (!Map.IsRecommendedDimension(mapWidth) || !Map.IsRecommendedDimension(mapLength) || !Map.IsRecommendedDimension(mapHeight)))
            {
                player.Message("&WThe map will have non-standard dimensions. " +
                                "You may see glitched blocks or visual artifacts. " +
                                "The only recommended map dimensions are: 16, 32, 64, 128, 256, 512, and 1024.");
            }

            // figure out full template name
            bool genFlatgrass = (theme == MapGenTheme.Forest && noTrees && template == MapGenTemplate.Flat);
            string templateFullName;
            if (genEmpty)
            {
                templateFullName = "Empty";
            }
            else if (genOcean)
            {
                templateFullName = "Ocean";
            }
            else if (genFlatgrass)
            {
                templateFullName = "Flatgrass";
            }
            else
            {
                if (theme == MapGenTheme.Forest && noTrees)
                {
                    templateFullName = "Grass " + template;
                }
                else
                {
                    templateFullName = theme + " " + template;
                }
            }

            // check file/world name
            string fileName = cmd.Next();
            string fullFileName = null;
            if (fileName == null)
            {
                // replacing current world
                if (playerWorld == null)
                {
                    player.Message("When used from console, /Gen requires FileName.");
                    CdGenerate.PrintUsage(player);
                    return;
                }
                if (!cmd.IsConfirmed)
                {
                    player.Confirm(cmd, "Replace THIS MAP with a generated one ({0})?", templateFullName);
                    return;
                }

            }
            else
            {
                if (cmd.HasNext)
                {
                    CdGenerate.PrintUsage(player);
                    return;
                }
                // saving to file
                fileName = fileName.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
                if (!fileName.EndsWith(".fcm", StringComparison.OrdinalIgnoreCase))
                {
                    fileName += ".fcm";
                }
                if (!Paths.IsValidPath(fileName))
                {
                    player.Message("Invalid filename.");
                    return;
                }
                fullFileName = Path.Combine(Paths.MapPath, fileName);
                if (!Paths.Contains(Paths.MapPath, fullFileName))
                {
                    player.MessageUnsafePath();
                    return;
                }
                string dirName = fullFileName.Substring(0, fullFileName.LastIndexOf(Path.DirectorySeparatorChar));
                if (!Directory.Exists(dirName))
                {
                    Directory.CreateDirectory(dirName);
                }
                if (!cmd.IsConfirmed && File.Exists(fullFileName))
                {
                    player.Confirm(cmd, "The mapfile \"{0}\" already exists. Overwrite?", fileName);
                    return;
                }
            }

            // generate the map
            Map map;
            player.MessageNow("Generating {0}...", templateFullName);

            if (genEmpty)
            {
                map = MapGenerator.GenerateEmpty(mapWidth, mapLength, mapHeight);

            }
            else if (genOcean)
            {
                map = MapGenerator.GenerateOcean(mapWidth, mapLength, mapHeight);

            }
            else if (genFlatgrass)
            {
                map = MapGenerator.GenerateFlatgrass(mapWidth, mapLength, mapHeight);

            }
            else
            {
                MapGeneratorArgs args = MapGenerator.MakeTemplate(template);
                if (theme == MapGenTheme.Desert)
                {
                    args.AddWater = false;
                }
                float ratio = mapHeight / (float)args.MapHeight;
                args.MapWidth = mapWidth;
                args.MapLength = mapLength;
                args.MapHeight = mapHeight;
                args.MaxHeight = (int)Math.Round(args.MaxHeight * ratio);
                args.MaxDepth = (int)Math.Round(args.MaxDepth * ratio);
                args.SnowAltitude = (int)Math.Round(args.SnowAltitude * ratio);
                args.Theme = theme;
                args.AddTrees = !noTrees;

                MapGenerator generator = new MapGenerator(args);
                map = generator.Generate();
            }

            // save map to file, or load it into a world
            if (fileName != null)
            {
                if (map.Save(fullFileName))
                {
                    player.Message("Generation done. Saved to {0}", fileName);
                }
                else
                {
                    player.Message("&WAn error occured while saving generated map to {0}", fileName);
                }
            }
            else
            {
                if (playerWorld == null) PlayerOpException.ThrowNoWorld(player);
                player.MessageNow("Generation done. Changing map...");
                playerWorld.MapChangedBy = player.Name;
                playerWorld.ChangeMap(map);
            }
            Server.RequestGC();
        }
        static void DumpStatsHandler( Player player, Command cmd )
        {
            string fileName = cmd.Next();
            if( fileName == null ) {
                CdDumpStats.PrintUsage( player );
                return;
            }

            if( !Paths.Contains( Paths.WorkingPath, fileName ) ) {
                player.MessageUnsafePath();
                return;
            }

            // ReSharper disable AssignNullToNotNullAttribute
            if( Paths.IsProtectedFileName( Path.GetFileName( fileName ) ) ) {
                // ReSharper restore AssignNullToNotNullAttribute
                player.Message( "You may not use this file." );
                return;
            }

            string extension = Path.GetExtension( fileName );
            if( extension == null || !extension.Equals( ".txt", StringComparison.OrdinalIgnoreCase ) ) {
                player.Message( "Stats filename must end with .txt" );
                return;
            }

            if( File.Exists( fileName ) && !cmd.IsConfirmed ) {
                player.Confirm( cmd, "File \"{0}\" already exists. Overwrite?", Path.GetFileName( fileName ) );
                return;
            }

            if( !Paths.TestFile( "DumpStats file", fileName, false, FileAccess.Write ) ) {
                player.Message( "Cannot create specified file. See log for details." );
                return;
            }

            PlayerInfo[] infos;
            using( FileStream fs = File.Create( fileName ) ) {
                using( StreamWriter writer = new StreamWriter( fs ) ) {
                    infos = PlayerDB.PlayerInfoList;
                    if( infos.Length == 0 ) {
                        writer.WriteLine( "(TOTAL) (0 players)" );
                        writer.WriteLine();
                    } else {
                        DumpPlayerGroupStats( writer, infos, "(TOTAL)" );
                    }

                    List<PlayerInfo> rankPlayers = new List<PlayerInfo>();
                    foreach( Rank rank in RankManager.Ranks ) {
                        // ReSharper disable LoopCanBeConvertedToQuery
                        for( int i = 0; i < infos.Length; i++ ) {
                            // ReSharper restore LoopCanBeConvertedToQuery
                            if( infos[i].Rank == rank ) rankPlayers.Add( infos[i] );
                        }
                        if( rankPlayers.Count == 0 ) {
                            writer.WriteLine( "{0}: 0 players, 0 banned, 0 inactive", rank.Name );
                            writer.WriteLine();
                        } else {
                            DumpPlayerGroupStats( writer, rankPlayers, rank.Name );
                        }
                        rankPlayers.Clear();
                    }
                }
            }

            player.Message( "Stats saved to \"{0}\"", fileName );
        }
Пример #35
0
        static void WorldLoadHandler(Player player, Command cmd)
        {
            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
                CdWorldLoad.PrintUsage(player);
                return;
            }

            string fullFileName = WorldManager.FindMapFile(player, fileName);
            if (fullFileName == null) return;

            // Loading map into current world
            if (worldName == null)
            {
                if (!cmd.IsConfirmed)
                {
                    player.Confirm(cmd, "Replace THIS MAP with \"{0}\"?", fileName);
                    return;
                }
                Map map;
                try
                {
                    map = MapUtility.Load(fullFileName);
                }
                catch (Exception ex)
                {
                    player.MessageNow("Could not load specified file: {0}: {1}", ex.GetType().Name, ex.Message);
                    return;
                }
                World world = player.World;

                // Loading to current world
                world.MapChangedBy = player.Name;
                world.ChangeMap(map);

                world.Players.Message(player, "{0}&S loaded a new map for this world.",
                                              player.ClassyName);
                player.MessageNow("New map loaded for the world {0}", world.ClassyName);

                Logger.Log(LogType.UserActivity,
                            "{0} loaded new map for world \"{1}\" from {2}",
                            player.Name, world.Name, fileName);

            }
            else
            {
                // Loading to some other (or new) world
                if (!World.IsValidName(worldName))
                {
                    player.MessageInvalidWorldName(worldName);
                    return;
                }

                string buildRankName = cmd.Next();
                string accessRankName = cmd.Next();
                Rank buildRank = RankManager.DefaultBuildRank;
                Rank accessRank = null;
                if (buildRankName != null)
                {
                    buildRank = RankManager.FindRank(buildRankName);
                    if (buildRank == null)
                    {
                        player.MessageNoRank(buildRankName);
                        return;
                    }
                    if (accessRankName != null)
                    {
                        accessRank = RankManager.FindRank(accessRankName);
                        if (accessRank == null)
                        {
                            player.MessageNoRank(accessRankName);
                            return;
                        }
                    }
                }

                // Retype world name, if needed
                if (worldName == "-")
                {
                    if (player.LastUsedWorldName != null)
                    {
                        worldName = player.LastUsedWorldName;
                    }
                    else
                    {
                        player.Message("Cannot repeat world name: you haven't used any names yet.");
                        return;
                    }
                }

                lock (WorldManager.SyncRoot)
                {
                    World world = WorldManager.FindWorldExact(worldName);
                    if (world != null)
                    {
                        player.LastUsedWorldName = world.Name;
                        // Replacing existing world's map
                        if (!cmd.IsConfirmed)
                        {
                            player.Confirm(cmd, "Replace map for {0}&S with \"{1}\"?",
                                            world.ClassyName, fileName);
                            return;
                        }

                        Map map;
                        try
                        {
                            map = MapUtility.Load(fullFileName);
                        }
                        catch (Exception ex)
                        {
                            player.MessageNow("Could not load specified file: {0}: {1}", ex.GetType().Name, ex.Message);
                            return;
                        }

                        try
                        {
                            world.MapChangedBy = player.Name;
                            world.ChangeMap(map);
                        }
                        catch (WorldOpException ex)
                        {
                            Logger.Log(LogType.Error,
                                        "Could not complete WorldLoad operation: {0}", ex.Message);
                            player.Message("&WWLoad: {0}", ex.Message);
                            return;
                        }

                        world.Players.Message(player, "{0}&S loaded a new map for the world {1}",
                                               player.ClassyName, world.ClassyName);
                        player.MessageNow("New map for the world {0}&S has been loaded.", world.ClassyName);
                        Logger.Log(LogType.UserActivity,
                                    "{0} loaded new map for world \"{1}\" from {2}",
                                    player.Name, world.Name, fullFileName);

                    }
                    else
                    {
                        // Adding a new world
                        string targetFullFileName = Path.Combine(Paths.MapPath, worldName + ".fcm");
                        if (!cmd.IsConfirmed &&
                            File.Exists(targetFullFileName) && // target file already exists
                            !Paths.Compare(targetFullFileName, fullFileName))
                        {
                            // and is different from sourceFile
                            player.Confirm(cmd,
                                            "A map named \"{0}\" already exists, and will be overwritten with \"{1}\".",
                                            Path.GetFileName(targetFullFileName), Path.GetFileName(fullFileName));
                            return;
                        }

                        Map map;
                        try
                        {
                            map = MapUtility.Load(fullFileName);
                        }
                        catch (Exception ex)
                        {
                            player.MessageNow("Could not load \"{0}\": {1}: {2}",
                                               fileName, ex.GetType().Name, ex.Message);
                            return;
                        }

                        World newWorld;
                        try
                        {
                            newWorld = WorldManager.AddWorld(player, worldName, map, false);
                        }
                        catch (WorldOpException ex)
                        {
                            player.Message("WLoad: {0}", ex.Message);
                            return;
                        }

                        if (newWorld == null)
                        {
                            player.MessageNow("Failed to create a new world.");
                            return;
                        }

                        player.LastUsedWorldName = worldName;
                        newWorld.BuildSecurity.MinRank = buildRank;
                        if (accessRank == null)
                        {
                            newWorld.AccessSecurity.ResetMinRank();
                        }
                        else
                        {
                            newWorld.AccessSecurity.MinRank = accessRank;
                        }
                        newWorld.BlockDB.AutoToggleIfNeeded();
                        if (BlockDB.IsEnabledGlobally && newWorld.BlockDB.IsEnabled)
                        {
                            player.Message("BlockDB is now auto-enabled on world {0}", newWorld.ClassyName);
                        }
                        newWorld.LoadedBy = player.Name;
                        newWorld.LoadedOn = DateTime.UtcNow;
                        Server.Message("{0}&S created a new world named {1}",
                                        player.ClassyName, newWorld.ClassyName);
                        Logger.Log(LogType.UserActivity,
                                    "{0} created a new world named \"{1}\" (loaded from \"{2}\")",
                                    player.Name, worldName, fileName);
                        WorldManager.SaveWorldList();
                        player.MessageNow("Access permission is {0}+&S, and build permission is {1}+",
                                           newWorld.AccessSecurity.MinRank.ClassyName,
                                           newWorld.BuildSecurity.MinRank.ClassyName);
                    }
                }
            }

            Server.RequestGC();
        }
        static void ImportRanks( Player player, Command cmd )
        {
            string serverName = cmd.Next();
            string fileName = cmd.Next();
            string rankName = cmd.Next();
            bool silent = (cmd.Next() != null);

            // Make sure all parameters are specified
            if( serverName == null || fileName == null || rankName == null ) {
                CdImport.PrintUsage( player );
                return;
            }

            // Check if file exists
            if( !File.Exists( fileName ) ) {
                player.Message( "File not found: {0}", fileName );
                return;
            }

            Rank targetRank = RankManager.FindRank( rankName );
            if( targetRank == null ) {
                player.MessageNoRank( rankName );
                return;
            }

            string[] names;

            switch( serverName.ToLower() ) {
                case "mcsharp":
                case "mczall":
                case "mclawl":
                    try {
                        names = File.ReadAllLines( fileName );
                    } catch( Exception ex ) {
                        Logger.Log( LogType.Error,
                                    "Could not open \"{0}\" to import ranks: {1}",
                                    fileName, ex );
                        return;
                    }
                    break;
                default:
                    player.Message( "fCraft does not support importing from {0}", serverName );
                    return;
            }

            if( !cmd.IsConfirmed ) {
                player.Confirm( cmd, "You are about to import {0} player ranks.", names.Length );
                return;
            }

            string reason = "(Import from " + serverName + ")";
            foreach( string name in names ) {
                PlayerInfo info = PlayerDB.FindPlayerInfoExact( name ) ??
                                  PlayerDB.AddFakeEntry( name, RankChangeType.Promoted );
                try {
                    info.ChangeRank( player, targetRank, reason, !silent, true, false );
                } catch( PlayerOpException ex ) {
                    player.Message( ex.MessageColored );
                }
            }

            PlayerDB.Save();
        }
Пример #37
0
        static void WorldRenameHandler(Player player, Command cmd)
        {
            string oldName = cmd.Next();
            string newName = cmd.Next();
            if (oldName == null || newName == null)
            {
                CdWorldRename.PrintUsage(player);
                return;
            }

            World oldWorld = WorldManager.FindWorldOrPrintMatches(player, oldName);
            if (oldWorld == null) return;
            oldName = oldWorld.Name;

            if (!World.IsValidName(newName))
            {
                player.MessageInvalidWorldName(newName);
                return;
            }

            World newWorld = WorldManager.FindWorldExact(newName);
            if (!cmd.IsConfirmed && newWorld != null && newWorld != oldWorld)
            {
                player.Confirm(cmd, "A world named {0}&S already exists. Replace it?", newWorld.ClassyName);
                return;
            }

            if (!cmd.IsConfirmed && File.Exists(Path.Combine(Paths.MapPath, newName + ".fcm")))
            {
                player.Confirm(cmd, "Renaming this world will overwrite an existing map file \"{0}.fcm\".", newName);
                return;
            }

            try
            {
                WorldManager.RenameWorld(oldWorld, newName, true, true);
            }
            catch (WorldOpException ex)
            {
                switch (ex.ErrorCode)
                {
                    case WorldOpExceptionCode.NoChangeNeeded:
                        player.MessageNow("WRename: World is already named \"{0}\"", oldName);
                        return;
                    case WorldOpExceptionCode.DuplicateWorldName:
                        player.MessageNow("WRename: Another world named \"{0}\" already exists.", newName);
                        return;
                    case WorldOpExceptionCode.InvalidWorldName:
                        player.MessageNow("WRename: Invalid world name: \"{0}\"", newName);
                        return;
                    case WorldOpExceptionCode.MapMoveError:
                        player.MessageNow("WRename: World \"{0}\" was renamed to \"{1}\", but the map file could not be moved due to an error: {2}",
                                            oldName, newName, ex.InnerException);
                        return;
                    default:
                        player.MessageNow("&WWRename: Unexpected error renaming world \"{0}\": {1}", oldName, ex.Message);
                        Logger.Log(LogType.Error,
                                    "WorldCommands.Rename: Unexpected error while renaming world {0} to {1}: {2}",
                                    oldWorld.Name, newName, ex);
                        return;
                }
            }

            player.LastUsedWorldName = newName;
            WorldManager.SaveWorldList();
            Logger.Log(LogType.UserActivity,
                        "{0} renamed the world \"{1}\" to \"{2}\".",
                        player.Name, oldName, newName);
            Server.Message("{0}&S renamed the world \"{1}\" to \"{2}\"",
                              player.ClassyName, oldName, newName);
        }
 static void PruneDBHandler( Player player, Command cmd )
 {
     if( !cmd.IsConfirmed ) {
         player.MessageNow( "PruneDB: Finding inactive players..." );
         int inactivePlayers = PlayerDB.CountInactivePlayers();
         if( inactivePlayers == 0 ) {
             player.Message( "PruneDB: No inactive players found." );
         } else {
             player.Confirm( cmd, "PruneDB: Erase {0} records of inactive players?",
                             inactivePlayers );
         }
     } else {
         Scheduler.NewBackgroundTask( PruneDBTask, player ).RunOnce();
     }
 }
Пример #39
0
        static void ImportBans(Player player, CommandReader cmd)
        {
            string serverName = cmd.Next();
            string fileName   = cmd.Next();

            // Make sure all parameters are specified
            if (serverName == null || fileName == null)
            {
                CdImport.PrintUsage(player);
                return;
            }

            // Check if file exists
            if (!File.Exists(fileName))
            {
                player.Message("File not found: {0}", fileName);
                return;
            }

            string[] names;

            switch (serverName.ToLower())
            {
            case "mcsharp":
            case "mczall":
            case "mclawl":
                try {
                    names = File.ReadAllLines(fileName);
                } catch (Exception ex) {
                    Logger.Log(LogType.Error,
                               "Could not open \"{0}\" to import bans: {1}",
                               fileName, ex);
                    return;
                }
                break;

            default:
                player.Message("fCraft does not support importing from {0}", serverName);
                return;
            }

            if (!cmd.IsConfirmed)
            {
                player.Confirm(cmd, "Import {0} bans from \"{1}\"?",
                               names.Length, Path.GetFileName(fileName));
                return;
            }

            string reason = "(import from " + serverName + ")";

            foreach (string name in names)
            {
                if (Player.IsValidName(name))
                {
                    PlayerInfo info = PlayerDB.FindExact(name) ??
                                      PlayerDB.AddUnrecognizedPlayer(name, RankChangeType.Default);
                    info.Ban(player, reason, true, true);
                }
                else
                {
                    IPAddress ip;
                    if (IPAddressUtil.IsIP(name) && IPAddress.TryParse(name, out ip))
                    {
                        ip.BanIP(player, reason, true, true);
                    }
                    else
                    {
                        player.Message("Could not parse \"{0}\" as either name or IP. Skipping.", name);
                    }
                }
            }

            PlayerDB.Save();
            IPBanList.Save();
        }