mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 15:19:47 +00:00
have clients send logs to server
This commit is contained in:
@@ -248,7 +248,6 @@
|
||||
* give naval units health
|
||||
* bug: player names not updating sometimes
|
||||
* make player editeable configs
|
||||
* games disconnects on multplayer after some time
|
||||
* couldn't scroll left on build menu to deploy bombs (mobile)
|
||||
* UI/test too big on mobile
|
||||
* bug: build city 25k bump doesn't match troop/worker ratio
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { EventBus } from "../core/EventBus"
|
||||
import { SendLogEvent } from "./Transport"
|
||||
|
||||
export enum LogSeverity {
|
||||
Info,
|
||||
Warn,
|
||||
Error
|
||||
}
|
||||
|
||||
export function initializeLogSender(eventBus: EventBus) {
|
||||
const log = (msg: string): void => {
|
||||
eventBus.emit(new SendLogEvent(LogSeverity.Info, msg))
|
||||
console.log(msg)
|
||||
}
|
||||
console.log = log
|
||||
}
|
||||
+26
-1
@@ -1,9 +1,10 @@
|
||||
import { Config } from "../core/configuration/Config"
|
||||
import { EventBus, GameEvent } from "../core/EventBus"
|
||||
import { AllianceRequest, AllPlayers, Cell, GameType, Player, PlayerID, PlayerType, Tile, UnitType } from "../core/game/Game"
|
||||
import { ClientID, ClientIntentMessageSchema, ClientJoinMessageSchema, GameID, Intent, ServerMessage, ServerMessageSchema, ClientPingMessageSchema, GameConfig } from "../core/Schemas"
|
||||
import { ClientID, ClientIntentMessageSchema, ClientJoinMessageSchema, GameID, Intent, ServerMessage, ServerMessageSchema, ClientPingMessageSchema, GameConfig, ClientLogMessageSchema } from "../core/Schemas"
|
||||
import { LobbyConfig } from "./GameRunner"
|
||||
import { LocalServer } from "./LocalServer"
|
||||
import { LogSeverity } from "./LogSender"
|
||||
|
||||
|
||||
export class SendAllianceRequestIntentEvent implements GameEvent {
|
||||
@@ -82,6 +83,13 @@ export class SendSetTargetTroopRatioEvent implements GameEvent {
|
||||
) { }
|
||||
}
|
||||
|
||||
export class SendLogEvent implements GameEvent {
|
||||
constructor(
|
||||
public readonly severity: LogSeverity,
|
||||
public readonly log: string,
|
||||
) { }
|
||||
}
|
||||
|
||||
export class Transport {
|
||||
|
||||
private socket: WebSocket
|
||||
@@ -118,6 +126,8 @@ export class Transport {
|
||||
this.eventBus.on(SendDonateIntentEvent, (e) => this.onSendDonateIntent(e))
|
||||
this.eventBus.on(SendSetTargetTroopRatioEvent, (e) => this.onSendSetTargetTroopRatioEvent(e))
|
||||
this.eventBus.on(BuildUnitIntentEvent, (e) => this.onBuildUnitIntent(e))
|
||||
|
||||
this.eventBus.on(SendLogEvent, (e) => this.onSendLogEvent(e))
|
||||
}
|
||||
|
||||
private startPing() {
|
||||
@@ -187,6 +197,20 @@ export class Transport {
|
||||
};
|
||||
}
|
||||
|
||||
private onSendLogEvent(event: SendLogEvent) {
|
||||
this.sendMsg(
|
||||
JSON.stringify(
|
||||
ClientLogMessageSchema.parse({
|
||||
type: "log",
|
||||
gameID: this.lobbyConfig.gameID,
|
||||
clientID: this.lobbyConfig.clientID,
|
||||
persistentID: this.lobbyConfig.persistentID,
|
||||
log: event.log,
|
||||
})
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
joinGame(numTurns: number) {
|
||||
this.sendMsg(
|
||||
JSON.stringify(
|
||||
@@ -218,6 +242,7 @@ export class Transport {
|
||||
this.socket.onclose = (event: CloseEvent) => { }
|
||||
}
|
||||
|
||||
|
||||
private onSendAllianceRequest(event: SendAllianceRequestIntentEvent) {
|
||||
this.sendIntent({
|
||||
type: "allianceRequest",
|
||||
|
||||
+15
-3
@@ -31,7 +31,7 @@ export type BuildUnitIntent = z.infer<typeof BuildUnitIntentSchema>
|
||||
export type Turn = z.infer<typeof TurnSchema>
|
||||
export type GameConfig = z.infer<typeof GameConfigSchema>
|
||||
|
||||
export type ClientMessage = ClientPingMessage | ClientIntentMessage | ClientJoinMessage
|
||||
export type ClientMessage = ClientPingMessage | ClientIntentMessage | ClientJoinMessage | ClientLogMessage
|
||||
export type ServerMessage = ServerSyncMessage | ServerStartGameMessage | ServerPingMessage
|
||||
|
||||
export type ServerSyncMessage = z.infer<typeof ServerTurnMessageSchema>
|
||||
@@ -41,6 +41,7 @@ export type ServerPingMessage = z.infer<typeof ServerPingMessageSchema>
|
||||
export type ClientPingMessage = z.infer<typeof ClientPingMessageSchema>
|
||||
export type ClientIntentMessage = z.infer<typeof ClientIntentMessageSchema>
|
||||
export type ClientJoinMessage = z.infer<typeof ClientJoinMessageSchema>
|
||||
export type ClientLogMessage = z.infer<typeof ClientLogMessageSchema>
|
||||
|
||||
export type PlayerRecord = z.infer<typeof PlayerRecordSchema>
|
||||
export type GameRecord = z.infer<typeof GameRecordSchema>
|
||||
@@ -208,11 +209,17 @@ export const ServerMessageSchema = z.union([ServerTurnMessageSchema, ServerStart
|
||||
// Client
|
||||
|
||||
const ClientBaseMessageSchema = z.object({
|
||||
type: z.string(),
|
||||
type: z.enum(['join', 'intent', 'ping', 'log']),
|
||||
clientID: z.string(),
|
||||
gameID: z.string(),
|
||||
})
|
||||
|
||||
export const ClientLogMessageSchema = ClientBaseMessageSchema.extend({
|
||||
type: z.literal('log'),
|
||||
severity: z.enum([''])
|
||||
log: z.string(),
|
||||
})
|
||||
|
||||
export const ClientPingMessageSchema = ClientBaseMessageSchema.extend({
|
||||
type: z.literal('ping'),
|
||||
})
|
||||
@@ -230,7 +237,12 @@ export const ClientJoinMessageSchema = ClientBaseMessageSchema.extend({
|
||||
username: z.string(),
|
||||
})
|
||||
|
||||
export const ClientMessageSchema = z.union([ClientPingMessageSchema, ClientIntentMessageSchema, ClientJoinMessageSchema]);
|
||||
export const ClientMessageSchema = z.union([
|
||||
ClientPingMessageSchema,
|
||||
ClientIntentMessageSchema,
|
||||
ClientJoinMessageSchema,
|
||||
ClientLogMessageSchema,
|
||||
]);
|
||||
|
||||
export const PlayerRecordSchema = z.object({
|
||||
clientID: z.string(),
|
||||
|
||||
@@ -122,7 +122,9 @@ wss.on('connection', (ws, req) => {
|
||||
clientMsg.lastTurn
|
||||
)
|
||||
}
|
||||
// TODO: send error message
|
||||
if(clientMsg.type == "log") {
|
||||
console.log()
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user