Split the function of PlayerList and PingInfo

This commit is contained in:
Tnze
2021-12-15 12:24:30 +08:00
parent fe6fc3dc7b
commit f7bdf676cc
5 changed files with 154 additions and 45 deletions

View File

@ -3,31 +3,23 @@ package server
import (
"container/list"
"sync"
"github.com/Tnze/go-mc/chat"
)
// PlayerList is an implement of ListPingHandler based on linked-list.
// PlayerList is a player list based on linked-list.
// This struct should not be copied after used.
type PlayerList struct {
name string
protocol int
maxPlayer int
description *chat.Message
players *list.List
maxPlayer int
players *list.List
// Only the linked-list is protected by this Mutex.
// Because others field never change after created.
playersLock sync.Mutex
}
// NewPlayerList create a PlayerList which implement ListPingHandler.
func NewPlayerList(name string, protocol, maxPlayers int, motd *chat.Message) *PlayerList {
func NewPlayerList(maxPlayers int) *PlayerList {
return &PlayerList{
name: name,
protocol: protocol,
maxPlayer: maxPlayers,
description: motd,
players: list.New(),
maxPlayer: maxPlayers,
players: list.New(),
}
}
@ -50,14 +42,6 @@ func (p *PlayerList) TryInsert(player PlayerSample) (remove func()) {
}
}
func (p *PlayerList) Name() string {
return p.name
}
func (p *PlayerList) Protocol() int {
return p.protocol
}
func (p *PlayerList) MaxPlayer() int {
return p.maxPlayer
}
@ -84,7 +68,3 @@ func (p *PlayerList) PlayerSamples() (sample []PlayerSample) {
}
return
}
func (p *PlayerList) Description() *chat.Message {
return p.description
}