-
Notifications
You must be signed in to change notification settings - Fork 438
/
Copy pathinstance_list_repository.h
48 lines (40 loc) · 1.08 KB
/
instance_list_repository.h
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
#ifndef EQEMU_INSTANCE_LIST_REPOSITORY_H
#define EQEMU_INSTANCE_LIST_REPOSITORY_H
#include "../database.h"
#include "../strings.h"
#include "base/base_instance_list_repository.h"
class InstanceListRepository: public BaseInstanceListRepository {
public:
static int UpdateDuration(Database& db, uint16 instance_id, uint32_t new_duration)
{
auto results = db.QueryDatabase(
fmt::format(
"UPDATE `{}` SET `duration` = {}, `expire_at` = (`duration` + `start_time`) WHERE `{}` = {}",
TableName(),
new_duration,
PrimaryKey(),
instance_id
)
);
return results.Success() ? results.RowsAffected() : 0;
}
static uint32 GetRemainingTimeByInstanceID(Database& db, uint16 instance_id)
{
auto results = db.QueryDatabase(
fmt::format(
SQL(
SELECT (`expire_at` - UNIX_TIMESTAMP()) AS `remaining` FROM `{}`
WHERE `id` = {}
),
TableName(),
instance_id
)
);
if (!results.Success() || !results.RowCount()) {
return 0;
}
auto row = results.begin();
return Strings::ToUnsignedInt(row[0]);
}
};
#endif //EQEMU_INSTANCE_LIST_REPOSITORY_H