Exemplo n.º 1
0
        /// <summary>
        /// ZoneServer Data Received methd
        /// Will be executed when data is received from ZoneServer
        /// Will split packet and add each packet in list and then send it to client
        /// </summary>
        /// <param name="sender">EventDrivenTCPClient object</param>
        /// <param name="data">byte[] data</param>
        void ZS_DataReceived(EventDrivenTCPClient sender, object data)
        {
            try
            {
                var packet = (byte[])Convert.ChangeType(data, typeof(byte[]));
                //File.WriteAllBytes("OGZS_" + Environment.TickCount + "_" + packet.Length, packet);
                Application.DoEvents();
                var packetList = new List <byte[]>();
                Application.DoEvents();
                packetList.Clear();
                Application.DoEvents();
                Packet.SplitPackets(packet, packet.Length, ref packetList);
                foreach (var t in packetList)
                {
                    var temp = new byte[4];
                    Array.Copy(t, 4, temp, 0, 4);
                    var id = Packet.GetClientId(temp);
                    if (player.ContainsKey(id))
                    {
                        var playerinfo = player[id];
                        //Below condition is for disconneting client or reconnecting client
                        if (playerinfo.ZoneStatus == Config.AS_ID)
                        {
                            if (t.Length == 952)
                            {
                                Write(playerinfo.Client.TcpClient, Packet.AlterAccountServerPacket(t));
                            }
                            else
                            {
                                Write(playerinfo.Client.TcpClient, t);
                            }
                        }
                        else
                        {
                            Write(playerinfo.Client.TcpClient, t);
                            //Below condition is for disconneting client or reconnecting client
                            if (t.Length == 12 && t[10] == 0x08 && t[11] == 0x11)
                            {
                                Config.PLAYER_COUNT--;
                                //player count update
                                _Main.Update_Player_Count();
                                //zonelog update
                                _Main.Update_zonelog("<LC> UID = " + id + " " + playerinfo.Account + " User Left");

                                playerinfo.Prepared = false;
                                LS.Send(Packet.SendDCToLS(id, playerinfo.Account, Packet.GetTime()));
                                playerinfo.ZoneStatus = -1;
                                ZS.Send(Packet.SendDCToASZS(id));
                                player.Remove(id);
                                if (clients.Contains(playerinfo.Client))
                                {
                                    lock (clients)
                                    {
                                        clients.Remove(playerinfo.Client);
                                    }
                                }
                            }
                            //Set Character Name
                            else if (t.Length == 39 && t[10] == 0x06 && t[11] == 0x11)
                            {
                                playerinfo.CharName = Packet.GetCharName(Crypt.Decrypt(t), 12);
                            }
                            //Below condition is to reduce chance of other packets come under same conditions
                            else if (t.Length > 18 && t[10] == 0x00 && t[11] == 0x18 && t[12] == 0x74 && t[13] == 0xCE && t[14] == 0xCA && t[15] == 0xE9 && t[16] == 0x87 && t[17] == 0x7F && t[18] == 0xAB)
                            {
                                var tempPacket = t;
                                Packet.SetStatusValues(tempPacket);
                            }
                        }
                        //Zone changed Packet : ZoneStatus Change
                        if (t.Length == 11 && t[8] == 0x01 && t[9] == 0xE1)
                        {
                            //zonelog update
                            _Main.Update_zonelog(playerinfo.Account + " (" + id + ") user zone changed " + playerinfo.ZoneStatus + " -> " + t[10]);
                            playerinfo.ZoneStatus = t[10];
                        }
                    }
                }
            }
            catch (Exception ZSDataArrival)
            {
                Logger.Write(Logger.GetLoggerFileName("ZoneServer"), "ZoneServer DataReceived : " + ZSDataArrival.ToString());
            }
        }