From b871576fe9ac235d4bb588de728f25340d1ec2da Mon Sep 17 00:00:00 2001 From: by <123456@qq.com> Date: Tue, 24 Sep 2024 13:47:16 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A8=83=E5=A8=83=E6=9C=BAlog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- machine/machinedoll/machinemgr.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/machine/machinedoll/machinemgr.go b/machine/machinedoll/machinemgr.go index 5b10bc3..e059a5b 100644 --- a/machine/machinedoll/machinemgr.go +++ b/machine/machinedoll/machinemgr.go @@ -71,7 +71,7 @@ func (this *MachineManager) Init() { Addr: addr, } SetBaseParam(conn) - logger.Logger.Trace("设置每台娃娃机基础配置!") + fmt.Println("与娃娃机连接成功!设置每台娃娃机基础配置!Id = ", i+1, "addr = ", addr) } /* fmt.Println("Connected to server:\n", this.ConnMap[1].RemoteAddr()) From b04d422d8bd22e7f02bdbbc2cf9ca60fb8efea2b Mon Sep 17 00:00:00 2001 From: by <123456@qq.com> Date: Tue, 24 Sep 2024 16:36:39 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A8=83=E5=A8=83=E6=9C=BA=E7=A6=BB?= =?UTF-8?q?=E7=BA=BF=20=E8=B8=A2=E5=87=BA=E6=88=BF=E9=97=B4=E7=8E=A9?= =?UTF-8?q?=E5=AE=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gamesrv/clawdoll/scene_clawdoll.go | 3 +-- gamesrv/clawdoll/scenepolicy_clawdoll.go | 3 +-- protocol/clawdoll/clawdoll.proto | 5 ++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/gamesrv/clawdoll/scene_clawdoll.go b/gamesrv/clawdoll/scene_clawdoll.go index 7b063fb..56e9e5d 100644 --- a/gamesrv/clawdoll/scene_clawdoll.go +++ b/gamesrv/clawdoll/scene_clawdoll.go @@ -74,7 +74,7 @@ type SceneEx struct { // 游戏是否能开始 func (this *SceneEx) CanStart() bool { //人数>=1自动开始 - if len(this.players) >= 1 && (this.GetRealPlayerNum() >= 1 || this.IsPreCreateScene() || this.IsHasPlaying()) { + if len(this.players) >= 1 && (this.GetRealPlayerNum() >= 1 || this.IsPreCreateScene() || this.IsHasPlaying()) && this.machineStatus == 1 { return true } return false @@ -191,7 +191,6 @@ func (this *SceneEx) ClawdollCreateRoomInfoPacket(s *base.Scene, p *base.Player) RoundId: proto.Int(this.RoundId), ParamsEx: nil, GameFreeId: 0, - BaseScore: proto.Int32(this.GetBaseScore()), } // 玩家信息 diff --git a/gamesrv/clawdoll/scenepolicy_clawdoll.go b/gamesrv/clawdoll/scenepolicy_clawdoll.go index 13b1d9b..9eaf13c 100644 --- a/gamesrv/clawdoll/scenepolicy_clawdoll.go +++ b/gamesrv/clawdoll/scenepolicy_clawdoll.go @@ -77,7 +77,7 @@ func (this *PolicyClawdoll) OnTick(s *base.Scene) { if machineStatus == 0 { //链接状态不可用 踢出所有玩家 for _, p := range sceneEx.players { - sceneEx.delPlayer(p.Player) + sceneEx.PlayerLeave(p.Player, common.PlayerLeaveReason_RoomClose, false) } sceneEx.machineStatus = 0 logger.Logger.Trace("娃娃机离线,当前场景暂停服务!") @@ -97,7 +97,6 @@ func (this *PolicyClawdoll) OnPlayerEnter(s *base.Scene, p *base.Player) { if s == nil || p == nil { return } - logger.Logger.Trace("(this *PolicyClawdoll) OnPlayerEnter, sceneId=", s.GetSceneId(), " player=", p.SnId) if sceneEx, ok := s.ExtraData.(*SceneEx); ok { playerEx := &PlayerEx{Player: p} diff --git a/protocol/clawdoll/clawdoll.proto b/protocol/clawdoll/clawdoll.proto index 3c57c6d..59b7f12 100644 --- a/protocol/clawdoll/clawdoll.proto +++ b/protocol/clawdoll/clawdoll.proto @@ -52,9 +52,8 @@ message SCCLAWDOLLRoomInfo { int32 TimeOut = 6; //该状态已经历时间 单位:秒 repeated CLAWDOLLPlayerData Players = 7; //房间内的玩家信息 int32 TotalPlayer = 8; //房间总人数 - int32 RoundId = 9; //当前局数ID - repeated int32 ParamsEx = 10; //其他参数 - + int32 RoundId = 9; //当前局数ID + repeated int32 ParamsEx = 10; //其他参数 int32 GameFreeId = 15; int32 BaseScore = 16; //基础分 } From 5fd2c7c195988cb6f3f5bc75be4823a92cd78713 Mon Sep 17 00:00:00 2001 From: by <123456@qq.com> Date: Tue, 24 Sep 2024 17:03:44 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=A8=83=E5=A8=83=E5=85=91=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- worldsrv/shopmgr.go | 1 + 1 file changed, 1 insertion(+) diff --git a/worldsrv/shopmgr.go b/worldsrv/shopmgr.go index ec6424f..735dbd1 100644 --- a/worldsrv/shopmgr.go +++ b/worldsrv/shopmgr.go @@ -1126,6 +1126,7 @@ func (this *ShopMgr) ExchangeList(p *Player) (ret bool) { JPrice: info.JPrice, Id: info.Id, Cash: info.Cash, + DPrice: info.DPrice, }) } var telData []*shop.TelChargeData From b4cebfd6878455e04775a20e69248e89a26a6fb1 Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Tue, 24 Sep 2024 18:05:35 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E7=AB=9E=E6=8A=80=E9=A6=86=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E6=88=BF=E9=97=B4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gamesrv/tienlen/scenedata_tienlen.go | 2 +- gamesrv/tienlen/scenepolicy_tienlen.go | 2 +- protocol/webapi/common.pb.go | 13 +- protocol/webapi/common.proto | 1 + worldsrv/action_friend.go | 4 +- worldsrv/action_game.go | 14 +- worldsrv/customroommgr.go | 351 +++++++++++++++++++++++++ worldsrv/etcd.go | 12 + worldsrv/gamesess.go | 4 +- worldsrv/playernotify.go | 12 +- worldsrv/scene.go | 134 +++++----- worldsrv/scenemgr.go | 40 +-- worldsrv/scenepolicydata.go | 17 +- 13 files changed, 501 insertions(+), 105 deletions(-) create mode 100644 worldsrv/customroommgr.go diff --git a/gamesrv/tienlen/scenedata_tienlen.go b/gamesrv/tienlen/scenedata_tienlen.go index d01ee18..77d4664 100644 --- a/gamesrv/tienlen/scenedata_tienlen.go +++ b/gamesrv/tienlen/scenedata_tienlen.go @@ -287,7 +287,7 @@ func (this *TienLenSceneData) OnPlayerLeave(p *base.Player, reason int) { } } } - if !this.GetDestroyed() && this.IsCustom() && len(this.players) == 0 { + if !this.GetDestroyed() && this.IsCustom() && len(this.players) == 0 && this.Creator > 0 { this.SceneDestroy(true) } } diff --git a/gamesrv/tienlen/scenepolicy_tienlen.go b/gamesrv/tienlen/scenepolicy_tienlen.go index 2e3dec9..9511393 100644 --- a/gamesrv/tienlen/scenepolicy_tienlen.go +++ b/gamesrv/tienlen/scenepolicy_tienlen.go @@ -607,7 +607,7 @@ func (this *SceneBaseStateTienLen) OnTick(s *base.Scene) { s.SetTimerRandomRobot(s.GetRobotTime()) } // 房卡房长时间没人解散房间 - if s.IsCustom() && s.GetRealPlayerCnt() == 0 && this.GetTimeout(s) > 5 { + if s.IsCustom() && s.GetRealPlayerCnt() == 0 && this.GetTimeout(s) > 5 && s.Creator > 0 { s.Destroy(true) } } diff --git a/protocol/webapi/common.pb.go b/protocol/webapi/common.pb.go index 2f4e42a..5a17a03 100644 --- a/protocol/webapi/common.pb.go +++ b/protocol/webapi/common.pb.go @@ -8788,6 +8788,7 @@ type RoomConfigSystem struct { FullTime int32 `protobuf:"varint,11,opt,name=FullTime,proto3" json:"FullTime,omitempty"` // 房间状态为满人时房间保留多久,单位秒 AutoCreate int32 `protobuf:"varint,12,opt,name=AutoCreate,proto3" json:"AutoCreate,omitempty"` // 自动创建开关 1开启 2关闭 AutoCreateTime int32 `protobuf:"varint,13,opt,name=AutoCreateTime,proto3" json:"AutoCreateTime,omitempty"` // 自动创建时间间隔,单位秒 + On int32 `protobuf:"varint,14,opt,name=On,proto3" json:"On,omitempty"` // 开关 1开启 2关闭 } func (x *RoomConfigSystem) Reset() { @@ -8913,6 +8914,13 @@ func (x *RoomConfigSystem) GetAutoCreateTime() int32 { return 0 } +func (x *RoomConfigSystem) GetOn() int32 { + if x != nil { + return x.On + } + return 0 +} + var File_common_proto protoreflect.FileDescriptor var file_common_proto_rawDesc = []byte{ @@ -10285,7 +10293,7 @@ var file_common_proto_rawDesc = []byte{ 0x28, 0x05, 0x52, 0x08, 0x43, 0x6f, 0x73, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x56, 0x6f, 0x69, 0x63, 0x65, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x56, 0x6f, 0x69, 0x63, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x55, 0x52, 0x49, 0x18, 0x10, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x55, 0x52, 0x49, 0x22, 0x86, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x55, 0x52, 0x49, 0x22, 0x96, 0x03, 0x0a, 0x10, 0x52, 0x6f, 0x6f, 0x6d, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x12, 0x1a, 0x0a, 0x08, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, @@ -10310,7 +10318,8 @@ var file_common_proto_rawDesc = []byte{ 0x01, 0x28, 0x05, 0x52, 0x0a, 0x41, 0x75, 0x74, 0x6f, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x26, 0x0a, 0x0e, 0x41, 0x75, 0x74, 0x6f, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0e, 0x41, 0x75, 0x74, 0x6f, 0x43, 0x72, 0x65, - 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x42, 0x26, 0x5a, 0x24, 0x6d, 0x6f, 0x6e, 0x67, 0x6f, + 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x4f, 0x6e, 0x18, 0x0e, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x02, 0x4f, 0x6e, 0x42, 0x26, 0x5a, 0x24, 0x6d, 0x6f, 0x6e, 0x67, 0x6f, 0x2e, 0x67, 0x61, 0x6d, 0x65, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x61, 0x6d, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2f, 0x77, 0x65, 0x62, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, diff --git a/protocol/webapi/common.proto b/protocol/webapi/common.proto index 19efed0..02a6e8b 100644 --- a/protocol/webapi/common.proto +++ b/protocol/webapi/common.proto @@ -978,4 +978,5 @@ message RoomConfigSystem{ int32 FullTime = 11; // 房间状态为满人时房间保留多久,单位秒 int32 AutoCreate = 12; // 自动创建开关 1开启 2关闭 int32 AutoCreateTime = 13; // 自动创建时间间隔,单位秒 + int32 On = 14; // 开关 1开启 2关闭 } \ No newline at end of file diff --git a/worldsrv/action_friend.go b/worldsrv/action_friend.go index b32e237..07a086b 100644 --- a/worldsrv/action_friend.go +++ b/worldsrv/action_friend.go @@ -503,8 +503,8 @@ func (this *CSInviteFriendOpHandler) Process(s *netlib.Session, packetid int, da // 房费是否充足 if scene.IsCustom() { - cfg := PlatformMgrSingleton.GetConfig(p.Platform).RoomConfig[scene.RoomConfigId] - if scene.CostType == 1 && !scene.sp.CostEnough(int(scene.CostType), scene.playerNum, cfg, p.SnId) { + cfg := PlatformMgrSingleton.GetConfig(p.Platform).RoomConfig[scene.CustomParam.RoomConfigId] + if scene.CustomParam.CostType == 1 && !scene.sp.CostEnough(int(scene.CustomParam.CostType), scene.playerNum, cfg, p.SnId) { logger.Logger.Trace("CSInviteFriendHandler cost error") opRetCode = friend.OpResultCode_OPRC_InviteFriend_CostNotEnough send(p) diff --git a/worldsrv/action_game.go b/worldsrv/action_game.go index 4aa858c..723b6c7 100644 --- a/worldsrv/action_game.go +++ b/worldsrv/action_game.go @@ -4,6 +4,7 @@ import ( "fmt" "math/rand" "slices" + "sort" "time" "mongo.games.com/goserver/core/basic" @@ -105,8 +106,8 @@ func (this *CSEnterRoomHandler) Process(s *netlib.Session, packetid int, data in } // 房费是否充足 if scene.IsCustom() { - cfg := PlatformMgrSingleton.GetConfig(p.Platform).RoomConfig[scene.RoomConfigId] - if scene.CostType == 1 && !scene.sp.CostEnough(int(scene.CostType), scene.playerNum, cfg, p.SnId) { + cfg := PlatformMgrSingleton.GetConfig(p.Platform).RoomConfig[scene.CustomParam.RoomConfigId] + if scene.CustomParam.CostType == 1 && !scene.sp.CostEnough(int(scene.CustomParam.CostType), scene.playerNum, cfg, p.SnId) { code = gamehall.OpResultCode_Game_OPRC_CostNotEnough logger.Logger.Trace("CSEnterRoomHandler cost error") goto failed @@ -1411,7 +1412,7 @@ func CSGetPrivateRoomListHandler(s *netlib.Session, packetId int, data interface GameFreeId: v.dbGameFree.GetId(), GameId: v.dbGameFree.GetGameId(), RoomTypeId: v.GetRoomTypeId(), - RoomConfigId: v.GetRoomConfigId(), + RoomConfigId: v.CustomParam.GetRoomConfigId(), RoomId: int32(v.sceneId), NeedPassword: int32(needPassword), CurrRound: v.currRound, @@ -1424,6 +1425,13 @@ func CSGetPrivateRoomListHandler(s *netlib.Session, packetId int, data interface } pack.Datas = append(pack.Datas, d) } + + pack.Datas = append(pack.Datas, CustomRoomMgrSingle.GetRoomList(p.Platform)...) + + sort.Slice(pack.Datas, func(i, j int) bool { + return pack.Datas[i].GetCreateTs() < pack.Datas[j].GetCreateTs() + }) + p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SC_GETPRIVATEROOMLIST), pack) logger.Logger.Tracef("SCGetPrivateRoomList: %v", pack) return nil diff --git a/worldsrv/customroommgr.go b/worldsrv/customroommgr.go new file mode 100644 index 0000000..75add0a --- /dev/null +++ b/worldsrv/customroommgr.go @@ -0,0 +1,351 @@ +package main + +import ( + "slices" + "time" + + "mongo.games.com/goserver/core/logger" + "mongo.games.com/goserver/core/module" + "mongo.games.com/goserver/core/timer" + + "mongo.games.com/game/common" + "mongo.games.com/game/model" + "mongo.games.com/game/protocol/gamehall" + "mongo.games.com/game/protocol/server" +) + +func init() { + RegisteGameSessionListener(CustomRoomMgrSingle) + module.RegisteModule(CustomRoomMgrSingle, time.Second*3, 0) +} + +var CustomRoomMgrSingle = &CustomRoomMgr{ + data: make(map[string]*CustomMgr), + list: make(map[string]map[int32]struct{}), +} + +type CustomRoomInfo struct { + Platform string + SystemConfigId int32 + Handle timer.TimerHandle + *gamehall.PrivateRoomInfo + *Scene +} + +func (c *CustomRoomInfo) Notify(tp common.ListOpType) { + if c.PrivateRoomInfo == nil || c.Scene != nil { + return + } + pack := &gamehall.SCGetPrivateRoomList{ + Tp: int32(tp), + Datas: []*gamehall.PrivateRoomInfo{c.PrivateRoomInfo}, + } + PlayerNotifySingle.SendToClient(common.NotifyPrivateRoomList, c.Platform, int(gamehall.GameHallPacketID_PACKET_SC_GETPRIVATEROOMLIST), pack) + logger.Logger.Tracef("CustomRoomInfo NotifyPrivateRoom: %v", pack) +} + +type CustomMgr struct { + List map[int32]*CustomRoomInfo // 满人房间假数据 + DestroyTime map[int32]time.Time // 空房间最后解散时间,配置id:解散时间 +} + +type CustomRoomMgr struct { + common.BaseClockSinker + data map[string]*CustomMgr + list map[string]map[int32]struct{} +} + +func (c *CustomRoomMgr) ModuleName() string { + return "CustomRoomMgr" +} + +func (c *CustomRoomMgr) Init() { + +} + +func (c *CustomRoomMgr) Update() { + for k, v := range c.list { + for kk := range v { + c.tryCreate(k, kk) + } + } + c.list = make(map[string]map[int32]struct{}) +} + +func (c *CustomRoomMgr) Shutdown() { + module.UnregisteModule(c) +} + +func (c *CustomRoomMgr) OnGameSessionRegiste(session *GameSession) { + for _, v := range PlatformMgrSingleton.GetPlatforms() { + if v == nil { + continue + } + plt := PlatformMgrSingleton.GetPlatform(v.IdStr) + if plt == nil { + continue + } + for _, info := range PlatformMgrSingleton.GetConfig(plt.IdStr).RoomConfigSystem { + if info == nil { + continue + } + gf := PlatformMgrSingleton.GetGameFree(plt.IdStr, info.GetGameFreeId()) + if gf == nil || !gf.GetStatus() || info.GetOn() == common.Off { + continue + } + + roomConfig := PlatformMgrSingleton.GetConfig(plt.IdStr).RoomConfig[info.GetRoomConfigId()] + if roomConfig == nil || roomConfig.GetOn() == common.Off { + return + } + + if len(session.gameIds) == 0 || slices.Contains(session.gameIds, gf.GetDbGameFree().GetGameId()) { + c.TouchCreate(plt.IdStr, info.GetId()) + } + } + } +} + +func (c *CustomRoomMgr) OnGameSessionUnregiste(session *GameSession) { +} + +func (c *CustomRoomMgr) TouchCreate(plt string, configId int32) { + m := c.list[plt] + if m == nil { + m = make(map[int32]struct{}) + c.list[plt] = m + } + c.list[plt][configId] = struct{}{} +} + +func (c *CustomRoomMgr) GetRoomList(plt string) []*gamehall.PrivateRoomInfo { + d := c.data[plt] + if d == nil { + return nil + } + var ret []*gamehall.PrivateRoomInfo + for _, v := range d.List { + if v != nil && v.PrivateRoomInfo != nil { + ret = append(ret, v.PrivateRoomInfo) + } + } + return ret +} + +func (c *CustomRoomMgr) tryCreate(plt string, configId int32) { + logger.Logger.Tracef("尝试创建竞技馆系统房间 %v", configId) + cfg := PlatformMgrSingleton.GetConfig(plt).RoomConfigSystem[configId] + if cfg == nil || cfg.GetOn() == common.Off { + return + } + + c.TryDestroy(plt, configId) + + m := c.data[plt] + if m == nil { + m = &CustomMgr{ + List: make(map[int32]*CustomRoomInfo), + DestroyTime: make(map[int32]time.Time), + } + c.data[plt] = m + } + _, ok := m.List[cfg.GetId()] + if ok { + return + } + + c.UpdateCreate(plt, cfg.GetId(), true) +} + +func (c *CustomRoomMgr) TryDestroy(plt string, configId int32) { + logger.Logger.Tracef("尝试解散竞技馆系统房间 %v", configId) + cfg := PlatformMgrSingleton.GetConfig(plt).RoomConfigSystem[configId] + if cfg == nil { + return + } + + v, ok := c.data[plt] + if !ok || v == nil { + return + } + + info := v.List[configId] + + if info != nil { + timer.StopTimer(info.Handle) + if info.Scene != nil && !info.deleting { + info.SendGameDestroy(true) + } + if info.Scene == nil { + c.Release(plt, configId) + } + } + if cfg.GetState() == 2 { // 假房间立刻删除 + c.Release(plt, configId) + } +} + +func (c *CustomRoomMgr) Release(plt string, configId int32) { + logger.Logger.Tracef("释放竞技馆房间创建记录 %v", configId) + v, ok := c.data[plt] + if !ok || v == nil { + return + } + + info := v.List[configId] + + if info != nil { + timer.StopTimer(info.Handle) + info.Notify(common.ListDel) + } + + delete(v.List, configId) + v.DestroyTime[configId] = time.Now() +} + +func (c *CustomRoomMgr) UpdateCreate(plt string, configId int32, mustCreate bool) { + cfg := PlatformMgrSingleton.GetConfig(plt).RoomConfigSystem[configId] + if cfg == nil { + return + } + + gf := PlatformMgrSingleton.GetGameFree(plt, cfg.GetGameFreeId()) + if gf == nil || !gf.GetStatus() || cfg.GetOn() == common.Off { + // 游戏没开 + return + } + + roomConfig := PlatformMgrSingleton.GetConfig(plt).RoomConfig[cfg.GetRoomConfigId()] + if roomConfig == nil || roomConfig.GetOn() == common.Off { + return + } + + m := c.data[plt] + if m == nil { + m = &CustomMgr{ + List: make(map[int32]*CustomRoomInfo), + DestroyTime: make(map[int32]time.Time), + } + c.data[plt] = m + } + _, ok := m.List[cfg.GetId()] + if ok { + return + } + + info := &CustomRoomInfo{ + Platform: plt, + SystemConfigId: cfg.GetId(), + } + m.List[cfg.GetId()] = info + + destroyTime := m.DestroyTime[cfg.GetId()] + subTime := time.Duration(0) + if !destroyTime.IsZero() { + subTime = time.Duration(cfg.GetAutoCreateTime())*time.Second - time.Now().Sub(destroyTime) + } + if subTime < 0 || mustCreate { + subTime = 0 + } + + f := func(fn func()) { + b, _ := timer.AfterTimer(func(h timer.TimerHandle, ud interface{}) bool { + fn() + return true + }, nil, subTime) + m.List[cfg.GetId()].Handle = b + } + + if cfg.GetAutoCreate() == 1 || mustCreate { + logger.Logger.Tracef("Update 竞技馆系统房间创建 %v", configId) + f(func() { + gf = PlatformMgrSingleton.GetGameFree(plt, cfg.GetGameFreeId()) + if gf == nil || !gf.GetStatus() || cfg.GetOn() == common.Off { + c.Release(plt, cfg.GetId()) + return + } + + roomConfig = PlatformMgrSingleton.GetConfig(plt).RoomConfig[cfg.GetRoomConfigId()] + if roomConfig == nil || roomConfig.GetOn() == common.Off { + c.Release(plt, cfg.GetId()) + return + } + + cfg = PlatformMgrSingleton.GetConfig(plt).RoomConfigSystem[configId] + if cfg == nil || cfg.GetOn() == common.Off { + c.Release(plt, cfg.GetId()) + return + } + + switch cfg.GetState() { + case 1: // 系统房间 + csp := CoinSceneMgrSingleton.GetCoinScenePool(cfg.GetPlatform(), cfg.GetGameFreeId()) + roomId := SceneMgrSingleton.GenOnePrivateSceneId() + scene := SceneMgrSingleton.CreateScene(&CreateSceneParam{ + CreateId: 0, + RoomId: roomId, + SceneMode: common.SceneModePrivateMatch, + TotalRound: int(cfg.GetRound()), + Params: common.CopySliceInt32ToInt64(csp.dbGameRule.GetParams()), + Platform: PlatformMgrSingleton.GetPlatform(cfg.GetPlatform()), + GF: csp.dbGameFree, + PlayerNum: cfg.GetPlayerNum(), + Channel: roomConfig.GetOnChannelName(), + CustomParam: &server.CustomParam{ + RoomTypeId: roomConfig.GetRoomType(), + RoomConfigId: roomConfig.GetId(), + CostType: 1, + Voice: cfg.GetVoice(), + }, + RoomConfigSystem: cfg, + }) + if scene != nil { + logger.Logger.Tracef("竞技馆系统房间创建成功 roomId:%v", scene.sceneId) + csp.AddScene(scene) + info.Scene = scene + } else { + logger.Logger.Warnf("竞技馆系统房间创建失败 roomConfigSystemId:%v", cfg.GetId()) + c.Release(plt, cfg.GetId()) + } + default: // 假房间 + roomId := SceneMgrSingleton.GenOnePrivateSceneId() + info.PrivateRoomInfo = &gamehall.PrivateRoomInfo{ + GameFreeId: cfg.GetGameFreeId(), + GameId: gf.GetDbGameFree().GetGameId(), + RoomTypeId: roomConfig.GetRoomType(), + RoomConfigId: roomConfig.GetId(), + RoomId: int32(roomId), + NeedPassword: 0, + CurrRound: int32(common.RandInt(1, int(cfg.GetRound()))), + MaxRound: cfg.GetRound(), + CurrNum: cfg.GetPlayerNum(), + MaxPlayer: cfg.GetPlayerNum(), + CreateTs: time.Now().Unix(), + State: 1, + } + for i := 0; i < int(cfg.GetPlayerNum()); i++ { + info.PrivateRoomInfo.Players = append(info.PrivateRoomInfo.Players, &gamehall.PrivatePlayerInfo{ + SnId: 0, + Name: "", + UseRoleId: common.RandInt32Slice(common.RolesIDs), + }) + } + info.Notify(common.ListAdd) + logger.Logger.Tracef("竞技馆假房间创建成功 %v", info.PrivateRoomInfo) + if cfg.FullTime <= 0 { + cfg.FullTime = int32(model.GameParamData.SceneMaxIdle) + } + if cfg.FullTime < 3 { + cfg.FullTime = 3 // 至少3秒 + } + b, _ := timer.AfterTimer(func(h timer.TimerHandle, ud interface{}) bool { + logger.Logger.Tracef("竞技馆假房间解散 %v", info) + c.Release(plt, configId) + c.UpdateCreate(plt, configId, false) + return true + }, nil, time.Duration(cfg.GetFullTime())*time.Second) + info.Handle = b + } + }) + } +} diff --git a/worldsrv/etcd.go b/worldsrv/etcd.go index 7c38728..686c3a9 100644 --- a/worldsrv/etcd.go +++ b/worldsrv/etcd.go @@ -512,6 +512,7 @@ func handlerEvent(ctx context.Context, completeKey string, isInit bool, event *c if !isInit { //PlayerMgrSington.BroadcastMessageToPlatform(config.GetPlatform(), int(0), nil) } + case clientv3.EventTypeDelete: if plt == "" || len(param) == 0 { return @@ -530,10 +531,21 @@ func handlerEvent(ctx context.Context, completeKey string, isInit bool, event *c } config := data.(*webapi.RoomConfigSystem) PlatformMgrSingleton.GetConfig(config.GetPlatform()).RoomConfigSystem[config.GetId()] = config + switch config.GetOn() { + case common.On: + CustomRoomMgrSingle.TouchCreate(config.GetPlatform(), config.GetId()) + case common.Off: + if !isInit { + CustomRoomMgrSingle.TryDestroy(config.GetPlatform(), config.GetId()) + } + } case clientv3.EventTypeDelete: if plt == "" || len(param) == 0 { return } + if !isInit { + CustomRoomMgrSingle.TryDestroy(plt, int32(param[0])) + } delete(PlatformMgrSingleton.GetConfig(plt).RoomConfigSystem, int32(param[0])) } diff --git a/worldsrv/gamesess.go b/worldsrv/gamesess.go index b853d68..6dcb5bc 100644 --- a/worldsrv/gamesess.go +++ b/worldsrv/gamesess.go @@ -174,8 +174,8 @@ func (this *GameSession) AddScene(args *AddSceneParam) { Match: args.S.MatchParam, Params: args.S.params, } - if args.S.GetRoomConfigId() != 0 { - cfg := PlatformMgrSingleton.GetConfig(args.S.platform.IdStr).RoomConfig[args.S.GetRoomConfigId()] + if args.S.CustomParam.GetRoomConfigId() != 0 { + cfg := PlatformMgrSingleton.GetConfig(args.S.platform.IdStr).RoomConfig[args.S.CustomParam.GetRoomConfigId()] if cfg != nil { for _, v := range cfg.GetReward() { msg.Items = append(msg.Items, &server_proto.Item{ diff --git a/worldsrv/playernotify.go b/worldsrv/playernotify.go index 8ca06e8..3d45bf7 100644 --- a/worldsrv/playernotify.go +++ b/worldsrv/playernotify.go @@ -77,19 +77,19 @@ func (p *PlayerNotify) GetPlayers(tp common.NotifyType) []int32 { // SendToClient 发送消息给客户端 // tp 消息类型 -func (p *PlayerNotify) SendToClient(tp common.NotifyType, packetId int, pack interface{}) { +func (p *PlayerNotify) SendToClient(tp common.NotifyType, platform string, packetId int, pack interface{}) { switch tp { case common.NotifyPrivateRoomList: d := pack.(*gamehall.SCGetPrivateRoomList) if len(d.GetDatas()) == 0 { return } - scene := SceneMgrSingleton.GetScene(int(d.GetDatas()[0].GetRoomId()), true) - if scene == nil { - return - } + //scene := SceneMgrSingleton.GetScene(int(d.GetDatas()[0].GetRoomId()), true) + //if scene == nil { + // return + //} roomConfigId := d.GetDatas()[0].GetRoomConfigId() - cfg := PlatformMgrSingleton.GetConfig(scene.platform.IdStr).RoomConfig[roomConfigId] + cfg := PlatformMgrSingleton.GetConfig(platform).RoomConfig[roomConfigId] if cfg == nil { return } diff --git a/worldsrv/scene.go b/worldsrv/scene.go index d6b2955..bf5a8d1 100644 --- a/worldsrv/scene.go +++ b/worldsrv/scene.go @@ -18,6 +18,7 @@ import ( "mongo.games.com/game/protocol/gamehall" hallproto "mongo.games.com/game/protocol/gamehall" serverproto "mongo.games.com/game/protocol/server" + webapiproto "mongo.games.com/game/protocol/webapi" "mongo.games.com/game/srvdata" ) @@ -28,45 +29,46 @@ type PlayerGameCtx struct { // Scene 场景(房间) type Scene struct { - sceneId int // 场景id - gameId int // 游戏id - gameMode int // 废弃,游戏模式(玩法) - sceneMode int // 房间模式,参考common.SceneMode_XXX - params []int64 // 场景参数 - playerNum int // 房间最大人数 - robotNum int // 机器人数量 - robotLimit int // 最大限制机器人数量 - creator int32 // 创建者账号id - replayCode string // 回放码 - currRound int32 // 当前第几轮 - totalRound int32 // 总共几轮,小于等于0表示无限轮 - cycleTimes int32 // 循环次数,未使用 - deleting bool // 正在删除 - starting bool // 正在开始 - closed bool // 房间已关闭 - force bool // 强制删除 - players map[int32]*Player // 玩家 - audiences map[int32]*Player // 观众 - seats [9]*Player // 座位 - gameSess *GameSession // 所在gameserver - sp ScenePolicy // 场景上的一些业务策略 - createTime time.Time // 创建时间 - lastTime time.Time // 最后活跃时间 - startTime time.Time // 游戏开始时间 - platform *Platform // 限制平台 - groupId int32 // 组id - dbGameFree *serverproto.DB_GameFree // 场次配置 - gameCtx map[int32]*PlayerGameCtx // 进入房间的环境,没有机器人数据 SnId - BaseScore int32 // 游戏底分,优先级,创建参数>本地配置>场次配置 - SceneState int32 // 房间当前状态 - State int32 // 当前游戏状态,后期放到ScenePolicy里去处理 - StateTs int64 // 切换到当前状态的时间 - StateSec int32 // 押注状态的秒数 - Channel []string // 客户端类型 - *serverproto.CustomParam // 房卡场参数 - *serverproto.MatchParam // 比赛场参数 - csp *CoinScenePool // 所在场景池 - hp *HundredSceneMgr // 百人场房间池 + sceneId int // 场景id + gameId int // 游戏id + gameMode int // 废弃,游戏模式(玩法) + sceneMode int // 房间模式,参考common.SceneMode_XXX + params []int64 // 场景参数 + playerNum int // 房间最大人数 + robotNum int // 机器人数量 + robotLimit int // 最大限制机器人数量 + creator int32 // 创建者账号id + replayCode string // 回放码 + currRound int32 // 当前第几轮 + totalRound int32 // 总共几轮,小于等于0表示无限轮 + cycleTimes int32 // 循环次数,未使用 + deleting bool // 正在删除 + starting bool // 正在开始 + closed bool // 房间已关闭 + force bool // 强制删除 + players map[int32]*Player // 玩家 + audiences map[int32]*Player // 观众 + seats [9]*Player // 座位 + gameSess *GameSession // 所在gameserver + sp ScenePolicy // 场景上的一些业务策略 + createTime time.Time // 创建时间 + lastTime time.Time // 最后活跃时间 + startTime time.Time // 游戏开始时间 + platform *Platform // 限制平台 + groupId int32 // 组id + dbGameFree *serverproto.DB_GameFree // 场次配置 + gameCtx map[int32]*PlayerGameCtx // 进入房间的环境,没有机器人数据 SnId + BaseScore int32 // 游戏底分,优先级,创建参数>本地配置>场次配置 + SceneState int32 // 房间当前状态 + State int32 // 当前游戏状态,后期放到ScenePolicy里去处理 + StateTs int64 // 切换到当前状态的时间 + StateSec int32 // 押注状态的秒数 + Channel []string // 客户端类型 + *serverproto.CustomParam // 房卡场参数 + *serverproto.MatchParam // 比赛场参数 + *webapiproto.RoomConfigSystem // 系统竞技馆房间 + csp *CoinScenePool // 所在场景池 + hp *HundredSceneMgr // 百人场房间池 } // NewScene 创建房间 @@ -81,29 +83,30 @@ func NewScene(args *CreateSceneParam) *Scene { } s := &Scene{ - sceneId: args.RoomId, - playerNum: int(args.PlayerNum), - creator: args.CreateId, - gameId: gameId, - gameMode: gameMode, - sceneMode: args.SceneMode, - params: args.Params, - cycleTimes: int32(args.CycleTimes), - players: make(map[int32]*Player), - audiences: make(map[int32]*Player), - gameSess: args.GS, - sp: sp, - createTime: time.Now(), - platform: args.Platform, - groupId: 0, - gameCtx: make(map[int32]*PlayerGameCtx), //进入房间的环境 - dbGameFree: args.GF, - currRound: 0, - totalRound: int32(args.TotalRound), - BaseScore: args.BaseScore, - Channel: args.Channel, - CustomParam: args.CustomParam, - MatchParam: args.MatchParam, + sceneId: args.RoomId, + playerNum: int(args.PlayerNum), + creator: args.CreateId, + gameId: gameId, + gameMode: gameMode, + sceneMode: args.SceneMode, + params: args.Params, + cycleTimes: int32(args.CycleTimes), + players: make(map[int32]*Player), + audiences: make(map[int32]*Player), + gameSess: args.GS, + sp: sp, + createTime: time.Now(), + platform: args.Platform, + groupId: 0, + gameCtx: make(map[int32]*PlayerGameCtx), //进入房间的环境 + dbGameFree: args.GF, + currRound: 0, + totalRound: int32(args.TotalRound), + BaseScore: args.BaseScore, + Channel: args.Channel, + CustomParam: args.CustomParam, + MatchParam: args.MatchParam, + RoomConfigSystem: args.RoomConfigSystem, } // 最大房间人数 if s.playerNum <= 0 { @@ -142,6 +145,9 @@ func NewScene(args *CreateSceneParam) *Scene { if s.CustomParam == nil { s.CustomParam = new(serverproto.CustomParam) } + if s.RoomConfigSystem == nil { + s.RoomConfigSystem = new(webapiproto.RoomConfigSystem) + } return s } @@ -932,7 +938,7 @@ func (this *Scene) ProtoPrivateRoom() *gamehall.PrivateRoomInfo { GameFreeId: this.dbGameFree.GetId(), GameId: int32(this.gameId), RoomTypeId: this.RoomTypeId, - RoomConfigId: this.RoomConfigId, + RoomConfigId: this.CustomParam.RoomConfigId, RoomId: int32(this.sceneId), NeedPassword: needPassword, CurrRound: this.currRound, @@ -959,7 +965,7 @@ func (this *Scene) NotifyPrivateRoom(tp common.ListOpType) { Tp: int32(tp), Datas: []*gamehall.PrivateRoomInfo{this.ProtoPrivateRoom()}, } - PlayerNotifySingle.SendToClient(common.NotifyPrivateRoomList, int(gamehall.GameHallPacketID_PACKET_SC_GETPRIVATEROOMLIST), pack) + PlayerNotifySingle.SendToClient(common.NotifyPrivateRoomList, this.platform.IdStr, int(gamehall.GameHallPacketID_PACKET_SC_GETPRIVATEROOMLIST), pack) logger.Logger.Tracef("NotifyPrivateRoom: %v", pack) } } diff --git a/worldsrv/scenemgr.go b/worldsrv/scenemgr.go index 894b918..4f98278 100644 --- a/worldsrv/scenemgr.go +++ b/worldsrv/scenemgr.go @@ -178,7 +178,7 @@ func (m *SceneMgr) MarshalAllRoom(platform string, groupId, gameId int, gameMode (s.dbGameFree.GetId() == gameFreeId || gameFreeId == 0) && (s.sceneMode == sceneMode || sceneMode == -1) && ((s.IsCustom() && isCustom) || !isCustom) && - (s.GetRoomConfigId() == roomConfigId || roomConfigId == 0)) || isNeedFindAll { + (s.CustomParam.GetRoomConfigId() == roomConfigId || roomConfigId == 0)) || isNeedFindAll { var platformName string if s.platform != nil { platformName = s.platform.IdStr @@ -199,12 +199,12 @@ func (m *SceneMgr) MarshalAllRoom(platform string, groupId, gameId int, gameMode RobotCnt: int32(s.robotNum), CreateTime: s.createTime.Unix(), BaseScore: s.dbGameFree.BaseScore, - RoomConfigId: s.GetRoomConfigId(), + RoomConfigId: s.CustomParam.GetRoomConfigId(), CurrRound: s.currRound, MaxRound: s.totalRound, Password: s.GetPassword(), - CostType: s.GetCostType(), - Voice: s.GetVoice(), + CostType: s.CustomParam.GetCostType(), + Voice: s.CustomParam.GetVoice(), PlayerNum: int32(s.playerNum), } if s.starting { @@ -215,6 +215,9 @@ func (m *SceneMgr) MarshalAllRoom(platform string, groupId, gameId int, gameMode if s.IsHundredScene() { si.Start = 1 } + if s.RoomConfigSystem.GetId() > 0 { + si.Creator = s.RoomConfigSystem.GetId() + } if s.gameSess != nil { si.SrvId = s.gameSess.GetSrvId() } @@ -369,20 +372,21 @@ func (m *SceneMgr) FindRoomList(args *FindRoomParam) []*Scene { } type CreateSceneParam struct { - CreateId int32 // 创建者id - RoomId int // 房间id - SceneMode int // 公共,私人,赛事 - CycleTimes int // 循环次数 - TotalRound int // 总轮数 - Params []int64 // 房间参数 - GS *GameSession // 游戏服务 - Platform *Platform // 所在平台 - GF *serverproto.DB_GameFree // 场次配置 - PlayerNum int32 // 玩家最大数量 - BaseScore int32 // 底分 - Channel []string // 客户端类型,允许查看的客户端类型 - *serverproto.CustomParam // 房卡场参数 - *serverproto.MatchParam // 比赛场参数 + CreateId int32 // 创建者id + RoomId int // 房间id + SceneMode int // 公共,私人,赛事 + CycleTimes int // 循环次数 + TotalRound int // 总轮数 + Params []int64 // 房间参数 + GS *GameSession // 游戏服务 + Platform *Platform // 所在平台 + GF *serverproto.DB_GameFree // 场次配置 + PlayerNum int32 // 玩家最大数量 + BaseScore int32 // 底分 + Channel []string // 客户端类型,允许查看的客户端类型 + *serverproto.CustomParam // 房卡场参数 + *serverproto.MatchParam // 比赛场参数 + *webapiproto.RoomConfigSystem // 竞技管系统房参数 } // CreateScene 创建房间 diff --git a/worldsrv/scenepolicydata.go b/worldsrv/scenepolicydata.go index 949bc78..173c64d 100644 --- a/worldsrv/scenepolicydata.go +++ b/worldsrv/scenepolicydata.go @@ -40,9 +40,14 @@ func (spd *ScenePolicyData) OnStart(s *Scene) { func (spd *ScenePolicyData) OnStop(s *Scene) { s.NotifyPrivateRoom(common.ListDel) // 房主付费,房间没有玩就解散了,返还房主建房费用 - if s.IsCustom() && s.GetCostType() == 2 && s.currRound == 0 { + if s.IsCustom() && s.CustomParam.GetCostType() == 2 && s.currRound == 0 { s.sp.GiveCostPayment(s, s.creator) } + // 系统房间解散后自动创建 + if s.RoomConfigSystem != nil { + CustomRoomMgrSingle.Release(s.platform.IdStr, s.RoomConfigSystem.GetId()) + CustomRoomMgrSingle.UpdateCreate(s.platform.IdStr, s.RoomConfigSystem.GetId(), false) + } } func (spd *ScenePolicyData) OnTick(s *Scene) { @@ -66,7 +71,7 @@ func (spd *ScenePolicyData) OnSceneState(s *Scene, state int) { case common.SceneStateStart: s.NotifyPrivateRoom(common.ListModify) if s.IsCustom() { - if s.GetCostType() == 1 { + if s.CustomParam.GetCostType() == 1 { for _, v := range s.players { spd.CostPayment(s, v.SnId) } @@ -136,11 +141,11 @@ func (spd *ScenePolicyData) CostPayment(s *Scene, snid int32) bool { if p == nil { return false } - roomConfig := PlatformMgrSingleton.GetConfig(p.Platform).RoomConfig[s.GetRoomConfigId()] + roomConfig := PlatformMgrSingleton.GetConfig(p.Platform).RoomConfig[s.CustomParam.GetRoomConfigId()] if roomConfig == nil { return false } - return spd.costEnough(int(s.GetCostType()), s.playerNum, roomConfig, p.SnId, func(items []*model.Item) { + return spd.costEnough(int(s.CustomParam.GetCostType()), s.playerNum, roomConfig, p.SnId, func(items []*model.Item) { for _, v := range items { v.ItemNum = -v.ItemNum } @@ -159,12 +164,12 @@ func (spd *ScenePolicyData) CostPayment(s *Scene, snid int32) bool { } func (spd *ScenePolicyData) GiveCostPayment(s *Scene, snid int32) bool { - roomConfig := PlatformMgrSingleton.GetConfig(s.platform.IdStr).RoomConfig[s.GetRoomConfigId()] + roomConfig := PlatformMgrSingleton.GetConfig(s.platform.IdStr).RoomConfig[s.CustomParam.GetRoomConfigId()] if roomConfig == nil { return false } - if s.GetCostType() != 2 { // 只有房主付费才有返还 + if s.CustomParam.GetCostType() != 2 { // 只有房主付费才有返还 return false }