This commit is contained in:
shoopea 2021-11-07 00:53:22 +08:00
parent 63b7d31a8a
commit 40df5ba19b
2 changed files with 18 additions and 21 deletions

19
ttd.go
View File

@ -235,6 +235,7 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
//logInfoDebug("Server.Poll() : AdminPacketServerClientInfo :\n- ClientID: %d\n- Address: %s\n- Name: %s\n- Lang: %d\n- Date: %d\n- CompanyID: %d", sp.ClientID, sp.Address, sp.Name, sp.Lang, sp.Date, sp.CompanyID) //logInfoDebug("Server.Poll() : AdminPacketServerClientInfo :\n- ClientID: %d\n- Address: %s\n- Name: %s\n- Lang: %d\n- Date: %d\n- CompanyID: %d", sp.ClientID, sp.Address, sp.Name, sp.Lang, sp.Date, sp.CompanyID)
clt := &ClientTTD{ clt := &ClientTTD{
ClientID: sp.ClientID, ClientID: sp.ClientID,
CompanyID: 255,
} }
if _, ok := s.Status.Clients[sp.ClientID]; ok { if _, ok := s.Status.Clients[sp.ClientID]; ok {
clt = s.Status.Clients[sp.ClientID] clt = s.Status.Clients[sp.ClientID]
@ -275,7 +276,11 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
cc.Online = true cc.Online = true
bot.SendChat(cfg.Telegram.ChatID, fmt.Sprintf("@%s playing.", cc.Username)) bot.SendChat(cfg.Telegram.ChatID, fmt.Sprintf("@%s playing.", cc.Username))
} else { } else {
bot.SendChat(cfg.Telegram.ChatID, fmt.Sprintf("%s unclaimed. Please /register to claim the company", s.Status.Companies[sp.CompanyID].Name)) if co, ok := s.Status.Companies[sp.CompanyID]; ok {
if co.ClientID == 0 {
bot.SendChat(cfg.Telegram.ChatID, fmt.Sprintf("Company '%s' unclaimed. Please /register to claim the company", s.Status.Companies[sp.CompanyID].Name))
}
}
} }
} else if clt.CompanyID != 255 && cfg.CompanyIsRegistered(clt.CompanyID) { } else if clt.CompanyID != 255 && cfg.CompanyIsRegistered(clt.CompanyID) {
cc := cfg.GetCompanyClient(clt.CompanyID) cc := cfg.GetCompanyClient(clt.CompanyID)
@ -298,15 +303,6 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
} }
sp.Read(buffer[:p.PLength]) sp.Read(buffer[:p.PLength])
logInfoDebug("Server.Poll() : AdminPacketServerClientQuit :\n- ClientID: %d", sp.ClientID) logInfoDebug("Server.Poll() : AdminPacketServerClientQuit :\n- ClientID: %d", sp.ClientID)
if len(s.Status.Clients) == 2 && !srv.Status.Paused {
if cfg.CompanyIsRegistered(s.Status.Clients[sp.ClientID].CompanyID) {
cc := cfg.GetCompanyClient(s.Status.Clients[sp.ClientID].CompanyID)
bot.SendChat(cfg.Telegram.ChatID, fmt.Sprintf("@%s leaving. Game paused.", cc.Username))
cc.Online = false
} else {
bot.SendChat(cfg.Telegram.ChatID, fmt.Sprintf("%s leaving. Game paused.", s.Status.Clients[sp.ClientID].Name))
}
} else {
if cfg.CompanyIsRegistered(s.Status.Clients[sp.ClientID].CompanyID) { if cfg.CompanyIsRegistered(s.Status.Clients[sp.ClientID].CompanyID) {
cc := cfg.GetCompanyClient(s.Status.Clients[sp.ClientID].CompanyID) cc := cfg.GetCompanyClient(s.Status.Clients[sp.ClientID].CompanyID)
bot.SendChat(cfg.Telegram.ChatID, fmt.Sprintf("@%s leaving.", cc.Username)) bot.SendChat(cfg.Telegram.ChatID, fmt.Sprintf("@%s leaving.", cc.Username))
@ -314,7 +310,6 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
} else { } else {
bot.SendChat(cfg.Telegram.ChatID, fmt.Sprintf("%s leaving.", s.Status.Clients[sp.ClientID].Name)) bot.SendChat(cfg.Telegram.ChatID, fmt.Sprintf("%s leaving.", s.Status.Clients[sp.ClientID].Name))
} }
}
delete(s.Status.Clients, sp.ClientID) delete(s.Status.Clients, sp.ClientID)
case AdminPacketServerCompanyNew: case AdminPacketServerCompanyNew:
sp := PacketServerCompanyNew{ sp := PacketServerCompanyNew{
@ -325,6 +320,7 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
c := &CompanyTTD{ c := &CompanyTTD{
CompanyID: sp.CompanyID, CompanyID: sp.CompanyID,
FirstSeen: time.Now(), FirstSeen: time.Now(),
ClientID: 0,
} }
s.Status.Companies[sp.CompanyID] = c s.Status.Companies[sp.CompanyID] = c
case AdminPacketServerCompanyInfo: case AdminPacketServerCompanyInfo:
@ -336,6 +332,7 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
c := &CompanyTTD{ c := &CompanyTTD{
CompanyID: sp.CompanyID, CompanyID: sp.CompanyID,
FirstSeen: time.Now(), FirstSeen: time.Now(),
ClientID: 0,
} }
if _, ok := s.Status.Companies[sp.CompanyID]; !ok { if _, ok := s.Status.Companies[sp.CompanyID]; !ok {
s.Status.Companies[sp.CompanyID] = c s.Status.Companies[sp.CompanyID] = c

View File

@ -1,6 +1,6 @@
// Code generated by version.sh (@generated) DO NOT EDIT. // Code generated by version.sh (@generated) DO NOT EDIT.
package main package main
var githash = "f85da9b" var githash = "63b7d31"
var buildstamp = "2021-11-06_16:26:28" var buildstamp = "2021-11-06_16:52:50"
var commits = "162" var commits = "164"
var version = "f85da9b-b162 - 2021-11-06_16:26:28" var version = "63b7d31-b164 - 2021-11-06_16:52:50"