diff --git a/modules/arena/modelarena.go b/modules/arena/modelarena.go index a1ac5c384..bf4b38702 100644 --- a/modules/arena/modelarena.go +++ b/modules/arena/modelarena.go @@ -387,11 +387,35 @@ func (this *modelArena) recoverTicket(info *pb.DBArenaUser) { func (this *modelArena) reddot(session comm.IUserSession) bool { var ( info *pb.DBArenaUser + user *pb.DBUser err error ) if info, err = this.queryPlayerInfo(session.GetUserId()); err != nil { return false } + if err == mgo.MongodbNil { + global := this.module.configure.GetGlobalConf() + if user = this.module.ModuleUser.GetUser(session.GetUserId()); user == nil { + return false + } + info = &pb.DBArenaUser{ + Uid: session.GetUserId(), + Name: user.Name, + Integral: global.ArenaInitiaIntegral, + Ticket: 10, + Streak: 0, + Record: make([]*pb.DBArenaBattleRecord, 0), + Lastrtickettime: 0, + Isdef: false, + Npc: make(map[int32]*pb.DBNpc), + } + if info.Dan, err = this.module.modelArena.computedan(info.Integral); err != nil { + return false + } + if err = this.module.modelArena.Add(session.GetUserId(), info); err != nil { + return false + } + } if info.Ticket > this.module.configure.GetGlobalConf().ArenaTicketCos { return true } diff --git a/modules/arena/module.go b/modules/arena/module.go index da92f88e4..c7873cc90 100644 --- a/modules/arena/module.go +++ b/modules/arena/module.go @@ -78,9 +78,7 @@ func (this *Arena) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (re for _, v := range rid { switch v { case comm.Reddot19: - if isredot := this.modelArena.reddot(session); isredot { - result[comm.Reddot19] = true - } + result[comm.Reddot19] = this.modelArena.reddot(session) break } } diff --git a/modules/battle/client.go b/modules/battle/client.go index c33801b19..e58bdbd01 100644 --- a/modules/battle/client.go +++ b/modules/battle/client.go @@ -2,10 +2,12 @@ package battle import ( "go_dreamfactory/modules" + "go_dreamfactory/pb" "go_dreamfactory/lego/core" "github.com/gorilla/websocket" + "google.golang.org/protobuf/proto" ) /* @@ -38,3 +40,22 @@ func (this *clientComp) Start() (err error) { 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 + } + } +} diff --git a/modules/battle/module_test.go b/modules/battle/module_test.go index c7242c0fc..b6160342f 100644 --- a/modules/battle/module_test.go +++ b/modules/battle/module_test.go @@ -12,6 +12,7 @@ import ( "go_dreamfactory/modules/hero" "go_dreamfactory/modules/items" "go_dreamfactory/modules/user" + "go_dreamfactory/pb" "go_dreamfactory/services" "go_dreamfactory/sys/configure" "go_dreamfactory/sys/db" @@ -20,6 +21,8 @@ import ( "time" "github.com/gorilla/websocket" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/anypb" ) func newService(ops ...rpcx.Option) core.IService { @@ -95,6 +98,12 @@ func Test_Comment(t *testing.T) { return } else { defer connect.Close() - connect.WriteMessage(websocket.TextMessage, []byte("from client to server")) + msg := &pb.BattleRpcMessage{ + Rid: 1, + Method: "test", + } + msg.Data, _ = anypb.New(&pb.BattleTestMessage{}) + data, _ := proto.Marshal(msg) + connect.WriteMessage(websocket.BinaryMessage, data) } } diff --git a/modules/horoscope/module.go b/modules/horoscope/module.go index 71506aa44..c1e0250cd 100644 --- a/modules/horoscope/module.go +++ b/modules/horoscope/module.go @@ -64,9 +64,7 @@ func (this *Horoscope) Reddot(session comm.IUserSession, rid ...comm.ReddotType) for _, v := range rid { switch v { case comm.Reddot17: - if isredot := this.modelHoroscope.reddot(session); isredot { - result[comm.Reddot17] = true - } + result[comm.Reddot17] = this.modelHoroscope.reddot(session) break } } diff --git a/modules/martialhall/module.go b/modules/martialhall/module.go index c8305cedb..8fdf936ae 100644 --- a/modules/martialhall/module.go +++ b/modules/martialhall/module.go @@ -56,19 +56,13 @@ func (this *Martialhall) Reddot(session comm.IUserSession, rid ...comm.ReddotTyp for _, v := range rid { switch v { case comm.Reddot23: - if isredot := this.modelMartialhall.checkReddot23(session); isredot { - reddot[comm.Reddot23] = true - } + reddot[comm.Reddot23] = this.modelMartialhall.checkReddot23(session) break case comm.Reddot24: - if isredot := this.modelMartialhall.checkReddot24(session); isredot { - reddot[comm.Reddot24] = true - } + reddot[comm.Reddot24] = this.modelMartialhall.checkReddot24(session) break case comm.Reddot25: - if isredot := this.modelMartialhall.checkReddot25(session); isredot { - reddot[comm.Reddot25] = true - } + reddot[comm.Reddot25] = this.modelMartialhall.checkReddot25(session) break } }