Example #1
0
        public void Run(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += UnhandledException_Handler;
            //Configure service current directory and managers
            Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
            if (!Directory.Exists("Converter"))
                Directory.CreateDirectory("Converter");

            //run as service
            if (args.Any(a => a.Equals("-service", StringComparison.InvariantCultureIgnoreCase)))
            {
                Run(this);
            }
            else
            {
                Version version = Assembly.GetExecutingAssembly().GetName().Version;
                if (!IsRunningInMono)
                    Console.Title = "C#raft v" + version;

                Console.WriteLine("C#raft v{0}", version);

                PlayerNBTConverter a = new PlayerNBTConverter();
                foreach (var s in Directory.GetFiles("Converter", "*.dat", SearchOption.TopDirectoryOnly))
                {
                    Console.WriteLine("Converting {0} to C#raft format", s);
                    a.ConvertPlayerNBT(s);
                }

                OnStart(args);

                while (true)
                {
                    string input = Console.ReadLine();
                    if (string.IsNullOrEmpty(input) || string.IsNullOrEmpty(input.Trim()))
                        continue;
                    if (Server == null) return;
                    string[] inputParts = input.Split();
                    var cleanedtokens = inputParts.Skip(1).ToArray();
                    try
                    {
                        var cmd = Server.ServerCommandHandler.Find(inputParts[0]) as IServerCommand;
                        if (cmd == null) return;
                        //todo - make this better
                        if (cmd is CmdStop)
                        {
                            Server.Stop();
                        }

                        //Event Start
                        ServerCommandEventArgs e = new ServerCommandEventArgs(Server, cmd, inputParts);
                        Server.PluginManager.CallEvent(Event.ServerCommand, e);
                        if (e.EventCanceled) { return; }
                        //Event End

                        cmd.Use(Server, inputParts[0], cleanedtokens);
                    }
                    catch (CommandNotFoundException e) { Server.Logger.Log(LogLevel.Info, e.Message); }
                    catch (Exception e)
                    {
                        Server.Logger.Log(LogLevel.Error, "There was an error while executing the command.");
                        Server.Logger.Log(e);
                    }
                }
                OnStop();
            }
        }
Example #2
0
 public virtual void OnCommand(ServerCommandEventArgs e) { }
Example #3
0
 private void OnCommand(ServerCommandEventArgs e)
 {
     foreach (EventListener el in Plugins)
     {
         ServerListener sl = (ServerListener)el.Listener;
         if (el.Event == Event.ServerCommand)
             sl.OnCommand(e);
     }
 }