예제 #1
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;
        }