|
@@ -11,10 +11,16 @@ const (
|
|
MAX_RUN = 3
|
|
MAX_RUN = 3
|
|
MIN_RUN = 1
|
|
MIN_RUN = 1
|
|
TIME_CHECK = 10 * 60 * time.Second // 十分钟检查一次
|
|
TIME_CHECK = 10 * 60 * time.Second // 十分钟检查一次
|
|
|
|
+ //TIME_CHECK = 60 * time.Second // 十分钟检查一次
|
|
|
|
+
|
|
|
|
+ TIME_RESET_TOTAL_BET = 24 * 3600 * time.Second
|
|
|
|
+ //TIME_RESET_TOTAL_BET = 300 * time.Second
|
|
)
|
|
)
|
|
|
|
|
|
var BotQueue *queue
|
|
var BotQueue *queue
|
|
var Working int64
|
|
var Working int64
|
|
|
|
+var TotalBet int64
|
|
|
|
+var MaxBet int64
|
|
|
|
|
|
func init() {
|
|
func init() {
|
|
BotQueue = newQueue()
|
|
BotQueue = newQueue()
|
|
@@ -31,7 +37,11 @@ func Run(bots []Account) {
|
|
ticker := time.NewTicker(TIME_CHECK)
|
|
ticker := time.NewTicker(TIME_CHECK)
|
|
defer ticker.Stop()
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
+ dayTicker := time.NewTicker(TIME_RESET_TOTAL_BET)
|
|
|
|
+ defer dayTicker.Stop()
|
|
|
|
+
|
|
botCh := make(chan Account)
|
|
botCh := make(chan Account)
|
|
|
|
+ resetBet()
|
|
master(botCh)
|
|
master(botCh)
|
|
|
|
|
|
for {
|
|
for {
|
|
@@ -39,6 +49,9 @@ func Run(bots []Account) {
|
|
case <-ticker.C:
|
|
case <-ticker.C:
|
|
master(botCh)
|
|
master(botCh)
|
|
|
|
|
|
|
|
+ case <-dayTicker.C:
|
|
|
|
+ resetBet()
|
|
|
|
+
|
|
case exitBot := <-botCh:
|
|
case exitBot := <-botCh:
|
|
logrus.Warnf("bot: %s exit!", exitBot.Player)
|
|
logrus.Warnf("bot: %s exit!", exitBot.Player)
|
|
atomic.AddInt64(&Working, -1)
|
|
atomic.AddInt64(&Working, -1)
|
|
@@ -51,6 +64,12 @@ func Run(bots []Account) {
|
|
func master(botCh chan<- Account) {
|
|
func master(botCh chan<- Account) {
|
|
logrus.Info("check running worker")
|
|
logrus.Info("check running worker")
|
|
|
|
|
|
|
|
+ totalBet := atomic.LoadInt64(&TotalBet)
|
|
|
|
+ if totalBet >= MaxBet {
|
|
|
|
+ logrus.Infof("TotalBet:%d >= MaxBet:%d, stop work!", totalBet, MaxBet)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
running := atomic.LoadInt64(&Working)
|
|
running := atomic.LoadInt64(&Working)
|
|
logrus.Infof("running %d bots, queue len: %d", running, BotQueue.getLen())
|
|
logrus.Infof("running %d bots, queue len: %d", running, BotQueue.getLen())
|
|
|
|
|
|
@@ -74,12 +93,17 @@ func worker(bot Account, botCh chan<- Account) {
|
|
atomic.AddInt64(&Working, 1)
|
|
atomic.AddInt64(&Working, 1)
|
|
for {
|
|
for {
|
|
|
|
|
|
- err := Transfer(bot.Player, bot.StarId)
|
|
|
|
|
|
+ bet, err := Transfer(bot.Player, bot.StarId)
|
|
if err != nil { // 下注失败退出
|
|
if err != nil { // 下注失败退出
|
|
logrus.WithField("error", err).Warnf("bot: %s transfer error", bot.Player)
|
|
logrus.WithField("error", err).Warnf("bot: %s transfer error", bot.Player)
|
|
break
|
|
break
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if atomic.AddInt64(&TotalBet, bet) >= atomic.LoadInt64(&MaxBet) {
|
|
|
|
+ logrus.Infof("TotalBet >= MaxBet, bot: %s stop", bot.Player)
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+
|
|
rand.Seed(time.Now().UnixNano())
|
|
rand.Seed(time.Now().UnixNano())
|
|
c := rand.Intn(6) + 15
|
|
c := rand.Intn(6) + 15
|
|
time.Sleep(time.Duration(c) * time.Second)
|
|
time.Sleep(time.Duration(c) * time.Second)
|
|
@@ -87,3 +111,14 @@ func worker(bot Account, botCh chan<- Account) {
|
|
|
|
|
|
botCh <- bot
|
|
botCh <- bot
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func resetBet() {
|
|
|
|
+ rand.Seed(time.Now().UnixNano())
|
|
|
|
+ max := rand.Int63n(15000001) + 35000000 // [3500, 5000] EOS
|
|
|
|
+ //max := rand.Int63n(5000) + 10000 // [3500, 5000] EOS
|
|
|
|
+
|
|
|
|
+ atomic.StoreInt64(&MaxBet, max)
|
|
|
|
+ atomic.StoreInt64(&TotalBet, 0)
|
|
|
|
+
|
|
|
|
+ logrus.Infof("Reset MaxBet:%d, TotalBet:%d", max, 0)
|
|
|
|
+}
|