Advertisement
Guest User

roomcs

a guest
May 4th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.50 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using System.Linq;
  4. using System.Collections;
  5. using System.Threading.Tasks;
  6. using System.Collections.Generic;
  7.  
  8. using Plus.Core;
  9. using Plus.HabboHotel.GameClients;
  10. using Plus.HabboHotel.Groups;
  11. using Plus.HabboHotel.Items;
  12. using Plus.HabboHotel.Rooms.AI;
  13. using Plus.HabboHotel.Rooms.Games;
  14. using Plus.Communication.Interfaces;
  15. using Plus.Communication.Packets.Outgoing;
  16.  
  17.  
  18. using Plus.HabboHotel.Rooms.Instance;
  19.  
  20. using Plus.HabboHotel.Items.Data.Toner;
  21. using Plus.HabboHotel.Rooms.Games.Freeze;
  22. using Plus.HabboHotel.Items.Data.Moodlight;
  23.  
  24. using Plus.Communication.Packets.Outgoing.Rooms.Avatar;
  25. using Plus.Communication.Packets.Outgoing.Rooms.Engine;
  26. using Plus.Communication.Packets.Outgoing.Rooms.Session;
  27.  
  28.  
  29. using Plus.HabboHotel.Rooms.Games.Football;
  30. using Plus.HabboHotel.Rooms.Games.Banzai;
  31. using Plus.HabboHotel.Rooms.Games.Teams;
  32. using Plus.HabboHotel.Rooms.Trading;
  33. using Plus.HabboHotel.Rooms.AI.Speech;
  34. using Plus.Database.Interfaces;
  35.  
  36. namespace Plus.HabboHotel.Rooms
  37. {
  38. public class Room : RoomData
  39. {
  40. public bool isCrashed;
  41. public bool mDisposed;
  42. public bool RoomMuted;
  43. public DateTime lastTimerReset;
  44. public DateTime lastRegeneration;
  45.  
  46.  
  47.  
  48. public Task ProcessTask;
  49. public ArrayList ActiveTrades;
  50.  
  51. public TonerData TonerData;
  52. public MoodlightData MoodlightData;
  53.  
  54. public Dictionary<int, double> MutedUsers;
  55.  
  56.  
  57. private Dictionary<int, List<RoomUser>> Tents;
  58.  
  59. public List<int> UsersWithRights;
  60. private GameManager _gameManager;
  61. private Freeze _freeze;
  62. private Soccer _soccer;
  63. private BattleBanzai _banzai;
  64.  
  65. private Gamemap _gamemap;
  66. private GameItemHandler _gameItemHandler;
  67.  
  68. private RoomData _roomData;
  69. public TeamManager teambanzai;
  70. public TeamManager teamfreeze;
  71.  
  72.  
  73. private RoomUserManager _roomUserManager;
  74. private RoomItemHandling _roomItemHandling;
  75.  
  76. private List<string> _wordFilterList;
  77.  
  78. private FilterComponent _filterComponent = null;
  79. private WiredComponent _wiredComponent = null;
  80. private BansComponent _bansComponent = null;
  81. private TradingComponent _tradingComponent = null;
  82.  
  83. public int IsLagging { get; set; }
  84. public int IdleTime { get; set; }
  85.  
  86. public Room(RoomData Data)
  87. {
  88. this.IsLagging = 0;
  89. this.IdleTime = 0;
  90.  
  91. this._roomData = Data;
  92. RoomMuted = false;
  93. mDisposed = false;
  94.  
  95. this.Id = Data.Id;
  96. this.Name = Data.Name;
  97. this.Description = Data.Description;
  98. this.OwnerName = Data.OwnerName;
  99. this.OwnerId = Data.OwnerId;
  100.  
  101. this.Category = Data.Category;
  102. this.Type = Data.Type;
  103. this.Access = Data.Access;
  104. this.UsersNow = 0;
  105. this.UsersMax = Data.UsersMax;
  106. this.ModelName = Data.ModelName;
  107. this.Score = Data.Score;
  108. this.Tags = new List<string>();
  109. foreach (string tag in Data.Tags)
  110. {
  111. Tags.Add(tag);
  112. }
  113.  
  114. this.AllowPets = Data.AllowPets;
  115. this.AllowPetsEating = Data.AllowPetsEating;
  116. this.RoomBlockingEnabled = Data.RoomBlockingEnabled;
  117. this.Hidewall = Data.Hidewall;
  118. this.Group = Data.Group;
  119.  
  120. this.Password = Data.Password;
  121. this.Wallpaper = Data.Wallpaper;
  122. this.Floor = Data.Floor;
  123. this.Landscape = Data.Landscape;
  124.  
  125. this.WallThickness = Data.WallThickness;
  126. this.FloorThickness = Data.FloorThickness;
  127.  
  128. this.chatMode = Data.chatMode;
  129. this.chatSize = Data.chatSize;
  130. this.chatSpeed = Data.chatSpeed;
  131. this.chatDistance = Data.chatDistance;
  132. this.extraFlood = Data.extraFlood;
  133.  
  134. this.TradeSettings = Data.TradeSettings;
  135.  
  136. this.WhoCanBan = Data.WhoCanBan;
  137. this.WhoCanKick = Data.WhoCanKick;
  138. this.WhoCanBan = Data.WhoCanBan;
  139.  
  140. this.PushEnabled = Data.PushEnabled;
  141. this.PullEnabled = Data.PullEnabled;
  142. this.SPullEnabled = Data.SPullEnabled;
  143. this.SPushEnabled = Data.SPushEnabled;
  144. this.EnablesEnabled = Data.EnablesEnabled;
  145. this.RespectNotificationsEnabled = Data.RespectNotificationsEnabled;
  146. this.PetMorphsAllowed = Data.PetMorphsAllowed;
  147.  
  148. this.ActiveTrades = new ArrayList();
  149. this.MutedUsers = new Dictionary<int, double>();
  150. this.Tents = new Dictionary<int, List<RoomUser>>();
  151.  
  152. _gamemap = new Gamemap(this);
  153. if (_roomItemHandling == null)
  154. _roomItemHandling = new RoomItemHandling(this);
  155. _roomUserManager = new RoomUserManager(this);
  156.  
  157. this._filterComponent = new FilterComponent(this);
  158. this._wiredComponent = new WiredComponent(this);
  159. this._bansComponent = new BansComponent(this);
  160. this._tradingComponent = new TradingComponent(this);
  161.  
  162. GetRoomItemHandler().LoadFurniture();
  163. GetGameMap().GenerateMaps();
  164.  
  165. this.LoadPromotions();
  166. this.LoadRights();
  167. this.LoadFilter();
  168. this.InitBots();
  169. this.InitPets();
  170.  
  171. Data.UsersNow = 1;
  172. }
  173.  
  174. public List<string> WordFilterList
  175. {
  176. get { return this._wordFilterList; }
  177. set { this._wordFilterList = value; }
  178. }
  179.  
  180. public int UserCount
  181. {
  182. get { return _roomUserManager.GetRoomUsers().Count; }
  183. }
  184.  
  185. public int RoomId
  186. {
  187. get { return Id; }
  188. }
  189.  
  190. public bool CanTradeInRoom
  191. {
  192. get { return true; }
  193. }
  194.  
  195. public RoomData RoomData
  196. {
  197. get { return _roomData; }
  198. }
  199.  
  200. public Gamemap GetGameMap()
  201. {
  202. return _gamemap;
  203. }
  204.  
  205.  
  206.  
  207. internal void FixGameMap()
  208. {
  209. gamemap = new Gamemap(this);
  210. }
  211.  
  212. public RoomItemHandling GetRoomItemHandler()
  213. {
  214. if (_roomItemHandling == null)
  215. {
  216. _roomItemHandling = new RoomItemHandling(this);
  217. }
  218. return _roomItemHandling;
  219. }
  220.  
  221. public RoomUserManager GetRoomUserManager()
  222. {
  223. return _roomUserManager;
  224. }
  225.  
  226. public Soccer GetSoccer()
  227. {
  228. if (_soccer == null)
  229. _soccer = new Soccer(this);
  230.  
  231. return _soccer;
  232. }
  233.  
  234. public TeamManager GetTeamManagerForBanzai()
  235. {
  236. if (teambanzai == null)
  237. teambanzai = TeamManager.createTeamforGame("banzai");
  238. return teambanzai;
  239. }
  240.  
  241. public TeamManager GetTeamManagerForFreeze()
  242. {
  243. if (teamfreeze == null)
  244. teamfreeze = TeamManager.createTeamforGame("freeze");
  245. return teamfreeze;
  246. }
  247.  
  248. public BattleBanzai GetBanzai()
  249. {
  250. if (_banzai == null)
  251. _banzai = new BattleBanzai(this);
  252. return _banzai;
  253. }
  254.  
  255. public Freeze GetFreeze()
  256. {
  257. if (_freeze == null)
  258. _freeze = new Freeze(this);
  259. return _freeze;
  260. }
  261.  
  262. public GameManager GetGameManager()
  263. {
  264. if (_gameManager == null)
  265. _gameManager = new GameManager(this);
  266. return _gameManager;
  267. }
  268.  
  269. public GameItemHandler GetGameItemHandler()
  270. {
  271. if (_gameItemHandler == null)
  272. _gameItemHandler = new GameItemHandler(this);
  273. return _gameItemHandler;
  274. }
  275.  
  276. public bool GotSoccer()
  277. {
  278. return (_soccer != null);
  279. }
  280.  
  281. public bool GotBanzai()
  282. {
  283. return (_banzai != null);
  284. }
  285.  
  286.  
  287. public bool GotFreeze()
  288. {
  289. return (_freeze != null);
  290. }
  291.  
  292. public void ClearTags()
  293. {
  294. Tags.Clear();
  295. }
  296.  
  297. public void AddTagRange(List<string> tags)
  298. {
  299. Tags.AddRange(tags);
  300. }
  301.  
  302. public void InitBots()
  303. {
  304. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  305. {
  306. dbClient.SetQuery("SELECT `id`,`room_id`,`name`,`motto`,`look`,`x`,`y`,`z`,`rotation`,`gender`,`user_id`,`ai_type`,`walk_mode`,`automatic_chat`,`speaking_interval`,`mix_sentences`,`chat_bubble` FROM `bots` WHERE `room_id` = '" + RoomId + "' AND `ai_type` != 'pet'");
  307. DataTable Data = dbClient.GetTable();
  308. if (Data == null)
  309. return;
  310.  
  311. foreach (DataRow Bot in Data.Rows)
  312. {
  313. dbClient.SetQuery("SELECT `text` FROM `bots_speech` WHERE `bot_id` = '" + Convert.ToInt32(Bot["id"]) + "'");
  314. DataTable BotSpeech = dbClient.GetTable();
  315.  
  316. List<RandomSpeech> Speeches = new List<RandomSpeech>();
  317.  
  318. foreach (DataRow Speech in BotSpeech.Rows)
  319. {
  320. Speeches.Add(new RandomSpeech(Convert.ToString(Speech["text"]), Convert.ToInt32(Bot["id"])));
  321. }
  322.  
  323. _roomUserManager.DeployBot(new RoomBot(Convert.ToInt32(Bot["id"]), Convert.ToInt32(Bot["room_id"]), Convert.ToString(Bot["ai_type"]), Convert.ToString(Bot["walk_mode"]), Convert.ToString(Bot["name"]), Convert.ToString(Bot["motto"]), Convert.ToString(Bot["look"]), int.Parse(Bot["x"].ToString()), int.Parse(Bot["y"].ToString()), int.Parse(Bot["z"].ToString()), int.Parse(Bot["rotation"].ToString()), 0, 0, 0, 0, ref Speeches, "M", 0, Convert.ToInt32(Bot["user_id"].ToString()), Convert.ToBoolean(Bot["automatic_chat"]), Convert.ToInt32(Bot["speaking_interval"]), PlusEnvironment.EnumToBool(Bot["mix_sentences"].ToString()), Convert.ToInt32(Bot["chat_bubble"])), null);
  324. }
  325. }
  326. }
  327.  
  328. public void InitPets()
  329. {
  330. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  331. {
  332. dbClient.SetQuery("SELECT `id`,`user_id`,`room_id`,`name`,`x`,`y`,`z` FROM `bots` WHERE `room_id` = '" + RoomId + "' AND `ai_type` = 'pet'");
  333. DataTable Data = dbClient.GetTable();
  334.  
  335. if (Data == null)
  336. return;
  337.  
  338. foreach (DataRow Row in Data.Rows)
  339. {
  340. dbClient.SetQuery("SELECT `type`,`race`,`color`,`experience`,`energy`,`nutrition`,`respect`,`createstamp`,`have_saddle`,`anyone_ride`,`hairdye`,`pethair`,`gnome_clothing` FROM `bots_petdata` WHERE `id` = '" + Row[0] + "' LIMIT 1");
  341. DataRow mRow = dbClient.GetRow();
  342. if (mRow == null)
  343. continue;
  344.  
  345. Pet Pet = new Pet(Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["user_id"]), Convert.ToInt32(Row["room_id"]), Convert.ToString(Row["name"]), Convert.ToInt32(mRow["type"]), Convert.ToString(mRow["race"]),
  346. Convert.ToString(mRow["color"]), Convert.ToInt32(mRow["experience"]), Convert.ToInt32(mRow["energy"]), Convert.ToInt32(mRow["nutrition"]), Convert.ToInt32(mRow["respect"]), Convert.ToDouble(mRow["createstamp"]), Convert.ToInt32(Row["x"]), Convert.ToInt32(Row["y"]),
  347. Convert.ToDouble(Row["z"]), Convert.ToInt32(mRow["have_saddle"]), Convert.ToInt32(mRow["anyone_ride"]), Convert.ToInt32(mRow["hairdye"]), Convert.ToInt32(mRow["pethair"]), Convert.ToString(mRow["gnome_clothing"]));
  348.  
  349. var RndSpeechList = new List<RandomSpeech>();
  350.  
  351. _roomUserManager.DeployBot(new RoomBot(Pet.PetId, RoomId, "pet", "freeroam", Pet.Name, "", Pet.Look, Pet.X, Pet.Y, Convert.ToInt32(Pet.Z), 0, 0, 0, 0, 0, ref RndSpeechList, "", 0, Pet.OwnerId, false, 0, false, 0), Pet);
  352. }
  353. }
  354. }
  355.  
  356. public FilterComponent GetFilter()
  357. {
  358. return this._filterComponent;
  359. }
  360.  
  361. public WiredComponent GetWired()
  362. {
  363. return this._wiredComponent;
  364. }
  365.  
  366. public BansComponent GetBans()
  367. {
  368. return this._bansComponent;
  369. }
  370.  
  371. public TradingComponent GetTrading()
  372. {
  373. return this._tradingComponent;
  374. }
  375.  
  376. public void LoadPromotions()
  377. {
  378. DataRow GetPromotion = null;
  379. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  380. {
  381. dbClient.SetQuery("SELECT * FROM `room_promotions` WHERE `room_id` = " + this.Id + " LIMIT 1;");
  382. GetPromotion = dbClient.GetRow();
  383.  
  384. if (GetPromotion != null)
  385. {
  386. if (Convert.ToDouble(GetPromotion["timestamp_expire"]) > PlusEnvironment.GetUnixTimestamp())
  387. RoomData._promotion = new RoomPromotion(Convert.ToString(GetPromotion["title"]), Convert.ToString(GetPromotion["description"]), Convert.ToDouble(GetPromotion["timestamp_start"]), Convert.ToDouble(GetPromotion["timestamp_expire"]), Convert.ToInt32(GetPromotion["category_id"]));
  388. }
  389. }
  390. }
  391.  
  392. public void LoadRights()
  393. {
  394. UsersWithRights = new List<int>();
  395. if (Group != null)
  396. return;
  397.  
  398. DataTable Data = null;
  399.  
  400. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  401. {
  402. dbClient.SetQuery("SELECT room_rights.user_id FROM room_rights WHERE room_id = @roomid");
  403. dbClient.AddParameter("roomid", Id);
  404. Data = dbClient.GetTable();
  405. }
  406.  
  407. if (Data != null)
  408. {
  409. foreach (DataRow Row in Data.Rows)
  410. {
  411. UsersWithRights.Add(Convert.ToInt32(Row["user_id"]));
  412. }
  413. }
  414. }
  415.  
  416. private void LoadFilter()
  417. {
  418. this._wordFilterList = new List<string>();
  419.  
  420. DataTable Data = null;
  421. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  422. {
  423. dbClient.SetQuery("SELECT * FROM `room_filter` WHERE `room_id` = @roomid;");
  424. dbClient.AddParameter("roomid", Id);
  425. Data = dbClient.GetTable();
  426. }
  427.  
  428. if (Data == null)
  429. return;
  430.  
  431. foreach (DataRow Row in Data.Rows)
  432. {
  433. this._wordFilterList.Add(Convert.ToString(Row["word"]));
  434. }
  435. }
  436.  
  437. public bool CheckRights(GameClient Session)
  438. {
  439. return CheckRights(Session, false);
  440. }
  441.  
  442. public bool CheckRights(GameClient Session, bool RequireOwnership, bool CheckForGroups = false)
  443. {
  444. try
  445. {
  446. if (Session == null || Session.GetHabbo() == null)
  447. return false;
  448.  
  449. if (Session.GetHabbo().Username == OwnerName && Type == "private")
  450. return true;
  451.  
  452. if (Session.GetHabbo().GetPermissions().HasRight("room_any_owner"))
  453. return true;
  454.  
  455. if (!RequireOwnership && Type == "private")
  456. {
  457. if (Session.GetHabbo().GetPermissions().HasRight("room_any_rights"))
  458. return true;
  459.  
  460. if (UsersWithRights.Contains(Session.GetHabbo().Id))
  461. return true;
  462. }
  463.  
  464. if (CheckForGroups && Type == "private")
  465. {
  466. if (Group == null)
  467. return false;
  468.  
  469. if (Group.IsAdmin(Session.GetHabbo().Id))
  470. return true;
  471.  
  472. if (Group.AdminOnlyDeco == 0)
  473. {
  474. if (Group.IsAdmin(Session.GetHabbo().Id))
  475. return true;
  476. }
  477. }
  478. }
  479. catch (Exception e) { ExceptionLogger.LogException(e); }
  480. return false;
  481. }
  482.  
  483. public void OnUserShoot(RoomUser User, Item Ball)
  484. {
  485. Func<Item, bool> predicate = null;
  486. string Key = null;
  487. foreach (Item item in this.GetRoomItemHandler().GetFurniObjects(Ball.GetX, Ball.GetY).ToList())
  488. {
  489. if (item.GetBaseItem().ItemName.StartsWith("fball_goal_"))
  490. {
  491. Key = item.GetBaseItem().ItemName.Split(new char[] { '_' })[2];
  492. User.UnIdle();
  493. User.DanceId = 0;
  494.  
  495.  
  496. PlusEnvironment.GetGame().GetAchievementManager().ProgressAchievement(User.GetClient(), "ACH_FootballGoalScored", 1);
  497.  
  498. SendPacket(new ActionComposer(User.VirtualId, 1));
  499. }
  500. }
  501.  
  502. if (Key != null)
  503. {
  504. if (predicate == null)
  505. {
  506. predicate = p => p.GetBaseItem().ItemName == ("fball_score_" + Key);
  507. }
  508.  
  509. foreach (Item item2 in this.GetRoomItemHandler().GetFloor.Where<Item>(predicate).ToList())
  510. {
  511. if (item2.GetBaseItem().ItemName == ("fball_score_" + Key))
  512. {
  513. if (!String.IsNullOrEmpty(item2.ExtraData))
  514. item2.ExtraData = (Convert.ToInt32(item2.ExtraData) + 1).ToString();
  515. else
  516. item2.ExtraData = "1";
  517. item2.UpdateState();
  518. }
  519. }
  520. }
  521. }
  522.  
  523. public void ProcessRoom()
  524. {
  525. if (isCrashed || mDisposed)
  526. return;
  527.  
  528. try
  529. {
  530. if (this.GetRoomUserManager().GetRoomUsers().Count == 0)
  531. this.IdleTime++;
  532. else if (this.IdleTime > 0)
  533. this.IdleTime = 0;
  534.  
  535. if (this.RoomData.HasActivePromotion && this.RoomData.Promotion.HasExpired)
  536. {
  537. this.RoomData.EndPromotion();
  538. }
  539.  
  540. if (this.IdleTime >= 60 && !this.RoomData.HasActivePromotion)
  541. {
  542. PlusEnvironment.GetGame().GetRoomManager().UnloadRoom(this);
  543. return;
  544. }
  545.  
  546. try { GetRoomItemHandler().OnCycle(); }
  547. catch (Exception e)
  548. {
  549. ExceptionLogger.LogException(e);
  550. }
  551.  
  552. try { GetRoomUserManager().OnCycle(); }
  553. catch (Exception e)
  554. {
  555. ExceptionLogger.LogException(e);
  556. }
  557.  
  558. #region Status Updates
  559. try
  560. {
  561. GetRoomUserManager().SerializeStatusUpdates();
  562. }
  563. catch (Exception e)
  564. {
  565. ExceptionLogger.LogException(e);
  566. }
  567. #endregion
  568.  
  569. #region Game Item Cycle
  570. try
  571. {
  572. if (_gameItemHandler != null)
  573. _gameItemHandler.OnCycle();
  574. }
  575. catch (Exception e)
  576. {
  577. ExceptionLogger.LogException(e);
  578. }
  579. #endregion
  580.  
  581. try { GetWired().OnCycle(); }
  582. catch (Exception e)
  583. {
  584. ExceptionLogger.LogException(e);
  585. }
  586.  
  587. }
  588. catch (Exception e)
  589. {
  590. ExceptionLogger.LogException(e);
  591. OnRoomCrash(e);
  592. }
  593. }
  594.  
  595. private void OnRoomCrash(Exception e)
  596. {
  597. try
  598. {
  599. foreach (RoomUser user in _roomUserManager.GetRoomUsers().ToList())
  600. {
  601. if (user == null || user.GetClient() == null)
  602. continue;
  603.  
  604. user.GetClient().SendNotification("Sorry, it appears that room has crashed!");//Unhandled exception in room: " + e);
  605.  
  606. try
  607. {
  608. GetRoomUserManager().RemoveUserFromRoom(user.GetClient(), true, false);
  609. }
  610. catch (Exception e2)
  611. {
  612. ExceptionLogger.LogException(e2); }
  613. }
  614. }
  615. catch (Exception e3)
  616. {
  617. ExceptionLogger.LogException(e3);
  618. }
  619.  
  620. isCrashed = true;
  621. PlusEnvironment.GetGame().GetRoomManager().UnloadRoom(this, true);
  622. }
  623.  
  624.  
  625. public bool CheckMute(GameClient Session)
  626. {
  627. if (MutedUsers.ContainsKey(Session.GetHabbo().Id))
  628. {
  629. if (MutedUsers[Session.GetHabbo().Id] < PlusEnvironment.GetUnixTimestamp())
  630. {
  631. MutedUsers.Remove(Session.GetHabbo().Id);
  632. }
  633. else
  634. {
  635. return true;
  636. }
  637. }
  638.  
  639. if (Session.GetHabbo().TimeMuted > 0 || (RoomMuted && Session.GetHabbo().Username != OwnerName))
  640. return true;
  641.  
  642. return false;
  643. }
  644.  
  645. public void SendObjects(GameClient Session)
  646. {
  647. Room Room = Session.GetHabbo().CurrentRoom;
  648.  
  649. Session.SendPacket(new HeightMapComposer(Room.GetGameMap().Model.Heightmap));
  650. Session.SendPacket(new FloorHeightMapComposer(Room.GetGameMap().Model.GetRelativeHeightmap(), Room.GetGameMap().StaticModel.WallHeight));
  651.  
  652. foreach (RoomUser RoomUser in _roomUserManager.GetUserList().ToList())
  653. {
  654. if (RoomUser == null)
  655. continue;
  656.  
  657. Session.SendPacket(new UsersComposer(RoomUser));
  658.  
  659. if (RoomUser.IsBot && RoomUser.BotData.DanceId > 0)
  660. Session.SendPacket(new DanceComposer(RoomUser, RoomUser.BotData.DanceId));
  661. else if (!RoomUser.IsBot && !RoomUser.IsPet && RoomUser.IsDancing)
  662. Session.SendPacket(new DanceComposer(RoomUser, RoomUser.DanceId));
  663.  
  664. if (RoomUser.IsAsleep)
  665. Session.SendPacket(new SleepComposer(RoomUser, true));
  666.  
  667. if (RoomUser.CarryItemID > 0 && RoomUser.CarryTimer > 0)
  668. Session.SendPacket(new CarryObjectComposer(RoomUser.VirtualId, RoomUser.CarryItemID));
  669.  
  670. if (!RoomUser.IsBot && !RoomUser.IsPet && RoomUser.CurrentEffect > 0)
  671. Session.SendPacket(new AvatarEffectComposer(RoomUser.VirtualId, RoomUser.CurrentEffect));
  672. }
  673.  
  674. Session.SendPacket(new UserUpdateComposer(_roomUserManager.GetUserList().ToList()));
  675. Session.SendPacket(new ObjectsComposer(Room.GetRoomItemHandler().GetFloor.ToArray(), this));
  676. Session.SendPacket(new ItemsComposer(Room.GetRoomItemHandler().GetWall.ToArray(), this));
  677. }
  678.  
  679. #region Tents
  680. public void AddTent(int TentId)
  681. {
  682. if (Tents.ContainsKey(TentId))
  683. Tents.Remove(TentId);
  684.  
  685. Tents.Add(TentId, new List<RoomUser>());
  686. }
  687.  
  688. public void RemoveTent(int TentId)
  689. {
  690. if (!Tents.ContainsKey(TentId))
  691. return;
  692.  
  693. List<RoomUser> Users = Tents[TentId];
  694. foreach (RoomUser User in Users.ToList())
  695. {
  696. if (User == null || User.GetClient() == null || User.GetClient().GetHabbo() == null)
  697. continue;
  698.  
  699. User.GetClient().GetHabbo().TentId = 0;
  700. }
  701.  
  702. if (Tents.ContainsKey(TentId))
  703. Tents.Remove(TentId);
  704. }
  705.  
  706. public void AddUserToTent(int TentId, RoomUser User)
  707. {
  708. if (User != null && User.GetClient() != null && User.GetClient().GetHabbo() != null)
  709. {
  710. if (!Tents.ContainsKey(TentId))
  711. Tents.Add(TentId, new List<RoomUser>());
  712.  
  713. if (!Tents[TentId].Contains(User))
  714. Tents[TentId].Add(User);
  715. User.GetClient().GetHabbo().TentId = TentId;
  716. }
  717. }
  718.  
  719. public void RemoveUserFromTent(int TentId, RoomUser User)
  720. {
  721. if (User != null && User.GetClient() != null && User.GetClient().GetHabbo() != null)
  722. {
  723. if (!Tents.ContainsKey(TentId))
  724. Tents.Add(TentId, new List<RoomUser>());
  725.  
  726. if (Tents[TentId].Contains(User))
  727. Tents[TentId].Remove(User);
  728.  
  729. User.GetClient().GetHabbo().TentId = 0;
  730. }
  731. }
  732.  
  733. public void SendToTent(int Id, int TentId, IServerPacket Packet)
  734. {
  735. if (!Tents.ContainsKey(TentId))
  736. return;
  737.  
  738. foreach (RoomUser User in Tents[TentId].ToList())
  739. {
  740. if (User == null || User.GetClient() == null || User.GetClient().GetHabbo() == null || User.GetClient().GetHabbo().GetIgnores().IgnoredUserIds().Contains(Id) || User.GetClient().GetHabbo().TentId != TentId)
  741. continue;
  742.  
  743. User.GetClient().SendPacket(Packet);
  744. }
  745. }
  746. #endregion
  747.  
  748. #region Communication (Packets)
  749. public void SendPacket(IServerPacket Message, bool UsersWithRightsOnly = false)
  750. {
  751. if (Message == null)
  752. return;
  753.  
  754. try
  755. {
  756.  
  757. List<RoomUser> Users = this._roomUserManager.GetUserList().ToList();
  758.  
  759. if (this == null || this._roomUserManager == null || Users == null)
  760. return;
  761.  
  762. foreach (RoomUser User in Users)
  763. {
  764. if (User == null || User.IsBot)
  765. continue;
  766.  
  767. if (User.GetClient() == null || User.GetClient().GetConnection() == null)
  768. continue;
  769.  
  770. if (UsersWithRightsOnly && !this.CheckRights(User.GetClient()))
  771. continue;
  772.  
  773. User.GetClient().SendPacket(Message);
  774. }
  775. }
  776. catch (Exception e)
  777. {
  778. ExceptionLogger.LogException(e);
  779. }
  780. }
  781.  
  782. public void BroadcastPacket(byte[] Packet)
  783. {
  784. foreach (RoomUser User in this._roomUserManager.GetUserList().ToList())
  785. {
  786. if (User == null || User.IsBot)
  787. continue;
  788.  
  789. if (User.GetClient() == null || User.GetClient().GetConnection() == null)
  790. continue;
  791.  
  792. User.GetClient().GetConnection().SendData(Packet);
  793. }
  794. }
  795.  
  796. public void SendPacket(List<ServerPacket> Messages)
  797. {
  798. if (Messages.Count == 0)
  799. return;
  800.  
  801. try
  802. {
  803. byte[] TotalBytes = new byte[0];
  804. int Current = 0;
  805.  
  806. foreach (ServerPacket Packet in Messages.ToList())
  807. {
  808. byte[] ToAdd = Packet.GetBytes();
  809. int NewLen = TotalBytes.Length + ToAdd.Length;
  810.  
  811. Array.Resize(ref TotalBytes, NewLen);
  812.  
  813. for (int i = 0; i < ToAdd.Length; i++)
  814. {
  815. TotalBytes[Current] = ToAdd[i];
  816. Current++;
  817. }
  818. }
  819.  
  820. this.BroadcastPacket(TotalBytes);
  821. }
  822. catch (Exception e)
  823. {
  824. ExceptionLogger.LogException(e);
  825. }
  826. }
  827. #endregion
  828.  
  829. public void Dispose()
  830. {
  831. SendPacket(new CloseConnectionComposer());
  832.  
  833. if (!mDisposed)
  834. {
  835. isCrashed = false;
  836. mDisposed = true;
  837.  
  838. /* TODO: Needs reviewing */
  839. try
  840. {
  841. if (ProcessTask != null && ProcessTask.IsCompleted)
  842. ProcessTask.Dispose();
  843. }
  844. catch { }
  845.  
  846. if (this.ActiveTrades.Count > 0)
  847. this.ActiveTrades.Clear();
  848.  
  849. this.TonerData = null;
  850. this.MoodlightData = null;
  851.  
  852. if (this.MutedUsers.Count > 0)
  853. this.MutedUsers.Clear();
  854.  
  855. if (this.Tents.Count > 0)
  856. this.Tents.Clear();
  857.  
  858. if (this.UsersWithRights.Count > 0)
  859. this.UsersWithRights.Clear();
  860.  
  861. if (this._gameManager != null)
  862. {
  863. this._gameManager.Dispose();
  864. this._gameManager = null;
  865. }
  866.  
  867. if (this._freeze != null)
  868. {
  869. this._freeze.Dispose();
  870. this._freeze = null;
  871. }
  872.  
  873. if (this._soccer != null)
  874. {
  875. this._soccer.Dispose();
  876. this._soccer = null;
  877. }
  878.  
  879. if (this._banzai != null)
  880. {
  881. this._banzai.Dispose();
  882. this._banzai = null;
  883. }
  884.  
  885. if (this._gamemap != null)
  886. {
  887. this._gamemap.Dispose();
  888. this._gamemap = null;
  889. }
  890.  
  891.  
  892. if (this._gameItemHandler != null)
  893. {
  894. this._gameItemHandler.Dispose();
  895. this._gameItemHandler = null;
  896. }
  897.  
  898. // Room Data?
  899.  
  900. if (this.teambanzai != null)
  901. {
  902. this.teambanzai.Dispose();
  903. this.teambanzai = null;
  904. }
  905.  
  906. if (this.teamfreeze != null)
  907. {
  908. this.teamfreeze.Dispose();
  909. this.teamfreeze = null;
  910. }
  911.  
  912. if (this._roomUserManager != null)
  913. {
  914. this._roomUserManager.Dispose();
  915. this._roomUserManager = null;
  916. }
  917.  
  918. if (this._roomItemHandling != null)
  919. {
  920. this._roomItemHandling.Dispose();
  921. this._roomItemHandling = null;
  922. }
  923.  
  924. if (this._wordFilterList.Count > 0)
  925. this._wordFilterList.Clear();
  926.  
  927. if (this._filterComponent != null)
  928. this._filterComponent.Cleanup();
  929.  
  930. if (this._wiredComponent != null)
  931. this._wiredComponent.Cleanup();
  932.  
  933. if (this._bansComponent != null)
  934. this._bansComponent.Cleanup();
  935.  
  936. if (this._tradingComponent != null)
  937. this._tradingComponent.Cleanup();
  938. }
  939. }
  940. }
  941. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement