HabboLatino / Butterstorm - RCON (MUS) commands
I noticed Butterstorm/Habbolatino didnt have any working RCON commands so i added a few.
PHP Code:
ha [Message]
hal [url] [Message]
alert [Username] [Message]
updatecredits [Username]
catarefresh
givebadge [Username] [Badge]
shutdown
ban [Username] [time] [reason]
unban [UsernameOrIP]
coins [Username] [Amount]
pixels [Username] [Amount]
crystals [Username] [Amount]
signout [UserID]
globalcredits [Amount]
massbadge [Badge]
**If you use MusCommander then you can paste the above commands into your "MusCommands.txt" and they will work.**
Replace the code inside your MusSocket.cs with the following code >
PHP Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Net;
using System.Net.Sockets;
using HabboEvents;
using Butterfly.HabboHotel.GameClients;
using Butterfly.HabboHotel.Rooms;
using Butterfly.Messages;
using Butterfly.Core;
using Database_Manager.Database.Session_Details.Interfaces;
namespace Butterfly.Net
{
class MusSocket
{
private Socket msSocket;
private String musIp;
private int musPort;
private HashSet<String> allowedIps;
public MusSocket(String _musIp, int _musPort, String[] _allowedIps, int backlog)
{
musIp = _musIp;
musPort = _musPort;
allowedIps = new HashSet<String>();
foreach (String ip in _allowedIps)
{
allowedIps.Add(ip);
}
try
{
msSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
msSocket.Bind(new IPEndPoint(IPAddress.Any, musPort));
msSocket.Listen(backlog);
msSocket.BeginAccept(OnEvent_NewConnection, msSocket);
Logging.WriteLine("MUS socket -> READY!");
}
catch (Exception e)
{
throw new ArgumentException("Could not set up MUS socket:\n" + e.ToString());
}
}
private void OnEvent_NewConnection(IAsyncResult iAr)
{
try
{
Socket socket = ((Socket)iAr.AsyncState).EndAccept(iAr);
String ip = socket.RemoteEndPoint.ToString().Split(':')[0];
if (allowedIps.Contains(ip) || ip == "127.0.0.1")
{
MusConnection nC = new MusConnection(socket);
}
else
{
socket.Close();
}
}
catch (Exception) { }
msSocket.BeginAccept(OnEvent_NewConnection, msSocket);
}
}
class MusConnection
{
private Socket socket;
private byte[] buffer = new byte[1024];
public MusConnection(Socket _socket)
{
socket = _socket;
try
{
socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, OnEvent_RecieveData, socket);
}
catch
{
tryClose();
}
}
private void tryClose()
{
try
{
socket.Shutdown(SocketShutdown.Both);
socket.Close();
socket.Dispose();
}
catch { }
socket = null;
buffer = null;
}
private void OnEvent_RecieveData(IAsyncResult iAr)
{
try
{
int bytes = 0;
try
{
bytes = socket.EndReceive(iAr);
}
catch { tryClose(); return; }
String data = Encoding.Default.GetString(buffer, 0, bytes);
if (data.Length > 0)
processCommand(data);
}
catch { }
tryClose();
}
private void processCommand(String data)
{
String header = "";
String param = "";
if (data.IndexOf(Convert.ToChar(1)) != -1)
{
header = data.Split(Convert.ToChar(1))[0].Trim();
param = data.Split(Convert.ToChar(1))[1];
}
else
{
header = data.Remove(Convert.ToChar(1)).Trim();
param = "";
}
string[] pars = param.Split(' ');
GameClient Client = null;
switch (header.ToLower())
{
case "updatecredits":
{
Client = ButterflyEnvironment.GetGame().GetClientManager().GetClientByUsername(pars[0]);
if (Client == null)
{
Respond("User " + pars[0] + " does not seem to be online!");
return;
}
DataRow newCredits;
using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
{
dbClient.setQuery("SELECT credits FROM users WHERE id = @userid");
dbClient.addParameter("userid", (int)Client.GetHabbo().Id);
newCredits = dbClient.getRow();
}
Client.GetHabbo().Credits = (int)newCredits["credits"];
Client.GetHabbo().UpdateCreditsBalance();
Respond("Credits for user " + pars[0] + " updated.");
break;
}
case "signout":
{
ButterflyEnvironment.GetGame().GetClientManager().GetClientByUserID(uint.Parse(pars[0])).Disconnect();
Respond("User disconnected.");
break;
}
case "ha":
{
string Notice = param;
ServerMessage HotelAlert = new ServerMessage(Outgoing.BroadcastMessage);
HotelAlert.AppendStringWithBreak(LanguageLocale.GetValue("hotelallert.notice") + "\r\n" +
Notice + "\r\n" + "- " + "Staff");
ButterflyEnvironment.GetGame().GetClientManager().QueueBroadcaseMessage(HotelAlert);
Respond("Hotel alert executed.");
break;
}
case "hal":
{
string Link = pars[0];
string Message = MergeParams(pars, 1);
ServerMessage nMessage = new ServerMessage(Outgoing.SendNotif);
nMessage.AppendStringWithBreak(LanguageLocale.GetValue("hotelallert.notice") + "\r\n" + Message + "\r\n-" + "");
nMessage.AppendStringWithBreak(Link);
ButterflyEnvironment.GetGame().GetClientManager().QueueBroadcaseMessage(nMessage);
Respond("Hotel Link Alert has been sent.");
break;
}
case "alert":
{
string TargetUser = null;
GameClient TargetClient = null;
TargetUser = pars[0];
TargetClient = ButterflyEnvironment.GetGame().GetClientManager().GetClientByUsername(TargetUser);
if (TargetClient == null)
{
Respond(LanguageLocale.GetValue("input.usernotfound"));
}
TargetClient.SendNotif(MergeParams(pars, 1));
Respond("Alert has been sent.");
break;
}
case "catarefresh":
{
using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
{
ButterflyEnvironment.GetGame().GetCatalog().Initialize(dbClient);
ButterflyEnvironment.GetGame().GetItemManager().LoadItems(dbClient);
}
ButterflyEnvironment.GetGame().GetCatalog().InitCache();
ButterflyEnvironment.GetGame().GetClientManager().QueueBroadcaseMessage(new ServerMessage(Outgoing.UpdateShop));
Respond("Catalog refreshed");
break;
}
case "ban":
{
GameClient TargetClient = null;
TargetClient = ButterflyEnvironment.GetGame().GetClientManager().GetClientByUsername(pars[0]);
if (TargetClient == null)
{
Respond(LanguageLocale.GetValue("input.usernotfound"));
}
int BanTime = 0;
try
{
BanTime = int.Parse(pars[1]);
}
catch (FormatException) { Respond("An error has occured."); }
if (BanTime <= 600)
{
Respond(LanguageLocale.GetValue("ban.toolesstime"));
}
else
{
ButterflyEnvironment.GetGame().GetBanManager().BanUser(TargetClient, "Staff", BanTime, MergeParams(pars, 2), false);
Respond(pars[0] + " has been banned!");
}
break;
}
case "unban":
{
if (pars[0].Length > 1)
{
ButterflyEnvironment.GetGame().GetBanManager().UnbanUser(pars[0]);
Respond("Ban Removed.");
}
break;
}
case "shutdown":
{
Logging.LogMessage("Server exiting at " + DateTime.Now);
Logging.DisablePrimaryWriting(true);
Respond("The server is saving users furniture, rooms, etc. The server will then shut down.");
Console.Write("The server is saving users furniture, rooms, etc. WAIT FOR THE SERVER TO CLOSE, DO NOT EXIT THE PROCESS IN TASK MANAGER!!");
ButterflyEnvironment.PreformShutDown(true);
break;
}
case "givebadge":
{
GameClient TargetClient = null;
TargetClient = ButterflyEnvironment.GetGame().GetClientManager().GetClientByUsername(pars[0]);
if (TargetClient != null)
{
TargetClient.GetHabbo().GetBadgeComponent().GiveBadge(ButterflyEnvironment.FilterInjectionChars(pars[1]), true);
ButterflyEnvironment.GetGame().GetModerationTool().LogStaffEntry("Staff", TargetClient.GetHabbo().Username, "Badge", "Badge given to user [" + pars[0] + "]");
Respond("Badge '" + pars[1] + "' given to " + pars[0]);
}
else
{
Respond(LanguageLocale.GetValue("input.usernotfound"));
}
break;
}
case "coins":
{
GameClient TargetClient = null;
TargetClient = ButterflyEnvironment.GetGame().GetClientManager().GetClientByUsername(pars[0]);
if (TargetClient != null)
{
int creditsToAdd;
if (int.TryParse(pars[1], out creditsToAdd))
{
TargetClient.GetHabbo().Credits = TargetClient.GetHabbo().Credits + creditsToAdd;
TargetClient.GetHabbo().UpdateCreditsBalance();
TargetClient.SendNotif("Staff" + LanguageLocale.GetValue("coins.awardmessage1") + creditsToAdd.ToString() + LanguageLocale.GetValue("coins.awardmessage2"));
Respond(LanguageLocale.GetValue("coins.updateok"));
}
else
{
Respond(LanguageLocale.GetValue("input.intonly"));
}
}
else
{
Respond(LanguageLocale.GetValue("input.usernotfound"));
}
break;
}
case "pixels":
{
GameClient TargetClient = null;
TargetClient = ButterflyEnvironment.GetGame().GetClientManager().GetClientByUsername(pars[0]);
if (TargetClient != null)
{
int PixelsToAdd;
if (int.TryParse(pars[1], out PixelsToAdd))
{
TargetClient.GetHabbo().ActivityPoints = TargetClient.GetHabbo().ActivityPoints + PixelsToAdd;
TargetClient.GetHabbo().UpdateActivityPointsBalance(true);
TargetClient.SendNotif("Staff" + LanguageLocale.GetValue("pixels.awardmessage1") + PixelsToAdd.ToString() + LanguageLocale.GetValue("pixels.awardmessage2"));
Respond(LanguageLocale.GetValue("pixels.updateok"));
}
else
{
Respond(LanguageLocale.GetValue("input.intonly"));
}
}
else
{
Respond(LanguageLocale.GetValue("input.usernotfound"));
}
break;
}
case "globalcredits":
{
try
{
int CreditAmount = int.Parse(pars[0]);
ButterflyEnvironment.GetGame().GetClientManager().QueueCreditsUpdate(CreditAmount);
using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
dbClient.runFastQuery("UPDATE users SET credits = credits + " + CreditAmount);
ButterflyEnvironment.GetGame().GetModerationTool().LogStaffEntry("Staff", string.Empty, "Mass Credits", "Send [" + CreditAmount + "] credits to everyone in the database");
Respond("Global credits updated");
}
catch
{
Respond(LanguageLocale.GetValue("input.intonly"));
}
break;
}
case "massbadge":
{
ButterflyEnvironment.GetGame().GetClientManager().QueueBadgeUpdate(pars[0]);
break;
}
case "crystals":
{
GameClient TargetClient = null;
TargetClient = ButterflyEnvironment.GetGame().GetClientManager().GetClientByUsername(pars[0]);
if (TargetClient == null)
{
Respond(LanguageLocale.GetValue("input.usernotfound"));
}
try
{
TargetClient.GetHabbo().GiveUserCrystals(int.Parse(pars[1]));
Respond("Send " + pars[1] + " Crystals to " + pars[0]);
}
catch (FormatException) { Respond("An error has occured"); }
break;
}
default:
{
break;
}
}
}
//Send response back to Rcon Client
private void Respond(string response)
{
byte[] respond = System.Text.Encoding.UTF8.GetBytes(response);
socket.Send(respond, respond.Length, SocketFlags.None);
}
private static string MergeParams(string[] Params, int Start)
{
StringBuilder MergedParams = new StringBuilder();
for (int i = 0; i < Params.Length; i++)
{
if (i < Start)
{
continue;
}
if (i > Start)
{
MergedParams.Append(" ");
}
MergedParams.Append(Params[i]);
}
return MergedParams.ToString();
}
}
}
This method will send a response back to your RCON client (PHP page or whatever) so you have some kind of confirmation that the command was executed.
PHP Code:
private void Respond(string response)
{
byte[] respond = System.Text.Encoding.UTF8.GetBytes(response);
socket.Send(respond, respond.Length, SocketFlags.None);
}
I know some of the commands are a little messy but I took most of them from the regular commands and edited them a little bit.
Have fun
Re: HabboLatino / Butterstorm - RCON (MUS) commands
Yeah MUS commands :D Thank you Leen ;3
Re: HabboLatino / Butterstorm - RCON (MUS) commands
I'm wondering, why are you defining everything internal?
Re: HabboLatino / Butterstorm - RCON (MUS) commands
How do i send/request a mus function from the client in revcms?
Re: HabboLatino / Butterstorm - RCON (MUS) commands
I don't know RevCMS but here is some php code you could use. You just have to figure out where to put it.
PHP Code:
<?php
function SendMUSData($header,$data=""){
$ip = $variable_from_the_config;
$port = $another_variable_from_the_config;
$data = $header.chr(1).$data;
if(!is_numeric($port)){ return false; }
$sock = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
socket_connect($sock, $ip, $port);
if(!is_resource($sock)){
return false;
} else {
socket_send($sock, $data, strlen($data), MSG_DONTROUTE);
//You can use socket_recv to get the response from the server.
//socket_recv($sock, $buf, 2048, MSG_WAITALL);
//echo $buf;
return true;
}
socket_close($sock);
}
?>
Re: HabboLatino / Butterstorm - RCON (MUS) commands
Now I know how to code commands on my emulator!
Thanks for this fix!
Re: HabboLatino / Butterstorm - RCON (MUS) commands
I noticed that i messed up on a couple of the commands and they didnt seem to work.
I edited the main post with the new code.
Re: HabboLatino / Butterstorm - RCON (MUS) commands
Protect the system against the noobs that can execute commands using the default MUS port of bstorm! Or else they could shoutdown your server easily!
Anyway, good system :P!
Re: HabboLatino / Butterstorm - RCON (MUS) commands
Quote:
Originally Posted by
ItachiKM
Protect the system against the noobs that can execute commands using the default MUS port of bstorm! Or else they could shoutdown your server easily!
Anyway, good system :P!
What kind of protection do you suggest?
PHP Code:
if (allowedIps.Contains(ip) || ip == "127.0.0.1")
{
MusConnection nC = new MusConnection(socket);
}
else
{
socket.Close();
}
I thought that would be enough?