[PlusEMU][Addon] User's avatar in alert

Core

Member
Nov 10, 2016
356
138
Alternative to this method you could always just save the users figure in the notifications folder and use that as a reference but it can also be done using a rewrite rule so that the image is updated when the user changes there looks.

How it works,
It will use a rewrite rule which filters for /fig/{data}.png in the notifications folder. In return meaning that you can use $"fig/{Session.GetHabbo().Look}" as the image argument for RoomNotificationComposer. To set it up, it's really easy.

Go to your c_images folder and create an .htaccess file (if using apachie, you will need a web.config for iis). The inside this file put;
Code:
RewriteEngine On
RewriteRule ^notifications/fig/([A-Za-z0-9-\.]+).png(|/)$ notifications/user.php?fig=$1

The reason I have put the rule in c_images as I wrote several scripts for this is because released swfs are cluttered with things that aren't needed. So I just wiped the entire c_images and wrote a 404 handler which requests file from habbo if it doesn't exist; that way not using large swfs. However, you could alternatively put it in the notifications folder but just remove the notifications/ from the rule. This script was wrote for the notifications only but can easily be modified if you wish to do the same as me:p.

Now you have rule set up, you want to create a file called user.php in c_images/notifications. Inside the file put the following
Code:
<?php
 
    if(!isset($_GET["fig"]) || empty($_GET["fig"])) {
        echo "No fig request";
        exit;
    }
 
    $ch = curl_init("https://www.habbo.com.br/habbo-imaging/avatarimage?hb=img&figure={$_GET["fig"]}&action=wav&direction=2&head_direction=3&size=m");
 
    curl_setopt_array($ch, array(
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HEADER         => false,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_ENCODING       => "",
        CURLOPT_USERAGENT      => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36",
        CURLOPT_AUTOREFERER    => true,
        CURLOPT_SSL_VERIFYPEER => false
    ));
 
    $content = curl_exec($ch);
    $type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
 
    curl_close($ch);
 
    if(!isset($content) || empty($content) || strpos($content, 'Not Found') !== false) {
        echo "Not found!";
        exit;
    }
     
    header("Content-Type: {$type}");
 
    echo $content;
?>

And, finally. Sending the new image to the client (this just goes where ever you want to send it...);

Code:
Session.SendMessage(new RoomNotificationComposer("Title Example", "Content Example", $"fig/{Session.GetHabbo().Look}");


You may need to add reference to the namespace for RoomNotificationComposer. Here is how;
Add the following to the top of the file...
Code:
using Plus.Communication.Packets.Outgoing.Rooms.Notifications;
 
Last edited:

MayoMayn

BestDev
Oct 18, 2016
1,423
683
Thanks a lot man, this cleared it out for me. You got any idea why the sockets doesn't work?
I'm using this function:
PHP:
function MUS($command, $data='') {
    $MUSdata = $command . chr(1) . $data;
    $socket = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp')) or die ('Could not create socket.\n');
    socket_connect($socket, 'IP GOES HERE', 30001) or die('Could not connect socket.\n');
    socket_send($socket, $MUSdata, strlen($MUSdata), MSG_DONTROUTE) or die('Could not send socket data.\n'); 
    socket_close($socket);
 }     

MUS("dc", "EXON");
I want to like you know, be able to give badges, items update users currencies etc, without them having to reload client.
 

Core

Member
Nov 10, 2016
356
138
Thanks a lot man, this cleared it out for me. You got any idea why the sockets doesn't work?
I'm using this function:
PHP:
function MUS($command, $data='') {
    $MUSdata = $command . chr(1) . $data;
    $socket = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp')) or die ('Could not create socket.\n');
    socket_connect($socket, 'IP GOES HERE', 30001) or die('Could not connect socket.\n');
    socket_send($socket, $MUSdata, strlen($MUSdata), MSG_DONTROUTE) or die('Could not send socket data.\n');  
    socket_close($socket);
 }      

MUS("disconnect", " EXON");

You need to change 'IP GOES HERE' if not already :).
Make sure 30001 is the MUS emulator port.
Open tcp port 30001 in the firewall.
Enable sockets in config.
 

Connor

Member
May 28, 2010
87
6
Followed the steps exactly the client is recognizing that the image is being loaded at "/c_images/notifications/fig/'somehabbofigure'.png" but no image is being created in the folder or being generated. Does it have something to do with the folder permissions?
 

Joe

Well-Known Member
Jun 10, 2012
4,172
1,955
Any one with the code for Event Alerts?

Sent from my SM-G928F using Tapatalk
Code:
using Plus.Communication.Packets.Outgoing.Moderation;
using Plus.HabboHotel.GameClients;
using System;
namespace Plus.HabboHotel.Rooms.Chat.Commands.Events
{
    internal class EventAlertCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get
            {
                return "command_event_alert";
            }
        }
        public string Parameters
        {
            get
            {
                return "";
            }
        }
        public string Description
        {
            get
            {
                return "Send a hotel alert for your event!";
            }
        }
        public void Execute(GameClient Session, Room Room, string[] Params)
        {
            if (Session != null)
            {
                if (Room != null)
                {
                    if (Params.Length != 1)
                    {
                        Session.SendWhisper("Invalid command! :eventalert", 0);
                    }
                    else if (!PlusEnvironment.Event)
                    {
                        PlusEnvironment.GetGame().GetClientManager().SendMessage(new BroadcastMessageAlertComposer(":follow " + Session.GetHabbo().Username + " for events! win prizes!\r\n- " + Session.GetHabbo().Username, ""), "");
                        PlusEnvironment.lastEvent = DateTime.Now;
                        PlusEnvironment.Event = true;
                    }
                    else
                    {
                        TimeSpan timeSpan = DateTime.Now - PlusEnvironment.lastEvent;
                        if (timeSpan.Hours >= 1)
                        {
                            PlusEnvironment.GetGame().GetClientManager().SendMessage(new BroadcastMessageAlertComposer(":follow " + Session.GetHabbo().Username + " for events! win prizes!\r\n- " + Session.GetHabbo().Username, ""), "");
                            PlusEnvironment.lastEvent = DateTime.Now;
                        }
                        else
                        {
                            int num = checked(60 - timeSpan.Minutes);
                            Session.SendWhisper("Event Cooldown! " + num + " minutes left until another event can be hosted.", 0);
                        }
                    }
                }
            }
        }
    }
}
If that's what you meant? My C# is weak, I would have no idea how to add this part.
Code:
Session.SendMessage(new RoomNotificationComposer("Title Example", "Content Example", $"fig/{Session.GetHabbo().Look}");
 
Last edited:

Core

Member
Nov 10, 2016
356
138
Followed the steps exactly the client is recognizing that the image is being loaded at "/c_images/notifications/fig/'somehabbofigure'.png" but no image is being created in the folder or being generated. Does it have something to do with the folder permissions?
It doesn't create an image? The script has no form of cache sends http request to habbo's figure on each request.
If using IIS you will need to make a web.config rule to handle the 404 exception instead of htaccess.
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
Code:
using Plus.Communication.Packets.Outgoing.Moderation;
using Plus.HabboHotel.GameClients;
using System;
namespace Plus.HabboHotel.Rooms.Chat.Commands.Events
{
    internal class EventAlertCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get
            {
                return "command_event_alert";
            }
        }
        public string Parameters
        {
            get
            {
                return "";
            }
        }
        public string Description
        {
            get
            {
                return "Send a hotel alert for your event!";
            }
        }
        public void Execute(GameClient Session, Room Room, string[] Params)
        {
            if (Session != null)
            {
                if (Room != null)
                {
                    if (Params.Length != 1)
                    {
                        Session.SendWhisper("Invalid command! :eventalert", 0);
                    }
                    else if (!PlusEnvironment.Event)
                    {
                        PlusEnvironment.GetGame().GetClientManager().SendMessage(new BroadcastMessageAlertComposer(":follow " + Session.GetHabbo().Username + " for events! win prizes!\r\n- " + Session.GetHabbo().Username, ""), "");
                        PlusEnvironment.lastEvent = DateTime.Now;
                        PlusEnvironment.Event = true;
                    }
                    else
                    {
                        TimeSpan timeSpan = DateTime.Now - PlusEnvironment.lastEvent;
                        if (timeSpan.Hours >= 1)
                        {
                            PlusEnvironment.GetGame().GetClientManager().SendMessage(new BroadcastMessageAlertComposer(":follow " + Session.GetHabbo().Username + " for events! win prizes!\r\n- " + Session.GetHabbo().Username, ""), "");
                            PlusEnvironment.lastEvent = DateTime.Now;
                        }
                        else
                        {
                            int num = checked(60 - timeSpan.Minutes);
                            Session.SendWhisper("Event Cooldown! " + num + " minutes left until another event can be hosted.", 0);
                        }
                    }
                }
            }
        }
    }
}
If that's what you meant? My C# is weak, I would have no idea how to add this part.
Code:
Session.SendMessage(new RoomNotificationComposer("Title Example", "Content Example", $"fig/{Session.GetHabbo().Look}");
Yeah thats it thanks

Sent from my SM-G928F using Tapatalk
 

Etrion

?
Dec 22, 2016
108
32
web.config:
<rule name="rule 1u">
<match url="^notifications/fig/([A-Za-z0-9-\.]+).png(|/)$" />
<action type="Rewrite" url="/notifications/user.php?fig={R:1}" />
</rule>

I know, easy to get, but maybe someone dunno how to convert :p

Edit: This is the error i get:
and this is how i put the figure part:
help pls?
 
Last edited:

Damien

Don't need glasses if you can C#
Feb 26, 2012
434
647
Where the get request is for the figure, add a replace to convert underscores to periods and it should work.

Code:
$figure = str_replace('_', '.', $_GET["figure"]);
 
Last edited:

Meap

Don't need glasses if you C#
Nov 7, 2010
1,045
296
Tried that as below
Code:
    $figure = str_replace('_', '.', $_GET["fig"]);
 
    $ch = curl_init("https://www.habbo.com.br/habbo-imaging/avatarimage?hb=img&figure={$figure}&action=wav&direction=2&head_direction=3&size=m");
either im a complete retard and done it incorrectly or it just doesn't want to work
 

Etrion

?
Dec 22, 2016
108
32
Tried that as below
Code:
    $figure = str_replace('_', '.', $_GET["fig"]);
 
    $ch = curl_init("https://www.habbo.com.br/habbo-imaging/avatarimage?hb=img&figure={$figure}&action=wav&direction=2&head_direction=3&size=m");
either im a complete retard and done it incorrectly or it just doesn't want to work

This will work:
PHP:
<?php

    if(!isset($_GET["fig"]) || empty($_GET["fig"])) {
        echo "No fig request";
        exit;
    }
$fig = $_GET['fig'];
$fig .= str_replace("_", ".", $fig);
$ch = curl_init("http://www.habbo.com/habbo-imaging/avatarimage?figure=$fig&action=wlk&direction=2&head_direction=3&gesture=sml&size=l");
    curl_setopt_array($ch, array(
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HEADER         => false,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_ENCODING       => "",
        CURLOPT_USERAGENT      => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36",
        CURLOPT_AUTOREFERER    => true,
        CURLOPT_SSL_VERIFYPEER => false
    ));

    $content = curl_exec($ch);
    $type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);

    curl_close($ch);

    if(!isset($content) || empty($content) || strpos($content, 'Not Found') !== false) {
        echo "Not found!";
        exit;
    }
   
    header("Content-Type: {$type}");

    echo $content;
?>
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
This will work:
PHP:
<?php

    if(!isset($_GET["fig"]) || empty($_GET["fig"])) {
        echo "No fig request";
        exit;
    }
$fig = $_GET['fig'];
$fig .= str_replace("_", ".", $fig);
$ch = curl_init("http://www.habbo.com/habbo-imaging/avatarimage?figure=$fig&action=wlk&direction=2&head_direction=3&gesture=sml&size=l");
    curl_setopt_array($ch, array(
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HEADER         => false,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_ENCODING       => "",
        CURLOPT_USERAGENT      => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36",
        CURLOPT_AUTOREFERER    => true,
        CURLOPT_SSL_VERIFYPEER => false
    ));

    $content = curl_exec($ch);
    $type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);

    curl_close($ch);

    if(!isset($content) || empty($content) || strpos($content, 'Not Found') !== false) {
        echo "Not found!";
        exit;
    }
   
    header("Content-Type: {$type}");

    echo $content;
?>
That is just plain stupid. If you got a 100 user base, that will be a 100 curls within few seconds, instead of caching it / save the image in a folder, so you don't have to overkill the curl totally, and then automatically next time if the user has changed figure, you just delete the old one from the images folder.

If you're interested I can code this to 100% functionality once I get to work.

Avatar Retros is stupid it sometimes require authentication because of CF services.

Sent from my SM-G928F using Tapatalk
 

Users who are viewing this thread

Top