entry

package
v0.0.3-glicko2 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InviteExpireSec = 60 * 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group interface {
	// ID returns the unique group id.
	ID() int64

	// Base returns the base information of the group.
	// Here we define a concrete struct `GroupBase`
	// to hold the common fields to avoid lots getter and setter method.
	Base() *GroupBase

	// IsFull checks if the group is full.
	IsFull() bool

	// SetCaptain sets the captain of the group.
	SetCaptain(Player)

	// GetCaptain returns the captain in the group.
	GetCaptain() Player

	// CanPlayTogether checks if the player can play with the group's players.
	CanPlayTogether(*pto.PlayerInfo) error

	// GetPlayerInfos 获取队伍用户信息
	GetPlayerInfos() pto.GroupUser

	// CanStartMatch checks if the group can start to match.
	CanStartMatch() bool
}

Group represents a group of players.

type GroupBase

type GroupBase struct {
	GroupID       int64
	GameMode      constant.GameMode
	ModeVersion   int64
	MatchStrategy constant.MatchStrategy

	// Do not do synchronization at this layer,
	// leave it to the caller to handle it uniformly,
	// to avoid deadlocks.
	sync.RWMutex

	// MatchID is a unique id to identify each match action.
	MatchID string

	// Settings holds the settings of the group.
	Settings GroupSettings

	// Configs holds the config of the group.
	Configs GroupConfig
	// contains filtered or unexported fields
}

GroupBase holds the common fields of a Group for all kinds of game mode and match strategy.

func NewGroupBase

func NewGroupBase(
	groupID int64, playerLimit int, playerBase *PlayerBase,
) *GroupBase

NewGroupBase creates a new GroupBase.

func (*GroupBase) AddInviteRecord

func (g *GroupBase) AddInviteRecord(inviteeUID string, nowUnix int64)

func (*GroupBase) AddPlayer

func (g *GroupBase) AddPlayer(p Player) error

func (*GroupBase) AllowNearbyJoin

func (g *GroupBase) AllowNearbyJoin() bool

func (*GroupBase) AllowRecentJoin

func (g *GroupBase) AllowRecentJoin() bool

func (*GroupBase) Base

func (g *GroupBase) Base() *GroupBase

func (*GroupBase) CanPlayTogether

func (g *GroupBase) CanPlayTogether(info *pto.PlayerInfo) error

func (*GroupBase) CanStartMatch

func (g *GroupBase) CanStartMatch() bool

func (*GroupBase) CheckState

func (g *GroupBase) CheckState(valids ...GroupState) error

func (*GroupBase) ClearPlayers

func (g *GroupBase) ClearPlayers()

func (*GroupBase) DelInviteRecord

func (g *GroupBase) DelInviteRecord(inviteeUID string)

func (*GroupBase) GetCaptain

func (g *GroupBase) GetCaptain() Player

func (*GroupBase) GetInviteExpireTimeStamp

func (g *GroupBase) GetInviteExpireTimeStamp(uid string) int64

func (*GroupBase) GetInviteRecords

func (g *GroupBase) GetInviteRecords() map[string]int64

func (*GroupBase) GetPlayerInfos

func (g *GroupBase) GetPlayerInfos() pto.GroupUser

func (*GroupBase) GetPlayers

func (g *GroupBase) GetPlayers() []Player

func (*GroupBase) GetState

func (g *GroupBase) GetState() GroupState

func (*GroupBase) ID

func (g *GroupBase) ID() int64

func (*GroupBase) IsFull

func (g *GroupBase) IsFull() bool

func (*GroupBase) IsInviteExpired

func (g *GroupBase) IsInviteExpired(uid string, nowUnix int64) bool

func (*GroupBase) PlayerExists

func (g *GroupBase) PlayerExists(uid string) bool

func (*GroupBase) PlayerLimit

func (g *GroupBase) PlayerLimit() int

func (*GroupBase) RemovePlayer

func (g *GroupBase) RemovePlayer(p Player) (empty bool)

func (*GroupBase) SetAllowNearbyJoin

func (g *GroupBase) SetAllowNearbyJoin(allow bool)

func (*GroupBase) SetAllowRecentJoin

func (g *GroupBase) SetAllowRecentJoin(allow bool)

func (*GroupBase) SetCaptain

func (g *GroupBase) SetCaptain(p Player)

func (*GroupBase) SetState

func (g *GroupBase) SetState(s GroupState)

func (*GroupBase) UIDs

func (g *GroupBase) UIDs() []string

type GroupConfig

type GroupConfig struct {
	PlayerLimit     int
	InviteExpireSec int64
}

type GroupRole

type GroupRole int8
const (
	GroupRoleMember  GroupRole = 0
	GroupRoleCaptain GroupRole = 1
)

type GroupSettings

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

GroupSettings defines the settings of a group.

type GroupState

type GroupState int8
const (
	GroupStateInvite    GroupState = 0
	GroupStateMatch     GroupState = 1
	GroupStateGame      GroupState = 2
	GroupStateDissolved GroupState = 3
)

type Player

type Player interface {
	Base() *PlayerBase
	UID() string
	GetPlayerInfo() *pto.PlayerInfo
}

Player represents a player in a Group.

type PlayerBase

type PlayerBase struct {
	sync.RWMutex

	GroupID int64

	VoiceState PlayerVoiceState

	// TODO: other common attributes
	pto.PlayerInfo
	// contains filtered or unexported fields
}

PlayerBase holds the common fields of a Player for all kinds of game mode and match strategy.

func NewPlayerBase

func NewPlayerBase(info *pto.PlayerInfo) *PlayerBase

func (*PlayerBase) Base

func (p *PlayerBase) Base() *PlayerBase

func (*PlayerBase) CheckOnlineState

func (p *PlayerBase) CheckOnlineState(valids ...PlayerOnlineState) error

CheckOnlineState checks if the player is in a valid online state.

func (*PlayerBase) GetOnlineState

func (p *PlayerBase) GetOnlineState() PlayerOnlineState

func (*PlayerBase) GetPlayerInfo

func (p *PlayerBase) GetPlayerInfo() *pto.PlayerInfo

func (*PlayerBase) GetVoiceState

func (p *PlayerBase) GetVoiceState() PlayerVoiceState

func (*PlayerBase) SetOnlineState

func (p *PlayerBase) SetOnlineState(s PlayerOnlineState)

func (*PlayerBase) SetVoiceState

func (p *PlayerBase) SetVoiceState(s PlayerVoiceState)

func (*PlayerBase) UID

func (p *PlayerBase) UID() string

type PlayerOnlineState

type PlayerOnlineState int8

PlayerOnlineState is the state of a player. TODO: try to use state machine to manage player state.

const (
	PlayerOnlineStateOffline  PlayerOnlineState = 0
	PlayerOnlineStateOnline   PlayerOnlineState = 1
	PlayerOnlineStateInGroup  PlayerOnlineState = 2
	PlayerOnlineStateInMatch  PlayerOnlineState = 3
	PlayerOnlineStateInGame   PlayerOnlineState = 4
	PlayerOnlineStateInSettle PlayerOnlineState = 5
)

type PlayerVoiceState

type PlayerVoiceState int8

PlayerVoiceState is the voice state of a player.

const (
	PlayerVoiceStateMute   PlayerVoiceState = 0
	PlayerVoiceStateUnmute PlayerVoiceState = 1
)

type Room

type Room interface {
	Base() *RoomBase
	ID() int64
	GetMatchInfo() *pto.MatchInfo
}

type RoomBase

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

func NewRoomBase

func NewRoomBase(id int64, t Team) *RoomBase

func (*RoomBase) AddTeam

func (r *RoomBase) AddTeam(t Team)

func (*RoomBase) Base

func (r *RoomBase) Base() *RoomBase

func (*RoomBase) GetMatchInfo

func (r *RoomBase) GetMatchInfo() *pto.MatchInfo

func (*RoomBase) GetTeams

func (r *RoomBase) GetTeams() []Team

func (*RoomBase) ID

func (r *RoomBase) ID() int64

func (*RoomBase) RemoveTeam

func (r *RoomBase) RemoveTeam(id int64)

type Team

type Team interface {
	Base() *TeamBase
	ID() int64
}

type TeamBase

type TeamBase struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewTeamBase

func NewTeamBase(id int64, g Group) *TeamBase

func (*TeamBase) AddGroup

func (t *TeamBase) AddGroup(g Group)

func (*TeamBase) Base

func (t *TeamBase) Base() *TeamBase

func (*TeamBase) GameMode

func (t *TeamBase) GameMode() constant.GameMode

func (*TeamBase) GetGroups

func (t *TeamBase) GetGroups() []Group

func (*TeamBase) ID

func (t *TeamBase) ID() int64

func (*TeamBase) MatchStrategy

func (t *TeamBase) MatchStrategy() constant.MatchStrategy

func (*TeamBase) RemoveGroup

func (t *TeamBase) RemoveGroup(id int64)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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