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

View File

@ -81,20 +81,18 @@ func (server *LoginServer) Start() {
} }
func (server *LoginServer) handleEvents() { func (server *LoginServer) handleEvents() {
for { for event := range server.eRecv {
select { switch event.Type {
case event := <-server.eRecv: case protocol.EVENT_CLIENT_DISCONNECT:
switch event.Type { server.disconnect(event.Peer)
case protocol.EVENT_CLIENT_DISCONNECT: case protocol.EVENT_CLIENT_PACKET:
server.disconnect(event.Peer) if err := server.handlePacket(event.Peer, event.PktID, protocol.NewPacket(event.Pkt)); err != nil {
case protocol.EVENT_CLIENT_PACKET: log.Printf("Error handling packet: %v", err)
defer pool.Put(event.Pkt) event.Peer.Kill()
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)
} }
} }
} }