Skip to content

Instantly share code, notes, and snippets.

@rjindael
Created August 10, 2021 18:15
Show Gist options
  • Save rjindael/e8de5232e1023de82cc4bdd04abb69d0 to your computer and use it in GitHub Desktop.
Save rjindael/e8de5232e1023de82cc4bdd04abb69d0 to your computer and use it in GitHub Desktop.
const rcctalk = require("rcctalk")
const path = require("path")
const uuid = require("uuid")
// If you omit the WSDL, then rcctalk will assume that the RCCService instance is a RCCService from 2018 or higher that does not use SOAP and instead uses the newer JSON format.
var client = rcctalk.connect({ ip: "127.0.0.1", port: 64989, wsdl: path.join(__dirname, "RCCServiceSoap.wsdl") })
/* HelloWorld */
if (await client.hello() != "Hello World") {
throw `Malformed client response when sending hello world request`
}
/* GetVersion */
// Version is fetched once after a successful connection to RCCService has been made
// It is then stored as a static variable named "version" within the Client object and its contents follows the Roblox version format
console.log(client.version) // "0.xxx.x.xxxxxx"
/* GetStatus */
console.log(await client.status()) // { version: "0.xxx.x.xxxxxx", environmentCount: int }
/* Jobs */
// No jobs have been created yet
console.log(await client.jobs.all()) // []
let jobId = uuid.v4() // randomly generated job ID
client.jobs.open(jobId, (60 * 60 * 8), 0, 2, "game.Players.MaxPlayers = 50")
console.log(await client.jobs.all()) // [ { id: jobId, expirationInSeconds: 28800, category: 0, cores: 2 } ]
// Open multiple jobs at once:
let jobId2 = uuid.v4()
let jobId3 = uuid.v4()
await client.jobs.open([
{ id: jobId2, expirationInSeconds: (60 * 60 * 8), category: 1, cores: 2 },
{ id: jobId3, expirationInSeconds: (60 * 60 * 8), category: 1, cores: 2 },
])
console.log(await client.jobs.all()) // [ { id: jobId, expirationInSeconds: 28800, category: 0, cores: 2 }, { id: jobId2, expirationInSeconds: 28800, category: 1, cores: 2 }, { id: jobId3, expirationInSeconds: 28800, category: 1, cores: 2 } ]
// All methods pertaining to job manipulation may only be identified by its job ID. You may not pass its index from the "all" array, or pass in its parameters.
// Closing a job:
await client.jobs.close(jobId2)
// Updating a jobs lease (expiration in seconds):
await client.jobs.setExpiration(jobId, (60 * 60 * 8) + (60 * 60 * 4))
// Getting a jobs expiration in seconds:
await client.jobs.getExpiration(jobId) // 43200
// Close all jobs (commented out for sake of example continuity):
// await client.jobs.closeAll()
// Close expired jobs
// We'll manually expire jobId3 to achieve this
client.jobs.setExpiration(jobId3, 1)
setTimeout(async () => { console.log(await client.closeExpiredJobs()) }, 1500) // Returns a number representing the amount of jobs that were closed. In this case, it is "1"
/* Script Execution */
console.log(await client.execute(jobId, "return game.Players.MaxPlayers")) // { type: "LUA_TNUMBER", data: 50 }
// Arrays and undefined objects and handled like so:
console.log(await client.execute(jobId, "return nil")) // { type: "LUA_TNIL", data: null }
console.log(await client.execute(jobId, "return { 'apples', 'bananas', 'lemons' }") // { type: "LUA_TTABLE", data: ["apples", "bananas, "lemons"] }
console.log(await client.execute(jobId, "return { ['foo'] = 'bar', ['fizz'] = 'buzz' }") // { type: "LUA_TTABLE", data: { foo: "bar", fizz: "buzz" } }
// Also works on nested items:
console.log(await client.execute(jobId, "return { ['necessities'] = { 'air', 'water', 'shelter', 'food' } }") // { type: "LUA_TTABLE", data: { necessities: ["air", "water", "shelter", "food"] } }
// RCCService has built in argument support when executing scripts
// In turn, rcctalk supports it. So, instead of string manipulation with the script itself, you can just pass it as as variadic arguments
console.log(await client.execute(jobId, "local mathHomework, logicHomework, favoriteNumber = ...; return mathHomework .. ' ' .. logicHomework .. ' ' .. favoriteNumber", (3 * 8), (true == true), 12) // { type: "LUA_TSTRING", data: "24 true 12" }
// As you might expect, when passing arguments, JavaScript arrays (and nested items too) get turned into its Lua counterparts.
// HOWEVER, you may not pass anything that is not a boolean, string, number, or array. rcctalk parses the values before sending a request to RCCService, and if it finds a foreign object it will throw an exception; you must catch this. This prevents unnecessary RCCService crashes.
/* Diagnostics */
// id, type
console.log(await client.diagnostics(jobId, 0)) // Diagnostics data
// type == 0 = general data
// type & 1 = leak dump
// type & 2 = allocate 500k
// type & 4 = dutycycles
// may or may not be additional request types in 2019+ rcc. Have to verify later
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment