You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.5 KiB
85 lines
2.5 KiB
package serviceGame |
|
|
|
import ( |
|
"context" |
|
"encoding/json" |
|
"github.com/gogf/gf/v2/errors/gerror" |
|
"github.com/gogf/gf/v2/frame/g" |
|
"tyj_admin/api/v1/game" |
|
"tyj_admin/internal/model/entity" |
|
"tyj_admin/internal/serviceGame/internal" |
|
) |
|
|
|
type IGameRole interface { |
|
GetGameRoleListSearch(ctx context.Context, req *game.RoleSearchReq) (res *game.RoleSearchRes, err error) |
|
GetRoleDetail(ctx context.Context, req *game.RoleDetailReq) (res *game.RoleDetailRes, err error) |
|
GetOnlineList(ctx context.Context, req *game.RoleOnlineReq) (res *game.RoleOnlineRes, err error) |
|
GetAccount(ctx context.Context, req *game.AccountReq) (res *game.AccountRes, err error) |
|
} |
|
|
|
type gameRoleImpl struct { |
|
} |
|
|
|
var gameRoleService = gameRoleImpl{} |
|
|
|
func GameRole() IGameRole { |
|
return &gameRoleService |
|
} |
|
|
|
// 获取玩家角色列表 |
|
func (s *gameRoleImpl) GetGameRoleListSearch(ctx context.Context, req *game.RoleSearchReq) (res *game.RoleSearchRes, err error) { |
|
res = new(game.RoleSearchRes) |
|
g.Try(ctx, func(ctx context.Context) { |
|
res.RoleList, err = internal.GetRoleList(ctx, req.Account) |
|
}) |
|
return |
|
} |
|
|
|
// 获取角色详情 |
|
func (s *gameRoleImpl) GetRoleDetail(ctx context.Context, req *game.RoleDetailReq) (res *game.RoleDetailRes, err error) { |
|
res = new(game.RoleDetailRes) |
|
g.Try(ctx, func(ctx context.Context) { |
|
res.RoleDetail, err = internal.GetRoleDetail(ctx, req.Uid, req.Channel) |
|
}) |
|
return |
|
} |
|
|
|
func (m *gameRoleImpl) GetOnlineList(ctx context.Context, req *game.RoleOnlineReq) (res *game.RoleOnlineRes, err error) { |
|
res = new(game.RoleOnlineRes) |
|
mqttMsg := internal.MqttOnlineReq{1, "onlineUser"} |
|
js, err := json.Marshal(mqttMsg) |
|
connectCh := make(chan *internal.MqttOnlineRes) |
|
defer close(connectCh) |
|
server := "192.168.2.100:3005" |
|
internal.SendMqttOnline(js, connectCh, server) |
|
var result *internal.MqttOnlineRes |
|
for { |
|
select { |
|
case result = <-connectCh: |
|
if result.Error != nil { |
|
err = gerror.New("失败") |
|
return |
|
} else { |
|
for _, v := range result.Body { |
|
for _, login := range v.LoginedList { |
|
info := new(entity.Online) |
|
info.ConnectId = v.ServerId |
|
info.Uid = login.Uid |
|
info.LoginTime = login.LoginTime |
|
info.Address = login.Address |
|
res.Onlines = append(res.Onlines, info) |
|
} |
|
|
|
} |
|
return |
|
} |
|
} |
|
} |
|
return |
|
} |
|
|
|
func (m *gameRoleImpl) GetAccount(ctx context.Context, req *game.AccountReq) (res *game.AccountRes, err error) { |
|
res = new(game.AccountRes) |
|
res.Accounts, err = internal.GetAccountList(ctx, req.Account, req.Tel, req.Ident, req.Name) |
|
return |
|
}
|
|
|