Move game log processing into SCUM companion

This commit is contained in:
npc0-hue
2026-09-02 10:18:27 +08:00
parent 7d9c1b7e9e
commit 40ac46ba17
14 changed files with 328 additions and 232 deletions
@@ -23,6 +23,7 @@ type ConsoleLogCollector struct {
ServerInstanceID string
CorrelationSecret string
Backoff time.Duration
OnSemanticEvents func(context.Context, SemanticEventBatch) error
}
func NewConsoleLogCollector(client ConsoleLogStreamClient, store ConsoleLogStore, serverInstanceID string, correlationSecret string) *ConsoleLogCollector {
@@ -69,6 +70,11 @@ func (collector *ConsoleLogCollector) handleEvent(ctx context.Context) func(LogS
if _, err := collector.Store.StoreSemanticEventBatch(ctx, batch); err != nil {
return err
}
if collector.OnSemanticEvents != nil {
if err := collector.OnSemanticEvents(ctx, batch); err != nil {
return err
}
}
return nil
}
}
@@ -79,7 +85,10 @@ func consoleRecordFromLogEvent(serverInstanceID string, event LogStreamEvent) (C
}
stream := consoleStreamName(event.StreamKey)
if stream == "" {
return ConsoleRecord{}, false
if !knownPluginLogStream(event.StreamKey) {
return ConsoleRecord{}, false
}
stream = strings.ToLower(strings.TrimSpace(event.StreamKey))
}
occurredAt := event.Entry.Timestamp
if occurredAt.IsZero() {
@@ -88,6 +97,15 @@ func consoleRecordFromLogEvent(serverInstanceID string, event LogStreamEvent) (C
return ConsoleRecord{ServerID: serverInstanceID, Stream: stream, Sequence: event.Entry.Seq, OccurredAt: occurredAt.UTC(), Text: event.Entry.Line}, true
}
func knownPluginLogStream(streamKey string) bool {
switch strings.ToLower(strings.TrimSpace(streamKey)) {
case "scum.login", "scum.chat", "scum.server", "scum.kill", "scum.trade", "scum.admin", "scum.performance":
return true
default:
return false
}
}
func consoleStreamName(streamKey string) string {
key := strings.ToLower(strings.TrimSpace(streamKey))
if strings.Contains(key, "stderr") || strings.HasSuffix(key, ".err") || strings.HasSuffix(key, "-err") {