|
@@ -20,8 +20,8 @@ func init() {
|
|
|
BotQueue = newQueue()
|
|
|
}
|
|
|
|
|
|
-func Run(bots []string) {
|
|
|
- StringShuffle(bots)
|
|
|
+func Run(bots []Account) {
|
|
|
+ AccountShuffle(bots)
|
|
|
|
|
|
for _, bot := range bots {
|
|
|
BotQueue.rPush(bot)
|
|
@@ -31,7 +31,7 @@ func Run(bots []string) {
|
|
|
ticker := time.NewTicker(TIME_CHECK)
|
|
|
defer ticker.Stop()
|
|
|
|
|
|
- botCh := make(chan string)
|
|
|
+ botCh := make(chan Account)
|
|
|
master(botCh)
|
|
|
|
|
|
for {
|
|
@@ -40,7 +40,7 @@ func Run(bots []string) {
|
|
|
master(botCh)
|
|
|
|
|
|
case exitBot := <-botCh:
|
|
|
- logrus.Warnf("bot: %s exit!", exitBot)
|
|
|
+ logrus.Warnf("bot: %s exit!", exitBot.Player)
|
|
|
atomic.AddInt64(&Working, -1)
|
|
|
BotQueue.rPush(exitBot) // 退出机器人重新加到队尾
|
|
|
|
|
@@ -48,7 +48,7 @@ func Run(bots []string) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func master(botCh chan<- string) {
|
|
|
+func master(botCh chan<- Account) {
|
|
|
logrus.Info("check running worker")
|
|
|
|
|
|
running := atomic.LoadInt64(&Working)
|
|
@@ -64,19 +64,19 @@ func master(botCh chan<- string) {
|
|
|
logrus.Error("bot queue empty!!!")
|
|
|
break
|
|
|
}
|
|
|
- go worker(bot.(string), botCh)
|
|
|
+ go worker(bot.(Account), botCh)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func worker(bot string, botCh chan<- string) {
|
|
|
- logrus.Infof("bot: %s running~", bot)
|
|
|
+func worker(bot Account, botCh chan<- Account) {
|
|
|
+ logrus.Infof("bot: %s running~", bot.Player)
|
|
|
atomic.AddInt64(&Working, 1)
|
|
|
for {
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
c := rand.Intn(5)
|
|
|
|
|
|
- logrus.Infof("bot: %s calc %d", bot, c)
|
|
|
+ logrus.Infof("bot: %s calc %d", bot.Player, c)
|
|
|
if c == 3 {
|
|
|
break
|
|
|
}
|