This commit is contained in:
wh_zcy 2023-01-29 10:51:23 +08:00
parent a6cd1233f6
commit 815d6513a8
7 changed files with 47 additions and 201 deletions

View File

@ -4,5 +4,5 @@ Website = "http://legu.cc"
Icon = "app.png" Icon = "app.png"
Name = "RobotGUI" Name = "RobotGUI"
ID = "cc.legu.app" ID = "cc.legu.app"
Version = "1.2.6" Version = "1.2.7"
Build = 34 Build = 37

View File

@ -27,11 +27,10 @@ import (
) )
var ( var (
connService service.ConnService connService service.ConnService
pttService service.PttService pttService service.PttService
configService service.ConfigService obs = observer.NewObserver()
obs = observer.NewObserver() logger *logrus.Logger
logger *logrus.Logger
) )
// //
@ -44,10 +43,10 @@ func init() {
os.Exit(1) os.Exit(1)
} }
if err = setupConfig(); err != nil { // if err = setupConfig(); err != nil {
fmt.Println(err) // fmt.Println(err)
os.Exit(1) // os.Exit(1)
} // }
if err = setupWsConn(); err != nil { if err = setupWsConn(); err != nil {
fmt.Println(err) fmt.Println(err)
@ -65,7 +64,7 @@ func main() {
app := app.NewWithID("df-toolkit") app := app.NewWithID("df-toolkit")
app.SetIcon(theme.ResourceAppPng) app.SetIcon(theme.ResourceAppPng)
appUI, err := ui.NewUI(app, configService, connService, pttService, obs) appUI, err := ui.NewUI(app, connService, pttService, obs)
if err != nil { if err != nil {
w := fyne.CurrentApp().NewWindow("错误") w := fyne.CurrentApp().NewWindow("错误")
w.SetContent(canvas.NewText(err.Error(), color.RGBA{255, 0, 0, 255})) w.SetContent(canvas.NewText(err.Error(), color.RGBA{255, 0, 0, 255}))
@ -135,18 +134,6 @@ func setupWsConn() (err error) {
return return
} }
func setupConfig() (err error) {
configService, err = service.NewConfigService()
if err != nil {
return
}
if err = configService.ApplyConfig(); err != nil {
return
}
return
}
func setupLogger() (err error) { func setupLogger() (err error) {
logrus.SetFormatter(&logrus.JSONFormatter{ logrus.SetFormatter(&logrus.JSONFormatter{
TimestampFormat: "2006-01-02 15:04:05", TimestampFormat: "2006-01-02 15:04:05",
@ -176,7 +163,7 @@ func setupLogger() (err error) {
// check version // check version
func checkVersion(app fyne.App, parent fyne.Window) { func checkVersion(app fyne.App, parent fyne.Window) {
logrus.Debug("check version") logrus.Debug("check version")
b, err := connService.HttpConnect(configService.GetConfig().UpgradeUrl + "version") b, err := connService.HttpConnect("http://10.0.0.9:8080/" + "version")
if err != nil { if err != nil {
dialog.ShowError(errors.New("版本检查:"+err.Error()), parent) dialog.ShowError(errors.New("版本检查:"+err.Error()), parent)
return return
@ -207,7 +194,7 @@ func checkVersion(app fyne.App, parent fyne.Window) {
cmd := exec.Command(run, uri) cmd := exec.Command(run, uri)
return cmd.Run() return cmd.Run()
} }
_ = open(configService.GetConfig().UpgradeUrl) _ = open("http://10.0.0.9:8080/")
defer parent.Close() defer parent.Close()
}, parent) }, parent)
chkDialog.SetConfirmText(common.BUTTON_OK) chkDialog.SetConfirmText(common.BUTTON_OK)

View File

@ -1,26 +0,0 @@
upgradeUrl: http://10.0.0.9:8080/
services:
- service:
sid: "df01"
name: 外网
url: ws://119.3.89.14:9891/gateway
- service:
sid: "dfz"
name: 赵长远
url: ws://10.0.0.238:7891/gateway
- service:
sid: "df01"
name: 内网
url: ws://10.0.0.9:7891/gateway
- service:
sid: "dfmxf"
name: 梅雄风
url: ws://10.0.0.85:7891/gateway
- service:
sid: "dflw"
name: 李伟
url: ws://10.0.0.85:7891/gateway
- service:
sid: "df01"
name: 压测服
url: ws://106.54.189.74:7891/gateway

View File

@ -1,106 +0,0 @@
package service
import (
"fmt"
"go_dreamfactory/cmd/v2/lib/common"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
type ConfigService interface {
GetConfig() *Config
LoadConfig() error
ApplyConfig() error
}
type ConfigServiceImpl struct {
ResourcePath string
Config *Config
}
type ServiceConf struct {
SId string `yaml:"sid"`
Name string `yaml:"name"`
Url string `yaml:"url"`
}
type Services struct {
Service *ServiceConf `yaml:"service"`
}
type Config struct {
Services []*Services `yaml:"services"`
UpgradeUrl string `yaml:"upgradeUrl"`
}
func NewConfigService() (ConfigService, error) {
srv := &ConfigServiceImpl{
ResourcePath: common.DEFAULT_RESOURCE_PATH,
Config: &Config{},
}
err := srv.init()
return srv, err
}
func (c *ConfigServiceImpl) LoadConfig() error {
viper.AddConfigPath("./" + c.ResourcePath)
return viper.ReadInConfig()
}
func (c *ConfigServiceImpl) ApplyConfig() error {
if err := c.LoadConfig(); err != nil {
logrus.Error(err)
return err
}
if err := viper.Unmarshal(c.Config); err != nil {
logrus.Error(err)
return err
}
return nil
}
func (c *ConfigServiceImpl) Unmarshal() error {
if sArr, ok := viper.Get("services").([]interface{}); ok {
for _, service := range sArr {
if services, ok := service.(map[interface{}]interface{}); ok {
for _, v := range services {
if vv, ok := v.(map[interface{}]interface{}); ok {
for k, _ := range vv {
kk := k.(string)
logrus.Debug(vv[kk])
srvConf := &ServiceConf{}
switch kk {
case "sid":
srvConf.SId = vv[kk].(string)
case "name":
srvConf.Name = vv[kk].(string)
case "url":
srvConf.Url = vv[kk].(string)
default:
return fmt.Errorf("config key[%s] not foud", kk)
}
c.Config.Services = append(c.Config.Services, &Services{})
}
}
logrus.Debug(v)
// if v
}
}
}
}
return nil
}
func (c *ConfigServiceImpl) GetConfig() *Config {
return c.Config
}
func (c *ConfigServiceImpl) init() error {
viper.SetConfigName("config")
viper.SetConfigType("yaml")
return nil
}

View File

@ -22,19 +22,17 @@ type UI interface {
} }
type UIImpl struct { type UIImpl struct {
app fyne.App app fyne.App
windows map[string]fyne.Window windows map[string]fyne.Window
winMux *sync.Mutex winMux *sync.Mutex
connService service.ConnService connService service.ConnService
pttService service.PttService pttService service.PttService
configService service.ConfigService obs observer.Observer
obs observer.Observer storage storage.Storage
storage storage.Storage config *storage.Config
config *storage.Config
} }
func NewUI(app fyne.App, func NewUI(app fyne.App,
configService service.ConfigService,
connService service.ConnService, connService service.ConnService,
pttService service.PttService, pttService service.PttService,
obs observer.Observer, obs observer.Observer,
@ -54,15 +52,14 @@ func NewUI(app fyne.App,
return nil, err return nil, err
} }
return &UIImpl{ return &UIImpl{
app: app, app: app,
windows: make(map[string]fyne.Window), windows: make(map[string]fyne.Window),
winMux: &sync.Mutex{}, winMux: &sync.Mutex{},
configService: configService, connService: connService,
connService: connService, pttService: pttService,
pttService: pttService, obs: obs,
obs: obs, storage: iStorage,
storage: iStorage, config: config,
config: config,
}, nil }, nil
} }

View File

@ -15,7 +15,6 @@ import (
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/sys/db" "go_dreamfactory/sys/db"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"runtime"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -296,12 +295,9 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T
module, err := this.service.GetModule(comm.ModuleWorldtask) module, err := this.service.GetModule(comm.ModuleWorldtask)
if err == nil { if err == nil {
go func() { go func() {
defer func() { //程序异常 收集异常信息传递给前端显示 defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
buf := make([]byte, 4096) log.Errorf("[worldtask ] err:%v ", r)
l := runtime.Stack(buf, false)
log.Errorf("[Handle Api] m:%s ", fmt.Sprintf("%v: %s", r, buf[:l]))
} }
}() }()
// 世界任务 // 世界任务
@ -338,9 +334,7 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T
go func() { go func() {
defer func() { //程序异常 收集异常信息传递给前端显示 defer func() { //程序异常 收集异常信息传递给前端显示
if r := recover(); r != nil { if r := recover(); r != nil {
buf := make([]byte, 4096) log.Errorf("[sociatytask ] err:%v ", r)
l := runtime.Stack(buf, false)
log.Errorf("[Handle Api] m:%s ", fmt.Sprintf("%v: %s", r, buf[:l]))
} }
}() }()
// 公会 // 公会

View File

@ -662,22 +662,22 @@ func (this *User) BingoSetUserLv(session comm.IUserSession, lv int32) error {
return nil return nil
} }
func (this *User) Update() { // func (this *User) Update() {
if this.IsCross() { // if this.IsCross() {
return // return
} // }
cu, err := this.UserOnlineList() // cu, err := this.UserOnlineList()
if err != nil { // if err != nil {
return // return
} // }
for _, v := range cu { // for _, v := range cu {
if isession, ok := this.ModuleBase.GetUserSession(v.Uid); ok { // if isession, ok := this.ModuleBase.GetUserSession(v.Uid); ok {
//del session // //del session
log.Debug("del session", log.Field{Key: "uid", Value: v.Uid}, log.Field{Key: "isLogin", Value: isession.IsLogin()}) // log.Debug("del session", log.Field{Key: "uid", Value: v.Uid}, log.Field{Key: "isLogin", Value: isession.IsLogin()})
} // }
} // }
} // }
// 玩家体力恢复 // 玩家体力恢复
func (this *User) RecoverUserPsStart(uid string) { func (this *User) RecoverUserPsStart(uid string) {