test session timeout

This commit is contained in:
wish
2023-03-11 01:08:21 +11:00
parent ab4669acc9
commit c110082ab5

View File

@@ -32,6 +32,7 @@ type Session struct {
cryptConn *network.CryptConn
sendPackets chan packet
clientContext *clientctx.ClientContext
lastPacket time.Time
userEnteredStage bool // If the user has entered a stage before
stageID string
@@ -73,6 +74,7 @@ func NewSession(server *Server, conn net.Conn) *Session {
cryptConn: network.NewCryptConn(conn),
sendPackets: make(chan packet, 20),
clientContext: &clientctx.ClientContext{}, // Unused
lastPacket: time.Now(),
sessionStart: TimeAdjusted().Unix(),
stageMoveStack: stringstack.New(),
}
@@ -160,6 +162,10 @@ func (s *Session) sendLoop() {
func (s *Session) recvLoop() {
for {
if time.Now().Add(-30 * time.Second).After(s.lastPacket) {
logoutPlayer(s)
return
}
if s.closed {
logoutPlayer(s)
return
@@ -181,6 +187,7 @@ func (s *Session) recvLoop() {
}
func (s *Session) handlePacketGroup(pktGroup []byte) {
s.lastPacket = time.Now()
bf := byteframe.NewByteFrameFromBytes(pktGroup)
opcodeUint16 := bf.ReadUint16()
opcode := network.PacketID(opcodeUint16)