예제 #1
0
        /// <summary>
        /// Sends a packet to the client.
        /// </summary>
        /// <param name="Packet">The packet to send.</param>
        public void Send(DataPacket Packet)
        {
            if (IsAIBot)
                return;

            // TODO: rewrite the sockets to actually handle this proper ...
            if (Packet.ReadString(Packet.BufferLength - 8, 8) == "TQClient") // this is actually never used, not removing it though just to be sure
            {
                using (var sendPacket = new DataPacket(Packet))
                {
                    sendPacket.WriteBytes(Packet.Copy(), 0);
                    sendPacket.WriteString("TQServer", sendPacket.BufferLength - 8);
                    NetworkClient.Send(sendPacket);
                }
            }
            else
            {
                using (var sendPacket = new DataPacket(new byte[Packet.BufferLength + 8]))
                {
                    sendPacket.WriteBytes(Packet.Copy(), 0);
                    sendPacket.WriteString("TQServer", sendPacket.BufferLength - 8);
                    NetworkClient.Send(sendPacket);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Handles all packets received by the game auth server.
        /// </summary>
        /// <param name="client">The socket client.</param>
        /// <param name="Packet">The packet.</param>
        /// <returns>ALWAYS returns false.</returns>
        private static bool HandlePacket(SocketClient client, DataPacket Packet)
        {
            if (Packet.PacketID == 9001)
            {
                if (Packet.ReadString(4, 16) == Program.Config.ReadString("ServerPassword"))
                {
                    string Account = Packet.ReadString(20, 16);
                    int DatabaseUID = Packet.ReadInt32(36);
                    if (DatabaseUID == 0)
                        return false;
                    uint EntityUID = Packet.ReadUInt32(40);
                    if (EntityUID == 0)
                        return false;

                    if (Core.Kernel.Clients.Contains(EntityUID))
                    {
                        UIDCollection.TryRemove(EntityUID);
                        return false;
                    }

                    if (UIDCollection.Contains(EntityUID))
                    {
                        int secondkey;
                        if (UIDCollection.TryGetSecondKey(EntityUID, out secondkey))
                        {
                            if (DatabaseUID == secondkey)
                                UIDCollection.TryRemove(EntityUID);
                        }
                        return false;
                    }

                    if (UIDCollection.Contains(DatabaseUID))
                    {
                        uint firstkey;
                        if (UIDCollection.TryGetFirstKey(DatabaseUID, out firstkey))
                        {
                            UIDCollection.TryRemove(DatabaseUID);
                        }
                    }

                    UIDCollection.TryAdd(EntityUID, DatabaseUID, DateTime.Now.AddMinutes(10));
                    //	return false;
                }
            }
            return false;
        }