Ejemplo n.º 1
0
        private void ZS_DataReceived(EventDrivenTCPClient sender, object data)
        {
            try
            {
                byte[]        buffer = (byte[])Convert.ChangeType(data, typeof(byte[]));
                List <byte[]> packetList;
                Packet.SplitPackets(buffer, buffer.Length, out packetList);
                foreach (byte[] sPacket in packetList)
                {
                    byte[] packet = sPacket;
                    Config.mConvert.Crypter.Decrypt(ref packet, ClientVer.v562);
                    MSG_HEAD_WITH_PROTOCOL pHeader = new MSG_HEAD_WITH_PROTOCOL();
                    pHeader.Deserialize(ref packet);
                    if (ZoneAgent._Players.ContainsKey(pHeader.dwPCID))
                    {
                        Client client = ZoneAgent._Players[pHeader.dwPCID];

                        if (pHeader.byCtrl == 0x01 && pHeader.byCmd == 0xE1)
                        {
                            //Zone Change Packet
                            _Main.UpdateLogMsg(string.Format("{0} {1} user zone changed {2}->{3}", client.Account, client.Uid, client.ZoneStatus, packet[0x0A]));
                            client.ZoneStatus = packet[0x0A];
                            continue;
                        }
                        else if (pHeader.wProtocol == 0x1800)
                        {
                            MSG_S2C_SAY pSay = new MSG_S2C_SAY();
                            pSay.Deserialize(ref packet);
                            if (pSayType.Notice == (pSayType)pSay.bySayType && "NOTICE" == pSay.szSayPC && uint.MaxValue == pSay.dwSayPCID)
                            {
                                ZoneAgent.szNotice = pSay.szWords;
                            }
                        }
                        else if (pHeader.wProtocol == 0x1107)
                        {
                            //world login: save character name and town
                            MSG_S2C_WORLD_LOGIN wLogin = new MSG_S2C_WORLD_LOGIN();
                            wLogin.Deserialize(ref packet);
                            client.Character = wLogin.szPCName;
                            client.Town      = wLogin.byTown;
                        }
                        //encrypt후 클라이언트로 send
                        //Config.mConvert.Convert_S2C(ref packet, client.Ver);
#if DEBUG
                        PacketLogger.LogPacket(packet, "server_to_client", client.Character);
#endif
                        ZoneAgent.Write(ref client, packet);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("ZS_DataReceived: {0}", ex));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// LS에서 들어오는 패킷 처리
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="data"></param>
        private void LS_DataReceived(EventDrivenTCPClient sender, object data)
        {
            try
            {
                byte[] packet = (byte[])Convert.ChangeType(data, typeof(byte[]));
                MSG_HEAD_WITH_PROTOCOL pHeader = new MSG_HEAD_WITH_PROTOCOL();
                pHeader.Deserialize(ref packet);
                switch (pHeader.byCtrl)
                {
                case 0x01:
                    switch (pHeader.byCmd)
                    {
                    case 0xE1:         //LS가 보내주는 접속할 새 클라이언트 정보 : Uid, 0A:userid(30)
                        if (!PreparedAcc.ContainsKey(pHeader.dwPCID))
                        {
                            MSG_LS2ZA_ACC_LOGIN accPrepare = new MSG_LS2ZA_ACC_LOGIN();
                            accPrepare.Deserialize(ref packet);
                            PreparedAcc.Add(pHeader.dwPCID, new LSuserInfo(accPrepare.szAccount));
                            //zonelog update
                            _Main.UpdateLogMsg(string.Format("<LC>UID={0} {1} Prepared", pHeader.dwPCID, accPrepare.szAccount));
                        }
                        break;

                    case 0xE3:         //duplicate login; request DC to ZA from loginserver
                        if (ZoneAgent._Players.ContainsKey(pHeader.dwPCID))
                        {
                            MSG_LS2ZA_REQ_LOGOUT reqLogout = new MSG_LS2ZA_REQ_LOGOUT();
                            reqLogout.Deserialize(ref packet);
                            //zonelog update
                            _Main.UpdateLogMsg(string.Format("<LC>UID={0} {1} Dropped, Duplicate login", reqLogout.MsgHeader.dwPCID, reqLogout.szAccount));
                            ZoneAgent.RemoveClient(pHeader.dwPCID, reqLogout.byReason);
                        }
                        break;

                    default:         //any other packet received
                        Logger.NewPacket("LS->ZA", packet, sender.IP.ToString(), ClientVer.undefined);
                        break;
                    }
                    break;

                default:
                    Logger.NewPacket("LS->ZA", packet, sender.IP.ToString(), ClientVer.undefined);
                    break;
                }
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("LS_DataReceived: {0}", ex));
            }
        }