Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Bot  b      = new Bot();
            bool readed = false;

            while (!readed)
            {
                try
                {
                    string data = System.IO.File.ReadAllText("crrntbrd.txt");
                    if (data != "" && data != "<EoF>")
                    {
                        data = data.Replace("<EoF>", "");
                        Helpfunctions.Instance.resetBuffer();
                        Helpfunctions.Instance.writeBufferToFile();
                        //readed = true;
                        b.doData(data);
                    }
                }
                catch
                {
                }
                System.Threading.Thread.Sleep(10);
            }

            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            System.AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
            Bot  b       = new Bot();
            bool network = Settings.Instance.useNetwork;

            while (true)
            {
                System.Threading.Thread.Sleep(10);
                if (network)
                {
                    FishNet.Instance.checkConnection();
                    KeyValuePair <string, string> msg = FishNet.Instance.readMessage();
                    if (msg.Value == "")
                    {
                        continue;
                    }
                    switch (msg.Key)
                    {
                    case "crrntbrd.txt":
                        b.doData(msg.Value);
                        break;

                    case "curdeck.txt":
                        b.doDeckData(msg.Value);
                        break;
                    }
                    continue;
                }
                try
                {
                    string data = System.IO.File.ReadAllText("crrntbrd.txt");
                    //Helpfunctions.Instance.ErrorLog(data);
                    if (data != "" && data != "<EoF>")
                    {
                        data = data.Replace("<EoF>", "");
                        Helpfunctions.Instance.resetBuffer();
                        Helpfunctions.Instance.writeBufferToFile();
                        //readed = true;
                        b.doData(data);
                    }
                }
                catch
                {
                }
                try
                {
                    string data = System.IO.File.ReadAllText("curdeck.txt");
                    //Helpfunctions.Instance.ErrorLog(data);
                    if (data != "" && data != "<EoF>")
                    {
                        data = data.Replace("<EoF>", "");
                        Helpfunctions.Instance.resetBuffer();
                        Helpfunctions.Instance.writeBufferToDeckFile();
                        //readed = true;
                        b.doDeckData(data);
                    }
                }
                catch
                {
                }
            }
        }
        public void start()
        {
            String ip_port = "127.0.0.1:11111";

            try
            {
                ip_port = System.IO.File.ReadAllText("ip.txt").Replace("\r\n", "").Replace(" ", "");
            }
            catch
            {
            }

            try
            {
                string ipa = ip_port.Split(':')[0];
                this.port      = Convert.ToInt32(ip_port.Split(':')[1]);
                this.ipAddress = IPAddress.Parse(ipa);
            }
            catch
            {
                Console.WriteLine("Error: cant read ip + port, legal tupel is 127.0.0.1:11111");
            }

            IPEndPoint remoteEP = new IPEndPoint(this.ipAddress, this.port);



            try
            {
                client.Connect(remoteEP);

                Console.WriteLine("Socket connected to {0}", client.RemoteEndPoint.ToString());

                // Encode the data string into a byte array.

                String   name   = Directory.GetCurrentDirectory();
                String[] splits = name.Split(Path.DirectorySeparatorChar);
                sendDataToServer("hello:" + splits[splits.Length - 1]);

                while (true)
                {
                    // Receive the response from the remote device.
                    int    bytesRec = client.Receive(bytes);
                    string datarec  = Encoding.ASCII.GetString(bytes, 0, bytesRec);
                    Console.WriteLine("######################rec from server: \r\n" + datarec);

                    if (datarec == "connected with HSServer" || datarec.StartsWith("ok "))
                    {
                        //nothing wait for board...
                    }
                    else
                    {
                        try
                        {
                            string data = datarec;
                            if (data != "" && data != "<EoF>")
                            {
                                data = data.Replace("<EoF>", "");
                                //Helpfunctions.Instance.resetBuffer();
                                //Helpfunctions.Instance.writeBufferToFile();
                                //readed = true;
                                b.doData(data, client);
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                // Release the socket.
                client.Shutdown(SocketShutdown.Both);
                client.Close();
            }
            catch (ArgumentNullException ane)
            {
                Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
            }
            catch (SocketException se)
            {
                Console.WriteLine("SocketException : {0}", se.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine("Unexpected exception : {0}", e.ToString());
            }
        }