add invalidateSessions

This commit is contained in:
wish
2025-02-18 03:16:18 +11:00
parent b3305d1185
commit 7c61f70590
2 changed files with 11 additions and 4 deletions

View File

@@ -207,6 +207,7 @@ func (s *Server) Start() error {
go s.acceptClients()
go s.manageSessions()
go s.invalidateSessions()
// Start the discord bot for chat integration.
if s.erupeConfig.Discord.Enabled && s.discordBot != nil {
@@ -278,6 +279,16 @@ func (s *Server) manageSessions() {
}
}
func (s *Server) invalidateSessions() {
for _, session := range s.sessions {
if time.Now().Add(-30 * time.Second).After(session.lastPacket) {
s.logger.Info("Session timeout", zap.String("Name", session.Name))
logoutPlayer(session)
}
}
time.Sleep(30 * time.Second)
}
// BroadcastMHF queues a MHFPacket to be sent to all sessions.
func (s *Server) BroadcastMHF(pkt mhfpacket.MHFPacket, ignoredSession *Session) {
// Broadcast the data.

View File

@@ -174,10 +174,6 @@ 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