Skip to content

Commit

Permalink
admin commands
Browse files Browse the repository at this point in the history
  • Loading branch information
GlorifiedPig committed Aug 12, 2017
1 parent c463877 commit 1d9d67b
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 21 deletions.
145 changes: 140 additions & 5 deletions lua/glorifiedbanking/module/cl_banking_concommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,143 @@ local function requestAdminCommand()
end )
end

concommand.Add( "glorifiedbanking_testaccess", function( ply )
requestAdminCommand()

print(HasAdminAccess)
end )
requestAdminCommand()

if HasAdminAccess then
local function AutoCompleteAddBankBalance( cmd, stringargs )
stringargs = string.Trim( stringargs )
stringargs = string.lower( stringargs )

local tbl = {}

for k, v in pairs( player.GetAll() ) do
local nick = v:Nick()
if string.find( string.lower( nick ), stringargs ) then
nick = "\"" .. nick .. "\""
nick = "glorifiedbanking_addbalance " .. nick

table.insert( tbl, nick )
end
end

return tbl
end

concommand.Add( "glorifiedbanking_addbalance", function( ply, cmd, args )
if args == nil or args[1] == nil or args[2] == nil then
print("Usage: glorifiedbanking_addbalance <player> <amount>")
return
end

local nick = args[1]
nick = string.lower( nick )

local amount = tonumber( args[2] )

for k, v in pairs( player.GetAll() ) do
if string.find( string.lower( v:Nick() ), nick ) then
net.Start( "GlorifiedBanking_Admin_AddBankBalance" )
net.WriteInt( amount, 32 )
net.WriteEntity( v )
net.SendToServer()

return
end
end

print( "Could not find player." )
end, AutoCompleteAddBankBalance )

local function AutoCompleteRemoveBankBalance( cmd, stringargs )
stringargs = string.Trim( stringargs )
stringargs = string.lower( stringargs )

local tbl = {}

for k, v in pairs( player.GetAll() ) do
local nick = v:Nick()
if string.find( string.lower( nick ), stringargs ) then
nick = "\"" .. nick .. "\""
nick = "glorifiedbanking_removebalance " .. nick

table.insert( tbl, nick )
end
end

return tbl
end

concommand.Add( "glorifiedbanking_removebalance", function( ply, cmd, args )
if args == nil or args[1] == nil or args[2] == nil then
print("Usage: glorifiedbanking_removebalance <player> <amount>")
return
end

local nick = args[1]
nick = string.lower( nick )

local amount = tonumber( args[2] )

for k, v in pairs( player.GetAll() ) do
if string.find( string.lower( v:Nick() ), nick ) then
net.Start( "GlorifiedBanking_Admin_RemoveBankBalance" )
net.WriteInt( amount, 32 )
net.WriteEntity( v )
net.SendToServer()

return
end
end

print( "Could not find player." )
end, AutoCompleteRemoveBankBalance )

local function AutoCompleteGetBankBalance( cmd, stringargs )
stringargs = string.Trim( stringargs )
stringargs = string.lower( stringargs )

local tbl = {}

for k, v in pairs( player.GetAll() ) do
local nick = v:Nick()
if string.find( string.lower( nick ), stringargs ) then
nick = "\"" .. nick .. "\""
nick = "glorifiedbanking_getbalance " .. nick

table.insert( tbl, nick )
end
end

return tbl
end

concommand.Add( "glorifiedbanking_getbalance", function( ply, cmd, args )
if args == nil or args[1] == nil then
print("Usage: glorifiedbanking_getbalance <player>")
return
end

local nick = args[1]
nick = string.lower( nick )

for k, v in pairs( player.GetAll() ) do
if string.find( string.lower( v:Nick() ), nick ) then
net.Start( "GlorifiedBanking_Admin_GetBankBalance" )
net.WriteEntity( v )
net.SendToServer()

timer.Simple( ply:Ping() / 1000 + 0.1, function()
net.Receive( "GlorifiedBanking_Admin_GetBankBalanceReceive", function()
local amount = net.ReadInt( 32 )

print( v:Nick() .. "'s bank balance is $" .. string.Comma( amount ) .. "." )
end )
end )

return
end
end

print( "Could not find player." )
end, AutoCompleteGetBankBalance )
end
2 changes: 1 addition & 1 deletion lua/glorifiedbanking/module/sh_privileges.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ glorifiedbanking.privilege = {

CAMI.RegisterPrivilege {
Name = glorifiedbanking.privilege.CAMI_CAN_USE_ADMIN_COMMANDS,
MinAccess = "superadmin"
MinAccess = glorifiedbanking.config.ADMIN_INHERIT_MINIMUM
}
89 changes: 75 additions & 14 deletions lua/glorifiedbanking/module/sv_banking_core.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
--[[ VERY IMPORTANT NOTICE:
ONLY USE THESE FUNCTIONS ON SERVERSIDE FILES! YOU WILL FUCK EVERYTHING UP IF YOU DO THEM ON CLIENTSIDE FILES! ]]--

util.AddNetworkString( "GlorifiedBanking_UpdateBankBalance" )
util.AddNetworkString( "GlorifiedBanking_UpdateBankBalanceReceive" )
util.AddNetworkString( "GlorifiedBanking_UpdateWithdrawal" )
util.AddNetworkString( "GlorifiedBanking_IsAffordableDeposit" )
util.AddNetworkString( "GlorifiedBanking_IsAffordableDepositReceive" )
util.AddNetworkString( "GlorifiedBanking_UpdateDeposit" )
util.AddNetworkString( "GlorifiedBanking_UpdateTransfer" )
util.AddNetworkString( "GlorifiedBanking_Notification" )
local NetStrings = {
-- updating bank balance
"GlorifiedBanking_UpdateBankBalance",
"GlorifiedBanking_UpdateBankBalanceReceive",

-- update withdrawals
"GlorifiedBanking_UpdateWithdrawal",

-- info from deposit
"GlorifiedBanking_IsAffordableDeposit",
"GlorifiedBanking_UpdateDeposit",

-- update a transfer
"GlorifiedBanking_UpdateTransfer",

-- send a notification to the client
"GlorifiedBanking_Notification",

-- administration netstrings
"GlorifiedBanking_Admin_AddBankBalance",
"GlorifiedBanking_Admin_RemoveBankBalance",
"GlorifiedBanking_Admin_GetBankBalance",

-- all "receive" netstrings
"GlorifiedBanking_IsAffordableDepositReceive",
"GlorifiedBanking_Admin_GetBankBalanceReceive"
}

for k, v in pairs( NetStrings ) do
util.AddNetworkString( v )
end

hook.Add( "PlayerInitialSpawn", "GlorifiedBanking_Banking_InitialSpawnCheck", function( ply )
if ply:GetPData( "GlorifiedBanking_BankBalance" ) == NIL or ply:GetPData( "GlorifiedBanking_BankBalance") == NULL then
Expand Down Expand Up @@ -51,15 +74,11 @@ function plyMeta:RemoveBankBalance( amt )
end

function plyMeta:ForceAddBankBalance( amt )
if amt <= glorifiedbanking.config.MAX_DEPOSIT then
self:SetPData( "GlorifiedBanking_BankBalance", self:GetBankBalance() + amt )
end
self:SetPData( "GlorifiedBanking_BankBalance", self:GetBankBalance() + amt )
end

function plyMeta:ForceRemoveBankBalance( amt )
if amt <= glorifiedbanking.config.MAX_WITHDRAWAL then
self:SetPData( "GlorifiedBanking_BankBalance", self:GetPData( "GlorifiedBanking_BankBalance" ) - amt )
end
self:SetPData( "GlorifiedBanking_BankBalance", self:GetPData( "GlorifiedBanking_BankBalance" ) - amt )
end

function plyMeta:TransferBankBalance( amt, player2 )
Expand Down Expand Up @@ -108,4 +127,46 @@ net.Receive( "GlorifiedBanking_UpdateTransfer", function( len, ply )
net.Send( player2 )

ply:TransferBankBalance( tonumber( amount ), player2 )
end )

net.Receive( "GlorifiedBanking_Admin_AddBankBalance", function( len, ply )
local amount = net.ReadInt( 32 )
local player2 = net.ReadEntity()

net.Start( "GlorifiedBanking_Notification" )
net.WriteString( "You have given $" .. string.Comma( amount ) .. " to " .. player2:Nick() .. "." )
net.WriteBool( false )
net.Send( ply )

net.Start( "GlorifiedBanking_Notification" )
net.WriteString( "You have been given $" .. string.Comma( amount ) .. " from administrator " .. ply:Nick() .. "." )
net.WriteBool( false )
net.Send( player2 )

player2:ForceAddBankBalance( amount )
end )

net.Receive( "GlorifiedBanking_Admin_RemoveBankBalance", function( len, ply )
local amount = net.ReadInt( 32 )
local player2 = net.ReadEntity()

net.Start( "GlorifiedBanking_Notification" )
net.WriteString( "You have removed $" .. string.Comma( amount ) .. " from " .. player2:Nick() .. "'s account." )
net.WriteBool( false )
net.Send( ply )

net.Start( "GlorifiedBanking_Notification" )
net.WriteString( "$" .. string.Comma( amount ) .. " has been removed from your account by administrator " .. ply:Nick() .. "." )
net.WriteBool( true )
net.Send( player2 )

player2:ForceRemoveBankBalance( amount )
end )

net.Receive( "GlorifiedBanking_Admin_GetBankBalance", function( len, ply )
local player2 = net.ReadEntity()

net.Start( "GlorifiedBanking_Admin_GetBankBalanceReceive" )
net.WriteInt( player2:GetBankBalance(), 32 )
net.Send( ply )
end )
4 changes: 3 additions & 1 deletion lua/glorifiedbanking/sh_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ glorifiedbanking.config.DERMA_BACKGROUND_COLOR = Color( 0, 0, 0, 150 ) -- The de
glorifiedbanking.config.DERMA_BACKGROUND_COLOR_SUBSECTION = Color( 35, 35, 35, 255 ) -- The default colour on the Withdrawal, Deposit and Transfer section.
glorifiedbanking.config.DERMA_BUTTON_COLOUR = Color( 41, 128, 185, 250 ) -- The default button colours of the ATM menu.

-- All the usergroups that are able to use administrative commands.
glorifiedbanking.config.ADMIN_INHERIT_MINIMUM = "superadmin" -- The minimum rank requirement (inherits from "x") to be able to use administrative commands.

-- All the usergroups that are able to use administrative commands. Group must inherit from 'superadmin'
glorifiedbanking.config.ADMIN_USERGROUPS = {
"superadmin",
"owner"
Expand Down

0 comments on commit 1d9d67b

Please sign in to comment.