mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 16:51:29 +00:00
[Zones] Convert Get/Set of Zone Timezone to Repositories (#3946)
* [Zones] Convert Get/Set of Zone Timezone to Repositories - Convert `GetZoneTimezone()` and `SetZoneTimeZone()` to repositories. * Update time_zone.cpp
This commit is contained in:
parent
73a099c5ea
commit
d41bd8f963
@ -44,7 +44,20 @@ public:
|
||||
*/
|
||||
|
||||
// Custom extended repository methods here
|
||||
static bool SetTimeZone(Database& db, uint32 zone_id, uint32 instance_version, uint32 timezone)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE `{}` SET `timezone` = {} WHERE `zoneidnumber` = {} AND `version` = {}",
|
||||
TableName(),
|
||||
timezone,
|
||||
zone_id,
|
||||
instance_version
|
||||
)
|
||||
);
|
||||
|
||||
return results.Success();
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EQEMU_ZONE_REPOSITORY_H
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
void SetTimeZone(Client *c, const Seperator *sep)
|
||||
{
|
||||
const auto arguments = sep->argnum;
|
||||
if (arguments < 2 || sep->IsNumber(2)) {
|
||||
if (arguments < 2 || !sep->IsNumber(2)) {
|
||||
c->Message(Chat::White, "Usage: #set time_zone [Hour] [Minute]");
|
||||
c->Message(
|
||||
Chat::White,
|
||||
@ -15,12 +15,13 @@ void SetTimeZone(Client *c, const Seperator *sep)
|
||||
return;
|
||||
}
|
||||
|
||||
uint8 minutes = 0;
|
||||
uint8 hours = Strings::ToUnsignedInt(sep->arg[2]);
|
||||
|
||||
if (hours > 24) {
|
||||
hours = 24;
|
||||
}
|
||||
EQ::Clamp(hours, static_cast<uint8>(0), static_cast<uint8>(24));
|
||||
|
||||
uint8 minutes = sep->IsNumber(3) ? Strings::ToUnsignedInt(sep->arg[3]) : 0;
|
||||
|
||||
EQ::Clamp(minutes, static_cast<uint8>(0), static_cast<uint8>(59));
|
||||
|
||||
uint8 real_hours = (
|
||||
(hours - 1) > 0 ?
|
||||
@ -28,14 +29,6 @@ void SetTimeZone(Client *c, const Seperator *sep)
|
||||
0
|
||||
);
|
||||
|
||||
if (sep->IsNumber(3)) {
|
||||
minutes = Strings::ToUnsignedInt(sep->arg[3]);
|
||||
|
||||
if (minutes > 59) {
|
||||
minutes = 59;
|
||||
}
|
||||
}
|
||||
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
@ -46,7 +39,7 @@ void SetTimeZone(Client *c, const Seperator *sep)
|
||||
|
||||
const int new_timezone = ((hours * 60) + minutes);
|
||||
zone->zone_time.setEQTimeZone(new_timezone);
|
||||
content_db.SetZoneTZ(zone->GetZoneID(), zone->GetInstanceVersion(), new_timezone);
|
||||
content_db.SetZoneTimezone(zone->GetZoneID(), zone->GetInstanceVersion(), new_timezone);
|
||||
|
||||
auto outapp = new EQApplicationPacket(OP_TimeOfDay, sizeof(TimeOfDay_Struct));
|
||||
|
||||
|
||||
@ -1217,7 +1217,7 @@ bool Zone::Init(bool is_static) {
|
||||
Expedition::CacheAllFromDatabase();
|
||||
|
||||
LogInfo("Loading timezone data");
|
||||
zone_time.setEQTimeZone(content_db.GetZoneTZ(zoneid, GetInstanceVersion()));
|
||||
zone_time.setEQTimeZone(content_db.GetZoneTimezone(zoneid, GetInstanceVersion()));
|
||||
|
||||
LogInfo("Zone booted successfully zone_id [{}] time_offset [{}]", zoneid, zone_time.getEQTimeZone());
|
||||
|
||||
|
||||
@ -49,6 +49,7 @@
|
||||
#include "../common/repositories/character_data_repository.h"
|
||||
#include "../common/repositories/character_corpses_repository.h"
|
||||
#include "../common/repositories/character_corpse_items_repository.h"
|
||||
#include "../common/repositories/zone_repository.h"
|
||||
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
@ -2574,35 +2575,27 @@ void ZoneDatabase::DeleteMerchantTemp(uint32 npc_id, uint32 slot_id, uint32 zone
|
||||
);
|
||||
}
|
||||
|
||||
//New functions for timezone
|
||||
uint32 ZoneDatabase::GetZoneTZ(uint32 zoneid, uint32 version) {
|
||||
uint32 ZoneDatabase::GetZoneTimezone(uint32 zone_id, uint32 instance_version)
|
||||
{
|
||||
const auto& l = ZoneRepository::GetWhere(
|
||||
*this,
|
||||
fmt::format(
|
||||
"`zoneidnumber` = {} AND (`version` = {} OR `version` = 0) ORDER BY `version` DESC",
|
||||
zone_id,
|
||||
instance_version
|
||||
)
|
||||
);
|
||||
|
||||
std::string query = StringFormat("SELECT timezone FROM zone WHERE zoneidnumber = %i "
|
||||
"AND (version = %i OR version = 0) ORDER BY version DESC",
|
||||
zoneid, version);
|
||||
auto results = QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return 0;
|
||||
}
|
||||
if (l.empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (results.RowCount() == 0)
|
||||
return 0;
|
||||
|
||||
auto& row = results.begin();
|
||||
return Strings::ToInt(row[0]);
|
||||
return l[0].id ? l[0].timezone : 0;
|
||||
}
|
||||
|
||||
bool ZoneDatabase::SetZoneTZ(uint32 zoneid, uint32 version, uint32 tz) {
|
||||
|
||||
std::string query = StringFormat("UPDATE zone SET timezone = %i "
|
||||
"WHERE zoneidnumber = %i AND version = %i",
|
||||
tz, zoneid, version);
|
||||
auto results = QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return results.RowsAffected() == 1;
|
||||
bool ZoneDatabase::SetZoneTimezone(uint32 zone_id, uint32 instance_version, uint32 timezone)
|
||||
{
|
||||
return ZoneRepository::SetTimeZone(*this, zone_id, instance_version, timezone);
|
||||
}
|
||||
|
||||
void ZoneDatabase::RefreshGroupFromDB(Client *client){
|
||||
|
||||
@ -627,8 +627,8 @@ public:
|
||||
bool SetTrapData(Trap* trap, bool repopnow = false);
|
||||
|
||||
/* Time */
|
||||
uint32 GetZoneTZ(uint32 zoneid, uint32 version);
|
||||
bool SetZoneTZ(uint32 zoneid, uint32 version, uint32 tz);
|
||||
uint32 GetZoneTimezone(uint32 zoneid, uint32 version);
|
||||
bool SetZoneTimezone(uint32 zoneid, uint32 version, uint32 tz);
|
||||
|
||||
/* Group */
|
||||
void RefreshGroupFromDB(Client *c);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user