-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSplinterforge.go
212 lines (202 loc) · 7.73 KB
/
Splinterforge.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package main
import (
_ "embed"
"fmt"
"os"
"runtime"
"splinterforge/ColorPrint"
"splinterforge/LogFunc"
"splinterforge/ProcedureFunc"
"splinterforge/ReadFunc"
"splinterforge/SpStruct"
"strconv"
"strings"
"sync"
"time"
"github.com/selenium-Driver-Check/SeleniumDriverCheck"
"github.com/tebeka/selenium"
"github.com/theckman/yacspin"
)
var (
accountLists = []SpStruct.UserData{}
r = &sync.WaitGroup{}
w = &sync.WaitGroup{}
s = &sync.WaitGroup{}
//headless, threadingLimit, showForgeReward, showAccountDetails, autoSelectCard, autoSelectHero, autoSelectSleepTime, splinterforgeAPIEndpoint, splinterlandAPIEndpoint, publicAPIEndpoint = ReadFunc.GetConfig("./config/config.txt")
headless = false
threadingLimit = 0
showForgeReward = false
showAccountDetails = false
autoSelectCard = false
autoSelectHero = false
autoSelectSleepTime = false
waitForBossRespawn = false
shareBattleLog = false
closeDriverDuringSleep = false
battlex2 = false
randomBosses = false
unwantedAbilities []string
splinterforgeAPIEndpoint = ""
splinterlandAPIEndpoint = ""
publicAPIEndpoint = ""
RealPath = ""
ConfigAccountsPath = ""
ConfigCardSettingPath = ""
)
func init() {
for i := 0; i < 1; i++ {
s.Add(1)
go func() {
CaculateTime := 1
for {
time.Sleep(1 * time.Hour)
now := time.Now()
fmt.Println("["+now.Format("2006-01-02 15:04:05")+"]", fmt.Sprintf("Splinterforge bot has been running for %v hour", CaculateTime))
CaculateTime ++
}
}()
}
PcPlatForm := runtime.GOOS
if PcPlatForm == "windows" {
ConfigAccountsPath = "config/accounts.txt"
ConfigCardSettingPath = "config/cardSettings.txt"
headless, threadingLimit, showForgeReward, showAccountDetails, autoSelectCard, autoSelectHero, autoSelectSleepTime, waitForBossRespawn, shareBattleLog, unwantedAbilities, closeDriverDuringSleep, battlex2, splinterforgeAPIEndpoint, splinterlandAPIEndpoint, publicAPIEndpoint, randomBosses = ReadFunc.GetConfig("config/config.txt")
} else if PcPlatForm == "darwin" {
path, err := os.Executable()
if err != nil {
panic(err)
}
if strings.Contains(path, "private") || strings.Contains(path, "___go_build") || strings.Contains(path, "folders/") {
RealPath, _ = os.Getwd()
} else {
RealPathLists := strings.Split(path, "/")
RealPath = strings.Join(RealPathLists[:len(RealPathLists)-1], "/")
}
ConfigAccountsPath = RealPath + "/config/accounts.txt"
ConfigCardSettingPath = RealPath + "/config/cardSettings.txt"
headless, threadingLimit, showForgeReward, showAccountDetails, autoSelectCard, autoSelectHero, autoSelectSleepTime, waitForBossRespawn, shareBattleLog, unwantedAbilities, closeDriverDuringSleep, battlex2, splinterforgeAPIEndpoint, splinterlandAPIEndpoint, publicAPIEndpoint , randomBosses = ReadFunc.GetConfig(RealPath + "/config/config.txt")
}
}
func initializeAccount(accountNo int) (string, string, string, string, []SpStruct.CardSelection, int) {
userName, postingKey, err := ReadFunc.GetAccountData(ConfigAccountsPath, accountNo)
if err != nil || userName == "" || postingKey == "" {
ColorPrint.PrintRed("ERROR", "Error in loading accounts.txt, please add username or posting key and try again.")
}
heroesType, bossId, playingSummoners, playingMonster, timeSleepInMinute, err := ReadFunc.GetCardSettingData(ConfigCardSettingPath, accountNo)
if heroesType == "" || bossId == "" {
fmt.Println("")
ColorPrint.PrintRed("SF", fmt.Sprintf("Error loading cardSettings.txt file for account %s", strconv.Itoa(accountNo)))
ColorPrint.PrintWhite("SF", "Terminating in 10 seconds...")
time.Sleep(10 * time.Second)
os.Exit(1)
}
if err != nil {
ColorPrint.PrintRed("ERROR", "Error loading cardSettings.txt file")
}
playingSummonersList := make([]SpStruct.Summoners, 0, len(playingSummoners))
playingMonsterList := make([]SpStruct.MonsterId, 0, len(playingMonster))
for _, i := range playingSummoners {
cardName, _ := ReadFunc.GetCardName(i)
playingSummonersList = append(playingSummonersList, SpStruct.Summoners{
PlayingSummonersDiv: fmt.Sprintf("//div/img[@id='%s']", i),
PlayingSummonersID: i,
PlayingSummonersName: cardName,
})
}
for _, i := range playingMonster {
cardName, _ := ReadFunc.GetCardName(i)
playingMonsterList = append(playingMonsterList, SpStruct.MonsterId{
PlayingMontersDiv: fmt.Sprintf("//div/img[@id='%s']", i),
PlayingMonstersID: i,
PlayingMonstersName: cardName,
})
}
var cardSelectionList = []SpStruct.CardSelection{}
cardSelection := SpStruct.CardSelection{
PlayingSummoners: playingSummonersList,
PlayingMonsters: playingMonsterList,
}
cardSelectionList = append(cardSelectionList, cardSelection)
return userName, postingKey, heroesType, bossId, cardSelectionList, timeSleepInMinute
}
func initializeUserData() {
LogFunc.PrintInfo()
cfg := yacspin.Config{
Frequency: 100 * time.Millisecond,
CharSet: yacspin.CharSets[59],
Suffix: " Initialization Driver",
SuffixAutoColon: true,
StopCharacter: " pass",
StopColors: []string{"fgGreen"},
StopMessage: "Success!",
}
spinner, _ := yacspin.New(cfg)
spinner.Start()
spinner.Message("Checking...")
wd, err := selenium.NewChromeDriverService(SeleniumDriverCheck.AutoDownload_ChromeDriver(false), 9515)
if err != nil {
fmt.Printf("Failed to create ChromeDriver service: %s\n", err)
os.Exit(1)
}
defer wd.Stop()
spinner.Stop()
cfg = yacspin.Config{
Frequency: 100 * time.Millisecond,
CharSet: yacspin.CharSets[59],
Suffix: " Reading config folder",
SuffixAutoColon: true,
StopCharacter: " pass",
StopColors: []string{"fgGreen"},
StopMessage: "Success!",
}
spinner, _ = yacspin.New(cfg)
spinner.Start()
spinner.Message("reading accounts.txt...")
lineCount, errCountLines := ReadFunc.GetLines(ConfigAccountsPath)
time.Sleep(500 * time.Millisecond)
if errCountLines == nil && lineCount > 1 {
spinner.Message("reading cardSettings.txt...")
for i := 0; i < lineCount-1; i++ {
r.Add(1)
time.Sleep(50 * time.Millisecond)
go func(num int) {
userName, postingKey, heroesType, bossId, cardSelection, timeSleepInMinute := initializeAccount(num + 1)
accountLists = append(accountLists, SpStruct.UserData{
UserName: userName,
PostingKey: postingKey,
BossID: bossId,
HeroesType: heroesType,
CardSelection: cardSelection,
TimeSleepInMinute: timeSleepInMinute,
})
r.Done()
}(i)
}
r.Wait()
spinner.Message("reading config.txt..")
time.Sleep(500 * time.Millisecond)
spinner.Stop()
LogFunc.PrintConfigSettings(lineCount-1, headless, threadingLimit, showForgeReward, showAccountDetails, waitForBossRespawn, shareBattleLog, closeDriverDuringSleep, battlex2, autoSelectCard, autoSelectHero, autoSelectSleepTime, unwantedAbilities, randomBosses)
for i := 0; i < len(accountLists); i += threadingLimit {
if len(accountLists)-i < threadingLimit {
threadingLimit = len(accountLists) - i
}
for j := 0; j < threadingLimit; j++ {
w.Add(1)
go ProcedureFunc.InitializeDriver(true, accountLists[i+j], headless, showForgeReward, showAccountDetails, autoSelectCard, autoSelectHero, autoSelectSleepTime, waitForBossRespawn, shareBattleLog, unwantedAbilities, closeDriverDuringSleep, battlex2, splinterforgeAPIEndpoint, splinterlandAPIEndpoint, publicAPIEndpoint, accountLists, randomBosses, s, w)
}
w.Wait()
LogFunc.PrintInfo()
}
s.Wait()
} else {
fmt.Println("")
ColorPrint.PrintRed("SF", "Please add accounts in accounts.txt")
ColorPrint.PrintWhite("SF", "Terminating in 10 seconds...")
time.Sleep(10 * time.Second)
os.Exit(1)
}
}
func main() {
initializeUserData()
}