[Point Blank] UDP3 answer - Форум администраторов игровых серверов
Форум администраторов игровых серверов StormWall - Защита от DDos атак
Регистрация Мнения Справка Пользователи Календарь Все разделы прочитаны
Вернуться   Форум администраторов игровых серверов > MMO > Point Blank (Piercing Blow)

Point Blank (Piercing Blow)
Общие вопросы по написанию эмулятора. General questions on developing emulator. При поддержке: Lucera 2 - разработка Java Interlude

Ответ
Опции темы
Непрочитано 28.06.2018, 23:10   #1
Пользователь

Автор темы (Топик Стартер) UDP3 answer

Hi,
i've a quickly question.

I've writted the header of the packet 4, than I've write the body.
The body have to been shifted again before send back to the client?

Thanks in advanca
ManuelDev вне форума Ответить с цитированием
Непрочитано 29.06.2018, 12:09   #2
Пользователь

Автор темы (Топик Стартер) Re: UDP3 answer

I've try shifted and unshifted, but he keep don't working!

This is the actual class, somebody understand what's the problem?

Код:
using Battle.Utils;
using System;
using System.IO;
using System.Text;
namespace Battle.Battle
{
    public class UdpPacket
    {
        public byte Id { get; set; }
        public byte Slot { get; set; }
        public float Time { get; set; }
        public byte Session { get; set; }
        public short Length { get; set; }
        public int Events { get; set; }
        public byte[] Data { get; set; }

        public BattleReceive Receive;
        public BattleSend send2;
        public BattleSend Event3;

        public UdpPacket(byte[] Buffer)
        {
            BinaryReader br = new BinaryReader(new MemoryStream(Buffer));
            Id = br.ReadByte();
            Slot = br.ReadByte();
            Time = br.ReadSingle();
            Session = br.ReadByte();
            Length = br.ReadInt16();
            Events = br.ReadInt32();

            send2 = new BattleSend();
            send2.writeC(4);
            send2.writeC(255);
            send2.writeFloat(Time);
            send2.writeC(Session);
            send2.writeH(Length);
            send2.writeD(0);

            if (Id == 3)
            {
                Data = br.ReadBytes(Length - 13);
                send2.writeB(Data); // <- This is working (just copying the received data)

                Event3 = HandlePacket(); // <- This isn't working (Just tried with PosRotation)
            }
        }


        public BattleSend HandlePacket()
        {
            byte[] events = Data;
            Unshift(events, Length % 6 + 1);
            BinaryReader read = new BinaryReader(new MemoryStream(events));
            byte opcode = read.ReadByte();
            ushort subSlot = read.ReadUInt16();
            ushort subLength = read.ReadUInt16();
            int flag = read.ReadInt32();
            int packetSize = 0;
            int packetFlag = 0;

            BattleSend eventData = new BattleSend();
            if (opcode == 0)
            {
                if ((flag & 0x01) > 0) int action = read.ReadInt16();
                if ((flag & 0x02) > 0)  int action = read.ReadInt16();

                if ((flag & 0x04) > 0) //Position rotation
                {
                    ushort posX = read.ReadUInt16();
                    ushort posY = read.ReadUInt16();
                    ushort posZ = read.ReadUInt16();
                    ushort camX = read.ReadUInt16();
                    ushort camY = read.ReadUInt16();
                    ushort zone = read.ReadUInt16();

                    eventData.writeUH(posX);
                    eventData.writeUH(posY);
                    eventData.writeUH(posZ);
                    eventData.writeUH(camX);
                    eventData.writeUH(camY;
                    eventData.writeUH(zone);

                    packetSize+= 12;
                    packetFlag += 4;
                     

                }

                if ((flag & 0x40) > 0) Log.Info("wep type: " + read.ReadByte() + ", wep: " + read.ReadInt32());
                if ((flag & 0x1000) > 0) Log.Info("HP: " + read.ReadUInt16()); //No working
                if ((flag & 0x80000) > 0) Log.Info("Hit a item!");
                if ((flag & 0x80000) > 0) Log.Info("Hit a player!");
            }

            BattleSend header = new BattleSend();
            header.writeC(4);
            header.writeC(255);
            header.writeFloat(Time);
            header.writeC(Session);
            header.writeH((short)(packetSize + 13));
            header.writeD(0);

            BattleSend body = new BattleSend();
            body.writeC(opcode);
            body.writeH(subSlot);
            body.writeH((short)packetSize);
            body.writeD(packetFlag);
            body.writeB(eventData.mstream.ToArray());

            byte[] toshift = body.mstream.ToArray();
            Shift(toshift, (packetSize + 13) % 6 + 1);
            header.writeB(toshift);
            return header;
        }

        public static void Shift(byte[] buffer, int bits)
        {
            int length = buffer.Length;
            byte first = buffer[0];
            byte current;

            for (int i = 0; i < length; i++)
            {
                if (i >= (length - 1))
                {
                    current = first;
                }
                else
                {
                    current = buffer[i + 1];
                }

                buffer[i] = (byte)(current >> (8 - bits) | (buffer[i] << bits));
            }
        }

        public static void Unshift(byte[] buffer, int bits)
        {
            int length = buffer.Length;
            byte last = buffer[length - 1];
            byte current;

            for (int i = length - 1; (i & 0x80000000) == 0; i--)
            {
                if (i <= 0)
                {
                    current = last;
                }
                else
                {
                    current = buffer[i - 1];
                }

                buffer[i] = (byte)(current << (8 - bits) | buffer[i] >> bits);
            }
        }
    }
}
How i call it
Код:
// ..

bool copyBuffer = false;
public void BeginReceive(IAsyncResult result){
    // ..
    byte[] buffer = client.EndReceive(result, ref remoteEP);
    UdpPacket Packet = new UdpPacket(buffer);

    switch(Packet.Id){
        case 65: // .. 
        case 66: // ..
        case 3:{
            foreach (Player pl in Room.Players.Values)
                        {
                            bool isUdp = Room.isUDP(pl.Slot, us.Slot == Room.leader);
                            if (isUdp)
                            {
                                // copyBuffer = true -> Working | copyBuffer = false -> Don't work, all players stopped
                                if(copyBuffer) client.Send(Packet.send2.mstream.ToArray(), Packet.send2.mstream.ToArray().Length, new IPEndPoint(IPAddress.Parse(pl.Ip), pl.Port));
                                else client.Send(Packet.Event3.mstream.ToArray(), Packet.Event3.mstream.ToArray().Length, new IPEndPoint(IPAddress.Parse(pl.Ip), pl.Port));
                            }
                        }
        }
        default: //..
    }
}
@PROGRAMMATOR
@Awiion
ManuelDev вне форума Ответить с цитированием
Непрочитано 30.06.2018, 18:28   #3
Пользователь

Автор темы (Топик Стартер) Re: UDP3 answer

Цитата:
Сообщение от ManuelDev Посмотреть сообщение
I've try shifted and unshifted, but he keep don't working!

This is the actual class, somebody understand what's the problem?

Код:
using Battle.Utils;
using System;
using System.IO;
using System.Text;
namespace Battle.Battle
{
    public class UdpPacket
    {
        public byte Id { get; set; }
        public byte Slot { get; set; }
        public float Time { get; set; }
        public byte Session { get; set; }
        public short Length { get; set; }
        public int Events { get; set; }
        public byte[] Data { get; set; }

        public BattleReceive Receive;
        public BattleSend send2;
        public BattleSend Event3;

        public UdpPacket(byte[] Buffer)
        {
            BinaryReader br = new BinaryReader(new MemoryStream(Buffer));
            Id = br.ReadByte();
            Slot = br.ReadByte();
            Time = br.ReadSingle();
            Session = br.ReadByte();
            Length = br.ReadInt16();
            Events = br.ReadInt32();

            send2 = new BattleSend();
            send2.writeC(4);
            send2.writeC(255);
            send2.writeFloat(Time);
            send2.writeC(Session);
            send2.writeH(Length);
            send2.writeD(0);

            if (Id == 3)
            {
                Data = br.ReadBytes(Length - 13);
                send2.writeB(Data); // <- This is working (just copying the received data)

                Event3 = HandlePacket(); // <- This isn't working (Just tried with PosRotation)
            }
        }


        public BattleSend HandlePacket()
        {
            byte[] events = Data;
            Unshift(events, Length % 6 + 1);
            BinaryReader read = new BinaryReader(new MemoryStream(events));
            byte opcode = read.ReadByte();
            ushort subSlot = read.ReadUInt16();
            ushort subLength = read.ReadUInt16();
            int flag = read.ReadInt32();
            int packetSize = 0;
            int packetFlag = 0;

            BattleSend eventData = new BattleSend();
            if (opcode == 0)
            {
                if ((flag & 0x01) > 0) int action = read.ReadInt16();
                if ((flag & 0x02) > 0)  int action = read.ReadInt16();

                if ((flag & 0x04) > 0) //Position rotation
                {
                    ushort posX = read.ReadUInt16();
                    ushort posY = read.ReadUInt16();
                    ushort posZ = read.ReadUInt16();
                    ushort camX = read.ReadUInt16();
                    ushort camY = read.ReadUInt16();
                    ushort zone = read.ReadUInt16();

                    eventData.writeUH(posX);
                    eventData.writeUH(posY);
                    eventData.writeUH(posZ);
                    eventData.writeUH(camX);
                    eventData.writeUH(camY;
                    eventData.writeUH(zone);

                    packetSize+= 12;
                    packetFlag += 4;
                     

                }

                if ((flag & 0x40) > 0) Log.Info("wep type: " + read.ReadByte() + ", wep: " + read.ReadInt32());
                if ((flag & 0x1000) > 0) Log.Info("HP: " + read.ReadUInt16()); //No working
                if ((flag & 0x80000) > 0) Log.Info("Hit a item!");
                if ((flag & 0x80000) > 0) Log.Info("Hit a player!");
            }

            BattleSend header = new BattleSend();
            header.writeC(4);
            header.writeC(255);
            header.writeFloat(Time);
            header.writeC(Session);
            header.writeH((short)(packetSize + 13));
            header.writeD(0);

            BattleSend body = new BattleSend();
            body.writeC(opcode);
            body.writeH(subSlot);
            body.writeH((short)packetSize);
            body.writeD(packetFlag);
            body.writeB(eventData.mstream.ToArray());

            byte[] toshift = body.mstream.ToArray();
            Shift(toshift, (packetSize + 13) % 6 + 1);
            header.writeB(toshift);
            return header;
        }

        public static void Shift(byte[] buffer, int bits)
        {
            int length = buffer.Length;
            byte first = buffer[0];
            byte current;

            for (int i = 0; i < length; i++)
            {
                if (i >= (length - 1))
                {
                    current = first;
                }
                else
                {
                    current = buffer[i + 1];
                }

                buffer[i] = (byte)(current >> (8 - bits) | (buffer[i] << bits));
            }
        }

        public static void Unshift(byte[] buffer, int bits)
        {
            int length = buffer.Length;
            byte last = buffer[length - 1];
            byte current;

            for (int i = length - 1; (i & 0x80000000) == 0; i--)
            {
                if (i <= 0)
                {
                    current = last;
                }
                else
                {
                    current = buffer[i - 1];
                }

                buffer[i] = (byte)(current << (8 - bits) | buffer[i] >> bits);
            }
        }
    }
}
How i call it
Код:
// ..

bool copyBuffer = false;
public void BeginReceive(IAsyncResult result){
    // ..
    byte[] buffer = client.EndReceive(result, ref remoteEP);
    UdpPacket Packet = new UdpPacket(buffer);

    switch(Packet.Id){
        case 65: // .. 
        case 66: // ..
        case 3:{
            foreach (Player pl in Room.Players.Values)
                        {
                            bool isUdp = Room.isUDP(pl.Slot, us.Slot == Room.leader);
                            if (isUdp)
                            {
                                // copyBuffer = true -> Working | copyBuffer = false -> Don't work, all players stopped
                                if(copyBuffer) client.Send(Packet.send2.mstream.ToArray(), Packet.send2.mstream.ToArray().Length, new IPEndPoint(IPAddress.Parse(pl.Ip), pl.Port));
                                else client.Send(Packet.Event3.mstream.ToArray(), Packet.Event3.mstream.ToArray().Length, new IPEndPoint(IPAddress.Parse(pl.Ip), pl.Port));
                            }
                        }
        }
        default: //..
    }
}
@PROGRAMMATOR
@Awiion
Anyone?
ManuelDev вне форума Ответить с цитированием
Непрочитано 03.07.2018, 16:27   #4
Пользователь

По умолчанию Re: UDP3 answer

@PROGRAMMATOR Help
bmzproject вне форума Ответить с цитированием
Ответ


Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
 
Опции темы

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.

Быстрый переход

Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
[Point Blank] Some infos about UDP3? ManuelDev Point Blank (Piercing Blow) 2 26.06.2018 09:38
[Point Blank] UDP3 bc.log ManuelDev Point Blank (Piercing Blow) 1 27.05.2018 13:12
[Point Blank] Help me UDP3 i'm get value Opcode3 bmzproject Point Blank (Piercing Blow) 5 24.02.2018 18:12
[Piercing Blow] UDP3 Урон Boris2105 Point Blank (Piercing Blow) 12 25.08.2017 18:10
[Point Blank] What does that mean? (UDP3) TheBestGuy Point Blank (Piercing Blow) 6 10.05.2017 23:28


© 2007–2018 «Форум администраторов игровых серверов»
Защита сайта от DDoS атак — StormWall
Работает на Булке неизвестной версии с переводом от zCarot
Текущее время: 00:19. Часовой пояс GMT +3.

Вверх