Documentation
¶
Overview ¶
clients must make send request eventually or be considered disconnected package implements disconnect notification for all other clients in the same room
Index ¶
Constants ¶
View Source
const ( GET = http.MethodGet POST = http.MethodPost ClientDefaultTimeout = time.Second / 30 ClientLargeTimeout = time.Second * 5 ClientDefaultPingPeriod = time.Second / 10 ClientLostPingsNumber = 3 ServerDefaultRoomUpdatePeriod = ClientDefaultPingPeriod ServerDefaultLastSeenTimeout = 3 * ServerDefaultRoomUpdatePeriod )
View Source
const ( COMMAND_ROOMBROADCAST = "B" COMMAND_CLIENTREQUEST = "C" COMMAND_REQUESTSTATE = "S" )
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(opts ClientOpts) (*Client, error)
func (*Client) PauseReason ¶
func (c *Client) PauseReason() PauseReason
func (*Client) RequestNewState ¶
func (*Client) SendRequest ¶
func (*Client) SendRoomBroadcast ¶
type ClientOpts ¶
type ClientOpts struct {
//default ClientDefaultTimeout
Timeout time.Duration
//default ClientDefaultPingPeriod
PingPeriod time.Duration
Addr string
Room, Role string
//Specific self disconnect (server lost). may be needed later , but in general use Pause
OnReconnect func()
OnDisconnect func()
//Any reason's pause of game process (disconnect self, disconnect other, loading new state self or other
//Specific reason may be getted by PauseReason()
OnPause func()
OnUnpause func()
OnCommonSend func() []byte
OnCommonRecv func(data []byte, readOwnPart bool)
OnStateChanged func(wanted string)
//async, must close result chan then done
OnGetStateData func([]byte)
OnCommand func(command string)
}
type CommonResp ¶
type MetricResp ¶
type MetricResp struct {
RoomCount int
RoomNames []string
OnlineTotal int
RoomOnline map[string]int
States map[string]string
Second ServerMetricMsg
Total ServerMetricMsg
}
func (MetricResp) String ¶
func (m MetricResp) String() string
type PauseReason ¶
type PauseReason struct {
PingLost bool
IsFull bool
IsCoherent bool
CurState string
WantState string
}
func (PauseReason) String ¶
func (pr PauseReason) String() string
type RoomCheckGetSetter ¶
type RoomCheckGetSetter interface {
//mb role separation needed, but now Common and State data get full and common
GetRoomCommon(room string) ([]byte, error)
SetRoomCommon(room string, data []byte) error
IsValidState(room string, state string) bool
RdyStateData(room string, state string)
GetStateData(room string) []byte
OnCommand(room string, role string, command string)
OnKillRoom(roomname string)
}
Interface all-in-one for server implementation
type RoomState ¶
type RoomState struct {
//room specific
IsFull bool
IsCoherent bool
RdyServData bool
Wanted string
}
network.Server - network.Client ping response IsFull - all needed roles are online IsCoherent - state of room is confirmed by all roles RdyServData - Server downloaded data for new state (needed while not coherent) Wanted - Wanted state
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) AddCommand ¶
sends command to all clients in room
func (*Server) Metric ¶
func (s *Server) Metric() MetricResp
type ServerMetricMsg ¶
type ServerMetricMsg struct {
Ping, State, Common ServerReqMetric
}
func (*ServerMetricMsg) Add ¶
func (a *ServerMetricMsg) Add(b ServerMetricMsg)
func (ServerMetricMsg) String ¶
func (m ServerMetricMsg) String() string
type ServerOpts ¶
type ServerOpts struct {
Addr string
//hooks for server implementation
RoomServ RoomCheckGetSetter
StartState string
NeededRoles []string
RoomUpdatePeriod time.Duration
LastSeenTimeout time.Duration
ConsoleHandler func(w http.ResponseWriter, r *http.Request)
}
Options to create and start server
type ServerReqMetric ¶
type ServerReqMetric struct {
//requests per second
RPS int
//request.body bytes per second
ReqBPS int
//responce.body bytes per second
RespBPS int
}
func (*ServerReqMetric) Add ¶
func (a *ServerReqMetric) Add(b ServerReqMetric)
func (ServerReqMetric) String ¶
func (m ServerReqMetric) String() string
type StateDataResp ¶
Click to show internal directories.
Click to hide internal directories.