Skip to content

Commit e468f5f

Browse files
committed
add new facture gw
1 parent fe91281 commit e468f5f

11 files changed

+525
-12
lines changed

Core/LowPriorityWorker.cs

+27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Akiled.Database.Interfaces;
2+
using AkiledEmulator.HabboHotel.Hotel.Giveaway;
23
using System;
34
using System.Diagnostics;
45

@@ -28,6 +29,32 @@ public static void Init()
2829
private static Stopwatch lowPriorityProcessWatch;
2930
public static void Process()
3031
{
32+
if (lowPriorityProcessWatch.ElapsedMilliseconds >= 60000 && isExecuted)
33+
{
34+
try
35+
{
36+
if (GiveAwayConfigs.enabled)
37+
{
38+
if (GiveAwayConfigs.timestamp < AkiledEnvironment.GetUnixTimestamp())
39+
{
40+
try
41+
{
42+
GiveAwayConfigs.Stop();
43+
44+
}
45+
catch (Exception ex)
46+
{
47+
Logging.LogException(ex.ToString());
48+
}
49+
}
50+
}
51+
}
52+
catch
53+
{
54+
55+
}
56+
}
57+
3158
if (lowPriorityProcessWatch.ElapsedMilliseconds >= 60000 || !isExecuted)
3259
{
3360
isExecuted = true;

HabboHotel/Game.cs

+10-5
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
using Akiled.HabboHotel.Support;
2424
using Akiled.HabboHotel.Users.Messenger;
2525
using Akiled.HabboHotel.WebClients;
26+
using AkiledEmulator.HabboHotel.Hotel.Giveaway;
2627
using System;
2728
using System.Diagnostics;
2829
using System.Threading;
30+
using static Akiled.HabboHotel.Rooms.Chat.Commands.Cmd.UserInfo;
2931

3032
namespace Akiled.HabboHotel
3133
{
@@ -55,6 +57,8 @@ public class Game
5557
private readonly CacheManager _cacheManager;
5658
private readonly CrackableManager _crackableManager;
5759
private readonly CraftingManager _craftingManager;
60+
private readonly GiveAwayBlocksManager _giveAwayBlocksM;
61+
5862
private Thread gameLoop; //Task
5963
public static bool gameLoopEnabled = true;
6064
public bool gameLoopActive;
@@ -115,6 +119,7 @@ public Game()
115119
this._craftingManager.Init();
116120
this._notiftopManager = new NotificationTopManager();
117121
this._notiftopManager.Init();
122+
118123
using (IQueryAdapter dbClient = AkiledEnvironment.GetDatabaseManager().GetQueryReactor())
119124
{
120125
StaffChat.Initialize(dbClient);
@@ -125,6 +130,8 @@ public Game()
125130
LowPriorityWorker.Init();
126131

127132
this.moduleWatch = new Stopwatch();
133+
134+
this._giveAwayBlocksM = new GiveAwayBlocksManager();
128135
}
129136

130137
#region Return values
@@ -225,6 +232,8 @@ public QuestManager GetQuestManager()
225232

226233
public HotelViewManager GetHotelView() => this._hotelViewManager;
227234

235+
public GiveAwayBlocksManager GetGiveAwayBlocks() => _giveAwayBlocksM;
236+
228237
#endregion
229238

230239
public void StartGameLoop()
@@ -264,12 +273,8 @@ private void MainGameLoop()
264273
if (gameLoopEnabled)
265274
{
266275
moduleWatch.Restart();
267-
268-
269276
LowPriorityWorker.Process();
270-
271-
272-
277+
273278
if (moduleWatch.ElapsedMilliseconds > 500)
274279
Console.WriteLine("High latency in LowPriorityWorker.Process ({0} ms)", moduleWatch.ElapsedMilliseconds);
275280
moduleWatch.Restart();

HabboHotel/GameClients/GameClientManager.cs

+19
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,25 @@ public Task BanUserAsync(GameClient Client, string Moderator, double LengthSecon
492492

493493
public void SendSuperNotif(string Title, string Notice, string Picture, string Link, string LinkTitle, bool Broadcast, bool Event) => this.SendMessage(new RoomNotificationComposer(Title, Notice, Picture, LinkTitle, Link));
494494

495+
public void SendWhisper(string Message, int Colour = 0)
496+
{
497+
try
498+
{
499+
foreach (GameClient Client in this._clients.Values.ToList())
500+
{
501+
RoomUser User = Client.GetHabbo().CurrentRoom.GetRoomUserManager().GetRoomUserByHabbo(Client.GetHabbo().Username);
502+
if (User == null || User.IsBot || User.IsPet)
503+
continue;
504+
505+
SendMessage(new WhisperMessageComposer(User.VirtualId, Message, 0, Colour == 0 ? User.LastBubble : Colour));
506+
}
507+
}
508+
catch (Exception e)
509+
{
510+
Logging.HandleException(e, "GameClientManager.SendWhisper");
511+
}
512+
}
513+
495514
private void GiveDiamonds()
496515
{
497516
if (diamondsQueuee.Count > 0)
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Akiled;
2+
using Akiled.Database.Interfaces;
3+
4+
namespace AkiledEmulator.HabboHotel.Hotel.Extras
5+
{
6+
public class RewardsOffline
7+
{
8+
public static void Rewards(int userId, int credits, int duckets, int diamonds, string badge, int item)
9+
{
10+
if (userId <= 0)
11+
return;
12+
13+
using (IQueryAdapter dbClient = AkiledEnvironment.GetDatabaseManager().GetQueryReactor())
14+
{
15+
dbClient.RunQuery("UPDATE `users` SET `credits`=credits + " + credits + ", `activity_points`=activity_points + " + duckets + ", `vip_points`=vip_points + " + diamonds + " WHERE `id`=" + userId + " LIMIT 1");
16+
17+
if (!string.IsNullOrEmpty(badge))
18+
dbClient.RunQuery("INSERT INTO `user_badges` (user_id, badge_id, badge_slot) VALUES (" + userId + ", '" + badge + "', 0)");
19+
if (item > 0)
20+
dbClient.RunQuery("INSERT INTO `items` (user_id, room_id, base_item) VALUES (" + userId + ", 0, " + item + ")");
21+
}
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using Akiled;
2+
using Akiled.Database.Interfaces;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Data;
6+
7+
namespace AkiledEmulator.HabboHotel.Hotel.Giveaway
8+
{
9+
public class GiveAwayBlocksManager
10+
{
11+
private Dictionary<int, GiveAwayBlocks> giveAwayBlock;
12+
13+
public GiveAwayBlocksManager()
14+
{
15+
giveAwayBlock = new Dictionary<int, GiveAwayBlocks>();
16+
Init(AkiledEnvironment.GetDatabaseManager().GetQueryReactor());
17+
}
18+
19+
public void Init(IQueryAdapter dbClient)
20+
{
21+
if (giveAwayBlock.Count > 0)
22+
giveAwayBlock.Clear();
23+
24+
dbClient.SetQuery("SELECT user_id, added FROM give_away_blocks");
25+
DataTable dataTable = dbClient.GetTable();
26+
27+
if (dataTable != null)
28+
foreach (DataRow row in dataTable.Rows)
29+
giveAwayBlock.Add(Convert.ToInt32(row["user_id"]), new GiveAwayBlocks(Convert.ToInt32(row["user_id"]), Convert.ToDouble(row["added"])));
30+
}
31+
32+
public void InsertBlock(int userId)
33+
{
34+
if (!giveAwayBlock.ContainsKey(userId))
35+
{
36+
double time = AkiledEnvironment.GetUnixTimestamp() + (GiveAwayConfigs.durationOfBlock * 60);
37+
using (IQueryAdapter dbClient = AkiledEnvironment.GetDatabaseManager().GetQueryReactor())
38+
dbClient.RunQuery("INSERT INTO give_away_blocks (user_id,added) VALUES (" + userId + ", " + time + ")");
39+
40+
giveAwayBlock.Add(userId, new GiveAwayBlocks(userId, time));
41+
}
42+
}
43+
44+
private void RemoveBlock(int userId)
45+
{
46+
if (giveAwayBlock.ContainsKey(userId))
47+
{
48+
using (IQueryAdapter dbClient = AkiledEnvironment.GetDatabaseManager().GetQueryReactor())
49+
dbClient.RunQuery("DELETE FROM give_away_blocks WHERE user_id = " + userId);
50+
51+
giveAwayBlock.Remove(userId);
52+
}
53+
}
54+
55+
public bool CheckTimeExpire(int userId, GiveAwayBlocks giveAwayBlocks)
56+
{
57+
if (giveAwayBlocks.timestamp > AkiledEnvironment.GetUnixTimestamp())
58+
return true;
59+
60+
RemoveBlock(userId);
61+
return false;
62+
}
63+
64+
public bool TryGet(int userId, out GiveAwayBlocks giveAwayBlocks)
65+
{
66+
if (giveAwayBlock.TryGetValue(userId, out giveAwayBlocks))
67+
return true;
68+
return false;
69+
}
70+
}
71+
72+
public class GiveAwayBlocks
73+
{
74+
public int userId { get; set; }
75+
public double timestamp { get; set; }
76+
77+
public GiveAwayBlocks(int userId, double added)
78+
{
79+
this.userId = userId;
80+
this.timestamp = added;
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)