mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 07:24:53 +09:00
Delete player statistics when deleting instances
Clear the statistics stored per user for the instance when an instance is deleted.
This commit is contained in:
1 parent
1021e29c98
commit
8865509011
4 files changed
+35
No files matched your search
@@ -12,6 +12,7 @@
|
||||
- Similarly fixed Web UI not showing the mod pack create, delete, list and host revoke token actions if the user is not a cluster admin.
|
||||
- Fixed Research Sync applying progress of a previous techology level to the level on the controller when it's the active research during instance startup.
|
||||
- Fixed data export with a mod using shorthand notation for the default value of a color-setting causing the ModPack data to be set to invalid data.
|
||||
- Fixed per user per instance player stats not being deleted when the instance it's for is deleted.
|
||||
|
||||
|
||||
## Version 2.0.0-alpha.16
|
||||
|
||||
@@ -964,6 +964,7 @@ export default class Controller {
|
||||
this.instancesDirty = true;
|
||||
|
||||
this.clearSavesOfInstance(instanceId);
|
||||
this.userManager.clearStatsOfInstance(instanceId);
|
||||
|
||||
let prev = instance.status;
|
||||
instance.status = "deleted";
|
||||
|
||||
@@ -113,4 +113,13 @@ export default class UserManager {
|
||||
this.onlineUsers.delete(user);
|
||||
}
|
||||
}
|
||||
|
||||
clearStatsOfInstance(instanceId: number) {
|
||||
for (const user of this.users.values()) {
|
||||
this.notifyLeave(user, instanceId);
|
||||
user.instanceStats.delete(instanceId);
|
||||
user.recalculatePlayerStats();
|
||||
}
|
||||
this.dirty = true;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const { PlayerStats } = require("@clusterio/lib");
|
||||
const { ControllerUser, UserManager } = require("@clusterio/controller");
|
||||
|
||||
describe("controller/src/UserManager", function() {
|
||||
@@ -31,5 +32,28 @@ describe("controller/src/UserManager", function() {
|
||||
assert(!userManager.onlineUsers.has(user));
|
||||
assert.deepEqual(user.instances, new Set());
|
||||
});
|
||||
describe(".clearStatsOfInstance()", function() {
|
||||
it("should remove the instance stats from existing users", function() {
|
||||
let user1 = ControllerUser.fromJSON({ name: "admin", roles: [1] });
|
||||
let user2 = ControllerUser.fromJSON({ name: "player", roles: [1] });
|
||||
userManager.users.set(user1.name, user1);
|
||||
userManager.users.set(user2.name, user2);
|
||||
user1.instanceStats.set(10, new PlayerStats({ join_count: 1 }));
|
||||
user1.instanceStats.set(11, new PlayerStats({ join_count: 6 }));
|
||||
user1.recalculatePlayerStats();
|
||||
userManager.notifyJoin(user1, 11);
|
||||
user2.instanceStats.set(10, new PlayerStats({ join_count: 3 }));
|
||||
user2.recalculatePlayerStats();
|
||||
assert.equal(user1.playerStats.joinCount, 7);
|
||||
assert.equal(user2.playerStats.joinCount, 3);
|
||||
assert(userManager.onlineUsers.has(user1));
|
||||
|
||||
userManager.clearStatsOfInstance(11);
|
||||
|
||||
assert.equal(user1.playerStats.joinCount, 1);
|
||||
assert(!userManager.onlineUsers.has(user1));
|
||||
assert.equal(user2.playerStats.joinCount, 3);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user