Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.11 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using System.Threading;
  4. using Quasar.Core;
  5. using Quasar.Database.Interfaces;
  6. using Quasar.HabboHotel.GameClients;
  7. using Quasar.HabboHotel.Rooms;
  8.  
  9. namespace Quasar.HabboHotel.Users.Ban
  10. {
  11. class BanManager
  12. {
  13. /* Private members vars */
  14. private GameClient m_Session;
  15. private int j_Timestamp;
  16. private string j_Reason;
  17. private string m_Date;
  18.  
  19. /* Method to initalize BanManager */
  20. /* @Parameters: GameClient Session */
  21. public bool Initialize(GameClient Session)
  22. {
  23. if (Session == null)
  24. return false;
  25. m_Session = Session;
  26. return true;
  27. }
  28.  
  29. /* Method to begin the main task */
  30. /* @Parameters: None */
  31. public void beginTask()
  32. {
  33. /* Receive Jail Data from Database */
  34. DataTable dTable = null;
  35. using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
  36. {
  37. dbClient.SetQuery("SELECT jailtime, reason FROM users WHERE username = @username LIMIT 1");
  38. dbClient.AddParameter("username", m_Session.GetHabbo().Username);
  39. dTable = dbClient.getTable();
  40. // Critical position as it could be NullException risky
  41. if (dTable != null)
  42. {
  43. foreach (DataRow dRow in dTable.Rows)
  44. {
  45. // Asigning row values to member variables
  46. this.j_Timestamp = Convert.ToInt32(dRow["jailtime"]);
  47. this.j_Reason = dRow["reason"].ToString();
  48. }
  49. }
  50. // Clear Data Table to free space
  51. dTable.Clear();
  52.  
  53. System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0);
  54. dateTime = dateTime.AddSeconds(this.j_Timestamp + QuasarEnvironment.GetIUnixTimestamp()).ToLocalTime();
  55. this.m_Date = dateTime.ToShortTimeString();
  56.  
  57. // Notify User that he got banned
  58. if (m_Session.GetHabbo().isInJail == 1)
  59. {
  60. // Adminprison
  61. 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");
  62. }
  63.  
  64. if (m_Session.GetHabbo().isInJail == 2)
  65. {
  66. // RP Prison
  67. 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");
  68. }
  69.  
  70. Thread worker_thread = new Thread(thread_ban_worker);
  71.  
  72.  
  73.  
  74. worker_thread.Start();
  75. }
  76. }
  77.  
  78. /* Thread Method to keep jail active calculated */
  79. /* @Parameters: None */
  80. private void thread_ban_worker()
  81. {
  82. /* Thread Loop */
  83. while (1 < this.j_Timestamp)
  84. {
  85. /* Check if session is null, if yes then stop the thread */
  86. if (m_Session.GetHabbo() != null)
  87. {
  88. System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0);
  89. dateTime = dateTime.AddSeconds(this.j_Timestamp).ToLocalTime();
  90. int differTime = Convert.ToInt32((dateTime - DateTime.Now).TotalSeconds);
  91. // Check if user is currently in room id 1 (jail)
  92. if (m_Session.GetHabbo().CurrentRoomId == 1 || m_Session.GetHabbo().CurrentRoomId == 134)
  93. {
  94. if (m_Session.GetHabbo().isInJail == 1 )
  95. {
  96. //Admin Prison
  97. 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);
  98. }
  99. if (m_Session.GetHabbo().isInJail == 2)
  100. {
  101. //RP Prison
  102. 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);
  103. }
  104.  
  105.  
  106.  
  107.  
  108. }
  109. // Let the thread sleep 20sec and notify him again with newer informations
  110. Thread.Sleep(20000);
  111. try
  112. {
  113. if (m_Session.GetHabbo() != null)
  114. {
  115. if (m_Session.GetHabbo().CurrentRoomId == 1 || m_Session.GetHabbo().CurrentRoomId == 134)
  116. {
  117. this.j_Timestamp -= 20;
  118.  
  119.  
  120. using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
  121. {
  122. dbClient.SetQuery("UPDATE users SET jailtime = @jailtime WHERE id = @userId LIMIT 1");
  123. dbClient.AddParameter("userId", m_Session.GetHabbo().Id);
  124. dbClient.AddParameter("jailtime", this.j_Timestamp);
  125. dbClient.RunQuery();
  126. }
  127. }
  128. }
  129.  
  130. } catch
  131. {
  132.  
  133. }
  134.  
  135. // Repeat the loop
  136. continue;
  137. }
  138. // Stop Thread # Infinity Thread loop prevention
  139. else
  140. return;
  141. }
  142. /* Free the user after jail time */
  143. if (m_Session != null)
  144. {
  145. // Set isInJail to 0
  146. if (m_Session.GetHabbo().isInJail == 1)
  147. {
  148. // Admin Prison
  149. m_Session.GetHabbo().isInJail = 0;
  150. // Update MySQL Database
  151. using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
  152. {
  153. dbClient.SetQuery("UPDATE users SET is_jail = '0', jailtime = '0' WHERE id = @userId LIMIT 1");
  154. dbClient.AddParameter("userId", m_Session.GetHabbo().Id);
  155. dbClient.RunQuery();
  156. }
  157. // Send User Notification
  158. 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!");
  159. // Kick user out of jail room
  160.  
  161.  
  162.  
  163. Room TargetRoom;
  164. if (!QuasarEnvironment.GetGame().GetRoomManager().TryGetRoom(1, out TargetRoom))
  165. return;
  166. else
  167. TargetRoom.GetRoomUserManager().RemoveUserFromRoom(m_Session, true, false);
  168. // Stop Thread # Infinity Thread loop prevention
  169. return;
  170.  
  171. }
  172.  
  173.  
  174. if (m_Session.GetHabbo().isInJail == 2)
  175. {
  176. // RP Prison
  177. m_Session.GetHabbo().isInJail = 0;
  178. // Update MySQL Database
  179. using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
  180. {
  181. dbClient.SetQuery("UPDATE users SET is_jail = '0', jailtime = '0' WHERE id = @userId LIMIT 1");
  182. dbClient.AddParameter("userId", m_Session.GetHabbo().Id);
  183. dbClient.RunQuery();
  184. }
  185. // Send User Notification
  186. 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.");
  187. // Kick user out of jail room
  188. m_Session.GetHabbo().Effects().ApplyEffect(0);
  189. Room TargetRoom;
  190. if (!QuasarEnvironment.GetGame().GetRoomManager().TryGetRoom(134, out TargetRoom))
  191. return;
  192. else
  193. TargetRoom.GetRoomUserManager().RemoveUserFromRoom(m_Session, true, false);
  194. // Stop Thread # Infinity Thread loop prevention
  195. return;
  196.  
  197. }
  198.  
  199.  
  200. }
  201. // Stop Thread # Infinity Thread loop prevention
  202. else
  203. return;
  204. }
  205. }
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement