From d54401a3febf9c9a0a0f2ccc26aff200a08b33ce Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Fri, 10 Feb 2023 14:44:09 +0800 Subject: [PATCH] update --- modules/friend/api_cross_accept.go | 2 +- modules/friend/api_cross_qiecuo.go | 6 ------ modules/friend/model_qiecuo.go | 20 ++++++++++++++------ modules/user/module.go | 2 ++ pb/friend_db.pb.go | 28 +++++++++++++++++++--------- sys/db/db.go | 5 +++-- 6 files changed, 39 insertions(+), 24 deletions(-) diff --git a/modules/friend/api_cross_accept.go b/modules/friend/api_cross_accept.go index 20ab7458f..4ef00eacf 100644 --- a/modules/friend/api_cross_accept.go +++ b/modules/friend/api_cross_accept.go @@ -29,7 +29,7 @@ func (this *apiComp) Accept(session comm.IUserSession, req *pb.FriendAcceptReq) if now-qr.Timestamp > 10 { //大于10s 切磋超时 code = pb.ErrorCode_FriendQiecuoTimeout //清除切磋记录 - this.moduleFriend.ModelFriendQiecuo.Del(req.Uid) + // this.moduleFriend.ModelFriendQiecuo.Del(req.Uid) return } } else { diff --git a/modules/friend/api_cross_qiecuo.go b/modules/friend/api_cross_qiecuo.go index 2a6658031..5ded5bcfd 100644 --- a/modules/friend/api_cross_qiecuo.go +++ b/modules/friend/api_cross_qiecuo.go @@ -30,12 +30,6 @@ func (this *apiComp) Qiecuo(session comm.IUserSession, req *pb.FriendQiecuoReq) return } - //已发送切磋 - // if qr.Timestamp != 0 { - // code = pb.ErrorCode_FriendQiecuoRequested - // return - // } - //判断是否切磋中 if qr.MatchId != "" { code = pb.ErrorCode_FriendQiecuoing diff --git a/modules/friend/model_qiecuo.go b/modules/friend/model_qiecuo.go index 5cd6baf32..5a8cebf86 100644 --- a/modules/friend/model_qiecuo.go +++ b/modules/friend/model_qiecuo.go @@ -44,18 +44,25 @@ func (this *ModelFriendQiecuo) createQiecuoRecord(uid, targetUid string) (*pb.Qi Uid: uid, TargetId: targetUid, Timestamp: configure.Now().Unix(), + Status: 1, //已发起 } if err := this.Add(uid, qr); err != nil { this.moduleFriend.Errorln(err) return nil, err } } else { - update := map[string]interface{}{ - "targetId": targetUid, - "timestamp": configure.Now().Unix(), - } - if err := this.Change(uid, update); err != nil { - return nil, err + //如果目标未接受且在超时时间内,不允许再次发送 + now := configure.Now().Unix() + if qr.Status == 1 && now-qr.Timestamp < 10 { + return qr, comm.NewCustomError(pb.ErrorCode_FriendQiecuoRequested) + } else { + update := map[string]interface{}{ + "targetId": targetUid, + "timestamp": configure.Now().Unix(), + } + if err := this.Change(uid, update); err != nil { + return nil, err + } } } @@ -68,6 +75,7 @@ func (this *ModelFriendQiecuo) updateQiecuoRecord(uid, targetUid, matchId string if qr != nil { update := map[string]interface{}{ "matchId": matchId, + "status": 2, //已接受 } if err := this.Change(uid, update); err != nil { this.moduleFriend.Errorln(err) diff --git a/modules/user/module.go b/modules/user/module.go index e7a1537e0..913207e17 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -129,6 +129,7 @@ func (this *User) GetCrossUser(uid string) (*pb.DBUser, error) { func (this *User) getRemoteUser(uid string) (*pb.DBUser, error) { reply := &pb.DBUser{} if err := this.getUserFromRemoteDb(uid, reply); err != nil { + this.Errorln("getRemoteUser", err) return nil, err } this.Debug("远程用户", log.Field{Key: "uid", Value: uid}, log.Field{Key: "user", Value: reply}) @@ -563,6 +564,7 @@ func (this *User) getUserFromRemoteDb(uid string, rsp *pb.DBUser) error { this.Errorln("Get User:", err) return err } + this.Debug("Get", log.Field{Key: "rsp",Value: rsp}) return nil } diff --git a/pb/friend_db.pb.go b/pb/friend_db.pb.go index 61647e5bb..ba1fdd1d3 100644 --- a/pb/friend_db.pb.go +++ b/pb/friend_db.pb.go @@ -227,6 +227,7 @@ type QiecuoRecord struct { Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid" bson:"uid"` //切磋发起人 TargetId string `protobuf:"bytes,2,opt,name=targetId,proto3" json:"targetId" bson:"targetId"` //切磋接受人 + Status int32 `protobuf:"varint,3,opt,name=status,proto3" json:"status" bson:"status"` //0默认 1已发送 2已接收 3已匹配 MatchId string `protobuf:"bytes,4,opt,name=matchId,proto3" json:"matchId" bson:"matchId"` //战斗ID Timestamp int64 `protobuf:"varint,5,opt,name=timestamp,proto3" json:"timestamp" bson:"timestamp"` //切磋发起时间戳 } @@ -277,6 +278,13 @@ func (x *QiecuoRecord) GetTargetId() string { return "" } +func (x *QiecuoRecord) GetStatus() int32 { + if x != nil { + return x.Status + } + return 0 +} + func (x *QiecuoRecord) GetMatchId() string { if x != nil { return x.MatchId @@ -326,15 +334,17 @@ var file_friend_friend_db_proto_rawDesc = []byte{ 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x61, 0x73, 0x73, 0x69, 0x73, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x61, 0x73, 0x73, 0x69, 0x73, 0x74, 0x48, 0x65, 0x72, 0x6f, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x61, 0x73, 0x73, 0x69, 0x73, 0x74, 0x48, - 0x65, 0x72, 0x6f, 0x49, 0x64, 0x22, 0x74, 0x0a, 0x0c, 0x51, 0x69, 0x65, 0x63, 0x75, 0x6f, 0x52, - 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x74, 0x61, 0x72, 0x67, 0x65, - 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x74, 0x61, 0x72, 0x67, 0x65, - 0x74, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x49, 0x64, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x49, 0x64, 0x12, 0x1c, 0x0a, - 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, - 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, - 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x72, 0x6f, 0x49, 0x64, 0x22, 0x8c, 0x01, 0x0a, 0x0c, 0x51, 0x69, 0x65, 0x63, 0x75, 0x6f, + 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x74, 0x61, 0x72, 0x67, + 0x65, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x74, 0x61, 0x72, 0x67, + 0x65, 0x74, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x18, 0x0a, 0x07, + 0x6d, 0x61, 0x74, 0x63, 0x68, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, + 0x61, 0x74, 0x63, 0x68, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, + 0x61, 0x6d, 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, + 0x74, 0x61, 0x6d, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/sys/db/db.go b/sys/db/db.go index 5878fa508..5da54feba 100644 --- a/sys/db/db.go +++ b/sys/db/db.go @@ -47,7 +47,7 @@ func (this *DB) init() (err error) { return } -//读取游戏配置文件 +// 读取游戏配置文件 func (this *DB) readercrossconf(path string) (err error) { config := make(comm.CrossConfigs, 0) var ( @@ -93,7 +93,7 @@ func (this *DB) readercrossconf(path string) (err error) { return } -//同步服务列表 +// 同步服务列表 func (this *DB) SyncServiceList() (err error) { if this.options.IsCross { err = this.ConnectServiceList() @@ -175,6 +175,7 @@ func (this *DB) ServerDBConn(stage string) (conn *DBConn, err error) { if !ok { err = fmt.Errorf("DBConn:%s on init", stage) } + log.Debug("servers", log.Field{Key: stage, Value: this.servers[stage]}) return }