Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Data;
- using System.Threading;
- using Quasar.Core;
- using Quasar.Database.Interfaces;
- using Quasar.HabboHotel.GameClients;
- using Quasar.HabboHotel.Rooms;
- namespace Quasar.HabboHotel.Users.Ban
- {
- class BanManager
- {
- /* Private members vars */
- private GameClient m_Session;
- private int j_Timestamp;
- private string j_Reason;
- private string m_Date;
- /* Method to initalize BanManager */
- /* @Parameters: GameClient Session */
- public bool Initialize(GameClient Session)
- {
- if (Session == null)
- return false;
- m_Session = Session;
- return true;
- }
- /* Method to begin the main task */
- /* @Parameters: None */
- public void beginTask()
- {
- /* Receive Jail Data from Database */
- DataTable dTable = null;
- using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- dbClient.SetQuery("SELECT jailtime, reason FROM users WHERE username = @username LIMIT 1");
- dbClient.AddParameter("username", m_Session.GetHabbo().Username);
- dTable = dbClient.getTable();
- // Critical position as it could be NullException risky
- if (dTable != null)
- {
- foreach (DataRow dRow in dTable.Rows)
- {
- // Asigning row values to member variables
- this.j_Timestamp = Convert.ToInt32(dRow["jailtime"]);
- this.j_Reason = dRow["reason"].ToString();
- }
- }
- // Clear Data Table to free space
- dTable.Clear();
- System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0);
- dateTime = dateTime.AddSeconds(this.j_Timestamp + QuasarEnvironment.GetIUnixTimestamp()).ToLocalTime();
- this.m_Date = dateTime.ToShortTimeString();
- // Notify User that he got banned
- if (m_Session.GetHabbo().isInJail == 1)
- {
- // Adminprison
- m_Session.SendNotification("<font color = '#B40404'><font size= '16'><b>Du wurdest aus Habbo gebannt!</b></font></font>\n\nDu wurdest für " + this.j_Timestamp.ToString() + " Sekunden aus dem Hotel gebannt.\r\rBegründung: " + this.j_Reason + "\r");
- }
- if (m_Session.GetHabbo().isInJail == 2)
- {
- // RP Prison
- m_Session.SendNotification("<font color = '#B40404'><font size= '16'><b>Du bist verhaftet!</b></font></font>\n\nDu wurdest für " + this.j_Timestamp.ToString() + " Sekunden in Gewahrsam genommen.\r\rBegründung: " + this.j_Reason + "\r");
- }
- Thread worker_thread = new Thread(thread_ban_worker);
- worker_thread.Start();
- }
- }
- /* Thread Method to keep jail active calculated */
- /* @Parameters: None */
- private void thread_ban_worker()
- {
- /* Thread Loop */
- while (1 < this.j_Timestamp)
- {
- /* Check if session is null, if yes then stop the thread */
- if (m_Session.GetHabbo() != null)
- {
- System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0);
- dateTime = dateTime.AddSeconds(this.j_Timestamp).ToLocalTime();
- int differTime = Convert.ToInt32((dateTime - DateTime.Now).TotalSeconds);
- // Check if user is currently in room id 1 (jail)
- if (m_Session.GetHabbo().CurrentRoomId == 1 || m_Session.GetHabbo().CurrentRoomId == 134)
- {
- if (m_Session.GetHabbo().isInJail == 1 )
- {
- //Admin Prison
- m_Session.SendWhisper("Deine Sanktion endet in " + this.j_Timestamp.ToString() + " Sekunden. Frei um: " + this.m_Date + " Uhr - Aktuelle Uhrzeit: " + DateTime.Now.ToLongTimeString() + " Uhr.", 1);
- }
- if (m_Session.GetHabbo().isInJail == 2)
- {
- //RP Prison
- m_Session.SendWhisper("Deine Knastzeit beträgt noch " + this.j_Timestamp.ToString() + " Sekunden. Frei um: " + this.m_Date + " Uhr - Aktuelle Uhrzeit: " + DateTime.Now.ToLongTimeString() + " Uhr.", 1);
- }
- }
- // Let the thread sleep 20sec and notify him again with newer informations
- Thread.Sleep(20000);
- try
- {
- if (m_Session.GetHabbo() != null)
- {
- if (m_Session.GetHabbo().CurrentRoomId == 1 || m_Session.GetHabbo().CurrentRoomId == 134)
- {
- this.j_Timestamp -= 20;
- using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- dbClient.SetQuery("UPDATE users SET jailtime = @jailtime WHERE id = @userId LIMIT 1");
- dbClient.AddParameter("userId", m_Session.GetHabbo().Id);
- dbClient.AddParameter("jailtime", this.j_Timestamp);
- dbClient.RunQuery();
- }
- }
- }
- } catch
- {
- }
- // Repeat the loop
- continue;
- }
- // Stop Thread # Infinity Thread loop prevention
- else
- return;
- }
- /* Free the user after jail time */
- if (m_Session != null)
- {
- // Set isInJail to 0
- if (m_Session.GetHabbo().isInJail == 1)
- {
- // Admin Prison
- m_Session.GetHabbo().isInJail = 0;
- // Update MySQL Database
- using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- dbClient.SetQuery("UPDATE users SET is_jail = '0', jailtime = '0' WHERE id = @userId LIMIT 1");
- dbClient.AddParameter("userId", m_Session.GetHabbo().Id);
- dbClient.RunQuery();
- }
- // Send User Notification
- m_Session.SendNotification("<font color = '#008000'><font size= '16'><b>Strafe abgesessen!</b></font></font>\n\nDeine Sanktion ist abgelaufen. Hoffentlich war es dir eine Lehre!");
- // Kick user out of jail room
- Room TargetRoom;
- if (!QuasarEnvironment.GetGame().GetRoomManager().TryGetRoom(1, out TargetRoom))
- return;
- else
- TargetRoom.GetRoomUserManager().RemoveUserFromRoom(m_Session, true, false);
- // Stop Thread # Infinity Thread loop prevention
- return;
- }
- if (m_Session.GetHabbo().isInJail == 2)
- {
- // RP Prison
- m_Session.GetHabbo().isInJail = 0;
- // Update MySQL Database
- using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
- {
- dbClient.SetQuery("UPDATE users SET is_jail = '0', jailtime = '0' WHERE id = @userId LIMIT 1");
- dbClient.AddParameter("userId", m_Session.GetHabbo().Id);
- dbClient.RunQuery();
- }
- // Send User Notification
- m_Session.SendNotification("<font color = '#008000'><font size= '16'><b>Strafe abgesessen!</b></font></font>\n\nDu hast deine Strafe im Gefängnis erfolgreich abgesessen! Hoffentlich war es dir eine Lehre.");
- // Kick user out of jail room
- m_Session.GetHabbo().Effects().ApplyEffect(0);
- Room TargetRoom;
- if (!QuasarEnvironment.GetGame().GetRoomManager().TryGetRoom(134, out TargetRoom))
- return;
- else
- TargetRoom.GetRoomUserManager().RemoveUserFromRoom(m_Session, true, false);
- // Stop Thread # Infinity Thread loop prevention
- return;
- }
- }
- // Stop Thread # Infinity Thread loop prevention
- else
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement