예제 #1
0
        public static HelloPacket Read(NBufferReader reader)
        {
            var ret = new HelloPacket();

            ret.BuildVer = reader.ReadUTF();
            ret.GameId   = reader.ReadUInt32();
            ret.Guid     = reader.ReadUTF();
            ret.Rand1    = reader.ReadUInt32();
            ret.Password = reader.ReadUTF();
            ret.Rand2    = reader.ReadUInt32();
            ret.Secret   = reader.ReadUTF();
            ret.KeyTime  = reader.ReadUInt32();
            ret.Key      = reader.ReadBytes(reader.ReadUInt16());
            ret.MapInfo  = reader.Read32UTF();
            ret.X1       = reader.ReadUTF();
            ret.X2       = reader.ReadUTF();
            ret.X3       = reader.ReadUTF();
            ret.X4       = reader.ReadUTF();
            ret.X5       = reader.ReadUTF();
            return(ret);
        }
예제 #2
0
        private NWriter OnHello(HelloPacket packet)
        {
            string dns  = destDns;
            int    port = destPort;

            Tuple <string, int, byte[]> x;
            int key;

            if (packet.Key.Length == 4 &&
                reconnKeys.TryGetValue(key = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(packet.Key, 0)), out x))
            {
                dns          = x.Item1;
                port         = x.Item2;
                packet.Key   = x.Item3;
                ConnectionId = key;
            }
            else
            {
                ConnectionId = -1;
            }

            server = new TcpClient();
            server.Connect(dns, port);
            AppendLog("Connected to remote '{0}'.", dns);

            var adr = ((IPEndPoint)server.Client.RemoteEndPoint).Address.ToString();

            if (serverNames.ContainsKey(adr))
            {
                ConnectionName = serverNames[adr];
            }

            Version = packet.BuildVer;
            GameId  = packet.GameId;

            svrWkr = new Thread(() => ProcessLoop(server, client, SendKey1, SendKey2, sendClient, OnServerPacketReceived));
            svrWkr.Start();

            return(new NWriter(server.GetStream()));
        }