跨服查询英雄数据
This commit is contained in:
parent
ddf5d1816f
commit
9138866fad
@ -61,7 +61,7 @@ const (
|
|||||||
ModuleHunting core.M_Modules = "hunting" //狩猎
|
ModuleHunting core.M_Modules = "hunting" //狩猎
|
||||||
ModuleLinestory core.M_Modules = "linestory" //支线剧情
|
ModuleLinestory core.M_Modules = "linestory" //支线剧情
|
||||||
ModuleBattle core.M_Modules = "battle" //战斗
|
ModuleBattle core.M_Modules = "battle" //战斗
|
||||||
ModuleLibrary core.M_Modules = "library" //
|
ModuleLibrary core.M_Modules = "library" // 藏书馆
|
||||||
//ModuleFetter core.M_Modules = "herofetter" //好友模块
|
//ModuleFetter core.M_Modules = "herofetter" //好友模块
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -147,6 +147,8 @@ const (
|
|||||||
TableFetter = "herofetter"
|
TableFetter = "herofetter"
|
||||||
|
|
||||||
TableCrossSession = "crosssession"
|
TableCrossSession = "crosssession"
|
||||||
|
|
||||||
|
TableServerData = "serverdata" // 跨服服务器相关数据
|
||||||
)
|
)
|
||||||
|
|
||||||
//RPC服务接口定义处
|
//RPC服务接口定义处
|
||||||
|
@ -63,6 +63,8 @@ type (
|
|||||||
|
|
||||||
//Create Monster
|
//Create Monster
|
||||||
CreateMonster(heroCid string, star, lv int32) (hero *pb.DBHero)
|
CreateMonster(heroCid string, star, lv int32) (hero *pb.DBHero)
|
||||||
|
// 跨服查询英雄详细信息
|
||||||
|
QueryCrossHeroinfo(oid string) (hero *pb.DBHero, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
//玩家
|
//玩家
|
||||||
|
@ -7,7 +7,11 @@ import (
|
|||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
"go_dreamfactory/modules"
|
"go_dreamfactory/modules"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
|
"go_dreamfactory/sys/db"
|
||||||
"go_dreamfactory/utils"
|
"go_dreamfactory/utils"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewModule() core.IModule {
|
func NewModule() core.IModule {
|
||||||
@ -337,3 +341,25 @@ func (this *Hero) CreateMonster(heroCid string, star, lv int32) (hero *pb.DBHero
|
|||||||
hero = this.modelHero.InitTempHero(heroCid, star, lv)
|
hero = this.modelHero.InitTempHero(heroCid, star, lv)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 只通过唯一id 查询英雄信息
|
||||||
|
func (this *Hero) QueryCrossHeroinfo(oid string) (hero *pb.DBHero, err error) {
|
||||||
|
for _, tag := range db.GetServerTags() {
|
||||||
|
conn, err1 := db.ServerDBConn(tag) // 遍历连接对象
|
||||||
|
if err1 != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
filter := bson.M{
|
||||||
|
"_id": oid,
|
||||||
|
}
|
||||||
|
sr := conn.Mgo.FindOne(comm.TableHero, filter)
|
||||||
|
hero = &pb.DBHero{}
|
||||||
|
if err = sr.Decode(hero); err != nil {
|
||||||
|
if err != mongo.ErrNoDocuments {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -28,6 +28,7 @@ const (
|
|||||||
UserSubTypeBattlerecord = "battlerecord" //玩家战斗记录
|
UserSubTypeBattlerecord = "battlerecord" //玩家战斗记录
|
||||||
UserSubTypeShowteam = "showteam" //展示阵容
|
UserSubTypeShowteam = "showteam" //展示阵容
|
||||||
UserSubTypeSettingteam = "settingteam" //设置阵容展示
|
UserSubTypeSettingteam = "settingteam" //设置阵容展示
|
||||||
|
UserGetServerDataResp = "getserverdata" //获取服务器信息
|
||||||
)
|
)
|
||||||
|
|
||||||
type apiComp struct {
|
type apiComp struct {
|
||||||
|
35
modules/user/api_getserverdata.go
Normal file
35
modules/user/api_getserverdata.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
"go_dreamfactory/sys/db"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (this *apiComp) GetServerDataCheck(session comm.IUserSession, req *pb.UserGetServerDataReq) (code pb.ErrorCode) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *apiComp) GetServerData(session comm.IUserSession, req *pb.UserGetServerDataReq) (code pb.ErrorCode, data proto.Message) {
|
||||||
|
|
||||||
|
rsp := &pb.UserGetServerDataResp{
|
||||||
|
Data: &pb.DBServerData{},
|
||||||
|
}
|
||||||
|
|
||||||
|
if conn, err := db.Cross(); err == nil {
|
||||||
|
dbModel := db.NewDBModel(comm.TableHero, time.Hour, conn)
|
||||||
|
if _data := dbModel.DB.FindOne("serverdata", bson.M{}); _data != nil {
|
||||||
|
_data.Decode(rsp.Data)
|
||||||
|
} else {
|
||||||
|
this.module.Errorf("err:%v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := session.SendMsg(string(this.module.GetType()), UserGetServerDataResp, rsp); err != nil {
|
||||||
|
code = pb.ErrorCode_SystemError
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
@ -143,5 +143,6 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (cod
|
|||||||
|
|
||||||
//推送登录公告
|
//推送登录公告
|
||||||
this.chat.SendSysChatToUser(session, comm.UserLoginNotice, 0)
|
this.chat.SendSysChatToUser(session, comm.UserLoginNotice, 0)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/modules/battle"
|
"go_dreamfactory/modules/battle"
|
||||||
"go_dreamfactory/modules/chat"
|
"go_dreamfactory/modules/chat"
|
||||||
"go_dreamfactory/modules/equipment"
|
"go_dreamfactory/modules/equipment"
|
||||||
@ -28,6 +29,7 @@ import (
|
|||||||
"go_dreamfactory/modules/task"
|
"go_dreamfactory/modules/task"
|
||||||
"go_dreamfactory/modules/user"
|
"go_dreamfactory/modules/user"
|
||||||
"go_dreamfactory/modules/viking"
|
"go_dreamfactory/modules/viking"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
"go_dreamfactory/services"
|
"go_dreamfactory/services"
|
||||||
"go_dreamfactory/sys/db"
|
"go_dreamfactory/sys/db"
|
||||||
"time"
|
"time"
|
||||||
@ -37,6 +39,9 @@ import (
|
|||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
"go_dreamfactory/lego/sys/timewheel"
|
"go_dreamfactory/lego/sys/timewheel"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -112,4 +117,21 @@ func (this *Service) InitSys() {
|
|||||||
} else {
|
} else {
|
||||||
log.Infof("init sys.db success!")
|
log.Infof("init sys.db success!")
|
||||||
}
|
}
|
||||||
|
conn, err := db.Local()
|
||||||
|
if err == nil {
|
||||||
|
model := db.NewDBModel(comm.TableServerData, 0, conn)
|
||||||
|
_len, err1 := model.DB.CountDocuments(comm.TableServerData, bson.M{})
|
||||||
|
if err1 != nil && _len > 0 {
|
||||||
|
fmt.Printf("%v,%v", _len, err1)
|
||||||
|
server := &pb.DBServerData{
|
||||||
|
Id: primitive.NewObjectID().Hex(),
|
||||||
|
ServerState: 1,
|
||||||
|
DisposableLoop: 1,
|
||||||
|
FixedLoop: 0,
|
||||||
|
SeasonType: 201,
|
||||||
|
OpenTime: time.Now().Unix(),
|
||||||
|
}
|
||||||
|
model.DB.InsertOne(comm.TableServerData, server)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user