Documentation
¶
Index ¶
- Constants
- type Client
- type ClientOption
- func WithAuth(username, password string) ClientOption
- func WithCallback(callback func([]byte)) ClientOption
- func WithCompression(enabled bool) ClientOption
- func WithDebugCallback(callback func(string)) ClientOption
- func WithSession(id string, sequence uint64) ClientOption
- func WithUnsequencedCallback(callback func([]byte)) ClientOption
- type DebugPacket
- type Header
- type HeartbeatPacket
- type LoginAcceptedPacket
- type LoginRejectedPacket
- type LoginRequestPacket
- type LogoutRequestPacket
- type Packet
- type SequencedDataPacket
- type Server
- type ServerOption
- type UnsequencedDataPacket
Constants ¶
const ( PacketTypeLoginRequest = 'L' PacketLengthLoginRequest = 52 PacketTypeLoginAccepted = 'A' PacketLengthLoginAccepted = 31 PacketTypeLoginRejected = 'J' PacketLengthLoginRejected = 2 PacketTypeLogoutRequest = 'O' PacketLengthLogoutRequest = 1 PacketTypeClientHeartbeat = 'R' PacketLengthClientHeartbeat = 1 PacketTypeServerHeartbeat = 'H' PacketLengthServerHeartbeat = 1 PacketTypeEndOfSession = 'Z' PacketLengthEndOfSession = 1 // Variable length packets PacketTypeSequencedData = 'S' PacketTypeUnsequencedData = 'U' PacketTypeDebug = '+' LoginRejectedNotAuthorized = 'A' )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(addr string, opts ...ClientOption) *Client
NewClient creates a new soupbintcp client. The default parameters can be configured using ClientOptions passed in as parameters
func (*Client) CurrentSequenceNumber ¶
CurrentSequenceNumber returns the client's current sequence number
func (*Client) CurrentSession ¶
CurrentSession returns the current session id
func (*Client) Login ¶
Login will try to connect to a new session and start receiving the first message If you want to connect to a specific session, use WithSession() in the NewClient options
func (*Client) Receive ¶
func (c *Client) Receive()
Receive will start listening for packets from the Server. Any sequenced or unsequenced data packets will be passed to your PacketCallback function. Receive will also attempt to automatically reconnect to the Server and rejoin the previous session with the current message sequence number. Receive will block until an end of session packet is received.
func (*Client) SendDebugMessage ¶
SendDebugMessage sends a debug packet with human readable text to the Server. Not normally used.
type ClientOption ¶
type ClientOption func(client *Client)
func WithAuth ¶
func WithAuth(username, password string) ClientOption
WithAuth sets the username and password to use when connecting to the Server
func WithCallback ¶
func WithCallback(callback func([]byte)) ClientOption
WithCallback sets the callback function for every sequenced packet received
func WithCompression ¶
func WithCompression(enabled bool) ClientOption
WithCompression allows you to enable soupbintcp (zlib) compression mode
func WithDebugCallback ¶
func WithDebugCallback(callback func(string)) ClientOption
WithDebugCallback sets the callback function for every debug packet received. Not normally used
func WithSession ¶
func WithSession(id string, sequence uint64) ClientOption
WithSession sets the initial session and sequence number when connecting to the Server
func WithUnsequencedCallback ¶
func WithUnsequencedCallback(callback func([]byte)) ClientOption
WithUnsequencedCallback sets the callback function for every unsequenced packet received
type DebugPacket ¶
func (DebugPacket) Bytes ¶
func (p DebugPacket) Bytes() []byte
type HeartbeatPacket ¶
type HeartbeatPacket struct {
Header
}
type LoginAcceptedPacket ¶
func (LoginAcceptedPacket) Bytes ¶
func (p LoginAcceptedPacket) Bytes() []byte
type LoginRejectedPacket ¶
func (LoginRejectedPacket) Bytes ¶
func (p LoginRejectedPacket) Bytes() []byte
type LoginRequestPacket ¶
type LoginRequestPacket struct { Header Username [6]byte Password [10]byte Session [10]byte SequenceNumber [20]byte HeartbeatTimeout [5]byte }
func (LoginRequestPacket) Bytes ¶
func (p LoginRequestPacket) Bytes() []byte
type LogoutRequestPacket ¶
type LogoutRequestPacket struct {
Header
}
type SequencedDataPacket ¶
func (SequencedDataPacket) Bytes ¶
func (p SequencedDataPacket) Bytes() []byte
type Server ¶
type Server struct { // LoginCallback is called for every login request. The username and password is supplied for you to perform additional auth logic LoginCallback func(username, password string) bool // PacketCallback is called for every unsequenced packet received from a client. The byte slice parameter contains just the message and should // be parsed by a higher level protocol PacketCallback func([]byte) // DebugCallback is called for every debug packet received from a client. This is not normally used. DebugCallback func([]byte) // contains filtered or unexported fields }
func NewServer ¶
func NewServer(opts ...ServerOption) *Server
func (*Server) CreateSession ¶
CreateSession creates a new session. There can only be one active session at a time
func (*Server) DeleteSession ¶
DeleteSession deletes an active session
func (*Server) ListenAndServe ¶
func (*Server) SendToSession ¶
SendToSession adds data to the session that will eventually be broadcast to all clients connected to the session. A session must first have been created with CreateSession
type ServerOption ¶
type ServerOption func(s *Server)
func WithLoginCallback ¶
func WithLoginCallback(callback func(username, password string) bool) ServerOption
func WithPacketCallback ¶
func WithPacketCallback(callback func([]byte)) ServerOption
func WithServerDebugCallback ¶
func WithServerDebugCallback(callback func([]byte)) ServerOption
type UnsequencedDataPacket ¶
func (UnsequencedDataPacket) Bytes ¶
func (p UnsequencedDataPacket) Bytes() []byte