新增rpc接口

This commit is contained in:
hahwu 2026-03-31 11:44:48 +08:00
parent 0f31ddd868
commit a6993fa15f
2 changed files with 105 additions and 0 deletions

View File

@ -31,6 +31,16 @@ func (s *backendServer) OrderShipping(ctx context.Context, req *msg.ReqOrderShip
return res, nil return res, nil
} }
func (s *backendServer) UserDetail(ctx context.Context, req *msg.UserDetailParam) (*msg.ResUserDetail, error) {
log.Debug("Received UserDetail request: %v", req)
res, err := game.AdminPlayerDetailInfo(req)
if err != nil {
log.Error("UserDetail error: %v", err)
return nil, err
}
return res, nil
}
func Start() { func Start() {
if conf.Server.RPCAddr == "" { if conf.Server.RPCAddr == "" {
log.Debug("RPC server address not configured, skipping gRPC server startup") log.Debug("RPC server address not configured, skipping gRPC server startup")

View File

@ -13,6 +13,7 @@ import (
"server/msg" "server/msg"
"server/pkg/github.com/name5566/leaf/gate" "server/pkg/github.com/name5566/leaf/gate"
"server/pkg/github.com/name5566/leaf/log" "server/pkg/github.com/name5566/leaf/log"
"strconv"
"time" "time"
"github.com/shirou/gopsutil/cpu" "github.com/shirou/gopsutil/cpu"
@ -348,3 +349,97 @@ func AdminShipping(req *msg.ReqOrderShipping) (*msg.ResOrderShipping, error) {
} }
return res, nil return res, nil
} }
func AdminPlayerDetailInfo(req *msg.UserDetailParam) (*msg.ResUserDetail, error) {
player := G_GameLogicPtr.GetPlayer(req.Uid)
online := true
if player == nil {
player = new(Player)
player.M_DwUin = req.Uid
player.InitPlayerOnly()
player.ZeroUpdate(nil)
online = false
}
banTime := db.GetPlayerBan(player.PlayMod.getBaseMod().Account)
actLog := make([]*msg.ActLog, 0, len(player.PlayMod.getFriendMod().ActivityLog))
for _, v := range player.PlayMod.getFriendMod().ActivityLog {
actLog = append(actLog, &msg.ActLog{
Type: int32(v.Type),
Time: v.Time,
Param: v.Param,
})
}
info := &msg.ResUserDetailInfo{
Name: player.PlayMod.getBaseMod().NickName,
Uid: player.M_DwUin,
AreaId: int32(player.PlayMod.getDecorateMod().GetAreaId()),
Face: int32(player.PlayMod.getFaceMod().SetId),
Charge: int32(player.PlayMod.getChargeMod().Charge),
MaxCharge: int32(player.PlayMod.getChargeMod().MaxCharge),
Level: int32(player.GetPlayerBaseMod().GetLevel()),
Diamond: int64(player.GetPlayerBaseMod().GetDiamond()),
Star: int32(player.GetPlayerBaseMod().GetStar()),
Energy: int32(player.GetPlayerBaseMod().GetEnergy()),
Mac: player.GetPlayerBaseMod().GetName(),
Login: int64(player.PlayMod.getBaseMod().LoginTime),
Cumulative: int64(player.PlayMod.getBaseMod().Cumulative),
RegisterTime: player.GetPlayerBaseMod().GetRegisterTime(),
TodayCumulative: int64(player.PlayMod.getBaseMod().TodayCumulative),
Ban: banTime > GoUtil.Now() || banTime == -1,
Bonus: int32(player.PlayMod.getLimitedTimeEventMod().Progress),
Code: player.PlayMod.getBaseMod().AddCode,
ActLog: actLog,
AdWatch: int32(player.PlayMod.getKvMod().GetAdValue()),
}
if online {
info.Cumulative = int64(player.PlayMod.getBaseMod().Cumulative) + GoUtil.Now() - int64(player.PlayMod.getBaseMod().LoginTime)
info.TodayCumulative = int64(player.PlayMod.getBaseMod().TodayCumulative) + GoUtil.Now() - int64(player.PlayMod.getBaseMod().LoginTime)
}
if chessMap := player.PlayMod.getChessMod().ChessMap; len(chessMap) > 0 {
info.ChessMap = make(map[int32]int32, len(chessMap))
for key, value := range chessMap {
chessID, err := strconv.Atoi(key)
if err != nil {
continue
}
info.ChessMap[int32(chessID)] = value
}
}
friendList := player.PlayMod.getFriendMod().NewFriendList
info.FriendList = make([]*msg.UserDetailFriendInfo, 0, len(friendList))
for uid := range friendList {
ps := G_GameLogicPtr.GetSimplePlayerByUid(uid)
if ps == nil {
continue
}
info.FriendList = append(info.FriendList, &msg.UserDetailFriendInfo{
Uid: int64(uid),
NickName: ps.Name,
Avatar: int32(ps.Face),
Level: int32(ps.Level),
LogoutTime: ps.Loginout,
LoginTime: ps.Login,
})
}
orderList := player.PlayMod.getOrderMod().OrderList
info.Order = make([]*msg.UserDetailOrderInfo, 0, len(orderList))
for orderID, order := range orderList {
info.Order = append(info.Order, &msg.UserDetailOrderInfo{
Id: fmt.Sprint(orderID),
Type: int32(order.Type),
Time: order.Timestamp,
ChessId: GoUtil.IntSliceToString(order.MergeId),
Diff: int32(order.Diff),
})
}
return &msg.ResUserDetail{
Code: 0,
Msg: "ok",
Info: info,
}, nil
}