connections

package
v0.9.7 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultScreenWidth is the default width of the screen
	DefaultScreenWidth = 80
	// DefaultScreenHeight is the default height of the screen
	DefaultScreenHeight = 24
)
View Source
const ReadBufferSize = 1024

Variables

View Source
var (
	ErrNotWebsocket = errors.New("connection is not a websocket")
	ErrWriteFailed  = errors.New("failed to write message")
)
View Source
var DefaultHeartbeatConfig = HeartbeatConfig{
	PongWait:   60 * time.Second,
	PingPeriod: (60 * time.Second * 9) / 10,
	WriteWait:  10 * time.Second,
}

Functions

func ActiveConnectionCount

func ActiveConnectionCount() int

make this more efficient later

func Cleanup

func Cleanup()

func IsWebsocket

func IsWebsocket(id ConnectionId) bool

func Kick

func Kick(id ConnectionId, reason string) (err error)

func OverwriteClientSettings

func OverwriteClientSettings(id ConnectionId, cs ClientSettings)

func Remove

func Remove(id ConnectionId) (err error)

func SendTo

func SendTo(b []byte, ids ...ConnectionId)

func SetShutdownChan

func SetShutdownChan(osSignalChan chan os.Signal)

make this more efficient later

func SignalShutdown

func SignalShutdown(s os.Signal)

func Stats

func Stats() (connections uint64, disconnections uint64)

Types

type ClientInput

type ClientInput struct {
	ConnectionId  ConnectionId // Who does this belong to?
	DataIn        []byte       // What was the last thing they typed?
	Buffer        []byte       // What is the current buffer
	Clipboard     []byte       // Text that can be easily pasted with ctrl-v
	LastSubmitted []byte       // The last thing submitted
	EnterPressed  bool         // Did they hit enter? It's stripped from the buffer/input FYI
	BSPressed     bool         // Did they hit backspace?
	TabPressed    bool         // Did they hit tab?
	History       InputHistory // A list of the last 10 things they typed
}

A structure to package up everything we need to know about this input.

func (*ClientInput) Reset

func (ci *ClientInput) Reset()

Reset the client input to essentially "No current input"

type ClientSettings

type ClientSettings struct {
	Display DisplaySettings
	// Is MSP enabled?
	MSPEnabled        bool // Do they accept sound in their client?
	SendTelnetGoAhead bool // Defaults false, should we send a IAC GA after prompts?
}

func GetClientSettings

func GetClientSettings(id ConnectionId) ClientSettings

func (ClientSettings) IsMsp

func (c ClientSettings) IsMsp() bool

type ConnectState

type ConnectState uint32
const (
	Login ConnectState = iota
	LoggedIn
	Zombie
	MaxHistory = 10
)

type ConnectionDetails

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

func Add

func Add(conn net.Conn, wsConn *websocket.Conn) *ConnectionDetails

func Get

Returns the total number of connections

func NewConnectionDetails

func NewConnectionDetails(connId ConnectionId, c net.Conn, wsC *websocket.Conn, config *HeartbeatConfig) *ConnectionDetails

func (*ConnectionDetails) AddInputHandler

func (cd *ConnectionDetails) AddInputHandler(name string, newInputHandler InputHandler, after ...string)

func (*ConnectionDetails) Close

func (cd *ConnectionDetails) Close()

func (*ConnectionDetails) ConnectionId

func (cd *ConnectionDetails) ConnectionId() ConnectionId

get for uniqueId

func (*ConnectionDetails) HandleInput

func (cd *ConnectionDetails) HandleInput(ci *ClientInput, handlerState map[string]any) (doNextHandler bool, lastHandler string, err error)

If HandleInput receives an error, we shouldn't pass input to the game logic

func (*ConnectionDetails) InputDisabled

func (cd *ConnectionDetails) InputDisabled(setTo ...bool) bool

func (*ConnectionDetails) IsLocal

func (cd *ConnectionDetails) IsLocal() bool

func (*ConnectionDetails) IsWebSocket

func (cd *ConnectionDetails) IsWebSocket() bool

func (*ConnectionDetails) Read

func (cd *ConnectionDetails) Read(p []byte) (n int, err error)

func (*ConnectionDetails) RemoteAddr

func (cd *ConnectionDetails) RemoteAddr() net.Addr

func (*ConnectionDetails) RemoveInputHandler

func (cd *ConnectionDetails) RemoveInputHandler(name string)

func (*ConnectionDetails) SetState

func (cd *ConnectionDetails) SetState(state ConnectState)

func (*ConnectionDetails) StartHeartbeat

func (cd *ConnectionDetails) StartHeartbeat(config HeartbeatConfig) error

func (*ConnectionDetails) State

func (cd *ConnectionDetails) State() ConnectState

set and get for state

func (*ConnectionDetails) Write

func (cd *ConnectionDetails) Write(p []byte) (n int, err error)

type ConnectionId

type ConnectionId = uint64

func Broadcast

func Broadcast(colorizedText []byte, skipConnectionIds ...ConnectionId) []ConnectionId

func GetAllConnectionIds

func GetAllConnectionIds() []ConnectionId

type DisplaySettings

type DisplaySettings struct {
	ScreenWidth  uint32
	ScreenHeight uint32
}

func (DisplaySettings) GetScreenHeight

func (c DisplaySettings) GetScreenHeight() int

func (DisplaySettings) GetScreenWidth

func (c DisplaySettings) GetScreenWidth() int

type HeartbeatConfig

type HeartbeatConfig struct {
	PongWait   time.Duration
	PingPeriod time.Duration
	WriteWait  time.Duration
}

type InputHandler

type InputHandler func(ci *ClientInput, handlerState map[string]any) (doNextHandler bool)

type InputHistory

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

func (*InputHistory) Add

func (ih *InputHistory) Add(input []byte)

func (*InputHistory) Get

func (ih *InputHistory) Get() []byte

func (*InputHistory) InHistory

func (ih *InputHistory) InHistory() bool

func (*InputHistory) Next

func (ih *InputHistory) Next()

func (*InputHistory) Position

func (ih *InputHistory) Position() int

returns position and whether position is not the last item

func (*InputHistory) Previous

func (ih *InputHistory) Previous()

func (*InputHistory) ResetPosition

func (ih *InputHistory) ResetPosition()

Jump to

Keyboard shortcuts

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