mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-14 15:41:30 +00:00
Cleaned up GetUnusedInstanceID logic and renamed instance_lockout* tables to instance_list*
This commit is contained in:
parent
e5fd0f5d75
commit
9d938cdd58
@ -1,5 +1,10 @@
|
||||
EQEMu Changelog (Started on Sept 24, 2003 15:50)
|
||||
-------------------------------------------------------
|
||||
== 02/13/2014 ==
|
||||
Sorvani: Renamed the instance_lockout and instance_lockout_player tables to instance_list and instance_list_player. Cleaned up the Database::GetUnusedInstanceID logic.
|
||||
|
||||
Required SQL: utils/sql/git/2014_02_13_Rename_instance_lockout_tables.sql
|
||||
|
||||
== 02/10/2014 ==
|
||||
demonstar55 (Secrets): Re-wrote the entity list to be a std::map. This should be used for direct entityID lookups and is noticably faster performance-wise. Also should result in less nil pointers potentially.
|
||||
Secrets: Fixed a crash issue that could occur on #repop related to quest timers.
|
||||
|
||||
@ -668,7 +668,7 @@ bool Database::DeleteCharacter(char *name)
|
||||
#if DEBUG >= 5
|
||||
printf(" instances");
|
||||
#endif
|
||||
RunQuery(query, MakeAnyLenString(&query, "DELETE FROM instance_lockout_player WHERE charid='%d'", charid), errbuf, nullptr, &affected_rows);
|
||||
RunQuery(query, MakeAnyLenString(&query, "DELETE FROM instance_list_player WHERE charid='%d'", charid), errbuf, nullptr, &affected_rows);
|
||||
if(query)
|
||||
{
|
||||
safe_delete_array(query);
|
||||
@ -2278,7 +2278,7 @@ bool Database::VerifyZoneInstance(uint32 zone_id, uint16 instance_id)
|
||||
char *query = 0;
|
||||
MYSQL_RES *result;
|
||||
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT id FROM instance_lockout where id=%u AND zone=%u",
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT id FROM instance_list where id=%u AND zone=%u",
|
||||
instance_id, zone_id), errbuf, &result))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
@ -2308,7 +2308,7 @@ bool Database::CharacterInInstanceGroup(uint16 instance_id, uint32 char_id)
|
||||
MYSQL_RES *result;
|
||||
bool lockout_instance_player = false;
|
||||
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT charid FROM instance_lockout_player where id=%u AND charid=%u",
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT charid FROM instance_list_player where id=%u AND charid=%u",
|
||||
instance_id, char_id), errbuf, &result))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
@ -2330,10 +2330,10 @@ void Database::DeleteInstance(uint16 instance_id)
|
||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
||||
char *query = 0;
|
||||
|
||||
RunQuery(query, MakeAnyLenString(&query, "DELETE FROM instance_lockout WHERE id=%u", instance_id), errbuf);
|
||||
RunQuery(query, MakeAnyLenString(&query, "DELETE FROM instance_list WHERE id=%u", instance_id), errbuf);
|
||||
safe_delete_array(query);
|
||||
|
||||
RunQuery(query, MakeAnyLenString(&query, "DELETE FROM instance_lockout_player WHERE id=%u", instance_id), errbuf);
|
||||
RunQuery(query, MakeAnyLenString(&query, "DELETE FROM instance_list_player WHERE id=%u", instance_id), errbuf);
|
||||
safe_delete_array(query);
|
||||
|
||||
RunQuery(query, MakeAnyLenString(&query, "DELETE FROM respawn_times WHERE instance_id=%u", instance_id), errbuf);
|
||||
@ -2354,7 +2354,7 @@ bool Database::CheckInstanceExpired(uint16 instance_id)
|
||||
int32 start_time = 0;
|
||||
int32 duration = 0;
|
||||
uint32 never_expires = 0;
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT start_time, duration, never_expires FROM instance_lockout WHERE id=%u",
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT start_time, duration, never_expires FROM instance_list WHERE id=%u",
|
||||
instance_id), errbuf, &result))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
@ -2400,7 +2400,7 @@ uint32 Database::ZoneIDFromInstanceID(uint16 instance_id)
|
||||
MYSQL_ROW row;
|
||||
uint32 ret;
|
||||
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT zone FROM instance_lockout where id=%u", instance_id),
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT zone FROM instance_list where id=%u", instance_id),
|
||||
errbuf, &result))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
@ -2433,7 +2433,7 @@ uint32 Database::VersionFromInstanceID(uint16 instance_id)
|
||||
MYSQL_ROW row;
|
||||
uint32 ret;
|
||||
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT version FROM instance_lockout where id=%u", instance_id),
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT version FROM instance_list where id=%u", instance_id),
|
||||
errbuf, &result))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
@ -2468,7 +2468,7 @@ uint32 Database::GetTimeRemainingInstance(uint16 instance_id, bool &is_perma)
|
||||
uint32 duration = 0;
|
||||
uint32 never_expires = 0;
|
||||
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT start_time, duration, never_expires FROM instance_lockout WHERE id=%u",
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT start_time, duration, never_expires FROM instance_list WHERE id=%u",
|
||||
instance_id), errbuf, &result))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
@ -2516,68 +2516,29 @@ bool Database::GetUnusedInstanceID(uint16 &instance_id)
|
||||
MYSQL_RES *result;
|
||||
MYSQL_ROW row;
|
||||
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT COUNT(*) FROM instance_lockout"), errbuf, &result))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
if (mysql_num_rows(result) != 0)
|
||||
{
|
||||
row = mysql_fetch_row(result);
|
||||
int count = atoi(row[0]);
|
||||
if(count == 0)
|
||||
{
|
||||
mysql_free_result(result);
|
||||
instance_id = RuleI(Zone, ReservedInstances) + 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mysql_free_result(result);
|
||||
}
|
||||
mysql_free_result(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
safe_delete_array(query);
|
||||
instance_id = 0;
|
||||
return false;
|
||||
}
|
||||
uint32 count = RuleI(Zone, ReservedInstances) + 1;
|
||||
uint32 max = 65535;
|
||||
|
||||
int32 count = RuleI(Zone, ReservedInstances) + 1;
|
||||
int32 max = 65535;
|
||||
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT id FROM instance_lockout where id >= %i ORDER BY id", count), errbuf, &result))
|
||||
{
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT id FROM instance_list where id >= %i ORDER BY id", count), errbuf, &result)) {
|
||||
safe_delete_array(query);
|
||||
if (mysql_num_rows(result) != 0)
|
||||
{
|
||||
while((row = mysql_fetch_row(result)))
|
||||
{
|
||||
if(count < atoi(row[0]))
|
||||
{
|
||||
if (mysql_num_rows(result) != 0) {
|
||||
while((row = mysql_fetch_row(result))) {
|
||||
if(count < atoi(row[0])) {
|
||||
instance_id = count;
|
||||
mysql_free_result(result);
|
||||
return true;
|
||||
}
|
||||
else if(count > max)
|
||||
{
|
||||
} else if(count > max) {
|
||||
instance_id = 0;
|
||||
mysql_free_result(result);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mysql_free_result(result);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
safe_delete_array(query);
|
||||
}
|
||||
instance_id = count;
|
||||
@ -2590,7 +2551,7 @@ bool Database::CreateInstance(uint16 instance_id, uint32 zone_id, uint32 version
|
||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
||||
char *query = 0;
|
||||
|
||||
if(RunQuery(query, MakeAnyLenString(&query, "INSERT INTO instance_lockout (id, zone, version, start_time, duration)"
|
||||
if(RunQuery(query, MakeAnyLenString(&query, "INSERT INTO instance_list (id, zone, version, start_time, duration)"
|
||||
" values(%lu, %lu, %lu, UNIX_TIMESTAMP(), %lu)", (unsigned long)instance_id, (unsigned long)zone_id, (unsigned long)version, (unsigned long)duration), errbuf))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
@ -2611,7 +2572,7 @@ void Database::PurgeExpiredInstances()
|
||||
MYSQL_ROW row;
|
||||
|
||||
uint16 id = 0;
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT id FROM instance_lockout where "
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT id FROM instance_list where "
|
||||
"(start_time+duration) <= UNIX_TIMESTAMP() and never_expires = 0"), errbuf, &result))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
@ -2638,7 +2599,7 @@ bool Database::AddClientToInstance(uint16 instance_id, uint32 char_id)
|
||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
||||
char *query = 0;
|
||||
|
||||
if(RunQuery(query, MakeAnyLenString(&query, "INSERT INTO instance_lockout_player(id, charid) "
|
||||
if(RunQuery(query, MakeAnyLenString(&query, "INSERT INTO instance_list_player(id, charid) "
|
||||
"values(%lu, %lu)", (unsigned long)instance_id, (unsigned long)char_id), errbuf))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
@ -2656,7 +2617,7 @@ bool Database::RemoveClientFromInstance(uint16 instance_id, uint32 char_id)
|
||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
||||
char *query = 0;
|
||||
|
||||
if(RunQuery(query, MakeAnyLenString(&query, "DELETE FROM instance_lockout_player WHERE id=%lu AND charid=%lu",
|
||||
if(RunQuery(query, MakeAnyLenString(&query, "DELETE FROM instance_list_player WHERE id=%lu AND charid=%lu",
|
||||
(unsigned long)instance_id, (unsigned long)char_id), errbuf))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
@ -2674,7 +2635,7 @@ bool Database::RemoveClientsFromInstance(uint16 instance_id)
|
||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
||||
char *query = 0;
|
||||
|
||||
if(RunQuery(query, MakeAnyLenString(&query, "DELETE FROM instance_lockout_player WHERE id=%lu",
|
||||
if(RunQuery(query, MakeAnyLenString(&query, "DELETE FROM instance_list_player WHERE id=%lu",
|
||||
(unsigned long)instance_id), errbuf))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
@ -2693,7 +2654,7 @@ bool Database::CheckInstanceExists(uint16 instance_id)
|
||||
char *query = 0;
|
||||
MYSQL_RES *result;
|
||||
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT * FROM instance_lockout where id=%u", instance_id),
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT * FROM instance_list where id=%u", instance_id),
|
||||
errbuf, &result))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
@ -2738,7 +2699,7 @@ uint16 Database::GetInstanceVersion(uint16 instance_id)
|
||||
MYSQL_ROW row;
|
||||
uint32 ret;
|
||||
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT version FROM instance_lockout where id=%u", instance_id),
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT version FROM instance_list where id=%u", instance_id),
|
||||
errbuf, &result))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
@ -2771,9 +2732,9 @@ uint16 Database::GetInstanceID(const char* zone, uint32 charid, int16 version)
|
||||
MYSQL_ROW row;
|
||||
uint16 ret;
|
||||
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT instance_lockout.id FROM instance_lockout, instance_lockout_player "
|
||||
"WHERE instance_lockout.zone=%u AND instance_lockout.version=%u AND instance_lockout.id=instance_lockout_player.id AND "
|
||||
"instance_lockout_player.charid=%u LIMIT 1;", GetZoneID(zone), version, charid, charid), errbuf, &result))
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT instance_list.id FROM instance_list, instance_list_player "
|
||||
"WHERE instance_list.zone=%u AND instance_list.version=%u AND instance_list.id=instance_list_player.id AND "
|
||||
"instance_list_player.charid=%u LIMIT 1;", GetZoneID(zone), version, charid, charid), errbuf, &result))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
if (mysql_num_rows(result) != 0)
|
||||
@ -2808,9 +2769,9 @@ uint16 Database::GetInstanceID(uint32 zone, uint32 charid, int16 version)
|
||||
MYSQL_ROW row;
|
||||
uint16 ret;
|
||||
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT instance_lockout.id FROM instance_lockout, instance_lockout_player "
|
||||
"WHERE instance_lockout.zone=%u AND instance_lockout.version=%u AND instance_lockout.id=instance_lockout_player.id AND "
|
||||
"instance_lockout_player.charid=%u LIMIT 1;", zone, version, charid), errbuf, &result))
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT instance_list.id FROM instance_list, instance_list_player "
|
||||
"WHERE instance_list.zone=%u AND instance_list.version=%u AND instance_list.id=instance_list_player.id AND "
|
||||
"instance_list_player.charid=%u LIMIT 1;", zone, version, charid), errbuf, &result))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
if (mysql_num_rows(result) != 0)
|
||||
@ -2840,7 +2801,7 @@ void Database::GetCharactersInInstance(uint16 instance_id, std::list<uint32> &ch
|
||||
MYSQL_RES *result;
|
||||
MYSQL_ROW row;
|
||||
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT charid FROM instance_lockout_player WHERE id=%u", instance_id), errbuf, &result)) {
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT charid FROM instance_list_player WHERE id=%u", instance_id), errbuf, &result)) {
|
||||
safe_delete_array(query);
|
||||
while ((row = mysql_fetch_row(result)))
|
||||
{
|
||||
@ -2950,7 +2911,7 @@ void Database::SetInstanceDuration(uint16 instance_id, uint32 new_duration)
|
||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
||||
char *query = 0;
|
||||
|
||||
if(RunQuery(query, MakeAnyLenString(&query, "UPDATE `instance_lockout` SET start_time=UNIX_TIMESTAMP(), "
|
||||
if(RunQuery(query, MakeAnyLenString(&query, "UPDATE `instance_list` SET start_time=UNIX_TIMESTAMP(), "
|
||||
"duration=%u WHERE id=%u", new_duration, instance_id), errbuf))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
@ -2970,7 +2931,7 @@ bool Database::GlobalInstance(uint16 instance_id)
|
||||
MYSQL_ROW row;
|
||||
bool ret;
|
||||
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT is_global from instance_lockout where id=%u LIMIT 1", instance_id), errbuf, &result))
|
||||
if (RunQuery(query, MakeAnyLenString(&query, "SELECT is_global from instance_list where id=%u LIMIT 1", instance_id), errbuf, &result))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
row = mysql_fetch_row(result);
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
-- rename the instance_lockout tables to instance_list. They have nothing to do with lockouts.
|
||||
ALTER TABLE `peq`.`instance_lockout` RENAME TO `peq`.`instance_list` ;
|
||||
ALTER TABLE `peq`.`instance_lockout_player` RENAME TO `peq`.`instance_list_player` ;
|
||||
@ -2484,9 +2484,9 @@ void ZoneDatabase::ListAllInstances(Client* c, uint32 charid)
|
||||
MYSQL_ROW row;
|
||||
|
||||
|
||||
if (RunQuery(query,MakeAnyLenString(&query, "SELECT instance_lockout.id, zone, version FROM instance_lockout JOIN"
|
||||
" instance_lockout_player ON instance_lockout.id = instance_lockout_player.id"
|
||||
" WHERE instance_lockout_player.charid=%lu", (unsigned long)charid),errbuf,&result))
|
||||
if (RunQuery(query,MakeAnyLenString(&query, "SELECT instance_list.id, zone, version FROM instance_list JOIN"
|
||||
" instance_list_player ON instance_list.id = instance_list_player.id"
|
||||
" WHERE instance_list_player.charid=%lu", (unsigned long)charid),errbuf,&result))
|
||||
{
|
||||
safe_delete_array(query);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user