OutputServerLog: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Reverted edits by Diki (talk) to last revision by AlexTMjugador)
m (Undo revision 80371 by FileEX (talk))
Tag: Undo
 
(8 intermediate revisions by 5 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 ( "onClientLogin", getRootElement(), logClientLogin )
addEventHandler ( "onPlayerLogin", root, logClientLogin )
</syntaxhighlight>
</syntaxhighlight>


Line 27: Line 27:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function outputPosition(source)
function outputPosition(source)
local x,y,z = getElementPosition(source)
  outputServerLog( table.concat({getElementPosition(source)}, ", ") )
outputServerLog(tostring(x) .. "," .. tostring(y) .. "," .. tostring(z))
end
end
addCommandHandler("op",outputPosition)
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>
</section>

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 [-]
Server

Example 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