SOCKETS

This module allows servers under the control of a proxy server to exchange information via sockets.

For the module to work, you need to install Skcrew on a proxy server ( Velocity or BungeeCord ).

Velocity is the recommended choice for a proxy server. BungeeCord is supported; however, Velocity is the preferred choice.

BungeeCord is supported but it is not recommended.

To configure the proxy server:

  • For Velocity , edit the velocity.toml file and specify the port for opening the server socket.
  • For BungeeCord , edit the config.yml file and specify the port for opening the server socket.

On the back-end server, specify the address of the proxy server and the port of the open server socket.

Configuration on a proxy server

socket-server-port: 1337

Configuration on a back-end server

sockets:
  enabled: false
  server-address: "127.0.0.1"
  server-port: 1337
  client-autoreconnect-time: 5

client-autoreconnect-time - describes the time after which the game server will try to reconnect if the proxy server is disabled.

EXPRESSIONS
CONDITIONS
EFFECTS
EVENTS
SIGNALS
WEB API

Subsections of Sockets

EXPRESSIONS

Get the current server

Returns the current (Back-end) server

(current|this) server

Get the server by name

Returns the server by its proxy configuration name.
Will return <none> if the server is not found.

server %string%

Get the name of a server

server[ ]name of %server%
%server%'s server[ ]name

Get a list of servers

The expression below returns a list of all servers defined in the proxy configuration.

[all] servers

Get a list of only online servers (Must be connected to the socket server)

[all] online servers

Get players from the server

Returns a list of players in the form of online players.

players (from|of|on) %servers%
%servers%'s players

Get a player on a proxy server

Accepts the player’s username or UUID, returns the online player, or <none> if the player is not online

network[ ]player %string%

The server player is automatically converted to OfflinePlayer if used in any expressions if necessary.

Get the player’s server

server of %networkplayer%
%networkplayer%'s server

Network Variable

Variable that is synchronized with all servers connected to the proxy. works as a regular variable in Skript

(network|proxy) variable %objects%

CONDITIONS

Check if a server is online

%servers% is (online|connected)
%servers% is(n't| not) (online|connected)

Check if a player is online

Allows you to change the player’s server if it is located on a server that is connected to a proxy server

%offlineplayers% is ([online ]on|connected to) proxy
%offlineplayers% (does|is)(n't| not) ([online ]on|connected to) proxy

EFFECTS

Kick a player from a proxy server

Allows you to specify the reason. The reason may be plain text, or an AdventureAPI component ( Velocity ) or ChatComponentAPI ( BungeeCord ) in JSON format.

kick %offlineplayers% from proxy [(with reason|by reason of|because [of]|on account of|due to) %string%]
kick %offlineplayers% from proxy with reason "Violation of rules"

Move the player to the server

Allows you to change the player’s server if it is located on a server that is connected to a proxy server

switch %offlineplayers% to %server%

EVENTS

Player has connected to the proxy server

Triggered when a player connects to the proxy but has not yet joined any server.

on player (join|connect)[(ed|s)] [to] proxy [server]

This event provides built-in data, allowing you to retrieve the connected player as an OfflinePlayer using event-player.

Player disconnects from the proxy server

on player (leave|disconnect)[(ed|s)] [from] proxy [server]

This event provides built-in data, allowing you to retrieve the connected player as an OfflinePlayer using event-player.

Current server connects to the proxy

Called after the server has been connected to the proxy.

on connect(ed|s) [to] proxy [server]
on proxy connect

Current server disconnects from the proxy

Called after the server has disconnected from the proxy.

on disconnect(ed|s) [from] proxy [server]
on proxy disconnect

Attempt to reconnect to the proxy

Called when the server attempts to reconnect to the proxy.

on reconnect(ing|s) [to] proxy [server]
on proxy reconnect

The server has connected to the proxy

Called after any server has connected to the proxy

on server connect(ed|s) [to] proxy [server]

The event has built-in data, using the event-server you can get a connected server

The server was disconnected from the proxy

Called after any server has disconnected from the proxy

on server disconnect(ed|s) [from] proxy [server]

The event has embedded data, using the event-server you can get a disconnected server

The player has connected to the back-end server

It is called after the player is connected to the back-end server, which is connected to the proxy.

on player (join|connect)[(ed|s)] [to] (proxied|network) server

The expression below allows you to track connections only to a specific server by its name.

on player (join|connect)[(ed|s)] [to] (proxied|network) server %string%

The event contains embedded data, such as event-server, which allows you to get the server the player is connected to, and event-player, which allows you to get the player in the form of an OfflinePlayer.

The player disconnected from the back-end server

It is called after the player disconnects from the back-end server that is connected to the proxy.

on player (leave|disconnect[e])[(d|s)] [from] (proxied|network) server

The expression below allows you to track disconnections only from a specific server by its name.

on player (leave|disconnect[e])[(d|s)] [from] (proxied|network) server %string%

The event has built-in data, using the event-server you can get the server of the player from which they left, and using the event-player you can get the player in the form of an OfflinePlayer

SIGNALS

Signals allow you to transfer information across servers.
Signals are better known as Plugin Messages.

Create a signal

A signal is formatted as key : values, which allows you to transfer any data that can be serialized.

signal [(with key|keyed)|(with name|named)] %string% (and|with) [data] %objects%
set {_signal} to signal named "broadcast" with data "Hello world!","Second data value!" and "Hey, look at me! I'm the third value!"

Get a signal’s key.

(key|signal name) of %signal%
%signal%'s (signal name|key)

Get a signal’s data

Returns a list of objects

data of %signal%
%signal%'s data

Send a signal

Allows you to send a signal to any connected server

Note: Only servers that are online will be able to receive the signal.

send signal %signals% to %servers%
set {_signal} to signal named "broadcast" with data "Hello world!","Ooo, spooky!", "Dark magic!"
send signal {_signal} to all servers

Listen for a signal event

It also allows you to track signals by key.

signal [(with key|keyed) %string%]

The event has built-in data, using the event-signal you can receive the incoming signal.

on join:
  set {_signal} to signal named "broadcast" with data "Welcome back %player%"
  send signal {_signal} to all servers

on signal with key "broadcast":
  broadcast (data of event-signal)

WEB API

Web API allows you to get information from servers, as well as send signals from outside.
Make sure that the web server is enabled in the Skcrew settings of your proxy server (see sockets setup ).

web-server-enabled: true
web-server-port: 1338
web-server-user: admin
web-server-password: admin

Here you can also configure the web server port and its authorization data to access the API.
Authorization is performed by passing the username and password to base64 in the request header.

Create a base64 authentication string by visiting base64encode.org and encoding the following format in the encoding field:

username:password

This format will help you generate a properly formatted base64 string.

Now, you can use the following header (replace YOUR-BASE64-AUTHENTICATION-STRING with the base64 authentication string):

Authorization: Basic YOUR-BASE64-AUTHENTICATION-STRING

Examples

In the following examples, we used “admin:admin” as the base64 authentication string.
Eg. the username is “admin” and the password is “admin”.

Available routes for requests.

GET    /players

Allows you to get a list of all players and the name of the server they are on.
Possible parameters:

  • server:string - allows you to get players from a specific server
curl localhost:1338/players -H "Authorization: Basic YWRtaW46YWRtaW4="
{
  "data": [
    {
      "name": "Lotzy",
      "uuid": "a0970e26-b9f4-3f73-bd06-ede16c390d34",
      "join_date": 1706008310,
      "time_played": 1089,
      "server_name": "lobby"
    }
  ]
}

GET    /players/{UUID/USERNAME}

Allows you to get a player, if they are online, by their username or UUID. As well as the server on which they are located.

curl localhost:1338/players/Lotzy -H "Authorization: Basic YWRtaW46YWRtaW4="
{
  "data": {
    "name": "Lotzy",
    "uuid": "a0970e26-b9f4-3f73-bd06-ede16c390d34",
    "join_date": 1706008310,
    "time_played": 2335,
    "server_name": "lobby",
    "server": {
      "name": "lobby",
      "address": "127.0.0.1",
      "port": 25565,
      "hostname": "127.0.0.1",
      "online": true,
      "connection_date": 1706008017,
      "uptime": 2628,
      "players_count": 1,
      "players": [
        {
          "name": "Lotzy",
          "uuid": "a0970e26-b9f4-3f73-bd06-ede16c390d34",
          "join_date": 1706008310,
          "time_played": 2335,
          "server_name": "lobby"
        }
      ]
    }
  }
}

GET  POST    /players/{UUID/USERNAME}/kick

Allows you to kick a player from a proxy server, by their username or UUID.
When using a POST request, you can specify the reason for the kick. The reason can be specified either in plain text, an AdventureAPI component ( Velocity ) or in ChatComponentAPI ( BungeeCord ) in JSON format.

curl localhost:1338/players/Lotzy/kick -X POST -H "Authorization: Basic YWRtaW46YWRtaW4=" -H "Content-Type: application/json" -d '"GET OUT!"'
{
  "data": "Player Lotzy kicked"
}

GET    /players/{UUID/USERNAME}/connect/{SERVER}

Allows you to move a player to another server, by their username or UUID.\

curl localhost:1338/players/Lotzy/connect/lobby -H "Authorization: Basic YWRtaW46YWRtaW4="
{
  "data": "Player Lotzy connected to server lobby"
}

GET    /servers

Get a list of all servers and players on them.
Possible parameters:

  • online:boolean - allows you to get only those servers that are online
curl localhost:1338/servers?online=true -H "Authorization: Basic YWRtaW46YWRtaW4="
{
  "data": [
    {
      "name": "lobby",
      "address": "127.0.0.1",
      "port": 25565,
      "hostname": "127.0.0.1",
      "online": true,
      "connection_date": 1706008017,
      "uptime": 2132,
      "players_count": 1,
      "players": [
        {
          "name": "Lotzy",
          "uuid": "a0970e26-b9f4-3f73-bd06-ede16c390d34",
          "join_date": 1706008310,
          "time_played": 1839,
          "server_name": "lobby"
        }
      ]
    }
  ]
}

POST    /servers/{SERVER}/signal

Allows you to send a signal to the connected server.
The signal itself is transmitted in the request body.

curl localhost:1338/servers/lobby/signal -X POST -H "Authorization: Basic YWRtaW46YWRtaW4=" -H "Content-Type: application/json" -d "{'signals':[{'key':'broadcast','data':['Hello world!']}]}"
{
  "data": {
    "response": "Signals successfully sended to servers"
  }
}

POST    /signal

Allows you to send a signal to the connected servers.
The signal itself and the list of servers are transmitted in the request body.

curl localhost:1338/servers/lobby/signal -X POST -H "Authorization: Basic YWRtaW46YWRtaW4=" -H "Content-Type: application/json" -d "{'servers':['lobby'],'signals':[{'key':'broadcast','data':['Hello world!']}]}"
{
  "data": {
    "response": "Signals successfully sended to servers"
  }
}

You can see an example of implementing API access in Python at this link