Рейтинг темы:
  • 0 Голос(ов) - 0 в среднем
  • 1
  • 2
  • 3
  • 4
  • 5
UDP 2 Проблема
#1
все работает.. респаунит.
но клиенты не видеть друг с другом

[Изображение: CMnuvZx.jpg]



Код:
namespace Battle
{
    class NetworkS
    {
        private static NetworkS _instance;
        private static UdpClient _client;
       // private static List<IPAddress> players;

        public static NetworkS Load()
        {
            _instance = new NetworkS();
            return _instance;
        }

        public NetworkS()
        {
            UdpClient udp = new UdpClient(40000);
            Logger.Info("[Network] Battle Server Host {0}", IPAddress.Any);
            _client = default(UdpClient);
            while(true)
            {
                //Thread.Sleep(100);
                if (udp != null)
                {
                    if (udp.Available > 0) //TODO:: Выбивает исключение, нужно проверять как то по другому....
                    {
                        _client = udp;

                        _client.BeginReceive(new AsyncCallback(BeginReceive), null);
                    }
                }
            }
        }
        private static void BeginReceive(IAsyncResult result)
        {
            IPEndPoint remoteEP = null;
            MemoryStream stream2;
            MemoryStream stream = new MemoryStream();
            byte[] buffer = _client.EndReceive(result, ref remoteEP);
            byte[] bytee = new byte[] { 0x04, 0xff, 0x91, 0xed, 0x0b, 0x41, 0x01, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x0a, 0x00, 0x00, 0xe6, 0xce, 0xc1, 0x44, 0x9a, 0xbe, 0xef, 0x55, 0xb3, 0x43, 0x05, 0x00, 0xf0, 0x1f, 0x09, 0x0a, 0x00, 0x06, 0x00, 0x00, 0x09, 0x0b, 0x00, 0x06, 0x00, 0x00, 0x09, 0x0c, 0x00, 0x06, 0x00, 0x00, 0x09, 0x0d, 0x00, 0x06, 0x00, 0x00, 0x09, 0x0e, 0x00, 0x06, 0x00, 0x00 };
            byte[] bytee2 = new byte[] { 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            switch (buffer[0])
            {
               // case 4:
                case 1:
                    {
                        Room room = new Room();
                        room.setId(buffer[1]);
                        String ip = buffer[2].ToString() + "." + buffer[3].ToString() + "." + buffer[4].ToString() + "." + buffer[5].ToString();
                        room.inetAddress = IPAddress.Parse(ip);
                        RoomManager.rooms.Add(RoomManager.rooms.Count, room);
                        Logger.Info("New room");
                        Logger.Info("{0}", RoomManager.rooms.Count);
                        break;
                    }
                case 2:
                    {

                        String ip = buffer[2].ToString() + "." + buffer[3].ToString() + "." + buffer[4].ToString() + "." + buffer[5].ToString();
                        Logger.Info("New player {0}", ip);
                        Room room = RoomManager.rooms[buffer[1]];
                        if (room != null)
                        {
                            if (!room.getPlayers().Equals(ip))
                            {
                                room.getPlayers().Add(room.getPlayers().Count, IPAddress.Parse(ip));
                            }
                        }
                        break;
                    }
                case 17:
                    RoomManager.removeRoom(buffer[1]);
                    Logger.Info("Room " + buffer[1] + " remove.");
                    return;

                case 18:
                    String NewIP = buffer[2].ToString() + "." + buffer[3].ToString() + "." + buffer[4].ToString() + "." + buffer[5].ToString();
                    Room NewRoom = RoomManager.rooms[buffer[1]];
                    if (NewRoom != null)
                    {
                        if (!NewRoom.getPlayers().Equals(NewIP))
                        {
                            NewRoom.getPlayers().Add(NewRoom.getPlayers().Count, IPAddress.Parse(NewIP));
                        }
                    }
                    
                    return;

                case 65:
                    {
                        stream2 = new MemoryStream();
                        stream2.WriteByte(66);
                        stream2.WriteByte(0);
                        stream2.Write(new byte[5], 0, 5);
                        stream2.WriteByte(0x0b);
                        stream2.Write(new byte[3], 0, 3);
                        // stream2.Write(buffer, 1, buffer.Length - 1);
                        _client.Send(stream2.ToArray(), stream2.ToArray().Length, remoteEP);
                        break;
                    }
                case 67:
                    new Player()._address = remoteEP.Address;
                    Logger.Info("Player remove");
                    //Program.getRoomManager().RemovePlayerInRoom(remoteEP.Address);
                    return;
                case 131:
                case 132:
                case 84:
                case 97:
                case 4:
                case 3:
                    {
                        Room room = RoomManager.getRoom(remoteEP.Address);
                        if (room.inetAddress.Equals(remoteEP.Address))
                        {
                            foreach (IPAddress player in room.getPlayers().Values)
                            {
                                stream2 = new MemoryStream();
                                stream2.WriteByte(buffer[0]);
                                // stream2.WriteByte(0);
                                stream2.Write(buffer, 1, buffer.Length - 1);
                                _client.Send(stream2.ToArray(), stream2.ToArray().Length, player.ToString(), 29890);
                            }
                        }
                        else
                        {
                            stream2 = new MemoryStream();
                            stream2.WriteByte(buffer[0]);
                            //stream2.WriteByte(0);
                            stream2.Write(buffer, 1, buffer.Length - 1);
                            _client.Send(stream2.ToArray(), stream2.ToArray().Length, room.inetAddress.ToString(), 29890);
                        }
                        /* stream2 = new MemoryStream();
                         stream2.WriteByte(4);
                         stream2.WriteByte(buffer[1]);
                         stream2.Write(buffer, 2, buffer.Length - 2);
                         _client.Send(stream2.ToArray(), stream2.ToArray().Length, "192.168.0.101", 29890);*/
                        break;
                    }
                default:
                    {
                        Logger.Info("New packet {0}",buffer[0]);
                        string hex = BitConverter.ToString(buffer).Replace("-", " ");
                        Logger.Info("{0}", hex.ToString());
                        break;
                    }
            }
        }
    }
}


SM_BATTLE_PRESTARTBATTLE

Код:
internal class SM_BATTLE_PRESTARTBATTLE : SendBaseGamePacket
    {
        private Room _room;

        private Account _player;

        public SM_BATTLE_PRESTARTBATTLE(Room room, Account p)
        {
            makeme();
            _player = p;
            _room = room;
        }

        protected internal override void write()
        {
            writeH(3349);
            writeD(_room.isBattleInt());
            writeD(_player.getSlot());
            writeC(2);
            writeB(_room.getLeader().publicAdddress());
            writeH(29890);
            writeB(_room.getLeader().publicAdddress());
            writeH(29890);
            writeC(0);
            writeB(_player.publicAdddress());
            writeH(29890);
            writeB(_player.publicAdddress());
            writeH(29890);
            writeC(0);
            writeB(IPAddress.Parse("104.199.104.25").GetAddressBytes());
            writeU(40000);
            _room.getSlot(_player.getSlot()).state = SLOT_STATE.SLOT_STATE_BATTLE_READY;
            writeB(new byte[] { 0x40, 0x9c });
            writeB(new byte[] {
                (byte) 0x91, 0x00, 0x00, 0x00,
                (byte) 0x47, 0x06, 0x00, 0x00
            });

            writeC(0);

            writeB(new byte[] {
                0x0a, 0x22, 0x00, 0x01, 0x10, 0x03, 0x1e, 0x05, 0x06, 0x07, 0x04, 0x09, 0x16, 0x0b, 0x1b, 0x08, 0x0e, 0x0f, 0x02, 0x11, 0x12, 0x21, 0x14, 0x15, 0x13, 0x17, 0x18, 0x19, 0x1a, 0x0c, 0x1c, 0x1d, 0x0d, 0x1f, 0x20
            });
        }
    }
}
Ответ
#2
@PROGRAMMATOR help me, please.
Ответ
#3
:confused:
Ответ
#4
я конечно не занимался PB, но если учесть что пакеты правильны то возможно нет боардкаста между соединениями. Пакеты информации об игроке посылаются другим соединениям?
PS. Впервые вижу чтоб на асинхронном сервере столько жрало времени ЦП
Ответ
#5
zOne62 Написал:все работает.. респаунит.
но клиенты не видеть друг с другом

[Изображение: CMnuvZx.jpg]



Код:
namespace Battle
{
    class NetworkS
    {
        private static NetworkS _instance;
        private static UdpClient _client;
       // private static List<IPAddress> players;

        public static NetworkS Load()
        {
            _instance = new NetworkS();
            return _instance;
        }

        public NetworkS()
        {
            UdpClient udp = new UdpClient(40000);
            Logger.Info("[Network] Battle Server Host {0}", IPAddress.Any);
            _client = default(UdpClient);
            while(true)
            {
                //Thread.Sleep(100);
                if (udp != null)
                {
                    if (udp.Available > 0) //TODO:: Выбивает исключение, нужно проверять как то по другому....
                    {
                        _client = udp;

                        _client.BeginReceive(new AsyncCallback(BeginReceive), null);
                    }
                }
            }
        }
        private static void BeginReceive(IAsyncResult result)
        {
            IPEndPoint remoteEP = null;
            MemoryStream stream2;
            MemoryStream stream = new MemoryStream();
            byte[] buffer = _client.EndReceive(result, ref remoteEP);
            byte[] bytee = new byte[] { 0x04, 0xff, 0x91, 0xed, 0x0b, 0x41, 0x01, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x0a, 0x00, 0x00, 0xe6, 0xce, 0xc1, 0x44, 0x9a, 0xbe, 0xef, 0x55, 0xb3, 0x43, 0x05, 0x00, 0xf0, 0x1f, 0x09, 0x0a, 0x00, 0x06, 0x00, 0x00, 0x09, 0x0b, 0x00, 0x06, 0x00, 0x00, 0x09, 0x0c, 0x00, 0x06, 0x00, 0x00, 0x09, 0x0d, 0x00, 0x06, 0x00, 0x00, 0x09, 0x0e, 0x00, 0x06, 0x00, 0x00 };
            byte[] bytee2 = new byte[] { 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            switch (buffer[0])
            {
               // case 4:
                case 1:
                    {
                        Room room = new Room();
                        room.setId(buffer[1]);
                        String ip = buffer[2].ToString() + "." + buffer[3].ToString() + "." + buffer[4].ToString() + "." + buffer[5].ToString();
                        room.inetAddress = IPAddress.Parse(ip);
                        RoomManager.rooms.Add(RoomManager.rooms.Count, room);
                        Logger.Info("New room");
                        Logger.Info("{0}", RoomManager.rooms.Count);
                        break;
                    }
                case 2:
                    {

                        String ip = buffer[2].ToString() + "." + buffer[3].ToString() + "." + buffer[4].ToString() + "." + buffer[5].ToString();
                        Logger.Info("New player {0}", ip);
                        Room room = RoomManager.rooms[buffer[1]];
                        if (room != null)
                        {
                            if (!room.getPlayers().Equals(ip))
                            {
                                room.getPlayers().Add(room.getPlayers().Count, IPAddress.Parse(ip));
                            }
                        }
                        break;
                    }
                case 17:
                    RoomManager.removeRoom(buffer[1]);
                    Logger.Info("Room " + buffer[1] + " remove.");
                    return;

                case 18:
                    String NewIP = buffer[2].ToString() + "." + buffer[3].ToString() + "." + buffer[4].ToString() + "." + buffer[5].ToString();
                    Room NewRoom = RoomManager.rooms[buffer[1]];
                    if (NewRoom != null)
                    {
                        if (!NewRoom.getPlayers().Equals(NewIP))
                        {
                            NewRoom.getPlayers().Add(NewRoom.getPlayers().Count, IPAddress.Parse(NewIP));
                        }
                    }
                    
                    return;

                case 65:
                    {
                        stream2 = new MemoryStream();
                        stream2.WriteByte(66);
                        stream2.WriteByte(0);
                        stream2.Write(new byte[5], 0, 5);
                        stream2.WriteByte(0x0b);
                        stream2.Write(new byte[3], 0, 3);
                        // stream2.Write(buffer, 1, buffer.Length - 1);
                        _client.Send(stream2.ToArray(), stream2.ToArray().Length, remoteEP);
                        break;
                    }
                case 67:
                    new Player()._address = remoteEP.Address;
                    Logger.Info("Player remove");
                    //Program.getRoomManager().RemovePlayerInRoom(remoteEP.Address);
                    return;
                case 131:
                case 132:
                case 84:
                case 97:
                case 4:
                case 3:
                    {
                        Room room = RoomManager.getRoom(remoteEP.Address);
                        if (room.inetAddress.Equals(remoteEP.Address))
                        {
                            foreach (IPAddress player in room.getPlayers().Values)
                            {
                                stream2 = new MemoryStream();
                                stream2.WriteByte(buffer[0]);
                                // stream2.WriteByte(0);
                                stream2.Write(buffer, 1, buffer.Length - 1);
                                _client.Send(stream2.ToArray(), stream2.ToArray().Length, player.ToString(), 29890);
                            }
                        }
                        else
                        {
                            stream2 = new MemoryStream();
                            stream2.WriteByte(buffer[0]);
                            //stream2.WriteByte(0);
                            stream2.Write(buffer, 1, buffer.Length - 1);
                            _client.Send(stream2.ToArray(), stream2.ToArray().Length, room.inetAddress.ToString(), 29890);
                        }
                        /* stream2 = new MemoryStream();
                         stream2.WriteByte(4);
                         stream2.WriteByte(buffer[1]);
                         stream2.Write(buffer, 2, buffer.Length - 2);
                         _client.Send(stream2.ToArray(), stream2.ToArray().Length, "192.168.0.101", 29890);*/
                        break;
                    }
                default:
                    {
                        Logger.Info("New packet {0}",buffer[0]);
                        string hex = BitConverter.ToString(buffer).Replace("-", " ");
                        Logger.Info("{0}", hex.ToString());
                        break;
                    }
            }
        }
    }
}

Ох зря вы его скопировали с других пиратов, легче переписать с 0 UDP сервер...
Ах и да ассинхронка неправильная...
Ответ
#6
DarkSkeleton12,
Там все не правильно, это костыль костылей.
__________________
zOne62,
Link
Разработка Emu: PiercingBlow 90%, APB Reloaded 100%.
Самый действенный инструмент для самообучения - грабли.
Ответ
#7
Awiion Написал:DarkSkeleton12,
Там все не правильно, это костыль костылей.

Куда же без них то в наше время то Big Grin
Ответ
#8
Надо советовать...
Легко стать ученым, трудно быть человеком...
Ответ
#9
zOne62,

1. Get Ip, Port
SM_BATTLE_PRESTARTBATTLE
- Ip
- Port

2. Wireshark
Setting filter UDP

3. Crypts and decrypt
Link

4. Udp Created
Server Link
Protocol Link
Разработка Emu: PiercingBlow 90%, APB Reloaded 100%.
Самый действенный инструмент для самообучения - грабли.
Ответ


Возможно похожие темы ...
Тема Автор Ответы Просмотры Последний пост
  Кто-нибудь знает, в чем проблема не появления бота Point Blank v3 16 ekobaff 1 739 09-14-2023, 11:29 AM
Последний пост: empireb
  проблема преобразования i3TexTimage tga tesla123 0 2,510 10-25-2019, 08:41 PM
Последний пост: tesla123
  проблема с файлом AngryKitten 25 6,850 06-18-2018, 11:42 AM
Последний пост: PROGRAMMATOR
  [Error PXSD] В чем проблема? немогу понять. Codex1to 0 1,817 12-17-2017, 07:49 PM
Последний пост: Codex1to
  Проблема в пакете не знаю что делать(((( slawa560 4 2,214 08-07-2017, 01:03 PM
Последний пост: Awiion
  какая проблема ? XRoro 4 1,911 10-30-2016, 04:10 PM
Последний пост: XRoro

Перейти к форуму:


Пользователи, просматривающие эту тему: 1 Гость(ей)