forked from Didstopia/rust-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Various bug fixes, stability improvements and overall cleanup
- Loading branch information
Showing
15 changed files
with
652 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,63 @@ | ||
#!/usr/bin/env node | ||
|
||
var argumentString = ""; | ||
var args = process.argv.splice(process.execArgv.length + 2); | ||
for (var i = 0; i < args.length; i++) | ||
{ | ||
if (i == args.length - 1) argumentString += args[i]; | ||
else argumentString += args[i] + " " | ||
var argumentString = '' | ||
var args = process.argv.splice(process.execArgv.length + 2) | ||
for (var i = 0; i < args.length; i++) { | ||
if (i === args.length - 1) argumentString += args[i] | ||
else argumentString += args[i] + ' ' | ||
} | ||
|
||
if (argumentString.length < 1) | ||
{ | ||
console.log("Error: Please specify an RCON command"); | ||
process.exit(); | ||
if (argumentString.length < 1) { | ||
console.log('Error: Please specify an RCON command') | ||
process.exit() | ||
} | ||
|
||
//console.log("Relaying RCON command: " + argumentString); | ||
// console.log("Relaying RCON command: " + argumentString); | ||
|
||
var serverHostname = 'localhost'; | ||
var serverPort = process.env.RUST_RCON_PORT; | ||
var serverPassword = process.env.RUST_RCON_PASSWORD; | ||
var serverHostname = 'localhost' | ||
var serverPort = process.env.RUST_RCON_PORT | ||
var serverPassword = process.env.RUST_RCON_PASSWORD | ||
|
||
var messageSent = false; | ||
var WebSocket = require('ws'); | ||
var ws = new WebSocket("ws://" + serverHostname + ":" + serverPort + "/" + serverPassword); | ||
ws.on('open', function open() | ||
{ | ||
setTimeout(function() | ||
{ | ||
messageSent = true; | ||
ws.send(createPacket(argumentString)); | ||
setTimeout(function() | ||
{ | ||
ws.close(1000); | ||
setTimeout(function() | ||
{ | ||
//console.log("Command relayed"); | ||
process.exit(); | ||
}); | ||
}, 1000); | ||
}, 250); | ||
}); | ||
ws.on('message', function(data, flags) | ||
{ | ||
if (!messageSent) return; | ||
try | ||
{ | ||
var json = JSON.parse(data); | ||
if (json !== undefined) | ||
{ | ||
if (json.Message !== undefined && json.Message.length > 0) | ||
{ | ||
console.log(json.Message); | ||
} | ||
} | ||
else console.log("Error: Invalid JSON received"); | ||
} | ||
catch(e) | ||
{ | ||
if (e) console.log(e); | ||
} | ||
}); | ||
ws.on('error', function(e) | ||
{ | ||
console.log(e); | ||
process.exit(); | ||
}); | ||
var messageSent = false | ||
var WebSocket = require('ws') | ||
var ws = new WebSocket('ws://' + serverHostname + ':' + serverPort + '/' + serverPassword) | ||
ws.on('open', function open () { | ||
setTimeout(function () { | ||
messageSent = true | ||
ws.send(createPacket(argumentString)) | ||
setTimeout(function () { | ||
ws.close(1000) | ||
setTimeout(function () { | ||
// console.log("Command relayed"); | ||
process.exit() | ||
}) | ||
}, 1000) | ||
}, 250) | ||
}) | ||
ws.on('message', function (data, flags) { | ||
if (!messageSent) return | ||
try { | ||
var json = JSON.parse(data) | ||
if (json !== undefined) { | ||
if (json.Message !== undefined && json.Message.length > 0) { | ||
console.log(json.Message) | ||
} | ||
} else console.log('Error: Invalid JSON received') | ||
} catch (e) { | ||
if (e) console.log(e) | ||
} | ||
}) | ||
ws.on('error', function (e) { | ||
console.log(e) | ||
process.exit() | ||
}) | ||
|
||
function createPacket(command) | ||
{ | ||
var packet = | ||
{ | ||
Identifier: -1, | ||
Message: command, | ||
Name: "WebRcon" | ||
}; | ||
return JSON.stringify(packet); | ||
function createPacket (command) { | ||
var packet = | ||
{ | ||
Identifier: -1, | ||
Message: command, | ||
Name: 'WebRcon' | ||
} | ||
return JSON.stringify(packet) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,6 @@ | |
"author": "", | ||
"private": "true", | ||
"dependencies": { | ||
"ws": "^4.0.0" | ||
"ws": "^6.1.2" | ||
} | ||
} |
Oops, something went wrong.