refactor(game): lock-free storage, remove /command, flatten engine wrapper
Three-stage refactor of the game-engine plumbing (game logic untouched): Stage 1 — lock-free persistence + admin serialisation. Remove the file lock from repo/fs (the .lock file, the Read/Write-vs-*Safe duality and the dead ReadSafe polling) and replace the two-step rename with a single atomic rename so concurrent reads are torn-free without a lock. Serialise the state-mutating admin writers (init/turn/banish) with one shared router LimitMiddleware, rewritten to block on the request context instead of a racy shared 100ms timer. Stage 2 — remove the obsolete immediate-command path end to end. Players submit through PUT /api/v1/order; the legacy PUT /api/v1/command path is deleted across game (route, handler, 24 command factories, Ctrl), backend (Commands handler/route, engineclient.ExecuteCommands), gateway (dispatch + executeUserGamesCommand + routing entry), the FlatBuffers/model contract (UserGamesCommand[Response]) and transcoder, plus every affected OpenAPI/README/FUNCTIONAL/ARCHITECTURE doc. The integration proxy test is converted to the order path. Stage 3 — flatten the REST->engine wrapper. Replace the executor adapter, the controller package functions and RepoController with one concrete controller.Service; drop the single-implementation Repo and Storage interfaces (repo.Repo / fs.FS are now concrete). Handlers depend on a thin handler.Engine seam and own the domain->REST projection; storage is resolved once at startup instead of per request. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -32,8 +32,6 @@ export { PlanetRouteLoadType } from './order/planet-route-load-type.js';
|
||||
export { Relation } from './order/relation.js';
|
||||
export { ShipGroupCargo } from './order/ship-group-cargo.js';
|
||||
export { ShipGroupUpgradeTech } from './order/ship-group-upgrade-tech.js';
|
||||
export { UserGamesCommand, UserGamesCommandT } from './order/user-games-command.js';
|
||||
export { UserGamesCommandResponse, UserGamesCommandResponseT } from './order/user-games-command-response.js';
|
||||
export { UserGamesOrder, UserGamesOrderT } from './order/user-games-order.js';
|
||||
export { UserGamesOrderGet, UserGamesOrderGetT } from './order/user-games-order-get.js';
|
||||
export { UserGamesOrderGetResponse, UserGamesOrderGetResponseT } from './order/user-games-order-get-response.js';
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
export class UserGamesCommandResponse implements flatbuffers.IUnpackableObject<UserGamesCommandResponseT> {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):UserGamesCommandResponse {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsUserGamesCommandResponse(bb:flatbuffers.ByteBuffer, obj?:UserGamesCommandResponse):UserGamesCommandResponse {
|
||||
return (obj || new UserGamesCommandResponse()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsUserGamesCommandResponse(bb:flatbuffers.ByteBuffer, obj?:UserGamesCommandResponse):UserGamesCommandResponse {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new UserGamesCommandResponse()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static startUserGamesCommandResponse(builder:flatbuffers.Builder) {
|
||||
builder.startObject(0);
|
||||
}
|
||||
|
||||
static endUserGamesCommandResponse(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createUserGamesCommandResponse(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
UserGamesCommandResponse.startUserGamesCommandResponse(builder);
|
||||
return UserGamesCommandResponse.endUserGamesCommandResponse(builder);
|
||||
}
|
||||
|
||||
unpack(): UserGamesCommandResponseT {
|
||||
return new UserGamesCommandResponseT();
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: UserGamesCommandResponseT): void {}
|
||||
}
|
||||
|
||||
export class UserGamesCommandResponseT implements flatbuffers.IGeneratedObject {
|
||||
constructor(){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
return UserGamesCommandResponse.createUserGamesCommandResponse(builder);
|
||||
}
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { UUID, UUIDT } from '../common/uuid.js';
|
||||
import { CommandItem, CommandItemT } from '../order/command-item.js';
|
||||
|
||||
|
||||
export class UserGamesCommand implements flatbuffers.IUnpackableObject<UserGamesCommandT> {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):UserGamesCommand {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsUserGamesCommand(bb:flatbuffers.ByteBuffer, obj?:UserGamesCommand):UserGamesCommand {
|
||||
return (obj || new UserGamesCommand()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsUserGamesCommand(bb:flatbuffers.ByteBuffer, obj?:UserGamesCommand):UserGamesCommand {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new UserGamesCommand()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
gameId(obj?:UUID):UUID|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? (obj || new UUID()).__init(this.bb_pos + offset, this.bb!) : null;
|
||||
}
|
||||
|
||||
commands(index: number, obj?:CommandItem):CommandItem|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? (obj || new CommandItem()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
|
||||
}
|
||||
|
||||
commandsLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
static startUserGamesCommand(builder:flatbuffers.Builder) {
|
||||
builder.startObject(2);
|
||||
}
|
||||
|
||||
static addGameId(builder:flatbuffers.Builder, gameIdOffset:flatbuffers.Offset) {
|
||||
builder.addFieldStruct(0, gameIdOffset, 0);
|
||||
}
|
||||
|
||||
static addCommands(builder:flatbuffers.Builder, commandsOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(1, commandsOffset, 0);
|
||||
}
|
||||
|
||||
static createCommandsVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startCommandsVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static endUserGamesCommand(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
builder.requiredField(offset, 4) // game_id
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createUserGamesCommand(builder:flatbuffers.Builder, gameIdOffset:flatbuffers.Offset, commandsOffset:flatbuffers.Offset):flatbuffers.Offset {
|
||||
UserGamesCommand.startUserGamesCommand(builder);
|
||||
UserGamesCommand.addGameId(builder, gameIdOffset);
|
||||
UserGamesCommand.addCommands(builder, commandsOffset);
|
||||
return UserGamesCommand.endUserGamesCommand(builder);
|
||||
}
|
||||
|
||||
unpack(): UserGamesCommandT {
|
||||
return new UserGamesCommandT(
|
||||
(this.gameId() !== null ? this.gameId()!.unpack() : null),
|
||||
this.bb!.createObjList<CommandItem, CommandItemT>(this.commands.bind(this), this.commandsLength())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
unpackTo(_o: UserGamesCommandT): void {
|
||||
_o.gameId = (this.gameId() !== null ? this.gameId()!.unpack() : null);
|
||||
_o.commands = this.bb!.createObjList<CommandItem, CommandItemT>(this.commands.bind(this), this.commandsLength());
|
||||
}
|
||||
}
|
||||
|
||||
export class UserGamesCommandT implements flatbuffers.IGeneratedObject {
|
||||
constructor(
|
||||
public gameId: UUIDT|null = null,
|
||||
public commands: (CommandItemT)[] = []
|
||||
){}
|
||||
|
||||
|
||||
pack(builder:flatbuffers.Builder): flatbuffers.Offset {
|
||||
const commands = UserGamesCommand.createCommandsVector(builder, builder.createObjectOffsetList(this.commands));
|
||||
|
||||
return UserGamesCommand.createUserGamesCommand(builder,
|
||||
(this.gameId !== null ? this.gameId!.pack(builder) : 0),
|
||||
commands
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user