mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 21:01:29 +00:00
[Fix] Fix Instance Creation Race Condition (#4803)
* [Fix] Fix Instance Creation Race Condition * Rejigger * Update database_instances.cpp * Update database_instances.cpp * Update database_instances.cpp * Update database_instances.cpp
This commit is contained in:
parent
444d688ad2
commit
23743a4050
@ -141,6 +141,7 @@ public:
|
|||||||
bool CheckInstanceExpired(uint16 instance_id);
|
bool CheckInstanceExpired(uint16 instance_id);
|
||||||
bool CreateInstance(uint16 instance_id, uint32 zone_id, uint32 version, uint32 duration);
|
bool CreateInstance(uint16 instance_id, uint32 zone_id, uint32 version, uint32 duration);
|
||||||
bool GetUnusedInstanceID(uint16& instance_id);
|
bool GetUnusedInstanceID(uint16& instance_id);
|
||||||
|
bool TryGetUnusedInstanceID(uint16& instance_id);
|
||||||
bool IsGlobalInstance(uint16 instance_id);
|
bool IsGlobalInstance(uint16 instance_id);
|
||||||
bool RemoveClientFromInstance(uint16 instance_id, uint32 char_id);
|
bool RemoveClientFromInstance(uint16 instance_id, uint32 char_id);
|
||||||
bool RemoveClientsFromInstance(uint16 instance_id);
|
bool RemoveClientsFromInstance(uint16 instance_id);
|
||||||
|
|||||||
@ -130,11 +130,32 @@ bool Database::CreateInstance(uint16 instance_id, uint32 zone_id, uint32 version
|
|||||||
e.duration = duration;
|
e.duration = duration;
|
||||||
|
|
||||||
RespawnTimesRepository::ClearInstanceTimers(*this, e.id);
|
RespawnTimesRepository::ClearInstanceTimers(*this, e.id);
|
||||||
|
InstanceListRepository::ReplaceOne(*this, e);
|
||||||
return InstanceListRepository::InsertOne(*this, e).id;
|
return instance_id > 0 && e.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Database::GetUnusedInstanceID(uint16 &instance_id)
|
bool Database::GetUnusedInstanceID(uint16 &instance_id)
|
||||||
|
{
|
||||||
|
// attempt to get an unused instance id
|
||||||
|
for (int a = 0; a < 10; a++) {
|
||||||
|
uint16 attempted_id = 0;
|
||||||
|
if (TryGetUnusedInstanceID(attempted_id)) {
|
||||||
|
auto i = InstanceListRepository::NewEntity();
|
||||||
|
i.id = attempted_id;
|
||||||
|
i.notes = "Prefetching";
|
||||||
|
auto n = InstanceListRepository::InsertOne(*this, i);
|
||||||
|
if (n.id > 0) {
|
||||||
|
instance_id = n.id;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
instance_id = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Database::TryGetUnusedInstanceID(uint16 &instance_id)
|
||||||
{
|
{
|
||||||
uint32 max_reserved_instance_id = RuleI(Instances, ReservedInstances);
|
uint32 max_reserved_instance_id = RuleI(Instances, ReservedInstances);
|
||||||
uint32 max_instance_id = 32000;
|
uint32 max_instance_id = 32000;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user