mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-14 07:55:33 +01:00
test session timeout
This commit is contained in:
@@ -32,6 +32,7 @@ type Session struct {
|
|||||||
cryptConn *network.CryptConn
|
cryptConn *network.CryptConn
|
||||||
sendPackets chan packet
|
sendPackets chan packet
|
||||||
clientContext *clientctx.ClientContext
|
clientContext *clientctx.ClientContext
|
||||||
|
lastPacket time.Time
|
||||||
|
|
||||||
userEnteredStage bool // If the user has entered a stage before
|
userEnteredStage bool // If the user has entered a stage before
|
||||||
stageID string
|
stageID string
|
||||||
@@ -73,6 +74,7 @@ func NewSession(server *Server, conn net.Conn) *Session {
|
|||||||
cryptConn: network.NewCryptConn(conn),
|
cryptConn: network.NewCryptConn(conn),
|
||||||
sendPackets: make(chan packet, 20),
|
sendPackets: make(chan packet, 20),
|
||||||
clientContext: &clientctx.ClientContext{}, // Unused
|
clientContext: &clientctx.ClientContext{}, // Unused
|
||||||
|
lastPacket: time.Now(),
|
||||||
sessionStart: TimeAdjusted().Unix(),
|
sessionStart: TimeAdjusted().Unix(),
|
||||||
stageMoveStack: stringstack.New(),
|
stageMoveStack: stringstack.New(),
|
||||||
}
|
}
|
||||||
@@ -160,6 +162,10 @@ func (s *Session) sendLoop() {
|
|||||||
|
|
||||||
func (s *Session) recvLoop() {
|
func (s *Session) recvLoop() {
|
||||||
for {
|
for {
|
||||||
|
if time.Now().Add(-30 * time.Second).After(s.lastPacket) {
|
||||||
|
logoutPlayer(s)
|
||||||
|
return
|
||||||
|
}
|
||||||
if s.closed {
|
if s.closed {
|
||||||
logoutPlayer(s)
|
logoutPlayer(s)
|
||||||
return
|
return
|
||||||
@@ -181,6 +187,7 @@ func (s *Session) recvLoop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) handlePacketGroup(pktGroup []byte) {
|
func (s *Session) handlePacketGroup(pktGroup []byte) {
|
||||||
|
s.lastPacket = time.Now()
|
||||||
bf := byteframe.NewByteFrameFromBytes(pktGroup)
|
bf := byteframe.NewByteFrameFromBytes(pktGroup)
|
||||||
opcodeUint16 := bf.ReadUint16()
|
opcodeUint16 := bf.ReadUint16()
|
||||||
opcode := network.PacketID(opcodeUint16)
|
opcode := network.PacketID(opcodeUint16)
|
||||||
|
|||||||
Reference in New Issue
Block a user