Allows you to connect multiple FXServer instances together and send data between all the servers at once
This resource does not do anything by default.
I've included a simple example script below.
When sending data, you might want to include a unique identifier per FXServer, this resource does not provide such.
Install as you would any other resource.
Upon starting for the first time, some packages will be downloaded by the FXServer package manager (yarn or webpack).
If it fails to download the packages, check the Yarn or NPM documentation on how to install the packages manually.
The structure expected by this system is one host server and as many client servers as you want.
Each client FXServer connects to the set host FXServer.
The resource utilizes some console variables to control how to do things.
Defaults to false
, set to true
to mark this FXServer as a host.
Defaults to 30220
, this is the port used by the sockets that send and receive the data.
Defaults to nothing (empty string), this is the authentication token used by both client and host. Note: If no token is set, the rcon_password
value is used instead. If rcon_password
is also not set, the host will allow all connections.
Defaults to http://localhost
, if the FXServer is not set as a host, it will try to connect to this endpoint
You might want to include the port in here aswell.
The xchat_token
value must match on the host and clients. The rcon_password
value is used if no token is set. No rcon_password
allows all connections regardless of token.
You have two FXServers, one hosted on 420.69.621.0:30120
and one on 926.42.007.0:30120
.
Set the xchat_token
value for both FXServers to any password you want, just make sure they're both the same!
In the config for 420.69.621.0:30120
, you set the FXServer as a host (xchat_server
to true
) and the port (xchat_server_port
) to 30220
In the config for 926.42.007.0:30120
, you set the endpoint (xchat_endpoint
) to 420.69.621.0:30220
(using the host port)
Starting the servers should successfully connect them together, and data can be shared between the two.
Any additional clients would simply require the same settings as 926.42.007.0:30120
, essentially making clients identical to configure.
There are only two events used by this system, one incoming and one outgoing.
Both are server side.
Sends the data to all connected FXServers (except the one sending it)
Data can be any type and anything.
Callback function's ok value determines if the FXServer could send the data.
ok: false
means the client is not connected to the host
ok: true
means the data was sent
Example:
TriggerEvent('xchat:sendData', 'Hello World', function(ok)
if ok then print('xchat:', 'message was sent') else print('xchat:', 'failed to send') end
end)
Triggered upon receiving data
Example:
AddEventHandler('xchat:receivedData', function(data)
print('xchat:', data)
end)
A simple script that relays chat messages between servers (server side)
AddEventHandler('chatMessage', function(username, color, message)
TriggerEvent('xchat:sendData', {event = 'chatMessage', username = username, color = color, message = message})
end)
AddEventHandler('xchat:receivedData', function(data)
if data.event == 'chatMessage' then
TriggerClientEvent('chatMessage', -1, data.username, data.color, data.message)
end
end)
Any chat message sent should also appear on the other servers in the network
Script by @glitchdetector