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.
173 lines
5.0 KiB
173 lines
5.0 KiB
using System.Linq;
|
|
using Sog;
|
|
|
|
namespace SMCenter
|
|
{
|
|
// 通用命令处理
|
|
public class DontTransAgentCmdProc : BaseCmdProc
|
|
{
|
|
public override void ClearData()
|
|
{
|
|
m_nowCmd = null;
|
|
}
|
|
|
|
// cmdParams[0] is serverId
|
|
public override int DoCmd(out string msg)
|
|
{
|
|
string lowerCMD = m_nowCmd.CMD;
|
|
|
|
// 如果最后输入的参数是\tab, console会立刻发包给center, center在把支持的命令补全后发回console
|
|
if (m_nowCmd.CmdParams[m_nowCmd.CmdParams.Count - 1] == "#tab")
|
|
{
|
|
msg = string.Empty;
|
|
|
|
// 这个for是不是写错了? list host push #tab 转换成 list 3 3 ?
|
|
for (int i = 0; i < m_nowCmd.CmdParams.Count - 1; i++)
|
|
{
|
|
lowerCMD += " " + m_nowCmd.CmdParams.Count;
|
|
}
|
|
|
|
foreach (var infocmd in CmdProcFactory.helpCmdInfo.Keys)
|
|
{
|
|
if (infocmd.StartsWith(lowerCMD))
|
|
{
|
|
msg += infocmd + " ";
|
|
}
|
|
}
|
|
|
|
// history在console本地处理, 没有注册到center的cmdfactory, 这里单独处理补全
|
|
if ("history".StartsWith(lowerCMD))
|
|
{
|
|
msg += "history";
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
if (lowerCMD == "listhost")
|
|
{
|
|
msg = "";
|
|
var agents = SMCenterNet.Instance.GetAllAgent();
|
|
foreach (ClientInfo app in agents)
|
|
{
|
|
msg += string.Format("\t HostName:\"{0}\"\n", app.HostName);
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
if (lowerCMD == "help")
|
|
{
|
|
msg = string.Empty;
|
|
foreach (var infocmd in CmdProcFactory.helpCmdInfo.Values)
|
|
{
|
|
if (string.IsNullOrEmpty(m_nowCmd.CmdParams[0]) == false)
|
|
{
|
|
if (infocmd.m_explainCmd.Contains(m_nowCmd.CmdParams[0]))
|
|
{
|
|
msg += infocmd.m_explainCmd;
|
|
msg += "\n";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
msg += infocmd.m_explainCmd;
|
|
msg += "\n";
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
if (lowerCMD == "enter_agent_shell")
|
|
{
|
|
var agents = SMCenterNet.Instance.GetAllAgent();
|
|
if (m_nowCmd.CmdParams[0] == "*")
|
|
{
|
|
ConsoleCmd.Instance.m_EnterAgent = agents;
|
|
ConsoleCmd.Instance.m_nowCmdModel = "allAgent Shell >";
|
|
msg = ConsoleCmd.Instance.m_nowCmdModel + "#success";
|
|
}
|
|
else if (agents.Find(p => p.HostName == m_nowCmd.CmdParams[0]) != null)
|
|
{
|
|
ConsoleCmd.Instance.m_EnterAgent = agents.Where(p => p.HostName == m_nowCmd.CmdParams[0]).ToList();
|
|
ConsoleCmd.Instance.m_nowCmdModel = m_nowCmd.CmdParams[0] + " Shell >";
|
|
msg = ConsoleCmd.Instance.m_nowCmdModel + "#success";
|
|
}
|
|
else
|
|
{
|
|
msg = "Enter " + m_nowCmd.CmdParams[0] + " Agent Fail";
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
if (m_nowCmd.CmdParams.Count < 1)
|
|
{
|
|
msg = "invalid cmd param";
|
|
return -1;
|
|
}
|
|
|
|
if (CmdUtils.CheckValidServerId(m_nowCmd.CmdParams[0], out string fixSvrId) == false)
|
|
{
|
|
msg = "invalid server id";
|
|
return -1;
|
|
}
|
|
|
|
if (fixSvrId != null)
|
|
{
|
|
m_nowCmd.CmdParams[0] = fixSvrId;
|
|
}
|
|
|
|
//这些是比较特殊的,不需要转达给agent(先这样)
|
|
if (lowerCMD == "disable")
|
|
{
|
|
msg = "Set Disable Sucess";
|
|
if (SMProcAppMgr.Instance.m_currHandleClient == null)
|
|
{
|
|
msg = "Set Disable Fail";
|
|
}
|
|
|
|
if(SMProcAppMgr.Instance.m_currHandleClient.m_disableServerID.Contains(m_nowCmd.CmdParams[0]))
|
|
{
|
|
msg = string.Format("disable list already have {0}", m_nowCmd.CmdParams[0]);
|
|
}
|
|
else
|
|
{
|
|
SMProcAppMgr.Instance.m_currHandleClient.m_disableServerID.Add(m_nowCmd.CmdParams[0]);
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
if (lowerCMD == "enable")
|
|
{
|
|
msg = "Set Enable Sucess";
|
|
if (SMProcAppMgr.Instance.m_currHandleClient == null)
|
|
{
|
|
msg = "Set Enable Fail";
|
|
return -1;
|
|
}
|
|
|
|
if(SMProcAppMgr.Instance.m_currHandleClient.m_disableServerID.Contains(m_nowCmd.CmdParams[0]))
|
|
{
|
|
SMProcAppMgr.Instance.m_currHandleClient.m_disableServerID.Remove(m_nowCmd.CmdParams[0]);
|
|
}
|
|
else
|
|
{
|
|
msg = string.Format("disable list not find {0}", m_nowCmd.CmdParams[0]);
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
msg = m_nowCmd.ConsoleInput + " begin ...";
|
|
TraceLog.Trace("DontTransAgentCmdProc.DoCmd {0}", msg);
|
|
return -1;
|
|
}
|
|
|
|
public override int UpdateCmd(long tMs)
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|