less talkative and better cleanup of stalled clients
This commit is contained in:
parent
37310c4d88
commit
440e45fc29
45
ttd.go
45
ttd.go
@ -383,12 +383,12 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
|
||||
}
|
||||
sp.Read(buffer[:p.PLength])
|
||||
|
||||
if sp.Message == "!unpause" {
|
||||
if sp.Message == "!unpause" || sp.Message == "unpause" {
|
||||
logInfoDebug("Server.Poll() : AdminPacketServerChat : Unpausing")
|
||||
clt := s.Status.Clients[sp.ClientID]
|
||||
clt.Paused = false
|
||||
s.Unpause()
|
||||
} else if sp.Message == "!pause" {
|
||||
} else if sp.Message == "!pause" || sp.Message == "pause" {
|
||||
logInfoDebug("Server.Poll() : AdminPacketServerChat : Pausing")
|
||||
clt := s.Status.Clients[sp.ClientID]
|
||||
clt.Paused = true
|
||||
@ -475,17 +475,8 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
|
||||
sp.Read(buffer[:p.PLength])
|
||||
|
||||
switch sp.Command {
|
||||
/*
|
||||
case "clients":
|
||||
for k, v := range s.Status.Clients {
|
||||
logInfoDebug("Server.Poll() : Client[%d] : %s - %d (%s)", k, v.Name, v.CompanyID, v.Address)
|
||||
}
|
||||
|
||||
case "companies":
|
||||
for k, v := range s.Status.Companies {
|
||||
logInfoDebug("Server.Poll() : Company[%d] : %s", k, v.Name)
|
||||
}
|
||||
*/
|
||||
case "pause":
|
||||
case "unpause":
|
||||
default:
|
||||
@ -578,6 +569,12 @@ func (s *ServerTTD) PruneClients() {
|
||||
for cltID, clt := range s.Status.Clients {
|
||||
if clt.LastSeen.Add(2 * updateHeartBeat).Before(time.Now()) {
|
||||
logInfoDebug("ServerTTD.PruneClients : deleting client #%d", cltID)
|
||||
if clt.CompanyID != 255 && cfg.CompanyIsRegistered(clt.CompanyID) {
|
||||
cc := cfg.GetCompanyClient(clt.CompanyID)
|
||||
if cc.Online {
|
||||
cc.Online = false
|
||||
}
|
||||
}
|
||||
delete(s.Status.Clients, cltID)
|
||||
}
|
||||
}
|
||||
@ -592,6 +589,28 @@ func (s *ServerTTD) PruneCompanies() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ServerTTD) UpdateConfigClients() {
|
||||
for _, cc := range cfg.Clients {
|
||||
if cc.Online {
|
||||
if cc.CompanyID != 255 {
|
||||
for coID, co := range s.Status.Companies {
|
||||
if coID == cc.CompanyID {
|
||||
hasClient := false
|
||||
for clID, _ := range s.Status.Clients {
|
||||
if clID == co.ClientID {
|
||||
hasClient = true
|
||||
}
|
||||
}
|
||||
if !hasClient {
|
||||
cc.Online = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ServerTTD) ComputeClientTime() {
|
||||
t := time.Now()
|
||||
daysNow := int(t.Sub(cfg.Game.StartDate).Hours() / 24)
|
||||
@ -673,7 +692,7 @@ func (s *ServerTTD) Pause() {
|
||||
err := s.Send(px.Bytes())
|
||||
|
||||
s.ComputeClientTime()
|
||||
bot.SendChat(cfg.Telegram.ChatID, "Game is paused.")
|
||||
//bot.SendChat(cfg.Telegram.ChatID, "Game is paused.")
|
||||
|
||||
s.Status.Paused = true
|
||||
logErrorDebug(err, "Server.Pause : Send()")
|
||||
@ -695,7 +714,7 @@ func (s *ServerTTD) Unpause() {
|
||||
err := s.Send(px.Bytes())
|
||||
|
||||
s.ComputeClientTime()
|
||||
bot.SendChat(cfg.Telegram.ChatID, "Game is unpaused.")
|
||||
//bot.SendChat(cfg.Telegram.ChatID, "Game is unpaused.")
|
||||
|
||||
s.Status.Paused = false
|
||||
logErrorDebug(err, "Server.Unpause : Send()")
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Code generated by version.sh (@generated) DO NOT EDIT.
|
||||
package main
|
||||
var githash = "69a6416"
|
||||
var buildstamp = "2021-11-13_06:38:27"
|
||||
var commits = "200"
|
||||
var version = "69a6416-b200 - 2021-11-13_06:38:27"
|
||||
var githash = "37310c4"
|
||||
var buildstamp = "2021-11-22_08:57:20"
|
||||
var commits = "201"
|
||||
var version = "37310c4-b201 - 2021-11-22_08:57:20"
|
||||
|
Loading…
Reference in New Issue
Block a user