Okay so today i started making a plugin and its named "Advanced Save System"
I want to add for every command AuthLevel but i dont know how .. + i want to add in config AuthLevel Option... but i dont know how
I tried to do this with "if player.net.connection.authLevel < 2 then return end" dunno if it works actualy .. and i want to set AuthLevel Option to config as i said help plz
Code:PLUGIN.Title = "Advanced Save System" PLUGIN.Version = V(0, 1, 0) PLUGIN.Description = "Advanced Save System." PLUGIN.Author = "Merka"function PLUGIN:Init() command.AddChatCommand("steamid", self.Plugin, "cmdSteamId") command.AddChatCommand("save", self.Plugin, "cmdSave") command.AddChatCommand("setautosave_2m", self.Plugin, "cmdas2m") command.AddChatCommand("setautosave_5m", self.Plugin, "cmdas5m") command.AddChatCommand("setautosave_10m", self.Plugin, "cmdas10m") command.AddChatCommand("setautosave_30m", self.Plugin, "cmdas30m") end function PLUGIN:cmdSteamId(player, command, arg) rust.SendChatMessage(player, "SERVER", "Your Steam ID is: " .. rust.UserIDFromPlayer(player)) end function PLUGIN:cmdSave(player, command, arg) if player.net.connection.authLevel < 2 then return end rust.RunServerCommand("server.save") end function PLUGIN:cmdas2m(player, command, arg) if player.net.connection.authLevel < 2 then return end rust.RunServerCommand("server.saveinterval 120") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 2minutes!") end function PLUGIN:cmdas5m(player, command, arg) if player.net.connection.authLevel < 2 then return end rust.RunServerCommand("server.saveinterval 300") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 5minutes!") end function PLUGIN:cmdas10m(player, command, arg) if player.net.connection.authLevel < 2 then return end rust.RunServerCommand("server.saveinterval 600") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 10minutes!") end function PLUGIN:cmdas30m(player, command, arg) if player.net.connection.authLevel < 2 then return end rust.RunServerCommand("server.saveinterval 1800") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 30minutes!") end function PLUGIN:OnServerSave() rust.BroadcastChat("Server-Save", "Save Process just finished!") end
Setting auth level per command?
Discussion in 'Rust Development' started by PaiN, Apr 8, 2015.
-
Wulf Community Admin
I'd recommend using the Oxide permissions system instead of Rust's auth levels. If you want an example of using auth levels though, take a look at a lot of my plugins. http://oxidemod.org/plugins/ping.656/
-
Code:
if player.net.connection.authLevel < 2 then return end
-
Wulf Community Admin
-
Code:PLUGIN.Title = "Advanced Save System" PLUGIN.Version = V(0, 1, 0) PLUGIN.Description = "Advanced Save System." PLUGIN.Author = "Merka" PLUGIN.HasConfig = truefunction PLUGIN:LoadDefaultConfig() self.Config.Settings = self.Config.Settings or {} self.Config.Settings.AuthLevel = tonumber(self.Config.Settings.AuthLevel) or 2 self:SaveConfig() endfunction PLUGIN:Init() command.AddChatCommand("steamid", self.Plugin, "cmdSteamId") command.AddChatCommand("save", self.Plugin, "cmdSave") command.AddChatCommand("setautosave_2m", self.Plugin, "cmdas2m") command.AddChatCommand("setautosave_5m", self.Plugin, "cmdas5m") command.AddChatCommand("setautosave_10m", self.Plugin, "cmdas10m") command.AddChatCommand("setautosave_30m", self.Plugin, "cmdas30m") end function PLUGIN:cmdSteamId(player, command, arg) rust.SendChatMessage(player, "SERVER", "Your Steam ID is: " .. rust.UserIDFromPlayer(player)) end function PLUGIN:cmdSave(player, command, arg) rust.RunServerCommand("server.save") end function PLUGIN:cmdas2m(player, command, arg) rust.RunServerCommand("server.saveinterval 120") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 2minutes!") end function PLUGIN:cmdas5m(player, command, arg) rust.RunServerCommand("server.saveinterval 300") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 5minutes!") end function PLUGIN:cmdas10m(player, command, arg) rust.RunServerCommand("server.saveinterval 600") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 10minutes!") end function PLUGIN:cmdas30m(player, command, arg) rust.RunServerCommand("server.saveinterval 1800") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 30minutes!") end function PLUGIN:OnServerSave() rust.BroadcastChat("Server-Save", "Save Process just finished!") end local function HasPermission(self, connection) local authLevel if connection then authLevel = connection.authLevel else authLevel = 2 end if debug then print(connection.username .. " has auth level: " .. tostring(authLevel)) end local neededLevel = tonumber(self.Config.Settings.AuthLevel) or 2 if authLevel and authLevel >= neededLevel then return true else return false end end
Code:{ "Settings": { "AuthLevel": 2 } }
-
Wulf Community Admin
My HasPermissions is probably a little bit overkill for what you want, but you aren't actually using it in your code above, so all of your commands are wide open for every user.
-
+ some code reduction
Code:local function HasPermission(self, connection) local authLevel if connection then authLevel = connection.authLevel else authLevel = 2 end if debug then print(connection.username .. " has auth level: " .. tostring(authLevel)) end local neededLevel = tonumber(self.Config.Settings.AuthLevel) or 2 if authLevel and authLevel >= neededLevel then return true else return false end end
Code:local function HasPermission(self, connection) local authLevel = (connection and connection.authLevel) or 2 if debug then print(connection.username .. " has auth level: " .. tostring(authLevel)) end local neededLevel = tonumber(self.Config.Settings.AuthLevel) or 2 return authLevel >= neededLevel end
-
Code:PLUGIN.Title = "Advanced Save System" PLUGIN.Version = V(0, 1, 0) PLUGIN.Description = "Advanced Save System." PLUGIN.Author = "Merka" PLUGIN.HasConfig = truefunction PLUGIN:LoadDefaultConfig() self.Config.Settings = self.Config.Settings or {} self.Config.Settings.AuthLevel = tonumber(self.Config.Settings.AuthLevel) or 2 self:SaveConfig() endfunction PLUGIN:Init() command.AddChatCommand("steamid", self.Plugin, "cmdSteamId") command.AddChatCommand("save", self.Plugin, "cmdSave") command.AddChatCommand("setautosave_2m", self.Plugin, "cmdas2m") command.AddChatCommand("setautosave_5m", self.Plugin, "cmdas5m") command.AddChatCommand("setautosave_10m", self.Plugin, "cmdas10m") command.AddChatCommand("setautosave_30m", self.Plugin, "cmdas30m") end local function HasPermission(self, connection) local authLevel = connection.authLevel or 2 if debug then print(connection.username .. " has auth level: " .. tostring(authLevel)) end local neededLevel = tonumber(self.Config.Settings.AuthLevel) or 2 return authLevel >= neededLevel end function PLUGIN:cmdSteamId(player, command, arg) rust.SendChatMessage(player, "SERVER", "Your Steam ID is: " .. rust.UserIDFromPlayer(player)) end function PLUGIN:cmdSave(player, command, arg) rust.RunServerCommand("server.save") end function PLUGIN:cmdas2m(player, command, arg) rust.RunServerCommand("server.saveinterval 120") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 2minutes!") end function PLUGIN:cmdas5m(player, command, arg) rust.RunServerCommand("server.saveinterval 300") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 5minutes!") end function PLUGIN:cmdas10m(player, command, arg) rust.RunServerCommand("server.saveinterval 600") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 10minutes!") end function PLUGIN:cmdas30m(player, command, arg) rust.RunServerCommand("server.saveinterval 1800") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 30minutes!") end function PLUGIN:OnServerSave() rust.BroadcastChat("Server-Save", "Save Process just finished!") end
-
Wulf Community Admin
Yes, but you still have to use the function before your command functions are run. You aren't checking if the user has permission.
-
-
Wulf Community Admin
-
connection.authLevel or 2 -> (connection and connection.authLevel) or 2 -
SO NOW MUST BE READY what about this
Code:PLUGIN.Title = "Advanced Save System" PLUGIN.Version = V(0, 1, 0) PLUGIN.Description = "Advanced Save System." PLUGIN.Author = "Merka" PLUGIN.HasConfig = truefunction PLUGIN:LoadDefaultConfig() self.Config.Settings = self.Config.Settings or {} self.Config.Settings.AuthLevel = tonumber(self.Config.Settings.AuthLevel) or 2 self:SaveConfig() endfunction PLUGIN:Init() command.AddChatCommand("steamid", self.Plugin, "cmdSteamId") command.AddChatCommand("save", self.Plugin, "cmdSave") command.AddChatCommand("setautosave_2m", self.Plugin, "cmdas2m") command.AddChatCommand("setautosave_5m", self.Plugin, "cmdas5m") command.AddChatCommand("setautosave_10m", self.Plugin, "cmdas10m") command.AddChatCommand("setautosave_30m", self.Plugin, "cmdas30m") end local function HasPermission(self, connection) (connection and connection.authLevel) or 2 if debug then print(connection.username .. " has auth level: " .. tostring(authLevel)) end local neededLevel = tonumber(self.Config.Settings.AuthLevel) or 2 return authLevel >= neededLevel end function PLUGIN:cmdSteamId(player, command, arg) rust.SendChatMessage(player, "SERVER", "Your Steam ID is: " .. rust.UserIDFromPlayer(player)) end function PLUGIN:cmdSave(player, command, arg) rust.RunServerCommand("server.save") end function PLUGIN:cmdas2m(player, command, arg) rust.RunServerCommand("server.saveinterval 120") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 2minutes!") end function PLUGIN:cmdas5m(player, command, arg) rust.RunServerCommand("server.saveinterval 300") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 5minutes!") end function PLUGIN:cmdas10m(player, command, arg) rust.RunServerCommand("server.saveinterval 600") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 10minutes!") end function PLUGIN:cmdas30m(player, command, arg) rust.RunServerCommand("server.saveinterval 1800") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 30minutes!") end function PLUGIN:OnServerSave() rust.BroadcastChat("Server-Save", "Save Process just finished!") end
-
Wulf Community Admin
Still missing the actual permission checking for each command.
Code:function PLUGIN:cmdSave(player, command, arg) if not HasPermission(self, player.net.connection) then return end rust.RunServerCommand("server.save") end
Code:local function HasPermission(self, connection) local authLevel = (connection and connection.authLevel) or 2 if debug then print(connection.username .. " has auth level: " .. tostring(authLevel)) end local neededLevel = tonumber(self.Config.Settings.AuthLevel) or 2 return authLevel >= neededLevel end
-
Code:function PLUGIN:cmdSteamId(player, command, arg) if HasPermission(self, player) then rust.SendChatMessage(player, "SERVER", "Your Steam ID is: " .. rust.UserIDFromPlayer(player)) end end
-
For god sake.. xD sry for beeing so retarded but still learning what about this ?
Code:PLUGIN.Title = "Advanced Save System" PLUGIN.Version = V(0, 1, 0) PLUGIN.Description = "Advanced Save System." PLUGIN.Author = "Merka" PLUGIN.HasConfig = truefunction PLUGIN:LoadDefaultConfig() self.Config.Settings = self.Config.Settings or {} self.Config.Settings.AuthLevel = tonumber(self.Config.Settings.AuthLevel) or 2 self:SaveConfig() endfunction PLUGIN:Init() command.AddChatCommand("steamid", self.Plugin, "cmdSteamId") command.AddChatCommand("save", self.Plugin, "cmdSave") command.AddChatCommand("setautosave_2m", self.Plugin, "cmdas2m") command.AddChatCommand("setautosave_5m", self.Plugin, "cmdas5m") command.AddChatCommand("setautosave_10m", self.Plugin, "cmdas10m") command.AddChatCommand("setautosave_30m", self.Plugin, "cmdas30m") end local function HasPermission(self, connection) (connection and connection.authLevel) or 2 if debug then print(connection.username .. " has auth level: " .. tostring(authLevel)) end local neededLevel = tonumber(self.Config.Settings.AuthLevel) or 2 return authLevel >= neededLevel end function PLUGIN:cmdSteamId(player, command, arg) if HasPermission(self, player:GetComponent("BaseNetworkable").net.connection) then rust.SendChatMessage(player, "SERVER", "Your Steam ID is: " .. rust.UserIDFromPlayer(player)) end function PLUGIN:cmdSave(player, command, arg) if HasPermission(self, player:GetComponent("BaseNetworkable").net.connection) then rust.RunServerCommand("server.save") end function PLUGIN:cmdas2m(player, command, arg) if HasPermission(self, player:GetComponent("BaseNetworkable").net.connection) then rust.RunServerCommand("server.saveinterval 120") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 2minutes!") end function PLUGIN:cmdas5m(player, command, arg) if HasPermission(self, player:GetComponent("BaseNetworkable").net.connection) then rust.RunServerCommand("server.saveinterval 300") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 5minutes!") end function PLUGIN:cmdas10m(player, command, arg) if HasPermission(self, player:GetComponent("BaseNetworkable").net.connection) then rust.RunServerCommand("server.saveinterval 600") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 10minutes!") end function PLUGIN:cmdas30m(player, command, arg) if HasPermission(self, player:GetComponent("BaseNetworkable").net.connection) then rust.RunServerCommand("server.saveinterval 1800") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 30minutes!") end function PLUGIN:OnServerSave() rust.BroadcastChat("Server-Save", "Save Process just finished!") end
-
Wulf Community Admin
Your if checks are a bit more than you need, and you're missing some closing tags for the if statements.
-
Not sure what you want but changed something hope this is what you told me to do
Code:PLUGIN.Title = "Advanced Save System" PLUGIN.Version = V(0, 1, 0) PLUGIN.Description = "Advanced Save System." PLUGIN.Author = "Merka" PLUGIN.HasConfig = truefunction PLUGIN:LoadDefaultConfig() self.Config.Settings = self.Config.Settings or {} self.Config.Settings.AuthLevel = tonumber(self.Config.Settings.AuthLevel) or 2 self:SaveConfig() endfunction PLUGIN:Init() command.AddChatCommand("steamid", self.Plugin, "cmdSteamId") command.AddChatCommand("save", self.Plugin, "cmdSave") command.AddChatCommand("setautosave_2m", self.Plugin, "cmdas2m") command.AddChatCommand("setautosave_5m", self.Plugin, "cmdas5m") command.AddChatCommand("setautosave_10m", self.Plugin, "cmdas10m") command.AddChatCommand("setautosave_30m", self.Plugin, "cmdas30m") end local function HasPermission(self, connection) (connection and connection.authLevel) or 2 if debug then print(connection.username .. " has auth level: " .. tostring(authLevel)) end local neededLevel = tonumber(self.Config.Settings.AuthLevel) or 2 return authLevel >= neededLevel end function PLUGIN:cmdSteamId(player, command, arg) if HasPermission(self, player:GetComponent("BaseNetworkable").net.connection) then rust.SendChatMessage(player, "SERVER", "Your Steam ID is: " .. rust.UserIDFromPlayer(player)) end function PLUGIN:cmdSave(player, command, arg) if HasPermission(self, player:GetComponent("BaseNetworkable").net.connection) then rust.RunServerCommand("server.save") end function PLUGIN:cmdas2m(player, command, arg) if HasPermission(self, player:GetComponent("BaseNetworkable").net.connection) then rust.RunServerCommand("server.saveinterval 120") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 2minutes!") end function PLUGIN:cmdas5m(player, command, arg) if HasPermission(self, player:GetComponent("BaseNetworkable").net.connection) then rust.RunServerCommand("server.saveinterval 300") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 5minutes!") end function PLUGIN:cmdas10m(player, command, arg) if HasPermission(self, player:GetComponent("BaseNetworkable").net.connection) then rust.RunServerCommand("server.saveinterval 600") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 10minutes!") end function PLUGIN:cmdas30m(player, command, arg) if HasPermission(self, player:GetComponent("BaseNetworkable").net.connection) then rust.RunServerCommand("server.saveinterval 1800") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 30minutes!") end function PLUGIN:OnServerSave() rust.BroadcastChat("Server-Save", "Save Process just finished!") end
-
Wulf Community Admin
Try running it on the server, you'll see.
Code:function PLUGIN:cmdSave(player, command, arg) if HasPermission(self, player.net.connection) then rust.RunServerCommand("server.save") end end
Code:function PLUGIN:cmdSave(player, command, arg) if not HasPermission(self, player.net.connection) then return end rust.RunServerCommand("server.save") end
-
Ready to Publish xD?
Code:PLUGIN.Title = "Advanced Save System" PLUGIN.Version = V(0, 1, 0) PLUGIN.Description = "Advanced Save System." PLUGIN.Author = "Merka" PLUGIN.HasConfig = truefunction PLUGIN:LoadDefaultConfig() self.Config.Settings = self.Config.Settings or {} self.Config.Settings.AuthLevel = tonumber(self.Config.Settings.AuthLevel) or 2 self:SaveConfig() endfunction PLUGIN:Init() command.AddChatCommand("steamid", self.Plugin, "cmdSteamId") command.AddChatCommand("save", self.Plugin, "cmdSave") command.AddChatCommand("setautosave_2m", self.Plugin, "cmdas2m") command.AddChatCommand("setautosave_5m", self.Plugin, "cmdas5m") command.AddChatCommand("setautosave_10m", self.Plugin, "cmdas10m") command.AddChatCommand("setautosave_30m", self.Plugin, "cmdas30m") end local function HasPermission(self, connection) (connection and connection.authLevel) or 2 if debug then print(connection.username .. " has auth level: " .. tostring(authLevel)) end local neededLevel = tonumber(self.Config.Settings.AuthLevel) or 2 return authLevel >= neededLevel end function PLUGIN:cmdSteamId(player, command, arg) if not HasPermission(self, player.net.connection) then return end rust.SendChatMessage(player, "SERVER", "Your Steam ID is: " .. rust.UserIDFromPlayer(player)) end function PLUGIN:cmdSave(player, command, arg) if not HasPermission(self, player.net.connection) then return end rust.RunServerCommand("server.save") end function PLUGIN:cmdas2m(player, command, arg) if not HasPermission(self, player.net.connection) then return end rust.RunServerCommand("server.saveinterval 120") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 2minutes!") end function PLUGIN:cmdas5m(player, command, arg) if not HasPermission(self, player.net.connection) then return end rust.RunServerCommand("server.saveinterval 300") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 5minutes!") end function PLUGIN:cmdas10m(player, command, arg) if not HasPermission(self, player.net.connection) then return end rust.RunServerCommand("server.saveinterval 600") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 10minutes!") end function PLUGIN:cmdas30m(player, command, arg) if not HasPermission(self, player.net.connection) then return end rust.RunServerCommand("server.saveinterval 1800") rust.SendChatMessage(player, "Save-System", "You just set the AUTO-SAVE to 30minutes!") end function PLUGIN:OnServerSave() rust.BroadcastChat("Server-Save", "Save Process just finished!") end