Skip to content

Commit 14e5558

Browse files
authored
Merge branch 'master' into stealth-rewrite
2 parents ad84d01 + b94ffdd commit 14e5558

Some content is hidden

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

64 files changed

+1225
-340
lines changed

[admin]/acpanel/meta.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<meta>
2-
<info description="Anti-Cheat Control Panel" author="ccw" version="0.1.8" type="script" />
3-
<min_mta_version server="1.3.1" client="1.3.1"></min_mta_version>
2+
<info description="Anti-Cheat Control Panel" author="ccw" version="0.2.0" type="script" />
3+
<min_mta_version server="1.6.0" client="1.6.0"></min_mta_version>
44

55
<script src="_common.lua"/>
66
<script src="s_joiner.lua"/>
@@ -20,7 +20,7 @@
2020

2121

2222
<settings>
23-
<setting name="*admingroup" value="Admin,AdminPlus"
23+
<setting name="*admingroup" value="Admin"
2424
friendlyname="Admin group list"
2525
group="_Advanced"
2626
accept="*"

[admin]/acpanel/s_main.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function updatePlayer(player)
4747

4848
if newAllowed and not oldAllowed then
4949
bindKey( player, "o", "down", "Show_AC_Panel" )
50-
outputChatBox ( "Press 'o' to open your AC panel", player )
50+
outputChatBox ( "Press 'o' to open AC panel", player )
5151
if not bAllowGui then return end
5252
sendAllSettingsToClient()
5353
triggerClientEvent(player, 'onAcpClientInitialSettings', resourceRoot, getServerConfigSettingsToTransfer() )
@@ -113,10 +113,10 @@ function doesResourceHasPermissions()
113113
end
114114

115115
if not bResourceHasPermissions then
116-
outputChatBox( "AC Panel can not start until this command is run:" )
117-
outputChatBox( "aclrequest allow acpanel all" )
116+
outputServerLog( "AC Panel can not start until this command is run:" )
117+
outputServerLog( "aclrequest allow acpanel all" )
118118
else
119-
outputChatBox( "Please restart AC Panel" )
119+
outputServerLog( "Please restart AC Panel" )
120120
end
121121
return false
122122
end

[admin]/acpanel/s_settings.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,16 @@ end
198198
-- Get version data from remote server
199199
---------------------------------------------------------
200200
function GetVersInfoFromRemoteServer()
201-
fetchRemote( "http://nightly.mtasa.com/ver/", onGotVersInfo )
201+
fetchRemote( "https://nightly.multitheftauto.com/ver/", onGotVersInfo )
202202
end
203203

204204
function onGotVersInfo( responseData, errno )
205205
if errno == 0 then
206206

207-
local ver = string.sub( getVersion().sortable, 0, 3 )
207+
local ver = string.sub( getVersion().sortable, 1, 3 )
208208

209-
releaseMinVersion = string.match( responseData, "default: " ..ver .. ".(.-)[^0-9.-]" )
210-
latestMinVersion = string.match( responseData, "minclientversion: " .. ver .. ".(.-)[^0-9.-]" )
209+
releaseMinVersion = string.match( responseData, "Auto-update default:%s*" .. ver .. "%.([%d%-%.]+)" )
210+
latestMinVersion = string.match( responseData, "Max recommended/minclientversion:%s*" .. ver .. "%.([%d%-%.]+)" )
211211

212212
if releaseMinVersion and latestMinVersion then
213213
releaseMinVersion = ver .. "." .. releaseMinVersion
@@ -247,7 +247,7 @@ function onGotAcPanelVersInfo( responseData, errno )
247247
setPanelSetting( "acpanelVersion", acpanelVersion )
248248
setPanelSetting( "acpanelUrl", acpanelUrl )
249249
if acpanelVersion > _version then
250-
outputChatBox("New version of Anti-Cheat panel is available!")
250+
outputServerLog("New version of Anti-Cheat panel is available!")
251251
end
252252
end
253253
end

[admin]/security/NOTES.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*** DISCLAIMER ***
2+
3+
This resource is very barebone and should be used as a learning foundation for security on your server.
4+
It only covers the most basic server events for detecting abusive behaviour and logs them without taking any action.
5+
There are many more ways to combat bad players with server and client scripting adapted to your server/gamemode.
6+
7+
As a general rule of thumb, following points should be considered:
8+
- never trust the client, if you accept data from client, validate it on server if they make any sense
9+
- use the variable "client" instead of "source" for custom server events, source can be faked, client not
10+
- try to avoid elementdatas, if you need elementdata to be synced to client and they should remain read only on client,
11+
add them to tblProtectedElementDatas in players.lua to prevent clients from updating them

[admin]/security/events.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- https://wiki.multitheftauto.com/wiki/OnPlayerTriggerInvalidEvent
2+
-- gets triggered when a remote clients triggers an invalid event on server
3+
function clientTriggersInvalidEvent(strEventName, bIsAdded, bIsRemote)
4+
logViolation(source, "Triggered invalid event \""..strEventName.."\" - bIsAdded: "..tostring(bIsAdded).." - bIsRemote: "..tostring(bIsRemote));
5+
end
6+
addEventHandler("onPlayerTriggerInvalidEvent", root, clientTriggersInvalidEvent);
7+
8+
9+
10+
-- https://wiki.multitheftauto.com/wiki/OnPlayerTriggerEventThreshold
11+
-- gets triggered when a remote clients exceeds the event trigger treshold set by server in config -> max_player_triggered_events_per_interval
12+
function clientTriggersEventThreshold()
13+
logViolation(source, "Exceeded event trigger threshold of "..tostring(getServerConfigSetting("max_player_triggered_events_per_interval")));
14+
end
15+
addEventHandler("onPlayerTriggerEventThreshold", root, clientTriggersEventThreshold);

[admin]/security/logging.lua

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
-- log messages triggered by player
2+
function logViolation(uPlayer, strMessage)
3+
local strPlayerName, strPlayerIP, strPlayerSerial = getPlayerName(uPlayer), getPlayerIP(uPlayer), getPlayerSerial(uPlayer);
4+
local strLogFileName = "violations.txt";
5+
local uFileHandle = fileExists(strLogFileName) and fileOpen(strLogFileName);
6+
7+
if(not uFileHandle) then
8+
uFileHandle = fileCreate(strLogFileName);
9+
fileFlush(uFileHandle);
10+
else
11+
fileSetPos(uFileHandle, fileGetSize(uFileHandle));
12+
end
13+
14+
local strViolationMessage = getDateTime().." CLIENT: "..strPlayerName.." | IP: "..strPlayerIP.." | SERIAL: "..strPlayerSerial.." | "..strMessage;
15+
16+
outputDebugString(strViolationMessage, 4, 255, 255, 255);
17+
outputServerLog(strViolationMessage);
18+
fileWrite(uFileHandle, strViolationMessage.."\n");
19+
fileClose(uFileHandle);
20+
end
21+
22+
23+
24+
-- log messages without player element
25+
function logAction(strMessage)
26+
local strLogFileName = "actions.txt";
27+
local uFileHandle = fileExists(strLogFileName) and fileOpen(strLogFileName);
28+
29+
if(not uFileHandle) then
30+
uFileHandle = fileCreate(strLogFileName);
31+
fileFlush(uFileHandle);
32+
else
33+
fileSetPos(uFileHandle, fileGetSize(uFileHandle));
34+
end
35+
36+
local strActionMessage = getDateTime().." "..strMessage;
37+
38+
outputDebugString(strActionMessage, 4, 255, 255, 255);
39+
outputServerLog(strActionMessage);
40+
fileWrite(uFileHandle, strActionMessage.."\n");
41+
fileClose(uFileHandle);
42+
end
43+
44+
45+
46+
-- get the current date and time for logging
47+
function getDateTime()
48+
local tblRealTime = getRealTime();
49+
local iDay = tblRealTime.monthday;
50+
local iMonth = tblRealTime.month + 1;
51+
local iYear = tblRealTime.year + 1900;
52+
local iHour = tblRealTime.hour;
53+
local iMinute = tblRealTime.minute;
54+
local iSecond = tblRealTime.second;
55+
56+
if(iDay < 10) then iDay = "0"..iDay end;
57+
if(iMonth < 10) then iMonth = "0"..iMonth end;
58+
if(iHour < 10) then iHour = "0"..iHour end;
59+
if(iMinute < 10) then iMinute = "0"..iMinute end;
60+
if(iSecond < 10) then iSecond = "0"..iSecond end;
61+
62+
return "["..tostring(iDay).."."..tostring(iMonth).."."..tostring(iYear).." - "..tostring(iHour)..":"..tostring(iMinute)..":"..tostring(iSecond).."]";
63+
end

[admin]/security/meta.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<meta>
2+
<info name="Security" author="-ffs-PLASMA" type="misc" version="1.0" description="Basic security functionality" />
3+
4+
<min_mta_version server="1.6.0-9.22470" />
5+
6+
<script src="logging.lua" type="server"/>
7+
<script src="events.lua" type="server"/>
8+
<script src="misc.lua" type="server"/>
9+
<script src="players.lua" type="server"/>
10+
</meta>

[admin]/security/misc.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- https://wiki.multitheftauto.com/wiki/OnSettingChange
2+
-- gets triggered when a resource setting has been changed
3+
function resourceSettingChanged(strSetting, strOldValue, strNewValue)
4+
logAction("Setting \""..strSetting.."\" has been changed from \""..fromJSON(strOldValue).."\" to \""..fromJSON(strNewValue).."\"");
5+
end
6+
addEventHandler("onSettingChange", root, resourceSettingChanged);
7+
8+
9+
10+
-- https://wiki.multitheftauto.com/wiki/OnAccountDataChange
11+
-- gets triggered when account has been changed
12+
function accountDataChanged(uAccount, strKey, strValue)
13+
logAction("Data \""..strKey.."\" of account \""..getAccountName(uAccount).."\" has been changed to \""..strValue.."\"");
14+
end
15+
addEventHandler("onAccountDataChange", root, accountDataChanged);

[admin]/security/players.lua

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
-- add the elementdatas you want to protect from client updates in here
2+
local tblProtectedElementDatas = {["Score"] = true};
3+
4+
5+
6+
-- https://wiki.multitheftauto.com/wiki/OnElementDataChange
7+
-- gets triggered when a client tries to change a synced elementdata, check if client is permitted to change that specific data
8+
-- also prevents one client changing the elementdata of another client
9+
function clientChangesElementData(strKey, varOldValue, varNewValue)
10+
if(client and (tblProtectedElementDatas[strKey] or client ~= source)) then
11+
logViolation(client, "Tried to change elementdata \""..tostring(strKey).."\" of resource \""..tostring(sourceResource).."\" from \""..tostring(varOldValue).."\" to \""..tostring(varNewValue).."\"");
12+
setElementData(source, strKey, varOldValue);
13+
end
14+
end
15+
addEventHandler("onElementDataChange", root, clientChangesElementData);
16+
17+
18+
19+
-- https://wiki.multitheftauto.com/wiki/OnPlayerACInfo
20+
-- gets triggered when AC detects something for client on connect
21+
function clientNotifyACInfo(tblDetectedACList, iD3D9Size, strD3D9MD5, strD3D9SHA256)
22+
logViolation(source, "AC list detected: "..table.concat(tblDetectedACList, ",").." - D3D9Size: "..tostring(iD3D9Size).." - D3D9MD5: "..tostring(strD3D9MD5));
23+
end
24+
addEventHandler("onPlayerACInfo", root, clientNotifyACInfo);
25+
26+
27+
28+
-- https://wiki.multitheftauto.com/wiki/OnPlayerModInfo
29+
-- gets triggered when client joins server with modified game files
30+
function clientNotifyModInfo(strFileName, tblItemList)
31+
for _, strItemName in ipairs(tblItemList) do
32+
logViolation(source, "Mod detected - file: "..strFileName.." - GTA ID: "..strItemName.id.." - GTA name: "..strItemName.name);
33+
end
34+
end
35+
addEventHandler("onPlayerModInfo", root, clientNotifyModInfo);
36+
37+
38+
39+
-- force all connected players to send their AC/Mod info on resource start
40+
addEventHandler("onResourceStart", resourceRoot, function()
41+
for _, uPlayer in ipairs(getElementsByType("player")) do
42+
resendPlayerModInfo(uPlayer);
43+
resendPlayerACInfo(uPlayer);
44+
end
45+
end);
46+
47+
48+
49+
-- https://wiki.multitheftauto.com/wiki/OnPlayerNetworkStatus
50+
-- gets triggered when connection from server to a client is interrupted
51+
function clientNetworkStatus(iStatus, iTicks)
52+
if(iStatus == 0) then
53+
logViolation(source, "Network interruption has began after "..iTicks.." ticks");
54+
elseif(iStatus == 1) then
55+
logViolation(source, "Network interruption has stopped after "..iTicks.." ticks");
56+
end
57+
end
58+
addEventHandler("onPlayerNetworkStatus", root, clientNetworkStatus);

[editor]/edf/edf.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,11 @@ function edfCreateElement(elementType, creatorClient, fromResource, parametersTa
620620
elseif dataField == "rotation" then
621621
edfSetElementRotation(newElement, dataValue[1], dataValue[2], dataValue[3], dataValue[4])
622622
elseif dataField == "interior" then
623-
setElementInterior(newElement, dataValue)
623+
if dataValue == -1 then
624+
setElementInterior(newElement, 0) -- Interior -1 only works on removeWorldModel (But element data must be set to -1)
625+
else
626+
setElementInterior(newElement, dataValue)
627+
end
624628
setElementData(newElement, dataField, dataValue)
625629
elseif dataField == "dimension" then
626630
setElementDimension(newElement, dataValue)

[editor]/edf/interface.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
local interface_mt = {
22
__index = function(t, k)
3-
t[k] = function(...) return call(t.res, k, ...) end
3+
t[k] = function(...)
4+
if getUserdataType(t.res) ~= "resource-data" or getResourceState(t.res) ~= "running" then return end
5+
return call(t.res, k, ...)
6+
end
47
return t[k]
58
end
69
}

[editor]/edf/properties_client.lua

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ propertyGetters = {
2323
model = getElementModel,
2424
rotZ = getPedRotation,
2525
health = getElementHealth,
26-
armor = setPedArmor,
26+
armor = getPedArmor,
2727
collisions = function(element)
2828
local collisions = getElementData(element, "collisions")
2929
if collisions == "true" or collisions == false then
@@ -152,9 +152,6 @@ propertySetters = {
152152
end,
153153
breakable = function(element, breakable)
154154
return setObjectBreakable(element, breakable == "true")
155-
end,
156-
collisions = function(element, state)
157-
return setElementCollisionsEnabled(element, state == "true")
158155
end
159156
},
160157
ped = {

[editor]/editor/freeroam.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ addEventHandler("onResourceStart", resourceRoot,
33
if not getResourceFromName("freeroam") then
44
outputChatBox("WARNING: 'FREEROAM' RESOURCE NOT FOUND. Editor will not function properly. Please install the 'freeroam' resource immediately!", root, 255, 0, 0)
55
outputDebugString("WARNING: 'FREEROAM' RESOURCE NOT FOUND. Editor will not function properly. Please install the 'freeroam' resource immediately!")
6-
editor_gui.outputMessage("WARNING: 'FREEROAM' RESOURCE NOT FOUND. Editor will not function properly. Please install the 'freeroam' resource immediately!", root, 255, 0, 0)
76
end
87
end
98
)

[editor]/editor_gui/client/currentbrowser.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ end
431431
function closeCurrentBrowser()
432432
if ( not currentBrowser.showing ) then return end
433433
currentBrowser.showing = false
434+
cSelectedElement = false
434435
if ( callbackFunction ) then
435436
local id = currentBrowserGUI.gridlist:getSelectedText()
436437
if ( not id ) then

[editor]/editor_gui/client/elementproperties.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,8 @@ function openPropertiesBox( element, resourceName, shortcut )
814814
addEventHandler("onClientElementDataChange", selectedElement, checkForNewID)
815815

816816
addEDFPropertyControlsForElement( selectedElement )
817-
addPropertyControl("selection", "locked", "Locked", function (control) exports.editor_main:lockSelectedElement(selectedElement, control:getValue() == "true" or false) end, {value = exports.editor_main:isElementLocked(selectedElement) and "true" or "false", validvalues = {"false","true"}, datafield = "locked"})
817+
-- `locked` is reserved for vehicles
818+
addPropertyControl("selection", "locked-s", "Locked selection", function (control) exports.editor_main:lockSelectedElement(selectedElement, control:getValue() == "true" or false) end, {value = exports.editor_main:isElementLocked(selectedElement) and "true" or "false", validvalues = {"false","true"}, datafield = "locked"})
818819

819820
creatingNewElment = false
820821
syncPropertiesCallback = applyPropertiesChanges

[editor]/editor_gui/client/interface.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ local interface = {
1414

1515
local interface_mt = {
1616
__index = function(t, k)
17-
return function(...) return call(t.res, k, ...) end
17+
return function(...)
18+
if getUserdataType(t.res) ~= "resource-data" or getResourceState(t.res) ~= "running" then return end
19+
return call(t.res, k, ...)
20+
end
1821
end
1922
}
2023

[editor]/editor_gui/client/test.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function quickTest()
3232
if tutorialVars.blockQuickTest then return end
3333
if lastTestGamemode == "<None>" then lastTestGamemode = false end
3434
editor_main.dropElement()
35-
triggerServerEvent ( "testResource",localPlayer, text )
35+
triggerServerEvent ( "testResource",localPlayer, lastTestGamemode )
3636
unbindControl ( "toggle_test", "down", quickTest )
3737
if tutorialVars.test then tutorialNext() end
3838
end
@@ -142,7 +142,7 @@ function disableColPatchInTesting()
142142

143143
-- Disable
144144
guiCheckBoxSetSelected(dialog.enableColPatch.GUI.checkbox, false)
145-
confirmSettings()
145+
doActions()
146146
end
147147

148148
function enableColPatchAfterTesting()
@@ -251,3 +251,11 @@ end
251251
function noDamageInBasicTest()
252252
cancelEvent()
253253
end
254+
255+
addEventHandler ( "saveloadtest_return", root,
256+
function ( command )
257+
if command == "new" or command == "open" then
258+
lastTestGamemode = nil
259+
end
260+
end
261+
)

[editor]/editor_gui/server/interface.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local interface = {
77

88
local interface_mt = {
99
__index = function(t, k)
10+
if getUserdataType(t.res) ~= "resource-data" or getResourceState(t.res) ~= "running" then return end
1011
return function(...) return call(t.res, k, ...) end
1112
end
1213
}

0 commit comments

Comments
 (0)