Add IPC to templates and handle helper function server

This commit is contained in:
Cooldude2606 committed 2024-01-24 00:40:22 +00:00
1 parent 2916dcc58c
commit 58231cc02c
11 files changed
+78 -19

No files matched your search

@@ -1,11 +1,17 @@
import * as lib from "@clusterio/lib";
import { BaseInstancePlugin } from "@clusterio/host";
import { PluginExampleEvent, PluginExampleRequest } from "./messages";
import { PluginExampleEvent, PluginExampleRequest } from "./messages";// [module] //
type PuginExampleIPC = {
tick: number,
player_name: string,
};// [] //
export class InstancePlugin extends BaseInstancePlugin {
async init() {
this.instance.handle(PluginExampleEvent, this.handlePluginExampleEvent.bind(this));
this.instance.handle(PluginExampleRequest, this.handlePluginExampleRequest.bind(this));
this.instance.handle(PluginExampleRequest, this.handlePluginExampleRequest.bind(this));// [module] //
this.instance.server.handle("ipc-// plugin_name //-plugin_example_ipc", this.handlePluginExampleIPC.bind(this));// [] //
}
async onInstanceConfigFieldChanged(field: string, curr: unknown, prev: unknown) {
@@ -21,7 +27,8 @@ export class InstancePlugin extends BaseInstancePlugin {
}
async onPlayerEvent(event: lib.PlayerEvent) {
this.logger.info(`onPlayerEvent::onPlayerEvent ${JSON.stringify(event)}`);
this.logger.info(`onPlayerEvent::onPlayerEvent ${JSON.stringify(event)}`);// [module] //
this.sendRcon("/sc ipc_// plugin_name //.foo()");// [] //
}
async handlePluginExampleEvent(event: PluginExampleEvent) {
@@ -34,5 +41,9 @@ export class InstancePlugin extends BaseInstancePlugin {
myResponseString: request.myString,
myResponseNumbers: request.myNumberArray,
};
}
}// [module] //
async handlePluginExampleIPC(event: PuginExampleIPC) {
this.logger.info(JSON.stringify(event));
}// [] //
}