diff --git a/src/NSmartProxy.ClientRouter/Router.cs b/src/NSmartProxy.ClientRouter/Router.cs index 22e2989..573db30 100644 --- a/src/NSmartProxy.ClientRouter/Router.cs +++ b/src/NSmartProxy.ClientRouter/Router.cs @@ -137,11 +137,11 @@ public async Task Start(bool AlwaysReconnect = false, Action comple _waiter = new TaskCompletionSource(); Router.TimeStamp = Guid.NewGuid(); - var appIdIpPortConfig = ClientConfig.Clients; + int clientId = 0; - + //0.5 处理登录/重登录/匿名登录逻辑 try @@ -204,7 +204,11 @@ public async Task Start(bool AlwaysReconnect = false, Action comple } else { + //ip地址和端口还原,服务端给的配置里的端口和ip地址需要作废。 + var originConfig = ClientConfig; ClientConfig = configResult.Data; + ClientConfig.ProviderAddress = originConfig.ProviderAddress; + ClientConfig.ProviderWebPort = originConfig.ProviderWebPort; } } else @@ -219,6 +223,7 @@ public async Task Start(bool AlwaysReconnect = false, Action comple } + //var appIdIpPortConfig = ClientConfig.Clients; //0 获取服务器端口配置 try { @@ -262,7 +267,7 @@ public async Task Start(bool AlwaysReconnect = false, Action comple int counter = 0; //2.从服务端返回的appid上分配客户端的appid TODO 3 appid逻辑需要重新梳理 - foreach (var app in appIdIpPortConfig) + foreach (var app in ClientConfig.Clients) { //if (app.AppId == 0) //{ @@ -274,7 +279,7 @@ public async Task Start(bool AlwaysReconnect = false, Action comple List tunnelstrs = new List(); foreach (var ap in clientModel.AppList) { - var cApp = appIdIpPortConfig.First(obj => obj.AppId == ap.AppId); + var cApp = ClientConfig.Clients.First(obj => obj.AppId == ap.AppId); //var cApp = appIdIpPortConfig[ap.AppId]; var tunnelStr = $@"{ap.AppId}:({cApp.Protocol}){ClientConfig.ProviderAddress}:{ap.Port}=>{cApp.IP}:{cApp.TargetServicePort}"; diff --git a/src/NSmartProxy.Data/Models/ClientModel.cs b/src/NSmartProxy.Data/Models/ClientModel.cs index b10d866..995ae63 100644 --- a/src/NSmartProxy.Data/Models/ClientModel.cs +++ b/src/NSmartProxy.Data/Models/ClientModel.cs @@ -38,7 +38,7 @@ public static ClientModel GetFromBytes(byte[] bytes, int totalLength = 0) int appCount = (totalLength - 2) / 3; if (((totalLength - 2) % 3) > 0) { - throw new Exception("error format"); + throw new Exception("格式错误:获取客户端对象失败"); } for (int i = 0; i < appCount; i++) { diff --git a/src/NSmartProxy.Infrastructure/Shared/NSPVersion.cs b/src/NSmartProxy.Infrastructure/Shared/NSPVersion.cs index 0dc0343..4d7a480 100644 --- a/src/NSmartProxy.Infrastructure/Shared/NSPVersion.cs +++ b/src/NSmartProxy.Infrastructure/Shared/NSPVersion.cs @@ -2,6 +2,6 @@ public sealed class NSPVersion { public const string NO_TOKEN_STRING = "notoken"; - public const string NSmartProxyClientName = "NSmartProxy Client v1.2.7204.3336"; - public const string NSmartProxyServerName = "NSmartProxy Server v1.2.7204.3336"; + public const string NSmartProxyClientName = "NSmartProxy Client v1.3.7231.7118"; + public const string NSmartProxyServerName = "NSmartProxy Server v1.3.7231.7118"; } \ No newline at end of file diff --git a/src/NSmartProxy.Infrastructure/Shared/NSPVersion.tt b/src/NSmartProxy.Infrastructure/Shared/NSPVersion.tt index 8eff022..25822f5 100644 --- a/src/NSmartProxy.Infrastructure/Shared/NSPVersion.tt +++ b/src/NSmartProxy.Infrastructure/Shared/NSPVersion.tt @@ -11,6 +11,6 @@ public sealed class NSPVersion { public const string NO_TOKEN_STRING = "notoken"; - public const string NSmartProxyClientName = "NSmartProxy Client v1.2.<#=v1#>.<#=v2#>"; - public const string NSmartProxyServerName = "NSmartProxy Server v1.2.<#=v1#>.<#=v2#>"; + public const string NSmartProxyClientName = "NSmartProxy Client v1.3.<#=v1#>.<#=v2#>"; + public const string NSmartProxyServerName = "NSmartProxy Server v1.3.<#=v1#>.<#=v2#>"; } \ No newline at end of file diff --git a/src/NSmartProxy/Extension/HttpServer_APIs.cs b/src/NSmartProxy/Extension/HttpServer_APIs.cs index 753a865..e6060f0 100644 --- a/src/NSmartProxy/Extension/HttpServer_APIs.cs +++ b/src/NSmartProxy/Extension/HttpServer_APIs.cs @@ -455,27 +455,37 @@ public NSPClientConfig GetServerClientConfig(string userId = null) [API] [Secure] - public void SetServerClientConfig(string userId, string config) + public void SetServerClientConfig(string userName, string config) { NSPClientConfig nspClientConfig = null; - try + if (String.IsNullOrWhiteSpace(config))//用户如果清空了配置则客户端会自行使用自己的配置文件 { - nspClientConfig = config.ToObject(); - nspClientConfig.UseServerControl = true; - nspClientConfig.ProviderAddress = HttpContext.Request.Url.Host; - nspClientConfig.ProviderWebPort = ServerContext.ServerConfig.WebAPIPort; - // nspClientConfig.ConfigPort = ServerContext.ServerConfig.ConfigPort; - // nspClientConfig.ReversePort = ServerContext.ServerConfig.ReversePort; + Dbop.SetConfig(userName, ""); } - catch (Exception e) + else { - throw new Exception("配置格式不正确。"); + try + { + nspClientConfig = config.ToObject(); + nspClientConfig.UseServerControl = true; + //nspClientConfig.ProviderAddress = HttpContext.Request.Url.Host; + // nspClientConfig.ProviderWebPort = ServerContext.ServerConfig.WebAPIPort; + // nspClientConfig.ConfigPort = ServerContext.ServerConfig.ConfigPort; + // nspClientConfig.ReversePort = ServerContext.ServerConfig.ReversePort; + } + catch (Exception e) + { + throw new Exception("配置格式不正确。"); + } + + Dbop.SetConfig(userName, nspClientConfig.ToJsonString()); } - Dbop.SetConfig(userId, nspClientConfig.ToJsonString()); //重置客户端(给客户端发送重定向请求让客户端主动重启) - //var userid = Dbop.Get(userId)?.ToObject().userId; - //ServerContext.CloseAllSourceByClient(int.Parse(userid)); + var userid = Dbop.Get(userName)?.ToObject().userId; + //var popClientAsync = await ServerContext.Clients[userid].AppMap.First().Value.PopClientAsync(); + + ServerContext.CloseAllSourceByClient(int.Parse(userid)); //ServerContext.CloseAllSourceByClient(); //return new NSPClientConfig(); diff --git a/src/NSmartProxy/Web/main.js b/src/NSmartProxy/Web/main.js index e6614a5..467acf6 100644 --- a/src/NSmartProxy/Web/main.js +++ b/src/NSmartProxy/Web/main.js @@ -1,6 +1,6 @@ //TODO 调试用 -//var basepath = "/";//api根地址,这里需要和配置文件一致 -var basepath = "http://localhost:12309/"; //调试时请把地址改成这个 +var basepath = "/";//api根地址,这里需要和配置文件一致 +//var basepath = "http://localhost:12309/"; //调试时请把地址改成这个 //hashchange事件,路由是如此实现的 (function () { diff --git a/src/NSmartProxy/Web/users.js b/src/NSmartProxy/Web/users.js index 64c55cd..30fa5f2 100644 --- a/src/NSmartProxy/Web/users.js +++ b/src/NSmartProxy/Web/users.js @@ -460,6 +460,8 @@ function formatJson(json, options) { } function isJSON(str) { + if (str == "") return ""; + if (typeof str == 'string') { try { var obj = JSON.parse(str); diff --git a/src/build.cmd b/src/build.cmd index 03413c7..96291ee 100644 --- a/src/build.cmd +++ b/src/build.cmd @@ -1,8 +1,8 @@ rem windows only -rem NSP v1.2 +rem NSP v1.3 @ECHO off -set Ver=v1.2_final5 +set Ver=v1.3_alpha set BuildPath=%~dp0../build set nsp_client_path=%BuildPath%/nspclient_%Ver%