namespace Holo.Managers { using Holo; using Holo.Virtual.Rooms; using Ion.Storage; using System; using System.Collections; using System.Data; using System.Runtime.InteropServices; using System.Threading; public static class roomManager { private static int _peakRoomCount; public static Hashtable _roomLayOut = new Hashtable(); private static Hashtable _Rooms = new Hashtable(); private static Thread CycleWatcher; private static Thread MAINCYCLETHREAD; public static void addRoom(int roomID, virtualRoom Room) { if (!_Rooms.ContainsKey(roomID)) { _Rooms.Add(roomID, Room); if (_Rooms.Count > _peakRoomCount) { _peakRoomCount = _Rooms.Count; } } } public static bool containsRoom(int roomID) { return _Rooms.ContainsKey(roomID); } private static void CYCLEALLSTATUSES() { Label_0000: try { if (_Rooms.Count > 0) { CYCLESTATUSUTILS.CYCLESTARTTIME = DateTime.Now; CYCLESTATUSUTILS.REFRESHROOMLIST(); try { foreach (virtualRoom room in CYCLESTATUSUTILS.SAFEROOMLIST.Values) { room.cycleStatuses(); } } catch (Exception exception) { Out.PrimaryErrorWriter("MAINCYCLETHREADERROR\r\n" + exception.ToString()); } int gETSLEEPTIME = CYCLESTATUSUTILS.GETSLEEPTIME; if (gETSLEEPTIME > 0) { Thread.Sleep(gETSLEEPTIME); } } else { Thread.Sleep(0x7d0); } goto Label_0000; } catch (Exception exception2) { Out.SecundaryErrorWriter(exception2.ToString()); goto Label_0000; } } public static virtualRoom getRoom(int roomID) { if (_Rooms.ContainsKey(roomID)) { return (virtualRoom) _Rooms[roomID]; } return null; } public static string getRoomState(int State) { if (State == 1) { return "closed"; } if (State == 2) { return "password"; } return "open"; } public static int getRoomState(string State) { if (State == "closed") { return 1; } if (State == "password") { return 2; } return 0; } public static void Init() { Out.WriteLine("Starting cyclesystem"); CYCLESTATUSUTILS.MAXCYCLECONFIGTIME = 410; StartThread(); CycleWatcher = new Thread(new ThreadStart(roomManager.WatchCycleThread)); CycleWatcher.Start(); Out.WriteLine("Cyclethread ready"); } public static void refreshWallitem(int roomID, int itemID, string cctName, string wallPosition, string itemVariable, int templateID, virtualRoom TheRoom) { try { templateID = 0x3ea; if (TheRoom != null) { TheRoom.sendData(string.Concat(new object[] { "AU", itemID, Convert.ToChar(2), Encoding.encodeVL64(templateID), "[nO", wallPosition, Convert.ToChar(2), itemVariable, Convert.ToChar(2) })); } } catch (Exception exception) { Out.PrimaryErrorWriter("Moonlightbug:\r\n" + exception.ToString()); } } public static void removeRoom(int roomID) { if (_Rooms.ContainsKey(roomID)) { _Rooms.Remove(roomID); updateRoomVisitorCount(roomID, 0); using (DatabaseClient client = Eucalypt.dbManager.GetClient()) { client.runQuery("UPDATE rooms SET visitors_now = null WHERE id = '" + roomID + "'"); } GC.Collect(); } } public static void ShutDownManager() { try { try { lock (_Rooms) { foreach (virtualRoom room in _Rooms) { try { room.Crash(); continue; } catch { continue; } } } _Rooms.Clear(); _Rooms = null; } catch { } } catch { } try { _roomLayOut.Clear(); _roomLayOut = null; } catch { } } private static void StartThread() { try { if (MAINCYCLETHREAD.IsAlive) { MAINCYCLETHREAD.Abort(); } } catch { } MAINCYCLETHREAD = new Thread(new ThreadStart(roomManager.CYCLEALLSTATUSES)); MAINCYCLETHREAD.Start(); } public static void updateRoomVisitorCount(int roomID, int visitorCount) { using (DatabaseClient client = Eucalypt.dbManager.GetClient()) { client.runQuery(string.Concat(new object[] { "UPDATE rooms SET visitors_now = '", visitorCount, "' WHERE id = '", roomID, "' LIMIT 1" })); } } private static void WatchCycleThread() { while (true) { if (CYCLESTATUSUTILS.GETSPENTTIME > 0xbb8) { try { MAINCYCLETHREAD.Abort(); } catch { } StartThread(); MAINCYCLETHREAD = null; } Thread.Sleep(0x7d0); } } public static int peakRoomCount { get { return _peakRoomCount; } } public static int roomCount { get { return _Rooms.Count; } } [StructLayout(LayoutKind.Sequential, Size=1)] private struct CYCLESTATUSUTILS { private static int mConfigTime; private static Hashtable mStorage; private static DateTime mStart; public static int MAXCYCLECONFIGTIME { get { return mConfigTime; } set { mConfigTime = value; } } public static Hashtable SAFEROOMLIST { get { return mStorage; } } public static void REFRESHROOMLIST() { if (mStorage == null) { mStorage = new Hashtable(); } if (mStorage.Count != 0) { mStorage.Clear(); } mStorage = (Hashtable) roomManager._Rooms.Clone(); } public static DateTime CYCLESTARTTIME { get { return mStart; } set { mStart = value; } } public static int GETSLEEPTIME { get { TimeSpan span = (TimeSpan) (DateTime.Now - mStart); return (mConfigTime - span.Milliseconds); } } public static int GETSPENTTIME { get { TimeSpan span = (TimeSpan) (DateTime.Now - mStart); return span.Milliseconds; } } } public static class moodlight { public static string getSettings(int roomID) { try { DataRow row; using (DatabaseClient client = Eucalypt.dbManager.GetClient()) { row = client.getRow("SELECT preset_cur,preset_1,preset_2,preset_3 FROM furniture_moodlight WHERE roomid = '" + roomID + "'"); } string str = Encoding.encodeVL64(3) + Encoding.encodeVL64(Convert.ToInt32(row["preset_cur"])); for (int i = 1; i <= 3; i++) { string[] strArray = row[i].ToString().Split(new char[] { char.Parse(",") }); object obj2 = str; str = string.Concat(new object[] { obj2, Encoding.encodeVL64(i), Encoding.encodeVL64(int.Parse(strArray[0])), strArray[1], Convert.ToChar(2), Encoding.encodeVL64(int.Parse(strArray[2])) }); } return str; } catch { return null; } } public static void setSettings(int roomID, bool isEnabled, int presetID, int bgState, string presetColour, int alphaDarkF, virtualRoom Room) { int num; string str; string str3; int templateID = 0; using (DatabaseClient client = Eucalypt.dbManager.GetClient()) { num = client.getInt("SELECT id FROM furniture_moodlight WHERE roomid = '" + roomID + "' LIMIT 1"); } if (!isEnabled) { string str2; using (DatabaseClient client2 = Eucalypt.dbManager.GetClient()) { str2 = client2.getString("SELECT var FROM furniture WHERE id = '" + num + "'"); templateID = client2.getInt("SELECT tid FROM furniture WHERE id = '" + num + "'"); } if (str2.Substring(0, 1) == "2") { str = "1" + str2.Substring(1); } else { str = "2" + str2.Substring(1); } using (DatabaseClient client3 = Eucalypt.dbManager.GetClient()) { client3.runQuery("UPDATE furniture SET var = '" + str + "' WHERE id = '" + num.ToString() + "' LIMIT 1"); goto Label_026E; } } str = "2," + presetID.ToString() + "," + bgState.ToString() + "," + presetColour + "," + alphaDarkF.ToString(); using (DatabaseClient client4 = Eucalypt.dbManager.GetClient()) { client4.AddParamWithValue("var", str); client4.AddParamWithValue("preset", bgState.ToString() + ", " + presetColour + ", " + alphaDarkF.ToString()); client4.runQuery("UPDATE furniture SET var = @var WHERE id = '" + num.ToString() + "' LIMIT 1"); client4.runQuery("UPDATE furniture_moodlight SET preset_cur = '" + presetID.ToString() + "',preset_" + presetID.ToString() + "= @preset WHERE id = '" + num.ToString() + "' LIMIT 1"); } Label_026E: using (DatabaseClient client5 = Eucalypt.dbManager.GetClient()) { str3 = client5.getString("SELECT wallpos FROM furniture WHERE id = '" + num + "'"); } roomManager.refreshWallitem(roomID, num, "roomdimmer", str3, str, templateID, Room); } } } }