Bläddra i källkod

调整数据结构

solupro 5 år sedan
förälder
incheckning
37871903ae
7 ändrade filer med 99 tillägg och 26 borttagningar
  1. 0 13
      bots.json
  2. 22 0
      config/bots.dev.json
  3. 46 0
      config/bots.prod.json
  4. 15 0
      eos.go
  5. 6 3
      main.go
  6. 9 9
      runner.go
  7. 1 1
      utils.go

+ 0 - 13
bots.json

@@ -1,13 +0,0 @@
-[
-  "bbbbb1111111",
-  "woainimama11",
-  "oppooppoopp1",
-  "youjumoijump",
-  "uziuziwinno1",
-  "paragonronl2",
-  "iqksosjhgyus",
-  "jjjjjjjjiiii",
-  "4tqibd3wmnzg",
-  "jvwh4d1ydfkw",
-  "5m2qzd3nz11u"
-]

+ 22 - 0
config/bots.dev.json

@@ -0,0 +1,22 @@
+[
+  {
+    "player": "xunbin",
+    "star_id": 7
+  },
+  {
+    "player": "junqiang",
+    "star_id": 8
+  },
+  {
+    "player": "kunbiao",
+    "star_id": 9
+  },
+  {
+    "player": "xiesj",
+    "star_id": 10
+  },
+  {
+    "player": "wangqian",
+    "star_id": 1
+  }
+]

+ 46 - 0
config/bots.prod.json

@@ -0,0 +1,46 @@
+[
+  {
+    "player": "bbbbb1111111",
+    "star_id": 215
+  },
+  {
+    "player": "woainimama11",
+    "star_id": 214
+  },
+  {
+    "player": "oppooppoopp1",
+    "star_id": 213
+  },
+  {
+    "player": "youjumoijump",
+    "star_id": 2
+  },
+  {
+    "player": "uziuziwinno1",
+    "star_id": 212
+  },
+  {
+    "player": "paragonronl2",
+    "star_id": 211
+  },
+  {
+    "player": "iqksosjhgyus",
+    "star_id": 3
+  },
+  {
+    "player": "jjjjjjjjiiii",
+    "star_id": 216
+  },
+  {
+    "player": "4tqibd3wmnzg",
+    "star_id": 210
+  },
+  {
+    "player": "jvwh4d1ydfkw",
+    "star_id": 209
+  },
+  {
+    "player": "5m2qzd3nz11u",
+    "star_id": 208
+  }
+]

+ 15 - 0
eos.go

@@ -1 +1,16 @@
 package main
+
+var NET_HOST string
+
+func init() {
+	if ENV == "dev" {
+		NET_HOST = "https://localnet.eosget.io:443/"
+	} else {
+		NET_HOST = "https://proxy.eosnode.tools:443/"
+	}
+}
+
+type Account struct {
+	Player string `json:"player"`
+	StarId int    `json:"star_id"`
+}

+ 6 - 3
main.go

@@ -3,17 +3,20 @@ package main
 import (
 	"encoding/json"
 	"flag"
+	"fmt"
 	"io/ioutil"
 )
 
+var ENV string
+
 func main() {
-	var configPath string
-	flag.StringVar(&configPath, "conf", "./bots.json", "bots config path")
+	flag.StringVar(&ENV, "env", "dev", "执行环节dev|prod")
 	flag.Parse()
 
+	configPath := fmt.Sprintf("./config/bots.%s.json", ENV)
 	f, err := ioutil.ReadFile(configPath)
 	CheckError(err)
-	bots := []string{}
+	bots := []Account{}
 	err = json.Unmarshal(f, &bots)
 	CheckError(err)
 

+ 9 - 9
runner.go

@@ -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
 		}

+ 1 - 1
utils.go

@@ -5,7 +5,7 @@ import (
 	"time"
 )
 
-func StringShuffle(list []string) {
+func AccountShuffle(list []Account) {
 	rand.Seed(time.Now().UnixNano())
 	rand.Shuffle(len(list), func(i, j int) {
 		list[i], list[j] = list[j], list[i]