mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 07:04:52 +09:00
* Improve config, message, and module templates * Update global handler in template module * Add comments to empty instance template
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import * as lib from "@clusterio/lib";
|
|
import { BaseHostPlugin } from "@clusterio/host";
|
|
//%if multi_context
|
|
import { PluginExampleEvent, PluginExampleRequest } from "./messages";
|
|
//%endif
|
|
|
|
export class HostPlugin extends BaseHostPlugin {
|
|
//%if multi_context
|
|
async init() {
|
|
this.host.handle(PluginExampleEvent, this.handlePluginExampleEvent.bind(this));
|
|
this.host.handle(PluginExampleRequest, this.handlePluginExampleRequest.bind(this));
|
|
}
|
|
//%endif
|
|
|
|
async onHostConfigFieldChanged(field: string, curr: unknown, prev: unknown) {
|
|
this.logger.info(`host::onInstanceConfigFieldChanged ${field}`);
|
|
}
|
|
|
|
async onShutdown() {
|
|
this.logger.info("host::onShutdown");
|
|
}
|
|
//%if multi_context
|
|
|
|
async handlePluginExampleEvent(event: PluginExampleEvent) {
|
|
this.logger.info(JSON.stringify(event));
|
|
}
|
|
|
|
async handlePluginExampleRequest(request: PluginExampleRequest) {
|
|
this.logger.info(JSON.stringify(request));
|
|
return {
|
|
myResponseString: request.myString,
|
|
myResponseNumbers: request.myNumberArray,
|
|
};
|
|
}
|
|
//%endif
|
|
}
|