Exemple #1
0
 internal Commands(HeroesAdminManager _manager)
 {
     this.manager     = _manager;
     this.commandDict = new Dictionary <string, Commands.CommandHandler>();
     MethodInfo[] methods = base.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
     foreach (MethodInfo methodInfo in methods)
     {
         object[] customAttributes = methodInfo.GetCustomAttributes(typeof(CommandHandlerAttribute), false);
         if (customAttributes.Length > 0)
         {
             Delegate @delegate = Delegate.CreateDelegate(typeof(Commands.CommandHandler), this, methodInfo, false);
             if (@delegate != null)
             {
                 foreach (CommandHandlerAttribute commandHandlerAttribute in customAttributes)
                 {
                     if (!this.commandDict.ContainsKey(commandHandlerAttribute.Command))
                     {
                         this.commandDict.Add(commandHandlerAttribute.Command, @delegate as Commands.CommandHandler);
                         RCClient.Console_AddCustomCommand(RCProcess.CustomCommandParser.ToRawString(commandHandlerAttribute.Name, commandHandlerAttribute.Command, commandHandlerAttribute.Argument));
                     }
                 }
             }
         }
     }
 }
Exemple #2
0
        private void Loop()
        {
            HeroesCommandBridge.Client.LoginSuccess += delegate(object s, EventArgs e)
            {
                Console.WriteLine("connected");
            };
            HeroesCommandBridge.Client.LoginFail += delegate(object s, EventArgs <Exception> e)
            {
                Console.WriteLine("Login Failure:\n{0}", e.Value.ToString());
            };
            HeroesCommandBridge.Client.ServerGroupAdded += delegate(object s, EventArgs <string> e)
            {
                Console.WriteLine("ServerGroup {0} found", e.Value);
            };
            HeroesCommandBridge.Client.ServerGroupRemoved += delegate(object s, EventArgs <string> e)
            {
                Console.WriteLine("ServerGroup {0} removed", e.Value);
            };
            HeroesCommandBridge.Client.Start();
            HeroesAdminManager manager = new HeroesAdminManager(HeroesCommandBridge.Client);

            manager.ServerGroupConnected += delegate(object s, EventArgs <string> e)
            {
                RCClient.Console_AddProperty("commandbridge", manager.ServerString);
                Console.WriteLine("ServerGroup {0} conncted", e.Value);
            };
            manager.ServerGroupDisconnected += delegate(object s, EventArgs <string> e)
            {
                RCClient.Console_AddProperty("commandbridge", manager.ServerString);
                Console.WriteLine("ServerGroup {0} disconnected", e.Value);
            };
            manager.ServerGroupUserCounted += delegate(object s, EventArgs <string> e)
            {
                Console.WriteLine(e.Value);
            };
            manager.ServerGroupNotified += delegate(object s, EventArgs <string> e)
            {
                HeroesCommandBridge.Notify(e.Value);
            };
            EchoClient echoClient = null;

            if (Settings.Default.EchoServerUse)
            {
                echoClient = new EchoClient();
                echoClient.AutoReconnect = true;
                HeroesCommandBridge.Client.ProcessLogged += delegate(object s, EventArgs <string> e)
                {
                    KeyValuePair <RCClient, RCProcess> keyValuePair = (KeyValuePair <RCClient, RCProcess>)s;
                    if (keyValuePair.Key != null && keyValuePair.Value != null)
                    {
                        echoClient.SendLog(string.Format("{0}_{1}", keyValuePair.Key.ID, keyValuePair.Value.Name), string.Format("{0}({1})", keyValuePair.Value.Description, keyValuePair.Key.Name), e.Value);
                    }
                };
                echoClient.ConnectionSucceed += delegate(object s, EventArgs e)
                {
                    Console.WriteLine("Echo Client connected");
                };
                echoClient.ConnectionFailed += delegate(object s, EventArgs <Exception> e)
                {
                    Console.WriteLine("Echo Client connection failed");
                };
                echoClient.Disconnected += delegate(object s, EventArgs e)
                {
                    Console.WriteLine("Echo Client disconnected");
                };
                echoClient.Start();
            }
            this.commandHandler = new Commands(manager);
            for (;;)
            {
                string text = Console.ReadLine();
                if (text != null && text.ToLower() == "shutdown")
                {
                    break;
                }
                HeroesCommandBridge.Thread.Enqueue(Job.Create <string>(new Action <string>(this.ProcessCommand), text));
            }
            if (echoClient != null)
            {
                echoClient.Stop();
                echoClient = null;
            }
            HeroesCommandBridge.Client.Stop();
            HeroesCommandBridge.Client = null;
        }