server

package
v0.6.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackupDatabase

func BackupDatabase(dbPath string) (string, error)

BackupDatabase creates a backup of the current database

func ClearMessages

func ClearMessages(db *sql.DB) error

func ConvertPluginMessage

func ConvertPluginMessage(pluginMsg sdk.Message) shared.Message

ConvertPluginMessage converts a plugin message to a shared message

func CreateSchema

func CreateSchema(db *sql.DB)

func GetDatabaseStats

func GetDatabaseStats(db *sql.DB) (string, error)

GetDatabaseStats returns statistics about the database

func GetMessagesAfter

func GetMessagesAfter(db *sql.DB, lastMessageID int64, limit int) []shared.Message

GetMessagesAfter retrieves messages with ID > lastMessageID

func GetRecentMessages

func GetRecentMessages(db *sql.DB) []shared.Message

func GetRecentMessagesForUser

func GetRecentMessagesForUser(db *sql.DB, username string, defaultLimit int, banGapsHistory bool) ([]shared.Message, int64)

GetRecentMessagesForUser returns personalized message history for a specific user

func InitDB

func InitDB(filepath string) *sql.DB

func InsertEncryptedMessage

func InsertEncryptedMessage(db *sql.DB, encryptedMsg *shared.EncryptedMessage)

InsertEncryptedMessage stores an encrypted message in the database

func InsertMessage

func InsertMessage(db *sql.DB, msg shared.Message)

func RunAdminPanel

func RunAdminPanel(hub *Hub, db *sql.DB, pluginManager *manager.PluginManager, configDir, dbPath string, port int) error

RunAdminPanel starts the admin panel TUI

func ServeWs

func ServeWs(hub *Hub, db *sql.DB, adminList []string, adminKey string, banGapsHistory bool) http.HandlerFunc

Types

type AdminPanel

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

AdminPanel represents the main admin panel state

func NewAdminPanel

func NewAdminPanel(hub *Hub, db *sql.DB, pluginManager *manager.PluginManager, configDir, dbPath string, port int) *AdminPanel

NewAdminPanel creates a new admin panel instance

func (*AdminPanel) Init

func (ap *AdminPanel) Init() tea.Cmd

Implement tea.Model interface

func (*AdminPanel) Update

func (ap *AdminPanel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*AdminPanel) View

func (ap *AdminPanel) View() string

type Client

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

type Config

type Config struct {
	Port     int      `json:"port"`
	Admins   []string `json:"admins"`
	AdminKey string   `json:"admin_key"`
}

func LoadConfig

func LoadConfig(path string) (Config, error)

LoadConfig loads configuration from a JSON file (for backward compatibility)

func LoadConfigFromDir

func LoadConfigFromDir(configDir string) (Config, error)

LoadConfigFromDir loads configuration from a directory, checking for JSON config files

type Hub

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

func NewHub

func NewHub(pluginDir, dataDir, registryURL string, db *sql.DB) *Hub

func (*Hub) AllowUser

func (h *Hub) AllowUser(username string, adminUsername string) bool

AllowUser removes a user from temporary kick list (override early)

func (*Hub) BanUser

func (h *Hub) BanUser(username string, adminUsername string)

BanUser adds a user to the permanent ban list

func (*Hub) CleanupExpiredBans

func (h *Hub) CleanupExpiredBans()

CleanupExpiredBans removes expired bans and kicks from the lists

func (*Hub) CleanupStaleConnections

func (h *Hub) CleanupStaleConnections()

CleanupStaleConnections removes clients with broken connections

func (*Hub) ForceDisconnectUser

func (h *Hub) ForceDisconnectUser(username string, adminUsername string) bool

ForceDisconnectUser forcibly removes a user from the clients map (admin command for stale connections)

func (*Hub) GetPluginManager

func (h *Hub) GetPluginManager() *manager.PluginManager

GetPluginManager returns the plugin manager reference

func (*Hub) IsUserBanned

func (h *Hub) IsUserBanned(username string) bool

IsUserBanned checks if a user is currently banned or kicked

func (*Hub) KickUser

func (h *Hub) KickUser(username string, adminUsername string)

KickUser temporarily bans a user for 24 hours

func (*Hub) Run

func (h *Hub) Run()

func (*Hub) UnbanUser

func (h *Hub) UnbanUser(username string, adminUsername string) bool

UnbanUser removes a user from the ban list

type PluginCommandHandler

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

PluginCommandHandler handles plugin-related commands

func NewPluginCommandHandler

func NewPluginCommandHandler(pluginManager *manager.PluginManager) *PluginCommandHandler

NewPluginCommandHandler creates a new plugin command handler

func (*PluginCommandHandler) GetPluginMessageChannel

func (h *PluginCommandHandler) GetPluginMessageChannel() <-chan sdk.Message

GetPluginMessageChannel returns the channel for receiving messages from plugins

func (*PluginCommandHandler) HandlePluginCommand

func (h *PluginCommandHandler) HandlePluginCommand(cmd string, args []string, isAdmin bool) (string, error)

HandlePluginCommand handles plugin-related commands

func (*PluginCommandHandler) SendMessageToPlugins

func (h *PluginCommandHandler) SendMessageToPlugins(msg shared.Message)

SendMessageToPlugins sends a message to all enabled plugins

func (*PluginCommandHandler) UpdateUserListForPlugins

func (h *PluginCommandHandler) UpdateUserListForPlugins(users []string)

UpdateUserListForPlugins updates the user list for plugins

type UserList

type UserList struct {
	Users []string `json:"users"`
}

type WSMessage

type WSMessage struct {
	Type string          `json:"type"`
	Data json.RawMessage `json:"data"`
}

Jump to

Keyboard shortcuts

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