crash fix for initialized map
This commit is contained in:
parent
a100fb6c68
commit
8d580181bf
14
bot.go
14
bot.go
@ -57,6 +57,8 @@ func (b *Bot) BotHandlers() {
|
||||
b.bot.Handle("/companies", botCompanies)
|
||||
b.bot.Handle("/clients", botClients)
|
||||
b.bot.Handle("/players", botPlayers)
|
||||
b.bot.Handle("/give", botGive)
|
||||
b.bot.Handle("/take", botTake)
|
||||
|
||||
b.bot.Handle(tb.OnPhoto, botPhoto)
|
||||
b.bot.Handle(tb.OnChannelPost, botChannelPost)
|
||||
@ -151,13 +153,13 @@ func botPlayers(m *tb.Message) {
|
||||
online := ""
|
||||
for _, cc := range cfg.Clients {
|
||||
if cc.Online {
|
||||
online = online + fmt.Sprintf(" - @%s (%s) : %s", cc.Username, cc.TimeLeft, srv.Status.Companies[cc.CompanyID].Name) + "\r\n"
|
||||
online = online + fmt.Sprintf(" - %s (%s) : %s", cc.Username, cc.TimeLeft, srv.Status.Companies[cc.CompanyID].Name) + "\r\n"
|
||||
}
|
||||
}
|
||||
offline := ""
|
||||
for _, cc := range cfg.Clients {
|
||||
if _, ok := srv.Status.Companies[cc.CompanyID]; ok && !cc.Online {
|
||||
offline = offline + fmt.Sprintf(" - @%s (%s) : %s", cc.Username, cc.TimeLeft, srv.Status.Companies[cc.CompanyID].Name) + "\r\n"
|
||||
offline = offline + fmt.Sprintf(" - %s (%s) : %s", cc.Username, cc.TimeLeft, srv.Status.Companies[cc.CompanyID].Name) + "\r\n"
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,6 +173,14 @@ func botPlayers(m *tb.Message) {
|
||||
bot.SendChat(m.Chat.ID, str)
|
||||
}
|
||||
|
||||
func botGive(m *tb.Message) {
|
||||
PrintText(m)
|
||||
}
|
||||
|
||||
func botTake(m *tb.Message) {
|
||||
PrintText(m)
|
||||
}
|
||||
|
||||
func botDeregister(m *tb.Message) {
|
||||
cc, ok := cfg.Clients[m.Sender.ID]
|
||||
if !ok {
|
||||
|
29
packet.go
29
packet.go
@ -380,14 +380,26 @@ func (p *PacketServerCompanyNew) Read(b []byte) {
|
||||
}
|
||||
|
||||
func (p *PacketServerCompanyInfo) Read(b []byte) {
|
||||
var err error
|
||||
r := bufio.NewReader(bytes.NewReader(b))
|
||||
r.Discard(3)
|
||||
c, _ := r.ReadByte()
|
||||
p.CompanyID = uint8(c)
|
||||
p.Name, _ = r.ReadString(0)
|
||||
p.Name, err = r.ReadString(0)
|
||||
logErrorDebug(err, "PacketServerCompanyInfo.Read : Name")
|
||||
if err != nil {
|
||||
p.Name = "Error"
|
||||
} else {
|
||||
p.Name = p.Name[:len(p.Name)-1]
|
||||
p.President, _ = r.ReadString(0)
|
||||
}
|
||||
|
||||
p.President, err = r.ReadString(0)
|
||||
logErrorDebug(err, "PacketServerCompanyInfo.Read : President")
|
||||
if err != nil {
|
||||
p.President = "Error"
|
||||
} else {
|
||||
p.President = p.President[:len(p.President)-1]
|
||||
}
|
||||
c, _ = r.ReadByte()
|
||||
p.Color = uint8(c)
|
||||
c, _ = r.ReadByte()
|
||||
@ -410,14 +422,25 @@ func (p *PacketServerCompanyInfo) Read(b []byte) {
|
||||
}
|
||||
|
||||
func (p *PacketServerCompanyUpdate) Read(b []byte) {
|
||||
var err error
|
||||
r := bufio.NewReader(bytes.NewReader(b))
|
||||
r.Discard(3)
|
||||
c, _ := r.ReadByte()
|
||||
p.CompanyID = uint8(c)
|
||||
p.Name, _ = r.ReadString(0)
|
||||
p.Name, err = r.ReadString(0)
|
||||
logErrorDebug(err, "PacketServerCompanyUpdate.Read : Name")
|
||||
if err != nil {
|
||||
p.Name = "Error"
|
||||
} else {
|
||||
p.Name = p.Name[:len(p.Name)-1]
|
||||
}
|
||||
p.President, _ = r.ReadString(0)
|
||||
logErrorDebug(err, "PacketServerCompanyUpdate.Read : President")
|
||||
if err != nil {
|
||||
p.President = "Error"
|
||||
} else {
|
||||
p.President = p.President[:len(p.President)-1]
|
||||
}
|
||||
c, _ = r.ReadByte()
|
||||
p.Color = uint8(c)
|
||||
c, _ = r.ReadByte()
|
||||
|
11
ttd.go
11
ttd.go
@ -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()
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Code generated by version.sh (@generated) DO NOT EDIT.
|
||||
package main
|
||||
var githash = "93de432"
|
||||
var buildstamp = "2021-11-09_05:24:29"
|
||||
var commits = "175"
|
||||
var version = "93de432-b175 - 2021-11-09_05:24:29"
|
||||
var githash = "a100fb6"
|
||||
var buildstamp = "2021-11-09_09:44:42"
|
||||
var commits = "176"
|
||||
var version = "a100fb6-b176 - 2021-11-09_09:44:42"
|
||||
|
Loading…
Reference in New Issue
Block a user