crash fix for initialized map

This commit is contained in:
shoopea
2021-11-09 17:45:01 +08:00
parent a100fb6c68
commit 8d580181bf
4 changed files with 56 additions and 14 deletions

11
ttd.go
View File

@@ -348,7 +348,16 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
}
sp.Read(buffer[:p.PLength])
logInfoDebug("Server.Poll() : PacketServerCompanyUpdate :\n- CompanyID: %d\n- Name: %s\n- President: %s\n- Protected: %t", sp.CompanyID, sp.Name, sp.President, sp.Protected)
c := s.Status.Companies[sp.CompanyID]
c := &CompanyTTD{
CompanyID: sp.CompanyID,
FirstSeen: time.Now(),
ClientID: 0,
}
if _, ok := s.Status.Companies[sp.CompanyID]; !ok {
s.Status.Companies[sp.CompanyID] = c
} else {
c = s.Status.Companies[sp.CompanyID]
}
c.Name = sp.Name
c.FirstSeen = time.Now()
c.LastSeen = time.Now()