/downloadmap

/downloadmap

Postby qpqpqp123 » 13 Aug 2013, 17:50

download map from sites example of this command
type /downloadmap spleef.2 http://goo.gl/zbl1f0

Code: Select all
/*
   Auto-generated command skeleton class.

   Use this as a basis for custom commands implemented via the MCDzienny scripting framework.
   File and class should be named a specific way.  For example, /update is named 'CmdUpdate.cs' for the file, and 'CmdUpdate' for the class.
*/

// Add any other using statements you need up here, of course.
// As a note, MCDzienny is designed for .NET 3.5.
using System;
using System.Net;
namespace MCDzienny
{
    public class CmdDownloadmap : Command
    {
        // The command's name, in all lowercase.  What you'll be putting behind the slash when using it.
        public override string name { get { return "downloadmap"; } }

        // Command's shortcut (please take care not to use an existing one, or you may have issues.
        public override string shortcut { get { return "dlm"; } }

        // Determines which submenu the command displays in under /help.
        public override string type { get { return "other"; } }

        // Determines whether or not this command can be used in a museum.  Block/map altering commands should be made false to avoid errors.
        public override bool museumUsable { get { return false; } }

        // Determines the command's default rank.  Valid values are:
        // LevelPermission.Nobody, LevelPermission.Banned, LevelPermission.Guest
        // LevelPermission.Builder, LevelPermission.AdvBuilder, LevelPermission.Operator, LevelPermission.Admin
        public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }

        // This is where the magic happens, naturally.
        // p is the player object for the player executing the command.  message is everything after the command invocation itself.
        public override void Use(Player p, string message)
        {
            string[] a = message.Split(' ');
            if (a.Length!=2)
            {
   Help(p);
                return;
            }
            try
            {
                string name = a[1] + ".lvl";
                using (WebClient web = new WebClient())
                {
                    if (message.Substring(0, 4) != "http")
                    {
                        message = "http://" + a[0];
                    }
                    Player.SendMessage(p, "Downloading file from: &f" + a[0] + Server.DefaultColor + ", please wait.");

                   
                    if (System.IO.File.Exists("levels/" + name + ".lvl"))
                    {
                        Player.SendMessage(p, "have map with that name");
                        return;
                    }



                    web.DownloadFile(message, "levels/" +name+".lvl");



                }
                Player.SendMessage(p, "Download complete. map name :%3" +name);

            }
            catch
            {
                Player.SendMessage(p, "%4 Download faild!!!");
            }
        }

        // This one controls what happens when you use /help [commandname].
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/downloadmap (name for map) (URl)- Dowload map.");
        }
    }
}
qpqpqp123
 
Posts: 59
Joined: 29 Apr 2013, 12:51

Re: /downloadmap

Postby joppiesaus » 13 Aug 2013, 18:00

This is very usefull. I think people will use it, good job and good coding! :)

EDIT: Here's a list of URLs for maps you can download of people!
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!

Re: /downloadmap

Postby qpqpqp123 » 13 Aug 2013, 18:18

sorry wrong code that is work code
Code: Select all
/*
   Auto-generated command skeleton class.

   Use this as a basis for custom commands implemented via the MCDzienny scripting framework.
   File and class should be named a specific way.  For example, /update is named 'CmdUpdate.cs' for the file, and 'CmdUpdate' for the class.
*/

// Add any other using statements you need up here, of course.
// As a note, MCDzienny is designed for .NET 3.5.
using System;
using System.Net;
namespace MCDzienny
{
    public class CmdDownloadmap : Command
    {
        // The command's name, in all lowercase.  What you'll be putting behind the slash when using it.
        public override string name { get { return "downloadmap"; } }

        // Command's shortcut (please take care not to use an existing one, or you may have issues.
        public override string shortcut { get { return ""; } }

        // Determines which submenu the command displays in under /help.
        public override string type { get { return "other"; } }

        // Determines whether or not this command can be used in a museum.  Block/map altering commands should be made false to avoid errors.
        public override bool museumUsable { get { return false; } }

        // Determines the command's default rank.  Valid values are:
        // LevelPermission.Nobody, LevelPermission.Banned, LevelPermission.Guest
        // LevelPermission.Builder, LevelPermission.AdvBuilder, LevelPermission.Operator, LevelPermission.Admin
        public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }

        // This is where the magic happens, naturally.
        // p is the player object for the player executing the command.  message is everything after the command invocation itself.
        public override void Use(Player p, string message)
        {
            string[] a = message.Split(' ');
            if (a.Length!=2)
            {
   Help(p);
                return;
            }
   string name = a[0] + ".lvl";
            try
            {
               
                using (WebClient web = new WebClient())
                {
                    if (a[0].Substring(0, 4) != "http")
                    {
                        message = "http://" + a[1];
                    }

                   
                    if (System.IO.File.Exists("levels/" + name + ".lvl"))
                    {
                        Player.SendMessage(p, "have map with that name");
                        return;
                    }
    Player.SendMessage(p, "Downloading file from: &f" + a[0] + Server.DefaultColor + ", please wait.");
                    web.DownloadFile(a[1], "levels/" +name+".lvl");
                }
                Player.SendMessage(p, "Download complete. map name :%3" +name);

            }
            catch
            {
                Player.SendMessage(p, "%4 Download faild!!!");
            }
        }

        // This one controls what happens when you use /help [commandname].
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/downloadmap (name for map) (URl)- Dowload map.");
        }
    }
}
qpqpqp123
 
Posts: 59
Joined: 29 Apr 2013, 12:51

Re: /downloadmap

Postby Ultima » 14 Aug 2013, 17:35

Does this work for non-webbased clients like XWoM?
User avatar
Ultima
 
Posts: 953
Joined: 19 Aug 2011, 23:45

Re: /downloadmap

Postby qpqpqp123 » 14 Aug 2013, 17:46

when I check that it was when I play on xWom
qpqpqp123
 
Posts: 59
Joined: 29 Apr 2013, 12:51

Re: /downloadmap

Postby Ultima » 29 Aug 2013, 18:31

The name is wrong, this commands uploads a map to the server. It doesn't download the current map.
User avatar
Ultima
 
Posts: 953
Joined: 19 Aug 2011, 23:45

Re: /downloadmap

Postby Conor » 02 Sep 2013, 18:07

Ultima wrote:The name is wrong, this commands uploads a map to the server. It doesn't download the current map.


It downloads a map and saves it in the server's level folder. This is what he intended it to do, the name is fine :P

@qpqpqp123 Nice command!
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor


Return to Custom Commands

Who is online

Users browsing this forum: No registered users and 4 guests

cron