You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
190 lines
6.2 KiB
190 lines
6.2 KiB
/*
|
|
Sog 游戏基础库
|
|
2016 by zouwei
|
|
*/
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.IO;
|
|
|
|
using Sog;
|
|
using ProtoCSStruct;
|
|
using Sog.IO;
|
|
|
|
namespace Chat
|
|
{
|
|
public class GmCmdSvc : BaseReloadableService
|
|
{
|
|
public override int GetServiceType()
|
|
{
|
|
return ChatServiceType.GmCmdSvc;
|
|
}
|
|
|
|
//销毁的时候清空指令注册
|
|
public override void Dispose()
|
|
{
|
|
GmCommandMgr.Instance.ClearAll();
|
|
}
|
|
|
|
//构造的时候注册所有指令
|
|
public GmCmdSvc()
|
|
{
|
|
RegisterAllGmCmd();
|
|
}
|
|
|
|
private void RegisterAllGmCmd()
|
|
{
|
|
//测试发送聊天
|
|
GmCommandMgr.Instance.Register("TestSendChat", "TestSendChat", this.TestSendChat, GMBroadCastType.GMBroadCastType_MustBroad);
|
|
|
|
GmCommandMgr.Instance.Register("ReloadNotice", "ReloadNotice id", this.ReloadNotice);
|
|
GmCommandMgr.Instance.Register("ReloadNoticeLamp", "ReloadNoticeLamp id [params...]", this.ReloadNoticeLamp);
|
|
|
|
GmCommandMgr.Instance.Register("ReloadAllNotice", "ReloadAllNotice NOT params", this.ReloadNoticeLamp);
|
|
|
|
GmCommandMgr.Instance.Register("SendNoticeLamp", "SendNoticeLamp [content] [showcount] [ShowInterval]", this.SendNoticeLamp/*, GMBroadCastType.GMBroadCastType_MustBroad*/);
|
|
//注册广播事件(暂时只开一个chatServer,就不需要广播了)
|
|
//GmCommandMgr.Instance.NotifyWorldBroadCastGMCmdToServer = NotifyWorldBroadCastGMCmdToServer;
|
|
|
|
GmCommandMgr.Instance.Register("ClearChatCache", "ClearChatCache", this.ClearChatCache);
|
|
}
|
|
|
|
//广播来的指令
|
|
public static void OnWorldNotifyDealGmCmd(StructPacket packet)
|
|
{
|
|
ref SSNotifyServerDealGMCmd gmCmd = ref packet.GetMessage<SSNotifyServerDealGMCmd>();
|
|
string[] splitStr = gmCmd.CmdParams.GetString().Split(' ');
|
|
GmCommandMgr.Instance.HandlerGmCommand(gmCmd.GmCmd.GetString(), gmCmd.UserId, splitStr, false);
|
|
}
|
|
|
|
private int TestSendChat(long userid, string[] cmdParams)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
|
|
public int ReloadNotice(long userid, string[] cmdParams)
|
|
{
|
|
if (cmdParams.Length < 1)
|
|
{
|
|
TraceLog.Error("GmCmdSvc.ReloadNotice invalid param,need id");
|
|
return -1;
|
|
}
|
|
|
|
uint id = 0;
|
|
uint.TryParse(cmdParams[0], out id);
|
|
|
|
if (id == 0)
|
|
{
|
|
TraceLog.Error("GmCmdSvc.ReloadNotice invalid id param {0}", cmdParams[0]);
|
|
return -3;
|
|
}
|
|
|
|
|
|
//SysNoticeSvc.ReloadByID(id);
|
|
|
|
return 0;
|
|
}
|
|
public int ReloadAllNotice(long userid, string[] cmdParams)
|
|
{
|
|
|
|
return 0;
|
|
}
|
|
public int ReloadNoticeLamp(long userid, string[] cmdParams)
|
|
{
|
|
if (cmdParams.Length < 1)
|
|
{
|
|
TraceLog.Error("GmCmdSvc.ReloadNoticeLamp invalid param,need id");
|
|
return -1;
|
|
}
|
|
|
|
uint id = 0;
|
|
uint.TryParse(cmdParams[0], out id);
|
|
if (id == 0)
|
|
{
|
|
TraceLog.Error("GmCmdSvc.ReloadNoticeLamp invalid id param {0}", cmdParams[0]);
|
|
return -3;
|
|
}
|
|
|
|
string[] reloadParam = null;
|
|
if (cmdParams.Length > 1)
|
|
{
|
|
reloadParam = new string[cmdParams.Length - 1];
|
|
|
|
for (int i = 0; i < reloadParam.Length; i++)
|
|
{
|
|
reloadParam[i] = cmdParams[i + 1];
|
|
}
|
|
}
|
|
|
|
|
|
//SysNoticeLampUtils.ReloadSysNoticeLampByID(id, reloadParam);
|
|
|
|
return 0;
|
|
}
|
|
|
|
public int SendNoticeLamp(long userid, string[] cmdParams)
|
|
{
|
|
if (cmdParams.Length < 1)
|
|
{
|
|
TraceLog.Error("GmCmdSvc.SendNoticeLamp invalid param,need content");
|
|
return -1;
|
|
}
|
|
|
|
int showCount = 0;
|
|
int showInterval = 0;
|
|
if (cmdParams.Length == 3)
|
|
{
|
|
int.TryParse(cmdParams[1], out showCount);
|
|
int.TryParse(cmdParams[2], out showInterval);
|
|
}
|
|
|
|
TraceLog.Debug("GmCmdSvc.SendNoticeLamp content {0}", cmdParams[0]);
|
|
//SysNoticeLampUtils.OnGmCmdNoticeLamp(cmdParams[0], showCount > 0 ? showCount : 1, showInterval > 0 ? showInterval : 30);
|
|
return 0;
|
|
}
|
|
|
|
//如果是需要广播的,通知下world进行广播
|
|
public void NotifyWorldBroadCastGMCmdToServer(long userId, string gmCmd, string cmdParams)
|
|
{
|
|
SSNotifyWorldBroadCastGMCmd notify = new SSNotifyWorldBroadCastGMCmd();
|
|
notify.UserId = userId;
|
|
notify.GmCmd.SetString(gmCmd);
|
|
notify.CmdParams.SetString(cmdParams);
|
|
notify.OnlyBroadCastSpec = userId > 0; //如果到了这里,userId又大于0 则是需要指定广播了
|
|
ChatServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.NotifyworldBroadcastgmcmd, ref notify, 0, 0);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 清理公会信息缓存
|
|
/// </summary>
|
|
/// <param name="userid"></param>
|
|
/// <param name="cmdParams"></param>
|
|
/// <returns></returns>
|
|
public int ClearChatCache(long userid, string[] cmdParams)
|
|
{
|
|
//白名单id 10000
|
|
if (userid != 10000)
|
|
{
|
|
TraceLog.Error("GmCmdSvc.ClearChatCache write id error! uid:{0}", userid);
|
|
return -1;
|
|
}
|
|
TraceLog.Trace("GmCmdSvc.ClearChatCache clear chat cache cmdParams:{0}!", cmdParams[0]);
|
|
|
|
ref var chatCache = ref ChatServerUtils.GetChatServerData().m_chatCacheInfo;
|
|
chatCache.m_needSave = true;
|
|
chatCache.m_channalCacheMap.Clear();
|
|
var total = chatCache.m_cacheStrutChatReq.GetTotalCount();
|
|
chatCache.m_cacheStrutChatReq = new StructMemoryCache<ChatCacheDataStruct>(total);
|
|
string saveFile = ChatCacheOp.GetSaveFilePath();
|
|
if (File.Exists(saveFile))
|
|
{
|
|
File.Delete(saveFile);
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|