Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster server variable handling #4567

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/zones/Mhaura/Zone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ zoneObject.onGameHour = function(zone)
GetNPCByID(ID.npc.LAUGHING_BISON):setAnimationSub(0)
end

SetServerVariable('Mhaura_Deastination', math.random(1, 100))
SetServerVariable('Mhaura_Destination', math.random(1, 100))
end

zoneObject.onInitialize = function(zone)
Expand Down Expand Up @@ -83,7 +83,7 @@ zoneObject.onEventFinish = function(player, csid, option, npc)
local DepartureTime = VanadielHour()

if DepartureTime % 8 == 0 then
if GetServerVariable('Mhaura_Deastination') > 89 then
if GetServerVariable('Mhaura_Destination') > 89 then
player:setPos(0, 0, 0, 0, xi.zone.SHIP_BOUND_FOR_SELBINA_PIRATES)
else
player:setPos(0, 0, 0, 0, xi.zone.SHIP_BOUND_FOR_SELBINA)
Expand Down
4 changes: 2 additions & 2 deletions scripts/zones/Selbina/Zone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ zoneObject.onInitialize = function(zone)
end

zoneObject.onGameHour = function(zone)
SetServerVariable('Selbina_Deastination', math.random(1, 100))
SetServerVariable('Selbina_Destination', math.random(1, 100))
end

zoneObject.onZoneIn = function(player, prevZone)
Expand Down Expand Up @@ -55,7 +55,7 @@ end

zoneObject.onEventFinish = function(player, csid, option, npc)
if csid == 200 then
if GetServerVariable('Selbina_Deastination') > 89 then
if GetServerVariable('Selbina_Destination') > 89 then
player:setPos(0, 0, 0, 0, xi.zone.SHIP_BOUND_FOR_MHAURA_PIRATES)
else
player:setPos(0, 0, 0, 0, xi.zone.SHIP_BOUND_FOR_MHAURA)
Expand Down
32 changes: 28 additions & 4 deletions src/map/utils/serverutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,22 @@ namespace serverutils
}
else
{
// TODO: Re-enable async
// async_work::doQuery("INSERT INTO server_variables VALUES ('%s', %i) ON DUPLICATE KEY UPDATE value = %i;", varName, value, value);
sql->Query("INSERT INTO server_variables VALUES ('%s', %i, %d) ON DUPLICATE KEY UPDATE value = %i, expiry = %d;", name, value, varTimestamp, value, varTimestamp);
if (sql->Query("SELECT value FROM server_variables WHERE name = '%s' LIMIT 1;", name) != SQL_ERROR)
{
// We're immediately clobbering previous query. It's ok we're done with it.
if (sql->NumRows() > 0)
{
// TODO: Re-enable async
// async_work::doQuery("UPDATE server_variables SET `value` = %i, `expiry` = %i, WHERE name = '%s' LIMIT 1;", value, varTimestamp, name);
sql->Query("UPDATE server_variables SET `value` = %i, `expiry` = %i WHERE name = '%s' LIMIT 1;", value, varTimestamp, name);
}
else
{
// TODO: Re-enable async
// async_work::doQuery("INSERT INTO server_variables VALUES ('%s', %i, %i);", name, value, varTimestamp);
sql->Query("INSERT INTO server_variables VALUES ('%s', %i, %i);", name, value, varTimestamp);
}
}
}
}

Expand All @@ -139,7 +152,18 @@ namespace serverutils
}
else
{
sql->Query("INSERT INTO server_variables VALUES ('%s', %i, %d) ON DUPLICATE KEY UPDATE value = %i, expiry = %d;", name, value, expiry, value, expiry);
if (sql->Query("SELECT value FROM server_variables WHERE name = '%s' LIMIT 1;", name) != SQL_ERROR)
{
// We're immediately clobbering previous query. It's ok we're done with it.
if (sql->NumRows() > 0)
{
sql->Query("UPDATE server_variables SET `value` = %i, `expiry` = %i WHERE name = '%s' LIMIT 1;", value, expiry, name);
}
else
{
sql->Query("INSERT INTO server_variables VALUES ('%s', %i, %i);", name, value, expiry);
}
}
}

if (setVarMaxRetry > 0)
Expand Down