mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
Keep a handle to the Instance in the connection the host has to the instance so that methods can be called directly on the Instance. This simplifies logic that exists outside of the link system like the host shutting down all of its instances when it exits. Fixes validation error thrown on host shutdown with running instances.
31 lines
897 B
TypeScript
31 lines
897 B
TypeScript
import * as lib from "@clusterio/lib";
|
|
import type Host from "./Host";
|
|
import type Instance from "./Instance";
|
|
|
|
|
|
export default class InstanceConnection extends lib.Link {
|
|
plugins = new Map<string, string>();
|
|
|
|
constructor(
|
|
connector: lib.VirtualConnector,
|
|
public host: Host,
|
|
public instance: Instance,
|
|
) {
|
|
super(connector);
|
|
this.router = this.host.router;
|
|
|
|
this.handle(lib.InstanceInitialisedEvent, this.handleInstanceInitialisedEvent.bind(this));
|
|
this.snoopEvent(lib.InstanceStatusChangedEvent, this.snoopInstanceStatusChangedEvent.bind(this));
|
|
}
|
|
|
|
async handleInstanceInitialisedEvent(event: lib.InstanceInitialisedEvent) {
|
|
this.plugins = new Map(Object.entries(event.plugins));
|
|
}
|
|
|
|
async snoopInstanceStatusChangedEvent(event: lib.InstanceStatusChangedEvent) {
|
|
if (this.instance.status === "stopped") {
|
|
this.host.instanceConnections.delete(this.instance.id);
|
|
}
|
|
}
|
|
}
|