From 9bbff431b0f42a19ed6efe6b98164586b5984a20 Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期二, 20 一月 2026 15:55:00 +0800
Subject: [PATCH] 16 卡牌服务端(后台GM广播;)
---
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/GMToolLogicProcess/Commands/GMT_BroadCast.py | 141 +++++++++++++++++++++++++++++++++++++++++++++++
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/ChPlayer.py | 2
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorld.py | 16 +++++
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyGameData.py | 2
4 files changed, 161 insertions(+), 0 deletions(-)
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorld.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorld.py
index 13de66e..652b5f1 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorld.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorld.py
@@ -905,6 +905,22 @@
return
return
+
+## 获得指定的时间格式
+# @param timeStr 时间列表
+# @param timeFormat 指定的转换格式
+# @return 时间datetime格式
+# @remarks 获得指定的时间格式
+def GetDateTimeByFormatStr(timeStr, timeFormat):
+ timeStr = timeStr.strip().split(".")[0]
+ try:
+ return datetime.datetime.strptime(timeStr, timeFormat)
+ except BaseException , e :
+ Log("%s : %s"%(e, timeStr))
+ return
+
+ return
+
#---------------------------------------------------------------------
##获得与现实时间差距的小时数
# @param dateTimeStr 比较时间字符 如"2010-05-26 11:21:25"
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/ChPlayer.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/ChPlayer.py
index f2ddac7..9f92601 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/ChPlayer.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/ChPlayer.py
@@ -125,6 +125,7 @@
import IPY_ServerDefine
import CommFunc
from PyMongoDB import RecvPackToMapDB
+import GMT_BroadCast
import PyMongoMain
import PlayerTalk
import PlayerHero
@@ -715,6 +716,7 @@
else:
PyMongoMain.GetUserCtrlDB().OnPlayerLogin(curPlayer)
+ GMT_BroadCast.OnPlayerLogin(curPlayer)
PlayerHero.OnPlayerLogin(curPlayer)
PlayerMail.OnPlayerLogin(curPlayer)
PlayerHJG.OnPlayerLogin(curPlayer)
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyGameData.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyGameData.py
index a6e2851..e80895e 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyGameData.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyGameData.py
@@ -38,6 +38,8 @@
g_turnFightMgr = None
+g_broadCastList = [] # 后台gm广播
+
g_arenaPlayerMatchDict = {} # 本服竞技场玩家匹配记录缓存 {playerID:[tagPlayerID, ...], ...}
g_beautyEffTypeDict = {} # 红颜特殊效果缓存 {playerID:{effType:[effValue, effTypeValue], ...}, ...}
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/GMToolLogicProcess/Commands/GMT_BroadCast.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/GMToolLogicProcess/Commands/GMT_BroadCast.py
new file mode 100644
index 0000000..f569f7e
--- /dev/null
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/GMToolLogicProcess/Commands/GMT_BroadCast.py
@@ -0,0 +1,141 @@
+#!/usr/bin/python
+# -*- coding: GBK -*-
+#-------------------------------------------------------------------------------
+#
+##@package PyMongoDB.GMToolLogicProcess.Commands.GMT_BroadCast
+#
+# @todo:GM工具命令 - 广播
+# @author hxp
+# @date 2026-01-20
+# @version 1.0
+#
+# 详细描述: GM工具命令 - 广播
+#
+#-------------------------------------------------------------------------------
+#"""Version = 2026-01-20 16:00"""
+#-------------------------------------------------------------------------------
+
+import ChConfig
+import GameWorld
+import DataRecordPack
+import ChPyNetSendPack
+import NetPackCommon
+import PyGameData
+import GMCommon
+
+import datetime
+
+Def_MaxBroadCast = 10 # 广播最大存储数量
+
+## 收到gm命令执行
+# @param gmCmdDict:gm命令字典
+# @return None
+def OnExec(gmCmdDict):
+ broadCastMsg = gmCmdDict.get(GMCommon.Def_GMKey_BroadCastMsg, '')
+ startTime = gmCmdDict.get(GMCommon.Def_GMKey_StartTime, '')
+ endTime = gmCmdDict.get(GMCommon.Def_GMKey_EndTime, '')
+
+ startDate = gmCmdDict.get(GMCommon.Def_GMKey_StartDate, '')
+ endDate = gmCmdDict.get(GMCommon.Def_GMKey_EndDate, '')
+ interval = GameWorld.ToIntDef(gmCmdDict.get(GMCommon.Def_GMKey_Interval, '1'), 1)
+ interval = max(1, interval)
+ isDelOthers = gmCmdDict.get(GMCommon.Def_GMKey_IsDelOthers, 0) == "on"
+
+ if startDate == '' or startTime == '' or endDate == '' or endTime == '':
+ # 没有设置时间,默认立即广播一次
+ startTime = GameWorld.GetCurrentDataTimeStr()
+ endTime = str(GameWorld.GetServerTime() + datetime.timedelta(seconds=59))
+ endTime = endTime.strip().split(".")[0]
+ else:
+ startTime = startDate + " " + startTime
+ endTime = endDate + ' ' + endTime
+
+ if broadCastMsg == '' or endTime == '' or startTime == '':
+ return GMCommon.Def_ParamErr
+
+ # 删除之前的存储的广播
+ if isDelOthers:
+ DelAllBroadCast()
+
+ startDate = GameWorld.GetDateTimeByFormatStr(startTime, ChConfig.TYPE_Time_Format)
+ endDate = GameWorld.GetDateTimeByFormatStr(endTime, ChConfig.TYPE_Time_Format)
+ dateTime = GameWorld.GetServerTime()
+
+ # 判断时间是否正确
+ if CheckDate(startDate, endDate) or CheckDate(dateTime, endDate):
+ return GMCommon.Def_InvalidTime
+
+ startTime = GameWorld.ChangeTimeStrToNum(startTime)
+ endTime = GameWorld.ChangeTimeStrToNum(endTime)
+
+ # 发送消息
+ SetBroadCastInfo(startTime, endTime, interval, broadCastMsg, isDelOthers)
+
+ # 流向
+ DataRecordPack.DR_ToolGMOperate(0, '', '', 'GMT_BroadCast', str(gmCmdDict))
+ return GMCommon.Def_Success
+
+def CheckDate(startDate, endDate):
+ ## 判断时间是否错误
+
+ if not startDate or not endDate:
+ return False
+
+ if (endDate - startDate).days < 0:
+ return True
+
+ return False
+
+def DelAllBroadCast():
+ ## 删除之前的存储的广播
+ PyGameData.g_broadCastList = []
+ return
+
+def SetBroadCastInfo(startTime, endTime, interval, msg, isDelOthers):
+ ## 添加广播
+
+ PyGameData.g_broadCastList.append([startTime, endTime, interval, msg])
+ if len(PyGameData.g_broadCastList) > Def_MaxBroadCast:
+ PyGameData.g_broadCastList = PyGameData.g_broadCastList[-Def_MaxBroadCast:]
+
+ # 广播在线玩家
+ NetPackCommon.SendFackPackOnline(GetBroadPack(startTime, endTime, interval, msg, isDelOthers))
+ return
+
+def OnPlayerLogin(curPlayer):
+
+ if PyGameData.g_broadCastList == []:
+ return
+
+ # 判断时间或还剩余的广播
+ tempList = []
+
+ curTime = GameWorld.GetServerTime()
+ for msgInfo in PyGameData.g_broadCastList:
+ startTime, endTime, interval, msg = msgInfo
+
+ dateTime = GameWorld.ChangeTimeNumToDatetime(endTime)
+
+ if (dateTime - curTime).days < 0:
+ continue
+
+ # 需要存储的广播
+ tempList.append(msgInfo)
+
+ # 通知客户端,广播内容
+ NetPackCommon.SendFakePack(curPlayer, GetBroadPack(startTime, endTime, interval, msg))
+
+ # 更新广播列表
+ PyGameData.g_broadCastList = tempList[:]
+ return
+
+def GetBroadPack(startTime, endTime, interval, msg, isDelOthers=False):
+ packData = ChPyNetSendPack.tagBroadCastInfo()
+ packData.Clear()
+ packData.IsDelOthers = isDelOthers
+ packData.StartTime = startTime
+ packData.EndTime = endTime
+ packData.Interval = interval
+ packData.Msg = msg
+ packData.MsgLen = len(msg)
+ return packData
--
Gitblit v1.8.0