diff --git a/scripts/zones/Mhaura/Zone.lua b/scripts/zones/Mhaura/Zone.lua index 425265a58cc..8abfca6078c 100644 --- a/scripts/zones/Mhaura/Zone.lua +++ b/scripts/zones/Mhaura/Zone.lua @@ -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) @@ -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) diff --git a/scripts/zones/Selbina/Zone.lua b/scripts/zones/Selbina/Zone.lua index 7f4b61e6989..849f6273cc4 100644 --- a/scripts/zones/Selbina/Zone.lua +++ b/scripts/zones/Selbina/Zone.lua @@ -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) @@ -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) diff --git a/src/map/utils/serverutils.cpp b/src/map/utils/serverutils.cpp index b49440cbedd..510fd78ce45 100644 --- a/src/map/utils/serverutils.cpp +++ b/src/map/utils/serverutils.cpp @@ -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); + } + } } } @@ -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)