Esempio n. 1
0
 private static void ChangeSettings(Client.GameClient client, GamePackets.Packet packet)
 {
     if (client.Entity != null)
     {
         client.Entity.Settings = new byte[packet.buffer.Length - 7];
         Buffer.BlockCopy(packet.buffer, 6, client.Entity.Settings, 0, packet.buffer.Length - 7);
     }
     client.Send(new GamePackets.Packet(GamePackets.Packet.PacketType.S2C_ChangeSettings, new byte[4]));
 }
Esempio n. 2
0
 public void Send(GamePackets.Packet packet)
 {
     packet.buffer[0] = Constants.packetStartsWith;
     packet.buffer[packet.buffer.Length - 1] = Constants.packetEndsWith;
     Socket.Send(packet.buffer);
     if (Program.CapturePackets)
     {
         Console.WriteLine("Captured a packet from Server (Game Server) Length: " + packet.buffer.Length + " Type: (" + packet.buffer[3] + "-" + packet.buffer[4] + "-" + packet.buffer[5] + ")");
     }
 }
Esempio n. 3
0
        private static void JoinToRoom(Client.GameClient client, GamePackets.Packet packet)
        {
            ushort Number   = BitConverter.ToUInt16(packet.buffer, 6);
            string Password = Encoding.ASCII.GetString(packet.buffer, 8, 10).Replace(Encoding.ASCII.GetString(new byte[] { 0x0 }), "");
            var    Room     = Kernel.Rooms.Where(i => i.Server == client.Account.Server && i.Channel == client.Entity.Channel && i.Number == (Number - 1)).FirstOrDefault();

            if (Room == null || client.Account.Server == null || client.Entity.Channel == 0)
            {
                return;
            }
            System.IO.MemoryStream memory = new System.IO.MemoryStream();
            System.IO.BinaryWriter writer = new System.IO.BinaryWriter(memory);

            if (Room.numberOfPlayers < Room.maxNumberOfPlayers)
            {
                if (Room.Password == Password)
                {
                    Room.Players.Add(client.Entity.UID, client);
                    writer.Write((uint)Enums.RoomAnswer.Success);
                    writer.Write(Number);
                    writer.Write(Room.maxNumberOfPlayers);
                    writer.Write(Room.MapID);
                    writer.Write(1u);
                    writer.Write((uint)Room.gameMode);
                    writer.Write((byte)0);
                    writer.Write((byte)1);
                    writer.Write((ushort)0);
                    writer.Write((uint)Room.objectiveType);
                    writer.Write((uint)Room.maxObjectiveCount);
                    writer.Write(0u);
                    writer.Write((uint)((uint)(Room.Status) - 1));
                }
                else
                {
                    writer.Write((uint)Enums.RoomAnswer.WrongPassword);
                    writer.Write(Number);
                }
            }
            else
            {
                writer.Write((uint)Enums.RoomAnswer.Full);
                writer.Write(Number);
            }
            memory.Position = 0;
            byte[] answer = new byte[memory.Length];
            memory.Read(answer, 0, answer.Length);
            writer.Close();
            memory.Close();
            var answerPacket = new GamePackets.Packet(GamePackets.Packet.PacketType.S2C_JoinRoom, answer);

            client.Send(answerPacket);
        }
Esempio n. 4
0
        private static void CreateRoom(Client.GameClient client, GamePackets.Packet packet)
        {
            if (client.Account.Server == null || client.Entity.Channel == 0)
            {
                return;
            }
            Room room = new Room()
            {
                Host    = client,
                Players = new Dictionary <uint, Client.GameClient>()
                {
                    { client.Entity.UID, client }
                },
                Channel            = client.Entity.Channel,
                Status             = Enums.RoomStatus.Waiting,
                maxNumberOfPlayers = packet.buffer[28],
                observersCount     = packet.buffer[30],
                Server             = client.Account.Server,
                VIP               = client.Entity.VIP,
                objectiveType     = (Enums.RoomObjType)packet.buffer[42],
                maxObjectiveCount = packet.buffer[46],
                NoFlash_Smoke     = packet.buffer[39] == 0 ? false : true,
                Name              = Encoding.ASCII.GetString(packet.buffer, 53, 80).Replace(Encoding.ASCII.GetString(new byte[] { 0x0 }), ""),
                Password          = Encoding.ASCII.GetString(packet.buffer, 6, 10).Replace(Encoding.ASCII.GetString(new byte[] { 0x0 }), ""),
                MapID             = BitConverter.ToUInt16(packet.buffer, 32),
                gameMode          = (Enums.GameMode)packet.buffer[34]
            };

            room.Number = GetRoomNumber(room);
            Kernel.Rooms.Add(room);
            byte[] buffer = new byte[268];
            buffer[0]   = 0x9C;
            buffer[1]   = 0xFF;
            buffer[2]   = 0xFF;
            buffer[3]   = 0xFF;
            buffer[266] = 0x90;
            client.Send(new GamePackets.Packet(GamePackets.Packet.PacketType.S2C_CreateRoom, buffer));
            AddRoomInLobby(room);
        }
Esempio n. 5
0
 private static void AutoJoinOptions(Client.GameClient client, GamePackets.Packet packet)
 {
     if (packet.buffer[22] != 1)//If not searching on the current channel
     {
         for (int s = 0; s < Program.Servers.ToArray().Length; s++)
         {
             for (int c = 0; c < 10; c++)
             {
                 var Rooms = Kernel.Rooms.Where(i => i.Server == Program.Servers.ToArray()[s] && (i.Channel == (ushort)(c + 1)) && !i.hasPassword && i.numberOfPlayers < i.Players.Count).ToArray();
                 Rooms = Rooms.Where(i => i.gameMode == (Enums.GameMode)BitConverter.ToUInt32(packet.buffer, 6)).ToArray();
                 if (BitConverter.ToUInt16(packet.buffer, 10) != ushort.MaxValue)
                 {
                     Rooms = Rooms.Where(i => i.MapID == BitConverter.ToUInt16(packet.buffer, 10)).ToArray();
                 }
                 Rooms = Rooms.Where(i => i.maxNumberOfPlayers >= packet.buffer[12]).ToArray();
                 if (packet.buffer[13] == 1)
                 {
                     Rooms = Rooms.Where(i => i.Status == Enums.RoomStatus.inGame).ToArray();
                 }
                 if (packet.buffer[13] == 2)
                 {
                     Rooms = Rooms.Where(i => i.Status == Enums.RoomStatus.Waiting).ToArray();
                 }
                 if (Rooms.FirstOrDefault() != null)
                 {
                     byte[] buffer = new byte[24];
                     Writer.Write(0xE0, 11 - 6, buffer);
                     Writer.Write(s, 14 - 6, buffer);
                     Writer.Write(c, 16 - 6, buffer);
                     Writer.Write(Rooms.FirstOrDefault().Number - 1, 18 - 6, buffer);
                     Writer.Write(2, 22 - 6, buffer);
                     Writer.Write(0x91, 26 - 6, buffer);
                     Writer.Write(0x54, 29 - 6, buffer);
                     client.Send(new GamePackets.Packet(GamePackets.Packet.PacketType.S2C_AutoJoin, buffer));
                 }
             }
         }
     }
     else
     {
         var Rooms = Kernel.Rooms.Where(i => i.Server == client.Account.Server && i.Channel == client.Entity.Channel && !i.hasPassword && i.numberOfPlayers < i.Players.Count).ToArray();
         Rooms = Rooms.Where(i => i.gameMode == (Enums.GameMode)BitConverter.ToUInt32(packet.buffer, 6)).ToArray();
         if (BitConverter.ToUInt16(packet.buffer, 10) != ushort.MaxValue)
         {
             Rooms = Rooms.Where(i => i.MapID == BitConverter.ToUInt16(packet.buffer, 10)).ToArray();
         }
         Rooms = Rooms.Where(i => i.maxNumberOfPlayers >= packet.buffer[12]).ToArray();
         if (packet.buffer[13] == 1)
         {
             Rooms = Rooms.Where(i => i.Status == Enums.RoomStatus.inGame).ToArray();
         }
         if (packet.buffer[13] == 2)
         {
             Rooms = Rooms.Where(i => i.Status == Enums.RoomStatus.Waiting).ToArray();
         }
         if (Rooms.FirstOrDefault() != null)
         {
             byte[] buffer = new byte[24];
             Writer.Write(0xE0, 11 - 6, buffer);
             Writer.Write(Array.IndexOf(Program.Servers.ToArray(), client.Account.Server), 14 - 6, buffer);
             Writer.Write(client.Entity.Channel - 1, 16 - 6, buffer);
             Writer.Write(Rooms.FirstOrDefault().Number - 1, 18 - 6, buffer);
             Writer.Write(2, 22 - 6, buffer);
             Writer.Write(0x91, 26 - 6, buffer);
             Writer.Write(0x54, 29 - 6, buffer);
             client.Send(new GamePackets.Packet(GamePackets.Packet.PacketType.S2C_AutoJoin, buffer));
         }
     }
 }
Esempio n. 6
0
        public static void Process(Client.GameClient client, GamePackets.Packet packet)
        {
            if (packet.CorrectPacket)
            {
                switch (packet.packetType)
                {
                case GamePackets.Packet.PacketType.C2S_AuthToChannelServer:
                    Database.AccountTable Account = null;
                    string Identifer = Encoding.ASCII.GetString(packet.buffer, 54, 31).Replace(Encoding.ASCII.GetString(new byte[] { 0x0 }), "");
                    if (Kernel.AwaitingPool.TryGetValue(Identifer, out Account))
                    {
                        client.Account = Account;
                        Kernel.AwaitingPool.Remove(Identifer);
                        Client.GameClient aClient = null;
                        if (Kernel.GamePool.TryGetValue(Account.EntityID, out aClient))
                        {
                            aClient.Disconnect();
                        }
                        Kernel.GamePool.Remove(Account.EntityID);
                        LoadEntity(client);
                        Kernel.GamePool.Add(Account.EntityID, client);
                        Console.WriteLine(client.Entity.Name + " has been logged on! (" + client.Account.Server.Name + ")");
                        Program.UpdateConsoleTitle();
                        SendCompleteLogin(client);
                        SendMyPlayerData(client);
                    }
                    break;

                case GamePackets.Packet.PacketType.C2S_GetChannels:
                    SendChannels(client);
                    break;

                case GamePackets.Packet.PacketType.C2S_ExitGameInfoInto:
                    SendExitInfoInto(client);
                    break;

                case GamePackets.Packet.PacketType.C2S_ConfirmBack:
                    var back = new GamePackets.Packet(GamePackets.Packet.PacketType.S2C_ConfirmBack, new byte[4] {
                        1, 0, 0, 0
                    });
                    client.Send(back);
                    break;

                case GamePackets.Packet.PacketType.C2S_ChannelJoin:
                    SendChannelJoin(client, packet.buffer[6]);
                    break;

                case GamePackets.Packet.PacketType.C2S_HeartBeat:
                    SendHeartBeat(client, BitConverter.ToUInt32(packet.buffer, 6));
                    break;

                case GamePackets.Packet.PacketType.C2S_ServerTime:
                    SendNewGUID(client);
                    break;

                case GamePackets.Packet.PacketType.C2S_GetPlayerStats:
                    SendPlayerStats(client, client);
                    break;

                case GamePackets.Packet.PacketType.S2C_GetAnotherPlayerStats:
                    SendPlayerStats(Kernel.GamePool.Values.Where(i => i.Entity != null && i.Entity.Name == Encoding.ASCII.GetString(packet.buffer, 6, 12)).FirstOrDefault(), client);
                    break;

                case GamePackets.Packet.PacketType.C2S_ChannelData:
                    client.Entity.Lobby = true;
                    SendChannelRooms(client);
                    SendPlayersOnChannel(client);
                    break;

                case GamePackets.Packet.PacketType.C2S_GetPlayersOnChannel:
                    SendPlayersOnChannel(client);
                    break;

                case GamePackets.Packet.PacketType.C2S_JoinToRoom:
                    client.Entity.Lobby = false;
                    JoinToRoom(client, packet);
                    break;

                case GamePackets.Packet.PacketType.C2S_CreateRoom:
                    CreateRoom(client, packet);
                    break;

                case GamePackets.Packet.PacketType.C2S_BackFromRoom:
                    BackFromRoom(client);
                    break;


                case GamePackets.Packet.PacketType.C2S_RequestExit:
                    SendExitInfo(client);
                    break;

                case GamePackets.Packet.PacketType.С2S_EnterToShootingRoom:
                    break;

                case GamePackets.Packet.PacketType.C2S_ChannelsUpdate:
                    SendChannels(client);
                    break;

                case GamePackets.Packet.PacketType.C2S_ExitFromChannelToChannelsList:
                    ExitFromChannel(client);
                    break;

                case GamePackets.Packet.PacketType.C2S_AutoJoin:
                    AutoJoinRoom(client);
                    break;

                case GamePackets.Packet.PacketType.C2S_AutoJoinOptions:
                    AutoJoinOptions(client, packet);
                    break;

                case GamePackets.Packet.PacketType.C2S_GetZP:
                    SendZP(client);
                    break;

                case GamePackets.Packet.PacketType.C2S_Mileage:
                    SendMileage(client);
                    break;

                case GamePackets.Packet.PacketType.C2S_StorageItems:
                    SendStorageItems(client);
                    break;

                case GamePackets.Packet.PacketType.C2S_FeverUpdate:
                    SendFeverStatus(client);
                    break;

                case GamePackets.Packet.PacketType.C2S_ChangeSettings:
                    ChangeSettings(client, packet);
                    break;

                case GamePackets.Packet.PacketType.C2S_FeverInfoUpdate:
                    SendFeverInfo(client);
                    break;

                case GamePackets.Packet.PacketType.Unknown:
                    if (Program.CaptureUnknownPackets)
                    {
                        Console.WriteLine("Unknown Packet! =>  (" + packet.buffer[3] + "-" + packet.buffer[4] + "-" + packet.buffer[5] + ")");
                    }
                    break;
                }
            }
            else
            {
                Console.WriteLine("Incorrent Packet Structure! =>  (" + packet.buffer[3] + "-" + packet.buffer[4] + "-" + packet.buffer[5] + ")");
            }
        }