Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.61 KB | None | 0 0
  1. using Butterfly.Core;
  2. using Butterfly.HabboHotel.ChatMessageStorage;
  3. using Butterfly.HabboHotel.GameClients;
  4. using Butterfly.HabboHotel.Items;
  5. using Butterfly.HabboHotel.Pets;
  6. using Butterfly.HabboHotel.RoomBots;
  7. using Butterfly.HabboHotel.Rooms.Games;
  8. using Butterfly.HabboHotel.Rooms.Wired;
  9. using Butterfly.Communication.Packets.Outgoing;
  10. using Butterfly.Database.Interfaces;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Data;
  14. using System.Linq;
  15. using Butterfly.HabboHotel.Rooms.Janken;
  16. using Butterfly.Communication.Packets.Outgoing.Structure;
  17. using Butterfly.HabboHotel.Rooms.Projectile;
  18. using Butterfly.HabboHotel.Roleplay;
  19. using System.Threading.Tasks;
  20. using System.Timers;
  21. using System.Text;
  22. using Butterfly.Communication.Packets.Outgoing.WebSocket;
  23.  
  24. namespace Butterfly.HabboHotel.Rooms
  25. {
  26. public delegate void RoomEventDelegate(object sender, EventArgs e);
  27. public delegate void RoomUserSaysDelegate(object sender, UserSaysArgs e, ref bool messageHandled);
  28. public delegate void TriggerUserDelegate(RoomUser user, string ActionType);
  29. public delegate void BotCollisionDelegate(RoomUser user, string BotName);
  30.  
  31. public class Room
  32. {
  33. public bool RoomMuted;
  34. public bool isCycling;
  35. public int IsLagging;
  36. public bool mCycleEnded;
  37. public int IdleTime;
  38. public static Timer aTimer;
  39. public bool RpRoom;
  40. public bool Pvp;
  41. public int RpHour;
  42. public int RpMinute;
  43. private int RpIntensity;
  44. public bool RpCycleHourEffect;
  45. public bool RpTimeSpeed;
  46. public static int PlayerZombieCount = 0;
  47. private TeamManager teammanager;
  48. public static int PlayerIsZombieCount = 0;
  49. public List<int> UsersWithRights;
  50. public bool EveryoneGotRights;
  51. private readonly Dictionary<int, double> Bans;
  52. private readonly Dictionary<int, double> Mutes;
  53. public bool HeightMapLoaded;
  54. public DateTime lastTimerReset;
  55. public GameManager game;
  56. private readonly Gamemap gamemap;
  57. private readonly RoomItemHandling roomItemHandling;
  58. private RoomUserManager roomUserManager;
  59. private Soccer soccer;
  60. private BattleBanzai banzai;
  61. private Freeze freeze;
  62. private JankenManager jankan;
  63. private GameItemHandler gameItemHandler;
  64. private WiredHandler wiredHandler;
  65. public MoodlightData MoodlightData;
  66. public List<Trade> ActiveTrades;
  67. public bool mIsIdle;
  68. private readonly ChatMessageManager chatMessageManager;
  69. public RoomData RoomData;
  70. public bool Disposed;
  71. public bool RoomMutePets;
  72. public bool FreezeRoom;
  73. public bool PushPullAllowed;
  74. public bool CloseFullRoom;
  75. public bool OldFoot;
  76. public bool RoomIngameChat;
  77. private ProjectileManager projecctileManager;
  78. private int SaveTimer;
  79.  
  80. public int UserCount
  81. {
  82. get
  83. {
  84. return this.roomUserManager.GetRoomUserCount();
  85. }
  86. }
  87.  
  88. public int Id
  89. {
  90. get
  91. {
  92. return this.RoomData.Id;
  93. }
  94. }
  95.  
  96.  
  97. public event TriggerUserDelegate TriggerUser;
  98. public event RoomUserSaysDelegate OnUserSays;
  99. public event RoomEventDelegate OnUserCmd;
  100. public event RoomEventDelegate OnUserCls;
  101.  
  102. public Room(RoomData Data)
  103. {
  104. RolePlayerManager RPManager = ButterflyEnvironment.GetGame().GetRoleplayManager().GetRolePlay(Data.OwnerId);
  105. if (RPManager != null)
  106. {
  107. this.RpRoom = true;
  108. this.Pvp = true;
  109. this.RpCycleHourEffect = true;
  110. this.RpTimeSpeed = false;
  111. this.RpHour = -1;
  112. }
  113.  
  114. this.SaveTimer = 0;
  115. this.Disposed = false;
  116. this.Bans = new Dictionary<int, double>();
  117. this.Mutes = new Dictionary<int, double>();
  118. this.ActiveTrades = new List<Trade>();
  119. this.mCycleEnded = false;
  120. this.HeightMapLoaded = false;
  121. this.RoomData = Data;
  122. this.EveryoneGotRights = Data.AllowRightsOverride;
  123. this.IdleTime = 0;
  124. this.RoomMuted = false;
  125. this.PushPullAllowed = true;
  126. this.RoomIngameChat = false;
  127. this.gamemap = new Gamemap(this);
  128. this.roomItemHandling = new RoomItemHandling(this);
  129. this.roomUserManager = new RoomUserManager(this);
  130. this.wiredHandler = new WiredHandler(this);
  131. this.projecctileManager = new ProjectileManager(this);
  132. this.chatMessageManager = new ChatMessageManager();
  133. this.chatMessageManager.LoadRoomChatlogs(this.Id);
  134. this.LoadRights();
  135. this.GetRoomItemHandler().LoadFurniture();
  136. if (this.RoomData.OwnerName == "HabboGame")
  137. this.GetRoomItemHandler().LoadFurniture(5400713);
  138.  
  139. this.GetGameMap().GenerateMaps();
  140. this.LoadBots();
  141. this.InitPets();
  142. this.lastTimerReset = DateTime.Now;
  143. }
  144.  
  145. public Gamemap GetGameMap()
  146. {
  147. return this.gamemap;
  148. }
  149.  
  150. public RoomItemHandling GetRoomItemHandler()
  151. {
  152. return this.roomItemHandling;
  153. }
  154.  
  155. public RoomUserManager GetRoomUserManager()
  156. {
  157. return this.roomUserManager;
  158. }
  159.  
  160. public Soccer GetSoccer()
  161. {
  162. if (this.soccer == null)
  163. this.soccer = new Soccer(this);
  164. return this.soccer;
  165. }
  166.  
  167. public TeamManager GetTeamManager()
  168. {
  169. if (this.teammanager == null)
  170. this.teammanager = new TeamManager();
  171. return this.teammanager;
  172. }
  173.  
  174. public BattleBanzai GetBanzai()
  175. {
  176. if (this.banzai == null)
  177. this.banzai = new BattleBanzai(this);
  178. return this.banzai;
  179. }
  180.  
  181. public Freeze GetFreeze()
  182. {
  183. if (this.freeze == null)
  184. this.freeze = new Freeze(this);
  185. return this.freeze;
  186. }
  187.  
  188. public JankenManager GetJanken()
  189. {
  190. if (this.jankan == null)
  191. this.jankan = new JankenManager(this);
  192. return this.jankan;
  193. }
  194.  
  195. public GameManager GetGameManager()
  196. {
  197. if (this.game == null)
  198. this.game = new GameManager(this);
  199. return this.game;
  200. }
  201.  
  202. public GameItemHandler GetGameItemHandler()
  203. {
  204. if (this.gameItemHandler == null)
  205. this.gameItemHandler = new GameItemHandler(this);
  206. return this.gameItemHandler;
  207. }
  208.  
  209. public WiredHandler GetWiredHandler()
  210. {
  211. if (this.wiredHandler == null)
  212. this.wiredHandler = new WiredHandler(this);
  213. return this.wiredHandler;
  214. }
  215.  
  216. public ProjectileManager GetProjectileManager()
  217. {
  218. if (this.projecctileManager == null)
  219. this.projecctileManager = new ProjectileManager(this);
  220. return this.projecctileManager;
  221. }
  222.  
  223. public bool GotSoccer()
  224. {
  225. return this.soccer != null;
  226. }
  227.  
  228. public bool GotBanzai()
  229. {
  230. return this.banzai != null;
  231. }
  232.  
  233. public bool GotFreeze()
  234. {
  235. return this.freeze != null;
  236. }
  237.  
  238. public bool GotJanken()
  239. {
  240. return this.jankan != null;
  241. }
  242.  
  243. public bool GotWired()
  244. {
  245. return this.wiredHandler != null;
  246. }
  247.  
  248. public ChatMessageManager GetChatMessageManager()
  249. {
  250. return this.chatMessageManager;
  251. }
  252.  
  253. public bool AllowsShous(RoomUser user, string message)
  254. {
  255. bool messageHandled = false;
  256. if (this.OnUserSays != null)
  257. this.OnUserSays(null, new UserSaysArgs(user, message), ref messageHandled);
  258.  
  259. return messageHandled;
  260. }
  261.  
  262. public void CollisionUser(RoomUser User)
  263. {
  264. if (this.OnUserCls == null)
  265. return;
  266.  
  267. int Lenght = 1;
  268. int GoalX = User.X;
  269. int GoalY = User.Y;
  270.  
  271. switch (User.RotBody)
  272. {
  273. case 0:
  274. GoalX = User.X;
  275. GoalY = User.Y - Lenght;
  276. break;
  277. case 1:
  278. GoalX = User.X + Lenght;
  279. GoalY = User.Y - Lenght;
  280. break;
  281. case 2:
  282. GoalX = User.X + Lenght;
  283. GoalY = User.Y;
  284. break;
  285. case 3:
  286. GoalX = User.X + Lenght;
  287. GoalY = User.Y + Lenght;
  288. break;
  289. case 4:
  290. GoalX = User.X;
  291. GoalY = User.Y + Lenght;
  292. break;
  293. case 5:
  294. GoalX = User.X - Lenght;
  295. GoalY = User.Y + Lenght;
  296. break;
  297. case 6:
  298. GoalX = User.X - Lenght;
  299. GoalY = User.Y;
  300. break;
  301. case 7:
  302. GoalX = User.X - Lenght;
  303. GoalY = User.Y - Lenght;
  304. break;
  305. }
  306.  
  307. RoomUser UserGoal = this.GetRoomUserManager().GetUserForSquare(GoalX, GoalY);
  308. if (UserGoal == null)
  309. return;
  310.  
  311. if (UserGoal.team == User.team && User.team != Team.none)
  312. return;
  313.  
  314. this.OnUserCls(UserGoal, null);
  315. }
  316.  
  317. public void UserCmd(RoomUser roomUser)
  318. {
  319. if (this.OnUserCmd != null)
  320. this.OnUserCmd(roomUser, null);
  321. }
  322.  
  323. public void ClearTags()
  324. {
  325. this.RoomData.Tags.Clear();
  326. }
  327.  
  328. public void AddTagRange(List<string> tags)
  329. {
  330. this.RoomData.Tags.AddRange(tags);
  331. }
  332.  
  333. private void LoadBots()
  334. {
  335. DataTable table;
  336. using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
  337. {
  338. queryreactor.SetQuery("SELECT * FROM bots WHERE room_id = " + this.Id);
  339. table = queryreactor.GetTable();
  340. if (table == null)
  341. return;
  342. foreach (DataRow Row in table.Rows)
  343. {
  344. RoomBot roomBot = new RoomBot(Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["user_id"]), Convert.ToInt32(Row["room_id"]), (this.RpRoom) ? AIType.RolePlayBot : AIType.Generic, (string)Row["walk_enabled"] == "1", (string)Row["name"], (string)Row["motto"], (string)Row["gender"], (string)Row["look"], (int)Row["x"], (int)Row["y"], (int)Row["z"], (int)Row["rotation"], (string)Row["chat_enabled"] == "1", (string)Row["chat_text"], (int)Row["chat_seconds"], (string)Row["is_dancing"] == "1", (int)Row["enable"], (int)Row["handitem"], Convert.ToInt32((string)Row["status"]));
  345. RoomUser roomUser = this.GetRoomUserManager().DeployBot(roomBot, (Pet)null);
  346. if (roomBot.IsDancing)
  347. roomUser.DanceId = 3;
  348. }
  349. }
  350. }
  351.  
  352. public void InitPets()
  353. {
  354. using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
  355. {
  356. queryreactor.SetQuery("SELECT id, user_id, room_id, name, type, race, color, expirience, energy, nutrition, respect, createstamp, x, y, z, have_saddle, hairdye, pethair, anyone_ride FROM user_pets WHERE room_id = " + this.Id);
  357. DataTable table = queryreactor.GetTable();
  358. if (table == null)
  359. return;
  360. foreach (DataRow Row in table.Rows)
  361. {
  362. Pet PetData = new Pet(Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["user_id"]), Convert.ToInt32(Row["room_id"]), (string)Row["name"], Convert.ToInt32(Row["type"]), (string)Row["race"], (string)Row["color"], (int)Row["expirience"], (int)Row["energy"], (int)Row["nutrition"], (int)Row["respect"], (double)Row["createstamp"], (int)Row["x"], (int)Row["y"], (double)Row["z"], (int)Row["have_saddle"], (int)Row["hairdye"], (int)Row["pethair"], (string)(Row["anyone_ride"]) == "1");
  363. List<string> list = new List<string>();
  364. this.roomUserManager.DeployBot(new RoomBot(PetData.PetId, PetData.OwnerId, this.Id, AIType.Pet, true, PetData.Name, "", "", PetData.Look, PetData.X, PetData.Y, PetData.Z, 0, false, "", 0, false, 0, 0, 0), PetData);
  365. }
  366. }
  367. }
  368.  
  369. public void onRoomKick()
  370. {
  371. List<RoomUser> list = new List<RoomUser>();
  372. foreach (RoomUser roomUser in this.roomUserManager.GetUserList().ToList())
  373. {
  374. if (!roomUser.IsBot && !roomUser.GetClient().GetHabbo().HasFuse("fuse_no_kick"))
  375. {
  376. this.GetRoomUserManager().RemoveUserFromRoom(roomUser.GetClient(), true, true);
  377. }
  378. }
  379. }
  380.  
  381. public void OnUserSay(RoomUser User, string Message, bool Shout)
  382. {
  383. foreach (RoomUser roomUser in this.roomUserManager.GetPets().ToList())
  384. {
  385. if (Shout)
  386. roomUser.BotAI.OnUserShout(User, Message);
  387. else
  388. roomUser.BotAI.OnUserSay(User, Message);
  389. }
  390. }
  391.  
  392. public void LoadRights()
  393. {
  394. this.UsersWithRights = new List<int>();
  395. DataTable dataTable = new DataTable();
  396. using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
  397. {
  398. queryreactor.SetQuery("SELECT room_rights.user_id FROM room_rights WHERE room_id = " + this.RoomData.Id);
  399. dataTable = queryreactor.GetTable();
  400. }
  401. if (dataTable == null)
  402. return;
  403. foreach (DataRow dataRow in dataTable.Rows)
  404. this.UsersWithRights.Add(Convert.ToInt32(dataRow["user_id"]));
  405. }
  406.  
  407. public int GetRightsLevel(GameClient Session)
  408. {
  409. if (Session == null || Session.GetHabbo() == null)
  410. return 0;
  411. if (Session.GetHabbo().Username == this.RoomData.OwnerName || Session.GetHabbo().HasFuse("fuse_any_room_controller"))
  412. return 4;
  413. if (Session.GetHabbo().HasFuse("fuse_any_room_rights"))
  414. return 3;
  415. if (this.UsersWithRights.Contains(Session.GetHabbo().Id))
  416. return 1;
  417. if (this.EveryoneGotRights)
  418. return 1;
  419.  
  420. return 0;
  421. }
  422.  
  423. public bool CheckRights(GameClient Session, bool RequireOwnership = false)
  424. {
  425. if (Session == null || Session.GetHabbo() == null)
  426. return false;
  427. if (Session.GetHabbo().Username == this.RoomData.OwnerName || Session.GetHabbo().HasFuse("fuse_any_room_controller"))
  428. return true;
  429. if (!RequireOwnership)
  430. {
  431. if (Session.GetHabbo().HasFuse("fuse_any_room_rights") || this.UsersWithRights.Contains(Session.GetHabbo().Id))
  432. return true;
  433. if (this.EveryoneGotRights)
  434. return true;
  435.  
  436. if (this.RoomData.Group == null)
  437. return false;
  438.  
  439. if (this.RoomData.Group.IsAdmin(Session.GetHabbo().Id))
  440. return true;
  441.  
  442. if (this.RoomData.Group.AdminOnlyDeco == 0)
  443. {
  444. if (this.RoomData.Group.IsMember(Session.GetHabbo().Id))
  445. return true;
  446. }
  447. }
  448. return false;
  449. }
  450.  
  451. public void SendObjects(GameClient Session)
  452. {
  453. Room Room = this;
  454.  
  455. Session.SendPacket(Room.GetGameMap().Model.SerializeRelativeHeightmap());
  456. Session.SendPacket(Room.GetGameMap().Model.GetHeightmap());
  457.  
  458. foreach (RoomUser RoomUser in roomUserManager.GetUserList().ToList())
  459. {
  460. if (RoomUser == null)
  461. continue;
  462.  
  463. if (RoomUser.IsSpectator)
  464. continue;
  465.  
  466. if (!RoomUser.IsBot && RoomUser.GetClient() == null)
  467. continue;
  468.  
  469. if (!RoomUser.IsBot && RoomUser.GetClient().GetHabbo() == null)
  470. continue;
  471.  
  472. Session.SendPacket(new UsersComposer(RoomUser));
  473.  
  474. if (RoomUser.IsDancing)
  475. Session.SendPacket(new DanceComposer(RoomUser, RoomUser.DanceId));
  476.  
  477. if (RoomUser.IsAsleep)
  478. Session.SendPacket(new SleepComposer(RoomUser, true));
  479.  
  480. if (RoomUser.CarryItemID > 0 && RoomUser.CarryTimer > 0)
  481. Session.SendPacket(new CarryObjectComposer(RoomUser.VirtualId, RoomUser.CarryItemID));
  482.  
  483. if (RoomUser.CurrentEffect > 0)
  484. Session.SendPacket(new AvatarEffectComposer(RoomUser.VirtualId, RoomUser.CurrentEffect));
  485. }
  486.  
  487. Session.SendPacket(new UserUpdateComposer(roomUserManager.GetUserList().ToList()));
  488. Session.SendPacket(new ObjectsComposer(Room.GetRoomItemHandler().GetFloor.ToArray(), this));
  489. Session.SendPacket(new ObjectsComposer(Room.GetRoomItemHandler().GetTempItems.ToArray(), this));
  490. Session.SendPacket(new ItemsComposer(Room.GetRoomItemHandler().GetWall.ToArray(), this));
  491. }
  492. public static void SetTimer()
  493. {
  494. // Create a timer with a two second interval.
  495. aTimer = new Timer(120000);
  496. // Hook up the Elapsed event for the timer.
  497. aTimer.Elapsed += OnTimedEvent;
  498. aTimer.AutoReset = false;
  499. aTimer.Enabled = true;
  500. }
  501. private static void OnTimedEvent(Object source, ElapsedEventArgs e)
  502. {
  503. aTimer.Stop();
  504. aTimer.Dispose();
  505. ButterflyEnvironment.ZombieInfectionMode = false;
  506. StringBuilder content = new StringBuilder();
  507. Room Room = ButterflyEnvironment.GetGame().GetRoomManager().GetRoom(ButterflyEnvironment.ZombieRoomID);
  508. if (!(PlayerZombieCount == 0))
  509. {
  510. content.Append("Voici la liste des survivants !\n\n");
  511. foreach (RoomUser RoomUser in Room.GetRoomUserManager().GetRoomUsers())
  512. {
  513. if (RoomUser == null || RoomUser.GetClient() == null)
  514. continue;
  515.  
  516. if (!(RoomUser.GetClient().GetHabbo().IsZombie == true))
  517. content.Append("- " + RoomUser.GetClient().GetHabbo().Username);
  518. }
  519. ServerPacket Message = new ServerPacket(ServerPacketHeader.BroadcastMessageAlertMessageComposer);
  520. Message.WriteString(content.ToString());
  521. Room.SendPacket(Message);
  522. }
  523. else
  524. Room.SendPacket(RoomNotificationComposer.SendBubble("zombie", "Les zombies ont gagnés !", ""));
  525. foreach (GameClient Client in ButterflyEnvironment.GetGame().GetClientManager()._clients.Values)
  526. {
  527. if (Client == null || Client.GetHabbo() == null)
  528. continue;
  529.  
  530. Client.GetHabbo().IsZombie = false;
  531. Client.GetHabbo().IsZombieKing = false;
  532. Client.GetHabbo().IsPlayerOfZombie = false;
  533. }
  534. PlayerZombieCount = 0;
  535. PlayerIsZombieCount = 0;
  536. ButterflyEnvironment.ZombieRoomID = 0;
  537. }
  538.  
  539. internal void ZombieTicker()
  540. {
  541. int maxCount = PlayerIsZombieCount + PlayerZombieCount;
  542. if (maxCount == PlayerIsZombieCount || PlayerIsZombieCount == 0)
  543. {
  544. aTimer.Stop();
  545. aTimer.Dispose();
  546. ButterflyEnvironment.ZombieInfectionMode = false;
  547. StringBuilder content = new StringBuilder();
  548. Room Room = ButterflyEnvironment.GetGame().GetRoomManager().GetRoom(ButterflyEnvironment.ZombieRoomID);
  549. if (!(PlayerZombieCount == 0))
  550. {
  551. content.Append("Voici la liste des survivants !\n\n");
  552. foreach (RoomUser RoomUser in Room.GetRoomUserManager().GetRoomUsers())
  553. {
  554. if (RoomUser == null || RoomUser.GetClient() == null)
  555. continue;
  556.  
  557. if (!(RoomUser.GetClient().GetHabbo().IsZombie == true))
  558. content.Append("- " + RoomUser.GetClient().GetHabbo().Username);
  559. }
  560. ServerPacket Message = new ServerPacket(ServerPacketHeader.BroadcastMessageAlertMessageComposer);
  561. Message.WriteString(content.ToString());
  562. Room.SendPacket(Message);
  563. }
  564. else
  565. Room.SendPacket(RoomNotificationComposer.SendBubble("zombie", "Les zombies ont gagnés !", ""));
  566. foreach (GameClient Client in ButterflyEnvironment.GetGame().GetClientManager()._clients.Values)
  567. {
  568. if (Client == null || Client.GetHabbo() == null)
  569. continue;
  570.  
  571. Client.GetHabbo().IsZombie = false;
  572. Client.GetHabbo().IsZombieKing = false;
  573. Client.GetHabbo().IsPlayerOfZombie = false;
  574. }
  575. PlayerZombieCount = 0;
  576. PlayerIsZombieCount = 0;
  577. ButterflyEnvironment.ZombieRoomID = 0;
  578. }
  579. }
  580.  
  581. public void ProcessRoom(object pCallback)
  582. {
  583. try
  584. {
  585. this.isCycling = true;
  586. if (this.Disposed)
  587. return;
  588.  
  589. try
  590. {
  591. int idleCount = 0;
  592.  
  593. if (ButterflyEnvironment.ZombieInfectionMode && Id == ButterflyEnvironment.ZombieRoomID)
  594. {
  595. Task ZombieTask = new Task(ZombieTicker);
  596. ZombieTask.Start();
  597. Console.WriteLine("Task On, room id = " + ButterflyEnvironment.ZombieRoomID);
  598. }
  599.  
  600. this.GetRoomUserManager().OnCycle(ref idleCount);
  601.  
  602. this.GetRoomItemHandler().OnCycle();
  603.  
  604. this.RpCycleHour();
  605.  
  606. this.GetProjectileManager().OnCycle();
  607.  
  608. if (idleCount > 0)
  609. this.IdleTime++;
  610. else
  611. this.IdleTime = 0;
  612.  
  613. if (!this.mCycleEnded)
  614. {
  615. if (this.IdleTime >= 60)
  616. {
  617. ButterflyEnvironment.GetGame().GetRoomManager().UnloadRoom(this);
  618. this.mIsIdle = false;
  619. return;
  620. }
  621. else
  622. {
  623. this.GetRoomUserManager().SerializeStatusUpdates();
  624. }
  625. }
  626.  
  627. if (this.GetGameItemHandler() != null)
  628. this.GetGameItemHandler().OnCycle();
  629.  
  630. if (this.GetWiredHandler() != null)
  631. this.GetWiredHandler().OnCycle();
  632.  
  633. if (this.GotJanken())
  634. this.GetJanken().OnCycle();
  635.  
  636. if (this.SaveTimer < ((5 * 60) * 2))
  637. this.SaveTimer++;
  638. else
  639. {
  640. this.SaveTimer = 0;
  641. using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
  642. {
  643. this.GetRoomItemHandler().SaveFurniture(queryreactor);
  644. }
  645. }
  646. }
  647. catch (Exception ex)
  648. {
  649. this.OnRoomCrash(ex);
  650. }
  651. }
  652. catch (Exception ex)
  653. {
  654. isCycling = false;
  655. Logging.LogCriticalException("Sub crash in room cycle: " + (ex).ToString());
  656. }
  657. finally
  658. {
  659. isCycling = false;
  660. }
  661. }
  662.  
  663. private void RpCycleHour()
  664. {
  665. if (!this.RpRoom)
  666. return;
  667.  
  668. DateTime Now = DateTime.Now;
  669.  
  670. int RpHourNow = (int)Math.Floor((double)(((Now.Minute * 60) + Now.Second) / 150)); //150sec = 2m30s = 1heure dans le rp
  671.  
  672. int RpMinuteNow = (int)Math.Floor((((Now.Minute * 60) + Now.Second) - (RpHourNow * 150)) / 2.5);
  673.  
  674. if (RpHourNow >= 16)
  675. RpHourNow = (RpHourNow + 8) - 24;
  676. else
  677. RpHourNow = RpHourNow + 8;
  678.  
  679. if (this.RpTimeSpeed)
  680. RpHourNow = (int)Math.Floor((double)(Now.Second / 2.5));
  681.  
  682. if (this.RpMinute != RpMinuteNow)
  683. this.RpMinute = RpMinuteNow;
  684.  
  685. if (this.RpHour == RpHourNow)
  686. return;
  687.  
  688. this.RpHour = RpHourNow;
  689.  
  690. if (!this.RpCycleHourEffect)
  691. return;
  692.  
  693. int Intensity = 255;
  694.  
  695. if (RpHour >= 8 && RpHour < 20) //Journée
  696. {
  697. Intensity = 255;
  698. }
  699. else if (RpHour >= 20 && RpHour < 21) //Crépuscule
  700. {
  701. Intensity = 200;
  702. }
  703. else if (RpHour >= 21 && RpHour < 22) //Crépuscule
  704. {
  705. Intensity = 150;
  706. }
  707. else if (RpHour >= 22 && RpHour < 23) //Crépuscule
  708. {
  709. Intensity = 100;
  710. }
  711. else if (RpHour >= 23 && RpHour < 24) //Crépuscule
  712. {
  713. Intensity = 75;
  714. }
  715. else if (RpHour >= 0 && RpHour < 4) //Nuit
  716. {
  717. Intensity = 50;
  718. }
  719. else if (RpHour >= 4 && RpHour < 5) //Aube
  720. {
  721. Intensity = 75;
  722. }
  723. else if (RpHour >= 5 && RpHour < 6) //Aube
  724. {
  725. Intensity = 100;
  726. }
  727. else if (RpHour >= 6 && RpHour < 7) //Aube
  728. {
  729. Intensity = 150;
  730. }
  731. else if (RpHour >= 7 && RpHour < 8) //Aube
  732. {
  733. Intensity = 200;
  734. }
  735.  
  736. if (this.RpIntensity == Intensity)
  737. return;
  738.  
  739. this.RpIntensity = Intensity;
  740.  
  741. this.UpdateRpMoodLight();
  742. this.UpdateRpToner();
  743. this.UpdateRpBlock();
  744. }
  745.  
  746. private void UpdateRpBlock()
  747. {
  748. List<Item> roomItems = this.GetRoomItemHandler().GetFloor.Where(i => i.GetBaseItem().Id == 99138022).ToList();
  749. if (roomItems == null)
  750. return;
  751.  
  752. int UseNum = 0;
  753. if (this.RpIntensity == 50)
  754. UseNum = 0;
  755. else if (this.RpIntensity == 75)
  756. UseNum = 1;
  757. else if (this.RpIntensity == 100)
  758. UseNum = 2;
  759. else if (this.RpIntensity == 150)
  760. UseNum = 3;
  761. else if (this.RpIntensity == 200)
  762. UseNum = 4;
  763. else if (this.RpIntensity == 255)
  764. UseNum = 5;
  765.  
  766. foreach (Item RoomItem in roomItems)
  767. {
  768. RoomItem.ExtraData = UseNum.ToString();
  769. RoomItem.UpdateState();
  770. }
  771. }
  772.  
  773. private void UpdateRpMoodLight()
  774. {
  775. if (this.MoodlightData == null)
  776. return;
  777.  
  778. Item roomItem = this.GetRoomItemHandler().GetItem(this.MoodlightData.ItemId);
  779. if (roomItem == null || roomItem.GetBaseItem().InteractionType != InteractionType.MOODLIGHT)
  780. return;
  781.  
  782. this.MoodlightData.Enabled = true;
  783. this.MoodlightData.CurrentPreset = 1;
  784. this.MoodlightData.UpdatePreset(1, "#000000", this.RpIntensity, false);
  785. roomItem.ExtraData = this.MoodlightData.GenerateExtraData();
  786. roomItem.UpdateState();
  787. }
  788.  
  789. private void UpdateRpToner()
  790. {
  791. Item roomItem = Enumerable.FirstOrDefault<Item>((IEnumerable<Item>)this.GetRoomItemHandler().GetFloor.Where(i => i.GetBaseItem().InteractionType == InteractionType.TONER));
  792. if (roomItem == null)
  793. return;
  794.  
  795. int Teinte = 135;
  796. int Saturation = 180;
  797. int Luminosite = (int)Math.Floor((double)this.RpIntensity / 2);
  798. roomItem.ExtraData = "on," + Teinte + "," + Saturation + "," + Luminosite;
  799. roomItem.UpdateState(true, true);
  800. }
  801.  
  802. public void OnRoomCrash(Exception e)
  803. {
  804. Logging.LogThreadException((e).ToString(), "Room cycle task for room " + this.Id);
  805. //ButterflyEnvironment.GetGame().GetRoomManager().UnloadRoom(this);
  806. }
  807.  
  808. public void SendPacketOnChat(IServerPacket Message, RoomUser ThisUser = null, bool UserMutedOnly = false, bool UserNotIngameOnly = false)
  809. {
  810. try
  811. {
  812. if (Message == null)
  813. return;
  814.  
  815. if (this == null || this.roomUserManager == null)
  816. return;
  817.  
  818. List<RoomUser> Users = this.roomUserManager.GetUserList().ToList();
  819. if (Users == null)
  820. return;
  821.  
  822. foreach (RoomUser User in Users)
  823. {
  824. if (User == null || User.IsBot)
  825. continue;
  826.  
  827. if (User.GetClient() == null || User.GetClient().GetConnection() == null || User.GetClient().GetHabbo() == null)
  828. continue;
  829.  
  830. if (UserMutedOnly && ThisUser != null && User.GetClient().GetHabbo().MutedUsers.Contains(ThisUser.UserId))
  831. continue;
  832.  
  833. if (ThisUser != null && ThisUser.GetClient() != null && ThisUser.GetClient().GetHabbo() != null && ThisUser.GetClient().GetHabbo().IgnoreAll && ThisUser != User)
  834. continue;
  835.  
  836. if (!UserMutedOnly && ThisUser == User)
  837. continue;
  838.  
  839. if (this.RoomIngameChat && (UserNotIngameOnly && User.team != Team.none))
  840. continue;
  841.  
  842. if (this.RoomData.ChatMaxDistance > 0 && (Math.Abs(ThisUser.X - User.X) > this.RoomData.ChatMaxDistance || Math.Abs(ThisUser.Y - User.Y) > this.RoomData.ChatMaxDistance))
  843. continue;
  844.  
  845. User.GetClient().SendPacket(Message);
  846. }
  847. }
  848. catch (Exception ex)
  849. {
  850. Logging.HandleException(ex, "Room.SendMessage (" + this.Id + ")");
  851. }
  852. }
  853.  
  854. public void SendPacketWeb(IServerPacket Message)
  855. {
  856. try
  857. {
  858. if (Message == null)
  859. return;
  860.  
  861. if (this == null || this.roomUserManager == null)
  862. return;
  863.  
  864. List<RoomUser> Users = this.roomUserManager.GetUserList().ToList();
  865. if (Users == null)
  866. return;
  867.  
  868. foreach (RoomUser User in Users)
  869. {
  870. if (User == null || User.IsBot)
  871. continue;
  872.  
  873. if (User.GetClient() == null || User.GetClient().GetConnection() == null)
  874. continue;
  875.  
  876. User.GetClient().GetHabbo().SendWebPacket(Message);
  877. }
  878. }
  879. catch (Exception ex)
  880. {
  881. Logging.HandleException(ex, "Room.SendMessageWeb (" + this.Id + ")");
  882. }
  883. }
  884. public void SendPacket(IServerPacket Message, bool UsersWithRightsOnly = false)
  885. {
  886. try
  887. {
  888. if (Message == null)
  889. return;
  890.  
  891. if (this == null || this.roomUserManager == null)
  892. return;
  893.  
  894. List<RoomUser> Users = this.roomUserManager.GetUserList().ToList();
  895. if (Users == null)
  896. return;
  897.  
  898. foreach (RoomUser User in Users)
  899. {
  900. if (User == null || User.IsBot)
  901. continue;
  902.  
  903. if (User.GetClient() == null || User.GetClient().GetConnection() == null)
  904. continue;
  905.  
  906. if (UsersWithRightsOnly && !this.CheckRights(User.GetClient()))
  907. continue;
  908.  
  909. User.GetClient().SendPacket(Message);
  910. }
  911. }
  912. catch (Exception ex)
  913. {
  914. Logging.HandleException(ex, "Room.SendMessage (" + this.Id + ")");
  915. }
  916. }
  917.  
  918. public void SendMessage(List<ServerPacket> Messages)
  919. {
  920. if (Messages.Count == 0)
  921. return;
  922.  
  923. try
  924. {
  925. byte[] TotalBytes = new byte[0];
  926. int Current = 0;
  927.  
  928. foreach (ServerPacket Packet in Messages.ToList())
  929. {
  930. byte[] ToAdd = Packet.GetBytes();
  931. int NewLen = TotalBytes.Length + ToAdd.Length;
  932.  
  933. Array.Resize(ref TotalBytes, NewLen);
  934.  
  935. for (int i = 0; i < ToAdd.Length; i++)
  936. {
  937. TotalBytes[Current] = ToAdd[i];
  938. Current++;
  939. }
  940. }
  941.  
  942. this.BroadcastPacket(TotalBytes);
  943. }
  944. catch (Exception e)
  945. {
  946. Logging.HandleException(e, "Room.SendMessage List<ServerPacket>");
  947. }
  948. }
  949.  
  950. public void BroadcastPacket(byte[] Packet)
  951. {
  952. foreach (RoomUser User in this.roomUserManager.GetUserList().ToList())
  953. {
  954. if (User == null || User.IsBot)
  955. continue;
  956.  
  957. if (User.GetClient() == null || User.GetClient().GetConnection() == null)
  958. continue;
  959.  
  960. User.GetClient().GetConnection().SendData(Packet);
  961. }
  962. }
  963.  
  964. public void Destroy()
  965. {
  966. this.SendPacket(new CloseConnectionComposer());
  967. this.Dispose();
  968. }
  969.  
  970. private void Dispose()
  971. {
  972. if (this.Disposed)
  973. return;
  974. this.Disposed = true;
  975. this.mCycleEnded = true;
  976.  
  977. using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
  978. {
  979. this.GetRoomItemHandler().SaveFurniture(queryreactor);
  980. }
  981. this.RoomData.Tags.Clear();
  982.  
  983. this.UsersWithRights.Clear();
  984. this.Bans.Clear();
  985. foreach (Item roomItem in this.GetRoomItemHandler().GetWallAndFloor)
  986. roomItem.Destroy();
  987.  
  988. this.GetRoomItemHandler().Destroy();
  989.  
  990. this.ActiveTrades.Clear();
  991.  
  992. this.GetRoomUserManager().UpdateUserCount(0);
  993. this.GetRoomUserManager().Destroy();
  994.  
  995. this.gamemap.Destroy();
  996. }
  997.  
  998. public Dictionary<int, double> getBans()
  999. {
  1000. return this.Bans;
  1001. }
  1002.  
  1003. public bool UserIsBanned(int pId)
  1004. {
  1005. return this.Bans.ContainsKey(pId);
  1006. }
  1007.  
  1008. public void RemoveBan(int pId)
  1009. {
  1010. this.Bans.Remove(pId);
  1011. }
  1012.  
  1013. public void AddBan(int pId, int Time)
  1014. {
  1015. if (this.Bans.ContainsKey(pId))
  1016. return;
  1017. this.Bans.Add(pId, (double)(ButterflyEnvironment.GetUnixTimestamp() + Time));
  1018. }
  1019.  
  1020. public bool HasBanExpired(int pId)
  1021. {
  1022. return !this.UserIsBanned(pId) || this.Bans[pId] - (double)ButterflyEnvironment.GetUnixTimestamp() <= 0.0;
  1023. }
  1024.  
  1025. public Dictionary<int, double> getMute()
  1026. {
  1027. return this.Mutes;
  1028. }
  1029.  
  1030. public bool UserIsMuted(int pId)
  1031. {
  1032. return this.Mutes.ContainsKey(pId);
  1033. }
  1034.  
  1035. public void RemoveMute(int pId)
  1036. {
  1037. this.Mutes.Remove(pId);
  1038. }
  1039.  
  1040. public void AddMute(int pId, int Time)
  1041. {
  1042. if (this.Mutes.ContainsKey(pId))
  1043. return;
  1044. this.Mutes.Add(pId, (double)(ButterflyEnvironment.GetUnixTimestamp() + Time));
  1045. }
  1046.  
  1047. public bool HasMuteExpired(int pId)
  1048. {
  1049. return !this.UserIsMuted(pId) || this.Mutes[pId] - (double)ButterflyEnvironment.GetUnixTimestamp() <= 0.0;
  1050. }
  1051.  
  1052. public bool HasActiveTrade(RoomUser User)
  1053. {
  1054. if (User.IsBot)
  1055. return false;
  1056. else
  1057. return this.HasActiveTrade(User.GetClient().GetHabbo().Id);
  1058. }
  1059.  
  1060. public bool HasActiveTrade(int UserId)
  1061. {
  1062. foreach (Trade trade in this.ActiveTrades)
  1063. {
  1064. if (trade.ContainsUser(UserId))
  1065. return true;
  1066. }
  1067. return false;
  1068. }
  1069.  
  1070. public Trade GetUserTrade(int UserId)
  1071. {
  1072. foreach (Trade trade in this.ActiveTrades)
  1073. {
  1074. if (trade.ContainsUser(UserId))
  1075. return trade;
  1076. }
  1077. return (Trade)null;
  1078. }
  1079.  
  1080. public void TryStartTrade(RoomUser UserOne, RoomUser UserTwo)
  1081. {
  1082. if (UserOne == null || UserTwo == null)
  1083. return;
  1084. if ((UserOne.IsBot || UserTwo.IsBot) || (UserOne.IsTrading || UserTwo.IsTrading || (this.HasActiveTrade(UserOne) || this.HasActiveTrade(UserTwo))))
  1085. return;
  1086.  
  1087. this.ActiveTrades.Add(new Trade(UserOne.GetClient().GetHabbo().Id, UserTwo.GetClient().GetHabbo().Id, this.Id));
  1088. }
  1089.  
  1090. public void TryStopTrade(int UserId)
  1091. {
  1092. Trade userTrade = this.GetUserTrade(UserId);
  1093. if (userTrade == null)
  1094. return;
  1095. userTrade.CloseTrade(UserId);
  1096. this.ActiveTrades.Remove(userTrade);
  1097. }
  1098.  
  1099. public void SetMaxUsers(int MaxUsers)
  1100. {
  1101. this.RoomData.UsersMax = MaxUsers;
  1102. using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
  1103. queryreactor.RunQuery(string.Concat(new object[4]
  1104. {
  1105. "UPDATE rooms SET users_max = ",
  1106. MaxUsers,
  1107. " WHERE id = ",
  1108. this.Id
  1109. }));
  1110. }
  1111.  
  1112. public static short CheckParse(char input)
  1113. {
  1114. switch (input)
  1115. {
  1116. case 'y':
  1117. case 'x':
  1118. case 'z':
  1119. case '0':
  1120. return 0;
  1121. case '1':
  1122. return 1;
  1123. case '2':
  1124. return 2;
  1125. case '3':
  1126. return 3;
  1127. case '4':
  1128. return 4;
  1129. case '5':
  1130. return 5;
  1131. case '6':
  1132. return 6;
  1133. case '7':
  1134. return 7;
  1135. case '8':
  1136. return 8;
  1137. case '9':
  1138. return 9;
  1139. case 'a':
  1140. return 10;
  1141. case 'b':
  1142. return 11;
  1143. case 'c':
  1144. return 12;
  1145. case 'd':
  1146. return 13;
  1147. case 'e':
  1148. return 14;
  1149. case 'f':
  1150. return 15;
  1151. case 'g':
  1152. return 16;
  1153. case 'h':
  1154. return 17;
  1155. case 'i':
  1156. return 18;
  1157. case 'j':
  1158. return 19;
  1159. case 'k':
  1160. return 20;
  1161. case 'l':
  1162. return 21;
  1163. case 'm':
  1164. return 22;
  1165. case 'n':
  1166. return 23;
  1167. case 'o':
  1168. return 24;
  1169. case 'p':
  1170. return 25;
  1171. case 'q':
  1172. return 26;
  1173. case 'r':
  1174. return 27;
  1175. case 's':
  1176. return 28;
  1177. case 't':
  1178. return 29;
  1179. case 'u':
  1180. return 30;
  1181. case 'v':
  1182. return 31;
  1183. case 'w':
  1184. return 32;
  1185. default:
  1186. return 99;
  1187. }
  1188. }
  1189. }
  1190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement