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.
209 lines
9.7 KiB
209 lines
9.7 KiB
using System.Collections.Generic;
|
|
using Sog;
|
|
|
|
namespace SMCenter
|
|
{
|
|
public static class CmdProcFactory
|
|
{
|
|
private static readonly int StartSeq = 1629962662;
|
|
|
|
private static int m_lastSeqNum;
|
|
|
|
public static Dictionary<string , BaseCmdProc> helpCmdInfo;
|
|
|
|
public static void Init()
|
|
{
|
|
m_lastSeqNum = (int)AppTime.ServerAppTime.GetTimeSecond() - StartSeq;
|
|
|
|
helpCmdInfo = new Dictionary<string, BaseCmdProc>();
|
|
|
|
BaseCmdProc proc = new DontTransAgentCmdProc();
|
|
proc.m_explainCmd = string.Format("help [cmd]: 获取指令帮助信息(可查看具体的命令帮助) \n");
|
|
proc.m_needCheckValidServerId = false;
|
|
helpCmdInfo.Add("help", proc);
|
|
|
|
proc = new CommCmdProc();
|
|
proc.m_explainCmd = string.Format("start [worldId].[apptype].[instId]: 开启指定游戏服务器进程,*为通配符 \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("start", proc);
|
|
proc = new CommCmdProc();
|
|
proc.m_explainCmd = string.Format("stop [worldId].[apptype].[instId]: 停止指定的游戏服务器进程 \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("stop", proc);
|
|
proc = new CommCmdProc();
|
|
proc.m_explainCmd = string.Format("kill [worldId].[apptype].[instId]: 停止指定的游戏服务器进程 \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("kill", proc);
|
|
proc = new CommCmdProc();
|
|
proc.m_explainCmd = string.Format("check [worldId].[apptype].[instId]: 检查指定的游戏服务器进程运行状态 \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("check", proc);
|
|
proc = new CommCmdProc();
|
|
proc.m_explainCmd = string.Format("hotfix [worldId].[apptype].[instId]: 重新加载指定的游戏服务器进程 \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("hotfix", proc);
|
|
proc = new CommCmdProc();
|
|
proc.m_explainCmd = string.Format("reloadconfig [worldId].[apptype].[instId]: 重新加载指定的游戏服务器配置文件 \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("reloadconfig", proc);
|
|
proc = new CommCmdProc();
|
|
proc.m_explainCmd = string.Format("reloadcluster [worldId].[apptype].[instId]: 重新加载游戏服务cluster管道文件 \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("reloadcluster", proc);
|
|
proc = new CommCmdProc();
|
|
proc.m_explainCmd = string.Format("gmcmd [worldId].[apptype].[instId] [attribute] [addnum] -t [uid]: GM管理指令 attribute操作的指令或属性, addnum 增加的数值, uid 玩家ID\n");
|
|
proc.m_explainCmd += string.Format("gmcmd [worldId].[apptype].[instId] [attribute] -b [base64编码]: GM管理指令 将[addnum] -t [uid]编码后获得 \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("gmcmd", proc);
|
|
proc = new CommCmdProc();
|
|
proc.m_explainCmd = string.Format("list [hostname]: 列出指定主机上的服务器进程,* 通配符列出所有 \n");
|
|
proc.m_needCheckValidServerId = false;
|
|
helpCmdInfo.Add("list", proc);
|
|
|
|
proc = new DontTransAgentCmdProc();
|
|
proc.m_explainCmd = string.Format("listhost : 查看所有的主机 \n");
|
|
proc.m_needCheckValidServerId = false;
|
|
helpCmdInfo.Add("listhost", proc);
|
|
proc = new DontTransAgentCmdProc();
|
|
proc.m_explainCmd = string.Format("disable [worldId].[apptype].[instId]: 屏蔽指定的服务器,后期指令对屏蔽的服务器无效 \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("disable", proc);
|
|
proc = new DontTransAgentCmdProc();
|
|
proc.m_explainCmd = string.Format("enable [worldId].[apptype].[instId]: 取消屏蔽指定的服务器 \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("enable", proc);
|
|
proc = new DontTransAgentCmdProc();
|
|
proc.m_explainCmd = string.Format("enter_agent_shell [HostName]: 进入指定Agent的Shell,* 为所有Agent \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("enter_agent_shell", proc);
|
|
|
|
proc = new FileTransCmdProc();
|
|
proc.m_explainCmd = string.Format("push [worldId].[apptype].[instId] -r [src] [dst]: 向指定的服务器传输文件 -r表示递归,支持绝对路径,相对路径以运行时目录为当前目录 \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("push", proc);
|
|
proc = new FileTransCmdProc();
|
|
proc.m_explainCmd = string.Format("pushcfg [worldId].[apptype].[instId]: 向指定服务器推送配置指定目录文件 \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("pushcfg", proc);
|
|
proc = new FileTransCmdProc();
|
|
proc.m_explainCmd = string.Format("pushbin [worldId].[apptype].[instId]: 向指定服务器推送dll,pdb文件 \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("pushbin", proc);
|
|
proc = new FileTransCmdProc();
|
|
proc.m_explainCmd = string.Format("pushagent [worldId].[apptype].[instId]: 向指定服务器推送SMAgent \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("pushagent", proc);
|
|
proc = new FileTransCmdProc();
|
|
proc.m_explainCmd = string.Format("pushsh [worldId].[apptype].[instId]: 向指定服务器推送sh文件 \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("pushsh", proc);
|
|
proc = new FileTransCmdProc();
|
|
proc.m_explainCmd = string.Format("cancelpush : 取消所有的文件推送(有文件传输时才有效) \n");
|
|
proc.m_needCheckValidServerId = false;
|
|
helpCmdInfo.Add("cancelpush", proc);
|
|
|
|
proc = new FilePullCmdProc();
|
|
proc.m_explainCmd = string.Format("pull [worldId].[apptype].[instId] -r [src] [dst]: 向指定的服务器请求文件 -r表示递归,支持绝对路径,相对路径以运行时目录为当前目录 \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("pull", proc);
|
|
|
|
proc = new FilePullCmdProc();
|
|
proc.m_explainCmd = string.Format("pullagentlog [worldId].[apptype].[instId]: 获取指定Agent的log \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("pullagentlog", proc);
|
|
|
|
proc = new FilePullCmdProc();
|
|
proc.m_explainCmd = string.Format("cancelpull : 取消所有的文件获取(有文件传输时才有效) \n");
|
|
proc.m_needCheckValidServerId = false;
|
|
helpCmdInfo.Add("cancelpull", proc);
|
|
|
|
proc = new UpdateAgentCmdProc();
|
|
proc.m_explainCmd = string.Format("updateagent : 更新所有的已经注册的Agent \n");
|
|
proc.m_needCheckValidServerId = false;
|
|
helpCmdInfo.Add("updateagent", proc);
|
|
|
|
proc = new CheckAgentCmdProc();
|
|
proc.m_explainCmd = string.Format("checkagent [HostName]: 检测指定的agent dll pdb文件是否一致(*为通配符,检测所有) \n");
|
|
proc.m_needCheckValidServerId = false;
|
|
helpCmdInfo.Add("checkagent", proc);
|
|
|
|
proc = new CheckAgentCmdProc();
|
|
proc.m_explainCmd = string.Format("checkpushfile [worldId].[apptype].[instId] : 检测指定的agent push文件是否一致 \n");
|
|
proc.m_needCheckValidServerId = false;
|
|
helpCmdInfo.Add("checkpushfile", proc);
|
|
|
|
proc = new CheckAgentCmdProc();
|
|
proc.m_explainCmd = string.Format("checkagentmem [HostName] : 检测指定的agent 的内存情况(尤其时传输文件后) \n");
|
|
proc.m_needCheckValidServerId = false;
|
|
helpCmdInfo.Add("checkagentmem", proc);
|
|
|
|
|
|
proc = new ShellCmdProc();
|
|
proc.m_explainCmd = string.Format("shell [worldId].[apptype].[instId] [Win or unix CMD]:在指定的服务器上执行shell指令 \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("shell", proc);
|
|
proc = new ShellCmdProc();
|
|
proc.m_explainCmd = string.Format("cancelshell [worldId].[apptype].[instId]: 取消指定的服务器上正在执行的shell指令 \n");
|
|
proc.m_needCheckValidServerId = true;
|
|
helpCmdInfo.Add("cancelshell", proc);
|
|
}
|
|
|
|
public static CmdInfo GetCmdInfo(string command)
|
|
{
|
|
string[] split = command.Split(' ');
|
|
if (split == null || split.Length < 1)
|
|
{
|
|
TraceLog.Error("CmdProcFactory.GetCmdInfo invalid CMD {0}", command);
|
|
return null;
|
|
}
|
|
|
|
string cmd = split[0].Trim().ToLower();
|
|
if (string.IsNullOrEmpty(cmd))
|
|
{
|
|
TraceLog.Error("CmdProcFactory.GetCmdInfo CMD is null");
|
|
return null;
|
|
}
|
|
|
|
var newCmd = new CmdInfo
|
|
{
|
|
SeqNum = ++m_lastSeqNum,
|
|
ConsoleInput = command,
|
|
CMD = cmd,
|
|
CreateTime = SMCenterUtils.GetTimeSecond(),
|
|
};
|
|
|
|
for (int i = 1; i < split.Length; i++)
|
|
{
|
|
newCmd.CmdParams.Add(split[i]);
|
|
}
|
|
|
|
//防止异常
|
|
if (split.Length == 1)
|
|
{
|
|
newCmd.CmdParams.Add("");
|
|
}
|
|
|
|
return newCmd;
|
|
}
|
|
|
|
|
|
public static BaseCmdProc GetCmdProc(CmdInfo cmdInfo)
|
|
{
|
|
if (cmdInfo == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
string lowerCmd = cmdInfo.CMD;
|
|
if(helpCmdInfo.ContainsKey(lowerCmd))
|
|
{
|
|
//以防万一,还是加上个清理数据的
|
|
helpCmdInfo[lowerCmd].ClearData();
|
|
helpCmdInfo[lowerCmd].InitCmd(cmdInfo);
|
|
return helpCmdInfo[lowerCmd];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|