[Uber] Process Engine Fix?

Results 1 to 23 of 23
  1. #1
    Account Upgraded | Title Enabled! SpazzEmu is offline
    MemberRank
    Jun 2010 Join Date
    Warwick, UKLocation
    444Posts

    [Uber] Process Engine Fix?

    Try Replacing your RoomManager.cs 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;   //Why????????
                this.EngineThread.Start();
    
                this.RoomsToUnload = new List<uint>();
                if (EngineThread == null)
                {
                    this.EngineThread.Start();
                }
    
            }
    
            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()
            {
                try
                {
                    Thread.Sleep(5000);
                  
    
                    while (true)
                    {
                        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;
                                }
    
                                Room.ProcessRoom();
                            }
    
    
    
                            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 (InvalidOperationException)
                        {
    EngineThread = null;
                        }
    
                        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 (Exception) { EngineThread = null; }
            }
    
            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.Hidewall, 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 (Models[Model].VipOnly && !Session.GetHabbo().HasFuse("fuse_use_vip_room_layouts"))
                {
                    Session.SendNotif("You must be an VIP to choose this room.");
                    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, "");
            }
        }
    }
    If the Process Engine Dies it should make EngineThread = null restarting the thread

    Credits
    me %50 for Fix
    Meth0d %50 UberEmu
    Last edited by SpazzEmu; 05-10-10 at 10:19 PM.


  2. #2
    Banned PEjump2 is offline
    BannedRank
    Jan 2010 Join Date
    The NetherlandsLocation
    2,838Posts

    Re: [Uber] Process Engine Fix?

    Nice fix :p

  3. #3
    Account Upgraded | Title Enabled! SpazzEmu is offline
    MemberRank
    Jun 2010 Join Date
    Warwick, UKLocation
    444Posts

    Re: [Uber] Process Engine Fix?

    ^ And you said I can't code I'm just to busy coding Java

  4. #4
    Banned PEjump2 is offline
    BannedRank
    Jan 2010 Join Date
    The NetherlandsLocation
    2,838Posts

    Re: [Uber] Process Engine Fix?

    Quote Originally Posted by SpazzEmu View Post
    ^ And you said I can't code I'm just to busy coding Java
    'k then i say from now: Spazz can't code C# :P

  5. #5
    yerro Adde is offline
    MemberRank
    Feb 2010 Join Date
    none ur bizzLocation
    2,731Posts

    Re: [Uber] Process Engine Fix?

    great fix, and pejump2 stop post shit like dat ^ it's spam.

  6. #6
    Account Upgraded | Title Enabled! SpazzEmu is offline
    MemberRank
    Jun 2010 Join Date
    Warwick, UKLocation
    444Posts

    Re: [Uber] Process Engine Fix?

    Quote Originally Posted by PEjump2 View Post
    'k then i say from now: Spazz can't code C# :P
    I think the Post above is C#

  7. #7
    swagggggg Livar is offline
    MemberRank
    Oct 2008 Join Date
    United KingdomLocation
    2,272Posts

    Re: [Uber] Process Engine Fix?

    Nice, needed it mate!

  8. #8
    Banned PEjump2 is offline
    BannedRank
    Jan 2010 Join Date
    The NetherlandsLocation
    2,838Posts

    Re: [Uber] Process Engine Fix?

    Quote Originally Posted by SpazzEmu View Post
    I think the Post above is C#
    But eh what the difference with the normal one? :P

  9. #9
    Account Upgraded | Title Enabled! SpazzEmu is offline
    MemberRank
    Jun 2010 Join Date
    Warwick, UKLocation
    444Posts

    Re: [Uber] Process Engine Fix?

    Quote Originally Posted by PEjump2 View Post
    But eh what the difference with the normal one? :P
    this makes EngineThread = null on error that should restart the EngineThread

  10. #10
    Banned PEjump2 is offline
    BannedRank
    Jan 2010 Join Date
    The NetherlandsLocation
    2,838Posts

    Re: [Uber] Process Engine Fix?

    Quote Originally Posted by SpazzEmu View Post
    this makes EngineThread = null on error that should restart the EngineThread
    'k but that still doesn't fix the crashes, the best thing is recoding the whole socket system so that the user crashes and not the emulator.

  11. #11
    Account Upgraded | Title Enabled! StrongFaith is offline
    MemberRank
    Aug 2010 Join Date
    .PHP filesLocation
    268Posts

    Re: [Uber] Process Engine Fix?

    Nice 10/10

  12. #12
    Account Upgraded | Title Enabled! SpazzEmu is offline
    MemberRank
    Jun 2010 Join Date
    Warwick, UKLocation
    444Posts

    Re: [Uber] Process Engine Fix?

    Quote Originally Posted by PEjump2 View Post
    'k but that still doesn't fix the crashes, the best thing is recoding the whole socket system so that the user crashes and not the emulator.
    working on it

  13. #13
    Alpha Member Zak© is offline
    MemberRank
    Oct 2007 Join Date
    2,693Posts

    Re: [Uber] Process Engine Fix?

    Least its helps. nice spazz

  14. #14
    Account Upgraded | Title Enabled! Tyerial is offline
    MemberRank
    May 2005 Join Date
    On a RockLocation
    249Posts

    Re: [Uber] Process Engine Fix?

    Quote Originally Posted by SpazzEmu View Post
    working on it
    thanks spazz =D cant wait for the other fixes just upset u closed ur project down =/

  15. #15
    Account Upgraded | Title Enabled! iJakey is offline
    MemberRank
    May 2010 Join Date
    355Posts

    Re: [Uber] Process Engine Fix?

    Instead of making tiny edits, and just null'ing things how about re-coding it so it doesn't crash?? Sounds good eh.

  16. #16
    Account Upgraded | Title Enabled! Tyerial is offline
    MemberRank
    May 2005 Join Date
    On a RockLocation
    249Posts

    Re: [Uber] Process Engine Fix?

    Quote Originally Posted by iJakey View Post
    Instead of making tiny edits, and just null'ing things how about re-coding it so it doesn't crash?? Sounds good eh.
    at least hes trying to make a stable one.... i still think all the coders of the Habbos emu should get together to MAKE One awesome stable server and nto worry about who got the bigger brain!

  17. #17
    Account Upgraded | Title Enabled! MikeDavies is offline
    MemberRank
    Aug 2010 Join Date
    WalesLocation
    629Posts

    Re: [Uber] Process Engine Fix?

    Quote Originally Posted by Tyerial View Post
    at least hes trying to make a stable one.... i still think all the coders of the Habbos emu should get together to MAKE One awesome stable server and nto worry about who got the bigger brain!
    One problem there. Everyone wants their e-penis to be bigger. Theres no way you could get a lot of coders together.

    And some people like to work alone

    And if you worked all together, one guy is gonna leak it coz you wouldnt let him code a bit of it

    See the problems?

  18. #18
    Account Upgraded | Title Enabled! Tyerial is offline
    MemberRank
    May 2005 Join Date
    On a RockLocation
    249Posts

    Re: [Uber] Process Engine Fix?

    Quote Originally Posted by MikeDavies View Post
    One problem there. Everyone wants their e-penis to be bigger. Theres no way you could get a lot of coders together.

    And some people like to work alone

    And if you worked all together, one guy is gonna leak it coz you wouldnt let him code a bit of it

    See the problems?
    E-penis is overrated -_-

  19. #19
    Account Upgraded | Title Enabled! Flurrie is offline
    MemberRank
    Jun 2010 Join Date
    281Posts

    Re: [Uber] Process Engine Fix?

    fixed ages ago cos of spazzlakes forum

  20. #20
    Lurking since '06 1ntel is offline
    MemberRank
    Jul 2006 Join Date
    401Posts

    Re: [Uber] Process Engine Fix?

    You know this does absolutely nothing correct, the Enumerator is not going to Enumerate through any rooms then items because the Lists its Enumerating are going to get reset on another thread...

    You need to create a lock statement which disposes the enumerator on finish and releases the lock to have a 100% stable Enumerator.


    Whats happening there is its enumerating through the items with no lock, so it can be modified at any time and then once modified.... BAM, the enumerator resets its current position, doesn't enumerate through and causes an exception then its going to restart and do the same, over and over and over again.

    Real fix: make a Monitor.Enter and Monitor.Exit so it disposes the enumerator and exits the lock when finished.

  21. #21
    Account Upgraded | Title Enabled! Flurrie is offline
    MemberRank
    Jun 2010 Join Date
    281Posts

    Re: [Uber] Process Engine Fix?

    Quote Originally Posted by matty13 View Post
    You know this does absolutely nothing correct, the Enumerator is not going to Enumerate through any rooms then items because the Lists its Enumerating are going to get reset on another thread...

    You need to create a lock statement which disposes the enumerator on finish and releases the lock to have a 100% stable Enumerator.


    Whats happening there is its enumerating through the items with no lock, so it can be modified at any time and then once modified.... BAM, the enumerator resets its current position, doesn't enumerate through and causes an exception then its going to restart and do the same, over and over and over again.

    Real fix: make a Monitor.Enter and Monitor.Exit so it disposes the enumerator and exits the lock when finished.
    Yh but this is kinda for noobs, not every1 is as good as you btw?

    like wats up with "real fix: make monitor.enter and monitor.exit? what is that srsly? talk a little more better towards users who are trying

  22. #22
    Account Upgraded | Title Enabled! iJakey is offline
    MemberRank
    May 2010 Join Date
    355Posts

    Re: [Uber] Process Engine Fix?

    There methods already given to you by the threading class, in replace of lock ().

  23. #23
    Lurking since '06 1ntel is offline
    MemberRank
    Jul 2006 Join Date
    401Posts

    Re: [Uber] Process Engine Fix?

    Quote Originally Posted by Flurrie View Post
    Yh but this is kinda for noobs, not every1 is as good as you btw?

    like wats up with "real fix: make monitor.enter and monitor.exit? what is that srsly? talk a little more better towards users who are trying
    Well i am working on a fix still i havn't got one working myself yet, but that is how i am approaching it because that is what the issue is here, is the lock not releasing properly.

    Basically Monitor.Enter / Exit is a longer way of typing lock (obj) on something, you can use the Monitor.Enter / Exit to like create your own lock, be more advanced with lock basically.

    But yeah basically remove the process engine, no one can walk, but you can type etc and the Hotel will be PERFECTLY stable. But when you lock it thats where it deadlocks and causes hotel to become unstable.



Advertisement