public ErrorCode Start() { this._heartBeater.Start(Consts.HEART_BEAT_INTERVAL, this.OnHeartBeat); this.netSessionMgr.CreateListener(0, 65535, ProtoType.TCP, null, this.netSessionMgr.CreateLSSession).Start(this.config.lsPort); this.netSessionMgr.CreateListener(1, 65535, ProtoType.TCP, null, this.netSessionMgr.CreateGSSession).Start(this.config.gsPort); this.netSessionMgr.CreateListener(2, 65535, ProtoType.TCP, null, this.netSessionMgr.CreateBSSession).Start(this.config.bsPort); IListener shellListener = this.netSessionMgr.CreateListener(3, 65535, ProtoType.TCP, null, this.netSessionMgr.CreateShellSession); shellListener.Start(this.config.shellPort); ShellSession.key = "C01B0BAE-4948-4F02-9F45-BC371274C295"; shellListener.OnSessionCreated += session => { ShellSession ss = ( ShellSession )session; ss.shellCommandHandler = cmd => { string s = string.Empty; #if !DISABLE_LUA object[] result = this._luaEnv.DoString($"return {cmd}"); if (result != null) { for (int i = 0; i < result.Length; i++) { s += result[i] == null ? "nil" : result[i].ToString(); } } #endif return(s); }; }; this.netSessionMgr.CreateConnector <L2DBSession>(SessionType.ServerC2DB, this.config.dbIP, this.config.dbPort, ProtoType.TCP, 20480, 0); this.redisWrapper.Connect(this.config.redisIP, this.config.redisPort, this.config.redisPwd); return(ErrorCode.Success); }
public INetSession CreateShellSession(ProtoType type, X509Certificate2 certificate) { ShellSession session = NetSessionPool.instance.Pop <ShellSession>(type, certificate); session.owner = this; session.type = SessionType.Shell; return(session); }
public static bool Logout(string username) { if (RoleAction.Session.TryGetValue(username, out string id)) { var _session = ShellSession.GetSession(id); _session.Clear(); RoleAction.Session.Remove(username.ToLower()); return(true); } return(false); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { #region 自定义Session 这里使用了长连接,接入了其他服务,改成可以直接独立运行的版本。 //ShellSession.InitSession<RedisSession>(); //services.AddDiySession(c => //{ // c.GetDiySession<RedisSession>(); //}); //services.AddObject(TcpFrame.CreateServer(AppSettings.Get("ServerIp"), 888)); #endregion #region 自定义Session 独立运行版本,0.0.1 ShellSession.InitSession <CacheSession>(); services.AddDiySession(c => { c.GetDiySession <CacheSession>(); }); CacheSession.StartKeep(1); // 每秒一次自检测 #endregion services.AddResponseCompression(); services.AddAshx(o => { //o.IsAsync = true; o.JsonOptions = new()// System.Text.Json.JsonSerializerOptions(System.Text.Json.JsonSerializerDefaults.Web) { //IgnoreReadOnlyFields = true, Encoder = System.Text.Encodings.Web.JavaScriptEncoder.Create(System.Text.Unicode.UnicodeRanges.All), }; //o.JsonOptions.Converters.Add(JsonConverterHelper.GetDateConverter()); o.JsonOptions.Converters.Add(JsonConverterHelper.GetDBNullConverter()); });//注册api。 //.AddHttpContext();//注册静态方式的HttpContext对象获取。 services.AddObject(new UpLoad());//上传有关配置注册 }
public static bool IsRepeatLogin(string BaseName) { if (RoleAction.Session.TryGetValue(BaseName, out string id)) { var _session = ShellSession.GetSession(id); //new RedisSession() { SpareId = id }; var keys = _session.GetKeys(); //.Contains("Admin"); if (keys.Contains("Admin")) { if (!IsQiangden) { return(false); } _session.Clear(); } RoleAction.Session.Remove(BaseName.ToLower()); return(true); } return(true); }
public ErrorCode Start() { this._heartBeater.Start(Consts.HEART_BEAT_INTERVAL, this.OnHeartBeat); X509Certificate2 certificate = new X509Certificate2(this.config.certPath, this.config.certPass); IListener cliListener = this.netSessionMgr.CreateListener(0, 65535, ProtoType.WebSocket, certificate, this.netSessionMgr.CreateClientSession); cliListener.Start(this.config.externalPort); IListener shellListener = this.netSessionMgr.CreateListener(1, 65535, ProtoType.TCP, null, this.netSessionMgr.CreateShellSession); shellListener.Start(this.config.shellPort); ShellSession.key = "88F77D88-8C5A-4FE7-B099-68088A27C8DE"; shellListener.OnSessionCreated += session => { ShellSession ss = ( ShellSession )session; ss.shellCommandHandler = cmd => { string s = string.Empty; #if !DISABLE_LUA object[] result = this._luaEnv.DoString($"return {cmd}"); if (result != null) { for (int i = 0; i < result.Length; i++) { s += result[i] == null ? "nil" : result[i].ToString(); } } #endif return(s); }; }; this.netSessionMgr.CreateConnector <G2CSSession>(SessionType.ServerG2CS, this.config.csIP, this.config.csPort, ProtoType.TCP, 1024 * 1024, 0); return(ErrorCode.Success); }
/// <summary> /// Called by CommandWindows to process the command string input by the user. /// If this results in a valid command being successfully ran, return true, otherwise return false. /// </summary> /// <param name="command">Command string to process.</param> /// <param name="shellSession">Shell session to use with this command.</param> /// <returns>A value indicating whether the command could be processed.</returns> public bool ProcessCommand(string command, ShellSession shellSession) { bool success = true; Window = shellSession.Window; var chdirCommand = $"cd \"{shellSession.CurrentDirectory}\""; Window.WriteCommandLink(shellSession.CurrentDirectory, Window.RunShellRequestCommand, chdirCommand); Window.WriteInfoText($" ==> {command}\n"); // For command execution, switch to the session's current directory. Directory.SetCurrentDirectory(shellSession.CurrentDirectory); int lastCommandResult; try { List <string> argList = Parser.Parse(command); lastCommandResult = LibManager.runCommand(argList.ToArray()); if (lastCommandResult != 0) { return(success = false); } } catch (InvalidCommandException e) { Executor.WriteInfoText(e.Message); success = false; } // Update the session's current directory based on the result of the command. shellSession.CurrentDirectory = Directory.GetCurrentDirectory(); return(success); }
/// <summary> /// Constructs a new RunShellRequestCommand instance associated with a specific shell session. /// </summary> /// <param name="shellSession">The shell session associated with this RunShellRequestCommand instance.</param> public RunShellRequestCommand(ShellSession shellSession) { ShellSession = shellSession; }
/// <summary> /// Initializes the command prompt for use with the next command. /// </summary> /// <param name="shellSession">The shell session to use with the command prompt.</param> public void PresentCommandPrompt(ShellSession shellSession) { CurrentWorkingDirectory = shellSession.CurrentDirectory; IndexOfLastHistoryDisplayed = -1; txtCommand.Text = string.Empty; }
public IWebResults ShellTo(string url, IUser user) { ISession shellSession = new ShellSession(Session, user); ShellWebConnection shellWebConnection = new BlockingShellWebConnection( WebServer, shellSession, url, new byte[0], ContentType, CookiesFromBrowser, CallingFrom, WebMethod.GET); shellWebConnection._BypassJavascript = BypassJavascript; return shellWebConnection.GenerateResultsForClient(); }
public IWebConnection CreateShellConnection(IUser user) { ISession shellSession = new ShellSession(Session, user); ShellWebConnection shellWebConnection = new BlockingShellWebConnection( this, shellSession, RequestedFile, GetParameters, new byte[0], ContentType, CookiesFromBrowser, CallingFrom); shellWebConnection._BypassJavascript = BypassJavascript; return shellWebConnection; }