Advertisement
Guest User

dddd

a guest
May 11th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.55 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> Bans;
  55. public Dictionary<int, double> MutedUsers;
  56.  
  57.  
  58. private Dictionary<int, List<RoomUser>> Tents;
  59.  
  60. public List<int> UsersWithRights;
  61. private GameManager _gameManager;
  62. private Freeze _freeze;
  63. private Soccer _soccer;
  64. private BattleBanzai _banzai;
  65.  
  66. private Gamemap _gamemap;
  67. private GameItemHandler _gameItemHandler;
  68.  
  69. private RoomData _roomData;
  70. public TeamManager teambanzai;
  71. public TeamManager teamfreeze;
  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.  
  81. public int IsLagging { get; set; }
  82. public int IdleTime { get; set; }
  83.  
  84. //private ProcessComponent _process = null;
  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.Bans = new Dictionary<int, double>();
  150. this.MutedUsers = new Dictionary<int, double>();
  151. this.Tents = new Dictionary<int, List<RoomUser>>();
  152.  
  153. _gamemap = new Gamemap(this);
  154. if (_roomItemHandling == null)
  155. _roomItemHandling = new RoomItemHandling(this);
  156. _roomUserManager = new RoomUserManager(this);
  157.  
  158. this._filterComponent = new FilterComponent(this);
  159. this._wiredComponent = new WiredComponent(this);
  160.  
  161. GetRoomItemHandler().LoadFurniture();
  162. GetGameMap().GenerateMaps();
  163.  
  164. this.LoadPromotions();
  165. this.LoadRights();
  166. this.LoadBans();
  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. #region Room Bans
  181.  
  182. public bool UserIsBanned(int pId)
  183. {
  184. return Bans.ContainsKey(pId);
  185. }
  186.  
  187. public void RemoveBan(int pId)
  188. {
  189. Bans.Remove(pId);
  190. }
  191.  
  192. public void AddBan(int pId, long Time)
  193. {
  194. if (!Bans.ContainsKey(Convert.ToInt32(pId)))
  195. Bans.Add(pId, PlusEnvironment.GetUnixTimestamp() + Time);
  196.  
  197. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  198. {
  199. dbClient.RunQuery("REPLACE INTO `room_bans` VALUES (" + pId + ", " + Id + ", " + (PlusEnvironment.GetUnixTimestamp() + Time) + ")");
  200. }
  201. }
  202.  
  203. public List<int> BannedUsers()
  204. {
  205. var Bans = new List<int>();
  206.  
  207. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  208. {
  209. dbClient.SetQuery("SELECT user_id FROM room_bans WHERE expire > UNIX_TIMESTAMP() AND room_id=" + Id);
  210. DataTable Table = dbClient.getTable();
  211.  
  212. foreach (DataRow Row in Table.Rows)
  213. {
  214. Bans.Add(Convert.ToInt32(Row[0]));
  215. }
  216. }
  217.  
  218. return Bans;
  219. }
  220.  
  221. public bool HasBanExpired(int pId)
  222. {
  223. if (!UserIsBanned(pId))
  224. return true;
  225.  
  226. if (Bans[pId] < PlusEnvironment.GetUnixTimestamp())
  227. return true;
  228.  
  229. return false;
  230. }
  231.  
  232. public void Unban(int UserId)
  233. {
  234. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  235. {
  236. dbClient.RunQuery("DELETE FROM `room_bans` WHERE `user_id` = '" + UserId + "' AND `room_id` = '" + Id + "' LIMIT 1");
  237. }
  238.  
  239. if (Bans.ContainsKey(UserId))
  240. Bans.Remove(UserId);
  241. }
  242.  
  243. #endregion
  244.  
  245. #region Trading
  246.  
  247. public bool HasActiveTrade(RoomUser User)
  248. {
  249. if (User.IsBot)
  250. return false;
  251.  
  252. return HasActiveTrade(User.GetClient().GetHabbo().Id);
  253. }
  254.  
  255. public bool HasActiveTrade(int UserId)
  256. {
  257. if (ActiveTrades.Count == 0)
  258. return false;
  259.  
  260. foreach (Trade Trade in ActiveTrades.ToArray())
  261. {
  262. if (Trade.ContainsUser(UserId))
  263. return true;
  264. }
  265. return false;
  266. }
  267.  
  268. public Trade GetUserTrade(int UserId)
  269. {
  270. foreach (Trade Trade in ActiveTrades.ToArray())
  271. {
  272. if (Trade.ContainsUser(UserId))
  273. {
  274. return Trade;
  275. }
  276. }
  277.  
  278. return null;
  279. }
  280.  
  281. public void TryStartTrade(RoomUser UserOne, RoomUser UserTwo)
  282. {
  283. if (UserOne == null || UserTwo == null || UserOne.IsBot || UserTwo.IsBot || UserOne.IsTrading ||
  284. UserTwo.IsTrading || HasActiveTrade(UserOne) || HasActiveTrade(UserTwo))
  285. return;
  286.  
  287. ActiveTrades.Add(new Trade(UserOne.GetClient().GetHabbo().Id, UserTwo.GetClient().GetHabbo().Id, RoomId));
  288. }
  289.  
  290. public void TryStopTrade(int UserId)
  291. {
  292. Trade Trade = GetUserTrade(UserId);
  293.  
  294. if (Trade == null)
  295. return;
  296.  
  297. Trade.CloseTrade(UserId);
  298. ActiveTrades.Remove(Trade);
  299. }
  300.  
  301. #endregion
  302.  
  303.  
  304. public int UserCount
  305. {
  306. get { return _roomUserManager.GetRoomUsers().Count; }
  307. }
  308.  
  309. public int RoomId
  310. {
  311. get { return Id; }
  312. }
  313.  
  314. public bool CanTradeInRoom
  315. {
  316. get { return true; }
  317. }
  318.  
  319. public RoomData RoomData
  320. {
  321. get { return _roomData; }
  322. }
  323.  
  324. public Gamemap GetGameMap()
  325. {
  326. return _gamemap;
  327. }
  328.  
  329. public RoomItemHandling GetRoomItemHandler()
  330. {
  331. if (_roomItemHandling == null)
  332. {
  333. _roomItemHandling = new RoomItemHandling(this);
  334. }
  335. return _roomItemHandling;
  336. }
  337.  
  338. public RoomUserManager GetRoomUserManager()
  339. {
  340. return _roomUserManager;
  341. }
  342.  
  343. public Soccer GetSoccer()
  344. {
  345. if (_soccer == null)
  346. _soccer = new Soccer(this);
  347.  
  348. return _soccer;
  349. }
  350.  
  351. public TeamManager GetTeamManagerForBanzai()
  352. {
  353. if (teambanzai == null)
  354. teambanzai = TeamManager.createTeamforGame("banzai");
  355. return teambanzai;
  356. }
  357.  
  358. public TeamManager GetTeamManagerForFreeze()
  359. {
  360. if (teamfreeze == null)
  361. teamfreeze = TeamManager.createTeamforGame("freeze");
  362. return teamfreeze;
  363. }
  364.  
  365. public BattleBanzai GetBanzai()
  366. {
  367. if (_banzai == null)
  368. _banzai = new BattleBanzai(this);
  369. return _banzai;
  370. }
  371.  
  372. public Freeze GetFreeze()
  373. {
  374. if (_freeze == null)
  375. _freeze = new Freeze(this);
  376. return _freeze;
  377. }
  378.  
  379. public GameManager GetGameManager()
  380. {
  381. if (_gameManager == null)
  382. _gameManager = new GameManager(this);
  383. return _gameManager;
  384. }
  385.  
  386. public GameItemHandler GetGameItemHandler()
  387. {
  388. if (_gameItemHandler == null)
  389. _gameItemHandler = new GameItemHandler(this);
  390. return _gameItemHandler;
  391. }
  392.  
  393. public bool GotSoccer()
  394. {
  395. return (_soccer != null);
  396. }
  397.  
  398. public bool GotBanzai()
  399. {
  400. return (_banzai != null);
  401. }
  402.  
  403. public bool GotFreeze()
  404. {
  405. return (_freeze != null);
  406. }
  407.  
  408. public void ClearTags()
  409. {
  410. Tags.Clear();
  411. }
  412.  
  413. public void AddTagRange(List<string> tags)
  414. {
  415. Tags.AddRange(tags);
  416. }
  417.  
  418. public void InitBots()
  419. {
  420. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  421. {
  422. 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'");
  423. DataTable Data = dbClient.getTable();
  424. if (Data == null)
  425. return;
  426.  
  427. foreach (DataRow Bot in Data.Rows)
  428. {
  429. dbClient.SetQuery("SELECT `text` FROM `bots_speech` WHERE `bot_id` = '" + Convert.ToInt32(Bot["id"]) + "'");
  430. DataTable BotSpeech = dbClient.getTable();
  431.  
  432. List<RandomSpeech> Speeches = new List<RandomSpeech>();
  433.  
  434. foreach (DataRow Speech in BotSpeech.Rows)
  435. {
  436. Speeches.Add(new RandomSpeech(Convert.ToString(Speech["text"]), Convert.ToInt32(Bot["id"])));
  437. }
  438.  
  439. _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);
  440. }
  441. }
  442. }
  443.  
  444. public void InitPets()
  445. {
  446. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  447. {
  448. dbClient.SetQuery("SELECT `id`,`user_id`,`room_id`,`name`,`x`,`y`,`z` FROM `bots` WHERE `room_id` = '" + RoomId + "' AND `ai_type` = 'pet'");
  449. DataTable Data = dbClient.getTable();
  450.  
  451. if (Data == null)
  452. return;
  453.  
  454. foreach (DataRow Row in Data.Rows)
  455. {
  456. 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");
  457. DataRow mRow = dbClient.getRow();
  458. if (mRow == null)
  459. continue;
  460.  
  461. 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"]),
  462. 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"]),
  463. 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"]));
  464.  
  465. var RndSpeechList = new List<RandomSpeech>();
  466.  
  467. _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);
  468. }
  469. }
  470. }
  471.  
  472. public FilterComponent GetFilter()
  473. {
  474. return this._filterComponent;
  475. }
  476.  
  477. public WiredComponent GetWired()
  478. {
  479. return this._wiredComponent;
  480. }
  481.  
  482. public void LoadPromotions()
  483. {
  484. DataRow GetPromotion = null;
  485. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  486. {
  487. dbClient.SetQuery("SELECT * FROM `room_promotions` WHERE `room_id` = " + this.Id + " LIMIT 1;");
  488. GetPromotion = dbClient.getRow();
  489.  
  490. if (GetPromotion != null)
  491. {
  492. if (Convert.ToDouble(GetPromotion["timestamp_expire"]) > PlusEnvironment.GetUnixTimestamp())
  493. 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"]));
  494. }
  495. }
  496. }
  497.  
  498. public void LoadRights()
  499. {
  500. UsersWithRights = new List<int>();
  501. if (Group != null)
  502. return;
  503.  
  504. DataTable Data = null;
  505.  
  506. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  507. {
  508. dbClient.SetQuery("SELECT room_rights.user_id FROM room_rights WHERE room_id = @roomid");
  509. dbClient.AddParameter("roomid", Id);
  510. Data = dbClient.getTable();
  511. }
  512.  
  513. if (Data != null)
  514. {
  515. foreach (DataRow Row in Data.Rows)
  516. {
  517. UsersWithRights.Add(Convert.ToInt32(Row["user_id"]));
  518. }
  519. }
  520. }
  521.  
  522. private void LoadFilter()
  523. {
  524. this._wordFilterList = new List<string>();
  525.  
  526. DataTable Data = null;
  527. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  528. {
  529. dbClient.SetQuery("SELECT * FROM `room_filter` WHERE `room_id` = @roomid;");
  530. dbClient.AddParameter("roomid", Id);
  531. Data = dbClient.getTable();
  532. }
  533.  
  534. if (Data == null)
  535. return;
  536.  
  537. foreach (DataRow Row in Data.Rows)
  538. {
  539. this._wordFilterList.Add(Convert.ToString(Row["word"]));
  540. }
  541. }
  542.  
  543. public void LoadBans()
  544. {
  545. this.Bans = new Dictionary<int, double>();
  546.  
  547. DataTable Bans;
  548.  
  549. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  550. {
  551. dbClient.SetQuery("SELECT user_id, expire FROM room_bans WHERE room_id = " + Id);
  552. Bans = dbClient.getTable();
  553. }
  554.  
  555. if (Bans == null)
  556. return;
  557.  
  558. foreach (DataRow ban in Bans.Rows)
  559. {
  560. this.Bans.Add(Convert.ToInt32(ban[0]), Convert.ToDouble(ban[1]));
  561. }
  562. }
  563.  
  564. public bool CheckRights(GameClient Session)
  565. {
  566. return CheckRights(Session, false);
  567. }
  568.  
  569. public bool CheckRights(GameClient Session, bool RequireOwnership, bool CheckForGroups = false)
  570. {
  571. try
  572. {
  573. if (Session == null || Session.GetHabbo() == null)
  574. return false;
  575.  
  576. if (Session.GetHabbo().Username == OwnerName && Type == "private")
  577. return true;
  578.  
  579. if (Session.GetHabbo().GetPermissions().HasRight("room_any_owner"))
  580. return true;
  581.  
  582. if (!RequireOwnership && Type == "private")
  583. {
  584. if (Session.GetHabbo().GetPermissions().HasRight("room_any_rights"))
  585. return true;
  586.  
  587. if (UsersWithRights.Contains(Session.GetHabbo().Id))
  588. return true;
  589. }
  590.  
  591. if (CheckForGroups && Type == "private")
  592. {
  593. if (Group == null)
  594. return false;
  595.  
  596. if (Group.IsAdmin(Session.GetHabbo().Id))
  597. return true;
  598.  
  599. if (Group.AdminOnlyDeco == 0)
  600. {
  601. if (Group.IsAdmin(Session.GetHabbo().Id))
  602. return true;
  603. }
  604. }
  605. }
  606. catch (Exception e) { Logging.HandleException(e, "Room.CheckRights"); }
  607. return false;
  608. }
  609.  
  610. public void OnUserShoot(RoomUser User, Item Ball)
  611. {
  612. Func<Item, bool> predicate = null;
  613. string Key = null;
  614. foreach (Item item in this.GetRoomItemHandler().GetFurniObjects(Ball.GetX, Ball.GetY).ToList())
  615. {
  616. if (item.GetBaseItem().ItemName.StartsWith("fball_goal_"))
  617. {
  618. Key = item.GetBaseItem().ItemName.Split(new char[] { '_' })[2];
  619. User.UnIdle();
  620. User.DanceId = 0;
  621.  
  622.  
  623. PlusEnvironment.GetGame().GetAchievementManager().ProgressAchievement(User.GetClient(), "ACH_FootballGoalScored", 1);
  624.  
  625. SendMessage(new ActionComposer(User.VirtualId, 1));
  626. }
  627. }
  628.  
  629. if (Key != null)
  630. {
  631. if (predicate == null)
  632. {
  633. predicate = p => p.GetBaseItem().ItemName == ("fball_score_" + Key);
  634. }
  635.  
  636. foreach (Item item2 in this.GetRoomItemHandler().GetFloor.Where<Item>(predicate).ToList())
  637. {
  638. if (item2.GetBaseItem().ItemName == ("fball_score_" + Key))
  639. {
  640. if (!String.IsNullOrEmpty(item2.ExtraData))
  641. item2.ExtraData = (Convert.ToInt32(item2.ExtraData) + 1).ToString();
  642. else
  643. item2.ExtraData = "1";
  644. item2.UpdateState();
  645. }
  646. }
  647. }
  648. }
  649.  
  650. public void ProcessRoom()
  651. {
  652. if (isCrashed || mDisposed)
  653. return;
  654.  
  655. try
  656. {
  657. if (this.GetRoomUserManager().GetRoomUsers().Count == 0)
  658. this.IdleTime++;
  659. else if (this.IdleTime > 0)
  660. this.IdleTime = 0;
  661.  
  662. if (this.RoomData.HasActivePromotion && this.RoomData.Promotion.HasExpired)
  663. {
  664. this.RoomData.EndPromotion();
  665. }
  666.  
  667. if (this.IdleTime >= 60 && !this.RoomData.HasActivePromotion)
  668. {
  669. PlusEnvironment.GetGame().GetRoomManager().UnloadRoom(this);
  670. return;
  671. }
  672.  
  673. try { GetRoomItemHandler().OnCycle(); }
  674. catch (Exception e)
  675. {
  676. Logging.LogException("Room ID [" + RoomId + "] is currently having issues cycling the room items." + e.ToString());
  677. }
  678.  
  679. try { GetRoomUserManager().OnCycle(); }
  680. catch (Exception e)
  681. {
  682. Logging.LogException("Room ID [" + RoomId + "] is currently having issues cycling the room users." + e.ToString());
  683. }
  684.  
  685. #region Status Updates
  686. try
  687. {
  688. GetRoomUserManager().SerializeStatusUpdates();
  689. }
  690. catch (Exception e)
  691. {
  692. Logging.LogException("Room ID [" + RoomId + "] is currently having issues cycling the room user statuses." + e.ToString());
  693. }
  694. #endregion
  695.  
  696. #region Game Item Cycle
  697. try
  698. {
  699. if (_gameItemHandler != null)
  700. _gameItemHandler.OnCycle();
  701. }
  702. catch (Exception e)
  703. {
  704. Logging.LogException("Room ID [" + RoomId + "] is currently having issues cycling the game items." + e.ToString());
  705. }
  706. #endregion
  707.  
  708. try { GetWired().OnCycle(); }
  709. catch (Exception e)
  710. {
  711. Logging.LogException("Room ID [" + RoomId + "] is currently having issues cycling wired." + e.ToString());
  712. }
  713.  
  714. }
  715. catch (Exception e)
  716. {
  717. Logging.WriteLine("Room ID [" + RoomId + "] has crashed.");
  718. Logging.LogException("Room ID [" + RoomId + "] has crashed." + e.ToString());
  719. OnRoomCrash(e);
  720. }
  721. }
  722.  
  723. private void OnRoomCrash(Exception e)
  724. {
  725. Logging.LogThreadException(e.ToString(), "Room cycle task for room " + RoomId);
  726.  
  727. try
  728. {
  729. foreach (RoomUser user in _roomUserManager.GetRoomUsers().ToList())
  730. {
  731. if (user == null || user.GetClient() == null)
  732. continue;
  733.  
  734. user.GetClient().SendNotification("Sorry, it appears that room has crashed!");//Unhandled exception in room: " + e);
  735.  
  736. try
  737. {
  738. GetRoomUserManager().RemoveUserFromRoom(user.GetClient(), true, false);
  739. }
  740. catch (Exception e2) { Logging.LogException(e2.ToString()); }
  741. }
  742. }
  743. catch (Exception e3) { Logging.LogException(e3.ToString()); }
  744.  
  745. isCrashed = true;
  746. PlusEnvironment.GetGame().GetRoomManager().UnloadRoom(this, true);
  747. }
  748.  
  749.  
  750. public bool CheckMute(GameClient Session)
  751. {
  752. if (MutedUsers.ContainsKey(Session.GetHabbo().Id))
  753. {
  754. if (MutedUsers[Session.GetHabbo().Id] < PlusEnvironment.GetUnixTimestamp())
  755. {
  756. MutedUsers.Remove(Session.GetHabbo().Id);
  757. }
  758. else
  759. {
  760. return true;
  761. }
  762. }
  763.  
  764. if (Session.GetHabbo().TimeMuted > 0 || (RoomMuted && Session.GetHabbo().Username != OwnerName))
  765. return true;
  766.  
  767. return false;
  768. }
  769.  
  770. public void AddChatlog(int Id, string Message)
  771. {
  772. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  773. {
  774. dbClient.SetQuery("INSERT INTO `chatlogs` (user_id, room_id, message, timestamp) VALUES (@user, @room, @message, @time)");
  775. dbClient.AddParameter("user", Id);
  776. dbClient.AddParameter("room", RoomId);
  777. dbClient.AddParameter("message", Message);
  778. dbClient.AddParameter("time", PlusEnvironment.GetUnixTimestamp());
  779. dbClient.RunQuery();
  780. }
  781. }
  782.  
  783. public void SendObjects(GameClient Session)
  784. {
  785. Room Room = Session.GetHabbo().CurrentRoom;
  786.  
  787. Session.SendMessage(new HeightMapComposer(Room.GetGameMap().Model.Heightmap));
  788. Session.SendMessage(new FloorHeightMapComposer(Room.GetGameMap().Model.GetRelativeHeightmap(), Room.GetGameMap().StaticModel.WallHeight));
  789.  
  790. foreach (RoomUser RoomUser in _roomUserManager.GetUserList().ToList())
  791. {
  792. if (RoomUser == null)
  793. continue;
  794.  
  795. Session.SendMessage(new UsersComposer(RoomUser));
  796.  
  797. if (RoomUser.IsBot && RoomUser.BotData.DanceId > 0)
  798. Session.SendMessage(new DanceComposer(RoomUser, RoomUser.BotData.DanceId));
  799. else if (!RoomUser.IsBot && !RoomUser.IsPet && RoomUser.IsDancing)
  800. Session.SendMessage(new DanceComposer(RoomUser, RoomUser.DanceId));
  801.  
  802. if (RoomUser.IsAsleep)
  803. Session.SendMessage(new SleepComposer(RoomUser, true));
  804.  
  805. if (RoomUser.CarryItemID > 0 && RoomUser.CarryTimer > 0)
  806. Session.SendMessage(new CarryObjectComposer(RoomUser.VirtualId, RoomUser.CarryItemID));
  807.  
  808. if (!RoomUser.IsBot && !RoomUser.IsPet && RoomUser.CurrentEffect > 0)
  809. Room.SendMessage(new AvatarEffectComposer(RoomUser.VirtualId, RoomUser.CurrentEffect));
  810. }
  811.  
  812. Session.SendMessage(new UserUpdateComposer(_roomUserManager.GetUserList().ToList()));
  813. Session.SendMessage(new ObjectsComposer(Room.GetRoomItemHandler().GetFloor.ToArray(), this));
  814. Session.SendMessage(new ItemsComposer(Room.GetRoomItemHandler().GetWall.ToArray(), this));
  815. }
  816.  
  817. #region Tents
  818. public void AddTent(int TentId)
  819. {
  820. if (Tents.ContainsKey(TentId))
  821. Tents.Remove(TentId);
  822.  
  823. Tents.Add(TentId, new List<RoomUser>());
  824. }
  825.  
  826. public void RemoveTent(int TentId, Item Item)
  827. {
  828. if (!Tents.ContainsKey(TentId))
  829. return;
  830.  
  831. List<RoomUser> Users = Tents[TentId];
  832. foreach (RoomUser User in Users.ToList())
  833. {
  834. if (User == null || User.GetClient() == null || User.GetClient().GetHabbo() == null)
  835. continue;
  836.  
  837. User.GetClient().GetHabbo().TentId = 0;
  838. }
  839.  
  840. if (Tents.ContainsKey(TentId))
  841. Tents.Remove(TentId);
  842. }
  843.  
  844. public void AddUserToTent(int TentId, RoomUser User, Item Item)
  845. {
  846. if (User != null && User.GetClient() != null && User.GetClient().GetHabbo() != null)
  847. {
  848. if (!Tents.ContainsKey(TentId))
  849. Tents.Add(TentId, new List<RoomUser>());
  850.  
  851. if (!Tents[TentId].Contains(User))
  852. Tents[TentId].Add(User);
  853. User.GetClient().GetHabbo().TentId = TentId;
  854. }
  855. }
  856.  
  857. public void RemoveUserFromTent(int TentId, RoomUser User, Item Item)
  858. {
  859. if (User != null && User.GetClient() != null && User.GetClient().GetHabbo() != null)
  860. {
  861. if (!Tents.ContainsKey(TentId))
  862. Tents.Add(TentId, new List<RoomUser>());
  863.  
  864. if (Tents[TentId].Contains(User))
  865. Tents[TentId].Remove(User);
  866.  
  867. User.GetClient().GetHabbo().TentId = 0;
  868. }
  869. }
  870.  
  871. public void SendToTent(int Id, int TentId, IServerPacket Packet)
  872. {
  873. if (!Tents.ContainsKey(TentId))
  874. return;
  875.  
  876. foreach (RoomUser User in Tents[TentId].ToList())
  877. {
  878. if (User == null || User.GetClient() == null || User.GetClient().GetHabbo() == null || User.GetClient().GetHabbo().MutedUsers.Contains(Id) || User.GetClient().GetHabbo().TentId != TentId)
  879. continue;
  880.  
  881. User.GetClient().SendMessage(Packet);
  882. }
  883. }
  884. #endregion
  885.  
  886. #region Communication (Packets)
  887. public void SendMessage(IServerPacket Message, bool UsersWithRightsOnly = false)
  888. {
  889. if (Message == null)
  890. return;
  891.  
  892. try
  893. {
  894.  
  895. List<RoomUser> Users = this._roomUserManager.GetUserList().ToList();
  896.  
  897. if (this == null || this._roomUserManager == null || Users == null)
  898. return;
  899.  
  900. foreach (RoomUser User in Users)
  901. {
  902. if (User == null || User.IsBot)
  903. continue;
  904.  
  905. if (User.GetClient() == null || User.GetClient().GetConnection() == null)
  906. continue;
  907.  
  908. if (UsersWithRightsOnly && !this.CheckRights(User.GetClient()))
  909. continue;
  910.  
  911. User.GetClient().SendMessage(Message);
  912. }
  913. }
  914. catch (Exception e)
  915. {
  916. Logging.HandleException(e, "Room.SendMessage");
  917. }
  918. }
  919.  
  920. public void BroadcastPacket(byte[] Packet)
  921. {
  922. foreach (RoomUser User in this._roomUserManager.GetUserList().ToList())
  923. {
  924. if (User == null || User.IsBot)
  925. continue;
  926.  
  927. if (User.GetClient() == null || User.GetClient().GetConnection() == null)
  928. continue;
  929.  
  930. User.GetClient().GetConnection().SendData(Packet);
  931. }
  932. }
  933.  
  934. public void SendMessage(List<ServerPacket> Messages)
  935. {
  936. if (Messages.Count == 0)
  937. return;
  938.  
  939. try
  940. {
  941. byte[] TotalBytes = new byte[0];
  942. int Current = 0;
  943.  
  944. foreach (ServerPacket Packet in Messages.ToList())
  945. {
  946. byte[] ToAdd = Packet.GetBytes();
  947. int NewLen = TotalBytes.Length + ToAdd.Length;
  948.  
  949. Array.Resize(ref TotalBytes, NewLen);
  950.  
  951. for (int i = 0; i < ToAdd.Length; i++)
  952. {
  953. TotalBytes[Current] = ToAdd[i];
  954. Current++;
  955. }
  956. }
  957.  
  958. this.BroadcastPacket(TotalBytes);
  959. }
  960. catch (Exception e)
  961. {
  962. Logging.HandleException(e, "Room.SendMessage List<ServerPacket>");
  963. }
  964. }
  965. #endregion
  966.  
  967. private void SaveAI()
  968. {
  969. foreach (RoomUser User in GetRoomUserManager().GetRoomUsers().ToList())
  970. {
  971. if (User == null || !User.IsBot)
  972. continue;
  973.  
  974. if (User.IsBot)
  975. {
  976. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  977. {
  978. dbClient.SetQuery("UPDATE bots SET x=@x, y=@y, z=@z, name=@name, look=@look, rotation=@rotation WHERE id=@id LIMIT 1;");
  979. dbClient.AddParameter("name", User.BotData.Name);
  980. dbClient.AddParameter("look", User.BotData.Look);
  981. dbClient.AddParameter("rotation", User.BotData.Rot);
  982. dbClient.AddParameter("x", User.X);
  983. dbClient.AddParameter("y", User.Y);
  984. dbClient.AddParameter("z", User.Z);
  985. dbClient.AddParameter("id", User.BotData.BotId);
  986. dbClient.RunQuery();
  987. }
  988. }
  989. }
  990. }
  991.  
  992. public void Dispose()
  993. {
  994. SendMessage(new CloseConnectionComposer());
  995.  
  996. if (!mDisposed)
  997. {
  998. isCrashed = false;
  999. mDisposed = true;
  1000.  
  1001. try
  1002. {
  1003. if (ProcessTask != null && ProcessTask.IsCompleted)
  1004. ProcessTask.Dispose();
  1005. }
  1006. catch { }
  1007.  
  1008. GetRoomItemHandler().SaveFurniture();
  1009.  
  1010. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  1011. {
  1012. dbClient.RunQuery("UPDATE `rooms` SET `users_now` = '0' WHERE `id` = '" + Id + "' LIMIT 1");
  1013. }
  1014.  
  1015. if (this._roomUserManager.PetCount > 0)
  1016. this._roomUserManager.UpdatePets();
  1017.  
  1018. this.SaveAI();
  1019.  
  1020. UsersNow = 0;
  1021. RoomData.UsersNow = 0;
  1022.  
  1023. UsersWithRights.Clear();
  1024. Bans.Clear();
  1025. MutedUsers.Clear();
  1026. Tents.Clear();
  1027.  
  1028. this.TonerData = null;
  1029. this.MoodlightData = null;
  1030.  
  1031. this._filterComponent.Cleanup();
  1032. this._wiredComponent.Cleanup();
  1033.  
  1034. if (this._gameItemHandler != null)
  1035. this._gameItemHandler.Dispose();
  1036.  
  1037. if (this._gameManager != null)
  1038. this._gameManager.Dispose();
  1039.  
  1040. if (this._freeze != null)
  1041. this._freeze.Dispose();
  1042.  
  1043. if (this._banzai != null)
  1044. this._banzai.Dispose();
  1045.  
  1046. if (this._soccer != null)
  1047. this._soccer.Dispose();
  1048.  
  1049. if (this._gamemap != null)
  1050. this._gamemap.Dispose();
  1051.  
  1052. if (this._roomUserManager != null)
  1053. this._roomUserManager.Dispose();
  1054.  
  1055. if (this._roomItemHandling != null)
  1056. this._roomItemHandling.Dispose();
  1057.  
  1058.  
  1059.  
  1060. if (ActiveTrades.Count > 0)
  1061. ActiveTrades.Clear();
  1062. }
  1063. }
  1064. }
  1065. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement