Skip to content

Commit d633573

Browse files
committed
Admin functions
1 parent cbfd71c commit d633573

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+895
-59
lines changed

functions/Admin/addBan.yaml

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,48 @@
1-
# Scraped from: https://wiki.multitheftauto.com/wiki/addBan
21
server:
32
name: addBan
4-
description: TODO
5-
incomplete: true
3+
description: This function will add a [[ban]] for the specified IP/username/serial to the server.
4+
notes:
5+
- type: info
6+
content: 'One of the three: IP, Username or Serial have to be specified.'
7+
- type: warning
8+
content: |
9+
Banning based on username is not recommended, because the player can change their nickname at any time and thus bypass the ban.
10+
This feature is a leftover from the times when MTA used [MTA Community](http://community.mtasa.com/) accounts for gameplay — today it's an outdated option, kept only for backward compatibility.
11+
- type: warning
12+
content: Banning based solely on IP is not recommended, as a player can change their IP, for example by using a VPN. The safest option is to ban the [[serial]].
13+
oop:
14+
element: ban
15+
constructorclass: Ban
16+
parameters:
17+
- name: IP
18+
type: string
19+
description: The IP to be banned. If you don't want to ban by IP, set this to [[nil]].
20+
- name: username
21+
type: string
22+
description: The username (nick) to be banned. If you don't want to ban by username, set this to [[nil]].
23+
- name: serial
24+
type: string
25+
description: The [[serial]] to be banned. If you don't want to ban by serial, set this to [[nil]].
26+
- name: responsibleElement
27+
type: player/string
28+
description: The element that is responsible for banning the IP/username/serial. This can be a [[player]] or the [[root]]. This also can be a [[string]] - max 30 characters.
29+
default: "\"Console\""
30+
- name: reason
31+
type: string
32+
description: The reason the IP/username/serial will be banned from the server. Max 125 characters.
33+
default: "\"\""
34+
- name: seconds
35+
type: int
36+
description: The amount of seconds the player will be banned from the server for. This can be 0 for an infinite amount of time.
37+
default: '0'
38+
returns:
39+
values:
40+
- type: ban|false
41+
name: ban
42+
description: Returns the new [[ban]] if the IP/username/serial was banned successfully, false if invalid arguments are specified.
43+
examples:
44+
- path: examples/addBan-1.lua
45+
description: This example add command to ban player serial.
46+
- path: examples/addBan_OOP-1.lua
47+
description: This example add command to ban player serial.
48+
oop: true

functions/Admin/banPlayer.yaml

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,45 @@
1-
# Scraped from: https://wiki.multitheftauto.com/wiki/banPlayer
21
server:
32
name: banPlayer
4-
description: TODO
5-
incomplete: true
3+
description: This function will ban the specified player by either IP, serial or username.
4+
oop:
5+
element: player
6+
method: ban
7+
parameters:
8+
- name: bannedPlayer
9+
type: player
10+
description: The [[player]] that will be banned from the server.
11+
- name: IP
12+
type: bool
13+
description: Will player be banned by IP?
14+
default: 'true'
15+
- name: username
16+
type: bool
17+
description: Will player be banned by username? (Preferred **false**).
18+
default: 'false'
19+
- name: serial
20+
type: bool
21+
description: Will player be banned by serial?
22+
default: 'false'
23+
- name: responsibleElement
24+
type: player/string
25+
description: The element that is responsible for banning the [[player]]. This can be a player or the root. This also can be a [[string]] - max 30 characters.
26+
default: "\"Console\""
27+
- name: reason
28+
type: string
29+
description: The reason the [[player]] will be banned from the server.
30+
default: "\"\""
31+
- name: seconds
32+
type: int
33+
description: The amount of seconds the [[player]] will be banned from the server for. This can be 0 for an infinite amount of time.
34+
default: '0'
35+
returns:
36+
values:
37+
- type: ban|false
38+
name: ban
39+
description: Returns a [[ban]] object if banned successfully, or false if unsuccessful.
40+
examples:
41+
- path: examples/banPlayer-1.lua
42+
description: This example lets a player ban anyone if he has ACL rights.
43+
- path: examples/banPlayer_OOP-1.lua
44+
description: This example lets a player ban anyone if he has ACL rights.
45+
oop: true

functions/Admin/examples/addBan-1.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
local function banSerial(source, command, noob, reason)
2+
if (noob) then
3+
local theNoob = getPlayerFromName(noob)
4+
if (theNoob) then
5+
local theNoobSerial = getPlayerSerial(theNoob)
6+
addBan(nil, nil, theNoobSerial, source, reason)
7+
else
8+
outputChatBox("Player "..noob.." not found.", source)
9+
end
10+
end
11+
end
12+
addCommandHandler("ban-serial", banSerial)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
local function banSerial(source, command, noob, reason)
2+
if (noob) then
3+
local theNoob = Player(noob)
4+
if (theNoob) then
5+
local theNoobSerial = theNoob.serial
6+
Ban(nil, nil, theNoobSerial, source, reason)
7+
else
8+
source:outputChat("Player "..noob.." not found.")
9+
end
10+
end
11+
end
12+
addCommandHandler("ban-serial", banSerial)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--Add the "ban" command handler
2+
-- Example with the player
3+
local function banPlayerCommand(theClient, commandName, bannedName, reason)
4+
-- Give the player a nice error if he doesn't have rights
5+
if (hasObjectPermissionTo(theClient, "function.banPlayer")) then
6+
--Get player element from the name
7+
local bannedPlayer = getPlayerFromName(bannedName)
8+
9+
-- Check if player exists
10+
if (not bannedPlayer) then
11+
outputChatBox("Player "..bannedName.." not found.", theClient)
12+
return
13+
end
14+
15+
--Ban the player
16+
banPlayer(bannedPlayer, false, false, true, theClient, reason)
17+
outputChatBox("ban: "..bannedName.." successfully banned", theClient)
18+
else
19+
outputChatBox("ban: You don't have enough permissions", theClient)
20+
end
21+
end
22+
addCommandHandler("ban", banPlayerCommand)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--Add the "ban" command handler
2+
-- Example with the player
3+
local function banPlayerCommand(theClient, commandName, bannedName, reason)
4+
-- Give the player a nice error if he doesn't have rights
5+
if (ACL.hasObjectPermissionTo(theClient, "function.banPlayer")) then
6+
--Get player element from the name
7+
local bannedPlayer = Player(bannedName)
8+
9+
-- Check if player exists
10+
if (not bannedPlayer) then
11+
theClient:outputChat("Player "..bannedName.." not found.")
12+
return
13+
end
14+
15+
--Ban the player
16+
bannedPlayer:ban(false, false, true, theClient, reason)
17+
theClient:outputChat("ban: "..bannedName.." successfully banned")
18+
else
19+
theClient:outputChat("ban: You don't have enough permissions")
20+
end
21+
end
22+
addCommandHandler("ban", banPlayerCommand)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
local function outputBan(ban)
2+
local banned = getBanNick(ban) -- Get the name of the player who was banned
3+
local banner = getBanAdmin(ban) -- Get the name of the admin who banned the player
4+
local reason = getBanReason(ban) -- Get the reason the player was banned
5+
outputChatBox("-----BAN-----",root,255,0,0)
6+
if (banned) then
7+
outputChatBox("Player banned: "..banned,root,255,0,0) -- Output the player name who was banned
8+
end
9+
if (banner) then
10+
outputChatBox("Banner: "..banner,root,255,0,0) -- Output the admin name who performed the ban
11+
end
12+
if (reason) then
13+
outputChatBox("Reason: "..reason,root,255,0,0) -- outputt the reason the player was banned
14+
end
15+
end
16+
addEventHandler("onBan", root, outputBan) -- When a player is banned trigger the outputBan function
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
local function outputBan(ban)
2+
local banned = ban.nick -- Get the name of the player who was banned
3+
local banner = ban.admin -- Get the name of the admin who banned the player
4+
local reason = ban.reason -- Get the reason the player was banned
5+
root:outputChat("-----BAN-----",255,0,0)
6+
if (banned) then
7+
root:outputChat("Player banned: "..banned,255,0,0) -- Output the player name who was banned
8+
end
9+
if (banner) then
10+
root:outputChat("Banner: "..banner,255,0,0) -- Output the admin name who performed the ban
11+
end
12+
if (reason) then
13+
root:outputChat("Reason: "..reason,255,0,0) -- outputt the reason the player was banned
14+
end
15+
end
16+
addEventHandler("onBan", root, outputBan) -- When a player is banned trigger the outputBan function
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
local function banPlayerCommand(thisPlayer, commandName, bannedName, reason)
2+
if (hasObjectPermissionTo(thisPlayer, "function.banPlayer")) then -- If the command user has the rights
3+
local bannedPlayer = getPlayerFromName(bannedName) -- Get player by name
4+
if (bannedPlayer) then
5+
local theBan = banPlayer(bannedPlayer, true, false, true, thisPlayer, reason) -- Ban the player
6+
outputChatBox("ban: " .. bannedName .. " successfully banned", thisPlayer) -- Send the banner a succes message
7+
outputChatBox("At IP Adress: " ..getBanIP(theBan), thisPlayer) -- And send him the IP adress of the banned player
8+
else
9+
outputChatBox("Player "..bannedName." not found", thisPlayer)
10+
end
11+
else
12+
outputChatBox("ban: You don't have enough permissions", thisPlayer) -- If the command user doesn't have the permissions
13+
end
14+
end
15+
addCommandHandler("ban", banPlayerCommand)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
local function banPlayerCommand(thisPlayer, commandName, bannedName, reason)
2+
if (ACL.hasObjectPermissionTo(thisPlayer, "function.banPlayer")) then -- If the command user has the rights
3+
local bannedPlayer = Player(bannedName) -- Get player by name
4+
if (bannedPlayer) then
5+
local theBan = bannedPlayer:ban(true, false, true, thisPlayer, reason) -- Ban the player
6+
thisPlayer:outputChat("ban: " .. bannedName .. " successfully banned") -- Send the banner a succes message
7+
thisPlayer:outputChat("At IP Adress: " ..theBan.ip) -- And send him the IP adress of the banned player
8+
else
9+
thisPlayer:outputChat("Player "..bannedName." not found")
10+
end
11+
else
12+
thisPlayer:outputChat("ban: You don't have enough permissions") -- If the command user doesn't have the permissions
13+
end
14+
end
15+
addCommandHandler("ban", banPlayerCommand)

0 commit comments

Comments
 (0)