diff --git a/lua/glorifiedbanking/module/cl_banking_concommands.lua b/lua/glorifiedbanking/module/cl_banking_concommands.lua index 18911b3..ca9ec17 100644 --- a/lua/glorifiedbanking/module/cl_banking_concommands.lua +++ b/lua/glorifiedbanking/module/cl_banking_concommands.lua @@ -17,8 +17,143 @@ local function requestAdminCommand() end ) end -concommand.Add( "glorifiedbanking_testaccess", function( ply ) - requestAdminCommand() - - print(HasAdminAccess) -end ) \ No newline at end of file +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 ") + 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 ") + 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 ") + 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 \ No newline at end of file diff --git a/lua/glorifiedbanking/module/sh_privileges.lua b/lua/glorifiedbanking/module/sh_privileges.lua index 801b1ce..5f10676 100644 --- a/lua/glorifiedbanking/module/sh_privileges.lua +++ b/lua/glorifiedbanking/module/sh_privileges.lua @@ -5,5 +5,5 @@ glorifiedbanking.privilege = { CAMI.RegisterPrivilege { Name = glorifiedbanking.privilege.CAMI_CAN_USE_ADMIN_COMMANDS, - MinAccess = "superadmin" + MinAccess = glorifiedbanking.config.ADMIN_INHERIT_MINIMUM } \ No newline at end of file diff --git a/lua/glorifiedbanking/module/sv_banking_core.lua b/lua/glorifiedbanking/module/sv_banking_core.lua index 0833cae..9ef82cf 100644 --- a/lua/glorifiedbanking/module/sv_banking_core.lua +++ b/lua/glorifiedbanking/module/sv_banking_core.lua @@ -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 @@ -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 ) @@ -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 ) \ No newline at end of file diff --git a/lua/glorifiedbanking/sh_config.lua b/lua/glorifiedbanking/sh_config.lua index 5f19da5..4f203d5 100644 --- a/lua/glorifiedbanking/sh_config.lua +++ b/lua/glorifiedbanking/sh_config.lua @@ -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"