Documentation ¶
Index ¶
- Constants
- Variables
- type BinaryData
- type Client
- type ClientManager
- func (m *ClientManager) Add(client *Client) error
- func (m *ClientManager) Clear()
- func (m *ClientManager) Count() int
- func (m *ClientManager) Exist(clientID int) bool
- func (m *ClientManager) First() (*Client, error)
- func (m *ClientManager) Get(clientID int) (*Client, error)
- func (m *ClientManager) GetAllClients() map[int]*Client
- func (m *ClientManager) Remove(clientID int)
- type GameObject
- type GameObjectManager
- func (m *GameObjectManager) Add(gameObject *GameObject) error
- func (m *GameObjectManager) Clear()
- func (m *GameObjectManager) Exist(objectID int) bool
- func (m *GameObjectManager) Get(objectID int) (*GameObject, error)
- func (m *GameObjectManager) GetAllGameObjects() map[int]*GameObject
- func (m *GameObjectManager) Remove(objectID int)
- type IDGenerator
- type RPCBufferManager
- type Redis
- type RelayService
- type RelayServiceFactory
- type Room
- func (r *Room) Close() error
- func (r *Room) CloseConnection(client *Client)
- func (r *Room) SendToAllClients(senderID int, message []byte)
- func (r *Room) SendToClient(targetID, senderID int, message []byte)
- func (r *Room) SendToHost(senderID int, message []byte)
- func (r *Room) SendToOtherClients(senderID int, message []byte)
- type RoomConfig
- type RoomServer
- type RoomService
- type RoomServiceFactory
- type Store
Constants ¶
const ( Inbound = iota Outbound )
Traffic
const ( NewConnect = iota ExitConnect )
Message types
Variables ¶
var ErrInvalidDataFormat = errors.New("invalid data length")
ErrInvalidDataFormat is when given unknown data.
var ErrPortIsOutOfRange = fmt.Errorf("port is out of range")
ErrPortIsOutOfRange is invalid ports request.
Functions ¶
This section is empty.
Types ¶
type BinaryData ¶
BinaryData is client and server data transfer format.
func NewInBoundData ¶
func NewInBoundData(b []byte) (*BinaryData, error)
NewInBoundData return a BinaryData struct parsed and formatted binary.
func NewOutBoundData ¶
func NewOutBoundData(b []byte) (*BinaryData, error)
NewOutBoundData return a BinaryData struct parsed and formatted binary.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a middleman between the connection and the room.
type ClientManager ¶
ClientManager manages clients.
func NewClientManager ¶
func NewClientManager() *ClientManager
NewClientManager is ClientManager constructed.
func (*ClientManager) Exist ¶
func (m *ClientManager) Exist(clientID int) bool
Exist checks the client exists.
func (*ClientManager) First ¶
func (m *ClientManager) First() (*Client, error)
First returns a first element.
func (*ClientManager) Get ¶
func (m *ClientManager) Get(clientID int) (*Client, error)
Get the client.
func (*ClientManager) GetAllClients ¶
func (m *ClientManager) GetAllClients() map[int]*Client
GetAllClients returns all clients.
type GameObject ¶
type GameObject struct {
// contains filtered or unexported fields
}
GameObject is object to be synchronized.
type GameObjectManager ¶
GameObjectManager manages GameObjects.
func NewGameObjectManager ¶
func NewGameObjectManager() *GameObjectManager
NewGameObjectManager is GameObjectManager constructed.
func (*GameObjectManager) Add ¶
func (m *GameObjectManager) Add(gameObject *GameObject) error
Add GameObject.
func (*GameObjectManager) Exist ¶
func (m *GameObjectManager) Exist(objectID int) bool
Exist checks the GameObject exists.
func (*GameObjectManager) Get ¶
func (m *GameObjectManager) Get(objectID int) (*GameObject, error)
Get GameObject.
func (*GameObjectManager) GetAllGameObjects ¶
func (m *GameObjectManager) GetAllGameObjects() map[int]*GameObject
GetAllGameObjects returns all GameObjects.
func (*GameObjectManager) Remove ¶
func (m *GameObjectManager) Remove(objectID int)
Remove GameObject.
type IDGenerator ¶
type IDGenerator struct {
// contains filtered or unexported fields
}
IDGenerator generates id.
func NewIDGenerator ¶
func NewIDGenerator() (*IDGenerator, error)
NewIDGenerator is IDGenerator constructed.
func (*IDGenerator) Generate ¶
func (g *IDGenerator) Generate() (int, error)
Generate generates a id.
type RPCBufferManager ¶
RPCBufferManager manages buffered rpc messages.
func NewRPCBufferManager ¶
func NewRPCBufferManager() *RPCBufferManager
NewRPCBufferManager is RPCBufferManger constructed.
func (*RPCBufferManager) Add ¶
func (m *RPCBufferManager) Add(message []byte, sender *Client)
Add new rpc message.
func (*RPCBufferManager) Remove ¶
func (m *RPCBufferManager) Remove(client *Client)
Remove rpc messages.
func (*RPCBufferManager) SendRPCBuffer ¶
func (m *RPCBufferManager) SendRPCBuffer(client *Client)
SendRPCBuffer sends all buffered rpc messages.
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
Redis is a structure that wraps goredis to make it easy to use.
func (*Redis) GenerateServerID ¶
GenerateServerID is a method to number unique ServerID.
func (*Redis) RegisterRoom ¶
RegisterRoom register room to redis.
func (*Redis) RegisterServer ¶
RegisterServer registers server to redis.
func (*Redis) UnregisterRoom ¶
UnregisterRoom unregisters room from redis.
type RelayService ¶
type RelayService struct {
// contains filtered or unexported fields
}
RelayService is a service relays data.
func (RelayService) Destroy ¶
func (s RelayService) Destroy() error
Destroy for implement RoomService.
func (RelayService) OnChangeHost ¶
func (s RelayService) OnChangeHost(_ int) error
OnChangeHost for implement RoomService.
func (*RelayService) OnRegisterClient ¶
func (s *RelayService) OnRegisterClient(_ int) error
OnRegisterClient for implement RoomService.
func (*RelayService) OnUnregisterClient ¶
func (s *RelayService) OnUnregisterClient(_ int) error
OnUnregisterClient for implement RoomService.
type RelayServiceFactory ¶
type RelayServiceFactory struct{}
RelayServiceFactory creates RelayService.
func (RelayServiceFactory) Create ¶
func (f RelayServiceFactory) Create(room *Room) (RoomService, error)
Create creates a EmptyRoomService.
type Room ¶
type Room struct {
// contains filtered or unexported fields
}
Room maintains the set of active clients and broadcasts messages to the clients.
func (*Room) CloseConnection ¶
CloseConnection closes the connection and unregisters the client.
func (*Room) SendToAllClients ¶
SendToAllClients sends outbound message to all registered clients.
func (*Room) SendToClient ¶
SendToClient sends outbound message to the client.
func (*Room) SendToHost ¶
SendToHost sends outbound message to the host.
func (*Room) SendToOtherClients ¶
SendToOtherClients sends outbound message to other registered clients.
type RoomConfig ¶
type RoomConfig struct { RoomID int ApplicationName string Version string Password string MaxUser int Info map[string]string Token []byte }
RoomConfig is room config.
type RoomServer ¶
type RoomServer struct { RoomUpdateDuration time.Duration ServerUpdateDuration time.Duration // contains filtered or unexported fields }
RoomServer is server manages rooms.
func NewRoomServer ¶
func NewRoomServer(factory RoomServiceFactory, store Store, address string) (*RoomServer, error)
NewRoomServer is a constructor of RoomServer.
func (*RoomServer) CreateRoom ¶
func (s *RoomServer) CreateRoom(ctx context.Context, request *pb.CreateRoomRequest) (*pb.CreateRoomResponse, error)
CreateRoom creates new room.
func (*RoomServer) Run ¶
func (s *RoomServer) Run(roomListener net.Listener, apiPort int) error
Run starts api and room server.
func (*RoomServer) Serve ¶
func (s *RoomServer) Serve(conn io.ReadWriteCloser) error
Serve handles requests from the peer.
type RoomService ¶
type RoomService interface { // Receive processes data sent from the client to the server. Receive(senderID int, data []byte) error // OnRegisterClient is called when the client connects to the room. OnRegisterClient(clientID int) error // OnUnregisterClient is called when the client disconnects from the room OnUnregisterClient(clientID int) error // OnChangeHost is called when the host changes. OnChangeHost(clientID int) error // Destroy is called when the room is destroyed. Destroy() error }
RoomService implements the processing performed by the room
type RoomServiceFactory ¶
type RoomServiceFactory interface { // Create creates a RoomService. Create(room *Room) (RoomService, error) }
RoomServiceFactory creates RoomServices.