detectionmgr

package
v5.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

detector.go

handlers.go

interface.go

logstream.go

types.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHandler

func AddHandler(detector *Detector, eventType EventType, handler Handler)

AddHandler is a convenient method to register a handler for an event type

func DefaultHandlers

func DefaultHandlers() map[EventType]Handler

DefaultHandlers returns a map of event types to default handlers

func GetPlayers

func GetPlayers(detector *Detector) map[string]string

GetPlayers returns the currently connected players

func HandleCustomDetection

func HandleCustomDetection(w http.ResponseWriter, r *http.Request)

HandleCustomDetections handles GET and POST requests for custom detections

func HandleDeleteCustomDetection

func HandleDeleteCustomDetection(w http.ResponseWriter, r *http.Request)

HandleCustomDetectionsWithID handles DELETE requests for a specific custom detection

func InitCustomDetectionsManager

func InitCustomDetectionsManager(detector *Detector)

InitCustomDetectionsManager initializes the custom detections manager

func ProcessLog

func ProcessLog(detector *Detector, logMessage string)

ProcessLog is a convenient method to process a log message

func RegisterDefaultHandlers

func RegisterDefaultHandlers(detector *Detector)

RegisterDefaultHandlers registers all default handlers with a detector

func StreamLogs

func StreamLogs(detector *Detector)

StartLogStream starts processing logs directly from the internal SSE manager

Types

type BackupInfo

type BackupInfo struct {
	BackupIndex string
}

BackupInfo contains information about a world save/backup

type CustomDetection

type CustomDetection struct {
	ID        string `json:"id"`
	Type      string `json:"type"` // "regex" or "keyword"
	Pattern   string `json:"pattern"`
	EventType string `json:"eventType"`
	Message   string `json:"message"`
}

CustomDetection defines a user-defined detection pattern

type CustomDetectionsManager

type CustomDetectionsManager struct {
	Detections []CustomDetection
	// contains filtered or unexported fields
}

CustomDetectionsManager handles loading, saving and managing custom detections

func NewCustomDetectionsManager

func NewCustomDetectionsManager(detector *Detector) *CustomDetectionsManager

NewCustomDetectionsManager creates a new manager and loads existing detections

func (*CustomDetectionsManager) AddDetection

func (m *CustomDetectionsManager) AddDetection(detection CustomDetection) error

AddDetection adds a new custom detection

func (*CustomDetectionsManager) DeleteDetection

func (m *CustomDetectionsManager) DeleteDetection(id string) error

DeleteDetection removes a custom detection by ID

func (*CustomDetectionsManager) GetDetections

func (m *CustomDetectionsManager) GetDetections() []CustomDetection

GetDetections returns all custom detections

func (*CustomDetectionsManager) LoadDetections

func (m *CustomDetectionsManager) LoadDetections() error

LoadDetections loads custom detections from file

type CustomPattern

type CustomPattern struct {
	Pattern     *regexp.Regexp
	EventType   EventType
	MessageTmpl string
	IsRegex     bool
	Keyword     string
}

type Detector

type Detector struct {
	// contains filtered or unexported fields
}

func NewDetector

func NewDetector() *Detector

NewDetector creates a new instance of Detector

func Start

func Start() *Detector

Start initializes the detector and returns it

func (*Detector) GetConnectedPlayers

func (d *Detector) GetConnectedPlayers() map[string]string

GetConnectedPlayers returns a copy of the connected players map

func (*Detector) ProcessLogMessage

func (d *Detector) ProcessLogMessage(logMessage string)

ProcessLogMessage analyzes a log message and triggers appropriate handlers

func (*Detector) RegisterHandler

func (d *Detector) RegisterHandler(eventType EventType, handler Handler)

RegisterHandler registers a handler for a specific event type

func (*Detector) SetCustomPatterns

func (d *Detector) SetCustomPatterns(patterns []CustomPattern)

type Event

type Event struct {
	Type          EventType
	Message       string
	RawLog        string
	Timestamp     string
	PlayerInfo    *PlayerInfo
	BackupInfo    *BackupInfo
	ExceptionInfo *ExceptionInfo
}

Event represents a detected event from server logs

type EventType

type EventType string

EventType defines the type of event detected

const (
	EventServerReady      EventType = "SERVER_READY"
	EventServerStarting   EventType = "SERVER_STARTING"
	EventServerError      EventType = "SERVER_ERROR"
	EventPlayerConnecting EventType = "PLAYER_CONNECTING"
	EventPlayerReady      EventType = "PLAYER_READY"
	EventPlayerDisconnect EventType = "PLAYER_DISCONNECT"
	EventWorldSaved       EventType = "WORLD_SAVED"
	EventException        EventType = "EXCEPTION"
	EventSettingsChanged  EventType = "SETTINGS_CHANGED"
	EventServerHosted     EventType = "SERVER_HOSTED"
	EventNewGameStarted   EventType = "NEW_GAME_STARTED"
	EventServerRunning    EventType = "SERVER_RUNNING"
	EventCustomDetection  EventType = "CUSTOM_DETECTION"
)

type ExceptionInfo

type ExceptionInfo struct {
	StackTrace string
}

ExceptionInfo contains information about a server exception

type Handler

type Handler func(event Event)

Handler is a function that handles detected events

type PlayerInfo

type PlayerInfo struct {
	Username string
	SteamID  string
}

PlayerInfo contains information about a player

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL