package battle import ( "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/lego/core" "github.com/gorilla/websocket" "google.golang.org/protobuf/proto" ) /* 战斗服务客户端组件 */ type clientComp struct { modules.MCompGate options *Options service core.IService module *Battle conn *websocket.Conn } //组件初始化接口 func (this *clientComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.MCompGate.Init(service, module, comp, options) this.options = options.(*Options) this.module = module.(*Battle) return } func (this *clientComp) Start() (err error) { err = this.MCompGate.Start() dialer := websocket.Dialer{} this.conn, _, err = dialer.Dial(this.options.BattleServerAddr, nil) return } //校验战斗过程 func (this *clientComp) CheckBattle() { } func (this *clientComp) run() { var ( data []byte msg *pb.BattleRpcMessage = &pb.BattleRpcMessage{} err error ) locp: for { if _, data, err = this.conn.ReadMessage(); err != nil { this.module.Errorf("client err:%v", err) break locp } if err = proto.Unmarshal(data, msg); err != nil { this.module.Errorf("client Unmarshal err:%v", err) break locp } } }