summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-06-09 00:42:32 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-06-09 00:42:32 +0200
commit1ca637f660a787cdaa0e1cbb5700333f21d727ee (patch)
treed45a80f4d462de1953d32a22ea32f54d1b5278bc
parentProtectionAreas: Implemented the ProtRemUserAll command's DB access (diff)
downloadcuberite-1ca637f660a787cdaa0e1cbb5700333f21d727ee.tar
cuberite-1ca637f660a787cdaa0e1cbb5700333f21d727ee.tar.gz
cuberite-1ca637f660a787cdaa0e1cbb5700333f21d727ee.tar.bz2
cuberite-1ca637f660a787cdaa0e1cbb5700333f21d727ee.tar.lz
cuberite-1ca637f660a787cdaa0e1cbb5700333f21d727ee.tar.xz
cuberite-1ca637f660a787cdaa0e1cbb5700333f21d727ee.tar.zst
cuberite-1ca637f660a787cdaa0e1cbb5700333f21d727ee.zip
Diffstat (limited to '')
-rw-r--r--MCServer/Plugins/ProtectionAreas/Storage.lua37
1 files changed, 36 insertions, 1 deletions
diff --git a/MCServer/Plugins/ProtectionAreas/Storage.lua b/MCServer/Plugins/ProtectionAreas/Storage.lua
index c444016f2..e9479fcbd 100644
--- a/MCServer/Plugins/ProtectionAreas/Storage.lua
+++ b/MCServer/Plugins/ProtectionAreas/Storage.lua
@@ -93,7 +93,7 @@ end
--- Creates the table of the specified name and columns[]
-- If the table exists, any columns missing are added; existing data is kept
function cStorage:CreateTable(a_TableName, a_Columns)
-
+ -- Try to create the table first
local sql = "CREATE TABLE IF NOT EXISTS '" .. a_TableName .. "' (";
sql = sql .. table.concat(a_Columns, ", ");
sql = sql .. ")";
@@ -101,6 +101,7 @@ function cStorage:CreateTable(a_TableName, a_Columns)
LOGWARNING(PluginPrefix .. "Cannot create DB Table " .. a_TableName);
return false;
end
+ -- SQLite doesn't inform us if it created the table or not, so we have to continue anyway
-- Check each column whether it exists
-- Remove all the existing columns from a_Columns:
@@ -154,6 +155,11 @@ end
--- Returns true if the specified area is allowed for the specified player
function cStorage:IsAreaAllowed(a_AreaID, a_PlayerName, a_WorldName)
+ assert(a_AreaID);
+ assert(a_PlayerName);
+ assert(a_WorldName);
+ assert(self);
+
local res = false;
local sql = "SELECT COUNT(*) FROM AllowedUsers WHERE (AreaID = " .. a_AreaID ..
") AND (UserName ='" .. a_PlayerName .. "')";
@@ -174,6 +180,12 @@ end
--- Loads cPlayerAreas for the specified player from the DB. Returns a cPlayerAreas object
function cStorage:LoadPlayerAreas(a_PlayerName, a_PlayerX, a_PlayerZ, a_WorldName)
+ assert(a_PlayerName);
+ assert(a_PlayerX);
+ assert(a_PlayerZ);
+ assert(a_WorldName);
+ assert(self);
+
res = cPlayerAreas:new();
-- Bounds for which the areas are loaded
@@ -213,6 +225,12 @@ end
--- Adds a new area into the DB. a_AllowedNames is a table listing all the players that are allowed in the area
-- Returns the ID of the new area, or -1 on failure
function cStorage:AddArea(a_Cuboid, a_WorldName, a_CreatorName, a_AllowedNames)
+ assert(a_Cuboid);
+ assert(a_WorldName);
+ assert(a_CreatorName);
+ assert(a_AllowedNames);
+ assert(self);
+
-- Store the area in the DB
local ID = -1;
local function RememberID(UserData, NumCols, Values, Names)
@@ -252,6 +270,10 @@ end
function cStorage:DelArea(a_WorldName, a_AreaID)
+ assert(a_WorldName);
+ assert(a_AreaID);
+ assert(self);
+
-- Since all areas are stored in a single DB (for now), the worldname parameter isn't used at all
-- Later if we change to a per-world DB, we'll need the world name
@@ -273,6 +295,11 @@ end
--- Removes the user from the specified area
function cStorage:RemoveUser(a_AreaID, a_UserName, a_WorldName)
+ assert(a_AreaID);
+ assert(a_UserName);
+ assert(a_WorldName);
+ assert(self);
+
-- WorldName is not used yet, because all the worlds share the same DB in this version
local sql = "DELETE FROM AllowedUsers WHERE " ..
"AreaID = " .. a_AreaID .. " AND UserName = '" .. a_UserName .. "'";
@@ -308,6 +335,11 @@ end
--- Calls the callback for each area intersecting the specified coords
-- Callback signature: function(ID, MinX, MinZ, MaxX, MaxZ, CreatorName)
function cStorage:ForEachArea(a_BlockX, a_BlockZ, a_WorldName, a_Callback)
+ assert(a_BlockX);
+ assert(a_BlockZ);
+ assert(a_WorldName);
+ assert(a_Callback);
+ assert(self);
-- SQL callback that parses the values and calls our callback
function CallCallback(UserData, NumValues, Values, Names)
@@ -343,6 +375,9 @@ end
--- Returns the info on the specified area
-- Returns MinX, MinZ, MaxX, MaxZ, CreatorName on success, or nothing on failure
function cStorage:GetArea(a_AreaID, a_WorldName)
+ assert(a_AreaID);
+ assert(a_WorldName);
+ assert(self);
local MinX, MinZ, MaxX, MaxZ, CreatorName;
local HasValues = false;