Advertisement
4bdu

Untitled

Oct 18th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.23 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Data;
  5. using System.Collections.Generic;
  6. using Plus.Database.Interfaces;
  7. using Plus.HabboHotel.Rooms;
  8. using Plus.HabboHotel.Users;
  9. using Plus.Utilities;
  10. using Plus.HabboHotel.Cache;
  11.  
  12. namespace Plus.Communication.Packets.Outgoing.Moderation
  13. {
  14. class ModeratorRoomChatlogComposer : ServerPacket
  15. {
  16. public ModeratorRoomChatlogComposer(Room Room)
  17. : base(ServerPacketHeader.ModeratorRoomChatlogMessageComposer)
  18. {
  19. base.WriteByte(1);
  20. base.WriteShort(2); //Count
  21. base.WriteString("roomName");
  22. base.WriteByte(2);
  23. base.WriteString(Room.Name);
  24. base.WriteString("roomId");
  25. base.WriteByte(1);
  26. base.WriteInteger(Room.Id);
  27.  
  28. DataTable table;
  29. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  30. {
  31. dbClient.SetQuery("SELECT * FROM `chatlogs` WHERE `room_id` = @rid ORDER BY `id` DESC LIMIT 250");
  32. dbClient.AddParameter("rid", Room.Id);
  33. table = dbClient.getTable();
  34. }
  35.  
  36. if (table != null)
  37. {
  38. base.WriteShort(table.Rows.Count);
  39.  
  40. foreach (DataRow row in table.Rows)
  41. {
  42. int timestamp;
  43.  
  44. try
  45. {
  46. timestamp = ((int) PlusEnvironment.GetUnixTimestamp() - Convert.ToInt32(row["timestamp"])) *
  47. 1000;
  48. }
  49. catch
  50. {
  51. timestamp = 0; // For whatever reason, the maths failed
  52. }
  53.  
  54. UserCache habbo =
  55. PlusEnvironment.GetGame().GetCacheManager().GenerateUser(Convert.ToInt32(row["user_id"]));
  56.  
  57. base.WriteInteger(timestamp);
  58.  
  59. if (habbo != null)
  60. {
  61. base.WriteInteger(habbo.Id);
  62. base.WriteString(habbo.Username);
  63. }
  64. else
  65. {
  66. base.WriteInteger(-1);
  67. base.WriteString("Unknown User");
  68. }
  69.  
  70. base.WriteString(
  71. string.IsNullOrWhiteSpace(Convert.ToString(row["message"]))
  72. ? "*user sent a blank message*"
  73. : Convert.ToString(row["message"]));
  74.  
  75. base.WriteBoolean(false);
  76. }
  77. }
  78. }
  79. }
  80. }
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. using System;
  88. using System.Linq;
  89. using System.Text;
  90. using System.Data;
  91. using System.Collections.Generic;
  92. using Plus.HabboHotel.Users;
  93. using Plus.Database.Interfaces;
  94. using Plus.HabboHotel.Rooms;
  95. using Plus.HabboHotel.Cache;
  96.  
  97. namespace Plus.Communication.Packets.Outgoing.Moderation
  98. {
  99. class ModeratorUserChatlogComposer : ServerPacket
  100. {
  101. public ModeratorUserChatlogComposer(int UserId)
  102. : base(ServerPacketHeader.ModeratorUserChatlogMessageComposer)
  103. {
  104. base.WriteInteger(UserId);
  105. base.WriteString(PlusEnvironment.GetGame().GetClientManager().GetNameById(UserId));
  106.  
  107. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  108. {
  109. dbClient.SetQuery(
  110. "SELECT room_id,entry_timestamp,exit_timestamp FROM user_roomvisits WHERE `user_id` = " + UserId +
  111. " ORDER BY entry_timestamp DESC LIMIT 5");
  112. DataTable visits = dbClient.getTable();
  113.  
  114. if (visits != null)
  115. {
  116. base.WriteInteger(visits.Rows.Count);
  117.  
  118. foreach (DataRow visit in visits.Rows)
  119. {
  120. string roomName = "Unknown";
  121.  
  122. Room room =
  123. PlusEnvironment.GetGame().GetRoomManager().LoadRoom(Convert.ToInt32(visit["room_id"]));
  124.  
  125. if (room != null)
  126. roomName = room.Name;
  127.  
  128. base.WriteByte(1);
  129. base.WriteShort(2); //Count
  130. base.WriteString("roomName");
  131. base.WriteByte(2);
  132. base.WriteString(roomName); // room name
  133. base.WriteString("roomId");
  134. base.WriteByte(1);
  135. base.WriteInteger(Convert.ToInt32(visit["room_id"]));
  136.  
  137. DataTable chatlogs = null;
  138. if ((Double) visit["exit_timestamp"] <= 0)
  139. {
  140. visit["exit_timestamp"] = PlusEnvironment.GetUnixTimestamp();
  141. }
  142.  
  143. dbClient.SetQuery("SELECT user_id,timestamp,message FROM `chatlogs` WHERE room_id = " +
  144. Convert.ToInt32(visit["room_id"]) + " AND timestamp > " +
  145. (Double) visit["entry_timestamp"] + " AND timestamp < " +
  146. (Double) visit["exit_timestamp"] + " ORDER BY timestamp DESC LIMIT 150");
  147. chatlogs = dbClient.getTable();
  148.  
  149. if (chatlogs != null)
  150. {
  151. base.WriteShort(chatlogs.Rows.Count);
  152.  
  153. foreach (DataRow log in chatlogs.Rows)
  154. {
  155. UserCache habbo =
  156. PlusEnvironment.GetGame()
  157. .GetCacheManager()
  158. .GenerateUser(Convert.ToInt32(log["user_id"]));
  159.  
  160. if (habbo == null)
  161. continue;
  162.  
  163. int timestamp;
  164.  
  165. try
  166. {
  167. timestamp = ((int) PlusEnvironment.GetUnixTimestamp() -
  168. Convert.ToInt32(log["timestamp"])) * 1000;
  169. }
  170. catch
  171. {
  172. timestamp = 0;
  173. }
  174.  
  175. base.WriteInteger(timestamp);
  176. base.WriteInteger(habbo.Id);
  177. base.WriteString(habbo.Username);
  178. base.WriteString(string.IsNullOrWhiteSpace(Convert.ToString(log["message"]))
  179. ? "*user sent a blank message*"
  180. : Convert.ToString(log["message"]));
  181. base.WriteBoolean(false);
  182. }
  183. }
  184. else
  185. base.WriteInteger(0);
  186. }
  187. }
  188. else
  189. base.WriteInteger(0);
  190. }
  191. }
  192. }
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement