namespace Holo.Managers { using Holo; using Holo.Virtual.Users; using Ion.Storage; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Text; using System.Threading; public static class userManager { private static int _peakUserCount; public static Hashtable _Users = new Hashtable(); private static Thread pingChecker; public static void addChatMessage(string userName, int roomID, string Message) { using (DatabaseClient client = Eucalypt.dbManager.GetClient()) { client.AddParamWithValue("username", userName); client.AddParamWithValue("roomid", roomID); client.AddParamWithValue("message", Message); client.runQuery("INSERT INTO system_chatlog (username,roomid,mtime,message) VALUES (@username,@roomid,CURRENT_TIMESTAMP,@message)"); } } public static void addUser(int userID, virtualUser User) { if (_Users.ContainsKey(userID)) { ((virtualUser) _Users[userID]).Disconnect(); if (_Users.ContainsKey(userID)) { _Users.Remove(userID); } } using (DatabaseClient client = Eucalypt.dbManager.GetClient()) { client.AddParamWithValue("name", User._Username); if (User.connectionRemoteIP == client.getString("SELECT ipaddress_last FROM users WHERE name = @name LIMIT 1")) { _Users.Add(userID, User); client.runQuery("UPDATE users SET ticket_sso = NULL WHERE id = '" + userID + "' LIMIT 1"); Out.WriteLine(string.Concat(new object[] { "User ", userID, " logged in. [", User._Username, "]" }), Out.logFlags.BelowStandardAction); } else { User.Disconnect(0x3e8); User.sendData("BKInvalid Session Ticket, please login again!"); } if (_Users.Count > client.getInt("SELECT onlinecount_peak FROM system")) { _peakUserCount = _Users.Count; } } } private static void checkPings() { List list = new List(); while (true) { try { foreach (virtualUser user in _Users.Values) { if (user.pingOK) { user.pingOK = false; user.sendData("@r"); } else { Out.WriteLine(user._Username + " timed out."); list.Add(user); } } } catch { } foreach (virtualUser user in list) { user.Disconnect(); } list.Clear(); Thread.Sleep(0xea60); Out.WriteTrace("Checking virtual user pings"); } } public static bool containsUser(int userID) { return _Users.ContainsKey(userID); } public static bool containsUser(string userName) { int key = getUserID(userName); return _Users.ContainsKey(key); } public static string generateBanReport(int userID) { string str4; try { DataRow row; DataRow row2; DatabaseClient client; DataRow row3; using (client = Eucalypt.dbManager.GetClient()) { row2 = client.getRow("SELECT date_expire,descr,ipaddress FROM users_bans WHERE userid = '" + userID + "'"); row = client.getRow("SELECT name,rank,ipaddress_last FROM users WHERE id = '" + userID + "'"); } if ((row2.Table.Rows.Count == 0) || (row.Table.Rows.Count == 0)) { return "holo.cast.banreport.null"; } string str = "-"; string str2 = "not available"; string str3 = "not available"; using (client = Eucalypt.dbManager.GetClient()) { row3 = client.getRow("SELECT userid,note,timestamp FROM system_stafflog WHERE action = 'ban' AND targetid = '" + userID + "' ORDER BY id ASC"); } if (row3.Table.Rows.Count > 0) { if (Convert.ToString(row3[1]) != "") { str = Convert.ToString(row3[1]); } using (client = Eucalypt.dbManager.GetClient()) { str2 = client.getString("SELECT name FROM users WHERE id = '" + Convert.ToString(row3[0]) + "'"); } str3 = Convert.ToString(row3[2]); } StringBuilder builder = new StringBuilder(stringManager.getString("banreport_header") + " "); builder.Append(string.Concat(new object[] { Convert.ToString(row[0]), " [", userID, "]\r" })); builder.Append(stringManager.getString("common_userrank") + ": " + Convert.ToString(row[1]) + "\r"); builder.Append(stringManager.getString("common_ip") + ": " + Convert.ToString(row[2]) + "\r"); builder.Append(stringManager.getString("banreport_banner") + ": " + str2 + "\r"); builder.Append(stringManager.getString("banreport_posted") + ": " + str3 + "\r"); builder.Append(stringManager.getString("banreport_expires") + ": " + Convert.ToString(row2[0]) + "\r"); builder.Append(stringManager.getString("banreport_reason") + ": " + Convert.ToString(row2[1]) + "\r"); bool flag2 = Convert.ToString(row2[2]) != ""; builder.Append(stringManager.getString("banreport_ipbanflag") + ": " + flag2.ToString().ToLower() + "\r"); builder.Append(stringManager.getString("banreport_staffnote") + ": " + str); str4 = builder.ToString(); } catch (Exception exception) { throw exception; } return str4; } public static string generateBanReport(string IP) { string str4; try { DataRow row; DatabaseClient client; DataRow row2; DataColumn column; using (client = Eucalypt.dbManager.GetClient()) { row = client.getRow("SELECT userid,date_expire,descr FROM users_bans WHERE ipaddress = '" + IP + "'"); } if (row.Table.Rows.Count == 0) { return "holo.cast.banreport.null"; } string str = "-"; string str2 = "not available"; string str3 = "not available"; using (client = Eucalypt.dbManager.GetClient()) { row2 = client.getRow("SELECT userid,note,timestamp FROM system_stafflog WHERE action = 'ban' AND targetid = '" + Convert.ToString(row[0]) + "' ORDER BY id ASC"); } if (row2.Table.Rows.Count > 0) { if (Convert.ToString(row2[1]) != "") { str = Convert.ToString(row2[1]); } using (client = Eucalypt.dbManager.GetClient()) { str2 = client.getString("SELECT name FROM users WHERE id = '" + Convert.ToString(row2[0]) + "'"); } str3 = Convert.ToString(row2[2]); } StringBuilder builder = new StringBuilder(stringManager.getString("banreport_header") + " "); builder.Append(IP + "\r"); builder.Append(stringManager.getString("banreport_banner") + ": " + str2 + "\r"); builder.Append(stringManager.getString("banreport_posted") + ": " + str3 + "\r"); builder.Append(stringManager.getString("banreport_expires") + ": " + Convert.ToString(row[0]) + "\r"); builder.Append(stringManager.getString("banreport_reason") + ": " + Convert.ToString(row[1]) + "\r"); bool flag2 = Convert.ToString(row[2]) != ""; builder.Append(stringManager.getString("banreport_ipbanflag") + ": " + flag2.ToString().ToLower() + "\r"); builder.Append(stringManager.getString("banreport_staffnote") + ": " + str + "\r\r"); using (client = Eucalypt.dbManager.GetClient()) { column = client.getColumn("SELECT name FROM users WHERE ipaddress_last = '" + IP + "'"); } builder.Append(stringManager.getString("banreport_affectedusernames") + ":"); foreach (DataRow row3 in column.Table.Rows) { builder.Append("\r - " + Convert.ToString(row["name"])); } str4 = builder.ToString(); } catch (Exception exception) { throw exception; } return str4; } public static string generateCommands(byte Rank, int userID) { string[] strArray = null; StringBuilder builder = new StringBuilder("BKYour Commands:"); string str = ""; str = ((((str + "%" + ":im NAME [MESSAGE] - Stuur een bericht naar een vriend%") + ":events - Laat evenementen venster zien%" + ":about - Laat informatie over de server zien%") + ":whosonline - Laat alle gebruikers + rank die online zijn zien%" + ":cleanhand - Verwijderd ALLE items in je hand (geen vergoeding)%") + ":brb - Zegt tegen iedereen dat je weg bent (Max 15 minutes)%" + ":back - Stop met het vertellen dat je weg bent%") + ":hotel/:info/:version - laat de informatie over dit hotel zien.%" + ":staff - Verteld je hoe je de staff kan bereiken%"; if (Rank > 1) { str = (str + "%") + ":chooser - Laat iedereen zien in de kamer%" + ":furni - Laat alle meubels zien in de kamer%"; if (rankManager.containsRight(Rank, "fuse_alert", userID)) { str = str + "%" + ":alert NAME MESSAGE - Sends a moderator alert%"; } if (rankManager.containsRight(Rank, "fuse_room_alert", userID)) { str = str + "%" + ":roomalert MESSAGE - Sends a moderator alert to a whole room%"; } if (rankManager.containsRight(Rank, "fuse_kick", userID)) { str = str + "%" + ":kick [MESSAGE] - Kicks a user from the room they are in%"; } if (rankManager.containsRight(Rank, "fuse_room_kick", userID)) { str = str + "%" + ":roomkick [MESSAGE] - Kicks all users but you from the room"; } if (rankManager.containsRight(Rank, "fuse_mute", userID)) { str = (str + "%") + ":shutup NAME [MESSAGE] - Stops a user from using say/shout%" + ":unmute NAME - Allows a user to say/shout again%"; } if (rankManager.containsRight(Rank, "fuse_room_mute", userID)) { str = (str + "%") + ":roomshutup [MESSAGE] - Stops all users in the room from using say/shout%" + ":roomunmute Allows all users in the room to say/shout again%"; } if (rankManager.containsRight(Rank, "fuse_ban", userID)) { str = str + "%" + ":ban NAME HOURS REASON - Bans a user for the how many hours%"; } if (rankManager.containsRight(Rank, "fuse_superban", userID)) { str = str + "%" + ":superban NAME HOURS REASON - Bans a user and there IP for how many hours%"; } if (rankManager.containsRight(Rank, "fuse_administrator_access", userID)) { str = (((str + "%" + ":ha MESSAGE - Sends an alert to all online users%") + ":offline MINUTES - Informs all online users that the hotel is going offline in how long you said%" + ":refresh - Updates certain parts of the server%") + ":cords - Display your current room position%" + ":teleport - Turns on teleport mode (WARNING: It causes the room to screw up)%") + ":warp X Y - Teleports you the the the location input%" + ":sendme PACKET - Sends a packet to your self (For debuging)%"; } if (rankManager.containsRight(Rank, "fuse_alert", userID)) { str = str + "%" + ":ra MESSAGE - Sends an alert to all online users with the same rank as you%"; } if (rankManager.containsRight(Rank, "fuse_teleport", userID)) { str = (str + "%") + ":teleport - Toggles your movent to teleport mode on/off%" + ":warp X Y - Teleports you to the co-ordinates entered%"; } if (rankManager.containsRight(Rank, "fuse_moderator_access", userID)) { str = str + "%" + ":userinfo NAME/:ui NAME - Displays infomation about a user%"; } } strArray = str.Split("%".ToCharArray()); int num = 30; foreach (string str2 in strArray) { if (num == 0) { builder.Append(Convert.ToChar(1) + "BKYour Commands:"); num = 30; } builder.Append("\r" + str2); num--; } return builder.ToString(); } public static string generateUserInfo(int userID, byte Rank) { DataRow row; DatabaseClient client; using (client = Eucalypt.dbManager.GetClient()) { row = client.getRow(string.Concat(new object[] { "SELECT name,rank,mission,credits,tickets,email,birth,hbirth,ipaddress_last,lastvisit FROM users WHERE id = '", userID, "' AND rank <= ", Rank })); } if (row.Table.Rows.Count == 0) { return stringManager.getString("userinfo_accesserror"); } StringBuilder builder = new StringBuilder(stringManager.getString("userinfo_header") + "\r"); builder.Append(string.Concat(new object[] { stringManager.getString("common_userid"), ": ", userID, "\r" })); builder.Append(stringManager.getString("common_username") + ": " + Convert.ToString(row[0]) + "\r"); builder.Append(stringManager.getString("common_userrank") + ": " + Convert.ToString(row[1]) + "\r"); builder.Append(stringManager.getString("common_usermission") + ": " + Convert.ToString(row[2]) + "\r"); builder.Append(stringManager.getString("common_credits") + ": " + Convert.ToString(row[3]) + "\r"); builder.Append(stringManager.getString("common_tickets") + ": " + Convert.ToString(row[4]) + "\r"); builder.Append(stringManager.getString("common_hbirth") + ": " + Convert.ToString(row[7]) + "\r\r"); builder.Append(stringManager.getString("common_birth") + ": " + Convert.ToString(row[6]) + "\r"); builder.Append(stringManager.getString("common_email") + ": " + Convert.ToString(row[5]) + "\r"); builder.Append(stringManager.getString("common_ip") + ": " + Convert.ToString(row[8]) + "\r\r"); if (_Users.ContainsKey(userID)) { virtualUser user = (virtualUser) _Users[userID]; string str = ""; if (user._roomID == 0) { str = stringManager.getString("common_hotelview"); } else { using (client = Eucalypt.dbManager.GetClient()) { str = string.Concat(new object[] { stringManager.getString("common_room"), " '", client.getString("SELECT name FROM rooms WHERE id = '" + user._roomID + "'"), "' [id: ", user._roomID, ", ", stringManager.getString("common_owner"), ": ", client.getString("SELECT owner FROM rooms WHERE id = '" + user._roomID + "'"), "]" }); } } builder.Append(stringManager.getString("common_location") + ": " + str); } else { builder.Append(stringManager.getString("common_lastaccess") + ": " + Convert.ToString(row[9])); } return builder.ToString(); } public static string generateWhosOnline(bool Admin) { int userCount = userManager.userCount; int num2 = 0; while (userCount > 30) { num2++; userCount -= 30; } num2++; StringBuilder builder = new StringBuilder("BKOnline Users"); if (num2 > 1) { builder.Append(" page 1/" + num2); } builder.Append(" Total online: " + userManager.userCount); int num3 = 30; int num4 = 1; if (Admin) { foreach (DictionaryEntry entry in _Users) { if (num3 == 0) { num4++; builder.Append(string.Concat(new object[] { Convert.ToChar(1), "BKOnline Users page ", num4, "/", num2, " Total online: ", userManager.userCount })); num3 = 30; } builder.Append(string.Concat(new object[] { "\r", getUserName((int) entry.Key), " [", entry.Key.ToString(), "] {", getUser((int) entry.Key)._Rank, "} ", getUser((int) entry.Key).connectionRemoteIP })); num3--; } } else { foreach (DictionaryEntry entry in _Users) { if (num3 == 0) { num4++; builder.Append(string.Concat(new object[] { Convert.ToChar(1), "BKOnline Users page ", num4, " Total online: ", userManager.userCount })); num3 = 30; } builder.Append(string.Concat(new object[] { "\r", getUserName((int) entry.Key), " {", getUser((int) entry.Key)._Rank, "}" })); num3--; } } return builder.ToString(); } public static string getBanReason(int userID) { using (DatabaseClient client = Eucalypt.dbManager.GetClient()) { if (client.findsResult("SELECT userid FROM users_bans WHERE userid = '" + userID + "'")) { if (DateTime.Compare(DateTime.Parse(client.getString("SELECT date_expire FROM users_bans WHERE userid = '" + userID + "'")), DateTime.Now) > 0) { return client.getString("SELECT descr FROM users_bans WHERE userid = '" + userID + "'"); } client.runQuery("DELETE FROM users_bans WHERE userid = '" + userID + "' LIMIT 1"); } } return ""; } public static string getBanReason(string IP) { using (DatabaseClient client = Eucalypt.dbManager.GetClient()) { if (client.findsResult("SELECT ipaddress FROM users_bans WHERE ipaddress = '" + IP + "'")) { if (DateTime.Compare(DateTime.Parse(client.getString("SELECT date_expire FROM users_bans WHERE ipaddress = '" + IP + "'")), DateTime.Now) > 0) { return client.getString("SELECT descr FROM users_bans WHERE ipaddress = '" + IP + "'"); } client.runQuery("DELETE FROM user_bans WHERE ipaddress = '" + IP + "' LIMIT 1"); } } return ""; } public static virtualUser getUser(int userID) { try { return (virtualUser) _Users[userID]; } catch { return null; } } public static virtualUser getUser(string userName) { return getUser(getUserID(userName)); } public static int[] getUserFriendIDs(int userID) { int[] numArray2; using (DatabaseClient client = Eucalypt.dbManager.GetClient()) { try { ArrayList list = new ArrayList(); int[] numArray = dataHandling.dColToArray(client.getColumn("SELECT friendid FROM messenger_friendships WHERE userid = '" + userID + "'"), null); foreach (int num in numArray) { list.Add(num); } numArray = dataHandling.dColToArray(client.getColumn("SELECT userid FROM messenger_friendships WHERE friendid = '" + userID + "'"), null); foreach (int num in numArray) { list.Add(num); } numArray2 = (int[]) list.ToArray(typeof(int)); } catch { numArray2 = new int[0]; } } return numArray2; } public static int getUserID(string userName) { using (DatabaseClient client = Eucalypt.dbManager.GetClient()) { client.AddParamWithValue("name", userName); return client.getInt("SELECT id FROM users WHERE name = @name LIMIT 1"); } } public static string getUserName(int userID) { using (DatabaseClient client = Eucalypt.dbManager.GetClient()) { return client.getString("SELECT name FROM users WHERE id = '" + userID + "' LIMIT 1"); } } public static void Init() { using (DatabaseClient client = Eucalypt.dbManager.GetClient()) { _peakUserCount = client.getInt("SELECT onlinecount_peak FROM system"); } try { pingChecker.Abort(); } catch { } pingChecker = new Thread(new ThreadStart(userManager.checkPings)); pingChecker.Priority = ThreadPriority.Lowest; pingChecker.Start(); } public static void removeUser(int userID) { if (_Users.ContainsKey(userID)) { _Users.Remove(userID); } } public static void sendData(string Data) { try { Hashtable hashtable = (Hashtable) _Users.Clone(); foreach (virtualUser user in hashtable.Values) { try { user.sendData(Data); } catch { Out.WritePlain("Gebruiker " + user._Username + " is offline"); } } } catch { } } public static void sendToRank(byte Rank, bool includeHigher, string Data) { try { foreach (virtualUser user in _Users.Values) { if ((user._Rank >= Rank) && (includeHigher || (user._Rank <= Rank))) { user.sendData(Data); } } } catch { } } public static void setBan(int userID, int Hours, string Reason) { string val = DateTime.Now.AddHours((double) Hours).ToString().Replace("/", "-").Replace(".", "-"); using (DatabaseClient client = Eucalypt.dbManager.GetClient()) { client.AddParamWithValue("userid", userID); client.AddParamWithValue("expires", val); client.AddParamWithValue("reason", Reason); client.runQuery("INSERT INTO users_bans (userid,date_expire,descr) VALUES (@userid,@expires,@reason)"); } if (_Users.ContainsKey(userID)) { virtualUser user = (virtualUser) _Users[userID]; user.sendData("@c" + Reason); user.Disconnect(0x3e8); } } public static void setBan(string IP, int Hours, string Reason) { DataColumn column; string val = DateTime.Now.AddHours((double) Hours).ToString().Replace("/", "-").Replace(".", "-"); using (DatabaseClient client = Eucalypt.dbManager.GetClient()) { client.AddParamWithValue("ip", IP); client.AddParamWithValue("expires", val); client.AddParamWithValue("reason", Reason); client.runQuery("INSERT INTO users_bans (ipaddress,date_expire,descr) VALUES (@ip,@expires,@reason)"); column = client.getColumn("SELECT id FROM users WHERE ipaddress_last = '" + IP + "'"); } foreach (DataRow row in column.Table.Rows) { if (_Users.ContainsKey(Convert.ToInt32(row["id"]))) { ((virtualUser) _Users[Convert.ToInt32(row["ID"])]).sendData("BKPacchetto bloccato by HanSolaris"); } } } public static bool userExists(int userID) { using (DatabaseClient client = Eucalypt.dbManager.GetClient()) { return client.findsResult("SELECT id FROM users WHERE id = '" + userID + "'"); } } public static int peakUserCount { get { return _peakUserCount; } } public static int userCount { get { return _Users.Count; } } } }