Exemplo n.º 1
0
        public void Connect(string ip, ushort port)
        {
            this.ip   = IPAddress.Parse(ip);
            this.port = port;
            isRunning = true;

            client = new TcpClient();
            client.Connect(ip, port);
            stream = client.GetStream();

            lock (streamLocker) {
                Protocol.BaseSend(stream, PacketType.ClientConnect, ClientConnect.Serialize(
                                      new ClientConnect()
                {
                    playerChampionType = PlayerChampionType.Jade
                })
                                  );

                while (!stream.DataAvailable)
                {
                    Thread.Sleep(1);
                }

                byte[] data = new byte[ClientConnectResponce.OneObjectSize];
                ClientConnectResponce responce;

                PacketType type = Protocol.BaseRecieve(stream, out data);
                if (type == PacketType.ClientConnectResponce)
                {
                    responce = ClientConnectResponce.Deserialize(data);
                    PlayerId = responce.playerId;
                }
                else
                {
                    throw new Exception("Recieve smth wrong in Client.Connect()");
                }
            }

            clientThread = new Thread(() => {
                ProcessClient();
            });
            clientThread.Start();
        }