caching

package
v0.0.0-...-bf66d8f Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTableNotFound            = errors.New("table not found")
	ErrClientAlreadyJoinedTable = errors.New("client already joined table")
	ErrCouldntCreateTable       = errors.New("couldn't create table")
	ErrObjectNotFound           = errors.New("one table object wasn't found")
)

Errors

View Source
var GamesMap = map[string]games.Game{}

Functions

func AddObjectToTable

func AddObjectToTable(room string, object *TableObject) error

* Object helpers

func CloseCaches

func CloseCaches()

func CloseSession

func CloseSession(sessionId string) bool

func CreateRoom

func CreateRoom(roomId string, data string)

CreateRoom creates a room in the cache

func DeleteConnection

func DeleteConnection(connId string)

TODO: Create a test for all deletion functions

func DeleteRoom

func DeleteRoom(roomID string)

DeleteRoom deletes a room from the cache

func EnterUDP

func EnterUDP(roomID string, connectionId string, clientId string, addr *net.UDPAddr, key *[]byte) bool

JoinRoom adds a member to a room in the cache

func ForwardGameEvent

func ForwardGameEvent(sessionId string, event games.EventContext) bool

func GetAllAdapters

func GetAllAdapters(room string) ([]string, bool)

Get all adapters from a room

func GetSession

func GetSession(sessionId string) (games.GameSession, bool)

func JoinRoom

func JoinRoom(roomID string, connectionId string) bool

JoinRoom adds a member to a room in the cache

func JoinSession

func JoinSession(connId string, sessionId string) bool

func JoinTable

func JoinTable(room string, client string) error

* Table management

func LeaveTable

func LeaveTable(room string, client string) error

func ModifyTableObject

func ModifyTableObject(room string, objectId string, data string, width float64, height float64) error

func MoveTableObject

func MoveTableObject(room string, objectId string, x, y float64) error

func OpenGameSession

func OpenGameSession(connId string, clientId string, roomId string, gameId string) (games.GameSession, bool)

func RemoveMember

func RemoveMember(roomID string, connectionId string) bool

func RemoveObjectFromTable

func RemoveObjectFromTable(room string, object string) error

func RotateTableObject

func RotateTableObject(room string, objectId string, rotation float64) error

func SaveConnections

func SaveConnections(roomId string, connections RoomConnections) bool

Save changes in a room

func SelectTableObject

func SelectTableObject(room string, objectId string, client string) error

func SetGameState

func SetGameState(sessionId string, state int) (games.GameSession, bool)

func SetMemberData

func SetMemberData(roomID string, connectionId string, clientId string, data string) bool

Sets the member data

func SetRoomData

func SetRoomData(roomID string, data string) bool

func SetupMemory

func SetupMemory()

func StartGameSession

func StartGameSession(sessionId string) bool

func TableMembers

func TableMembers(room string) (bool, []string)

func TestRooms

func TestRooms(t *testing.T)

TestRooms tests the caching of rooms

Types

type Connection

type Connection struct {
	ID             string
	Room           string
	ClientID       string
	CurrentSession string
	UDP            *net.UDPAddr
	Key            []byte
	Cipher         cipher.Block
}

func EmptyConnection

func EmptyConnection(connId string, room string) Connection

func GetConnection

func GetConnection(connId string) (Connection, bool)

func VerifyUDP

func VerifyUDP(clientId string, udp net.Addr, hash []byte, voice []byte) (Connection, bool)

packetHash = encrypted hash included in the packet by the client hash = computed hash of the packet

func (*Connection) KeyBase64

func (c *Connection) KeyBase64() string

type ReturnableMember

type ReturnableMember struct {
	ID       string `json:"id"` // Syntax: data:clientID
	Muted    bool   `json:"muted"`
	Deafened bool   `json:"deafened"`
}

TODO: Implement as standard

type Room

type Room struct {
	Mutex    *sync.Mutex
	ID       string   // Account ID of the owner
	Data     string   // Encrypted room data
	Sessions []string // List of game session ids
	Start    int64    // Timestamp of when the room was created
}

func GetRoom

func GetRoom(roomID string) (Room, bool)

GetRoom gets a room from the cache

type RoomConnection

type RoomConnection struct {
	Connected      bool
	Connection     *net.UDPAddr
	Adapter        string
	Key            *[]byte
	ClientID       string
	CurrentSession string
	Data           string

	//* Client status
	Muted    bool
	Deafened bool
}

func (*RoomConnection) ToReturnableMember

func (r *RoomConnection) ToReturnableMember() ReturnableMember

type RoomConnections

type RoomConnections map[string]RoomConnection

Member (Connection) ID -> Connections

func GetAllConnections

func GetAllConnections(room string) (RoomConnections, bool)

Get all connections from a room

type TableData

type TableData struct {
	Mutex      *sync.Mutex
	Room       string
	Members    []string
	ObjectList []string         // List of all object ids
	Objects    *ristretto.Cache // Cache for all objects on the table (Object ID -> Object)
}

func GetTable

func GetTable(room string) (bool, *TableData)

type TableObject

type TableObject struct {
	ID        string  `json:"id"`
	LocationX float64 `json:"x"`
	LocationY float64 `json:"y"`
	Width     float64 `json:"w"`
	Height    float64 `json:"h"`
	Rotation  float64 `json:"r"`
	Type      int     `json:"t"`
	Creator   string  `json:"cr"` // ID of the creator
	Holder    string  `json:"ho"` // ID of the current card holder (others can't move/modify it while it's held)
	Data      string  `json:"d"`  // Encrypted
}

func GetTableObject

func GetTableObject(room string, objectId string) (*TableObject, bool)

func TableObjects

func TableObjects(room string) ([]*TableObject, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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