Page 1 of 3

Post your custom code here

Posted: August 21st, 2011, 6:58 am
by Jonty800
---

Re: Post your custom code here

Posted: August 21st, 2011, 7:01 am
by Jonty800
---

Re: Post your custom code here

Posted: August 21st, 2011, 5:51 pm
by fragmer
Please disable crash reporting if you modify your copy of fCraft.

I have to keep pruning my crash report database to delete crashes caused by custom code. Wastes a lot of my time.

Re: Post your custom code here

Posted: August 21st, 2011, 5:59 pm
by boblol0909
/door and /removedoor
Show
It makes and removes doors. When you click the selected blocks go away and come back. For the lulz!

And @ fragmer, sorry I shall remove it promptly.

Re: Post your custom code here

Posted: August 21st, 2011, 6:53 pm
by Jonty800
Sorry fragmer.

Thanks Bob!

For some reason it doesn't recognize "Tuple"

Code: Select all

var values = Tuple.Create(DL, player);
Any idea how I can fix that?

Re: Post your custom code here

Posted: August 21st, 2011, 7:01 pm
by boblol0909
You must have .NET framework 4 to use tuples, I could rewrite it if you want to use it.


edit:and I think you forgot to change your help in /away

Re: Post your custom code here

Posted: August 21st, 2011, 7:07 pm
by Jonty800
LOL! That's a bit embarrassing :P Thanks.

If you could re-write it for me that would be fantastic :)

Re: Post your custom code here

Posted: August 21st, 2011, 7:08 pm
by boblol0909
Easy fix,

Doors for people without framework 4:
edit:fixed a spot that could cause an error
editedit: fixed two people clicking door at same time causing door to disappear :P
Show

Re: Post your custom code here

Posted: August 21st, 2011, 8:10 pm
by Jonty800
WOW! Great work Bob, Thanks :)

Here's the door code for people using Branch 0.60x

Code: Select all

using System;
using System.Collections.Generic;
using fCraft.Events;

namespace fCraft
{
    public static class Doors
    {
        static readonly TimeSpan DoorCloseTimer = TimeSpan.FromMilliseconds(1500); // time that door will stay open
        public static Dictionary<string, string[]> DoorLookUp = new Dictionary<string, string[]>();
        // DoorLookUp to store currently open doors

        public static void Init()
        {
            CommandManager.RegisterCommand(cdDoor);
            CommandManager.RegisterCommand(cdDoorRemove);

            Server.PlayerClicked += PlayerClickedDoor;

        }

        static readonly CommandDescriptor cdDoorRemove = new CommandDescriptor
        {
            Name = "removedoor",
            Aliases = new[] { "rd" },
            Category = CommandCategory.Zone,
            Permissions = new[] { Permission.Chat },
            Help = "Removes door.",
            Handler = DoorRemove
        };

        static void DoorRemove(Player player, Command cmd)
        {
            if (player.World.Map.Zones.Find(player.Info.Name + "door") != null)
            {
                player.World.Map.Zones.Remove(player.Info.Name + "door");
                DoorLookUp.Remove(player.Info.Name + "door");
                player.Message("Door removed.");
            }

        }

        static readonly CommandDescriptor cdDoor = new CommandDescriptor
        {
            Name = "door",
            Category = CommandCategory.Zone,
            Permissions = new[] { Permission.Chat },
            Help = "Creates door zone. Left click to open doors.",
            Handler = Door
        };

        static void Door(Player player, Command cmd)
        {
            if (player.World.Map.Zones.Find(player.Info.Name + "door") != null)
            {
                player.Message("One door per person.");
                return;
            }

            Zone door = new Zone();
            door.Name = player.Info.Name + "door";
            player.SelectionStart(2, DoorAdd, door, cdDoor.Permissions);
            player.Message("Door: Place a block or type /mark to use your location.");

        }

        static void DoorAdd(Player player, Position[] marks, object tag)
        {
            int maxBlocks = 12;  //max door size, change as needed... should add config key

            int sx = Math.Min(marks[0].X, marks[1].X);
            int ex = Math.Max(marks[0].X, marks[1].X);
            int sy = Math.Min(marks[0].Y, marks[1].Y);
            int ey = Math.Max(marks[0].Y, marks[1].Y);
            int sh = Math.Min(marks[0].Z, marks[1].Z);
            int eh = Math.Max(marks[0].Z, marks[1].Z);

            int volume = (ex - sx + 1) * (ey - sy + 1) * (eh - sh + 1);
            if (volume > maxBlocks)
            {
                player.Message("Doors are only allowed to be {0} blocks", maxBlocks);
                return;
            }

            ZoneCommands.ZoneAddCallback(player, marks, tag);
            player.Message("Door successfully created");

            Logger.Log("{0} created door {1} (on world {2})", LogType.UserActivity, player.Name, player.Name + "door", player.World.Name);
        }


        static void DoorTimer_Elapsed(SchedulerTask task)
        {
            string door = (string)task.UserState;
            string[] doorVars = DoorLookUp[door];
            string x, y, z, b;

            Player player = Server.FindPlayerExact(doorVars[4]);

            //parse values from DoorLookUp
            x = doorVars[0].TrimEnd(' '); y = doorVars[1].TrimEnd(' '); z = doorVars[2].TrimEnd(' '); b = doorVars[3].TrimEnd(' ');
            string[] xs = x.Split(' '), ys = y.Split(' '), zs = z.Split(' '), bs = b.Split(' ');

            int i = 0;

            foreach (string arg in xs)
            {
                player.World.Map.QueueUpdate(new BlockUpdate(null, Int32.Parse(xs[i]), Int32.Parse(ys[i]), Int32.Parse(zs[i]), Byte.Parse(bs[i])));
                i++;
            }


        }

        public static void PlayerClickedDoor(object sender, PlayerClickedEventArgs e)
        {

            Zone[] allowed, denied;
            if (e.Player.World.Map.Zones.CheckDetailed(e.X, e.Y, e.Z, e.Player, out allowed, out denied))
            {
                foreach (Zone zone in allowed)
                {
                    if (zone.Name.Contains("door"))
                    {

                        CutDoor(zone, e.Player);

                    }
                }

            }
        }

        public static void CutDoor(Zone zone, Player player)
        {

            int sx = zone.Bounds.XMin;
            int ex = zone.Bounds.XMax;
            int sy = zone.Bounds.YMin;
            int ey = zone.Bounds.YMax;
            int sh = zone.Bounds.ZMin;
            int eh = zone.Bounds.ZMax;

            string[] DL = new string[5];

            DL[0] = ""; DL[1] = ""; DL[2] = ""; DL[3] = ""; DL[4] = player.Name;

            //for each block in selection, add x, y, z coords and block type to string array
            for (int i = sx; i <= ex; i++)
            {
                for (int j = sy; j <= ey; j++)
                {
                    for (int k = sh; k <= eh; k++)
                    {
                        DL[0] += i.ToString() + " "; //x
                        DL[1] += j.ToString() + " "; //y
                        DL[2] += k.ToString() + " "; //z
                        DL[3] += player.World.Map.GetBlockByte(i, j, k) + " "; //block

                        //clear the door
                        player.World.Map.QueueUpdate(new BlockUpdate(null, i, j, k, Block.Air));

                    }
                }
            }

            Logger.Log("{0} opened door {1} (on world {2})", LogType.UserActivity, player.Name, zone.Name, player.World.Name);

           

            if (!DoorLookUp.ContainsKey(zone.Name))
            {
                DoorLookUp.Add(zone.Name, DL);
            }
            else
            {
                DoorLookUp[zone.Name] = DL;
            }

            Scheduler.NewTask(DoorTimer_Elapsed).RunOnce(zone.Name, DoorCloseTimer); //timer to re-close door
        }
    }
}

Re: Post your custom code here

Posted: August 28th, 2011, 12:17 pm
by zaqquater
-removed-

Re: Post your custom code here

Posted: August 28th, 2011, 2:36 pm
by Jonty800
If you have experience in c#, then you can find /bi in branch-0.60x of fCraft. All the commands I have written are compatible with branch-0.60x.

I don't want to share a command that isn't mine lol. You could always ask Fragmer very nicely on his irc #fcraft

Re: Post your custom code here

Posted: August 28th, 2011, 4:27 pm
by zaqquater
-removed-

nvm

Re: Post your custom code here

Posted: August 28th, 2011, 4:31 pm
by Jonty800
You need a program called "tortoiseSVN"
http://tortoisesvn.tigris.org/

When this is installed, right click a new folder and click "SVN Checkout"

Use the url: http://svn.fcraft.net:8080/svn/fcraft/branch-0.60x
and checkout the HEAD revision.

Then all them files should download into your new folder

Re: Post your custom code here

Posted: August 28th, 2011, 8:13 pm
by fragmer
And if you are working with 0.600, keep in mind that it's a work in progress. It can behave strangely, corrupt your files, lose your data, crash, or not start at all. I cannot provide any support for 0.600 until it's stabilized and released.

Re: Post your custom code here

Posted: August 29th, 2011, 4:47 am
by zaqquater
@jonty thankyou now i have server gui 0.60 but i got some error message when i open the config file. And i can run console but server is not running, because of error message the server won't start it's just show log. thanks four ur help. really appreciate it alot.

@fragmer
yes i understand the risk. thank you :D

Re: Post your custom code here

Posted: August 29th, 2011, 6:13 am
by IAmRouge
Jonty800 wrote:Hey, I thought it would be nice to share our custom code with each other (if people want to lol)

I have a few bits that I'm willing to share, although I wouldn't consider them to be amazing. But I was mainly trying to concentrate on the functionality and atmosphere of the server.

Chat commands

/away

Code: Select all

static readonly CommandDescriptor cdAway = new CommandDescriptor
        {
            Name = "away",
            Category = CommandCategory.Chat,
            IsConsoleSafe = true,
            Usage = "/away [optional message]",
            Help = "Request an Op to review your build.",
            Handler = Away
        };

        internal static void Away(Player player, Command cmd)
        {
            if (player.Info.IsMuted)
            {
                player.MessageMuted();
                return;
            }

            if (player.Can(Permission.Chat))
            {
                string msg = cmd.NextAll().Trim();
                
                if (msg.Length > 0)
                {
                    Server.Players.Message("&S{0} &cis Away &9({1})", player.ClassyName, msg);
                }
                else
                {
                    Server.Players.Message("&S{0} &cis Away &9(Away From Keyboard)", player.ClassyName);
                }
            }
        }
There is a command for that its /hide

Re: Post your custom code here

Posted: August 29th, 2011, 7:31 am
by Jonty800
Try getting the HEAD revision, then move ipbans.txt, playerdb.txt, config.xml and worlds.xml and folder 'maps' from your server backup (old server) into the new folder where you put the head revision. Then open and check configGUI.

If you have a config.xml problem:

If you delete your config.xml, then run ConfigGUI and click "OK" without changing anything, you will get the very same default config.xml

Re: Post your custom code here

Posted: August 29th, 2011, 9:20 am
by zaqquater
-removed-

Re: Post your custom code here

Posted: August 29th, 2011, 9:27 am
by Jonty800
That is very strange....
Does the problem still happen if you build your solution to 'release' instead of 'debug' ?

If so, then build it to 'debug events' and then send me another screenshot of the console.

Re: Post your custom code here

Posted: August 29th, 2011, 10:09 am
by zaqquater
-removed-

Re: Post your custom code here

Posted: August 29th, 2011, 10:18 am
by Jonty800
you need to edit "config.xml"

search for "blockdb" and change the whole line from:

<!--<EnableBlockDB>False</EnableBlockDB>-->

to

<EnableBlockDB>True</EnableBlockDB>

also in your code, you need to make it so /blockdb, /bi and /undox start with:

Code: Select all

static void BlockDBHandler( Player player, Command cmd ) {
            

            string worldName = cmd.Next();
            if( worldName == null ) {
                World[] trackedWorlds = WorldManager.WorldList.Where( w => w.BlockDB.Enabled ).ToArray();
                if( trackedWorlds.Length > 0 ) {
                    player.Message( "BlockDB is enabled on: {0}",
                                    trackedWorlds.JoinToClassyString() );
This means removing the part between the {} that contains "BlockDB is disabled on this server".

I cant remember what the whole section you have to delete is, because I have already deleted it lol

Re: Post your custom code here

Posted: August 29th, 2011, 12:39 pm
by zaqquater
-removed-

Re: Post your custom code here

Posted: August 29th, 2011, 12:52 pm
by Jonty800
No, you downloaded the head revision, edit sections "cdblockdb", "cdblockinfo" from WorldCommands and in BuildingCommands edit "cdundox"

all you have to do is delete this from all 3 sections.

Code: Select all

if( !BlockDB.IsEnabled ) {
                player.Message( "&WBlockDB is disabled on this server." );
                return;
            }
and then build the source for release again.

Re: Post your custom code here

Posted: August 29th, 2011, 1:23 pm
by TVStar
Jonty800 wrote:Try getting the HEAD revision, then move ipbans.txt, playerdb.txt, config.xml and worlds.xml and folder 'maps' from your server backup (old server) into the new folder where you put the head revision. Then open and check configGUI.

If you have a config.xml problem:

If you delete your config.xml, then run ConfigGUI and click "OK" without changing anything, you will get the very same default config.xml
dont work for my have you teamviewer?

Re: Post your custom code here

Posted: August 29th, 2011, 1:26 pm
by zaqquater
-removed-

Re: Post your custom code here

Posted: August 29th, 2011, 1:36 pm
by Jonty800
guestwipe only works if you have two maps.

One called "Guest" and other called "guestwipe"

The command will replace guest with guestwipe, so make sure guestwipe is the same as your guest map, but clean (no player buildings on it). The easy way is to be on your guest map and just use /save guestwipe

Re: Post your custom code here

Posted: August 29th, 2011, 1:42 pm
by Jonty800
Oh wait! Error messages! I understand now. A lot has been changed in the code since I made /guestwipe.

Here is the updated code for the latest revision of branch 0.60x

Code: Select all

static readonly CommandDescriptor CdGuestwipe = new CommandDescriptor
        {
            Name = "guestwipe",

            Category = CommandCategory.World,
            Permissions = new[] { Permission.Guestwipe },
            IsConsoleSafe = true,
            Usage = "/guestwipe",
            Help = "Wipes a map with the name 'Guest'.",
            Handler = Guestwipe
        };

        internal static void Guestwipe(Player player, Command cmd)
        {
            string guestwipe = cmd.Next();
            if (guestwipe == null)
            {
                Scheduler.NewTask(t => Server.Players.Message("&9Warning! The Guest world will be wiped in 30 seconds.")).RunOnce(TimeSpan.FromSeconds(1));
                Scheduler.NewTask(t => Server.Players.Message("&9Warning! The Guest world will be wiped in 15 seconds.")).RunOnce(TimeSpan.FromSeconds(16));
                Scheduler.NewTask(t => player.Message("&4Prepare to use /ok when notified.")).RunOnce(TimeSpan.FromSeconds(25));
                Scheduler.NewTask(t => WorldLoadHandler(player, new Command("/wload2 guestwipe guest"))).RunOnce(TimeSpan.FromSeconds(30));
            }
        }
and wload2

Code: Select all

#region wload2
        static readonly CommandDescriptor CdWorldLoad2 = new CommandDescriptor
        {
            Name = "wload2",
            Aliases = new[] { "wadd2" },
            Category = CommandCategory.World,
            IsConsoleSafe = true,
            IsHidden = true,
            Permissions = new[] { Permission.ThemedRealms },
            Usage = "/wload FileName [WorldName]",
            Help = "Using this command could get you banned",
            Handler = WorldLoad2
        };


        internal static void WorldLoad2(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, "About to 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;
                }

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

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


            }
            else
            {
                // Loading to some other (or new) world
                if (!World.IsValidName(worldName))
                {
                    player.MessageNow("Invalid world name: \"{0}\".", worldName);
                    return;
                }

                lock (WorldManager.WorldListLock)
                {
                    World world = WorldManager.FindWorldExact(worldName);
                    if (world != null)
                    {
                        // Replacing existing world's map
                        if (!cmd.IsConfirmed)
                        {
                            player.Confirm(cmd, "About to 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.ChangeMap(map);
                        }
                        catch (WorldOpException ex)
                        {
                            Logger.Log("Could not complete WorldLoad operation: {0}", LogType.Error, 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("{0} loaded new map for world \"{1}\" from {2}", LogType.UserActivity,
                                    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;
                        }

                        try
                        {
                            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, null, false);
                        }
                        catch (WorldOpException ex)
                        {
                            player.Message("WLoad: {0}", ex.Message);
                            return;
                        }

                        if (newWorld != null)
                        {
                            newWorld.BuildSecurity.MinRank = Rank.Parse(ConfigKey.DefaultBuildRank.GetString());
                            Server.Message("{0}&S created a new world named {1}",
                                              player.ClassyName, newWorld.ClassyName);
                            Logger.Log("{0} created a new world named \"{1}\" (loaded from \"{2}\")", LogType.UserActivity,
                                        player.Name, worldName, fileName);
                            WorldManager.SaveWorldList();
                            player.MessageNow("Reminder: New world's access permission is {0}+&S, and build permission is {1}+",
                                               newWorld.AccessSecurity.MinRank.ClassyName,
                                               newWorld.BuildSecurity.MinRank.ClassyName);
                        }
                        else
                        {
                            player.MessageNow("Failed to create a new world.");
                        }
                    }
                }
            }

            Server.RequestGC();
        }
        #endregion
...and the permission (put into permission.cs)

Code: Select all

/// <summary> Ability to wipe the guest world </summary>
        Guestwipe,

Re: Post your custom code here

Posted: August 29th, 2011, 1:46 pm
by TVStar
TVStar wrote:
Jonty800 wrote:Try getting the HEAD revision, then move ipbans.txt, playerdb.txt, config.xml and worlds.xml and folder 'maps' from your server backup (old server) into the new folder where you put the head revision. Then open and check configGUI.

If you have a config.xml problem:

If you delete your config.xml, then run ConfigGUI and click "OK" without changing anything, you will get the very same default config.xml
dont work for my have you teamviewer?

Re: Post your custom code here

Posted: August 29th, 2011, 1:51 pm
by Jonty800
I dont have teamviewer. My internet at home is so slow it wont even have the bandwidth for it, since I'm usually at University.

What doesn't work for you?

edit: I hope you didnt put the old server files into the head revision root... you need to compile the source and then put the files into /bin/release

Re: Post your custom code here

Posted: August 29th, 2011, 2:04 pm
by TVStar
i renamed Debug to release but it keep say that error i have replaced it do with my old server that files but dont works