Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            #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;

            Configuration = ClientConfiguration.LoadConfiguration("clientConfig.xml");
            Client = new CoCClient();
            Client.ChatMessage += OnChatMessage;
            Client.Avatar.ID = Configuration.UserID;
            Client.Avatar.Token = Configuration.UserToken;

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

            while (true)
            {
                var message = Console.ReadLine();
                Client.SendChatMessage(message); //TODO: Handle stuff interms of commands.
            }
        }
        public static ClientConfiguration LoadConfiguration(string configFilePath)
        {
            if (File.Exists(configFilePath))
            {
                var config = new ClientConfiguration();
                var readerSettings = new XmlReaderSettings()
                {
                    IgnoreComments = true,
                    IgnoreWhitespace = true
                };

                using (var reader = XmlReader.Create(configFilePath, readerSettings))
                {
                    var lastElement = reader.Name;
                    while (reader.Read())
                    {
                    ReadXmlElements:
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            lastElement = reader.Name;
                            switch (lastElement)
                            {
                                case "id":
                                    config.UserID = reader.ReadElementContentAsLong();
                                    goto ReadXmlElements;

                                case "token":
                                    var token = reader.ReadElementContentAsString();
                                    config.UserToken = token == "null" ? null : token;
                                    goto ReadXmlElements;
                            }
                        }
                    }
                }
                return config;
            }

            var writerSettings = new XmlWriterSettings()
            {
                Indent = true,
            };

            using (var writer = XmlWriter.Create(configFilePath, writerSettings))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("clientConfiguration");

                writer.WriteElementString("id", _DefaultConfiguration.UserID.ToString());
                writer.WriteComment("The user ID that will be used for login in.");

                var token = _DefaultConfiguration.UserToken == null ? "null" : _DefaultConfiguration.UserToken;
                writer.WriteElementString("token", token);
                writer.WriteComment("The user token that will be used for login in.");

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
            return _DefaultConfiguration;
        }
Ejemplo n.º 3
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;

            Configuration = ClientConfiguration.LoadConfiguration("clientConfig.xml");
            Client = new CoCClient();
            Client.Login += OnLogin;
            Client.ChatMessage += OnChatMessage;
            Client.Avatar.ID = Configuration.UserID;
            Client.Avatar.Token = Configuration.UserToken;

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

            while (true)
            {
                var command = Console.ReadLine();
                if (command[0] == '/')
                    Console.WriteLine("TODO: Handle command.");
                else
                //Client.SendChatMessage(command);
                {
                    Client.SendPacket(new AllianceChatMessageClientPacket()
                    {
                        Message = command
                    });
                }
            }
        }