Skip to content

Commit

Permalink
Merge pull request #126 from Itokoyamato/improv-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Thuillier authored Jul 6, 2020
2 parents dbb4555 + 5d8102e commit e8b3823
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 107 deletions.
72 changes: 42 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ You can support my work:
- [Table of Contents](#table-of-contents)
- [Setting up TokoVOIP](#setting-up-tokovoip)
- [(players) Setting up the ts3-plugin](#players-setting-up-the-ts3-plugin)
- [(servers) Setting up the ws-server](#servers-setting-up-the-ws-server)
- [(servers) Setting up the fivem-script](#servers-setting-up-the-fivem-script)
- [(servers) Setting up the ws-server and fivem-script](#servers-setting-up-the-ws-server-and-fivem-script)
- [Step 1: Setting up the ws-server](#step-1-setting-up-the-ws-server)
- [Step 2: Setting up the fivem-script](#step-2-setting-up-the-fivem-script)
- [(servers) Setting up ws-server as Standalone](#servers-setting-up-ws-server-as-standalone)
- [(servers) Onesync Infinity](#servers-onesync-infinity)
- [How does it work ?](#how-does-it-work-)
- [Why do I need a ws-server ?](#why-do-i-need-a-ws-server-)
Expand All @@ -31,43 +33,53 @@ You can support my work:
- [Dependencies and sources](#dependencies-and-sources)

# Setting up TokoVOIP
You can download the ws-server, fivem-script & ts3-plugin on the [release](https://github.com/Itokoyamato/TokoVOIP_TS3/releases) page
You can download the ws-server, fivem-script & ts3-plugin on the [release](https://github.com/Itokoyamato/TokoVOIP_TS3/releases) page

## (players) Setting up the ts3-plugin
Every player must install Teamspeak 3 and the TokoVOIP plugin
* Install the plugin downloaded on the [release](https://github.com/Itokoyamato/TokoVOIP_TS3/releases) page
Every player must install Teamspeak 3 and the TokoVOIP plugin
* Install the plugin downloaded on the [release](https://github.com/Itokoyamato/TokoVOIP_TS3/releases) page
* Connect to the fivem server
* Connect to the TS3 server
* Join the right TS3 channel

The TS3 Plugin will connect only if you are already in-game
The TS3 Plugin will try to connect if you join a TS3 channel containing 'tokovoip' in it's name
You can use the buttons in `Plugins->TokoVoip` to manually connect/disconnect the TS3 Plugin
## (servers) Setting up the ws-server
* **Configure the server**
Edit [config.js](https://github.com/Itokoyamato/TokoVOIP_TS3/blob/master/ws_server/config.js) to match your configuration. Fill the IPs using your host's public IP.
Note: **TSServer** must be an **IP**, domain names are currently not supported. Please open an issue if that's something you would like to see available

* **Run the server**
* **Running as Standalone**
It can be run as a standalone NodeJS application, on the same machine as your fivem server, or on a completely different machine
* Download [Node.js](https://nodejs.org/en/)
* Open ws-server folder in cmd / terminal
* Execute `npm i`
* After its done run `node index.js`
I recommend using pm2 module to run the ws-server in the background
* **Running as FXServer resource**
The ws-server is compatible and can be run as a FXServer resource directly
Just start it the same way you'd start any other resource

**Running it as a standalone is recommended to decouple the potential performance issues from your FiveM server, even if it's on the same machine**

## (servers) Setting up the fivem-script
* **Configure the script**
Edit [c_config.lua](https://github.com/Itokoyamato/TokoVOIP_TS3/blob/feat-websocket-proxy/fivem_script/tokovoip_script/c_config.lua) & [s_config.lua](https://github.com/Itokoyamato/TokoVOIP_TS3/blob/feat-websocket-proxy/fivem_script/tokovoip_script/s_config.lua) to match your preference
**You must configure the [wsServer](https://github.com/Itokoyamato/TokoVOIP_TS3/blob/feat-websocket-proxy/fivem_script/tokovoip_script/c_config.lua#L20) to match the IP:PORT address of your ws-server**

A documentation for the FiveM script is available [here](fivem_script)

## (servers) Setting up the ws-server and fivem-script

### Step 1: Setting up the ws-server
* Download ws-server from the [release](https://github.com/Itokoyamato/TokoVOIP_TS3/releases) page
* Extract it in your fivem resources folder
* Open [ws_server/config.js](https://github.com/Itokoyamato/TokoVOIP_TS3/blob/master/ws_server/config.js)
* Change "`TSServer`" to your Teamspeak server IPv4
Note: domain names are currently not supported. Please open an issue if that's something you would like to see available
* start `ws_server` in your fivem server console
* Copy the `IP:PORT` in the console after `Listening on` and save it for [**Step 2: Setting up the fivem-script**](#step-2-setting-up-the-fivem-script)

### Step 2: Setting up the fivem-script
* Download tokovoip_script from the [release](https://github.com/Itokoyamato/TokoVOIP_TS3/releases) page
* Extract it in your fivem resources folder
* Open [tokovoip_script/c_config.lua](https://github.com/Itokoyamato/TokoVOIP_TS3/blob/master/fivem_script/tokovoip_script/c_config.lua)
* Edit `wsServer` with the `IP:PORT` you copied from the ws-server console in [**Step 1: Setting up the ws-server**](#step-1-setting-up-the-ws-server)
* Edit the `TSChannel` to match your Teamspeak configuration
* Edit other settings to your preferences
* Open and edit [s_config.lua](https://github.com/Itokoyamato/TokoVOIP_TS3/blob/master/fivem_script/tokovoip_script/s_config.lua) to your preference

A documentation for the FiveM script is available [here](fivem_script)

## (servers) Setting up ws-server as Standalone
It can be run as a standalone NodeJS application, on the same machine as your fivem server, or on a completely different machine
* Download [Node.js](https://nodejs.org/en/)
* Open [config.js](https://github.com/Itokoyamato/TokoVOIP_TS3/blob/master/ws_server/config.js)
* Change "`TSServer`" to your Teamspeak server `IPv4`
* Change "`FivemServerPort`" to your FiveM server `port`
* If the ws-server is hosted on a separate machine:
Change "`FivemServerIP`" to your FiveM server `IPv4`
* Open ws-server folder in cmd / terminal
* Execute `npm i`
* After its done run `node index.js`
A module such as `pm2` can be used to run the ws-server in the background

## (servers) Onesync Infinity
Onesync infinity is supported with TokoVOIP 1.5.0+
Expand Down
2 changes: 1 addition & 1 deletion fivem_script/tokovoip_script/src/c_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ local function clientProcessing()
end


if (remotePlayerChannel <= voip.config.radioClickMaxChannel) then
if (type(remotePlayerChannel) == "number" and remotePlayerChannel <= voip.config.radioClickMaxChannel) then
founduserData.radioEffect = true;
end

Expand Down
22 changes: 17 additions & 5 deletions ws_server/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
module.exports = {
TSServer: "127.0.0.1", // IP Address of your teamspeak 3 server
WSServerIP: "127.0.0.1", // IP Address of the ws-server is running on
WSServerPort: 3000, // Websocket port, default: 3000
FivemServerIP: "127.0.0.1", // IP Adress of your FiveM server
FivemServerPort: 32000, // Port of your FiveM Server
//-- [REQUIRED] IPv4 Address of your teamspeak 3 server
TSServer: "127.0.0.1",

//-- [REQUIRED] Port of the ws_server
WSServerPort: 3000,

//-- [OPTIONAL] IPv4 Address of the ws_server
//-- Set by autoconfig
// WSServerIP: "127.0.0.1",

//-- [OPTIONAL] IPv4 Adress of your FiveM server
//-- Set by autoconfig if you run ws_server as FXServer resource or standalone on the same machine
// FivemServerIP: "127.0.0.1",

//-- [OPTIONAL] Port of your FiveM Server
//-- Set by autoconfig if you run ws_server as FXServer resource
// FivemServerPort: 32000,
};
112 changes: 80 additions & 32 deletions ws_server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ const http = require('http').createServer(app);
const io = require('socket.io')(http);
const axios = require('axios');
const lodash = require('lodash');
require('console-stamp')(console, { pattern: 'dd/mm/yyyy HH:MM:ss.l' });
const chalk = require('chalk');
const config = require('./config.js');
const publicIp = require('public-ip');

let hostIP;
let runningOnFivem = false;

try {
eval('GetResourcePath(GetCurrentResourceName())');
runningOnFivem = true;
} catch(e) {}

require('console-stamp')(console, { pattern: 'dd/mm/yyyy HH:MM:ss.l' });

let masterHeartbeatInterval;
const clients = {};
Expand All @@ -20,54 +30,92 @@ console.log(chalk`Like {cyan TokoVOIP} ? Consider supporting the development: {h
app.use(express.json());

(async _ => {
let configError = false;
// Configuration checks
const IPv4Regex = new RegExp('^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$');
if (!IPv4Regex.test(config.TSServer)) {
configError = true;
hostIP = await publicIp.v4();
if (config.WSServerIP === undefined) {
config.WSServerIP = hostIP;
console.log(chalk`{yellow AUTOCONFIG:} Setting {cyan WSServerIP} to {cyan ${hostIP}} (you can manually edit in config.js)`);
await sleep(0);
}
if (config.FivemServerIP === undefined) {
config.FivemServerIP = hostIP;
console.log(chalk`{yellow AUTOCONFIG:} Setting {cyan FivemServerIP} to {cyan ${hostIP}} (you can manually edit in config.js)`);
await sleep(0);
}
if (config.FivemServerPort === undefined && runningOnFivem) {
config.FivemServerPort = GetConvar('netPort');
console.log(chalk`{yellow AUTOCONFIG:} Setting {cyan FivemServerPort} to {cyan ${config.FivemServerPort}} (you can manually edit in config.js)`);
await sleep(0);
}

if (!config.TSServer || !config.WSServerIP || !config.WSServerPort || !config.FivemServerIP || !config.FivemServerPort) {
console.error(chalk`{red Config error:
Missing one of TSServer, WSServerIP, WSServerPort, FivemServerIP or FivemServerPort}`
);
return;
}

// Boot
http.listen(config.WSServerPort, async _ => {
console.log('Checking configuration ...');
let configError = false;
const IPv4Regex = new RegExp('^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$');
if (!IPv4Regex.test(config.TSServer)) {
configError = true;
console.error(chalk`{red Config error:
TSServer is invalid.
It must be an IPv4 address.
Domain names are not supported.}`
);
}
);
} else {
await new Promise((resolve, reject) => {
net.createConnection(10011, config.TSServer).on('connect', resolve).on('error', reject);
})
.catch(e => {
console.warn(chalk`{yellow Failed to reach TeamSpeak server at ${config.TSServer}:10011.
Please check your configuration.
It could be using a different ServerQuery port, in which case you can ignore this warning.}`
);
});
}

const FiveMURI = `http://${config.FivemServerIP}:${config.FivemServerPort}/info.json`;
await axios.get(FiveMURI)
.catch(e => {
configError = true
console.error(chalk`{red Config error:
Could not check FiveM server.
const FiveMURI = `http://${config.FivemServerIP}:${config.FivemServerPort}/info.json`;
await axios.get(FiveMURI)
.catch(e => {
configError = true
console.error(chalk`{red Config error:
FiveM server does not seem online.
Is it accessible from the internet ?
Make sure your configuration is correct and your ports are open.}
{cyan (${FiveMURI})}`
);
});
const wsURI = `http://${config.WSServerIP}:${config.WSServerPort}`
await axios.get(wsURI)
.catch(e => {
configError = true;
console.error(chalk`{red Config error:
Could not check WS server.
);
});
const wsURI = `http://${config.WSServerIP}:${config.WSServerPort}`
await axios.get(wsURI)
.catch(e => {
configError = true;
console.error(chalk`{red Config error:
Could not access WS server.
Is it accessible from the internet ?
Make sure your configuration is correct and your ports are open.}
{cyan (${wsURI})}`
);
});
);
});

if (config.FivemServerIP.includes('127.0.0.1') || config.FivemServerIP.includes('localhost')) {
configError = true;
console.error(chalk`{red Config error:
if (config.FivemServerIP.includes('127.0.0.1') || config.FivemServerIP.includes('localhost')) {
configError = true;
console.error(chalk`{red Config error:
FiveMServerIP cannot be 127.0.0.1 or localhost.
It will be blocked by FiveM.
It has to be a valid public IPv4.
You might need to open your ports to run it locally.}`);
}
if (configError) process.exit();
}
if (configError) return;

console.log(chalk`Everything looks {green good} ! Have fun`);
await sleep(0);

console.log(chalk`Listening on "{cyan ${config.WSServerIP}:${config.WSServerPort}}" (copy and paste this address as "wsServer" in tokovoip_script/c_config.lua)`);

// Boot
http.listen(config.WSServerPort, async _ => {
console.log(`Listening on *:${config.WSServerPort}`);
masterHeartbeat();
masterHeartbeatInterval = setInterval(masterHeartbeat, 300000);
});
Expand Down
Loading

0 comments on commit e8b3823

Please sign in to comment.