Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. using System.Net;
  6. using System.Net.Sockets;
  7.  
  8. using Uber.Storage;
  9. using Uber.HabboHotel.GameClients;
  10. using Uber.HabboHotel.Rooms;
  11. using Uber.Messages;
  12.  
  13. namespace Uber.Net
  14. {
  15. class MusSocket
  16. {
  17. public Socket msSocket;
  18.  
  19. public String musIp;
  20. public int musPort;
  21.  
  22. public HashSet<String> allowedIps;
  23.  
  24. public MusSocket(String _musIp, int _musPort, String[] _allowedIps, int backlog)
  25. {
  26. musIp = _musIp;
  27. musPort = _musPort;
  28.  
  29. allowedIps = new HashSet<String>();
  30.  
  31. foreach (String ip in _allowedIps)
  32. {
  33. allowedIps.Add(ip);
  34. }
  35.  
  36. try
  37. {
  38. msSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  39.  
  40. msSocket.Bind(new IPEndPoint(IPAddress.Parse(musIp), musPort));
  41. msSocket.Listen(backlog);
  42.  
  43. msSocket.BeginAccept(OnEvent_NewConnection, msSocket);
  44.  
  45. UberEnvironment.GetLogging().WriteLine("MUS Socket " + musIp + ":" + musPort);
  46. }
  47.  
  48. catch (Exception e)
  49. {
  50. throw new Exception("Could not set up MUS socket:\n" + e.Message);
  51. }
  52. }
  53.  
  54. public void OnEvent_NewConnection(IAsyncResult iAr)
  55. {
  56. Socket socket = ((Socket)iAr.AsyncState).EndAccept(iAr);
  57. String ip = socket.RemoteEndPoint.ToString().Split(':')[0];
  58.  
  59. if (allowedIps.Contains(ip))
  60. {
  61. MusConnection nC = new MusConnection(socket);
  62. }
  63. else
  64. {
  65. socket.Close();
  66. UberEnvironment.GetLogging().WriteLine("Unauthorised MUS Access Attempt From: " + ip, Core.LogLevel.Warning);
  67. }
  68.  
  69. msSocket.BeginAccept(OnEvent_NewConnection, msSocket);
  70. }
  71. }
  72.  
  73. class MusConnection
  74. {
  75. private Socket socket;
  76. private byte[] buffer = new byte[1024];
  77.  
  78. public MusConnection(Socket _socket)
  79. {
  80. socket = _socket;
  81.  
  82. try
  83. {
  84. socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, OnEvent_RecieveData, null);
  85. }
  86.  
  87. catch (Exception)
  88. {
  89. tryClose();
  90. }
  91. }
  92.  
  93. public void tryClose()
  94. {
  95. try
  96. {
  97. socket.Close();
  98. }
  99. catch (Exception) { }
  100. }
  101.  
  102. public void OnEvent_RecieveData(IAsyncResult iAr)
  103. {
  104. try
  105. {
  106. int bytes = socket.EndReceive(iAr);
  107. String data = Encoding.Default.GetString(buffer, 0, bytes);
  108.  
  109. if (data.Length > 0)
  110. {
  111. processCommand(data);
  112. }
  113. }
  114. catch (Exception) { }
  115.  
  116. tryClose();
  117. }
  118.  
  119. public void processCommand(String data)
  120. {
  121. String header = data.Split(Convert.ToChar(1))[0];
  122. String param = data.Split(Convert.ToChar(1))[1];
  123.  
  124. UberEnvironment.GetLogging().WriteLine("[MUSConnection.ProcessCommand]: " + data);
  125.  
  126. uint userId = 0;
  127. GameClient Client = null;
  128. Room Room = null;
  129. RoomUser RoomUser = null;
  130. DataRow Row = null;
  131. ServerMessage Message = null;
  132.  
  133. switch (header.ToLower())
  134. {
  135. case "updatecredits":
  136. {
  137. if (param == "ALL")
  138. {
  139. UberEnvironment.GetGame().GetClientManager().DeployHotelCreditsUpdate();
  140. }
  141. else
  142. {
  143. Client = UberEnvironment.GetGame().GetClientManager().GetClientByHabbo(uint.Parse(param));
  144.  
  145. if (Client == null)
  146. {
  147. return;
  148. }
  149.  
  150. int newCredits = 0;
  151.  
  152. using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
  153. {
  154. newCredits = (int)dbClient.ReadDataRow("SELECT credits FROM users WHERE id = '" + Client.GetHabbo().Id + "' LIMIT 1")[0];
  155. }
  156.  
  157. Client.GetHabbo().Credits = newCredits;
  158. Client.GetHabbo().UpdateCreditsBalance(false);
  159. }
  160.  
  161. break;
  162. }
  163. case "reloadbans":
  164. {
  165. UberEnvironment.GetGame().GetBanManager().LoadBans();
  166. UberEnvironment.GetGame().GetClientManager().CheckForAllBanConflicts();
  167. break;
  168. }
  169. case "signout":
  170. {
  171. UberEnvironment.GetGame().GetClientManager().GetClientByHabbo(uint.Parse(param)).Disconnect();
  172. break;
  173. }
  174. case "updatetags":
  175. {
  176. Client = UberEnvironment.GetGame().GetClientManager().GetClientByHabbo(uint.Parse(param));
  177. Client.GetHabbo().LoadTags();
  178. break;
  179. }
  180. case "ha":
  181. {
  182. ServerMessage HotelAlert = new ServerMessage(139);
  183. HotelAlert.AppendStringWithBreak("Message from the Hotel Management: " + param);
  184. UberEnvironment.GetGame().GetClientManager().BroadcastMessage(HotelAlert);
  185. break;
  186. }
  187. case "reboot":
  188. {
  189. UberEnvironment.Destroy();
  190. break;
  191. }
  192. case "updatemotto":
  193. case "updatelook":
  194. {
  195. userId = uint.Parse(param);
  196. Client = UberEnvironment.GetGame().GetClientManager().GetClientByHabbo(userId);
  197.  
  198. using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
  199. {
  200. Row = dbClient.ReadDataRow("SELECT look,gender,motto,mutant_penalty,block_newfriends FROM users WHERE id = '" + Client.GetHabbo().Id + "' LIMIT 1");
  201. }
  202.  
  203. Client.GetHabbo().Look = (string)Row["look"];
  204. Client.GetHabbo().Gender = Row["gender"].ToString().ToLower();
  205. Client.GetHabbo().Motto = UberEnvironment.FilterInjectionChars((string)Row["motto"]);
  206. Client.GetHabbo().BlockNewFriends = UberEnvironment.EnumToBool(Row["block_newfriends"].ToString());
  207.  
  208. if (Row["mutant_penalty"].ToString() != "0")
  209. {
  210. if (!Client.GetHabbo().MutantPenalty)
  211. {
  212. Client.SendNotif("For scripting and/or manipulating your look, we have decided to punish you, by changing and locking your look and motto for a week (or perhaps permanently, depending on our mood). Enjoy!");
  213. Client.GetHabbo().MutantPenalty = true;
  214. }
  215. }
  216.  
  217. // DJHhr-890-39.hd-600-1.sh-907-84.lg-715-84.ch-650-84.ca-1819-.fa-1212-f?
  218. Client.GetMessageHandler().GetResponse().Init(266);
  219. Client.GetMessageHandler().GetResponse().AppendInt32(-1);
  220. Client.GetMessageHandler().GetResponse().AppendStringWithBreak(Client.GetHabbo().Look);
  221. Client.GetMessageHandler().GetResponse().AppendStringWithBreak(Client.GetHabbo().Gender.ToLower());
  222. Client.GetMessageHandler().GetResponse().AppendStringWithBreak(Client.GetHabbo().Motto);
  223. Client.GetMessageHandler().SendResponse();
  224.  
  225. if (Client.GetHabbo().InRoom)
  226. {
  227. Room = UberEnvironment.GetGame().GetRoomManager().GetRoom(Client.GetHabbo().CurrentRoomId);
  228. RoomUser = Room.GetRoomUserByHabbo(Client.GetHabbo().Id);
  229.  
  230. Message = new ServerMessage(266);
  231. Message.AppendInt32(RoomUser.VirtualId);
  232. Message.AppendStringWithBreak(Client.GetHabbo().Look);
  233. Message.AppendStringWithBreak(Client.GetHabbo().Gender.ToLower());
  234. Message.AppendStringWithBreak(Client.GetHabbo().Motto);
  235.  
  236. Room.SendMessage(Message);
  237. }
  238.  
  239. // Unlock achievements
  240. switch (header.ToLower())
  241. {
  242. case "updatemotto":
  243.  
  244. UberEnvironment.GetGame().GetAchievementManager().UnlockAchievement(Client, 5, 1);
  245. break;
  246.  
  247. case "updatelook":
  248.  
  249. if (!Client.GetHabbo().MutantPenalty)
  250. {
  251. UberEnvironment.GetGame().GetAchievementManager().UnlockAchievement(Client, 1, 1);
  252. }
  253.  
  254. break;
  255. }
  256.  
  257. break;
  258. }
  259. default:
  260. {
  261. UberEnvironment.GetLogging().WriteLine("Unrecognized MUS packet: " + data, Core.LogLevel.Error);
  262. break;
  263. }
  264. }
  265. }
  266. }
  267. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement