Beispiel #1
0
        public static void Main(string[] args)
        {
            //TODO: Implement better command line handling.
            #if DEBUG
            args = new string[]
            {
                "gamea.clashofclans.com",
                "9339"
            };
            #endif
            var port = -1;
            var address = (IPAddress)null;
            if (!TryGetPort(args, out port))
                return;
            if (!TryGetIPAddress(args, out address))
                return;

            Kernal = new StandardKernel();
            Kernal.Load(Assembly.GetExecutingAssembly());

            Console.WriteLine("Starting proxy server...");
            ProxyService = Kernal.Get<IProxyService>();
            ProxyService.Start();

            // TODO: Setup visitor design pattern so that 1 or more implementations can be notified of these events.
            Configuration = ClientConfiguration.LoadConfiguration("clientConfig.xml");
            Client = new CoCClient();
            Client.Login += OnLogin;
            Client.ChatMessage += OnChatMessage;
            Client.AllianceInfo += ProxyService.OnAllianceInfo;
            Client.Avatar.ID = Configuration.UserID;
            Client.Avatar.Token = Configuration.UserToken;

            Console.WriteLine("Connecting to {0}:{1}...", address, port);
            Client.Connect(new IPEndPoint(address, port));

            Console.WriteLine("Waiting for commands..");

            while (true)
            {
                var input = Console.ReadLine();

                if (string.IsNullOrWhiteSpace(input))
                    continue;

                if (input[0] == '/')
                {
                    var command = input.Substring(1).Split(' ');

                    switch (command[0])
                    {
                        case "a":
                            Client.SendAllianceInfoRequest(long.Parse(command[1]));
                            break;
                    }
                }
                else
                    Client.SendChatMessage(input);
            }
        }