mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-12 15:04:38 +01:00
add invalidateSessions
This commit is contained in:
@@ -207,6 +207,7 @@ func (s *Server) Start() error {
|
|||||||
|
|
||||||
go s.acceptClients()
|
go s.acceptClients()
|
||||||
go s.manageSessions()
|
go s.manageSessions()
|
||||||
|
go s.invalidateSessions()
|
||||||
|
|
||||||
// Start the discord bot for chat integration.
|
// Start the discord bot for chat integration.
|
||||||
if s.erupeConfig.Discord.Enabled && s.discordBot != nil {
|
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.
|
// BroadcastMHF queues a MHFPacket to be sent to all sessions.
|
||||||
func (s *Server) BroadcastMHF(pkt mhfpacket.MHFPacket, ignoredSession *Session) {
|
func (s *Server) BroadcastMHF(pkt mhfpacket.MHFPacket, ignoredSession *Session) {
|
||||||
// Broadcast the data.
|
// Broadcast the data.
|
||||||
|
|||||||
@@ -174,10 +174,6 @@ 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
|
||||||
|
|||||||
Reference in New Issue
Block a user