Пример #1
0
        // Envoi un packet
        public void SendTCP(PacketOut packet)
        {
            //Fix the packet size
            packet.WritePacketLength();
            packet = Crypt(packet);

            //Get the packet buffer
            byte[] buf = packet.ToArray();             //packet.WritePacketLength sets the Capacity

            //Send the buffer
            SendTCP(buf);
        }
Пример #2
0
        public void SendToAll(PacketOut Packet)
        {
            Packet.WritePacketLength();

            lock (Clients.SyncRoot)
            {
                for (int i = 0; i < Clients.Length; ++i)
                {
                    if (Clients[i] != null)
                    {
                        Clients[i].SendTCP(Packet.ToArray());
                    }
                }
            }
        }
Пример #3
0
        public void SendToAll(PacketOut Packet)
        {
            Packet.WritePacketLength();

            LockReadClients();

            for (int i = 0; i < Clients.Length; ++i)
            {
                if (Clients[i] != null)
                {
                    Clients[i].SendTCP(Packet.ToArray());
                }
            }

            UnLockReadClients();
        }
        // Unused
        public void SendToAll(PacketOut Packet)
        {
            if (!Packet.Finalized)
            {
                Packet.WritePacketLength();
            }

            LockReadClients();

            for (int i = 0; i < Clients.Length; ++i)
            {
                if (Clients[i] != null)
                {
                    Clients[i].SendAsynchronousTCP(Packet.ToArray());
                }
            }

            UnLockReadClients();
        }
Пример #5
0
        private void SendBuffer(Player Plr,ref PacketOut Buffer,ref byte Count)
        {
            // On Envoi le Packet des items
            byte[] ArrayBuf = Buffer.ToArray();
            PacketOut Packet = new PacketOut((byte)Opcodes.F_GET_ITEM);
            Packet.WriteByte(Count);
            Packet.Fill(0, 3);
            Packet.Write(ArrayBuf, 0, ArrayBuf.Length);
            Packet.WritePacketLength();

            Plr.SendPacket(Packet);

            // On Remet le compteur a zero
            Count = 0;

            // On Initalise un nouveau buffer
            Buffer = new PacketOut(0);
            Buffer.Position = 0;
        }
Пример #6
0
        public static byte[] BuildCharacters(int AccountId)
        {
            Log.Debug("BuildCharacters", "AcocuntId = " + AccountId);

            Character[] Chars = GetAccountChar(AccountId)._Chars;
            UInt16 Count = 0;

            // On Compte le nombre de personnages existant du joueur
            for (UInt16 c = 0; c < Chars.Length; ++c)
                if (Chars[c] != null) ++Count;

            PacketOut Out = new PacketOut(0);
            Out.Position = 0;

            Out.WriteByte(MAX_SLOT);
            Out.WriteUInt32(0xFF);
            Out.WriteByte(0x14);

            Character Char = null;
            for (int i = 0; i < MAX_SLOT; ++i)
            {
                Char = Chars[i];

                if (Char == null)
                    Out.Fill(0, 284); // 284
                else
                {
                    List<Character_item> Items = CharMgr.GetItemChar(Char.CharacterId);

                    Out.FillString(Char.Name, 48);
                    Out.WriteByte(Char.Value.Level);
                    Out.WriteByte(Char.Career);
                    Out.WriteByte(Char.Realm);
                    Out.WriteByte(Char.Sex);
                    Out.WriteByte(Char.ModelId);
                    Out.WriteUInt16(Char.Value.ZoneId);
                    Out.Fill(0, 5);

                    Character_item Item = null;
                    for (UInt16 SlotId = 14; SlotId < 30; ++SlotId)
                    {
                        Item = Items.Find(item => item != null && item.SlotId == SlotId);
                        if (Item == null)
                            Out.WriteUInt32(0);
                        else
                            Out.WriteUInt32R(Item.ModelId);

                        Out.Fill(0, 4);
                    }

                    Out.Fill(0, 6);

                    for (int j = 0; j < 5; ++j)
                    {
                        Out.Fill(0, 6);
                        Out.WriteUInt16(0xFF00);
                    }

                    for (UInt16 SlotId = 10; SlotId < 13; ++SlotId)
                    {
                        Item = Items.Find(item => item != null && item.SlotId == SlotId);
                        Out.WriteUInt16(0);
                        if (Item == null)
                            Out.WriteUInt16(0);
                        else
                            Out.WriteUInt16R((ushort)Item.ModelId);
                    }

                    Out.Fill(0, 10);
                    Out.WriteUInt16(0xFF00);
                    Out.WriteByte(0);
                    Out.WriteByte(Char.Race);
                    Out.WriteUInt16(0);
                    Out.Write(Char.bTraits, 0, Char.bTraits.Length);
                    Out.Fill(0, 14);// 272
                }
            }
            return Out.ToArray();
        }
Пример #7
0
 public void SendCopy(PacketOut Out)
 {
     Out.WritePacketLength();
     PacketOut packet = new PacketOut(0);
     packet.Position = 0;
     packet.Write(Out.ToArray(), 0, Out.ToArray().Length);
     SendPacket(packet);
 }
Пример #8
0
        public PacketOut Crypt(PacketOut packet)
        {
            if (m_crypts.Count <= 0)
            {
                return(packet);
            }

            byte[] Packet = packet.ToArray();

            Log.Tcp("SendTCP", Packet, 0, (int)Packet.Length);

            int Hpos = 0;

            Hpos += PacketOut.SizeLen;
            if (PacketOut.OpcodeInLen)
            {
                Hpos += packet.OpcodeLen;
            }

            byte[] Header  = new byte[Hpos];
            byte[] ToCrypt = new byte[(packet.Length - Hpos)];

            for (int i = 0; i < Hpos; ++i)
            {
                Header[i] = Packet[i];
            }

            for (int i = Hpos; i < Packet.Length; ++i)
            {
                ToCrypt[i - Hpos] = Packet[i];
            }

            try
            {
                foreach (KeyValuePair <ICryptHandler, CryptKey[]> Entry in m_crypts)
                {
                    ToCrypt = Entry.Key.Crypt(Entry.Value[0], ToCrypt);
                }
            }
            catch (Exception e)
            {
                Log.Error("BaseClient", "Crypt Error : " + e.ToString());
                return(packet);
            }

            PacketOut Out = new PacketOut((byte)0);

            Out.Opcode    = packet.Opcode;
            Out.OpcodeLen = packet.OpcodeLen;
            Out.Position  = 0;
            Out.SetLength(0);

            byte[] Total = new byte[Header.Length + ToCrypt.Length];

            for (int i = 0; i < Total.Length; ++i)
            {
                if (i < Header.Length)
                {
                    Total[i] = Header[i];
                }
                else
                {
                    Total[i] = ToCrypt[i - Header.Length];
                }
            }

            Out.Write(Total, 0, Total.Length);

            return(Out);
        }
Пример #9
0
        public static byte[] BuildCharactersList(int AccountId)
        {
            Log.Debug("BuildCharactersList", "AcocuntId = " + AccountId);
            Character[] Chars = GetAccountChar(AccountId)._Chars;
            int count = 0;

            PacketOut Out = new PacketOut(0);
            Out.Position = 0;

            Character Char = null;
            for (int k = 0; k < MAX_SLOT; ++k)
            {
                Char = Chars[k];
                if (Char != null)
                {
                    List<Character_items> Items = CharMgr.GetItemChar(Char.CharacterId);

                    /****  char slot start ****/
                    Out.FillString(Char.Name, 48); // name
                    Out.WriteByte(Char.Value[0].Level); // Level
                    Out.WriteByte(Char.Career); //career
                    Out.WriteByte(Char.Realm); // realm
                    Out.WriteByte(Char.Sex); // gender
                    Out.WriteUInt16R(Char.ModelId); //model id
                    Out.WriteUInt16R(Char.Value[0].ZoneId); // zone id
                    Out.Fill(0, 12); // unk

                    Character_items Item = null;
                    for (UInt16 SlotId = 14; SlotId < 30; ++SlotId)
                    {
                        Item = Items.Find(item => item != null && item.SlotId == SlotId);

                        if (Item == null)
                        {
                            Out.WriteInt32(0);
                            Out.WriteInt32(0);
                        }
                        else
                        {

                            Out.WriteInt32((int)Item.ModelId);
                            Out.WriteUInt16R(0); // primary dye
                            Out.WriteUInt16R(0); // secondary dye
                        }
                    }
                    Out.WriteUInt32(0x00); // 0x00000000
                    for (int i = 0; i < 4; i++)
                    {
                        Out.WriteUInt32(0xFF000000);
                        Out.WriteUInt32(0x00);
                    }
                    Out.WriteUInt32(0xFF000000);

                    //weapons
                    for (UInt16 SlotId = 10; SlotId < 13; ++SlotId)
                    {
                        Item = Items.Find(item => item != null && item.SlotId == SlotId);

                        if (Item == null)
                            Out.WriteUInt32(0);
                        else
                        {
                            Out.WriteUInt16R((ushort)Item.ModelId);
                            Out.WriteUInt16(0);
                        }
                    }
                    Out.Fill(0, 8);
                    Out.WriteUInt16(0xFF00);
                    Out.WriteByte(0);
                    Out.WriteByte(Char.Race); // char slot position
                    Out.WriteUInt16(0x00); //unk

                   /* //Traits [8 bytes]
                    Out.WriteByte(1); //face
                    Out.WriteByte(4); //jewel
                    Out.WriteByte(4); //scar
                    Out.WriteByte(0); //hair
                    Out.WriteByte(3); //hair color
                    Out.WriteByte(2); //skin color
                    Out.WriteByte(0); //eye color
                    Out.WriteByte(5); //metal color
                    */
                    Out.Write(Char.bTraits, 0, Char.bTraits.Length);

                    Out.Fill(0, 14); //unk

                    count++;
                }
            }

            for (int i = 0; i < (MAX_SLOT - count); ++i)
                Out.Write(new byte[284], 0, 284);

            return Out.ToArray();
        }
Пример #10
0
        public void SendFriends(List<Character_social> Socials)
        {
            PacketOut Out = new PacketOut((byte)Opcodes.F_SOCIAL_NETWORK);
            Out.WriteUInt16(0);
            Out.WriteByte(1);
            Out.WriteByte((byte)Socials.Count);
            Out.WriteByte(0);

            foreach (Character_social Social in Socials)
                BuildPlayerInfo(ref Out, Social);

            Log.Dump("Friends", Out.ToArray(), 0, Out.ToArray().Length);
            GetPlayer().SendPacket(Out);
        }
Пример #11
0
 public void SendCopy(PacketOut Out)
 {
     Out.WritePacketLength();
     byte[] Buf = Out.ToArray();
     PacketOut packet = new PacketOut(0);
     packet.Position = 0;
     packet.Write(Buf, 0, Buf.Length);
     SendPacket(packet);
     
 }