more minor refactoring

This commit is contained in:
CPunch 2023-08-23 18:37:57 -05:00
parent 458e907c99
commit dcb86e2518
2 changed files with 14 additions and 16 deletions

View File

@ -76,7 +76,7 @@ func (server *LoginServer) Login(peer *protocol.CNPeer, pkt protocol.Packet) err
// client is resending a login packet??
if peer.AccountID != -1 {
SendError(LOGIN_ERROR)
return fmt.Errorf("Out of order P_CL2LS_REQ_LOGIN!")
return fmt.Errorf("out of order P_CL2LS_REQ_LOGIN")
}
// attempt login
@ -155,7 +155,7 @@ func (server *LoginServer) SaveCharacterName(peer *protocol.CNPeer, pkt protocol
if peer.AccountID == -1 {
peer.Send(protocol.P_LS2CL_REP_SAVE_CHAR_NAME_FAIL, protocol.SP_LS2CL_REP_SAVE_CHAR_NAME_FAIL{})
return fmt.Errorf("Out of order P_LS2CL_REP_SAVE_CHAR_NAME_FAIL!")
return fmt.Errorf("out of order P_LS2CL_REP_SAVE_CHAR_NAME_FAIL")
}
// TODO: sanity check SzFirstName && SzLastName
@ -260,7 +260,7 @@ func (server *LoginServer) ShardSelect(peer *protocol.CNPeer, pkt protocol.Packe
shards := server.redisHndlr.GetShards()
if len(shards) == 0 {
SendFail(peer)
return fmt.Errorf("LoginServer has found no linked shards!")
return fmt.Errorf("loginServer has found no linked shards")
}
key, err := protocol.GenSerialKey()

View File

@ -81,20 +81,18 @@ func (server *LoginServer) Start() {
}
func (server *LoginServer) handleEvents() {
for {
select {
case event := <-server.eRecv:
for event := range server.eRecv {
switch event.Type {
case protocol.EVENT_CLIENT_DISCONNECT:
server.disconnect(event.Peer)
case protocol.EVENT_CLIENT_PACKET:
defer pool.Put(event.Pkt)
if err := server.handlePacket(event.Peer, event.PktID, protocol.NewPacket(event.Pkt)); err != nil {
log.Printf("Error handling packet: %v", err)
event.Peer.Kill()
}
}
// the packet is given to us by the event, so we'll need to make sure to return it to the pool
pool.Put(event.Pkt)
}
}
}