mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 07:33:12 +09:00
Player session end tracking
This commit is contained in:
1 parent
2eedddf17f
commit
73ab8fc4f3
5 files changed
+288
-3
No files matched your search
@@ -9,6 +9,7 @@ import {
|
||||
RecipeData,
|
||||
PlayerPositionEvent,
|
||||
PlayerData,
|
||||
PlayerSessionEndEvent,
|
||||
} from "./messages";
|
||||
|
||||
interface TileDataIpc {
|
||||
@@ -49,6 +50,11 @@ interface PlayerPositionIpc {
|
||||
sec: number;
|
||||
}
|
||||
|
||||
interface PlayerSessionEndIpc {
|
||||
player_name: string;
|
||||
surface: string;
|
||||
}
|
||||
|
||||
export class InstancePlugin extends BaseInstancePlugin {
|
||||
pendingTileUpdates = new Map<string, Set<[number, number, [number, number, number, number]]>>();
|
||||
|
||||
@@ -84,6 +90,13 @@ export class InstancePlugin extends BaseInstancePlugin {
|
||||
`Error handling player position data from Lua:\n${err}`
|
||||
));
|
||||
});
|
||||
|
||||
// Listen for player session end data from Lua module
|
||||
this.instance.server.on("ipc-minimap:player_session_end", (data: PlayerSessionEndIpc) => {
|
||||
this.handlePlayerSessionEndFromLua(data).catch(err => this.logger.error(
|
||||
`Error handling player session end data from Lua:\n${err}`
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
async handleTileDataFromLua(data: TileDataIpc) {
|
||||
@@ -188,6 +201,26 @@ export class InstancePlugin extends BaseInstancePlugin {
|
||||
}
|
||||
}
|
||||
|
||||
async handlePlayerSessionEndFromLua(data: PlayerSessionEndIpc) {
|
||||
try {
|
||||
if (!data) {
|
||||
this.logger.error("Invalid player session end data received");
|
||||
return;
|
||||
}
|
||||
|
||||
const event = new PlayerSessionEndEvent(
|
||||
this.instance.config.get("instance.id"),
|
||||
{
|
||||
player_name: data.player_name,
|
||||
surface: data.surface,
|
||||
}
|
||||
);
|
||||
this.instance.sendTo("controller", event);
|
||||
} catch (err: unknown) {
|
||||
this.logger.error(`Failed to process player session end data from Lua: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
async onStart() {
|
||||
// Initialize the Lua module when the instance starts
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user