diff --git a/comm/const.go b/comm/const.go index 279752332..e57ce1bb0 100644 --- a/comm/const.go +++ b/comm/const.go @@ -70,7 +70,7 @@ const ( //ModuleFetter core.M_Modules = "herofetter" //好友模块 ModuleSociaty core.M_Modules = "sociaty" //公会 ModulePay core.M_Modules = "pay" //支付 - ModuleAlliance core.M_Modules = "alliance" //联盟学院 + ModuleAcademy core.M_Modules = "academy" //联盟学院 ModulePrivilege core.M_Modules = "privilege" //特权 ModuleGrowtask core.M_Modules = "growtask" //成长任务 ModuleWorldtask core.M_Modules = "worldtask" //世界任务 diff --git a/lego/utils/codec/string.go b/lego/utils/codec/string.go index 64d93aefb..e63d8b100 100644 --- a/lego/utils/codec/string.go +++ b/lego/utils/codec/string.go @@ -6,6 +6,21 @@ func Atoi(b []byte) (int, error) { return strconv.Atoi(BytesToString(b)) } +func StringToInt64(b string) int64 { + if i, err := strconv.ParseInt(b, 10, 64); err != nil { + return 0 + } else { + return i + } +} +func StringToFloat64(b string) float64 { + if i, err := strconv.ParseFloat(b, 64); err != nil { + return 0 + } else { + return i + } +} + func ParseInt(b []byte, base int, bitSize int) (int64, error) { return strconv.ParseInt(BytesToString(b), base, bitSize) } diff --git a/modules/academy/module.go b/modules/academy/module.go index a1adb3584..e32401898 100644 --- a/modules/academy/module.go +++ b/modules/academy/module.go @@ -28,7 +28,7 @@ type Academy struct { //模块名 func (this *Academy) GetType() core.M_Modules { - return comm.ModuleForum + return comm.ModuleAcademy } //模块初始化接口 注册用户创建角色事件 diff --git a/services/worker/main.go b/services/worker/main.go index af8752fc1..d88c6e000 100644 --- a/services/worker/main.go +++ b/services/worker/main.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "go_dreamfactory/comm" + "go_dreamfactory/modules/academy" "go_dreamfactory/modules/arena" "go_dreamfactory/modules/battle" "go_dreamfactory/modules/chat" @@ -103,6 +104,7 @@ func main() { //privilege.NewModule(), growtask.NewModule(), worldtask.NewModule(), + academy.NewModule(), ) } diff --git a/sys/configure/configure.go b/sys/configure/configure.go index a1ab892cf..962d282c7 100644 --- a/sys/configure/configure.go +++ b/sys/configure/configure.go @@ -4,6 +4,7 @@ import ( "fmt" "go_dreamfactory/lego" "go_dreamfactory/lego/sys/log" + "go_dreamfactory/lego/utils/codec" "io/fs" "io/ioutil" "os" @@ -43,6 +44,7 @@ type Configure struct { clock sync.RWMutex configure map[string]interface{} fileinfos map[string]*FileInfo + offsettime time.Duration //偏移时间 } func (this *Configure) Start() (err error) { @@ -59,7 +61,7 @@ func (this *Configure) Start() (err error) { } timer.Stop() }() - + this.readoffsettime() return } func (this *Configure) Stop() (err error) { @@ -67,6 +69,11 @@ func (this *Configure) Stop() (err error) { return } +//服务当前时间 +func (this *Configure) Now() time.Time { + return time.Now().Add(this.offsettime) +} + //加载配置文件 func (this *Configure) RegisterConfigure(name string, fn interface{}, callback func()) (err error) { this.hlock.RLock() @@ -209,4 +216,25 @@ func (this *Configure) checkConfigure() { } } } + this.readoffsettime() +} + +//读取偏移时间 +func (this *Configure) readoffsettime() { + var ( + fliepath string + file *os.File + data []byte + offtimeStr string + err error + ) + if file, err = os.Open(fliepath); err != nil { + return + } + defer file.Close() + if data, err = ioutil.ReadAll(file); err != nil { + return + } + offtimeStr = codec.BytesToString(data) + this.offsettime = time.Second * time.Duration(codec.StringToInt64(offtimeStr)) } diff --git a/sys/configure/core.go b/sys/configure/core.go index f4c9f5e8a..697da9b05 100644 --- a/sys/configure/core.go +++ b/sys/configure/core.go @@ -19,6 +19,7 @@ type ( Stop() (err error) RegisterConfigure(name string, fn interface{}, callback func()) (err error) //注册配置 GetConfigure(name string) (v interface{}, err error) //获取配置 + Now() time.Time //服务器当前时间 } ) @@ -57,5 +58,5 @@ func GetConfigure(name string) (v interface{}, err error) { //当前时间 func Now() time.Time { - return time.Now() + return defsys.Now() } diff --git a/sys/configure/options.go b/sys/configure/options.go index e95a6e802..3166cfca9 100644 --- a/sys/configure/options.go +++ b/sys/configure/options.go @@ -1,6 +1,7 @@ package configure import ( + "go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/utils/mapstructure" ) @@ -9,6 +10,8 @@ type Options struct { ConfigurePath string //配置中心路径 TimestampFile string //时间戳配置文件路径 CheckInterval int //配置文件更新检查间隔时间 单位秒 + Debug bool //日志是否开启 + Log log.ILogger } func SetConfigurePath(v string) Option { @@ -27,6 +30,18 @@ func SetCheckInterval(v int) Option { } } +func SetDebug(v bool) Option { + return func(o *Options) { + o.Debug = v + } +} + +func SetLog(v log.ILogger) Option { + return func(o *Options) { + o.Log = v + } +} + func newOptions(config map[string]interface{}, opts ...Option) (Options, error) { options := Options{ CheckInterval: 60, @@ -37,6 +52,9 @@ func newOptions(config map[string]interface{}, opts ...Option) (Options, error) for _, o := range opts { o(&options) } + if options.Log == nil { + options.Log = log.NewTurnlog(options.Debug, log.Clone("sys.rpc", 3)) + } return options, nil } @@ -47,6 +65,9 @@ func newOptionsByOption(opts ...Option) (Options, error) { for _, o := range opts { o(&options) } + if options.Log == nil { + options.Log = log.NewTurnlog(options.Debug, log.Clone("sys.configure", 3)) + } return options, nil }