Beispiel #1
0
        public void MakeTestPacket2(Stream network, string AccountName, string CharName)
        {
            byte[]            rawAccount = StringToChars(AccountName);
            byte[]            rawChar    = StringToChars(CharName);
            TGSGetDataRequest packet     = new TGSGetDataRequest();

            packet.h.seqno  = 1;
            packet.h.size   = (short)(rawAccount.Length + rawChar.Length + Marshal.SizeOf(packet));
            packet.h.type   = (byte)EPacketType.GSGetDataRequest;
            packet.datatype = 1;
            byte[] rawPacket = D2DBS.core.StructToBytes(packet);
            network.Write(rawPacket, 0, rawPacket.Length);
            network.Write(rawAccount, 0, rawAccount.Length);
            network.Write(rawChar, 0, rawChar.Length);
        }
Beispiel #2
0
        private int HandleGetDataRequest(ConnInfo Conn, List <byte> buf)
        {
            TGSGetDataRequest packet = new TGSGetDataRequest();
            int pos = Marshal.SizeOf(packet);

            packet = (TGSGetDataRequest)D2DBS.core.BytesToStruct(buf.ToArray(), Marshal.SizeOf(packet), packet.GetType());
            string[]  Names       = BytesToString(buf.GetRange(pos, buf.Count - pos)).Split('\0');
            string    AccountName = Names[0];
            string    CharName    = Names[1];
            TCharInfo CharInfo    = new TCharInfo();
            byte      result      = 1;

            byte[] data = null;
            if (packet.datatype == 1)
            {
                if (D2DBS.charlock.SetCharLock(CharName, Conn.GSId))
                {
                    data = D2DBS.charfile.GetCharSave(AccountName, CharName);
                    if (data == null)
                    {
                        result = 1;
                        D2DBS.log.Write("error", "Failed to load charsave `" + CharName + "`(*" + AccountName + ") for gs " + Conn.GSId.ToString());
                        D2DBS.charlock.UnlockChar(CharName);
                    }
                    else
                    {
                        result = 0;
                        D2DBS.log.Write("info", "Loaded charsave `" + CharName + "`(*" + AccountName + ") for gs " + Conn.GSId.ToString());
                    }
                }
                else
                {
                    int LockGSId = D2DBS.charlock.GetGSIdByLock(CharName);
                    result = 1;
                    D2DBS.log.Write("warn", "Char `" + CharName + "`(*" + AccountName + ") already locked on gs " + LockGSId.ToString() + " for gs " + Conn.GSId.ToString());
                    //KickPlayer(D2DBS.net.GetConnByGSId(LockGSId), CharName);
                }
            }
            else
            {
                data = D2DBS.charfile.GetCharInfoRaw(AccountName, CharName);
                D2DBS.log.Write("info", "Loaded charinfo `" + CharName + "`(*" + AccountName + ") for gs " + Conn.GSId.ToString());
            }
            if (result == 0)
            {
                byte[] RAWCharInfo = D2DBS.charfile.GetCharInfoRaw(AccountName, CharName);
                if (RAWCharInfo == null)
                {
                    D2DBS.log.Write("error", "Failed to load charinfo `" + CharName + "`(*" + AccountName + ") for gs " + Conn.GSId.ToString());
                    D2DBS.charlock.UnlockChar(CharName);
                    result = 1;
                }
                else
                {
                    CharInfo = (TCharInfo)D2DBS.core.BytesToStruct(RAWCharInfo, typeof(TCharInfo));
                }
            }
            TDBSGetDataReply rpacket = new TDBSGetDataReply();

            if (result == 0)
            {
                int ladder_time = int.Parse(D2DBS.config["ladderinit_time"]);
                if (D2DBS.charfile.GetLadder((ushort)CharInfo.summary.charstatus) == 1)
                {
                    if (CharInfo.header.create_time < ladder_time)
                    {
                        rpacket.allowladder = 0;
                        D2DBS.log.Write("info", "Char `" + CharName + "`(*" + AccountName + ") expired for ladder, converting to non-ladder");
                    }
                    else
                    {
                        rpacket.allowladder = 1;
                    }
                }
                else
                {
                    rpacket.allowladder = 0;
                }
                rpacket.charcreatetime = CharInfo.header.create_time;
                rpacket.datalen        = (short)data.Length;
            }
            else
            {
                rpacket.allowladder    = 0;
                rpacket.charcreatetime = 0;
                rpacket.datalen        = 0;
            }
            byte[] rawcharname = StringToChars(CharName);
            rpacket.h.seqno  = packet.h.seqno;
            rpacket.h.type   = (byte)EPacketType.DBSGetDataReply;
            rpacket.h.size   = (short)(Marshal.SizeOf(rpacket) + rawcharname.Length + rpacket.datalen);
            rpacket.datatype = packet.datatype;
            rpacket.result   = result;
            lock (Conn.StreamLocker)
            {
                Conn.NetWriter.Write(D2DBS.core.StructToBytes(rpacket));
                Conn.NetWriter.Write(rawcharname);
                if (rpacket.datalen > 0)
                {
                    Conn.NetWriter.Write(data);
                }
                Conn.NetWriter.Flush();
            }
            return(0);
        }