Skip to content

Commit

Permalink
minor session optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
sekaiwish committed Jan 11, 2024
1 parent 2685476 commit af29ee6
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions server/channelserver/sys_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,11 @@ func NewSession(server *Server, conn net.Conn) *Session {

// Start starts the session packet send and recv loop(s).
func (s *Session) Start() {
go func() {
s.logger.Debug("New connection", zap.String("RemoteAddr", s.rawConn.RemoteAddr().String()))
// Unlike the sign and entrance server,
// the client DOES NOT initalize the channel connection with 8 NULL bytes.
go s.sendLoop()
s.recvLoop()
}()
s.logger.Debug("New connection", zap.String("RemoteAddr", s.rawConn.RemoteAddr().String()))
// Unlike the sign and entrance server,
// the client DOES NOT initalize the channel connection with 8 NULL bytes.
go s.sendLoop()
go s.recvLoop()
}

// QueueSend queues a packet (raw []byte) to be sent.
Expand Down Expand Up @@ -150,16 +148,19 @@ func (s *Session) QueueAck(ackHandle uint32, data []byte) {
}

func (s *Session) sendLoop() {
var pkt packet
for {
if s.closed {
return
}
pkt := <-s.sendPackets
err := s.cryptConn.SendPacket(append(pkt.data, []byte{0x00, 0x10}...))
if err != nil {
s.logger.Warn("Failed to send packet")
for len(s.sendPackets) > 0 {
pkt = <-s.sendPackets
err := s.cryptConn.SendPacket(append(pkt.data, []byte{0x00, 0x10}...))
if err != nil {
s.logger.Warn("Failed to send packet")
}
}
time.Sleep(10 * time.Millisecond)
time.Sleep(5 * time.Millisecond)
}
}

Expand All @@ -178,14 +179,13 @@ func (s *Session) recvLoop() {
s.logger.Info(fmt.Sprintf("[%s] Disconnected", s.Name))
logoutPlayer(s)
return
}
if err != nil {
} else if err != nil {
s.logger.Warn("Error on ReadPacket, exiting recv loop", zap.Error(err))
logoutPlayer(s)
return
}
s.handlePacketGroup(pkt)
time.Sleep(10 * time.Millisecond)
time.Sleep(5 * time.Millisecond)
}
}

Expand Down

0 comments on commit af29ee6

Please sign in to comment.