OutputServerLog: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
Tag: Undo |
||
(17 intermediate revisions by 14 users not shown) | |||
Line 1: | Line 1: | ||
{{Server function}} | |||
__NOTOC__ | |||
__NOTOC__ | This outputs a line of text to the server's log. This could be useful for debugging. | ||
This | |||
==Syntax== | ==Syntax== | ||
Line 10: | Line 9: | ||
===Required Arguments=== | ===Required Arguments=== | ||
*''' | *'''text:''' The text to be output to the log. | ||
===Returns=== | ===Returns=== | ||
Returns ''true'' if | Returns ''true'' if successful, ''false'' otherwise. | ||
==Example== | ==Example== | ||
This example | <section name="Server" class="server" show="true"> | ||
'''Example 1:''' This example outputs client logins to the server log. | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function logClientLogin ( previous_account, current_account ) | |||
outputServerLog ( "Client " .. getPlayerName ( source ) .. " logged in as " .. getAccountName ( current_account ) ) | |||
end | |||
addEventHandler ( "onPlayerLogin", root, logClientLogin ) | |||
</syntaxhighlight> | |||
'''Example 2:''' This example outputs the clients position to the server | |||
<syntaxhighlight lang="lua"> | |||
function outputPosition(source) | |||
outputServerLog( table.concat({getElementPosition(source)}, ", ") ) | |||
end | |||
addCommandHandler("op", outputPosition) | |||
</syntaxhighlight> | |||
'''Example 3:''' This is an debugging example, to identify which resource/source is responsible for vehicles that get spawned/exist but aren't supposed to be (like forbidden, where they can still spawn it through creation vulnerability, or identify which resource is hooked into (that has spawnvehicle server event) by a LUA code injector/hacked client so you know which resource/calls you have to secure | |||
<syntaxhighlight lang="lua"> | |||
local triggeredByModels = { [432]=true } | |||
function detectVehicleCreation() | |||
if getElementType(source) == "vehicle" and triggeredByModels[getElementModel(source)] then | |||
outputServerLog ("** ILLEGAL VEHICLE DETECTED ** "..getVehicleName(source).." was found at "..toJSON({getElementPosition(source)}).. " dim: "..getElementDimension(source).. " & int: "..getElementInterior(source)) | |||
local x,y,z = getElementPosition(source) | |||
local sphere = createColSphere(x,y,z,40) | |||
setElementInterior(sphere, getElementInterior(source)) | |||
setElementDimension(sphere, getElementDimension(source)) | |||
attachElements(sphere, source) | |||
local players = {} | |||
local pc = getElementsWithinColShape(sphere, "player") | |||
for _,p in pairs (pc) do | |||
if p then | |||
table.insert (players, getPlayerName(p)) | |||
end | |||
end | |||
if players and #players ~= 0 then | |||
outputServerLog ("** Nearby players: (possibly driver/spawner) "..toJSON(players)) | |||
end | |||
outputServerLog ("** Responsible resource: "..tostring(getElementID(getElementParent(getElementParent(source))))) | |||
destroyElement(sphere) | |||
end | |||
end | |||
addEventHandler ("onElementStartSync", root, detectVehicleCreation) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | |||
==See Also== | ==See Also== | ||
{{ | {{Server functions}} |
Latest revision as of 22:35, 6 September 2024
This outputs a line of text to the server's log. This could be useful for debugging.
Syntax
bool outputServerLog ( string text )
Required Arguments
- text: The text to be output to the log.
Returns
Returns true if successful, false otherwise.
Example
Click to collapse [-]
ServerExample 1: This example outputs client logins to the server log.
function logClientLogin ( previous_account, current_account ) outputServerLog ( "Client " .. getPlayerName ( source ) .. " logged in as " .. getAccountName ( current_account ) ) end addEventHandler ( "onPlayerLogin", root, logClientLogin )
Example 2: This example outputs the clients position to the server
function outputPosition(source) outputServerLog( table.concat({getElementPosition(source)}, ", ") ) end addCommandHandler("op", outputPosition)
Example 3: This is an debugging example, to identify which resource/source is responsible for vehicles that get spawned/exist but aren't supposed to be (like forbidden, where they can still spawn it through creation vulnerability, or identify which resource is hooked into (that has spawnvehicle server event) by a LUA code injector/hacked client so you know which resource/calls you have to secure
local triggeredByModels = { [432]=true } function detectVehicleCreation() if getElementType(source) == "vehicle" and triggeredByModels[getElementModel(source)] then outputServerLog ("** ILLEGAL VEHICLE DETECTED ** "..getVehicleName(source).." was found at "..toJSON({getElementPosition(source)}).. " dim: "..getElementDimension(source).. " & int: "..getElementInterior(source)) local x,y,z = getElementPosition(source) local sphere = createColSphere(x,y,z,40) setElementInterior(sphere, getElementInterior(source)) setElementDimension(sphere, getElementDimension(source)) attachElements(sphere, source) local players = {} local pc = getElementsWithinColShape(sphere, "player") for _,p in pairs (pc) do if p then table.insert (players, getPlayerName(p)) end end if players and #players ~= 0 then outputServerLog ("** Nearby players: (possibly driver/spawner) "..toJSON(players)) end outputServerLog ("** Responsible resource: "..tostring(getElementID(getElementParent(getElementParent(source))))) destroyElement(sphere) end end addEventHandler ("onElementStartSync", root, detectVehicleCreation)
See Also
- getMaxPlayers
- getServerConfigSetting
- getServerHttpPort
- getServerName
- getServerPassword
- getServerPort
- isGlitchEnabled
- setGlitchEnabled
- setMaxPlayers
- setServerConfigSetting
- setServerPassword
- shutdown