iguagile

package
v0.0.0-...-c6caa78 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2023 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Inbound = iota
	Outbound
)

Traffic

View Source
const (
	NewConnect = iota
	ExitConnect
)

Message types

Variables

View Source
var ErrInvalidDataFormat = errors.New("invalid data length")

ErrInvalidDataFormat is when given unknown data.

View Source
var ErrPortIsOutOfRange = fmt.Errorf("port is out of range")

ErrPortIsOutOfRange is invalid ports request.

Functions

This section is empty.

Types

type BinaryData

type BinaryData struct {
	Traffic     int
	ID          []byte
	Target      byte
	MessageType byte
	Payload     []byte
}

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.

func NewClient

func NewClient(room *Room, conn io.ReadWriteCloser) (*Client, error)

NewClient is Client constructed.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection.

func (*Client) GetID

func (c *Client) GetID() int

GetID is getter for id.

func (*Client) GetIDByte

func (c *Client) GetIDByte() []byte

GetIDByte is getter for idByte.

func (*Client) Send

func (c *Client) Send(message []byte)

Send is enqueue outbound messages.

type ClientManager

type ClientManager struct {
	*sync.Mutex
	// contains filtered or unexported fields
}

ClientManager manages clients.

func NewClientManager

func NewClientManager() *ClientManager

NewClientManager is ClientManager constructed.

func (*ClientManager) Add

func (m *ClientManager) Add(client *Client) error

Add the client.

func (*ClientManager) Clear

func (m *ClientManager) Clear()

Clear all clients.

func (*ClientManager) Count

func (m *ClientManager) Count() int

Count clients.

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.

func (*ClientManager) Remove

func (m *ClientManager) Remove(clientID int)

Remove the client.

type GameObject

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

GameObject is object to be synchronized.

type GameObjectManager

type GameObjectManager struct {
	*sync.Mutex
	// contains filtered or unexported fields
}

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) Clear

func (m *GameObjectManager) Clear()

Clear all GameObjects.

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) Free

func (g *IDGenerator) Free(id int) error

Free deallocates the id.

func (*IDGenerator) Generate

func (g *IDGenerator) Generate() (int, error)

Generate generates a id.

type RPCBufferManager

type RPCBufferManager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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) Clear

func (m *RPCBufferManager) Clear()

Clear all rpc messages.

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 NewRedis

func NewRedis(hostname string) (*Redis, error)

NewRedis is a constructor of Redis. Perform initialization at once.

func (*Redis) Close

func (r *Redis) Close() error

Close is a method to release resources collectively.

func (*Redis) GenerateServerID

func (r *Redis) GenerateServerID() (int, error)

GenerateServerID is a method to number unique ServerID.

func (*Redis) RegisterRoom

func (r *Redis) RegisterRoom(room *pb.Room) error

RegisterRoom register room to redis.

func (*Redis) RegisterServer

func (r *Redis) RegisterServer(server *pb.Server) error

RegisterServer registers server to redis.

func (*Redis) UnregisterRoom

func (r *Redis) UnregisterRoom(room *pb.Room) error

UnregisterRoom unregisters room from redis.

func (*Redis) UnregisterServer

func (r *Redis) UnregisterServer(server *pb.Server) error

UnregisterServer unregisters server 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.

func (*RelayService) Receive

func (s *RelayService) Receive(senderID int, data []byte) error

Receive receives data and sends to all clients.

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) Close

func (r *Room) Close() error

Close closes all client connections.

func (*Room) CloseConnection

func (r *Room) CloseConnection(client *Client)

CloseConnection closes the connection and unregisters the client.

func (*Room) SendToAllClients

func (r *Room) SendToAllClients(senderID int, message []byte)

SendToAllClients sends outbound message to all registered clients.

func (*Room) SendToClient

func (r *Room) SendToClient(targetID, senderID int, message []byte)

SendToClient sends outbound message to the client.

func (*Room) SendToHost

func (r *Room) SendToHost(senderID int, message []byte)

SendToHost sends outbound message to the host.

func (*Room) SendToOtherClients

func (r *Room) SendToOtherClients(senderID int, message []byte)

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.

type Store

type Store interface {
	Close() error
	GenerateServerID() (int, error)
	RegisterServer(*pb.Server) error
	UnregisterServer(*pb.Server) error
	RegisterRoom(*pb.Room) error
	UnregisterRoom(*pb.Room) error
}

Store is an interface for connecting to backend storage and storing data.

Jump to

Keyboard shortcuts

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