Networking

Hooks

swatch_networking_playerauthenticated

Called after player spawned and responded to the sWatch authentication.

After this you can use sWatch.sendLua.

Arguments

  1. (Player) player

swatch_networking_concommand_run

Called whenever a command is executed on the server. This only works with commands added with concommand.Add.

Arguments

  1. (Player) ply - Can be eighter player or NULL for console.

  2. (String) command

  3. (Any) arguments

  4. (String) argumentString

Returns

  1. (Boolean) block - false to block the command from running

swatch_networking_runconsolecommand

Called when RunConsoleCommand is executed serverside.

Arguments

  1. (String) command

  2. (Vararg) arguments

Returns

  1. (Boolean) block - false to block the command from running

swatch_networking_post

Called when http.Post is called.

Arguments

  1. (String) domain

  2. (String) url

  3. (Any) parameters

Returns

  1. (Boolean) block - false to block request

swatch_networking_fetch
swatch_networking_incoming

Called before net.Receive. Used to block or log netmessages received by clients.

Arguments

  1. (Player) player

  2. (String) netmessageName

  3. (Number) length

Returns

  1. (Boolean) block - false to block message from being received in net.Receive

swatch_networking_incoming_post

Called after net.Receive has been executed. Used to log timing.

Arguments

  1. (Player) player

  2. (String) netmessageName

  3. (Number) deltaTime - time in ms it took to execute corresponding net.Recieve

Functions

sWatch.setQuarantine

All netmessages (except from sWatch) of a player in quarantine will get ignored.

Arguments

  1. (Player|SteamID32|SteamID64) player

  2. (Boolean) shouldQuarantine - false to remove from quarantine, true to quarantine

sWatch.isQuarantined

Returns if a player is quarantined.

Arguments

  1. (Player|SteamID32|SteamID64) player

Returns

  1. (Boolean) isQuarantined

sWatch.queryIPScore

Arguments

  1. (String) IP-Address

  2. (Player) player (optional)

  3. (Function) callback

Example

local ip = ply:IPAddress()
// Extract IP-Address (remove port and block local addresses)
ip = sWatch.extractIP(ip, true)
if not ip then return end
sWatch.queryIPScore(ip, ply, function(data)
    if not data or not data.success then return end
    // your code here
end)

You have to first specify an API-Key in the ingame settings. Read more about the callback return value in the official API-Documentation: https://www.ipqualityscore.com/documentation/proxy-detection/overview

sWatch.isPlayerAuthenticated

A player is marked authenticated as soon as we receive our first response netmessage. This may took some time and happens after the PlayerInitialSpawn hook is called.

This can be used together with sWatch.sendLua (see a example in section below).

Arguments

  1. (Player|SteamID|SteamID64) player

Returns

  1. (Boolean) isAuthenticated

sWatch.sendLua

This addon is fileless for the client. So no code is visible via a conventional filestealer. Every code gets send over netmessages and is then run via RunString on the client. If protected is set true, the code is compiled, compressed and encrypted to prevent manipulation and no RunString is used.

Arguments

  1. (Player|SteamID32|SteamID64) player

  2. (String) code

  3. (Boolean) protected (optional, default=false) - protection against code manipulation

  4. (Boolean) cache (optional, default=false) - only necessary if protected=true. Makes protection faster for large payloads.

Example

// we can only send Lua to authenticated players
if sWatch.isPlayerAuthenticated(ply) then
    sWatch.sendLua(ply, [[
        for i = 1, 10 do
            print(i)
        end
        // you can write arbitrary Lua code here
    ]])
end
// wait until the player has authenticated
hook.Add("swatch_networking_playerauthenticated", "my_hook", function(ply) 
    sWatch.sendLua(ply, [[
        // you can write arbitrary Lua code here
    ]])
end)
sWatch.takeScreenshot

This is usually called via admin menu. If you want to call it manually on the server, the screenshot will get saved in the data folder. See the ingame options under 'Networking' and 'Screenshot' for more details. Make sure to enable this feature in your settings.

Arguments

  1. (Player) player

  2. (Player) creator - nil if not called via admin menu)

sWatch.netmessage

This functions creates a netmessage. The real message name gets randomized.

We can restrict the netmessage to our groups ("staff", "protected). If we recieve a message by player that is not allowed to, the message will get blocked and he will get (depending on your settings) punished.

Only use this when necessary, as you have to send the ransomized message name to the client. It is idealy for admin menu and anticheat payload.

Arguments

  1. (String) messageName

  2. (String) restrictedTo - ("staff", "protected" or leave empty for no restrictions)

Returns

  1. (String) randomizedMessageName

Example

// create new netmessage as soon as the sWatch finish loading
hook.Add("swatch_init_loaded", "my_hook", function()
    net.Receive(sWatch.netmessage("anticheat_detection"), function(len, ply)
        print("received netmessage")
    end)
end)

// send client request to send this netmessage
hook.Add("swatch_networking_playerauthenticated", "my_hook", function(ply) 
    sWatch.sendLua(ply, string.format([[
       net.Start(%q)
       net.SendToServer()
    ]], sWatch.netmessage("my_new_netmessage")))
end)
// create a netmessage that only staff members are allowed to send
net.Receive(sWatch.netmessage("staff_only_message", "staff"), function() 
end)
// only by protected players
net.Receive(sWatch.netmessage("protected_only_message", "protected"), function() 
end)
// by everyone
net.Receive(sWatch.netmessage("message"), function() 
end)
sWatch.getNetmessage

Returns the original name of a netmessage

Arguments

  1. (String) randomizedMessage

Returns

  1. (String) originalMessageName (first argument of sWatch.netmessage)

sWatch.isInternalNetmessage

Returns true if the message was created with sWatch.netmessage.

Arguments

  1. (String) netmessageName - can be eighter randomized or internal name

Returns

  1. (Boolean) isInternal

sWatch.getPlayerNetmessages

Returns a table of all netmessages received by a specific player. All internal and randomized messages of this addon will get translated to their original name.

Arguments

  1. (Player|SteamID32|SteamID64) player

Returns

  1. (Table) messages

sWatch.isFakenet

If enabled in settings, we create fake backdoors and exploits to trick hackers/cheaters/scriptkids into using them.

Arguments

  1. (String) messagename

Returns

  1. (Boolean) isFakenet

hook.Add("swatch_networking_incoming", "my_hook", function(client, strName, len)
    local isFakeNet = sWatch.isFakenet(strName)
    if isFakeNet then
        print("Player used a fakenet")
        client:Kick()
    end
end)
sWatch.getExistingBackdoors

Returns a list of all real backdoors on your server. NOT FAKE BACKDOORS.

Returns

  1. (Table) backdoors

sWatch.getExistingExploits

Analogue to sWatch.getExistingBackdoors. Returns a list of all exploits on your server.

Returns

  1. (Table) exploits

sWatch.getPlayerCommands

Arguments

  1. (Player|SteamID32|SteamID64) player

Returns

  1. (Table) concommands

Last updated