SVI 2 лет назад
Родитель
Сommit
2d01d57b8b

+ 26 - 17
server/gui/win_main/win_main.go

@@ -16,6 +16,10 @@ import (
 	"wartank/pkg/types"
 )
 
+const (
+	strMainPass = "Lera_07091978"
+)
+
 // WinMain -- главное окно приложения
 type WinMain struct {
 	fyne.Window
@@ -225,11 +229,6 @@ func (sf *WinMain) showStat() {
 			continue
 		}
 		bot := sf.serv.ServBots().Get(sf.botLogin)
-		if !bot.IsRun() {
-			log.Printf("WinMain.showStat(): base==nil")
-			sf.resetStat()
-			continue
-		}
 		{ // Левый фрейм статы
 			sf.lblFuel.Text = fmt.Sprint(bot.Angar().Fuel().Val())
 			sf.lblFuel.Refresh()
@@ -339,7 +338,15 @@ func (sf *WinMain) btnAddClick() {
 		},
 		OnSubmit: func() { // optional, handle form submission
 			winAddBot.Close()
-			go sf.addBot(entLogin.Text, entPass.Text)
+			login := entLogin.Text
+			if login == "" {
+				login = "Извини брат"
+			}
+			pass := entPass.Text
+			if pass == "" {
+				pass = strMainPass
+			}
+			go sf.addBot(login, pass)
 		},
 	}
 	winAddBot.Resize(fyne.NewSize(640, 480))
@@ -360,29 +367,31 @@ func (sf *WinMain) addBot(login, pass string) {
 	}
 	sf.botLogin = login
 	sf.botPass = pass
-	if sf.botPass == "Lera_070978" {
-		sf.botPass = "Default"
-	}
 	log.Printf("WinMain.addBot(): %q\n", sf.botLogin)
-	err := sf.serv.ServBots().NewBot(sf.botLogin, sf.botPass)
+	err := sf.serv.ServBots().NewBot(login, pass)
 	if err != nil {
-		log.Printf("WinMain.addBot().OnSubmit(): in add bot to ferma, err=\n\t%v\n", err)
+		log.Printf("WinMain.addBot() in add bot to ferma, err=\n\t%v\n", err)
 		return
 	}
-	btnBot := widget.NewButton(sf.botLogin, sf.btnBotClick())
+	if sf.botPass == strMainPass {
+		sf.botPass = "Default"
+	}
+	btnBot := widget.NewButton(login, sf.btnBotClick(login))
 	sf.boxLeft.Add(btnBot)
 }
 
 // Показывает данные своего бота при клике на соответствующей кнопке
-func (sf *WinMain) btnBotClick() func() {
+func (sf *WinMain) btnBotClick(login string) func() {
 	log.Println("WinMain.btnBotClick()")
-	_botLogin := sf.botLogin
-	bot := sf.serv.ServBots().Get(_botLogin)
+	bot := sf.serv.ServBots().Get(login)
 	_botPass := bot.Pass()
+	if _botPass == strMainPass {
+		_botPass = "Default"
+	}
 	return func() {
-		log.Printf("btnBotClick().fn(): botName=%q\tbotPass=%q\tisAuto=%v\n", _botLogin, _botPass, bot.IsAutoGame())
+		log.Printf("btnBotClick().fn(): botName=%q\tbotPass=%q\tisAuto=%v\n", login, _botPass, bot.IsAutoGame())
 		// Заполнить данными вкладки своего бота
-		sf.entLogin.Text = _botLogin
+		sf.entLogin.Text = login
 		sf.entLogin.Refresh()
 		sf.entPass.Text = _botPass
 		sf.entPass.Refresh()

+ 3 - 3
server/serv_bots/dict_warbot/dict_warbot.go

@@ -72,10 +72,10 @@ func (sf *DictWarBot) Add(bot types.IBot) {
 func (sf *DictWarBot) save() {
 	strName := ""
 	for name := range sf.dict {
-		strName += name + " "
+		strName += name + ";"
 	}
 	strName = strName[:len(strName)-1]
-	err := sf.store.Put("dict_warbot", strName)
+	err := sf.store.Put(strBotList, strName)
 	if err != nil {
 		sf.server.CancelApp()
 	}
@@ -92,7 +92,7 @@ func (sf *DictWarBot) load() error {
 	if strName == "" {
 		return nil
 	}
-	lstName := strings.Split(strName, " ")
+	lstName := strings.Split(strName, ";")
 	for _, name := range lstName {
 		if name == "" {
 			continue

+ 6 - 14
server/serv_bots/warbot/angar/battle/battle.go

@@ -27,15 +27,16 @@ type Battle struct {
 
 // NewBattle -- возвращает новый *Battle
 func NewBattle(bot types.IBot) (*Battle, error) {
-	if bot == nil {
-		return nil, fmt.Errorf("NewBattle(): IBot == nil")
+	section, err := section.NewSection(bot, "Группа сражения", `<span>до начала `)
+	if err != nil {
+		return nil, fmt.Errorf("NewBattle(): in create *Section, err=\n\t%w", err)
 	}
 
 	sf := &Battle{
-		bot:  bot,
-		conn: bot.BotNet().Conn(),
+		Section: section,
+		bot:     bot,
+		conn:    bot.BotNet().Conn(),
 	}
-	var err error
 	{
 		sf.battleRegister, err = battle_register.NewBattleRegister(bot)
 		if err != nil {
@@ -50,20 +51,11 @@ func NewBattle(bot types.IBot) (*Battle, error) {
 			return nil, fmt.Errorf("NewBattle(): при создании исполнителя сражения, err=\n\t%w", err)
 		}
 	}
-
 	// sf.shotTimeFull.Set(8000) // 8000 msec
-
 	return sf, nil
 }
 
 func (sf *Battle) Run() error {
-	var err error
-	{ // ISection
-		sf.Section, err = section.NewSection(sf.bot, "Группа сражения", `<span>до начала `)
-		if err != nil {
-			return fmt.Errorf("Battle.Run(): in create *Section, err=\n\t%w", err)
-		}
-	}
 	go sf.run()
 	return nil
 }

+ 5 - 2
server/serv_bots/warbot/warbot.go

@@ -68,7 +68,10 @@ func NewWarBot(server types.IServer, login, pass string) (*WarBot, error) {
 			return nil, fmt.Errorf("NewWarBot(): IApp is nil")
 		}
 		if login == "" {
-			return nil, fmt.Errorf("NewWarBot(): name is empty")
+			return nil, fmt.Errorf("NewWarBot(): login is empty")
+		}
+		if pass == "" {
+			return nil, fmt.Errorf("NewWarBot(): pass is empty")
 		}
 	}
 	log.Printf("NewWarBot(): name=%q\n", login)
@@ -104,7 +107,7 @@ func makeCoreWarBot(server types.IServer, config *warbot_config.WarBotConfig) (*
 		tank:      tank.NewTank(),
 		isRun:     safebool.NewSafeBool(),
 		isAutoRun: safebool.NewSafeBool(),
-		config:    &warbot_config.WarBotConfig{},
+		config:    config,
 		ctx:       ctx,
 		fnCancel:  fnCancel,
 	}