Documentation
¶
Index ¶
- Constants
- Variables
- func ActiveConnectionCount() int
- func Cleanup()
- func IsWebsocket(id ConnectionId) bool
- func Kick(id ConnectionId, reason string) (err error)
- func OverwriteClientSettings(id ConnectionId, cs ClientSettings)
- func Remove(id ConnectionId) (err error)
- func SendTo(b []byte, ids ...ConnectionId)
- func SetShutdownChan(osSignalChan chan os.Signal)
- func SignalShutdown(s os.Signal)
- func Stats() (connections uint64, disconnections uint64)
- type ClientInput
- type ClientSettings
- type ConnectState
- type ConnectionDetails
- func (cd *ConnectionDetails) AddInputHandler(name string, newInputHandler InputHandler, after ...string)
- func (cd *ConnectionDetails) Close()
- func (cd *ConnectionDetails) ConnectionId() ConnectionId
- func (cd *ConnectionDetails) HandleInput(ci *ClientInput, handlerState map[string]any) (doNextHandler bool, lastHandler string, err error)
- func (cd *ConnectionDetails) InputDisabled(setTo ...bool) bool
- func (cd *ConnectionDetails) IsLocal() bool
- func (cd *ConnectionDetails) IsWebSocket() bool
- func (cd *ConnectionDetails) Read(p []byte) (n int, err error)
- func (cd *ConnectionDetails) RemoteAddr() net.Addr
- func (cd *ConnectionDetails) RemoveInputHandler(name string)
- func (cd *ConnectionDetails) SetState(state ConnectState)
- func (cd *ConnectionDetails) StartHeartbeat(config HeartbeatConfig) error
- func (cd *ConnectionDetails) State() ConnectState
- func (cd *ConnectionDetails) Write(p []byte) (n int, err error)
- type ConnectionId
- type DisplaySettings
- type HeartbeatConfig
- type InputHandler
- type InputHistory
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 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 ¶
make this more efficient later
func SignalShutdown ¶
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 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) 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
type ConnectionId ¶
type ConnectionId = uint64
func Broadcast ¶
func Broadcast(colorizedText []byte, skipConnectionIds ...ConnectionId) []ConnectionId
func GetAllConnectionIds ¶
func GetAllConnectionIds() []ConnectionId
type DisplaySettings ¶
func (DisplaySettings) GetScreenHeight ¶
func (c DisplaySettings) GetScreenHeight() int
func (DisplaySettings) GetScreenWidth ¶
func (c DisplaySettings) GetScreenWidth() int
type HeartbeatConfig ¶
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()
Click to show internal directories.
Click to hide internal directories.