public override void ExecuteCommand(ShellCommandInfo commandInfo) { try { if (!base.Client.IsConnected) { IPEndPoint endPoint = null; if (commandInfo.Parameters.Length == 2) { endPoint = new IPEndPoint(IPAddress.Parse(commandInfo[0]), int.Parse(commandInfo[1])); } else { endPoint = new IPEndPoint(IPAddress.Parse(AppConfig.ServerHost), AppConfig.ServerPort); } base.Client.ConnectAsync(endPoint).Wait(); } else { ConsoleLogger.Warn("client already connectd " + base.Client.RemoteEndPoint.ToString()); } } catch (Exception e) { ConsoleLogger.ErrorFormat("{0} --> {1} {2}", base.Name, DateTime.Now, e); } }
public override void ExecuteCommand(ShellCommandInfo commandInfo) { try { if (base.Client.IsConnected) { int count = 10; if (commandInfo.Parameters.Length > 0 && !int.TryParse(commandInfo[0], out count)) { ConsoleLogger.ErrorFormat("command '{0}' invalid", base.Name); } else { base.Client.Send(CommandCodes.LISTCLIENT, BitConverter.GetBytes(count).Reverse().ToArray()); } } else { ConsoleLogger.Warn("client not connectd to the server"); } } catch (Exception e) { ConsoleLogger.ErrorFormat("{0} --> {1} {2}", base.Name, DateTime.Now, e); } }
public override void ExecuteCommand(ShellCommandInfo commandInfo) { var sessions = base.Server.GetSessions(i => i.Logged); ConsoleLogger.InfoFormat("{0} total {1} will be receiving '{2}' mission", DateTime.Now, base.Server.SessionCount, base.Name); if (sessions.Count() > 0) { var body = Guid.NewGuid().ToByteArray(); foreach (var sess in sessions) { sess.Send(CommandCodes.BACKUP, body); } } }
public override void ExecuteCommand(ShellCommandInfo commandInfo) { int count = 10; if (commandInfo.Parameters.Length > 0 && !int.TryParse(commandInfo[0], out count)) { ConsoleLogger.ErrorFormat("command '{0}' invalid", base.Name); } else { ConsoleLogger.InfoFormat("Total {0} sessions Online", base.Server.SessionCount); foreach (var s in base.Server.GetAllSessions().OrderBy(i => i.LastActiveTime).Take(count)) { ConsoleLogger.InfoFormat("{0} {1} [{2}] {3} {4}", s.SessionID, s.RemoteEndPoint, s.UserName, s.StartTime, s.LastActiveTime); } } }
public override void ExecuteCommand(ShellCommandInfo commandInfo) { int count = 10; if (commandInfo.Parameters.Length > 0 && !int.TryParse(commandInfo[0], out count)) { ConsoleLogger.ErrorFormat("command '{0}' invalid", base.Name); } else { var users = UserProvider.GetLoggedUserList(); ConsoleLogger.InfoFormat("Total {0} Users Logged", users.Count()); foreach (var u in users.OrderBy(i => i.LoggedTime).Take(count)) { ConsoleLogger.InfoFormat("{0} {1} {2}", u.UserName, u.RemoteEndPoint, u.LoggedTime); } } }
public override void ExecuteCommand(ShellCommandInfo commandInfo) { string file = commandInfo.Parameters.Length > 0 ? commandInfo[0] : ""; if (file == "") { ConsoleLogger.ErrorFormat("command '{0}' invalid", base.Name); } else { if (File.Exists(file)) { var sessions = Server.GetSessions(i => i.Logged && !i.IsAdministrator); ConsoleLogger.InfoFormat("{0} total {1} clients will be receiving file '{2}'", DateTime.Now, base.Server.SessionCount, file); if (sessions.Count() > 0) { var fi = new FileInfo(file); using (var fs = fi.OpenRead()) { var ms = new MemoryStream(); fs.CopyTo(ms); var info = new SendFileInfo { FileBytes = ms.ToArray(), Name = fi.Name, FileId = Guid.NewGuid().ToString(), Length = fi.Length, CreateTime = DateTime.Now }; info.SHA = HashAlgorithmProvider.ComputeHash(HashAlgorithmType.SHA1, info.FileBytes, true); fs.Close(); ms.Close(); foreach (var sess in sessions) { sess.SendFile(info); } } } } else { ConsoleLogger.WarnFormat("file '{0}' not found", file); } } }
public override void ExecuteCommand(ShellCommandInfo commandInfo) { string file = commandInfo.Parameters.Length > 0 ? commandInfo[0] : ""; if (file == "") { ConsoleLogger.ErrorFormat("command '{0}' invalid", base.Name); } else { if (base.Client.IsConnected) { if (File.Exists(file)) { var fi = new FileInfo(file); using (var fs = fi.OpenRead()) { var ms = new MemoryStream(); fs.CopyTo(ms); var info = new SendFileInfo { FileBytes = ms.ToArray(), Name = fi.Name, FileId = Guid.NewGuid().ToString(), Length = fi.Length, CreateTime = DateTime.Now }; info.SHA = HashAlgorithmProvider.ComputeHash(HashAlgorithmType.SHA1, info.FileBytes, true); fs.Close(); ms.Close(); base.Client.TransferFile(info); } } else { ConsoleLogger.WarnFormat("file '{0}' not found", file); } } else { ConsoleLogger.Warn("client not connected to the server"); } } }
public override void ExecuteCommand(ShellCommandInfo commandInfo) { try { if (base.Client.IsConnected) { base.Client.Send(CommandCodes.PING, BitConverter.GetBytes(DateTimeExtension.CurrentTimestamp) .Reverse().ToArray()); } else { ConsoleLogger.Warn("client not connectd to the server"); } } catch (Exception e) { ConsoleLogger.ErrorFormat("{0} --> {1} {2}", base.Name, DateTime.Now, e); } }
public override void ExecuteCommand(ShellCommandInfo commandInfo) { try { if (base.Client.IsConnected) { base.Client.StopAutoRestoreConnection(); base.Client.Close(); } else { ConsoleLogger.Warn("client not connected to the server"); } } catch (Exception e) { ConsoleLogger.ErrorFormat("{0} --> {1} {2}", base.Name, DateTime.Now, e); } }
public override void ExecuteCommand(ShellCommandInfo commandInfo) { string what = commandInfo.Parameters.Length > 0 ? commandInfo[0] : ""; if (what == "") { ConsoleLogger.ErrorFormat("command '{0}' invalid", base.Name); } else { var session = base.Server.GetSessionByID(commandInfo[0]); if (session != null) { session.Close(); } else { ConsoleLogger.WarnFormat("session '{0}' not found", commandInfo[0]); } } }
public override void ExecuteCommand(ShellCommandInfo commandInfo) { string what = commandInfo.Parameters.Length > 0 ? commandInfo[0] : ""; if (what == "") { ConsoleLogger.ErrorFormat("command '{0}' invalid", base.Name); } else { var session = base.Server.GetSessionByID(commandInfo[0]); if (session != null) { session.Send(CommandCodes.PING, BitConverter.GetBytes(DateTimeExtension.CurrentTimestamp) .Reverse().ToArray()); } else { ConsoleLogger.WarnFormat("session '{0}' not found", commandInfo[0]); } } }
public ShellCommandInfo GetCommandInfo(string line) { ShellCommandInfo commandInfo = null; if (!string.IsNullOrEmpty(line)) { line = line.ToLower(); var cmds = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (cmds.Length <= 1) { commandInfo = new ShellCommandInfo(cmds[0]); } else { string body = line.Substring(cmds[0].Length); //判断是否有引号包含的字符串 if (body.Contains("\"")) { var parameters = new List<string>(); foreach (var b in body.Split(new string[] { "\"" }, StringSplitOptions.RemoveEmptyEntries)) { if (!string.IsNullOrWhiteSpace(b)) { parameters.Add(b.Trim(' ')); } } commandInfo = new ShellCommandInfo(cmds[0], parameters.ToArray()); } else { var parameters = new string[cmds.Length - 1]; Array.Copy(cmds, 1, parameters, 0, parameters.Length); commandInfo = new ShellCommandInfo(cmds[0], parameters); } } } return commandInfo; }
public abstract void ExecuteCommand(ShellCommandInfo commandInfo);