mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 15:33:12 +09:00
Provide controller resources at construction time
Load hosts, instances, mod packs, mods and users before constructing the Controller instances. This allows these resources to be correctly typed as always available and prevents any possibility of save being initiated on these resources before they are loaded.
This commit is contained in:
1 parent
a0b02ee68b
commit
ab52cc35bf
11 files changed
+91
-77
No files matched your search
@@ -46,9 +46,9 @@ export default class HostConnection extends BaseConnection {
|
||||
this.plugins = new Map(Object.entries(registerData.plugins));
|
||||
this._checkPluginVersions();
|
||||
|
||||
let currentHostInfo = this._controller.hosts!.get(this._id);
|
||||
let currentHostInfo = this._controller.hosts.get(this._id);
|
||||
|
||||
this._controller.hosts!.set(this._id, {
|
||||
this._controller.hosts.set(this._id, {
|
||||
agent: this._agent,
|
||||
id: this._id,
|
||||
name: this._name,
|
||||
@@ -70,7 +70,7 @@ export default class HostConnection extends BaseConnection {
|
||||
|
||||
this.connector.on("close", () => {
|
||||
// Update status to unknown for instances on this host.
|
||||
for (let instance of this._controller.instances!.values()) {
|
||||
for (let instance of this._controller.instances.values()) {
|
||||
if (instance.config.get("instance.assigned_host") !== this._id) {
|
||||
continue;
|
||||
}
|
||||
@@ -105,7 +105,7 @@ export default class HostConnection extends BaseConnection {
|
||||
break;
|
||||
|
||||
case lib.Address.instance:
|
||||
let instance = this._controller.instances!.get(message.src.id);
|
||||
let instance = this._controller.instances.get(message.src.id);
|
||||
if (!instance || instance.config.get("instance.assigned_host") !== this._id) {
|
||||
throw new lib.InvalidMessage(
|
||||
`Received message with invalid src ${message.src} from ${origin}`
|
||||
@@ -157,7 +157,7 @@ export default class HostConnection extends BaseConnection {
|
||||
}
|
||||
|
||||
async handleInstanceStatusChangedEvent(request: lib.InstanceStatusChangedEvent) {
|
||||
let instance = this._controller.instances!.get(request.instanceId);
|
||||
let instance = this._controller.instances.get(request.instanceId);
|
||||
|
||||
// It's possible to get updates from an instance that does not exist
|
||||
// or is not assigned to the host it originated from if it was
|
||||
@@ -187,7 +187,7 @@ export default class HostConnection extends BaseConnection {
|
||||
|
||||
async handleInstancesUpdateRequest(request: lib.InstancesUpdateRequest) {
|
||||
// Push updated instance configs
|
||||
for (let instance of this._controller.instances!.values()) {
|
||||
for (let instance of this._controller.instances.values()) {
|
||||
if (instance.config.get("instance.assigned_host") === this._id) {
|
||||
await this.send(
|
||||
new lib.InstanceAssignInternalRequest(instance.id, instance.config.serialize("host"))
|
||||
@@ -200,7 +200,7 @@ export default class HostConnection extends BaseConnection {
|
||||
let instanceConfig = new lib.InstanceConfig("controller");
|
||||
await instanceConfig.load(instanceData.config as lib.SerializedConfig, "host");
|
||||
|
||||
let controllerInstance = this._controller.instances!.get(instanceConfig.get("instance.id"));
|
||||
let controllerInstance = this._controller.instances.get(instanceConfig.get("instance.id"));
|
||||
if (controllerInstance) {
|
||||
// Check if this instance is assigned somewhere else.
|
||||
if (controllerInstance.config.get("instance.assigned_host") !== this._id) {
|
||||
@@ -227,7 +227,7 @@ export default class HostConnection extends BaseConnection {
|
||||
let newInstance = new InstanceInfo(
|
||||
{ config: instanceConfig, status: instanceData.status as InstanceStatus }
|
||||
);
|
||||
this._controller.instances!.set(instanceConfig.get("instance.id"), newInstance);
|
||||
this._controller.instances.set(instanceConfig.get("instance.id"), newInstance);
|
||||
this._controller.instancesDirty = true;
|
||||
this._controller.addInstanceHooks(newInstance);
|
||||
await this.send(
|
||||
@@ -292,7 +292,7 @@ export default class HostConnection extends BaseConnection {
|
||||
user.recalculatePlayerStats();
|
||||
this._controller.userUpdated(user);
|
||||
|
||||
let instance = this._controller.instances!.get(instanceId)!;
|
||||
let instance = this._controller.instances.get(instanceId)!;
|
||||
await lib.invokeHook(this._controller.plugins, "onPlayerEvent", instance, {
|
||||
type: event.type,
|
||||
name: event.name,
|
||||
|
||||
Reference in new issue
Block a user