ProcessEngine Fix (Recoded)
Download this:
UppIT - Free File hosting - RoomProcess.cs
Add this to: Uber >> HabboHotel >> Rooms.
Replace whole RoomManager with:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Threading;
using Uber.HabboHotel.Items;
using Uber.HabboHotel.GameClients;
using Uber.Storage;
namespace Uber.HabboHotel.Rooms
{
class RoomManager
{
public readonly int MAX_PETS_PER_ROOM = 5;
private Dictionary<uint, Room> Rooms;
private Dictionary<string, RoomModel> Models;
private List<TeleUserData> TeleActions;
private Thread EngineThread;
private List<uint> RoomsToUnload;
public int LoadedRoomsCount
{
get
{
return this.Rooms.Count;
}
}
public RoomManager()
{
this.Rooms = new Dictionary<uint, Room>();
this.Models = new Dictionary<string, RoomModel>();
this.TeleActions = new List<TeleUserData>();
this.EngineThread = new Thread(ProcessEngine);
this.EngineThread.Name = "Room Engine";
this.EngineThread.Priority = ThreadPriority.AboveNormal;
this.EngineThread.Start();
this.RoomsToUnload = new List<uint>();
}
public void AddTeleAction(TeleUserData Act)
{
this.TeleActions.Add(Act);
}
public List<Room> GetEventRoomsForCategory(int Category)
{
List<Room> EventRooms = new List<Room>();
Dictionary<uint, Room>.Enumerator eRooms = this.Rooms.GetEnumerator();
while (eRooms.MoveNext())
{
Room Room = eRooms.Current.Value;
if (Room.Event == null)
{
continue;
}
if (Category > 0 && Room.Event.Category != Category)
{
continue;
}
EventRooms.Add(Room);
}
return EventRooms;
}
public void ProcessEngine()
{
Thread.Sleep(5000);
while (true)
{
try
{
DateTime ExecutionStart = DateTime.Now;
try
{
Dictionary<uint, Room>.Enumerator eRooms = this.Rooms.GetEnumerator();
while (eRooms.MoveNext())
{
Room Room = eRooms.Current.Value;
if (!Room.KeepAlive)
{
continue;
}
RoomProcess.ProcessEngine(100, Room);
}
foreach (uint RoomId in this.RoomsToUnload)
{
UnloadRoom(RoomId);
}
this.RoomsToUnload.Clear();
List<TeleUserData>.Enumerator eTeleActions = this.TeleActions.GetEnumerator();
while (eTeleActions.MoveNext())
{
eTeleActions.Current.Execute();
}
this.TeleActions.Clear();
}
catch
{
RoomProcess.Faked = 1;
}
finally
{
DateTime ExecutionComplete = DateTime.Now;
TimeSpan Diff = ExecutionComplete - ExecutionStart;
double sleepTime = 500 - Diff.TotalMilliseconds;
if (sleepTime < 0)
{
sleepTime = 0;
}
if (sleepTime > 500)
{
sleepTime = 500;
}
Thread.Sleep((int)Math.Floor(sleepTime));
}
}
catch { RoomProcess.Faked = 1; }
}
}
public void LoadModels()
{
DataTable Data = null;
Models.Clear();
using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
{
Data = dbClient.ReadDataTable("SELECT SQL_NO_CACHE id,door_x,door_y,door_z,door_dir,heightmap,public_items,club_only FROM room_models");
}
if (Data == null)
{
return;
}
foreach (DataRow Row in Data.Rows)
{
Models.Add((string)Row["id"], new RoomModel((string)Row["id"], (int)Row["door_x"],
(int)Row["door_y"], (Double)Row["door_z"], (int)Row["door_dir"], (string)Row["heightmap"],
(string)Row["public_items"], UberEnvironment.EnumToBool(Row["club_only"].ToString())));
}
}
public RoomModel GetModel(string Model)
{
if (Models.ContainsKey(Model))
{
return Models[Model];
}
return null;
}
public RoomData GenerateNullableRoomData(uint RoomId)
{
if (GenerateRoomData(RoomId) != null)
{
return GenerateRoomData(RoomId);
}
RoomData Data = new RoomData();
Data.FillNull(RoomId);
return Data;
}
public RoomData GenerateRoomData(uint RoomId)
{
RoomData Data = new RoomData();
if (IsRoomLoaded(RoomId))
{
Data.Fill(GetRoom(RoomId));
}
else
{
DataRow Row = null;
using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
{
Row = dbClient.ReadDataRow("SELECT SQL_NO_CACHE * FROM rooms WHERE id = '" + RoomId + "' LIMIT 1");
}
if (Row == null)
{
return null;
}
Data.Fill(Row);
}
return Data;
}
public Boolean IsRoomLoaded(uint RoomId)
{
if (GetRoom(RoomId) != null)
{
return true;
}
return false;
}
public void LoadRoom(uint Id)
{
if (IsRoomLoaded(Id))
{
return;
}
RoomData Data = GenerateRoomData(Id);
if (Data == null)
{
return;
}
Room Room = new Room(Data.Id, Data.Name, Data.Description, Data.Type, Data.Owner, Data.Category, Data.State,
Data.UsersMax, Data.ModelName, Data.CCTs, Data.Score, Data.Tags, Data.AllowPets, Data.AllowPetsEating,
Data.AllowWalkthrough, Data.HideWalls, Data.Icon, Data.Password, Data.Wallpaper, Data.Floor, Data.Landscape);
try
{
Rooms.Add(Room.RoomId, Room);
}
catch (NullReferenceException e)
{ UberEnvironment.GetLogging().WriteLine(e.ToString(), Core.LogLevel.Error); }
Room.InitBots();
Room.InitPets();
UberEnvironment.GetLogging().WriteLine("[RoomMgr] Loaded room: \"" + Room.Name + "\" (ID: " + Id + ")", Uber.Core.LogLevel.Information);
}
public void RequestRoomUnload(uint Id)
{
if (!IsRoomLoaded(Id))
{
return;
}
GetRoom(Id).KeepAlive = false;
RoomsToUnload.Add(Id);
}
public void UnloadRoom(uint Id)
{
Room Room = GetRoom(Id);
if (Room == null)
{
return;
}
Room.Destroy();
Rooms.Remove(Id);
UberEnvironment.GetLogging().WriteLine("[RoomMgr] Unloaded room: \"" + Room.Name + "\" (ID: " + Id + ")", Uber.Core.LogLevel.Information);
}
public Room GetRoom(uint RoomId)
{
Dictionary<uint, Room>.Enumerator eRooms = this.Rooms.GetEnumerator();
while (eRooms.MoveNext())
{
Room Room = eRooms.Current.Value;
if (Room.RoomId == RoomId)
{
return Room;
}
}
return null;
}
public RoomData CreateRoom(GameClient Session, string Name, string Model)
{
Name = UberEnvironment.FilterInjectionChars(Name);
if (!Models.ContainsKey(Model))
{
Session.SendNotif("Sorry, this room model has not been added yet. Try again later.");
return null;
}
if (Models[Model].ClubOnly && !Session.GetHabbo().HasFuse("fuse_use_special_room_layouts"))
{
Session.SendNotif("You must be an Uber Club member to use that room layout.");
return null;
}
if (Name.Length < 3)
{
Session.SendNotif("Room name is too short for room creation!");
return null;
}
using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
{
dbClient.AddParamWithValue("caption", Name);
dbClient.AddParamWithValue("model", Model);
dbClient.AddParamWithValue("username", Session.GetHabbo().Username);
dbClient.ExecuteQuery("INSERT INTO rooms (roomtype,caption,owner,model_name) VALUES ('private',@caption,@username,@model)");
}
uint RoomId = 0;
using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
{
dbClient.AddParamWithValue("caption", Name);
dbClient.AddParamWithValue("username", Session.GetHabbo().Username);
RoomId = (uint)dbClient.ReadDataRow("SELECT SQL_NO_CACHE id FROM rooms WHERE owner = @username AND caption = @caption ORDER BY id DESC")[0];
}
return GenerateRoomData(RoomId);
}
}
class TeleUserData
{
private RoomUser User;
private uint RoomId;
private uint TeleId;
public TeleUserData(RoomUser User, uint RoomId, uint TeleId)
{
this.User = User;
this.RoomId = RoomId;
this.TeleId = TeleId;
}
public void Execute()
{
if (User == null || User.IsBot)
{
return;
}
User.GetClient().GetHabbo().IsTeleporting = true;
User.GetClient().GetHabbo().TeleporterId = TeleId;
User.GetClient().GetMessageHandler().PrepareRoomForUser(RoomId, "");
}
}
}
AND Replace WHOLE void: ProcessRoom() in : Room.cs with:
Code:
public void ProcessRoom()
{
int i = 0;
try
{
// Loop through all furni and process them if they want to be processed
List<RoomItem>.Enumerator eItems = this.Items.GetEnumerator();
while (eItems.MoveNext())
{
try
{
RoomItem Item = eItems.Current;
if (!Item.UpdateNeeded)
{
continue;
}
Item.ProcessUpdates();
}
catch
{
RoomProcess.Faked = 1;
continue;
}
}
// Loop through all users and bots and process them
List<uint> ToRemove = new List<uint>();
List<RoomUser>.Enumerator eUsers = this.UserList.GetEnumerator();
while (eUsers.MoveNext())
{
RoomUser User = eUsers.Current;
User.IdleTime++;
if (!User.IsAsleep && User.IdleTime >= 600)
{
User.IsAsleep = true;
ServerMessage FallAsleep = new ServerMessage(486);
FallAsleep.AppendInt32(User.VirtualId);
FallAsleep.AppendBoolean(true);
SendMessage(FallAsleep);
}
if (User.NeedsAutokick && !ToRemove.Contains(User.HabboId))
{
ToRemove.Add(User.HabboId);
}
if (User.CarryItemID > 0)
{
User.CarryTimer--;
if (User.CarryTimer <= 0)
{
User.CarryItem(0);
}
}
bool invalidSetStep = false;
if (User.SetStep)
{
if (CanWalk(User.SetX, User.SetY, 0, true) || User.AllowOverride || AllowWalkthrough == true) // crap walkthrough fix
{
UserMatrix[User.X, User.Y] = false;
User.X = User.SetX;
User.Y = User.SetY;
User.Z = User.SetZ;
UserMatrix[User.X, User.Y] = true;
UpdateUserStatus(User);
}
else
{
invalidSetStep = true;
}
User.SetStep = false;
}
if (User.PathRecalcNeeded)
{
Pathfinder Pathfinder = new Pathfinder(this, User);
User.GoalX = User.PathRecalcX;
User.GoalY = User.PathRecalcY;
User.Path.Clear();
User.Path = Pathfinder.FindPath();
if (User.Path.Count > 1)
{
User.PathStep = 1;
User.IsWalking = true;
User.PathRecalcNeeded = false;
}
else
{
User.PathRecalcNeeded = false;
User.Path.Clear();
}
}
if (User.IsWalking)
{
if (invalidSetStep || User.PathStep >= User.Path.Count || User.GoalX == User.X && User.Y == User.GoalY)
{
User.Path.Clear();
User.IsWalking = false;
User.RemoveStatus("mv");
User.PathRecalcNeeded = false;
if (User.X == Model.DoorX && User.Y == Model.DoorY && !ToRemove.Contains(User.HabboId) && !User.IsBot)
{
ToRemove.Add(User.HabboId);
}
UpdateUserStatus(User);
}
else
{
int k = (User.Path.Count - User.PathStep) - 1;
Coord NextStep = User.Path[k];
User.PathStep++;
int nextX = NextStep.x;
int nextY = NextStep.y;
User.RemoveStatus("mv");
bool LastStep = false;
if (nextX == User.GoalX && nextY == User.GoalY)
{
LastStep = true;
}
if (CanWalk(nextX, nextY, 0, LastStep) || User.AllowOverride)
{
double nextZ = SqAbsoluteHeight(nextX, nextY);
User.Statusses.Remove("lay");
User.Statusses.Remove("sit");
User.AddStatus("mv", nextX + "," + nextY + "," + nextZ.ToString().Replace(',', '.'));
int newRot = Rotation.Calculate(User.X, User.Y, nextX, nextY);
User.RotBody = newRot;
User.RotHead = newRot;
User.SetStep = true;
User.SetX = BedMatrix[nextX, nextY].x;
User.SetY = BedMatrix[nextX, nextY].y;
User.SetZ = nextZ;
}
else
{
User.IsWalking = false;
}
}
User.UpdateNeeded = true;
}
else
{
if (User.Statusses.ContainsKey("mv"))
{
User.RemoveStatus("mv");
User.UpdateNeeded = true;
}
}
if (User.IsBot)
{
User.BotAI.OnTimerTick();
}
else
{
i++; // we do not count bots. we do not take kindly to their kind 'round 'ere.
}
}
foreach (uint toRemove in ToRemove)
{
RemoveUserFromRoom(UberEnvironment.GetGame().GetClientManager().GetClientByHabbo(toRemove), true, false);
}
// UPDATE idle time
if (i >= 1)
{
this.IdleTime = 0;
}
else
{
this.IdleTime++;
}
// If room has been idle for a while
if (this.IdleTime >= 60)
{
UberEnvironment.GetLogging().WriteLine("[RoomMgr] Requesting unload of idle room - ID#: " + Id, Uber.Core.LogLevel.Debug);
UberEnvironment.GetGame().GetRoomManager().RequestRoomUnload(Id);
}
ServerMessage UPDATEs = SerializeStatusUPDATEs(false);
if (UPDATEs != null)
{
SendMessage(UPDATEs);
}
}
catch
{
RoomProcess.Faked = 1;
}
}
Re: ProcessEngine Fix (Recoded)
Wasn't this already released, By Spazz?
But anyways. Nice release mate, Thanks.
Re: ProcessEngine Fix (Recoded)
what was wrong with the original?
Re: ProcessEngine Fix (Recoded)
Its just crashing, and Walking is freezing Ugly Question.
Re: ProcessEngine Fix (Recoded)
It means that this code ends with the instability of the uber emulator?
Re: ProcessEngine Fix (Recoded)
The difference between this and Spazz released version is that Spazz's code is an 50% fix, and this is almost the total fix :P
Nice release ;]
Re: ProcessEngine Fix (Recoded)
Ok I'll try it features which can bring the concert?
Re: ProcessEngine Fix (Recoded)
@srdanilo2014
This Code Should work By the look at it (Not Tested it my self (Java FTW!)), It Stops the Walking Bug and Stabilizes the emulator
@PEjump2
I think my code was %25 and was Never Tested (Just Edited in Notepad and pasted Hence the "?" at the end of the thread Title)
@wichard
Nice to see people are still developing Uber and Fixing some errors I made also Good Look with Releases!
Thanks
Spazz
Re: ProcessEngine Fix (Recoded)
dis really working? or no
Re: ProcessEngine Fix (Recoded)
Quote:
Originally Posted by
GrandCoder
dis really working? or no
Are u blind?
Rea the other replys before posting a ridiculous question.
Ontopic, great may encourage me to switch from r26 to flash (If it's getting stable)
Re: ProcessEngine Fix (Recoded)
@SpazzEmu
I tried to use your fix, but it does'nt work.
Re: ProcessEngine Fix (Recoded)
Quote:
Originally Posted by
GrandCoder
Shut ur mouth kid u little newbie to rz u should read comments some say it dosnt and some says it does so im making sure before it fucks my emu iight so relax ur self -.-. And i Asked Wichard Not you .. MYOB
ONT: if it works great 10/10
How does that make him a newbie? What exactly have you contributed to the community other than a simple add-on for UberCMS?
No offense, I'm just sick of seeing people like you thinking they're some 1337 coder or something because they can "code" simple PHP scripts.
Ontopic: Nice release, I'll try this.
Re: ProcessEngine Fix (Recoded)
Looking good wichard. Hopefully it will help Uber users, as of myself, I don't use Uber so won't help me. But still nice :P
Re: ProcessEngine Fix (Recoded)
Quote:
Originally Posted by
GrandCoder
Shut ur mouth kid u little newbie to rz u should read comments some say it dosnt and some says it does so im making sure before it fucks my emu iight so relax ur self -.-. And i Asked Wichard Not you .. MYOB
ONT: if it works great 10/10
this is prob not the best way to communicate on the forum...
Re: ProcessEngine Fix (Recoded)
If your "GrandCoder" it is.v:thumbup1:
ON-TOPIC: Nice release, me and matty were trying to do kind of the same thing, just never got to it.