-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathBroadcast.go
49 lines (42 loc) · 1.38 KB
/
Broadcast.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"log"
"math/rand"
"strconv"
"time"
"github.com/hoshinonyaruko/palworld-go/config"
)
type palworldBroadcast struct {
Config config.Config
Ticker *time.Ticker
BackupTask *BackupTask
}
func NewpalworldBroadcast(config config.Config) *palworldBroadcast {
return &palworldBroadcast{
Config: config,
Ticker: time.NewTicker(time.Duration(config.MessageBroadcastInterval) * time.Second),
}
}
func (task *palworldBroadcast) Schedule() {
for range task.Ticker.C {
task.RunpalworldBroadcast()
}
}
func (task *palworldBroadcast) RunpalworldBroadcast() {
log.Println("准备进行全服推送...现已支持所有语言broadcast!")
// 初始化RCON客户端
address := task.Config.Address + ":" + strconv.Itoa(task.Config.WorldSettings.RconPort)
rconClient := NewRconClient(address, task.Config.WorldSettings.AdminPassword, task.BackupTask, &task.Config)
if rconClient == nil {
log.Println("RCON客户端初始化失败,无法进行定期推送,请按教程正确开启rcon和设置服务端admin密码")
return
}
// RegularMessages是RegularMessages切片
if len(task.Config.RegularMessages) > 0 {
// 随机生成一个索引来选择消息
randomIndex := rand.Intn(len(task.Config.RegularMessages))
// 获取随机选择的消息
randomMessage := task.Config.RegularMessages[randomIndex]
Broadcast(randomMessage, rconClient, task.Config.UseDll)
}
}