Esempio n. 1
0
        public static Account GetAccount(SOEClient client)
        {
            if (Client2Account.ContainsKey(client))
            {
                return(Client2Account[client]);
            }

            return(null);
        }
Esempio n. 2
0
 public static void OnClientDisconnect(SOEClient client)
 {
     // Does this client have an account?
     if (Client2Account.ContainsKey(client))
     {
         // Log them out!
         Logout(GetAccount(client));
     }
 }
Esempio n. 3
0
        public static void SendLoginResponse(SOEClient client, bool success)
        {
            // Login Reply
            SOEWriter writer = new SOEWriter((ushort)LoginMessages.LoginResponse, true);

            // Success?
            writer.AddBoolean(success);

            // Send the reply!
            SOEMessage reply = writer.GetFinalSOEMessage(client);

            client.SendMessage(reply);
        }
Esempio n. 4
0
        public SOEMessage GetFinalSOEMessage(SOEClient client)
        {
            // Are we a packet?
            if (!IsMessage)
            {
                // Yes, and there really isn't a nice way to deal with this..
                client.Server.Log("[ERROR] Tried Calling 'GetFinalSOEMessage' on written SOEPacket. Returning null.");

                // Welp, goodbye world! :'(
                return(null);
            }

            // Make our message
            SOEMessage message = new SOEMessage(OpCode, GetRaw());

            // Does this message have to be fragmented?
            if (Data.Count > client.GetBufferSize())
            {
                // Setup a reader and keep track of our size
                SOEReader reader = new SOEReader(GetRaw());
                int       size   = message.GetLength();

                // While there are fragments to be added..
                while (size > 0)
                {
                    // Store the next fragment
                    byte[] raw;

                    // Is this fragment going to be smaller than the buffer size?
                    if (size < client.GetBufferSize())
                    {
                        raw  = reader.ReadBytes(size);
                        size = 0;
                    }
                    else
                    {
                        raw   = reader.ReadBytes((int)client.GetBufferSize());
                        size -= (int)client.GetBufferSize();
                    }

                    // Add the finalized fragment
                    message.AddFragment(raw);
                }
            }

            // Return the message we made
            return(message);
        }
Esempio n. 5
0
        public static void AddAccount(SOEClient owner, Account account)
        {
            // Are they already logged in?
            if (ID2Account.ContainsKey(account.ID))
            {
                // Uh oh! Log the old one out..
                Log.Warn("A user has logged into an account that is already in use! Disconnecting old client!");
                ID2Client[account.ID].Disconnect((ushort)SOEDisconnectReasons.NewConnection);
            }

            // Log
            Log.InfoFormat("Account '{0}' has successfully logged in!", account.Username);

            // Add the new one!
            ID2Client.Add(account.ID, owner);
            Client2Account.Add(owner, account);
            ID2Account.Add(account.ID, account);
            Username2Account.Add(account.Username, account);
        }
Esempio n. 6
0
        public static void HandleCommand(SOEClient sender, byte[] command)
        {
            // Setup a reader
            SOEReader reader = new SOEReader(command);

            // Get the command code
            ushort commandOpCode = reader.ReadHostUInt16();

            // Handle
            switch (commandOpCode)
            {
            case ((ushort)ClientLogCommands.Log):
                ClientLogManager.ReceiveLog(sender, command);
                break;

            default:
                Log.DebugFormat("Received unknown command! {0:X2}", commandOpCode);
                break;
            }
        }
Esempio n. 7
0
        public static void HandleEnqueueCommand(SOEClient sender, SOEMessage message)
        {
            // Is this client even authed?
            if (AccountManager.GetAccount(sender) == null)
            {
                Log.ErrorFormat("Unauthorized client tried enqueing command!");
                sender.Disconnect((ushort)SOEDisconnectReasons.Terminated);
                return;
            }

            // Setup a reader
            SOEReader reader = new SOEReader(message);

            // Get the length
            bool hasLength = reader.ReadBoolean(); // assuming this even is "has length" or just a random 01

            byte[] command = hasLength ? reader.ReadBlob() : reader.ReadToEnd();

            // Handle command!
            HandleCommand(sender, command);
        }
Esempio n. 8
0
 public static bool IsAuthorized(SOEClient client)
 {
     return(Client2Account.ContainsKey(client));
 }
Esempio n. 9
0
        public SOEPacket GetFinalSOEPacket(SOEClient client, bool compressed, bool appendCRC)
        {
            // Data
            byte[] originalPacket = GetRaw();
            byte[] rawData        = new byte[Data.Count - 2];
            byte[] newPacket;

            // Fail-safe
            ushort originalOpCode = 0;

            // Are we a message?
            if (IsMessage)
            {
                // Yes, so we'll try make a data packet.
                // Can we fit into one packet?
                SOEMessage message = GetFinalSOEMessage(client);
                if (message.IsFragmented)
                {
                    // We're gonna have to fragment, so we can't handle this gracefully...
                    client.Server.Log("[ERROR] Tried to handle 'GetFinalSOEPacket' call on written SOEMessage gracefully but failed due to fragmentation. Returning null.");
                    client.Server.Log("[INFO] Call 'GetFinalSOEMessage' as it deals with fragmentation!");

                    // Welp, goodbye world! :'(
                    return(null);
                }

                // Make the new packet
                Data = new List <byte>();
                AddUInt16(client.GetNextSequenceNumber());
                AddBytes(originalPacket);

                // Set our raw data
                rawData = GetRaw();

                // Change our OpCode so that we're a reliable data packet
                originalOpCode = OpCode;
                OpCode         = (ushort)SOEOPCodes.RELIABLE_DATA;

                // Because we're reliable data, take compression into consideration and append a CRC
                compressed = true;
                appendCRC  = true;

                // We handled it gracefully! :)
                client.Server.Log("[INFO] Handled 'GetFinalSOEPacket' call on written SOEMessage gracefully.");
            }
            else
            {
                // Get just the data for this packet. (Remove the OP Code)
                byte[] completeRawData = GetRaw();
                for (int i = 2; i < completeRawData.Length; i++)
                {
                    rawData[i - 2] = completeRawData[i];
                }
            }

            // Start a new packet
            Data = new List <byte>();
            AddUInt16(OpCode);

            // Are we compressable?
            if (client.IsCompressable())
            {
                if (compressed)
                {
                    AddBoolean(rawData.Length > 100);
                    if (rawData.Length > 100)
                    {
                        rawData = client.Compress(rawData);
                    }
                }
            }

            // Are we encrypted?
            if (client.IsEncrypted())
            {
                //  Encrypt the SOE Packet
                rawData = client.Encrypt(rawData);
            }

            // Add the raw data
            AddBytes(rawData);

            // Appended CRC32?
            if (appendCRC)
            {
                AddBytes(client.GetAppendedCRC32(GetRaw()));
            }

            // Set our new packet
            newPacket = GetRaw();

            // Get our old message before compression/encryption
            Data = new List <byte>(originalPacket);

            // If we are a message, set our OpCode back
            if (IsMessage)
            {
                // Set our OpCode back too..
                OpCode = originalOpCode;
            }

            // Return the compressed/encrypted packet
            return(new SOEPacket(OpCode, newPacket));
        }
Esempio n. 10
0
 public LoginRequest(SOEClient client, string token, string version)
 {
     Client  = client;
     Token   = token;
     Version = version;
 }