Skip to content

Commit 10b4caf

Browse files
committed
支持怀旧端的gm配置
1 parent e4d8332 commit 10b4caf

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

bhandler/enter_game_handler.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package bhandler
22

33
import (
4+
"strconv"
5+
46
"github.com/liuguangw/billing_go/common"
7+
"github.com/liuguangw/billing_go/models"
58
"github.com/liuguangw/billing_go/services"
69
"golang.org/x/text/encoding/simplifiedchinese"
710
)
@@ -40,6 +43,8 @@ func (h *EnterGameHandler) GetResponse(request *common.BillingPacket) *common.Bi
4043
CharName: string(charName),
4144
}
4245
markOnline(h.Resource.LoginUsers, h.Resource.OnlineUsers, h.Resource.MacCounters, string(username), clientInfo)
46+
//角色id
47+
charguid := packetReader.ReadInt()
4348
//
4449
h.Resource.Logger.Info("user [" + string(username) + "] " + string(charName) + " entered game")
4550
//Packets::BLRetBillingStart
@@ -58,6 +63,18 @@ func (h *EnterGameHandler) GetResponse(request *common.BillingPacket) *common.Bi
5863
padLen = 16
5964
}
6065
extraData := make([]byte, padLen)
66+
//检查角色是否为gm(仅限怀旧)
67+
if h.BillType == common.BillTypeHuaiJiu {
68+
if isGm, err := models.CheckIsGm(h.Resource.Db, charguid); err != nil {
69+
h.Resource.Logger.Error("check is gm failed: " + err.Error())
70+
} else {
71+
// 登录的角色为gm
72+
if isGm {
73+
extraData[padLen-1] = 1
74+
h.Resource.Logger.Info(string(charName) + "(guid: " + strconv.Itoa(charguid) + ") is gm")
75+
}
76+
}
77+
}
6178
opData = append(opData, extraData...)
6279
response.OpData = opData
6380
return response

common/billing_packet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (packet *BillingPacket) String() string {
121121
}
122122

123123
// InitBillingPacketHead 初始化头部标识
124-
func InitBillingPacketHead(billType byte) {
124+
func InitBillingPacketHead(billType int) {
125125
if billType == BillTypeCommon {
126126
BillingPacketHead = [2]byte{0xAA, 0x55}
127127
} else if billType == BillTypeHuaiJiu {

models/account_cfg.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package models
2+
3+
// AccountCfg GM配置
4+
type AccountCfg struct {
5+
Charguid int //角色id
6+
Isgm int //是否为gm
7+
}

models/check_gm.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package models
2+
3+
import "database/sql"
4+
5+
// CheckIsGm 查询角色是否为gm,怀旧专用
6+
func CheckIsGm(db *sql.DB, charguid int) (bool, error) {
7+
var accountCfg AccountCfg
8+
row := db.QueryRow("SELECT charguid, isgm FROM account_cfg WHERE charguid=?", charguid)
9+
if err := row.Err(); err != nil {
10+
return false, err
11+
}
12+
if err := row.Scan(&accountCfg.Charguid, &accountCfg.Isgm); err != nil {
13+
if err == sql.ErrNoRows {
14+
// 查询不到此记录
15+
return false, nil
16+
}
17+
return false, err
18+
}
19+
return accountCfg.Isgm > 0, nil
20+
}

services/billing/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewServer() (*Server, error) {
2929
return nil, err
3030
}
3131
//初始化头部标识
32-
common.InitBillingPacketHead(byte(serverConfig.BillType))
32+
common.InitBillingPacketHead(serverConfig.BillType)
3333
return &Server{config: serverConfig}, nil
3434
}
3535

0 commit comments

Comments
 (0)