add ingame msg

This commit is contained in:
shoopea
2021-11-13 14:27:29 +08:00
parent ccd41c2e1b
commit 54d777934b
2 changed files with 18 additions and 6 deletions

16
ttd.go
View File

@@ -608,10 +608,22 @@ func (s *ServerTTD) ComputeClientTime() {
for _, cc := range cfg.Clients {
if cc.Online {
if cc.TimeLeft > 0 && cc.TimeLeft < diff {
bot.SendChat(cfg.Telegram.ChatID, fmt.Sprintf("@%s got not time left. Grace period of %s.", cc.Username, cfg.Game.Threshold))
msg := fmt.Sprintf("@%s got not time left. Grace period of %s.", cc.Username, cfg.Game.Threshold)
bot.SendChat(cfg.Telegram.ChatID, msg)
px := PacketAdminRCon{
Packet: Packet{PType: AdminPacketAdminRCon},
Command: fmt.Sprintf("say %s", msg),
}
srv.Send(px.Bytes())
}
if (cc.TimeLeft+cfg.Game.Threshold) > 0 && (cc.TimeLeft+cfg.Game.Threshold) < diff {
bot.SendChat(cfg.Telegram.ChatID, fmt.Sprintf("@%s got not time left. Grace period over.", cc.Username))
msg := fmt.Sprintf("@%s got not time left. Grace period over.", cc.Username)
bot.SendChat(cfg.Telegram.ChatID, msg)
px := PacketAdminRCon{
Packet: Packet{PType: AdminPacketAdminRCon},
Command: fmt.Sprintf("say %s", msg),
}
srv.Send(px.Bytes())
}
cc.TimeLeft = cc.TimeLeft - diff
}