diff --git a/comm/const.go b/comm/const.go index 28c2a7c73..572bcaf60 100644 --- a/comm/const.go +++ b/comm/const.go @@ -856,7 +856,12 @@ const ( Rtype224 TaskType = 224 // 击败石阵秘境中指定关卡的首领时,每名上阵英雄血量≤比例(千分比) Rtype225 TaskType = 225 // 在石阵秘境中,挑战指定类型的战斗关卡(普通:14,首领:28),失败N次 Rtype226 TaskType = 226 // 击败石阵秘境中指定关卡的首领时,背包中指定道具数量=指定数量 - Rtype227 TaskType = 227 // 指定ID战斗失败 + Rtype227 TaskType = 227 // 指定世界任务战斗ID 战斗失败 + Rtype228 TaskType = 228 // 第一次获得x星英雄 + Rtype229 TaskType = 229 // 购买莫个礼包(读计费点id) + Rtype230 TaskType = 230 // 星期几登录 + Rtype231 TaskType = 231 // 每期循环塔达到x层 + Rtype232 TaskType = 232 // 种族塔通关x阵营x层 ) const ( MailLineEasy int32 = 1 // 简单 diff --git a/modules/robot/client.go b/modules/robot/client.go new file mode 100644 index 000000000..7184abe87 --- /dev/null +++ b/modules/robot/client.go @@ -0,0 +1,67 @@ +package robot + +import ( + "go_dreamfactory/lego/sys/log" + "go_dreamfactory/pb" + "sync" + "sync/atomic" + + "github.com/gorilla/websocket" + "google.golang.org/protobuf/proto" +) + +type Client struct { + sessionId string + uId string + wsConn *websocket.Conn + state int32 //状态 0 关闭 1 运行 2 关闭中 + closeSignal chan bool + wg sync.WaitGroup +} + +func (this *Client) readLoop() { + defer this.wg.Done() + var ( + data []byte + msg *pb.UserMessage = &pb.UserMessage{} + err error + ) +locp: + for { + if _, data, err = this.wsConn.ReadMessage(); err != nil { + log.Errorf("agent:%s uId:%s ReadMessage err:%v", this.sessionId, this.uId, err) + go this.Close() + break locp + } + + if err = proto.Unmarshal(data, msg); err != nil { + log.Errorf("agent:%s uId:%s Unmarshal err:%v", this.sessionId, this.uId, err) + go this.Close() + break locp + } else { + // this.gateway.Debugf("----------2 agent:%s uId:%s MainType:%s SubType:%s ", this.sessionId, this.uId, msg.MainType, msg.SubType) + if err = this.messageDistribution(msg); err != nil { + break locp + } + + } + } + log.Debugf("agent:%s uId:%s readLoop end!", this.sessionId, this.uId) +} + +// 外部代用关闭 +func (this *Client) Close() { + if !atomic.CompareAndSwapInt32(&this.state, 1, 2) { + return + } + this.wsConn.Close() + this.closeSignal <- true + this.wg.Wait() + atomic.StoreInt32(&this.state, 0) +} + +// 分发用户消息 +func (this *Client) messageDistribution(msg *pb.UserMessage) (err error) { + + return +} diff --git a/modules/robot/module.go b/modules/robot/module.go new file mode 100644 index 000000000..b95529f8c --- /dev/null +++ b/modules/robot/module.go @@ -0,0 +1,46 @@ +package robot + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/base" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" +) + +/* +模块名:红点系统 +描述:统一获取红点信息 +开发:李伟 +*/ +func NewModule() core.IModule { + m := new(Reddot) + return m +} + +type Reddot struct { + modules.ModuleBase + service base.IRPCXService +} + +// 模块名 +func (this *Reddot) GetType() core.M_Modules { + return comm.ModuleReddot +} + +// 模块初始化接口 注册用户创建角色事件 +func (this *Reddot) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { + err = this.ModuleBase.Init(service, module, options) + this.service = service.(base.IRPCXService) + return +} +func (this *Reddot) Start() (err error) { + err = this.ModuleBase.Start() + + return +} + +// 装备组件 +func (this *Reddot) OnInstallComp() { + this.ModuleBase.OnInstallComp() + +} diff --git a/services/robot/main.go b/services/robot/main.go new file mode 100644 index 000000000..44d1b8f4b --- /dev/null +++ b/services/robot/main.go @@ -0,0 +1,65 @@ +package main + +import ( + "flag" + "fmt" + "go_dreamfactory/services" + "go_dreamfactory/sys/db" + + "go_dreamfactory/lego" + "go_dreamfactory/lego/base/rpcx" + "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/cron" + "go_dreamfactory/lego/sys/log" +) + +/* +服务类型:mainte +服务描述:数据库维护以及GM后台接口 服务 +*/ +var ( + conf = flag.String("conf", "./conf/robot.yaml", "获取需要启动的服务配置文件") //启动服务的Id +) + +/*服务启动的入口函数*/ +func main() { + flag.Parse() + s := NewService( + rpcx.SetConfPath(*conf), + rpcx.SetVersion("1.0.0.0"), + ) + s.OnInstallComp( //装备组件 + //services.NewGateRouteComp(), //此服务需要接受用户的消息 需要装备网关组件 + ) + lego.Run(s) //运行模块 + +} + +func NewService(ops ...rpcx.Option) core.IService { + s := new(Service) + s.Configure(ops...) + return s +} + +// worker 的服务对象定义 +type Service struct { + services.ServiceBase +} + +// 初始化worker需要的一些系统工具 +func (this *Service) InitSys() { + this.ServiceBase.InitSys() + + //定时系统 + if err := cron.OnInit(nil); err != nil { + panic(fmt.Sprintf("init sys.cron err: %s", err.Error())) + } else { + log.Infof("init sys.cron success!") + } + //存储系统 + if err := db.OnInit(this.GetSettings().Sys["db"]); err != nil { + panic(fmt.Sprintf("init sys.db err: %s", err.Error())) + } else { + log.Infof("init sys.db success!") + } +}