Further work on discord rich presence. Current implementation is untested.
This commit is contained in:
parent
98684a9c1f
commit
a4012458be
@ -3,6 +3,7 @@ const path = require('path')
|
||||
const {AssetGuard} = require(path.join(__dirname, 'assets', 'js', 'assetguard.js'))
|
||||
const ProcessBuilder = require(path.join(__dirname, 'assets', 'js', 'processbuilder.js'))
|
||||
const ConfigManager = require(path.join(__dirname, 'assets', 'js', 'configmanager.js'))
|
||||
const DiscordWrapper = require(path.join(__dirname, 'assets', 'js', 'discordwrapper.js'))
|
||||
|
||||
document.addEventListener('readystatechange', function(){
|
||||
if (document.readyState === 'interactive'){
|
||||
@ -95,6 +96,14 @@ testdownloads = async function(){
|
||||
}
|
||||
}
|
||||
proc.stdout.on('data', tempListener)
|
||||
// Init Discord Hook (Untested)
|
||||
const distro = AssetGuard.retrieveDistributionDataSync(ConfigManager.getGameDirectory)
|
||||
if(distro.discord != null && serv.discord != null){
|
||||
DiscordWrapper.initRPC(distro.discord, serv.discord)
|
||||
proc.on('close', (code, signal) => {
|
||||
DiscordWrapper.shutdownRPC()
|
||||
})
|
||||
}
|
||||
} catch(err) {
|
||||
//det_text.innerHTML = 'Error: ' + err.message;
|
||||
det_text.innerHTML = 'Error: See log for details..';
|
||||
|
@ -42,10 +42,7 @@ const DEFAULT_CONFIG = {
|
||||
clientToken: uuidV4(),
|
||||
selectedServer: null, // Resolved
|
||||
selectedAccount: null,
|
||||
authenticationDatabase: [],
|
||||
discord: {
|
||||
clientID: 385581240906022916
|
||||
}
|
||||
authenticationDatabase: []
|
||||
}
|
||||
|
||||
let config = null;
|
||||
@ -123,25 +120,6 @@ exports.setSelectedServer = function(serverID){
|
||||
|
||||
//TODO Write Authentication Database/Selected Account accessors here
|
||||
|
||||
/**
|
||||
* Retrieve the launcher's Discord Client ID.
|
||||
*
|
||||
* @param {Boolean} def - optional. If true, the default value will be returned.
|
||||
* @returns {String} - the launcher's Discord Client ID.
|
||||
*/
|
||||
exports.getDiscordClientID = function(def = false){
|
||||
return !def ? config.discord.clientID : DEFAULT_CONFIG.discord.clientID
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the launcher's Discord Client ID.
|
||||
*
|
||||
* @param {String} clientID - the launcher's new Discord Client ID.
|
||||
*/
|
||||
exports.setDiscordClientID = function(clientID){
|
||||
config.discord.clientID = clientID
|
||||
}
|
||||
|
||||
// User Configurable Settings
|
||||
|
||||
// Java Settings
|
||||
|
@ -4,24 +4,37 @@ const ConfigManager = require('./configmanager.js')
|
||||
|
||||
let rpc
|
||||
|
||||
function initRPC(){
|
||||
exports.initRPC = function(genSettings, servSettings){
|
||||
rpc = new Client({ transport: 'ipc' });
|
||||
|
||||
rpc.login(ConfigManager.getDiscordClientID()).catch(error => {
|
||||
rpc.on('ready', () => {
|
||||
const activity = {
|
||||
// state = top text
|
||||
// details = bottom text
|
||||
state: 'Server: ' + settings.shortId,
|
||||
details: '',
|
||||
largeImageKey: servSettings.largeImageKey,
|
||||
largeImageText: serSettings.largeImageText,
|
||||
smallImageKey: genSettings.smallImageKey,
|
||||
smallImageText: genSettings.smallImageText,
|
||||
startTimestamp: new Date().getTime() / 1000,
|
||||
instance: false
|
||||
}
|
||||
|
||||
rpc.setActivity(activity)
|
||||
})
|
||||
|
||||
rpc.login(genSettings.clientID()).catch(error => {
|
||||
if(error.message.includes('ENOENT')) {
|
||||
console.log('Unable to initialize Discord Rich Presence, no client detected.')
|
||||
} else {
|
||||
console.log('Unable to initialize Discord Rich Presence: ' + error.message)
|
||||
}
|
||||
})
|
||||
|
||||
const activity = {
|
||||
details: 'Playing on WesterosCraft',
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function shutdownRPC(){
|
||||
exports.shutdownRPC = function(){
|
||||
rpc.setActivity({})
|
||||
rpc.destroy()
|
||||
rpc = null
|
||||
}
|
@ -1,5 +1,10 @@
|
||||
{
|
||||
"version": "1.0",
|
||||
"discord": {
|
||||
"clientID": 385581240906022916,
|
||||
"smallImageText": "WesterosCraft",
|
||||
"smallImageKey": "seal-circle"
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"id": "WesterosCraft-1.11.2",
|
||||
@ -9,6 +14,11 @@
|
||||
"revision": "0.0.1",
|
||||
"server_ip": "mc.westeroscraft.com",
|
||||
"mc_version": "1.11.2",
|
||||
"discord": {
|
||||
"shortId": "Production",
|
||||
"largeImageText": "WesterosCraft Production Server",
|
||||
"largeImageKey": "server-prod"
|
||||
},
|
||||
"default_selected": true,
|
||||
"autoconnect": true,
|
||||
"modules": [
|
||||
|
@ -5,6 +5,11 @@ The distribution index is written in JSON. The general format of the index is as
|
||||
```json
|
||||
{
|
||||
"version": "1.0",
|
||||
"discord": {
|
||||
"clientID": 12334567890,
|
||||
"smallImageText": "WesterosCraft",
|
||||
"smallImageKey": "seal-circle"
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"id": "Example_Server",
|
||||
@ -14,6 +19,11 @@ The distribution index is written in JSON. The general format of the index is as
|
||||
"revision": "0.0.1",
|
||||
"server_ip": "mc.westeroscraft.com:1337",
|
||||
"mc_version": "1.11.2",
|
||||
"discord": {
|
||||
"shortId": "Example",
|
||||
"largeImageText": "WesterosCraft Example Server",
|
||||
"largeImageKey": "server-example"
|
||||
},
|
||||
"default_selected": true,
|
||||
"autoconnect": true,
|
||||
"modules": [
|
||||
@ -26,6 +36,8 @@ The distribution index is written in JSON. The general format of the index is as
|
||||
|
||||
You can declare an unlimited number of servers, however you must provide valid values for the fields listed above. In addition to that, the server can declare modules.
|
||||
|
||||
The discord settings are to enable the use of Rich Presence on the launcher. For more details, see [discord's documentation](https://discordapp.com/developers/docs/rich-presence/how-to#updating-presence-update-presence-payload-fields).
|
||||
|
||||
Only one server in the array should have the `default_selected` property enabled. This will tell the launcher that this is the default server to select if either the previously selected server is invalid, or there is no previously selected server. This field is not defined by any server (avoid this), the first server will be selected as the default. If multiple servers have `default_selected` enabled, the first one the launcher finds will be the effective value. Servers which are not the default may omit this property rather than explicitly setting it to false.
|
||||
|
||||
## Modules
|
||||
|
Loading…
Reference in New Issue
Block a user