Browse Source

online, server services

master
linquan 4 weeks ago
parent
commit
816925d56f
  1. 4
      api/v1/game/basicinfo.go
  2. 74
      api/v1/game/pub.go
  3. 23
      internal/controller/game_server.go
  4. 5
      internal/controller/out_id.go
  5. 27
      internal/dao/game_online_count.go
  6. 77
      internal/dao/internal/game_online_count.go
  7. 17
      internal/model/do/game_online_count.go
  8. 12
      internal/model/entity/game_online_count.go
  9. 11
      internal/serviceGame/cron.go
  10. 21
      internal/serviceGame/game_role.go
  11. 66
      internal/serviceGame/internal/basicinfo.go
  12. 1
      internal/serviceGame/internal/dbinit.go
  13. 49
      internal/serviceGame/internal/manage.go
  14. 109
      internal/serviceGame/internal/online.go
  15. 7
      internal/serviceGame/internal/out.go
  16. 12
      internal/serviceGame/manage.go
  17. 11
      internal/serviceGame/pub.go

4
api/v1/game/basicinfo.go

@ -47,8 +47,8 @@ type RoleOnlineTop struct {
type RoleOnlineTopRes struct {
g.Meta `mime:"application/json"`
Onlines []RoleOnlineTop `json:"onlines"`
Total int `json:"total"`
Onlines []entity.GameOnlineCount `json:"onlines"`
Total int `json:"total"`
}
type AccountReq struct {

74
api/v1/game/pub.go

@ -26,6 +26,16 @@ type GetOutIdRes struct {
Id int64 `json:"publicId"`
}
type GetItemIdReq struct {
g.Meta `path:"/uniqueId/get" tags:"外部接口" method:"get" summary:"获取id"`
Type int64 `p:"type" description:"类型、"`
}
type GetItemIdRes struct {
g.Meta `mime:"application/json"`
Id int64 `json:"uniqueId"`
}
type LoginOutReq struct {
g.Meta `path:"/loginOut" tags:"外部接口" method:"post" summary:"添加登录登出记录"`
Uid int64 `p:"uid"`
@ -167,3 +177,67 @@ type ItemRecordTwoReq struct {
type ItemRecordTwoRes struct {
g.Meta `mime:"application/json"`
}
type CheckUserReq struct {
g.Meta `path:"/user/check" tags:"账号" method:"get" summary:"查询账号"`
Username string `p:"username" v:"required#用户名不能为空"`
Password string `p:"password" v:"required#密码不能为空"`
}
type CheckUserRes struct {
g.Meta `mime:"application/json"`
Exist int32 `p:"exist"`
}
type UserLogReq struct {
g.Meta `path:"/user/log" tags:"账号" method:"get" summary:"账号使用记录"`
}
type UserLogRes struct {
g.Meta `mime:"application/json"`
}
type ReviewStateReq struct {
g.Meta `path:"/reviewState" tags:"账号" method:"get" summary:"审核状态"`
ServerId int32 `p:"serverId" `
State int32 `p:"state" `
}
type SmallLayoutBlueprint struct {
ArtID int64 `json:"ArtID"`
OwnerId int64 `json:"OwnerId"`
CreateTime int64 `json:"CreateTime"`
LikeInfos []int64 `json:"LikeInfos"`
SubscribeInfos []int64 `json:"SubscribeInfos"`
Name string `json:"Name"`
State int32 `json:"State"`
SmallLayoutInfos []SmallLayoutInfo `json:"SmallLayoutInfos"`
}
type SmallLayoutInfo struct {
GameUnitType int32 `json:"GameUnitType"`
ConfigId int32 `json:"ConfigId"`
PosX int32 `json:"PosX"`
PosY int32 `json:"PosY"`
IsFlip bool `json:"IsFlip"`
SkinId int32 `json:"SkinId"`
}
type ReviewStateRes struct {
g.Meta `mime:"application/json"`
ServerId int32 `json:"serverId"`
SmallLayoutBlueprint []map[string]interface{} `json:"SmallLayoutBlueprint"`
}
type SetReviewStateReq struct {
g.Meta `path:"/setReviewState" tags:"账号" method:"get" summary:"审核状态"`
ServerId int32 `p:"serverId" `
ArtID int64 `p:"ArtID" `
State int32 `p:"State" `
}
type SetReviewStateRes struct {
g.Meta `mime:"application/json"`
ServerId int32 `json:"serverId"`
Result int32 `json:"result"`
}

23
internal/controller/game_server.go

@ -5,6 +5,8 @@ import (
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/frame/g"
"tyj_admin/api/v1/game"
"tyj_admin/api/v1/system"
"tyj_admin/internal/service"
"tyj_admin/internal/serviceGame"
)
@ -119,3 +121,24 @@ func (c *serverController) LogAccount(ctx context.Context, req *game.LogAccountR
res, err = serviceGame.GameManage().LogAccount(ctx, req)
return
}
func (c *serverController) CheckUser(ctx context.Context, req *game.CheckUserReq) (res *game.CheckUserRes, err error) {
//res, err = serviceGame.GamePub().CheckUser(ctx, req)
_, err = service.User().GetAdminUserByUsernamePassword(ctx, &system.UserLoginReq{Username: req.Username, Password: req.Password})
if err == nil {
res.Exist = 1
} else {
res.Exist = 0
}
return
}
func (c *serverController) ReviewState(ctx context.Context, req *game.ReviewStateReq) (res *game.ReviewStateRes, err error) {
res, err = serviceGame.GameManage().ReviewState(ctx, req)
return
}
func (c *serverController) SetReviewState(ctx context.Context, req *game.SetReviewStateReq) (res *game.SetReviewStateRes, err error) {
res, err = serviceGame.GameManage().SetReviewState(ctx, req)
return
}

5
internal/controller/out_id.go

@ -16,3 +16,8 @@ func (c *outIdController) GetId(ctx context.Context, req *game.GetOutIdReq) (res
res, err = serviceGame.GamePub().GetId(ctx, req)
return
}
func (c *outIdController) GetItemId(ctx context.Context, req *game.GetItemIdReq) (res *game.GetItemIdRes, err error) {
res, err = serviceGame.GamePub().GetItemId(ctx, req)
return
}

27
internal/dao/game_online_count.go

@ -0,0 +1,27 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"tyj_admin/internal/dao/internal"
)
// internalGameOnlineCountDao is internal type for wrapping internal DAO implements.
type internalGameOnlineCountDao = *internal.GameOnlineCountDao
// gameOnlineCountDao is the data access object for table game_online_count.
// You can define custom methods on it to extend its functionality as you wish.
type gameOnlineCountDao struct {
internalGameOnlineCountDao
}
var (
// GameOnlineCount is globally public accessible object for table game_online_count operations.
GameOnlineCount = gameOnlineCountDao{
internal.NewGameOnlineCountDao(),
}
)
// Fill with you ideas below.

77
internal/dao/internal/game_online_count.go

@ -0,0 +1,77 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// GameOnlineCountDao is the data access object for table game_online_count.
type GameOnlineCountDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns GameOnlineCountColumns // columns contains all the column names of Table for convenient usage.
}
// GameOnlineCountColumns defines and stores column names for table game_online_count.
type GameOnlineCountColumns struct {
Id string //
Online string //
DailyTop string //
}
// gameOnlineCountColumns holds the columns for table game_online_count.
var gameOnlineCountColumns = GameOnlineCountColumns{
Id: "id",
Online: "online",
DailyTop: "daily_top",
}
// NewGameOnlineCountDao creates and returns a new DAO object for table data access.
func NewGameOnlineCountDao() *GameOnlineCountDao {
return &GameOnlineCountDao{
group: "default",
table: "game_online_count",
columns: gameOnlineCountColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *GameOnlineCountDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *GameOnlineCountDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *GameOnlineCountDao) Columns() GameOnlineCountColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *GameOnlineCountDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *GameOnlineCountDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *GameOnlineCountDao) Transaction(ctx context.Context, f func(ctx context.Context, tx *gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

17
internal/model/do/game_online_count.go

@ -0,0 +1,17 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
)
// GameOnlineCount is the golang structure of table game_online_count for DAO operations like Where/Data.
type GameOnlineCount struct {
g.Meta `orm:"table:game_online_count, do:true"`
Id interface{} //
Online interface{} //
DailyTop interface{} //
}

12
internal/model/entity/game_online_count.go

@ -0,0 +1,12 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
// GameOnlineCount is the golang structure for table game_online_count.
type GameOnlineCount struct {
Id int `json:"id" description:""`
Online int `json:"online" description:""`
DailyTop int `json:"dailyTop" description:""`
}

11
internal/serviceGame/cron.go

@ -40,6 +40,7 @@ func init() {
gameCronService.Cron(t.UnixMilli())
gameCronService.MailCron(t.UnixMilli())
gameCronService.CronAdvertisement(ctx, t.Unix())
gameCronService.CronDay(ctx, t.Unix())
}
}()
@ -224,3 +225,13 @@ func (c *gameCronImpl) CronAdvertisement(ctx context.Context, sTime int64) {
rdbTop.HSet(ctx, consts.ADVERTISE_DATA_SAVE, consts.ADVERTISE_TOKEN_REFRESH_SIGN, 0)
}
}
func (c *gameCronImpl) CronDay(ctx context.Context, sTime int64) {
t := time.Now()
addTime := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
timeSamp := addTime.Unix()
if sTime == timeSamp {
go internal.ResetOnlineTop(ctx)
}
return
}

21
internal/serviceGame/game_role.go

@ -7,9 +7,7 @@ import (
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"time"
"tyj_admin/api/v1/game"
"tyj_admin/internal/consts"
"tyj_admin/internal/serviceGame/internal"
)
@ -85,16 +83,17 @@ func (s *gameRoleImpl) GetOnlineList(ctx context.Context, req *game.RoleOnlineRe
}
func (s *gameRoleImpl) GetOnlineTopList(ctx context.Context, req *game.RoleOnlineTopReq) (res *game.RoleOnlineTopRes, err error) {
res = new(game.RoleOnlineTopRes)
fsql := fmt.Sprintf(`select max(num) as num,server,channel,date from game_online where STR_TO_DATE(date, "%%Y-%%m-%%d")="%s" `, time.Now().Format(consts.DATE_FORMAT))
if req.ServerId != 0 {
fsql += fmt.Sprintf("and server=%d ", req.ServerId)
}
fsql += "group by date,server,channel"
sSql := fmt.Sprintf(`select sum(b.num) as num,b.server,b.date from (%s) as b group by b.date,b.server`, fsql)
tsql := fmt.Sprintf(`select max(a.num) as num,a.server from (%s) as a group by a.server ORDER BY a.server asc`, sSql)
err = g.Model().Raw(tsql).Scan(&res.Onlines)
//fsql := fmt.Sprintf(`select max(num) as num,server,channel,date from game_online where STR_TO_DATE(date, "%%Y-%%m-%%d")="%s" `, time.Now().Format(consts.DATE_FORMAT))
//if req.ServerId != 0 {
// fsql += fmt.Sprintf("and server=%d ", req.ServerId)
//}
//fsql += "group by date,server,channel"
//sSql := fmt.Sprintf(`select sum(b.num) as num,b.server,b.date from (%s) as b group by b.date,b.server`, fsql)
//tsql := fmt.Sprintf(`select max(a.num) as num,a.server from (%s) as a group by a.server ORDER BY a.server asc`, sSql)
//err = g.Model().Raw(tsql).Scan(&res.Onlines)
//g.Log().Printf(ctx, "res.Onlines: %v", gjson.MustEncodeString(res.Onlines))
res, err = internal.GetOnlineTopList(ctx, req)
return
}

66
internal/serviceGame/internal/basicinfo.go

@ -58,16 +58,18 @@ func loadServeronline(k, sv string) {
g.Log().Info(ctx, " InitMysql === ", accounts)
for _, v := range accounts {
account := v.(string)
uv1, _ := strconv.ParseInt(account, 0, 64)
uv1, _ := strconv.ParseInt(account, 10, 64)
ids = append(ids, uv1)
}
g.Log().Info(ctx, " InitMysql ids=== ", ids)
}
id, err := strconv.Atoi(k)
go SetOnlineCount(ctx, id, len(ids))
if len(ids) > 0 {
model = model.WhereNotIn("uid", ids)
}
id, err := strconv.Atoi(k)
model.Where("server=?", id).Where("e_date=?", 0).Update("e_date=c_date")
g.Log().Info(ctx, "a== ", ids)
}
@ -761,7 +763,12 @@ func GetItemLogTwo(ctx context.Context, req *game.GetItemLogTwoReq) (res *game.G
return
}
var online = map[int]int64{}
type onlineData struct {
Time int64 `json:"time"`
Count int64 `json:"count"`
}
var online = map[string]int64{}
func GameRegister(ctx context.Context, req *game.RegisterReq) (res *game.RegisterRes, err error) {
if req.Account == "" {
@ -844,6 +851,7 @@ func setAccount(ctx context.Context, req *game.LoginOutReq) {
func LoginOut(ctx context.Context, req *game.LoginOutReq) (res *game.LoginOutRes, err error) {
g.Try(ctx, func(ctx context.Context) {
count := 0
modelLog := dao.LoginOutLog.Ctx(ctx)
var loginLog []entity.LoginOutLog
@ -856,6 +864,7 @@ func LoginOut(ctx context.Context, req *game.LoginOutReq) (res *game.LoginOutRes
modelLog.WherePri(loginLog[0].Id).Update(g.Map{
dao.LoginOutLog.Columns().EDate: gtime.Timestamp(),
})
//online[fmt.Sprint(req.Server)].Count -= 1
}
if req.State == consts.LogIn_State {
_, err = modelLog.Insert(&do.LoginOutLog{
@ -865,6 +874,9 @@ func LoginOut(ctx context.Context, req *game.LoginOutReq) (res *game.LoginOutRes
})
count = 1
go sendAdvertisement(ctx, req.Uid)
go IncrOnlineCount(ctx, req.Server)
} else if req.State == consts.LogOut_State {
go DecrOnlineCount(ctx, req.Server)
}
if count == 1 {
@ -922,28 +934,9 @@ func LoginOut(ctx context.Context, req *game.LoginOutReq) (res *game.LoginOutRes
})
}
}
if gtime.Now().Unix()-online[req.Server] > 5 {
online[req.Server] = gtime.Now().Unix()
var onlineData []entity.OnlineData
onlineModel := g.Model("login_out_log", "a").
Fields("count(1) as num,b.channel")
if req.Server != 0 {
onlineModel.Where("a.server=?", req.Server)
}
err1 := onlineModel.Where("a.e_date", 0).
InnerJoin("game_unit", "b", "b.uid=a.uid").
Group("b.channel").
Scan(&onlineData)
//g.Log().Debugf(ctx, "onlineData -> "+gjson.MustEncodeString(onlineData))
if err1 == nil {
var insertData []do.GameOnline
for _, v := range onlineData {
g.Log().Debugf(ctx, "onlineData -> "+gjson.MustEncodeString(v)+" channel:"+v.Channel)
insertData = append(insertData, do.GameOnline{Channel: v.Channel, Server: req.Server, Num: v.Num})
}
dao.GameOnline.Ctx(ctx).Insert(insertData)
}
if gtime.Now().Unix()-online[fmt.Sprint(req.Server)] > 5 {
online[fmt.Sprint(req.Server)] = gtime.Now().Unix()
go addOnline(ctx, req.Server)
}
return
@ -951,6 +944,29 @@ func LoginOut(ctx context.Context, req *game.LoginOutReq) (res *game.LoginOutRes
return
}
func addOnline(ctx context.Context, server int) {
var onlineData []entity.OnlineData
onlineModel := g.Model("login_out_log", "a").
Fields("count(1) as num,b.channel")
if server != 0 {
onlineModel.Where("a.server=?", server)
}
err1 := onlineModel.Where("a.e_date", 0).
InnerJoin("game_unit", "b", "b.uid=a.uid").
Group("b.channel").
Scan(&onlineData)
//g.Log().Debugf(ctx, "onlineData -> "+gjson.MustEncodeString(onlineData))
if err1 == nil {
var insertData []do.GameOnline
for _, v := range onlineData {
g.Log().Debugf(ctx, "onlineData -> "+gjson.MustEncodeString(v)+" channel:"+v.Channel)
insertData = append(insertData, do.GameOnline{Channel: v.Channel, Server: server, Num: v.Num})
}
dao.GameOnline.Ctx(ctx).Insert(insertData)
}
}
func sendAdvertisement(ctx context.Context, uid int64) {
units := []entity.GameUnit{}
err := dao.GameUnit.Ctx(ctx).Where("uid=?", uid).Where("OAID<>''").Scan(&units)

1
internal/serviceGame/internal/dbinit.go

@ -106,6 +106,7 @@ func InitRedis(ctx context.Context) {
rdbTop := RedisDbList[0]
rdbTop.Do(ctx, "select", 0)
rdbTop.SetNX(ctx, "public_id", 999999, 0)
rdbTop.SetNX(ctx, "public_item_id", 100000, 0)
rdbTop.SetNX(ctx, "public_unit_id", 1000000000, 0)
}

49
internal/serviceGame/internal/manage.go

@ -331,6 +331,9 @@ func RegisterNum(ctx context.Context, req *game.RegisterCountReq) (res *game.Reg
return
}
/*
** 导出问题账号
**/
func LogAccount(ctx context.Context, req *game.LogAccountReq) (res *game.LogAccountRes, err error) {
res = new(game.LogAccountRes)
modelTotal := dao.LoginLogoutInfo.Ctx(ctx)
@ -397,3 +400,49 @@ func getUnitDay(ctx context.Context, server int, uid int64, day int) {
//g.Log().Info(ctx, "err== ", err)
return
}
func ReviewState(ctx context.Context, req *game.ReviewStateReq) (res *game.ReviewStateRes, err error) {
res = new(game.ReviewStateRes)
res.ServerId = req.ServerId
mongodb, ok := MongoDatabaseList[fmt.Sprint(req.ServerId)]
if !ok {
g.Log().Info(ctx, "err== db is nil")
return
}
query := bson.M{"State": req.State}
if req.State == -1 {
query = bson.M{}
}
stores := []map[string]interface{}{}
err = mongodb.Collection("SmallLayoutBlueprint").Find(ctx, query).All(&stores)
if err != nil {
g.Log().Info(ctx, "err== ", err)
return
}
if len(stores) <= 0 {
g.Log().Infof(ctx, "uid: %d, server: %d err== unit is nil", req.ServerId)
return
}
res.SmallLayoutBlueprint = stores
return
}
func SetReviewState(ctx context.Context, req *game.SetReviewStateReq) (res *game.SetReviewStateRes, err error) {
res = new(game.SetReviewStateRes)
res.ServerId = req.ServerId
mongodb, ok := MongoDatabaseList[fmt.Sprint(req.ServerId)]
if !ok {
g.Log().Info(ctx, "err== db is nil")
return
}
filter := bson.M{"ArtID": req.ArtID}
update := bson.M{"State": req.State}
err = mongodb.Collection("SmallLayoutBlueprint").UpdateOne(ctx, filter, bson.M{"$set": update})
if err != nil {
g.Log().Info(ctx, "err== ", err)
return
}
res.Result = 1
return
}

109
internal/serviceGame/internal/online.go

@ -1,62 +1,79 @@
package internal
import (
"encoding/json"
"fmt"
mqtt "github.com/eclipse/paho.mqtt.golang"
"strings"
"context"
"github.com/gogf/gf/v2/frame/g"
"log"
"tyj_admin/api/v1/game"
"tyj_admin/internal/dao"
"tyj_admin/internal/model/do"
"tyj_admin/internal/model/entity"
)
type MqttOnlineReq struct {
ReqId int64 `json:"reqId"`
ModuleId string `json:"moduleId"`
func IncrOnlineCount(ctx context.Context, server int) {
model := dao.GameOnlineCount.Ctx(ctx)
model = model.Where("id=?", server)
_, err := model.Update("online=online+1")
if err != nil {
log.Print(err)
return
}
var online []*entity.GameOnlineCount
_ = model.Scan(&online)
if len(online) > 0 && online[0].Online > online[0].DailyTop {
_, _ = model.Update(g.Map{dao.GameOnlineCount.Columns().DailyTop: online[0].Online})
}
}
type MqttOnlineRes struct {
RespId int `json:"respId"`
Error interface{} `json:"error"`
Body map[string]OnlineBody `json:"body"`
func DecrOnlineCount(ctx context.Context, server int) {
model := dao.GameOnlineCount.Ctx(ctx)
model = model.Where("id=?", server)
_, err := model.Update("online=online-1")
if err != nil {
log.Print(err)
return
}
}
type OnlineBody struct {
ServerId string `json:"serverId"`
LoginedList []OnlineLoginInfo `json:"loginedList"`
}
func SetOnlineCount(ctx context.Context, server int, count int) {
model := dao.GameOnlineCount.Ctx(ctx)
model = model.Where("id=?", server)
var onlineIndex []*entity.GameOnlineCount
_ = model.Scan(&onlineIndex)
if len(onlineIndex) == 0 {
_, _ = dao.GameOnlineCount.Ctx(ctx).Insert(do.GameOnlineCount{Id: server, Online: count, DailyTop: count})
}
type OnlineLoginInfo struct {
LoginTime int64 `json:"loginTime"`
Uid int32 `json:"uid"`
Address string `json:"address"`
}
_, err := model.Update(g.Map{dao.GameOnlineCount.Columns().Online: count})
if err != nil {
log.Print(err)
return
}
func SendMqttOnline(msg interface{}, c chan *MqttOnlineRes, server string) {
var online []*entity.GameOnlineCount
_ = model.Scan(&online)
if len(online) > 0 && online[0].Online > online[0].DailyTop {
_, _ = model.Update(g.Map{dao.GameOnlineCount.Columns().DailyTop: online[0].Online})
}
}
registerFunc := func(client mqtt.Client, qtmsg mqtt.Message) {
ss := string(msg.([]byte))
fmt.Println(ss)
err := ClientSend("client", 0, false, ss)
if err != nil {
c <- &MqttOnlineRes{Error: err}
func ResetOnlineTop(ctx context.Context) {
model := dao.GameOnlineCount.Ctx(ctx)
var online []*entity.GameOnlineCount
_ = model.Scan(&online)
for _, v := range online {
if v != nil {
_, _ = model.Where("id=?", v.Id).Update(g.Map{dao.GameOnlineCount.Columns().DailyTop: v.Online})
}
//ClientSend("client", 0, false, `{"reqId":3,"moduleId":"webadmin","body":{"uids":"lq0001","gm":1,"moduleType":"changeGM"}}`)
}
callback := func(client mqtt.Client, qtmsg mqtt.Message) {
res := &MqttOnlineRes{}
client.Disconnect(1)
ss := string(qtmsg.Payload())
ss = ss[1 : len(ss)-1]
ss = strings.Replace(ss, "\\", "", -1)
err := json.Unmarshal([]byte(ss), res)
if err == nil && res.RespId == 1 {
c <- res
return
}
c <- &MqttOnlineRes{Error: err}
}
if err := NewMqttClient(registerFunc, callback, server); err != nil {
c <- &MqttOnlineRes{Error: err}
}
}
func GetOnlineTopList(ctx context.Context, req *game.RoleOnlineTopReq) (res *game.RoleOnlineTopRes, err error) {
model := dao.GameOnlineCount.Ctx(ctx)
if req.ServerId != 0 {
model = model.Where("id=?", req.ServerId)
}
res = new(game.RoleOnlineTopRes)
_ = model.Scan(&res.Onlines)
return
}

7
internal/serviceGame/internal/out.go

@ -26,6 +26,13 @@ func GetUnitIdIncrease(ctx context.Context) (int64, error) {
return result.Val(), result.Err()
}
func GetItemIdIncrease(ctx context.Context) (int64, error) {
rdbTop := RedisDbList[0]
rdbTop.Do(ctx, "select", 0)
result := rdbTop.Incr(ctx, "public_item_id")
return result.Val(), result.Err()
}
func CheckUidHadPId(ctx context.Context, uid int64) bool {
rdbTop := RedisDbList[0]
rdbTop.Do(ctx, "select", 0)

12
internal/serviceGame/manage.go

@ -35,6 +35,8 @@ type IGameManage interface {
GetShopItemList(ctx context.Context, req *game.GetShopItemListReq) (res *game.GetShopItemListRes, err error)
GetOperLog(ctx context.Context, req *game.GetOperLogReq) (res *game.GetOperLogRes, err error)
LogAccount(ctx context.Context, req *game.LogAccountReq) (res *game.LogAccountRes, err error)
ReviewState(ctx context.Context, req *game.ReviewStateReq) (res *game.ReviewStateRes, err error)
SetReviewState(ctx context.Context, req *game.SetReviewStateReq) (res *game.SetReviewStateRes, err error)
}
type gameManageImpl struct {
@ -369,3 +371,13 @@ func (ga *gameManageImpl) LogAccount(ctx context.Context, req *game.LogAccountRe
res, err = internal.LogAccount(ctx, req)
return
}
func (ga *gameManageImpl) ReviewState(ctx context.Context, req *game.ReviewStateReq) (res *game.ReviewStateRes, err error) {
res, err = internal.ReviewState(ctx, req)
return
}
func (ga *gameManageImpl) SetReviewState(ctx context.Context, req *game.SetReviewStateReq) (res *game.SetReviewStateRes, err error) {
res, err = internal.SetReviewState(ctx, req)
return
}

11
internal/serviceGame/pub.go

@ -15,6 +15,7 @@ import (
type IGamePub interface {
GetId(ctx context.Context, req *game.GetOutIdReq) (res *game.GetOutIdRes, err error)
GetItemId(ctx context.Context, req *game.GetItemIdReq) (res *game.GetItemIdRes, err error)
LoginOut(ctx context.Context, req *game.LoginOutReq) (res *game.LoginOutRes, err error)
ItemRecord(ctx context.Context, req *game.ItemRecordReq) (res *game.ItemRecordRes, err error)
ItemRecordTwo(ctx context.Context, req *game.ItemRecordTwoReq) (res *game.ItemRecordTwoRes, err error)
@ -137,6 +138,7 @@ func (c *gamePubImpl) GetServerConfig(ctx context.Context, req *game.GetServerCo
log.Println("为查询到服务器配置!")
return
}
go internal.SetOnlineCount(ctx, req.ServerId, 0)
res.Id = loginUrl[0].Id
res.GameDifficulty = loginUrl[0].Difficulty
@ -212,3 +214,12 @@ func (c *gamePubImpl) CheckSecondRebate(ctx context.Context, req *game.CheckSeco
return
}
func (c *gamePubImpl) GetItemId(ctx context.Context, req *game.GetItemIdReq) (res *game.GetItemIdRes, err error) {
res = new(game.GetItemIdRes)
g.Try(ctx, func(ctx context.Context) {
res.Id, err = internal.GetItemIdIncrease(ctx)
return
})
return
}

Loading…
Cancel
Save