summaryrefslogtreecommitdiffstats
path: root/MCServer
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-06-08 21:16:57 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-06-08 21:16:57 +0200
commitbfd1ce5e53c57322e12025d796bea11994c0c1cc (patch)
treeb16f75b88e50d2419f8dd866923162942c26ff5f /MCServer
parentProtectionAreas: Added ProtListUsers, implemented ProtRemoveUser, fixed ProtDelID commands (diff)
downloadcuberite-bfd1ce5e53c57322e12025d796bea11994c0c1cc.tar
cuberite-bfd1ce5e53c57322e12025d796bea11994c0c1cc.tar.gz
cuberite-bfd1ce5e53c57322e12025d796bea11994c0c1cc.tar.bz2
cuberite-bfd1ce5e53c57322e12025d796bea11994c0c1cc.tar.lz
cuberite-bfd1ce5e53c57322e12025d796bea11994c0c1cc.tar.xz
cuberite-bfd1ce5e53c57322e12025d796bea11994c0c1cc.tar.zst
cuberite-bfd1ce5e53c57322e12025d796bea11994c0c1cc.zip
Diffstat (limited to 'MCServer')
-rw-r--r--MCServer/Plugins/ProtectionAreas/CommandHandlers.lua14
-rw-r--r--MCServer/Plugins/ProtectionAreas/Storage.lua46
2 files changed, 58 insertions, 2 deletions
diff --git a/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua b/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua
index 4ce0b2f35..b28c5149a 100644
--- a/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua
+++ b/MCServer/Plugins/ProtectionAreas/CommandHandlers.lua
@@ -108,8 +108,18 @@ function HandleAddAreaUser(a_Split, a_Player)
end
-- Add the area to the storage
- g_Storage:AddAreaUsers(tonumber(a_Split[2]), a_Player:GetWorld():GetName(), a_Player:GetName(), AllowedNames);
- a_Player:SendMessage("Users added: " .. table.concat(AllowedNames, ", "));
+ if (not(g_Storage:AddAreaUsers(
+ tonumber(a_Split[2]), a_Player:GetWorld():GetName(), a_Player:GetName(), AllowedNames))
+ ) then
+ LOGWARNING("g_Storage:AddAreaUsers failed");
+ a_Player:SendMessage("Cannot add users, DB failure");
+ return true;
+ end
+ if (#AllowedNames == 0) then
+ a_Player:SendMessage("All the specified users were already allowed.");
+ else
+ a_Player:SendMessage("Users added: " .. table.concat(AllowedNames, ", "));
+ end
-- Reload all currently logged in players
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
diff --git a/MCServer/Plugins/ProtectionAreas/Storage.lua b/MCServer/Plugins/ProtectionAreas/Storage.lua
index 118ab0434..defa9b394 100644
--- a/MCServer/Plugins/ProtectionAreas/Storage.lua
+++ b/MCServer/Plugins/ProtectionAreas/Storage.lua
@@ -379,6 +379,7 @@ function cStorage:ForEachUserInArea(a_AreaID, a_WorldName, a_Callback)
assert(a_AreaID);
assert(a_WorldName);
assert(a_Callback);
+ assert(self);
-- Since in this version all the worlds share a single DB, the a_WorldName parameter is not actually used
-- But this may change in the future, when we have a per-world DB
@@ -402,3 +403,48 @@ end
+--- Adds the specified usernames to the specified area, if not already present
+-- a_Users is an array table of usernames to add
+function cStorage:AddAreaUsers(a_AreaID, a_WorldName, a_AddedBy, a_Users)
+ assert(a_AreaID);
+ assert(a_WorldName);
+ assert(a_Users);
+ assert(self);
+
+ -- Remove from a_Users the usernames already present in the area
+ local sql = "SELECT UserName FROM AllowedUsers WHERE AreaID = " .. a_AreaID;
+ local function Remove(UserData, NumValues, Values, Names)
+ if (NumValues ~= 1) then
+ -- Invalid response format
+ return 0;
+ end
+ local DBName = Values[1];
+ -- Remove the name from a_Users, if exists
+ for idx, Name in ipairs(a_Users) do
+ if (Name == DBName) then
+ table.remove(a_Users, idx);
+ return 0;
+ end
+ end
+ return 0;
+ end
+ if (not(self:DBExec(sql, Remove))) then
+ LOGWARNING("SQL error while iterating through users");
+ return false;
+ end
+
+ -- Add the users
+ for idx, Name in ipairs(a_Users) do
+ local sql = "INSERT INTO AllowedUsers (AreaID, UserName) VALUES (" .. a_AreaID .. ", '" .. Name .. "')";
+ if (not(self:DBExec(sql))) then
+ LOGWARNING("SQL error while adding user " .. Name .. " to area " .. a_AreaID);
+ end
+ end
+
+ return true;
+end
+
+
+
+
+