Documentation
¶
Index ¶
- func ClientStateToString(state ClientState) string
- type ClientState
- type ConnClient
- type ConnServer
- func (s *ConnServer) AuthenticateClient(clientID, username, password, method string) error
- func (s *ConnServer) BroadcastMessage(msg *message.Message) error
- func (s *ConnServer) BroadcastToRoom(roomID string, msg *message.Message) error
- func (s *ConnServer) CreateRoom(id, name, description string) error
- func (s *ConnServer) DeleteRoom(roomID string) error
- func (s *ConnServer) GetClient(id string) (*ConnClient, bool)
- func (s *ConnServer) GetClientCount() int
- func (s *ConnServer) GetClientRooms(clientID string) []string
- func (s *ConnServer) GetConfig() *ServerConfig
- func (s *ConnServer) GetConnectedClients() []string
- func (s *ConnServer) GetEventManager() events.EventManager
- func (s *ConnServer) GetRoom(roomID string) (*Room, bool)
- func (s *ConnServer) JoinRoom(clientID, roomID string) error
- func (s *ConnServer) LeaveRoom(clientID, roomID string) error
- func (s *ConnServer) ListRooms() []string
- func (s *ConnServer) RegisterContextMessageHandler(messageType int64, handler ContextMessageHandler)
- func (s *ConnServer) RegisterMessageHandler(messageType int64, handler func(*message.Message) error)
- func (s *ConnServer) SendMessage(clientID string, msg *message.Message) error
- func (s *ConnServer) SetClientName(id, name string) error
- func (s *ConnServer) SetClientState(id string, state ClientState) error
- func (s *ConnServer) Shutdown()
- func (s *ConnServer) StartServer() error
- func (s *ConnServer) UpdateConfig(config *ServerConfig)
- func (s *ConnServer) WaitForShutdown()
- type ContextMessageHandler
- type Room
- type ServerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClientStateToString ¶
func ClientStateToString(state ClientState) string
ClientStateToString converts a ClientState to string
Types ¶
type ClientState ¶
type ClientState int
ClientState represents the current state of a client connection
const ( ClientStateConnecting ClientState = iota ClientStateConnected ClientStateAuthenticated ClientStateDisconnected )
type ConnClient ¶
type ConnClient struct {
Id string
Name string
Conn connection.GameConnection
AckManager *message.AckManager
State ClientState
ConnectedAt time.Time
LastActivity time.Time
Rooms map[string]bool
// contains filtered or unexported fields
}
Represents a client connection with enhanced session management
type ConnServer ¶
type ConnServer struct {
// contains filtered or unexported fields
}
Represents a Server Connection, of which we could have several with different ports or encodings, like TCP vs websocket server
func NewServer ¶
func NewServer(host, port string) *ConnServer
func NewServerWithConfig ¶
func NewServerWithConfig(config *ServerConfig) *ConnServer
func NewTCPAndWebSocketServer ¶
func NewTCPAndWebSocketServer(host, tcpPort, wsPort string) *ConnServer
NewTCPAndWebSocketServer creates a server with both TCP and WebSocket support
func NewWebSocketServer ¶
func NewWebSocketServer(host, tcpPort, wsPort string) *ConnServer
NewWebSocketServer creates a server with WebSocket support enabled
func (*ConnServer) AuthenticateClient ¶
func (s *ConnServer) AuthenticateClient(clientID, username, password, method string) error
AuthenticateClient performs authentication and triggers events
func (*ConnServer) BroadcastMessage ¶
func (s *ConnServer) BroadcastMessage(msg *message.Message) error
BroadcastMessage broadcasts a message to all connected clients
func (*ConnServer) BroadcastToRoom ¶
func (s *ConnServer) BroadcastToRoom(roomID string, msg *message.Message) error
BroadcastToRoom sends a message to all clients in a specific room
func (*ConnServer) CreateRoom ¶
func (s *ConnServer) CreateRoom(id, name, description string) error
CreateRoom creates a new room/channel
func (*ConnServer) DeleteRoom ¶
func (s *ConnServer) DeleteRoom(roomID string) error
DeleteRoom removes a room and removes all clients from it
func (*ConnServer) GetClient ¶
func (s *ConnServer) GetClient(id string) (*ConnClient, bool)
GetClient returns a client by ID
func (*ConnServer) GetClientCount ¶
func (s *ConnServer) GetClientCount() int
GetClientCount returns the number of connected clients
func (*ConnServer) GetClientRooms ¶
func (s *ConnServer) GetClientRooms(clientID string) []string
GetClientRooms returns all rooms a client is in
func (*ConnServer) GetConfig ¶
func (s *ConnServer) GetConfig() *ServerConfig
GetConfig returns the server configuration
func (*ConnServer) GetConnectedClients ¶
func (s *ConnServer) GetConnectedClients() []string
GetConnectedClients returns a list of connected client IDs
func (*ConnServer) GetEventManager ¶
func (s *ConnServer) GetEventManager() events.EventManager
GetEventManager returns the event manager
func (*ConnServer) GetRoom ¶
func (s *ConnServer) GetRoom(roomID string) (*Room, bool)
GetRoom returns a room by ID
func (*ConnServer) JoinRoom ¶
func (s *ConnServer) JoinRoom(clientID, roomID string) error
JoinRoom adds a client to a room
func (*ConnServer) LeaveRoom ¶
func (s *ConnServer) LeaveRoom(clientID, roomID string) error
LeaveRoom removes a client from a room
func (*ConnServer) ListRooms ¶
func (s *ConnServer) ListRooms() []string
ListRooms returns all room IDs
func (*ConnServer) RegisterContextMessageHandler ¶
func (s *ConnServer) RegisterContextMessageHandler(messageType int64, handler ContextMessageHandler)
RegisterContextMessageHandler registers a custom message handler that includes client context
func (*ConnServer) RegisterMessageHandler ¶
func (s *ConnServer) RegisterMessageHandler(messageType int64, handler func(*message.Message) error)
RegisterMessageHandler registers a custom message handler for a specific message type
func (*ConnServer) SendMessage ¶
func (s *ConnServer) SendMessage(clientID string, msg *message.Message) error
SendMessage sends a message to a client with acknowledgment tracking (public method)
func (*ConnServer) SetClientName ¶
func (s *ConnServer) SetClientName(id, name string) error
SetClientName sets the name for a client
func (*ConnServer) SetClientState ¶
func (s *ConnServer) SetClientState(id string, state ClientState) error
SetClientState sets the state for a client
func (*ConnServer) Shutdown ¶
func (s *ConnServer) Shutdown()
Shutdown gracefully shuts down the server
func (*ConnServer) StartServer ¶
func (s *ConnServer) StartServer() error
StartServer starts the server and begins accepting connections
func (*ConnServer) UpdateConfig ¶
func (s *ConnServer) UpdateConfig(config *ServerConfig)
UpdateConfig updates the server configuration (some settings require restart)
func (*ConnServer) WaitForShutdown ¶
func (s *ConnServer) WaitForShutdown()
WaitForShutdown waits for the server to complete shutdown
type ContextMessageHandler ¶
ContextMessageHandler is a message handler that receives client context
type Room ¶
type Room struct {
ID string
Name string
Description string
Clients map[string]*ConnClient
CreatedAt time.Time
// contains filtered or unexported fields
}
Room represents a channel/room for targeted messaging
type ServerConfig ¶
type ServerConfig struct {
Host string
Port string
WebSocketPort string // Optional WebSocket port
MaxConnections int
ConnectionTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
HeartbeatInterval time.Duration
ClientInactivityTimeout time.Duration
MaxRooms int
MaxClientsPerRoom int
EnableWebSocket bool // Enable WebSocket server
// Rate limiting configuration
RateLimitEnabled bool
MaxConnectionsPerIP int
RateLimitWindow time.Duration
MaxConnectionsPerSecond int
}
ServerConfig holds configuration options for the server
func DefaultServerConfig ¶
func DefaultServerConfig() *ServerConfig
DefaultServerConfig returns a server configuration with sensible defaults