修复高并发(1K)下的一些问题

This commit is contained in:
flswld committed 2023-10-10 20:54:14 +08:00
1 parent be737e45e9
commit c4fa288b93
13 files changed
+194 -213

No files matched your search

-2
View File
@@ -35,7 +35,6 @@ type GameMsg struct {
const (
ClientRttNotify = iota // 客户端网络时延上报
ClientTimeNotify // 客户端本地时间上报
KickPlayerNotify // 通知GATE剔除玩家
UserOfflineNotify // 玩家离线通知GS
)
@@ -43,7 +42,6 @@ const (
type ConnCtrlMsg struct {
UserId uint32
ClientRtt uint32
ClientTime uint32
KickUserId uint32
KickReason uint32
}
+40 -57
View File
@@ -41,6 +41,9 @@ const (
// 转发客户端消息到其他服务器 每个连接独立协程
func (k *KcpConnManager) forwardClientMsgToServerHandle(protoMsg *ProtoMsg, session *Session) {
if session.connState == ConnClose {
return
}
if protoMsg.HeadMessage == nil {
logger.Error("recv null head msg: %v", protoMsg)
return
@@ -78,52 +81,6 @@ func (k *KcpConnManager) forwardClientMsgToServerHandle(protoMsg *ProtoMsg, sess
}
session.sendChan <- msg
k.forceCloseKcpConn(protoMsg.SessionId, kcp.EnetClientClose)
case cmd.PingReq:
// ping
req := protoMsg.PayloadMessage.(*proto.PingReq)
logger.Debug("user ping req, data: %v", req.String())
// 返回数据到客户端
rsp := new(proto.PingRsp)
rsp.ClientTime = req.ClientTime
msg := &ProtoMsg{
SessionId: protoMsg.SessionId,
CmdId: cmd.PingRsp,
HeadMessage: k.getHeadMsg(protoMsg.HeadMessage.ClientSequenceId),
PayloadMessage: rsp,
}
session.sendChan <- msg
if session.connState != ConnActive {
return
}
// 通知GS玩家客户端往返时延
rtt := uint32(0)
if !session.conn.IsTcpMode() {
logger.Debug("sessionId: %v, KcpRTO: %v, KcpSRTT: %v, KcpRTTVar: %v",
protoMsg.SessionId, session.conn.GetKcpRTO(), session.conn.GetKcpSRTT(), session.conn.GetKcpSRTTVar())
rtt = uint32(session.conn.GetKcpSRTT())
} else {
rtt = session.tcpRtt
}
connCtrlMsg := &mq.ConnCtrlMsg{
UserId: session.userId,
ClientRtt: rtt,
ClientTime: 0,
}
k.messageQueue.SendToGs(session.gsServerAppId, &mq.NetMsg{
MsgType: mq.MsgTypeConnCtrl,
EventId: mq.ClientRttNotify,
ConnCtrlMsg: connCtrlMsg,
})
// 通知GS玩家客户端的本地时钟
connCtrlMsg = &mq.ConnCtrlMsg{
UserId: session.userId,
ClientTime: req.ClientTime,
}
k.messageQueue.SendToGs(session.gsServerAppId, &mq.NetMsg{
MsgType: mq.MsgTypeConnCtrl,
EventId: mq.ClientTimeNotify,
ConnCtrlMsg: connCtrlMsg,
})
case cmd.PlayerLoginReq:
// GS登录包
if session.connState != ConnWaitLogin {
@@ -193,6 +150,26 @@ func (k *KcpConnManager) forwardClientMsgToServerHandle(protoMsg *ProtoMsg, sess
EventId: mq.NormalMsg,
GameMsg: gameMsg,
})
// 通知GS玩家客户端往返时延
if protoMsg.CmdId == cmd.PingReq {
rtt := uint32(0)
if !session.conn.IsTcpMode() {
logger.Debug("sessionId: %v, KcpRTO: %v, KcpSRTT: %v, KcpRTTVar: %v",
protoMsg.SessionId, session.conn.GetKcpRTO(), session.conn.GetKcpSRTT(), session.conn.GetKcpSRTTVar())
rtt = uint32(session.conn.GetKcpSRTT())
} else {
rtt = session.tcpRtt
}
connCtrlMsg := &mq.ConnCtrlMsg{
UserId: session.userId,
ClientRtt: rtt,
}
k.messageQueue.SendToGs(session.gsServerAppId, &mq.NetMsg{
MsgType: mq.MsgTypeConnCtrl,
EventId: mq.ClientRttNotify,
ConnCtrlMsg: connCtrlMsg,
})
}
}
}
@@ -253,23 +230,29 @@ func (k *KcpConnManager) gameMsgHandle(
logger.Error("session is nil, sessionId: %v", protoMsg.SessionId)
return
}
if session.connState == ConnClose {
return
}
if len(session.sendChan) == SessionSendChanLen {
logger.Error("session send chan is full, sessionId: %v", protoMsg.SessionId)
return
}
if protoMsg.CmdId == cmd.PlayerLoginRsp {
logger.Debug("session active, sessionId: %v", protoMsg.SessionId)
session.connState = ConnActive
// 通知GS玩家各个服务器的appid
serverMsg := &mq.ServerMsg{
UserId: session.userId,
AnticheatServerAppId: session.anticheatServerAppId,
rsp := protoMsg.PayloadMessage.(*proto.PlayerLoginRsp)
if rsp.Retcode == 0 {
logger.Debug("session active, sessionId: %v", protoMsg.SessionId)
session.connState = ConnActive
// 通知GS玩家各个服务器的appid
serverMsg := &mq.ServerMsg{
UserId: session.userId,
AnticheatServerAppId: session.anticheatServerAppId,
}
k.messageQueue.SendToGs(session.gsServerAppId, &mq.NetMsg{
MsgType: mq.MsgTypeServer,
EventId: mq.ServerAppidBindNotify,
ServerMsg: serverMsg,
})
}
k.messageQueue.SendToGs(session.gsServerAppId, &mq.NetMsg{
MsgType: mq.MsgTypeServer,
EventId: mq.ServerAppidBindNotify,
ServerMsg: serverMsg,
})
}
session.sendChan <- protoMsg
}
+3 -1
View File
@@ -1,6 +1,7 @@
package game
import (
"os"
"runtime"
"strconv"
"time"
@@ -158,7 +159,8 @@ func (g *Game) gameMainLoopD() {
lastPanicTime = now
} else {
logger.Error("!!! GAME MAIN LOOP STOP !!!")
break
time.Sleep(time.Second * 10)
os.Exit(-1)
}
}
}
+1 -2
View File
@@ -15,6 +15,7 @@ import (
func (r *RouteManager) initRoute() {
r.handlerFuncRouteMap = map[uint16]HandlerFunc{
cmd.PingReq: GAME.PingReq,
cmd.SetPlayerBornDataReq: GAME.SetPlayerBornDataReq,
cmd.QueryPathReq: GAME.QueryPathReq,
cmd.UnionCmdNotify: GAME.UnionCmdNotify,
@@ -186,8 +187,6 @@ func (r *RouteManager) RouteHandle(netMsg *mq.NetMsg) {
switch netMsg.EventId {
case mq.ClientRttNotify:
GAME.ClientRttNotify(connCtrlMsg.UserId, connCtrlMsg.ClientRtt)
case mq.ClientTimeNotify:
GAME.ClientTimeNotify(connCtrlMsg.UserId, connCtrlMsg.ClientTime)
case mq.UserOfflineNotify:
GAME.OnOffline(connCtrlMsg.UserId, &ChangeGsInfo{
IsChangeGs: false,
+8 -8
View File
@@ -22,7 +22,7 @@ const (
)
type WorldManager struct {
worldMap map[uint32]*World
worldMap map[uint64]*World
snowflake *alg.SnowflakeWorker
aiWorld *World // 本服的Ai玩家世界
sceneBlockAoiMap map[uint32]*alg.AoiManager // 全局各场景地图的aoi管理器
@@ -31,23 +31,23 @@ type WorldManager struct {
func NewWorldManager(snowflake *alg.SnowflakeWorker) (r *WorldManager) {
r = new(WorldManager)
r.worldMap = make(map[uint32]*World)
r.worldMap = make(map[uint64]*World)
r.snowflake = snowflake
r.LoadSceneBlockAoiMap()
r.multiplayerWorldNum = 0
return r
}
func (w *WorldManager) GetWorldById(worldId uint32) *World {
func (w *WorldManager) GetWorldById(worldId uint64) *World {
return w.worldMap[worldId]
}
func (w *WorldManager) GetAllWorld() map[uint32]*World {
func (w *WorldManager) GetAllWorld() map[uint64]*World {
return w.worldMap
}
func (w *WorldManager) CreateWorld(owner *model.Player) *World {
worldId := uint32(w.snowflake.GenId())
worldId := uint64(w.snowflake.GenId())
world := &World{
id: worldId,
owner: owner,
@@ -80,7 +80,7 @@ func (w *WorldManager) CreateWorld(owner *model.Player) *World {
return world
}
func (w *WorldManager) DestroyWorld(worldId uint32) {
func (w *WorldManager) DestroyWorld(worldId uint64) {
world := w.GetWorldById(worldId)
for _, player := range world.playerMap {
world.RemovePlayer(player)
@@ -204,7 +204,7 @@ type EnterSceneContext struct {
// World 世界数据结构
type World struct {
id uint32
id uint64
owner *model.Player
playerMap map[uint32]*model.Player
sceneMap map[uint32]*Scene
@@ -227,7 +227,7 @@ func (w *World) GetBulletPhysicsEngine() *PhysicsEngine {
return w.bulletPhysicsEngine
}
func (w *World) GetId() uint32 {
func (w *World) GetId() uint64 {
return w.id
}
+1 -1
View File
@@ -651,7 +651,7 @@ func (g *GadgetClientEntity) GetPropOwnerEntityId() uint32 {
type GadgetVehicleEntity struct {
vehicleId uint32
worldId uint32
worldId uint64
ownerUid uint32
maxStamina float32
curStamina float32
+17 -15
View File
@@ -16,6 +16,23 @@ import (
pb "google.golang.org/protobuf/proto"
)
func (g *Game) PingReq(player *model.Player, payloadMsg pb.Message) {
req := payloadMsg.(*proto.PingReq)
player.ClientTime = req.ClientTime
now := uint32(time.Now().Unix())
// 客户端与服务器时间相差太过严重
if math.Abs(float64(now-player.ClientTime)) > 600.0 {
logger.Debug("abs of client time and server time above 600s, uid: %v", player.PlayerId)
}
player.LastKeepaliveTime = now
g.SendMsg(cmd.PingRsp, player.PlayerId, player.ClientSeq, &proto.PingRsp{
ClientTime: req.ClientTime,
Seq: req.Seq,
})
}
func (g *Game) PlayerSetPauseReq(player *model.Player, payloadMsg pb.Message) {
req := payloadMsg.(*proto.PlayerSetPauseReq)
isPaused := req.IsPaused
@@ -50,21 +67,6 @@ func (g *Game) ClientRttNotify(userId uint32, clientRtt uint32) {
player.ClientRTT = clientRtt
}
func (g *Game) ClientTimeNotify(userId uint32, clientTime uint32) {
player := USER_MANAGER.GetOnlineUser(userId)
if player == nil {
logger.Error("player is nil, uid: %v", userId)
return
}
player.ClientTime = clientTime
now := uint32(time.Now().Unix())
// 客户端与服务器时间相差太过严重
if math.Abs(float64(now-player.ClientTime)) > 600.0 {
logger.Debug("abs of client time and server time above 600s, uid: %v", userId)
}
player.LastKeepaliveTime = now
}
func (g *Game) ServerAnnounceNotify(announceId uint32, announceMsg string) {
for _, onlinePlayer := range USER_MANAGER.GetAllOnlineUserList() {
now := uint32(time.Now().Unix())
+1 -1
View File
@@ -902,7 +902,7 @@ func (g *Game) AddSceneGroup(player *model.Player, scene *Scene, groupConfig *gd
func (g *Game) RemoveSceneGroup(player *model.Player, scene *Scene, groupConfig *gdconf.Group) {
group := scene.GetGroupById(uint32(groupConfig.Id))
if group == nil {
logger.Error("group not exist, groupId: %v, uid: %v", groupConfig.Id, player.PlayerId)
// logger.Error("group not exist, groupId: %v, uid: %v", groupConfig.Id, player.PlayerId)
return
}
for suiteId := range group.GetAllSuite() {
+1 -1
View File
@@ -59,7 +59,7 @@ type Player struct {
// 在线数据 请随意 记得加忽略字段的tag
LastSaveTime uint32 `bson:"-" msgpack:"-"` // 上一次存档保存时间
DbState int `bson:"-" msgpack:"-"` // 数据库存档状态
WorldId uint32 `bson:"-" msgpack:"-"` // 所在的世界id
WorldId uint64 `bson:"-" msgpack:"-"` // 所在的世界id
GameObjectGuidCounter uint64 `bson:"-" msgpack:"-"` // 游戏对象guid计数器
LastKeepaliveTime uint32 `bson:"-" msgpack:"-"` // 上一次保持活跃时间
ClientTime uint32 `bson:"-" msgpack:"-"` // 客户端本地时钟
+2 -2
View File
@@ -422,7 +422,7 @@ func (s *DiscoveryService) getRandomServerInstance(instMap *sync.Map) *ServerIns
instList = append(instList, value.(*ServerInstance))
return true
})
sort.SliceStable(instList, func(i, j int) bool {
sort.Slice(instList, func(i, j int) bool {
return instList[i].appId < instList[j].appId
})
index := random.GetRandomInt32(0, int32(len(instList)-1))
@@ -436,7 +436,7 @@ func (s *DiscoveryService) getMinLoadServerInstance(instMap *sync.Map) *ServerIn
instList = append(instList, value.(*ServerInstance))
return true
})
sort.SliceStable(instList, func(i, j int) bool {
sort.Slice(instList, func(i, j int) bool {
return instList[i].appId < instList[j].appId
})
minLoadInstIndex := 0
+90 -98
View File
@@ -1688,99 +1688,96 @@ const (
// cmd_player
const (
GetPlayerTokenReq = 172
GetPlayerTokenRsp = 198
PlayerLoginReq = 112
PlayerLoginRsp = 135
PlayerLogoutReq = 107
PlayerLogoutRsp = 121
PlayerLogoutNotify = 103
PlayerDataNotify = 190
ChangeGameTimeReq = 173
ChangeGameTimeRsp = 199
PlayerGameTimeNotify = 131
PlayerPropNotify = 175
ClientTriggerEventNotify = 148
SetPlayerPropReq = 197
SetPlayerPropRsp = 181
SetPlayerBornDataReq = 105
SetPlayerBornDataRsp = 182
DoSetPlayerBornDataNotify = 147
PlayerPropChangeNotify = 139
SetPlayerNameReq = 153
SetPlayerNameRsp = 122
SetOpenStateReq = 165
SetOpenStateRsp = 104
OpenStateUpdateNotify = 193
OpenStateChangeNotify = 127
PlayerCookReq = 194
PlayerCookRsp = 188
PlayerRandomCookReq = 126
PlayerRandomCookRsp = 163
CookDataNotify = 195
CookRecipeDataNotify = 106
CookGradeDataNotify = 134
PlayerCompoundMaterialReq = 150
PlayerCompoundMaterialRsp = 143
TakeCompoundOutputReq = 174
TakeCompoundOutputRsp = 176
CompoundDataNotify = 146
GetCompoundDataReq = 141
GetCompoundDataRsp = 149
PlayerTimeNotify = 191
PlayerSetPauseReq = 124
PlayerSetPauseRsp = 156
PlayerSetLanguageReq = 142
PlayerSetLanguageRsp = 130
DataResVersionNotify = 167
DailyTaskDataNotify = 158
DailyTaskProgressNotify = 170
DailyTaskScoreRewardNotify = 117
WorldOwnerDailyTaskNotify = 102
AddRandTaskInfoNotify = 119
RemoveRandTaskInfoNotify = 161
TakePlayerLevelRewardReq = 129
TakePlayerLevelRewardRsp = 157
PlayerLevelRewardUpdateNotify = 200
GivingRecordNotify = 116
GivingRecordChangeNotify = 187
ItemGivingReq = 140
ItemGivingRsp = 118
PlayerCookArgsReq = 166
PlayerCookArgsRsp = 168
PlayerLuaShellNotify = 133
ServerDisconnectClientNotify = 184
AntiAddictNotify = 180
PlayerForceExitReq = 189
PlayerForceExitRsp = 159
PlayerInjectFixNotify = 132
TaskVarNotify = 160
ClientLockGameTimeNotify = 114
GetNextResourceInfoReq = 192
GetNextResourceInfoRsp = 120
AdjustWorldLevelReq = 164
AdjustWorldLevelRsp = 138
DailyTaskFilterCityReq = 111
DailyTaskFilterCityRsp = 144
DailyTaskUnlockedCitiesNotify = 186
ExclusiveRuleNotify = 101
CompoundUnlockNotify = 128
GameplayRecommendationSkillRequest = 151
GameplayRecommendationReliquaryRequest = 151
GameplayRecommendationElementReliquaryRequest = 151
GetGameplayRecommendationReq = 151
GetGameplayRecommendationRsp = 123
TakeBackGivingItemReq = 171
TakeBackGivingItemRsp = 145
PlayerNicknameAuditDataNotify = 108
PlayerNicknameNotify = 109
NicknameAuditConfigNotify = 152
ReadNicknameAuditReq = 177
ReadNicknameAuditRsp = 137
PlayerCompoundMaterialBoostReq = 185
PlayerCompoundMaterialBoostRsp = 125
PlayerGameTimeByLuaNotify = 178
PlayerIpRegionNotify = 136
GetPlayerTokenReq = 172
GetPlayerTokenRsp = 198
PlayerLoginReq = 112
PlayerLoginRsp = 135
PlayerLogoutReq = 107
PlayerLogoutRsp = 121
PlayerLogoutNotify = 103
PlayerDataNotify = 190
ChangeGameTimeReq = 173
ChangeGameTimeRsp = 199
PlayerGameTimeNotify = 131
PlayerPropNotify = 175
ClientTriggerEventNotify = 148
SetPlayerPropReq = 197
SetPlayerPropRsp = 181
SetPlayerBornDataReq = 105
SetPlayerBornDataRsp = 182
DoSetPlayerBornDataNotify = 147
PlayerPropChangeNotify = 139
SetPlayerNameReq = 153
SetPlayerNameRsp = 122
SetOpenStateReq = 165
SetOpenStateRsp = 104
OpenStateUpdateNotify = 193
OpenStateChangeNotify = 127
PlayerCookReq = 194
PlayerCookRsp = 188
PlayerRandomCookReq = 126
PlayerRandomCookRsp = 163
CookDataNotify = 195
CookRecipeDataNotify = 106
CookGradeDataNotify = 134
PlayerCompoundMaterialReq = 150
PlayerCompoundMaterialRsp = 143
TakeCompoundOutputReq = 174
TakeCompoundOutputRsp = 176
CompoundDataNotify = 146
GetCompoundDataReq = 141
GetCompoundDataRsp = 149
PlayerTimeNotify = 191
PlayerSetPauseReq = 124
PlayerSetPauseRsp = 156
PlayerSetLanguageReq = 142
PlayerSetLanguageRsp = 130
DataResVersionNotify = 167
DailyTaskDataNotify = 158
DailyTaskProgressNotify = 170
DailyTaskScoreRewardNotify = 117
WorldOwnerDailyTaskNotify = 102
AddRandTaskInfoNotify = 119
RemoveRandTaskInfoNotify = 161
TakePlayerLevelRewardReq = 129
TakePlayerLevelRewardRsp = 157
PlayerLevelRewardUpdateNotify = 200
GivingRecordNotify = 116
GivingRecordChangeNotify = 187
ItemGivingReq = 140
ItemGivingRsp = 118
PlayerCookArgsReq = 166
PlayerCookArgsRsp = 168
PlayerLuaShellNotify = 133
ServerDisconnectClientNotify = 184
AntiAddictNotify = 180
PlayerForceExitReq = 189
PlayerForceExitRsp = 159
PlayerInjectFixNotify = 132
TaskVarNotify = 160
ClientLockGameTimeNotify = 114
GetNextResourceInfoReq = 192
GetNextResourceInfoRsp = 120
AdjustWorldLevelReq = 164
AdjustWorldLevelRsp = 138
DailyTaskFilterCityReq = 111
DailyTaskFilterCityRsp = 144
DailyTaskUnlockedCitiesNotify = 186
ExclusiveRuleNotify = 101
CompoundUnlockNotify = 128
GetGameplayRecommendationReq = 151
GetGameplayRecommendationRsp = 123
TakeBackGivingItemReq = 171
TakeBackGivingItemRsp = 145
PlayerNicknameAuditDataNotify = 108
PlayerNicknameNotify = 109
NicknameAuditConfigNotify = 152
ReadNicknameAuditReq = 177
ReadNicknameAuditRsp = 137
PlayerCompoundMaterialBoostReq = 185
PlayerCompoundMaterialBoostRsp = 125
PlayerGameTimeByLuaNotify = 178
PlayerIpRegionNotify = 136
)
// cmd_property
@@ -1896,7 +1893,6 @@ const (
// cmd_reputation
const (
CityReputationRequestInfo = 2872
GetCityReputationInfoReq = 2872
GetCityReputationInfoRsp = 2898
TakeCityReputationLevelRewardReq = 2812
@@ -4082,9 +4078,6 @@ func (c *CmdProtoMap) registerAllMessage() {
c.regMsg(DailyTaskUnlockedCitiesNotify, func() any { return new(proto.DailyTaskUnlockedCitiesNotify) })
c.regMsg(ExclusiveRuleNotify, func() any { return new(proto.ExclusiveRuleNotify) })
c.regMsg(CompoundUnlockNotify, func() any { return new(proto.CompoundUnlockNotify) })
c.regMsg(GameplayRecommendationSkillRequest, func() any { return new(proto.GameplayRecommendationSkillRequest) })
c.regMsg(GameplayRecommendationReliquaryRequest, func() any { return new(proto.GameplayRecommendationReliquaryRequest) })
c.regMsg(GameplayRecommendationElementReliquaryRequest, func() any { return new(proto.GameplayRecommendationElementReliquaryRequest) })
c.regMsg(GetGameplayRecommendationReq, func() any { return new(proto.GetGameplayRecommendationReq) })
c.regMsg(GetGameplayRecommendationRsp, func() any { return new(proto.GetGameplayRecommendationRsp) })
c.regMsg(TakeBackGivingItemReq, func() any { return new(proto.TakeBackGivingItemReq) })
@@ -4199,7 +4192,6 @@ func (c *CmdProtoMap) registerAllMessage() {
c.regMsg(ServerMessageNotify, func() any { return new(proto.ServerMessageNotify) })
// cmd_reputation
c.regMsg(CityReputationRequestInfo, func() any { return new(proto.CityReputationRequestInfo) })
c.regMsg(GetCityReputationInfoReq, func() any { return new(proto.GetCityReputationInfoReq) })
c.regMsg(GetCityReputationInfoRsp, func() any { return new(proto.GetCityReputationInfoRsp) })
c.regMsg(TakeCityReputationLevelRewardReq, func() any { return new(proto.TakeCityReputationLevelRewardReq) })
+22 -21
View File
@@ -303,6 +303,28 @@ func forwardLoop(session *net.Session, messageQueue *mq.MessageQueue, gateAppId
}
func runRobot() {
if config.GetConfig().Hk4eRobot.DosEnable {
dosBatchNum := int(config.GetConfig().Hk4eRobot.DosBatchNum)
for i := 0; i < int(config.GetConfig().Hk4eRobot.DosTotalNum); i += dosBatchNum {
wg := new(sync.WaitGroup)
wg.Add(dosBatchNum)
for j := 0; j < dosBatchNum; j++ {
go httpLogin(config.GetConfig().Hk4eRobot.Account+strconv.Itoa(i+j), wg)
}
wg.Wait()
time.Sleep(time.Millisecond * 10)
}
} else {
httpLogin(config.GetConfig().Hk4eRobot.Account, nil)
}
}
func httpLogin(account string, wg *sync.WaitGroup) {
defer func() {
if config.GetConfig().Hk4eRobot.DosEnable {
wg.Done()
}
}()
dispatchInfo, err := login.GetDispatchInfo(config.GetConfig().Hk4eRobot.RegionListUrl,
config.GetConfig().Hk4eRobot.RegionListParam,
config.GetConfig().Hk4eRobot.CurRegionUrl,
@@ -312,27 +334,6 @@ func runRobot() {
logger.Error("get dispatch info error: %v", err)
return
}
if config.GetConfig().Hk4eRobot.DosEnable {
dosBatchNum := int(config.GetConfig().Hk4eRobot.DosBatchNum)
for i := 0; i < int(config.GetConfig().Hk4eRobot.DosTotalNum); i += dosBatchNum {
wg := new(sync.WaitGroup)
wg.Add(dosBatchNum)
for j := 0; j < dosBatchNum; j++ {
go httpLogin(config.GetConfig().Hk4eRobot.Account+"_"+strconv.Itoa(i+j), dispatchInfo, wg)
}
wg.Wait()
}
} else {
httpLogin(config.GetConfig().Hk4eRobot.Account, dispatchInfo, nil)
}
}
func httpLogin(account string, dispatchInfo *login.DispatchInfo, wg *sync.WaitGroup) {
defer func() {
if config.GetConfig().Hk4eRobot.DosEnable {
wg.Done()
}
}()
accountInfo, err := login.AccountLogin(config.GetConfig().Hk4eRobot.LoginSdkUrl, account, config.GetConfig().Hk4eRobot.Password)
if err != nil {
logger.Error("account login error: %v", err)
+8 -4
View File
@@ -30,6 +30,7 @@ func Logic(account string, session *net.Session) {
avatarEntityId := uint32(0)
moveRot := random.GetRandomFloat32(0.0, 359.9)
moveReliableSeq := uint32(0)
isBorn := true
for {
select {
case protoMsg := <-session.RecvChan:
@@ -42,11 +43,14 @@ func Logic(account string, session *net.Session) {
return
}
logger.Info("robot gs login ok, account: %v", account)
if !isBorn {
session.SendMsg(cmd.SetPlayerBornDataReq, &proto.SetPlayerBornDataReq{
AvatarId: 10000007,
NickName: account,
})
}
case cmd.DoSetPlayerBornDataNotify:
session.SendMsg(cmd.SetPlayerBornDataReq, &proto.SetPlayerBornDataReq{
AvatarId: 10000007,
NickName: account,
})
isBorn = false
case cmd.PlayerDataNotify:
ntf := protoMsg.PayloadMessage.(*proto.PlayerDataNotify)
logger.Info("player name: %v", ntf.NickName)