misc. db.GetPlayers() result is now truncated

This commit is contained in:
CPunch 2023-03-11 03:28:11 -06:00
parent c62ed5d101
commit cbe308a0bd
3 changed files with 21 additions and 13 deletions

View File

@ -5,7 +5,7 @@ import (
"sync"
)
var allocator = sync.Pool{
var allocator = &sync.Pool{
New: func() any { return new(bytes.Buffer) },
}

View File

@ -105,9 +105,14 @@ func (server *LoginServer) Login(peer *Peer, pkt protocol.Packet) error {
return err
}
// truncate plrs
if len(plrs) > 3 {
plrs = plrs[:4]
}
// build character list
charInfo := make([]protocol.SP_LS2CL_REP_CHAR_INFO, 0, 4)
for _, plr := range plrs {
charInfo := [4]protocol.SP_LS2CL_REP_CHAR_INFO{}
for i, plr := range plrs {
PCStyle, PCStyle2 := util.Player2PCStyle(&plr)
info := protocol.SP_LS2CL_REP_CHAR_INFO{
ISlot: int8(plr.Slot),
@ -126,10 +131,10 @@ func (server *LoginServer) Login(peer *Peer, pkt protocol.Packet) error {
}
copy(info.AEquip[:], AEquip)
charInfo = append(charInfo, info)
charInfo[i] = info
}
return server.AcceptLogin(peer, loginPkt.SzID, loginPkt.IClientVerC, 1, charInfo)
return server.AcceptLogin(peer, loginPkt.SzID, loginPkt.IClientVerC, 1, charInfo[:len(plrs)])
}
func (server *LoginServer) CheckCharacterName(peer *Peer, pkt protocol.Packet) error {
@ -191,6 +196,7 @@ func validateCharacterCreation(character *protocol.SP_CL2LS_REQ_CHAR_CREATE) boo
return false
}
// TODO: sanity check items in SOn_Item; see db.FinishPlayer()
return true
}

View File

@ -24,15 +24,15 @@ type PeerHandler interface {
}
type Peer struct {
Player *db.Player
conn net.Conn
handler PeerHandler
SzID string
E_key []byte
FE_key []byte
SzID string
AccountID int
Player *db.Player
handler PeerHandler
conn net.Conn
alive bool
whichKey int
alive bool
}
func NewPeer(handler PeerHandler, conn net.Conn) *Peer {
@ -50,14 +50,15 @@ func NewPeer(handler PeerHandler, conn net.Conn) *Peer {
}
func (peer *Peer) Send(typeID uint32, data ...interface{}) error {
// grab buffer from pool
buf := pool.Get()
defer pool.Put(buf) // always return the buffer to the pool
defer pool.Put(buf)
// body start
pkt := protocol.NewPacket(buf)
// encode type id
if err := pkt.Encode(uint32(typeID)); err != nil {
if err := pkt.Encode(typeID); err != nil {
return err
}
@ -117,8 +118,9 @@ func (peer *Peer) Handler() {
return
}
// read packet body
// grab buffer && read packet body
buf := pool.Get()
defer pool.Put(buf)
if _, err := buf.ReadFrom(io.LimitReader(peer.conn, int64(sz))); err != nil {
log.Printf("[FATAL] failed to read packet body! %v", err)
return