[MERCURYEMU] User/Roomforward [MERCURYEMU]
EDIT:
It works almost! Just one build error left!
using Mercury.Core;
using Mercury.HabboHotel.GameClients;
using Mercury.HabboHotel.Rooms;
using Mercury.Messages;
using Mercury.Messages.Headers;
using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
namespace Mercury.Net
{
internal class MusConnection
{
private Socket socket;
private byte[] buffer = new byte[1024];
internal MusConnection(Socket _socket)
{
this.socket = _socket;
try
{
this.socket.BeginReceive(this.buffer, 0, this.buffer.Length, SocketFlags.None, new AsyncCallback(this.OnEvent_RecieveData), this.socket);
}
catch
{
this.tryClose();
}
}
internal void tryClose()
{
try
{
this.socket.Shutdown(SocketShutdown.Both);
this.socket.Close();
this.socket.Dispose();
}
catch
{
}
this.socket = null;
this.buffer = null;
}
internal void OnEvent_RecieveData(IAsyncResult iAr)
{
try
{
int count = 0;
try
{
count = this.socket.EndReceive(iAr);
}
catch
{
this.tryClose();
return;
}
string @String = Encoding.Default.GetString(this.buffer, 0, count);
if @String.Length > 0)
{
this.processCommand @String);
}
}
catch (Exception value)
{
Console.WriteLine(value);
}
this.tryClose();
}
internal void processCommand(string data)
{
string text = data.Split(new char[]
{
Convert.ToChar(1)
})[0];
string text2 = data.Split(new char[]
{
Convert.ToChar(1)
})[1];
string[] array = text2.Split(new char[]
{
Convert.ToChar(5)
});
//string a;
switch (header.ToLower())
{
case "updatemotto":
{
Client = MercuryEnvironment.GetGame().GetClientManager().GetClientByUserID(Convert.ToUInt32(Params[0]));
Client.GetHabbo().Motto = MergeParams(Params, 1);
ServerMessage Update = new ServerMessage(Outgoing.UpdateUserInformation);
Update.AppendInt32(-1);
Update.AppendString(Client.GetHabbo().Look);
Update.AppendString(Client.GetHabbo().Gender.ToLower());
Update.AppendString(Client.GetHabbo().Motto);
Update.AppendInt32(Client.GetHabbo().AchievementPoints);
Client.SendMessage(Update);
if (Client.GetHabbo().CurrentRoom != null)
{
User = Client.GetHabbo().CurrentRoom.GetRoomUserManager().GetRoomUserByHabbo(Client.GetHabbo().Username);
ServerMessage RoomUpdate = new ServerMessage(Outgoing.UpdateUserInformation);
RoomUpdate.AppendInt32(User.VirtualId);
RoomUpdate.AppendString(Client.GetHabbo().Look);
RoomUpdate.AppendString(Client.GetHabbo().Gender.ToLower());
RoomUpdate.AppendString(Client.GetHabbo().Motto);
RoomUpdate.AppendInt32(Client.GetHabbo().AchievementPoints);
Client.GetHabbo().CurrentRoom.SendMessage(RoomUpdate);
}
break;
}
case "updaterooms":
{
uint OwnerId = Convert.ToUInt32(Params[0]);
string Owner = Params[1];
foreach (Room room in MercuryEnvironment.GetGame().GetRoomManager().loadedRooms.Values)
{
if (room.OwnerId == OwnerId)
{
MercuryEnvironment.GetGame().GetRoomManager().UnloadRoom(room);
room.RequestReload();
}
}
break;
}
case "addtoinventory":
{
uint UserId = Convert.ToUInt32(Params[0]);
int ItemId = Convert.ToInt32(Params[1]);
Client = MercuryEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
if (Client != null && Client.GetHabbo() != null && Client.GetHabbo().GetInventoryComponent() != null)
{
Client.GetHabbo().GetInventoryComponent().UpdateItems(true);
Client.GetHabbo().GetInventoryComponent().SendNewItems(ItemId);
}
break;
}
case "updatecredits":
{
uint UserId = Convert.ToUInt32(Params[0]);
int NewCredits = Convert.ToInt32(Params[1]);
Client = MercuryEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
if (Client != null && Client.GetHabbo() != null)
{
Client.GetHabbo().Credits = NewCredits;
Client.GetHabbo().UpdateCreditsBalance();
}
break;
}
case "updatesubscription":
{
uint UserId = Convert.ToUInt32(Params[0]);
int DurationSeconds = Convert.ToInt32(Params[1]);
Client = MercuryEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
if (Client != null && Client.GetHabbo() != null)
{
Client.GetHabbo().GetSubscriptionManager().ReloadSubscription(1, DurationSeconds, Client);
Client.GetHabbo().SerializeClub();
Client.SendMessage(new ServerMessage(Outgoing.UpdateShop));
}
break;
}
case "senduser":
{
uint UserId = Convert.ToUInt32(Params[0]);
int RoomId = Convert.ToInt32(Params[1]);
Client = MercuryEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
if (Client != null)
{
ServerMessage SendUser = new ServerMessage(Outgoing.RoomForwardMessageComposer);
SendUser.AppendInt32(RoomId);
Client.SendMessage(SendUser);
}
}
IL_3A3:
Logging.WriteLine("[MUS SOCKET] Comando MUS procesado correctamente: '" + text + "'", ConsoleColor.Green);
return;
}
IL_38B:
Logging.WriteLine("[MUS SOCKET] Paquete MUS no reconocido: " + text + "//" + data, ConsoleColor.DarkRed);
}
public static string MergeParams(string[] Params, int Start)
{
StringBuilder stringBuilder = new StringBuilder();
checked
{
for (int i = 0; i < Params.Length; i++)
{
if (i >= Start)
{
if (i > Start)
{
stringBuilder.Append(" ");
}
stringBuilder.Append(Params[i]);
}
}
return stringBuilder.ToString();
}
}
}
}
here the build error:
http://i60.tinypic.com/30ib8ld.png
Re: [MERCURYEMU] User/Roomforward [MERCURYEMU]
What are you trying to-do exactly?
Re: [MERCURYEMU] User/Roomforward [MERCURYEMU]
Well you could try replacing:
Code:
switch(header.ToLower())
By:
Code:
switch(text.ToLower())
Quote:
Originally Posted by
Bozzie
What are you trying to-do exactly?
Getting MUS handler to work properly I guess.
Re: [MERCURYEMU] User/Roomforward [MERCURYEMU]
Doesnt work... get 52 build errors... I tried switch(string.ToLower()) as well.
Anyone know how to fix? I think @FatalLulz know how to fix
Re: [MERCURYEMU] User/Roomforward [MERCURYEMU]
Easy fix. You never defined 'header' You removed the coding for it xP
Code:
String header = data.Split(Convert.ToChar(1))[0];
Put that in the processCommand void.
Re: [MERCURYEMU] User/Roomforward [MERCURYEMU]
Quote:
Originally Posted by
FatalLulz
Easy fix. You never defined 'header' You removed the coding for it xP
Code:
String header = data.Split(Convert.ToChar(1))[0];
Put that in the processCommand void.
Mind posting the whole code? Would make it easier.
Re: [MERCURYEMU] User/Roomforward [MERCURYEMU]
Quote:
Originally Posted by
Kristophers
Mind posting the whole code? Would make it easier.
This is the whole code.. O.o
Just add, (he's done it different to I)
Code:
string[] array = header.Split(new char[0]
{
Convert.ToChar(1)
});
in the processCommand void.
Re: [MERCURYEMU] User/Roomforward [MERCURYEMU]
Now i have this code:
using Mercury.Core;
using Mercury.HabboHotel.GameClients;
using Mercury.HabboHotel.Rooms;
using Mercury.Messages;
using Mercury.Messages.Headers;
using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
namespace Mercury.Net
{
internal class MusConnection
{
private Socket socket;
private byte[] buffer = new byte[1024];
internal MusConnection(Socket _socket)
{
this.socket = _socket;
try
{
this.socket.BeginReceive(this.buffer, 0, this.buffer.Length, SocketFlags.None, new AsyncCallback(this.OnEvent_RecieveData), this.socket);
}
catch
{
this.tryClose();
}
}
internal void tryClose()
{
try
{
this.socket.Shutdown(SocketShutdown.Both);
this.socket.Close();
this.socket.Dispose();
}
catch
{
}
this.socket = null;
this.buffer = null;
}
internal void OnEvent_RecieveData(IAsyncResult iAr)
{
try
{
int count = 0;
try
{
count = this.socket.EndReceive(iAr);
}
catch
{
this.tryClose();
return;
}
string @String = Encoding.Default.GetString(this.buffer, 0, count);
if @String.Length > 0)
{
this.processCommand @String);
}
}
catch (Exception value)
{
Console.WriteLine(value);
}
this.tryClose();
}
internal void processCommand(string data)
{
string text = data.Split(new char[]
{
Convert.ToChar(1)
})[0];
string text2 = data.Split(new char[]
{
Convert.ToChar(1)
})[1];
//string[] array = text2.Split(new char[]
//{
//Convert.ToChar(5)
//});
string[] array = header.Split(new char[]
{
Convert.ToChar(1)
});
string a;
//switch (header.ToLower())
switch (header.ToLower())
{
case "updatemotto":
{
Client = MercuryEnvironment.GetGame().GetClientManager().GetClientByUserID(Convert.ToUInt32(Params[0]));
Client.GetHabbo().Motto = MergeParams(Params, 1);
ServerMessage Update = new ServerMessage(Outgoing.UpdateUserInformation);
Update.AppendInt32(-1);
Update.AppendString(Client.GetHabbo().Look);
Update.AppendString(Client.GetHabbo().Gender.ToLower());
Update.AppendString(Client.GetHabbo().Motto);
Update.AppendInt32(Client.GetHabbo().AchievementPoints);
Client.SendMessage(Update);
if (Client.GetHabbo().CurrentRoom != null)
{
User = Client.GetHabbo().CurrentRoom.GetRoomUserManager().GetRoomUserByHabbo(Client.GetHabbo().Username);
ServerMessage RoomUpdate = new ServerMessage(Outgoing.UpdateUserInformation);
RoomUpdate.AppendInt32(User.VirtualId);
RoomUpdate.AppendString(Client.GetHabbo().Look);
RoomUpdate.AppendString(Client.GetHabbo().Gender.ToLower());
RoomUpdate.AppendString(Client.GetHabbo().Motto);
RoomUpdate.AppendInt32(Client.GetHabbo().AchievementPoints);
Client.GetHabbo().CurrentRoom.SendMessage(RoomUpdate);
}
break;
}
case "updaterooms":
{
uint OwnerId = Convert.ToUInt32(Params[0]);
string Owner = Params[1];
foreach (Room room in MercuryEnvironment.GetGame().GetRoomManager().loadedRooms.Values)
{
if (room.OwnerId == OwnerId)
{
MercuryEnvironment.GetGame().GetRoomManager().UnloadRoom(room);
room.RequestReload();
}
}
break;
}
case "addtoinventory":
{
uint UserId = Convert.ToUInt32(Params[0]);
int ItemId = Convert.ToInt32(Params[1]);
Client = MercuryEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
if (Client != null && Client.GetHabbo() != null && Client.GetHabbo().GetInventoryComponent() != null)
{
Client.GetHabbo().GetInventoryComponent().UpdateItems(true);
Client.GetHabbo().GetInventoryComponent().SendNewItems(ItemId);
}
break;
}
case "updatecredits":
{
uint UserId = Convert.ToUInt32(Params[0]);
int NewCredits = Convert.ToInt32(Params[1]);
Client = MercuryEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
if (Client != null && Client.GetHabbo() != null)
{
Client.GetHabbo().Credits = NewCredits;
Client.GetHabbo().UpdateCreditsBalance();
}
break;
}
case "updatesubscription":
{
uint UserId = Convert.ToUInt32(Params[0]);
int DurationSeconds = Convert.ToInt32(Params[1]);
Client = MercuryEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
if (Client != null && Client.GetHabbo() != null)
{
Client.GetHabbo().GetSubscriptionManager().ReloadSubscription(1, DurationSeconds, Client);
Client.GetHabbo().SerializeClub();
Client.SendMessage(new ServerMessage(Outgoing.UpdateShop));
}
break;
}
case "senduser":
{
uint UserId = Convert.ToUInt32(Params[0]);
int RoomId = Convert.ToInt32(Params[1]);
Client = MercuryEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
if (Client != null)
{
ServerMessage SendUser = new ServerMessage(Outgoing.RoomForwardMessageComposer);
SendUser.AppendInt32(RoomId);
Client.SendMessage(SendUser);
}
}
IL_3A3:
Logging.WriteLine("[MUS SOCKET] Comando MUS procesado correctamente: '" + text + "'", ConsoleColor.Green);
return;
}
IL_38B:
Logging.WriteLine("[MUS SOCKET] Paquete MUS no reconocido: " + text + "//" + data, ConsoleColor.DarkRed);
}
public static string MergeParams(string[] Params, int Start)
{
StringBuilder stringBuilder = new StringBuilder();
checked
{
for (int i = 0; i < Params.Length; i++)
{
if (i >= Start)
{
if (i > Start)
{
stringBuilder.Append(" ");
}
stringBuilder.Append(Params[i]);
}
}
return stringBuilder.ToString();
}
}
}
}
But it works not (i have now 2 build errors) image:
http://i57.tinypic.com/euoe15.png @FatalLulz can you post the whole code like mine? (but then fixed?)