-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathTimerCheckerDemo.cpp
More file actions
59 lines (48 loc) · 1.68 KB
/
Copy pathTimerCheckerDemo.cpp
File metadata and controls
59 lines (48 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// This block belongs at the start of the script with the rest
// FROM HERE //
Struct VIPTimerElements
{
uint64 test_time;
};
uint64 VIPTest_Cooldown = 30; // seconds // make this just a local variable for the function or make it a global variable that can be called from any script.
// TO HERE //
// This block belongs inside a PlayerScript OnLogin function
// FROM HERE //
QueryResult timer_result = LoginDatabase.PQuery("SELECT `KickCooldown` FROM `auth`.`account_access` where `id`=%u;", account_id);
if (timer_result)
{
Field* field = timer_result->Fetch();
uint32 test_time = field[0].GetUInt64(); // Value in the DB (Currently what they have)
VIPTimerElements& timers_data = VipTimers[account_id];
// Save the DB values to the MyData object
timers_data.test_time = test_time;
}
// To HERE //
// A stand alone function to cutdown on lines dont need the same code over n over for timers. just make 1 and key it :)
bool CheckTimer(uint8 timer_id, ChatHandler* handler)
{
uint32 account_id = handler->GetSession()->GetAccountId();
uint64 current_test_time = sWorld->GetGameTime(); // seconds
if (timer_id == 1)
{
if ((current_test_time < (VipTimers[account_id].test_time + VIPTest_Cooldown)))
{
// This result means he has a cooldown so return false
return false;
}
else
{
// This result means no cooldown left so return true
LoginDatabase.PExecute("UPDATE `account_access` SET `KickCooldown` = '%d' WHERE `id` = '%d';", VipTimers[account_id].test_time, account_id);
return true;
}
}
}
// using the standalone checker inside a command block
static bool HandleVIPTestCommand(ChatHandler* handler, const char* args)
{
if (CheckTimer(1, handler))
{
// do stuff
}
}