Esempio n. 1
0
        /// <summary>
        /// 33 - "@a"
        /// </summary>
        private void SendMsg()
        {
            uint   buddyID = Request.PopWireduint();
            string sText   = Request.PopFixedString();

            // Buddy in list?
            if (mSession.GetMessenger().GetBuddy(buddyID) != null)
            {
                // Buddy online?
                GameClient buddyClient = IonEnvironment.GetHabboHotel().GetClients().GetClientOfHabbo(buddyID);
                if (buddyClient == null)
                {
                    Response.Initialize(ResponseOpcodes.InstantMessageError); // Opcode
                    Response.AppendInt32(5);                                  // Error code
                    Response.AppendUInt32(mSession.GetHabbo().ID);
                    SendResponse();
                }
                else
                {
                    ServerMessage notify = new ServerMessage(ResponseOpcodes.NewConsole);
                    notify.AppendUInt32(mSession.GetHabbo().ID);
                    notify.AppendString(sText);
                    buddyClient.GetConnection().SendMessage(notify);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Handles a given amount of data in a given byte array, by attempting to parse messages from the received data and process them in the message handler.
        /// </summary>
        /// <param name="Data">The byte array with the data to process.</param>
        /// <param name="numBytesToProcess">The actual amount of bytes in the byte array to process.</param>
        public void HandleConnectionData(ref byte[] data)
        {
            // Gameclient protocol or policyrequest?
            if (data[0] != 64)
            {
                IonEnvironment.GetLog().WriteInformation("Client " + mID + " sent non-gameclient message: " + IonEnvironment.GetDefaultTextEncoding().GetString(data));

                string xmlPolicy =
                    "<?xml version=\"1.0\"?>\r\n" +
                    "<!DOCTYPE cross-domain-policy SYSTEM \"/xml/dtds/cross-domain-policy.dtd\">\r\n" +
                    "<cross-domain-policy>\r\n" +
                    "<allow-access-from domain=\"*\" to-ports=\"1-31111\" />\r\n" +
                    "</cross-domain-policy>\x0";

                IonEnvironment.GetLog().WriteInformation("Client " + mID + ": sending XML cross domain policy file: " + xmlPolicy);
                mConnection.SendData(xmlPolicy);

                mMessageHandler.GetResponse().Initialize(ResponseOpcodes.SecretKey); // "@A"
                mMessageHandler.GetResponse().Append("ION/Deltar");
                mMessageHandler.SendResponse();
            }
            else
            {
                int pos = 0;
                while (pos < data.Length)
                {
                    try
                    {
                        // Total length of message (without this): 3 Base64 bytes
                        int messageLength = Base64Encoding.DecodeInt32(new byte[] { data[pos++], data[pos++], data[pos++] });

                        // ID of message: 2 Base64 bytes
                        uint messageID = Base64Encoding.DecodeUInt32(new byte[] { data[pos++], data[pos++] });

                        // Data of message: (messageLength - 2) bytes
                        byte[] Content = new byte[messageLength - 2];
                        for (int i = 0; i < Content.Length; i++)
                        {
                            Content[i] = data[pos++];
                        }

                        // Create message object
                        ClientMessage message = new ClientMessage(messageID, Content);

                        // Handle message object
                        mMessageHandler.HandleRequest(message);
                    }
                    catch (IndexOutOfRangeException) // Bad formatting!
                    {
                        IonEnvironment.GetHabboHotel().GetClients().StopClient(mID);
                    }
                    catch (Exception ex)
                    {
                        IonEnvironment.GetLog().WriteUnhandledExceptionError("GameClient.HandleConnectionData", ex);
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Attempts to save the Habbo DataObject of this session to the Database.
        /// </summary>
        public bool SaveUserObject()
        {
            if (mHabbo != null)
            {
                return(IonEnvironment.GetHabboHotel().GetHabbos().UpdateHabbo(mHabbo));
            }

            return(false);
        }
Esempio n. 4
0
        /// <summary>
        /// Handles a newly created IonTcpConnection and performs some checks, before adding it to the connection collection and starting the client session.
        /// </summary>
        /// <param name="connection">The IonTcpConnection instance representing the new connection to handle.</param>
        public void HandleNewConnection(IonTcpConnection connection)
        {
            // TODO: check max simultaneous connections
            // TODO: check max simultaneous connections per IP
            // TODO: check project specific actions

            // INFO: client ID = connection ID, client ID = session ID
            // Add connection to collection
            mConnections.Add(connection.ID, connection);

            // Create session for new client
            IonEnvironment.GetHabboHotel().GetClients().StartClient(connection.ID);
        }
Esempio n. 5
0
        /// <summary>
        /// 370 - "Er"
        /// </summary>
        private void GetAchievements()
        {
            // Get achievements from Database
            List <string> achievements = IonEnvironment.GetHabboHotel().GetAchievements().GetAchievements(mSession.GetHabbo().ID);

            // Build response
            Response.Initialize(ResponseOpcodes.Achievements); // "Ce"
            Response.AppendInt32(achievements.Count);
            foreach (string achievement in achievements)
            {
                Response.AppendString(achievement);
            }
            SendResponse();
        }
Esempio n. 6
0
        /// <summary>
        /// Attempts to reload the Habbo DataObject of this session from the Database. If no DataObject is found anymore, the old one is kept.
        /// </summary>
        public bool ReloadUserObject()
        {
            if (mHabbo != null)
            {
                Habbo newObject = IonEnvironment.GetHabboHotel().GetHabbos().GetHabbo(mHabbo.ID);
                if (newObject != null)
                {
                    mHabbo = newObject;
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 7
0
        public Habbo Login(string sTicket)
        {
            // Do not use HabboManager.GetHabbo(string) here, as caching is planned to be implemented there
            Habbo habbo = new Habbo();

            if (!habbo.LoadBySsoTicket(IonEnvironment.GetDatabase(), sTicket))
            {
                throw new IncorrectLoginException("login incorrect: Wrong ticket");
            }
            else
            {
                // Drop old client (if logged in via other connection)
                IonEnvironment.GetHabboHotel().GetClients().KillClientOfHabbo(habbo.ID);

                return(habbo);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Tries to login this client on a Habbo account with a given username and password.
        /// </summary>
        /// <param name="sUsername">The username of the Habbo to attempt to login on.</param>
        /// <param name="sPassword">The login password of the Habbo username. Case sensitive.</param>
        public void Login(string sUsername, string sPassword)
        {
            try
            {
                // Try to login
                mHabbo = IonEnvironment.GetHabboHotel().GetAuthenticator().Login(sUsername, sPassword);

                // Authenticator has forced unique login now
                this.CompleteLogin();
            }
            catch (IncorrectLoginException exLogin)
            {
                SendClientError(exLogin.Message);
            }
            catch (ModerationBanException exBan)
            {
                SendBanMessage(exBan.Message);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 102 = "A?"
        /// </summary>
        private void GetCatalogPage()
        {
            uint pageID = Request.PopWireduint();

            Response.Initialize(ResponseOpcodes.CatalogPage);
            CatalogPage page = IonEnvironment.GetHabboHotel().GetCatalog().GetPage(pageID);

            if (page != null)
            {
                Response.AppendObject(page);

                List <CatalogProduct> products = IonEnvironment.GetHabboHotel().GetCatalog().GetProducts(pageID);
                foreach (CatalogProduct product in products)
                {
                    Response.AppendObject(product);
                }
            }
            SendResponse();
        }
Esempio n. 10
0
        public Habbo GetHabbo(uint ID)
        {
            // Prefer active client over Database
            GameClient client = IonEnvironment.GetHabboHotel().GetClients().GetClientOfHabbo(ID);

            if (client != null)
            {
                return(client.GetHabbo());
            }
            else
            {
                Habbo habbo = new Habbo();
                if (habbo.LoadByID(IonEnvironment.GetDatabase(), ID))
                {
                    return(habbo);
                }
            }

            return(null);
        }
Esempio n. 11
0
        public Habbo Login(string sUsername, string sPassword)
        {
            // Do not use HabboManager.GetHabbo(string) here, as caching is planned to be implemented there
            Habbo habbo = new Habbo();

            if (habbo.LoadByUsername(IonEnvironment.GetDatabase(), sUsername) == false)
            {
                throw new IncorrectLoginException("login incorrect: Wrong username");
            }

            if (habbo.Password != sPassword)
            {
                throw new IncorrectLoginException("login incorrect: Wrong password");
            }

            // Drop old client (if logged in via other connection)
            IonEnvironment.GetHabboHotel().GetClients().KillClientOfHabbo(habbo.ID);

            return(habbo);
        }
Esempio n. 12
0
        /// <summary>
        /// 101 - "Ae"
        /// </summary>
        private void GetCatalogIndex()
        {
            Response.Initialize(ResponseOpcodes.CatalogIndex);

            // Add all visible pages to the index response
            List <CatalogPage> pages = IonEnvironment.GetHabboHotel().GetCatalog().GetPages();

            foreach (CatalogPage page in pages)
            {
                Response.AppendBoolean(page.Visible);
                Response.AppendInt32((int)page.IconColor);
                Response.AppendInt32((int)page.IconImage);
                Response.AppendUInt32(page.ID);
                Response.AppendString(page.Name);
                Response.AppendBoolean(page.ComingSoon);
                Response.AppendUInt32(page.TreeID);
            }

            SendResponse();
        }
Esempio n. 13
0
        /// <summary>
        /// 41 - "@i"
        /// </summary>
        private void HabboSearch()
        {
            GetCatalogIndex();
            return;

            // Parse search criteria
            string sCriteria = Request.PopFixedString();

            sCriteria = sCriteria.Replace("%", "");

            // Query Habbos with names similar to criteria
            List <MessengerBuddy> matches = IonEnvironment.GetHabboHotel().GetMessenger().SearchHabbos(sCriteria);

            // Build response
            Response.Initialize(ResponseOpcodes.HabboSearchResult);
            Response.AppendInt32(matches.Count);
            foreach (MessengerBuddy match in matches)
            {
                //...
            }
            SendResponse();
        }
Esempio n. 14
0
        /// <summary>
        /// 34 - "@b"
        /// </summary>
        private void SendRoomInvite()
        {
            // TODO: check if this session is in room

            // Determine how many receivers
            int amount = Request.PopWiredInt32();
            List <GameClient> receivers = new List <GameClient>(amount);

            // Get receivers
            for (int i = 0; i < amount; i++)
            {
                // User in buddy list?
                uint buddyID = Request.PopWireduint();
                if (mSession.GetMessenger().GetBuddy(buddyID) != null)
                {
                    // User online?
                    GameClient buddyClient = IonEnvironment.GetHabboHotel().GetClients().GetClientOfHabbo(buddyID);
                    if (buddyClient != null)
                    {
                        receivers.Add(buddyClient);
                    }
                }
            }

            // Parse text
            string sText = Request.PopFixedString();

            // Notify the receivers
            ServerMessage notify = new ServerMessage(ResponseOpcodes.RoomInvite);

            //...
            foreach (GameClient receiver in receivers)
            {
                receiver.GetConnection().SendMessage(notify);
            }
        }
Esempio n. 15
0
        private void CompleteLogin()
        {
            // Actually logged in?
            if (mHabbo != null)
            {
                // Send user rights
                mMessageHandler.GetResponse().Initialize(ResponseOpcodes.UserRights); // "@B"
                foreach (string sRight in IonEnvironment.GetHabboHotel().GetUserRights().GetRights(mHabbo.Role))
                {
                    mMessageHandler.GetResponse().AppendString(sRight);
                }
                mMessageHandler.SendResponse();

                // Login OK!
                mMessageHandler.GetResponse().Initialize(3); // "@C"
                mMessageHandler.SendResponse();

                // Register handlers
                mMessageHandler.UnRegisterPreLogin();
                mMessageHandler.RegisterUser();
                mMessageHandler.RegisterNavigator();
                mMessageHandler.RegisterCatalog();
            }
        }
Esempio n. 16
0
 private void ConnectionDead()
 {
     IonEnvironment.GetHabboHotel().GetClients().StopClient(mID);
 }