ingress

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClientTypeWS = iota
	ClientTypeENet
)
View Source
const (
	NetworkStatusConnected = iota
	NetworkStatusDisconnected
)
View Source
const (
	// Server -> client
	InfoOp int = iota
	ServerConnectedOp
	ServerDisconnectedOp
	ServerResponseOp
	AuthSucceededOp
	AuthFailedOp
	ChatOp
	// Client -> server
	ConnectOp
	DisconnectOp
	CommandOp
	DiscordCodeOp
	// server -> client OR client -> server
	PacketOp
)
View Source
const (
	CLIENT_MESSAGE_LIMIT int = 16
)

Variables

This section is empty.

Functions

func WriteTimeout

func WriteTimeout(ctx context.Context, timeout time.Duration, c *websocket.Conn, msg []byte) error

Types

type AuthSucceededMessage

type AuthSucceededMessage struct {
	Op         int // AuthSucceededOp
	Code       string
	PrivateKey string
}

type ChatMessage

type ChatMessage struct {
	Op      int // ChatOp
	Message string
}

type ClientID

type ClientID uint32

A unique identifier for this client for the lifetime of their session.

type ClientType

type ClientType uint8

type ClusterCommand

type ClusterCommand struct {
	Command  string
	Response chan CommandResult
}

type CommandMessage

type CommandMessage struct {
	Op      int // CommandOp
	Command string
	// Uniquely identifies the command so we can send a response
	Id int
}

Issuing a cluster command on behalf of the user.

type CommandResult

type CommandResult struct {
	Err error
}

type ConnectMessage

type ConnectMessage struct {
	Op int // ConnectOp
	// One of the servers hosted by the cluster
	Target string
}

Connect the client to a server

type Connection

type Connection interface {
	Session() *utils.Session

	// Lasts for the duration of the client's connection to its ingress.
	NetworkStatus() NetworkStatus
	Host() string
	Type() ClientType
	DeviceType() string
	// Tell the client that we've connected
	Connect(name string, isHidden bool, shouldCopy bool)
	// Messages going to the client
	Send(packet io.RawPacket) <-chan error
	// Messages going to the server
	ReceivePackets() <-chan io.RawPacket
	// Clients can issue commands out-of-band
	// Commands sent in ordinary game packets are interpreted anyway
	ReceiveCommands() <-chan ClusterCommand
	// When the client disconnects on its own
	ReceiveDisconnect() <-chan bool
	// Forcibly disconnect this client
	Disconnect(reason int, message string)
	Destroy()
}

type DiscordCodeMessage

type DiscordCodeMessage struct {
	Op   int // DiscordCodeOp or AuthFailedOp
	Code string
}

type ENetClient

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

func NewENetClient

func NewENetClient() *ENetClient

func (*ENetClient) Connect

func (c *ENetClient) Connect(name string, isHidden bool, shouldCopy bool)

func (*ENetClient) Destroy

func (c *ENetClient) Destroy()

func (*ENetClient) DeviceType

func (c *ENetClient) DeviceType() string

func (*ENetClient) Disconnect

func (c *ENetClient) Disconnect(reason int, message string)

func (*ENetClient) Host

func (c *ENetClient) Host() string

func (*ENetClient) NetworkStatus

func (c *ENetClient) NetworkStatus() NetworkStatus

func (*ENetClient) Poll

func (c *ENetClient) Poll(ctx context.Context)

func (*ENetClient) ReceiveCommands

func (c *ENetClient) ReceiveCommands() <-chan ClusterCommand

func (*ENetClient) ReceiveDisconnect

func (c *ENetClient) ReceiveDisconnect() <-chan bool

func (*ENetClient) ReceivePackets

func (c *ENetClient) ReceivePackets() <-chan io.RawPacket

func (*ENetClient) Send

func (c *ENetClient) Send(packet io.RawPacket) <-chan error

func (*ENetClient) ServerChanged

func (c *ENetClient) ServerChanged(target string)

func (*ENetClient) Session

func (c *ENetClient) Session() *utils.Session

func (*ENetClient) Type

func (c *ENetClient) Type() ClientType

type ENetIngress

type ENetIngress struct {

	// Run when a client joins
	InitialCommand string
	// contains filtered or unexported fields
}

func NewENetIngress

func NewENetIngress(newClients chan Connection) *ENetIngress

func (*ENetIngress) AddClient

func (server *ENetIngress) AddClient(s *ENetClient)

func (*ENetIngress) FindClientForPeer

func (server *ENetIngress) FindClientForPeer(peer *enet.Peer) *ENetClient

func (*ENetIngress) Poll

func (server *ENetIngress) Poll(ctx context.Context)

func (*ENetIngress) RemoveClient

func (server *ENetIngress) RemoveClient(client *ENetClient)

func (*ENetIngress) Serve

func (server *ENetIngress) Serve(port int) error

func (*ENetIngress) Shutdown

func (server *ENetIngress) Shutdown()

type GenericMessage

type GenericMessage struct {
	Op int
}

type InfoMessage

type InfoMessage struct {
	Op int // InfoOp
	// All of the servers from the master (real Sauerbraten servers.)
	Master []ServerInfo
	// All of the servers this cluster hosts.
	Cluster []string
}

Contains information on servers this cluster contains and real ones from the master.

type NetworkStatus

type NetworkStatus uint8

The status of the client's connection to the cluster.

type PacketACK

type PacketACK struct {
	Packet io.RawPacket
	Error  chan error
}

type PacketMessage

type PacketMessage struct {
	Op      int // ServerPacketOp or ClientPacketOp
	Channel int
	Data    []byte
	Length  int
}

Contains a packet from the server a client is connected to.

type ResponseMessage

type ResponseMessage struct {
	Op       int // ServerResponseOp
	Success  bool
	Response string
	// Uniquely identifies the command so we can send a response
	Id int
}

type ServerConnectedMessage

type ServerConnectedMessage struct {
	Op     int // ServerConnectedOp
	Server string
	// Whether to put the server in the URL or not
	Internal bool
	// Whether this is the user's server
	Owned bool
}

type ServerDisconnectedMessage

type ServerDisconnectedMessage struct {
	Op      int // ServerDisconnectedOp
	Message string
	Reason  int
}

type ServerInfo

type ServerInfo struct {
	Host   string
	Port   int
	Info   []byte
	Length int
}

type WSClient

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

func NewWSClient

func NewWSClient() *WSClient

func (*WSClient) Connect

func (c *WSClient) Connect(name string, isHidden bool, shouldCopy bool)

func (*WSClient) Destroy

func (c *WSClient) Destroy()

func (*WSClient) DeviceType

func (c *WSClient) DeviceType() string

func (*WSClient) Disconnect

func (c *WSClient) Disconnect(reason int, message string)

func (*WSClient) Host

func (c *WSClient) Host() string

func (*WSClient) NetworkStatus

func (c *WSClient) NetworkStatus() NetworkStatus

func (*WSClient) ReceiveCommands

func (c *WSClient) ReceiveCommands() <-chan ClusterCommand

func (*WSClient) ReceiveDisconnect

func (c *WSClient) ReceiveDisconnect() <-chan bool

func (*WSClient) ReceivePackets

func (c *WSClient) ReceivePackets() <-chan io.RawPacket

func (*WSClient) Send

func (c *WSClient) Send(packet io.RawPacket) <-chan error

func (*WSClient) SendGlobalChat

func (c *WSClient) SendGlobalChat(message string)

func (*WSClient) Session

func (c *WSClient) Session() *utils.Session

func (*WSClient) Type

func (c *WSClient) Type() ClientType

type WSIngress

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

func NewWSIngress

func NewWSIngress(newClients chan Connection) *WSIngress

func (*WSIngress) AddClient

func (server *WSIngress) AddClient(s *WSClient)

func (*WSIngress) Broadcast

func (server *WSIngress) Broadcast(msg []byte)

func (*WSIngress) BuildBroadcast

func (server *WSIngress) BuildBroadcast() ([]byte, error)

func (*WSIngress) HandleClient

func (server *WSIngress) HandleClient(ctx context.Context, c *websocket.Conn, host string, deviceType string) error

func (*WSIngress) HandleLogin

func (server *WSIngress) HandleLogin(ctx context.Context, client *WSClient, code string)

func (*WSIngress) RemoveClient

func (server *WSIngress) RemoveClient(client *WSClient)

func (*WSIngress) ServeHTTP

func (server *WSIngress) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*WSIngress) Shutdown

func (server *WSIngress) Shutdown(ctx context.Context)

func (*WSIngress) StartWatcher

func (server *WSIngress) StartWatcher(ctx context.Context)

Jump to

Keyboard shortcuts

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