This project it's to control remotely and safely the Plus Emulator.
Fix:
Put that on Environment:
PHP Code:
internal static ControleCenter foos = new sul0wn.Core.ControleCenter();
internal static int FoosOK = 0;
After
PHP Code:
MusSystem = new MusSocket(SilverwaveEnvironment.GetConfig().data["mus.tcp.bindip"]
Put that:
PHP Code:
foos.Server_Load();
Put that two .cs on your solution:
ControleCenter.cs
PHP Code:
using System;
using sul0wn.HabboHotel;
using System.Collections.Generic;
using sul0wn.Messages;
using Database_Manager.Database.Session_Details.Interfaces;
using System.Linq;
using sul0wn.Messages.Headers;
using System.Net.Sockets;
using System.Net;
using System.Collections;
using ChatApplication;
using System.Text;
namespace sul0wn.Core
{
/// <summary>
/// Description of ControleCenter.
/// </summary>
public class ControleCenter
{
// Structure to store the client information
private struct Client
{
public EndPoint endPoint;
public string name;
}
// Listing of clients
private ArrayList clientList;
// Server socket
private Socket serverSocket;
// Data stream
private byte[] dataStream = new byte[1024];
// Status delegate
private delegate void UpdateStatusDelegate(string status);
private UpdateStatusDelegate updateStatusDelegate = null;
internal HashSet<String> allowedIps;
internal static Game getGame()
{
return sul0wnEnvironment.GetGame();
}
internal void Server_Load()
{
try
{
// Initialise the ArrayList of connected clients
this.clientList = new ArrayList();
String[] _allowedIps = sul0wnEnvironment.GetConfig().data["rcon.allowip"].Split(Convert.ToChar(";"));
// Initialise the delegate which updates the status
this.updateStatusDelegate = new UpdateStatusDelegate(this.UpdateStatus);
// Initialise the socket
serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
int port = int.Parse(sul0wnEnvironment.GetConfig().data["rcon.port"]);
// Initialise the IPEndPoint for the server and listen on port 30000
IPEndPoint server = new IPEndPoint(IPAddress.Any, port);
// Associate the socket with this IP address and port
serverSocket.Bind(server);
// Initialise the IPEndPoint for the clients
IPEndPoint clients = new IPEndPoint(IPAddress.Any, 0);
// Initialise the EndPoint for the clients
EndPoint epSender = (EndPoint)clients;
// Start listening for incoming data
serverSocket.BeginReceiveFrom(this.dataStream, 0, this.dataStream.Length, SocketFlags.None, ref epSender, new AsyncCallback(ReceiveData), epSender);
Console.ForegroundColor = ConsoleColor.Blue;
Logging.WriteLine("[RCON] Listening....");
Console.ForegroundColor = ConsoleColor.Green;
}
catch (Exception ex)
{
}
}
public void SendData(IAsyncResult asyncResult)
{
try
{
serverSocket.EndSend(asyncResult);
return;
}
catch (Exception ex)
{
}
}
internal void sendLOL(string message)
{
byte[] data;
Packet sendData = new Packet();
IPEndPoint clients = new IPEndPoint(IPAddress.Any, 0);
// Initialise the EndPoint for the clients
EndPoint epSender = (EndPoint)clients;
// Receive all data
// Start populating the packet to be sent
sendData.ChatDataIdentifier = DataIdentifier.Message;
sendData.ChatName = "Emulator";
sendData.ChatMessage = string.Format(message);
// Get packet as byte array
data = sendData.GetDataStream();
foreach (Client client in this.clientList)
{
if (client.endPoint != epSender || sendData.ChatDataIdentifier != DataIdentifier.LogIn)
{
// Broadcast to all logged on users
serverSocket.BeginSendTo(data, 0, data.Length, SocketFlags.None, client.endPoint, new AsyncCallback(this.SendData), client.endPoint);
}
}
Logging.WriteLine("[RCON] Send Data to RCON.");
return;
}
private void ReceiveData(IAsyncResult asyncResult)
{
try
{
byte[] data;
// Initialise a packet object to store the received data
Packet receivedData = new Packet(this.dataStream);
// Initialise a packet object to store the data to be sent
Packet sendData = new Packet();
// Initialise the IPEndPoint for the clients
IPEndPoint clients = new IPEndPoint(IPAddress.Any, 0);
// Initialise the EndPoint for the clients
EndPoint epSender = (EndPoint)clients;
// Receive all data
serverSocket.EndReceiveFrom(asyncResult, ref epSender);
// Start populating the packet to be sent
sendData.ChatDataIdentifier = receivedData.ChatDataIdentifier;
sendData.ChatName = receivedData.ChatName;
switch (receivedData.ChatDataIdentifier)
{
case DataIdentifier.Message:
string[] parameters = receivedData.ChatMessage.Split(' ');
#region Command parsing
switch (parameters[0])
{
case "command":
switch(parameters[1])
{
case "shutdown":
{
Logging.LogMessage("Server exiting at " + DateTime.Now);
Logging.DisablePrimaryWriting(true);
Logging.WriteLine("The server is saving users furniture, rooms, etc. WAIT FOR THE SERVER TO CLOSE, DO NOT EXIT THE PROCESS IN TASK MANAGER!!", ConsoleColor.Yellow);
sul0wnEnvironment.PerformShutDown(false);
break;
}
case "flush":
{
if (parameters.Length < 2)
sendData.ChatMessage = string.Format("[Message] You need to specify a parameter within your command. Type help for more information");
else
{
switch (parameters[2])
{
case "database":
{
sul0wnEnvironment.GetDatabaseManager().Destroy();
sendData.ChatMessage = string.Format("[Message] Closed old connections");
break;
}
case "settings":
{
if (parameters.Length < 3)
sendData.ChatMessage = string.Format("[Message] You need to specify a parameter within your command. Type help for more information");
else
{
switch (parameters[3])
{
case "catalog":
{
sendData.ChatMessage = string.Format("[Message] Flushing catalog settings");
using (IQueryAdapter dbClient = sul0wnEnvironment.GetDatabaseManager().getQueryreactor())
{
getGame().GetCatalog().Initialize(dbClient);
}
getGame().GetClientManager().QueueBroadcaseMessage(new ServerMessage(441));
sendData.ChatMessage = string.Format("[Message] Catalog flushed");
break;
}
case "modeldata":
{
sendData.ChatMessage = string.Format("[Message] Flushing modeldata");
using (IQueryAdapter dbClient = sul0wnEnvironment.GetDatabaseManager().getQueryreactor())
{
getGame().GetRoomManager().LoadModels(dbClient);
}
sendData.ChatMessage = string.Format("[Message] Models flushed");
break;
}
case "bans":
{
sendData.ChatMessage = string.Format("[Message] Flushing bans");
using (IQueryAdapter dbClient = sul0wnEnvironment.GetDatabaseManager().getQueryreactor())
{
getGame().GetBanManager().LoadBans(dbClient);
}
sendData.ChatMessage = string.Format("[Message] Bans flushed");
break;
}
case "language":
{
sendData.ChatMessage = string.Format("[Message] Flushing language files");
using (IQueryAdapter dbClient = sul0wnEnvironment.GetDatabaseManager().getQueryreactor())
LanguageLocale.Init(dbClient);
sendData.ChatMessage = string.Format("[Message] Language files flushed");
break;
}
}
}
break;
}
case "console":
{
Console.Clear();
break;
}
case "memory":
{
GC.Collect();
sendData.ChatMessage = string.Format("[Message] Memory flushed");
break;
}
default:
{
break;
}
}
}
break;
}
case "view":
{
switch (parameters[2])
{
case "console":
{
sendData.ChatMessage = string.Format("[Message] Press ENTER for disabling console writing");
Logging.DisabledState = false;
break;
}
}
break;
}
case "alert":
{
string Notice = receivedData.ChatMessage.Substring(6);
ServerMessage HotelAlert = new ServerMessage(Outgoing.BroadcastMessage);
HotelAlert.AppendString(LanguageLocale.GetValue("console.noticefromadmin") + "\n\n" +
Notice);
HotelAlert.AppendString("");
getGame().GetClientManager().QueueBroadcaseMessage(HotelAlert);
sendData.ChatMessage = string.Format("[Message] [" + Notice + "] sent");
break;
}
case "help":
{
sendData.ChatMessage = string.Format("[Message] shutdown - shuts down the server");
sendData.ChatMessage = string.Format("[Message] view");
sendData.ChatMessage = string.Format("[Message] console - views server output (Press enter to disable)");
sendData.ChatMessage = string.Format("[Message] alert (message) - sends alert to everyone online");
break;
}
default:
{
break;
}
}
break;
default:
sendData.ChatMessage = string.Format("{0}: {1}", receivedData.ChatName, receivedData.ChatMessage);
break;
}
#endregion
break;
case DataIdentifier.LogIn:
// Populate client object
Client client = new Client();
client.endPoint = epSender;
client.name = receivedData.ChatName;
string password = sul0wnEnvironment.GetConfig().data["rcon.pass"];
if(receivedData.ChatMessage == password)
{
// Add client to list
this.clientList.Add(client);
sendData.ChatMessage = string.Format(" {0} Entered on RCON", receivedData.ChatName);
sul0wnEnvironment.FoosOK = 1;
}
break;
case DataIdentifier.LogOut:
// Remove current client from list
foreach (Client c in this.clientList)
{
if (c.endPoint.Equals(epSender))
{
this.clientList.Remove(c);
break;
}
}
sendData.ChatMessage = string.Format("-- {0} has gone offline --", receivedData.ChatName);
sul0wnEnvironment.FoosOK = 0;
break;
}
// Get packet as byte array
data = sendData.GetDataStream();
foreach (Client client in this.clientList)
{
if (client.endPoint != epSender || sendData.ChatDataIdentifier != DataIdentifier.LogIn)
{
// Broadcast to all logged on users
serverSocket.BeginSendTo(data, 0, data.Length, SocketFlags.None, client.endPoint, new AsyncCallback(this.SendData), client.endPoint);
}
}
// Listen for more connections again...
serverSocket.BeginReceiveFrom(this.dataStream, 0, this.dataStream.Length, SocketFlags.None, ref epSender, new AsyncCallback(this.ReceiveData), epSender);
// Update status through a delegate
Logging.WriteLine("[RCON] " + sendData.ChatMessage);
}
catch (Exception ex)
{
}
}
public 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();
}
private void UpdateStatus(string status)
{
Console.ForegroundColor = ConsoleColor.Blue;
Logging.WriteLine("[RCON]: " + status);
Console.ForegroundColor = ConsoleColor.Green;
}
}
}
Packet.cs
PHP Code:
using System;
using System.Collections.Generic;
using System.Text;
namespace ChatApplication
{
// ----------------
// Packet Structure
// ----------------
// Description -> |dataIdentifier|name length|message length| name | message |
// Size in bytes -> | 4 | 4 | 4 |name length|message length|
public enum DataIdentifier
{
Message,
LogIn,
LogOut,
Null
}
public class Packet
{
#region Private Members
private DataIdentifier dataIdentifier;
private string name;
private string message;
#endregion
#region Public Properties
public DataIdentifier ChatDataIdentifier
{
get { return dataIdentifier; }
set { dataIdentifier = value; }
}
public string ChatName
{
get { return name; }
set { name = value; }
}
public string ChatMessage
{
get { return message; }
set { message = value; }
}
#endregion
#region Methods
// Default Constructor
public Packet()
{
this.dataIdentifier = DataIdentifier.Null;
this.message = null;
this.name = null;
}
public Packet(byte[] dataStream)
{
// Read the data identifier from the beginning of the stream (4 bytes)
this.dataIdentifier = (DataIdentifier)BitConverter.ToInt32(dataStream, 0);
// Read the length of the name (4 bytes)
int nameLength = BitConverter.ToInt32(dataStream, 4);
// Read the length of the message (4 bytes)
int msgLength = BitConverter.ToInt32(dataStream, 8);
// Read the name field
if (nameLength > 0)
this.name = Encoding.UTF8.GetString(dataStream, 12, nameLength);
else
this.name = null;
// Read the message field
if (msgLength > 0)
this.message = Encoding.UTF8.GetString(dataStream, 12 + nameLength, msgLength);
else
this.message = null;
}
// Converts the packet into a byte array for sending/receiving
public byte[] GetDataStream()
{
List<byte> dataStream = new List<byte>();
// Add the dataIdentifier
dataStream.AddRange(BitConverter.GetBytes((int)this.dataIdentifier));
// Add the name length
if (this.name != null)
dataStream.AddRange(BitConverter.GetBytes(this.name.Length));
else
dataStream.AddRange(BitConverter.GetBytes(0));
// Add the message length
if (this.message != null)
dataStream.AddRange(BitConverter.GetBytes(this.message.Length));
else
dataStream.AddRange(BitConverter.GetBytes(0));
// Add the name
if (this.name != null)
dataStream.AddRange(Encoding.UTF8.GetBytes(this.name));
// Add the message
if (this.message != null)
dataStream.AddRange(Encoding.UTF8.GetBytes(this.message));
return dataStream.ToArray();
}
#endregion
}
}
Add that on settings.ini
Code:
rcon.allowip=127.0.0.1
rcon.pass=aaff102030
rcon.port=3909
Now Debug. , To Create the Remote Control (The Client Side)
Download this Project: https://mega.co.nz/#!XYdWkAaR!HSk1_b...s1vyS6J12jC1j8
Debug, and update the .ini
Now Open your emulator, Wait and Open the client.
To send a message only say Anything, to send a command say "command COMMANDNAME"
You can send The outgoing and header and incoming packets to the client side, and the users Entering.
Roommgr.cs
PHP Code:
if(sul0wnEnvironment.FoosOK == 1)
sul0wnEnvironment.foos.sendLOL("[RoomMgr] Loaded room: \"" + Room.Name + "\" (ID: " + Id + ")");
And:
if(sul0wnEnvironment.FoosOK == 1)
sul0wnEnvironment.foos.sendLOL("[RoomMgr] Unloaded room: \"" + Room.Name + "\" (ID: " + Room.RoomId + ")");
Navigator.cs
PHP Code:
if(sul0wnEnvironment.FoosOK == 1)
sul0wnEnvironment.foos.sendLOL("[ " + this.Request.PopFixedString() + " ] is online");
ServerMessage.cs
PHP Code:
if(sul0wnEnvironment.FoosOK == 1)
sul0wnEnvironment.foos.sendLOL("[Outgoing] Handled Packet: " + Header.ToString());
PS: change SUL0WN to SILVERWAVE
Credits to Me.
Enjoy.