OutputServerLog: Difference between revisions
Jump to navigation
Jump to search
Dutchman101 (talk | contribs) (Added code example) |
Tag: Undo |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 21: | Line 21: | ||
outputServerLog ( "Client " .. getPlayerName ( source ) .. " logged in as " .. getAccountName ( current_account ) ) | outputServerLog ( "Client " .. getPlayerName ( source ) .. " logged in as " .. getAccountName ( current_account ) ) | ||
end | end | ||
addEventHandler ( "onPlayerLogin", | addEventHandler ( "onPlayerLogin", root, logClientLogin ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
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