Merge branch 'master' of git.kingsome.cn:server/game2006go

This commit is contained in:
殷勇 2023-09-12 19:40:32 +08:00
commit e32452b60b
10 changed files with 109 additions and 8 deletions

View File

@ -47,6 +47,7 @@ type MsgHandler interface {
CMStartGame(*f5.MsgHdr, *CMStartGame) CMStartGame(*f5.MsgHdr, *CMStartGame)
CMSetPrepare(*f5.MsgHdr, *CMSetPrepare) CMSetPrepare(*f5.MsgHdr, *CMSetPrepare)
CMKickout(*f5.MsgHdr, *CMKickout) CMKickout(*f5.MsgHdr, *CMKickout)
CMCloseNotify(*f5.MsgHdr, *CMCloseNotify)
} }
func (this *MsgHandlerImpl) CMPing(hdr *f5.MsgHdr, msg *CMPing) { func (this *MsgHandlerImpl) CMPing(hdr *f5.MsgHdr, msg *CMPing) {
@ -85,6 +86,9 @@ func (this *MsgHandlerImpl) CMSetPrepare(hdr *f5.MsgHdr, msg *CMSetPrepare) {
func (this *MsgHandlerImpl) CMKickout(hdr *f5.MsgHdr, msg *CMKickout) { func (this *MsgHandlerImpl) CMKickout(hdr *f5.MsgHdr, msg *CMKickout) {
} }
func (this *MsgHandlerImpl) CMCloseNotify(hdr *f5.MsgHdr, msg *CMCloseNotify) {
}
func (this *CMPing) GetNetMsgId() uint16 { func (this *CMPing) GetNetMsgId() uint16 {
return uint16(CMMessageIdE__CMPing) return uint16(CMMessageIdE__CMPing)
} }
@ -177,6 +181,10 @@ func (this *CMKickout) GetNetMsgId() uint16 {
return uint16(CMMessageIdE__CMKickout) return uint16(CMMessageIdE__CMKickout)
} }
func (this *CMCloseNotify) GetNetMsgId() uint16 {
return uint16(CMMessageIdE__CMCloseNotify)
}
func (this *SMRoomMemberChangeNotify) GetNetMsgId() uint16 { func (this *SMRoomMemberChangeNotify) GetNetMsgId() uint16 {
return uint16(SMMessageIdE__SMRoomMemberChangeNotify) return uint16(SMMessageIdE__SMRoomMemberChangeNotify)
} }
@ -197,6 +205,10 @@ func (this *SMRoomChangeNotify) GetNetMsgId() uint16 {
return uint16(SMMessageIdE__SMRoomChangeNotify) return uint16(SMMessageIdE__SMRoomChangeNotify)
} }
func (this *SMRoomGameStartNotify) GetNetMsgId() uint16 {
return uint16(SMMessageIdE__SMRoomGameStartNotify)
}
func init() { func init() {
handlers[int(CMMessageIdE__CMPing)] = &CsNetMsgHandler{ handlers[int(CMMessageIdE__CMPing)] = &CsNetMsgHandler{
@ -343,4 +355,16 @@ func init() {
}, },
} }
handlers[int(CMMessageIdE__CMCloseNotify)] = &CsNetMsgHandler{
MsgId: int(CMMessageIdE__CMCloseNotify),
ParseCb: func (data []byte) interface{} {
msg := &CMCloseNotify{}
proto.Unmarshal(data, msg)
return msg
},
Cb: func (hdr *f5.MsgHdr, handler MsgHandler) {
handler.CMCloseNotify(hdr, hdr.Msg.(*CMCloseNotify))
},
}
} }

View File

@ -28,6 +28,7 @@ func (this *HandlerMgr) Init() {
cs.RegHandlerId(int(cs.CMMessageIdE__CMStartGame), constant.ROOM_HANDLER_ID) cs.RegHandlerId(int(cs.CMMessageIdE__CMStartGame), constant.ROOM_HANDLER_ID)
cs.RegHandlerId(int(cs.CMMessageIdE__CMSetPrepare), constant.ROOM_HANDLER_ID) cs.RegHandlerId(int(cs.CMMessageIdE__CMSetPrepare), constant.ROOM_HANDLER_ID)
cs.RegHandlerId(int(cs.CMMessageIdE__CMKickout), constant.ROOM_HANDLER_ID) cs.RegHandlerId(int(cs.CMMessageIdE__CMKickout), constant.ROOM_HANDLER_ID)
cs.RegHandlerId(int(cs.CMMessageIdE__CMCloseNotify), constant.ROOM_HANDLER_ID)
} }
func (this *HandlerMgr) UnInit() { func (this *HandlerMgr) UnInit() {

View File

@ -18,6 +18,9 @@ func (this *Config) Init1() {
if this.GetAutoStartTime() < 30 { if this.GetAutoStartTime() < 30 {
panic("config.auto_start_time config error") panic("config.auto_start_time config error")
} }
if this.GetGameStartNotifyTime() < 3 || this.GetGameStartNotifyTime() > 35 {
panic("config.game_start_notify_time config error")
}
} }
func (this *ConfigTable) PostInit1() { func (this *ConfigTable) PostInit1() {

View File

@ -47,6 +47,7 @@ type FriendDb struct {
type Config struct { type Config struct {
gameapi_url string gameapi_url string
auto_start_time int32 auto_start_time int32
game_start_notify_time int32
_flags1_ uint64 _flags1_ uint64
_flags2_ uint64 _flags2_ uint64
@ -196,6 +197,14 @@ func (this *Config) HasAutoStartTime() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0 return (this._flags1_ & (uint64(1) << 2)) > 0
} }
func (this *Config) GetGameStartNotifyTime() int32 {
return this.game_start_notify_time
}
func (this *Config) HasGameStartNotifyTime() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *HallCluster) LoadFromKv(kv map[string]interface{}) { func (this *HallCluster) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.instance_id, "instance_id", &this._flags1_, 1, kv) f5.ReadMetaTableField(&this.instance_id, "instance_id", &this._flags1_, 1, kv)
@ -228,4 +237,5 @@ func (this *FriendDb) LoadFromKv(kv map[string]interface{}) {
func (this *Config) LoadFromKv(kv map[string]interface{}) { func (this *Config) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.gameapi_url, "gameapi_url", &this._flags1_, 1, kv) f5.ReadMetaTableField(&this.gameapi_url, "gameapi_url", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.auto_start_time, "auto_start_time", &this._flags1_, 2, kv) f5.ReadMetaTableField(&this.auto_start_time, "auto_start_time", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.game_start_notify_time, "game_start_notify_time", &this._flags1_, 3, kv)
} }

View File

@ -22,7 +22,9 @@ func (this *player) GetAccountId() string {
} }
func (this *player) SendMsg(rspMsg proto.Message) { func (this *player) SendMsg(rspMsg proto.Message) {
GetWspListener().SendProxyMsg(this.socket.Conn, this.socket.SocketHandle, rspMsg) if this.socket.IsValid() {
GetWspListener().SendProxyMsg(this.socket.Conn, this.socket.SocketHandle, rspMsg)
}
} }
func (this *player) GetRoom() common.Room { func (this *player) GetRoom() common.Room {
@ -50,7 +52,6 @@ func (this *player) GetName() string {
return "" return ""
} }
func (this *player) GetAvatarUrl() string { func (this *player) GetAvatarUrl() string {
return "" return ""
} }

View File

@ -2,7 +2,6 @@ syntax = "proto2";
package cs; package cs;
option go_package = ".;cs"; option go_package = ".;cs";
//id定义
enum CMMessageId_e enum CMMessageId_e
{ {
_CMPing = 101; _CMPing = 101;
@ -18,6 +17,7 @@ enum CMMessageId_e
_CMStartGame = 111; _CMStartGame = 111;
_CMSetPrepare = 112; _CMSetPrepare = 112;
_CMKickout = 113; _CMKickout = 113;
_CMCloseNotify = 114;
} }
enum SMMessageId_e enum SMMessageId_e
@ -42,4 +42,5 @@ enum SMMessageId_e
_SMRoomLeaveNotify = 1003; _SMRoomLeaveNotify = 1003;
_SMRoomDisbandNotify = 1004; _SMRoomDisbandNotify = 1004;
_SMRoomChangeNotify = 1005; _SMRoomChangeNotify = 1005;
_SMRoomGameStartNotify = 1006;
} }

View File

@ -271,6 +271,12 @@ message CMKickout
{ {
} }
//
message CMCloseNotify
{
optional int32 param = 1; //1SMRoomGameStartNotify
}
// //
message SMRoomMemberChangeNotify message SMRoomMemberChangeNotify
{ {
@ -281,6 +287,7 @@ message SMRoomMemberChangeNotify
message SMRoomKickoutNotify message SMRoomKickoutNotify
{ {
repeated string account_ids = 1; //account_id列表 repeated string account_ids = 1; //account_id列表
optional int32 reason = 2; // 1: 2:(<2)
} }
// //
@ -301,3 +308,12 @@ message SMRoomChangeNotify
{ {
optional MFRoom room = 1; // optional MFRoom room = 1; //
} }
//,10,
message SMRoomGameStartNotify
{
optional int32 zone_id = 1; //id
optional int32 node_id = 2; //id
optional string team_uuid = 3; //CMJoin战斗服时用
optional string custom_room_payload = 4; //
}

View File

@ -38,4 +38,5 @@ message Config
{ {
optional string gameapi_url = 1; optional string gameapi_url = 1;
optional int32 auto_start_time = 2; optional int32 auto_start_time = 2;
optional int32 game_start_notify_time = 3;
} }

View File

@ -11,6 +11,7 @@ import (
type member struct { type member struct {
joinTime int64 joinTime int64
state int32 state int32
closeGameStartNotify bool
entry q5.ListHead entry q5.ListHead
teamEntry q5.ListHead teamEntry q5.ListHead
hum common.Player hum common.Player

View File

@ -26,10 +26,14 @@ type room struct {
owner *member owner *member
roomState int32 roomState int32
startTime int64 startTime int64
startType int32 startReason int32
disbandTime int64
disbandReason int32
teams map[string]*team teams map[string]*team
members map[string]*member members map[string]*member
startTimer *f5.TimerWp startTimer *f5.TimerWp
attacher *f5.TimerAttacher
gameStartNotifyMsg *cs.SMRoomGameStartNotify
} }
func (this *room) init(roomId string, roomIdx int64, mapId int32, owner common.Player, passwd string) { func (this *room) init(roomId string, roomIdx int64, mapId int32, owner common.Player, passwd string) {
@ -48,13 +52,15 @@ func (this *room) init(roomId string, roomIdx int64, mapId int32, owner common.P
owner.GetTeamUuid(): newTeam(this.owner), owner.GetTeamUuid(): newTeam(this.owner),
} }
this.owner.hum.SetRoom(this) this.owner.hum.SetRoom(this)
this.startTimer = f5.GetTimer().SetTimeoutWp( this.attacher = f5.GetTimer().NewTimerAttacher()
mt.Table.Config.Get().GetAutoStartTime(), this.startTimer = f5.GetTimer().SetTimeoutExWp(
1000 * mt.Table.Config.Get().GetAutoStartTime(),
func (e int32, args *q5.Args) { func (e int32, args *q5.Args) {
if e == q5.TIMER_EXEC_EVENT { if e == q5.TIMER_EXEC_EVENT {
this.autoStart() this.autoStart()
} }
}) },
this.attacher)
} }
func (this *room) getMember(accountId string) *member { func (this *room) getMember(accountId string) *member {
@ -189,6 +195,14 @@ func (this *room) CMKickout(hdr *f5.MsgHdr, msg *cs.CMKickout) {
} }
} }
func (this *room) CMCloseNotify(hdr *f5.MsgHdr, msg *cs.CMCloseNotify) {
hum := hdr.Context.(common.Player)
m := this.getMember(hum.GetAccountId())
if m != nil {
m.closeGameStartNotify = true
}
}
func (this *room) broadcastMsg(msg proto.Message) { func (this *room) broadcastMsg(msg proto.Message) {
for _, m := range(this.members) { for _, m := range(this.members) {
m.hum.SendMsg(msg) m.hum.SendMsg(msg)
@ -211,14 +225,43 @@ func (this *room) started() bool {
func (this *room) doDisband(reason int32) { func (this *room) doDisband(reason int32) {
this.roomState = ROOM_DISBAND_STATE this.roomState = ROOM_DISBAND_STATE
this.disbandTime = q5.GetTickCount()
this.disbandReason = reason
} }
func (this *room) doStart(reason int32) { func (this *room) doStart(reason int32) {
this.roomState = ROOM_STARTED_STATE this.roomState = ROOM_STARTED_STATE
this.startTime = q5.GetTickCount() this.startTime = q5.GetTickCount()
this.startType = ROOM_AUTO_START_TYPE this.startReason = ROOM_AUTO_START_TYPE
f5.GetTimer().SetIntervalExWp(
1000,
func (e int32, args *q5.Args) {
if e == q5.TIMER_EXEC_EVENT {
if q5.GetTickCount() - this.startTime <
int64(1000 * mt.Table.Config.Get().GetGameStartNotifyTime()) {
this.notifyGameStart()
}
}
},
this.attacher)
} }
func (this *room) view() bool { func (this *room) view() bool {
return this.roomState == ROOM_INIT_STATE return this.roomState == ROOM_INIT_STATE
} }
func (this *room) notifyGameStart() {
if this.gameStartNotifyMsg == nil {
this.gameStartNotifyMsg = &cs.SMRoomGameStartNotify{}
this.gameStartNotifyMsg.ZoneId = proto.Int32(this.config.zoneId)
this.gameStartNotifyMsg.NodeId = proto.Int32(this.config.nodeId)
this.gameStartNotifyMsg.TeamUuid = proto.String(q5.ToString(this.roomIdx))
}
for _, m := range(this.members) {
if m.state == MEMBER_READY_STATE &&
m.hum.GetRoom() == this &&
!m.closeGameStartNotify {
m.hum.SendMsg(this.gameStartNotifyMsg)
}
}
}