diff --git a/server/hallserver/cs/cs.auto_gen.go b/server/hallserver/cs/cs.auto_gen.go index 49ad91c9..cdea75f3 100644 --- a/server/hallserver/cs/cs.auto_gen.go +++ b/server/hallserver/cs/cs.auto_gen.go @@ -47,6 +47,7 @@ type MsgHandler interface { CMStartGame(*f5.MsgHdr, *CMStartGame) CMSetPrepare(*f5.MsgHdr, *CMSetPrepare) CMKickout(*f5.MsgHdr, *CMKickout) + CMCloseNotify(*f5.MsgHdr, *CMCloseNotify) } 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) CMCloseNotify(hdr *f5.MsgHdr, msg *CMCloseNotify) { +} + func (this *CMPing) GetNetMsgId() uint16 { return uint16(CMMessageIdE__CMPing) } @@ -177,6 +181,10 @@ func (this *CMKickout) GetNetMsgId() uint16 { return uint16(CMMessageIdE__CMKickout) } +func (this *CMCloseNotify) GetNetMsgId() uint16 { + return uint16(CMMessageIdE__CMCloseNotify) +} + func (this *SMRoomMemberChangeNotify) GetNetMsgId() uint16 { return uint16(SMMessageIdE__SMRoomMemberChangeNotify) } @@ -197,6 +205,10 @@ func (this *SMRoomChangeNotify) GetNetMsgId() uint16 { return uint16(SMMessageIdE__SMRoomChangeNotify) } +func (this *SMRoomGameStartNotify) GetNetMsgId() uint16 { + return uint16(SMMessageIdE__SMRoomGameStartNotify) +} + func init() { 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)) + }, + } + } \ No newline at end of file diff --git a/server/hallserver/listener/handlermgr.go b/server/hallserver/listener/handlermgr.go index 8a904650..ca55eeb3 100644 --- a/server/hallserver/listener/handlermgr.go +++ b/server/hallserver/listener/handlermgr.go @@ -28,6 +28,7 @@ func (this *HandlerMgr) Init() { 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__CMKickout), constant.ROOM_HANDLER_ID) + cs.RegHandlerId(int(cs.CMMessageIdE__CMCloseNotify), constant.ROOM_HANDLER_ID) } func (this *HandlerMgr) UnInit() { diff --git a/server/hallserver/mt/Config.go b/server/hallserver/mt/Config.go index 61edb560..096739b7 100644 --- a/server/hallserver/mt/Config.go +++ b/server/hallserver/mt/Config.go @@ -18,6 +18,9 @@ func (this *Config) Init1() { if this.GetAutoStartTime() < 30 { 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() { diff --git a/server/hallserver/mtb/mtb.auto_gen.go b/server/hallserver/mtb/mtb.auto_gen.go index 3bb4817f..63446069 100644 --- a/server/hallserver/mtb/mtb.auto_gen.go +++ b/server/hallserver/mtb/mtb.auto_gen.go @@ -47,6 +47,7 @@ type FriendDb struct { type Config struct { gameapi_url string auto_start_time int32 + game_start_notify_time int32 _flags1_ uint64 _flags2_ uint64 @@ -196,6 +197,14 @@ func (this *Config) HasAutoStartTime() bool { 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{}) { 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{}) { 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.game_start_notify_time, "game_start_notify_time", &this._flags1_, 3, kv) } diff --git a/server/hallserver/player/player.go b/server/hallserver/player/player.go index a4f6522d..cde4f26f 100644 --- a/server/hallserver/player/player.go +++ b/server/hallserver/player/player.go @@ -22,7 +22,9 @@ func (this *player) GetAccountId() string { } 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 { @@ -50,7 +52,6 @@ func (this *player) GetName() string { return "" } - func (this *player) GetAvatarUrl() string { return "" } diff --git a/server/hallserver/proto/cs_msgid.proto b/server/hallserver/proto/cs_msgid.proto index b99468f2..96b4ec5e 100644 --- a/server/hallserver/proto/cs_msgid.proto +++ b/server/hallserver/proto/cs_msgid.proto @@ -2,7 +2,6 @@ syntax = "proto2"; package cs; option go_package = ".;cs"; -//消息id定义 enum CMMessageId_e { _CMPing = 101; @@ -18,6 +17,7 @@ enum CMMessageId_e _CMStartGame = 111; _CMSetPrepare = 112; _CMKickout = 113; + _CMCloseNotify = 114; } enum SMMessageId_e @@ -42,4 +42,5 @@ enum SMMessageId_e _SMRoomLeaveNotify = 1003; _SMRoomDisbandNotify = 1004; _SMRoomChangeNotify = 1005; + _SMRoomGameStartNotify = 1006; } diff --git a/server/hallserver/proto/cs_proto.proto b/server/hallserver/proto/cs_proto.proto index 0e94cb01..e40cade2 100644 --- a/server/hallserver/proto/cs_proto.proto +++ b/server/hallserver/proto/cs_proto.proto @@ -271,6 +271,12 @@ message CMKickout { } +//关闭通知 +message CMCloseNotify +{ + optional int32 param = 1; //1:关闭SMRoomGameStartNotify +} + //房间成员信息变更通知 message SMRoomMemberChangeNotify { @@ -281,6 +287,7 @@ message SMRoomMemberChangeNotify message SMRoomKickoutNotify { repeated string account_ids = 1; //成员account_id列表 + optional int32 reason = 2; //解散原因 1:房主解散 2:系统解散(倒计时超时后队伍数<2) } //房间玩家离开通知 @@ -301,3 +308,12 @@ message SMRoomChangeNotify { 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; //自定义房间透传数据 +} diff --git a/server/hallserver/proto/mt.proto b/server/hallserver/proto/mt.proto index 2673bbdf..3639b4b7 100644 --- a/server/hallserver/proto/mt.proto +++ b/server/hallserver/proto/mt.proto @@ -38,4 +38,5 @@ message Config { optional string gameapi_url = 1; optional int32 auto_start_time = 2; + optional int32 game_start_notify_time = 3; } diff --git a/server/hallserver/room/member.go b/server/hallserver/room/member.go index 5f867970..93a06afe 100644 --- a/server/hallserver/room/member.go +++ b/server/hallserver/room/member.go @@ -11,6 +11,7 @@ import ( type member struct { joinTime int64 state int32 + closeGameStartNotify bool entry q5.ListHead teamEntry q5.ListHead hum common.Player diff --git a/server/hallserver/room/room.go b/server/hallserver/room/room.go index 543be8db..08118c4f 100644 --- a/server/hallserver/room/room.go +++ b/server/hallserver/room/room.go @@ -26,10 +26,14 @@ type room struct { owner *member roomState int32 startTime int64 - startType int32 + startReason int32 + disbandTime int64 + disbandReason int32 teams map[string]*team members map[string]*member startTimer *f5.TimerWp + attacher *f5.TimerAttacher + gameStartNotifyMsg *cs.SMRoomGameStartNotify } 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), } this.owner.hum.SetRoom(this) - this.startTimer = f5.GetTimer().SetTimeoutWp( - mt.Table.Config.Get().GetAutoStartTime(), + this.attacher = f5.GetTimer().NewTimerAttacher() + this.startTimer = f5.GetTimer().SetTimeoutExWp( + 1000 * mt.Table.Config.Get().GetAutoStartTime(), func (e int32, args *q5.Args) { if e == q5.TIMER_EXEC_EVENT { this.autoStart() } - }) + }, + this.attacher) } 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) { for _, m := range(this.members) { m.hum.SendMsg(msg) @@ -211,14 +225,43 @@ func (this *room) started() bool { func (this *room) doDisband(reason int32) { this.roomState = ROOM_DISBAND_STATE + this.disbandTime = q5.GetTickCount() + this.disbandReason = reason } func (this *room) doStart(reason int32) { this.roomState = ROOM_STARTED_STATE 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 { 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) + } + } +}