Skip to content

Commit a055ca4

Browse files
committed
1.3_alpha released.
1 parent 394029a commit a055ca4

File tree

8 files changed

+43
-26
lines changed

8 files changed

+43
-26
lines changed

src/NSmartProxy.ClientRouter/Router.cs

+9-4
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ public async Task Start(bool AlwaysReconnect = false, Action<ClientModel> comple
137137
_waiter = new TaskCompletionSource<object>();
138138
Router.TimeStamp = Guid.NewGuid();
139139

140-
var appIdIpPortConfig = ClientConfig.Clients;
140+
141141
int clientId = 0;
142142

143143

144-
144+
145145

146146
//0.5 处理登录/重登录/匿名登录逻辑
147147
try
@@ -204,7 +204,11 @@ public async Task Start(bool AlwaysReconnect = false, Action<ClientModel> comple
204204
}
205205
else
206206
{
207+
//ip地址和端口还原,服务端给的配置里的端口和ip地址需要作废。
208+
var originConfig = ClientConfig;
207209
ClientConfig = configResult.Data;
210+
ClientConfig.ProviderAddress = originConfig.ProviderAddress;
211+
ClientConfig.ProviderWebPort = originConfig.ProviderWebPort;
208212
}
209213
}
210214
else
@@ -219,6 +223,7 @@ public async Task Start(bool AlwaysReconnect = false, Action<ClientModel> comple
219223

220224
}
221225

226+
//var appIdIpPortConfig = ClientConfig.Clients;
222227
//0 获取服务器端口配置
223228
try
224229
{
@@ -262,7 +267,7 @@ public async Task Start(bool AlwaysReconnect = false, Action<ClientModel> comple
262267
int counter = 0;
263268

264269
//2.从服务端返回的appid上分配客户端的appid TODO 3 appid逻辑需要重新梳理
265-
foreach (var app in appIdIpPortConfig)
270+
foreach (var app in ClientConfig.Clients)
266271
{
267272
//if (app.AppId == 0)
268273
//{
@@ -274,7 +279,7 @@ public async Task Start(bool AlwaysReconnect = false, Action<ClientModel> comple
274279
List<string> tunnelstrs = new List<string>();
275280
foreach (var ap in clientModel.AppList)
276281
{
277-
var cApp = appIdIpPortConfig.First(obj => obj.AppId == ap.AppId);
282+
var cApp = ClientConfig.Clients.First(obj => obj.AppId == ap.AppId);
278283
//var cApp = appIdIpPortConfig[ap.AppId];
279284
var tunnelStr = $@"{ap.AppId}:({cApp.Protocol}){ClientConfig.ProviderAddress}:{ap.Port}=>{cApp.IP}:{cApp.TargetServicePort}";
280285

src/NSmartProxy.Data/Models/ClientModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static ClientModel GetFromBytes(byte[] bytes, int totalLength = 0)
3838
int appCount = (totalLength - 2) / 3;
3939
if (((totalLength - 2) % 3) > 0)
4040
{
41-
throw new Exception("error format");
41+
throw new Exception("格式错误:获取客户端对象失败");
4242
}
4343
for (int i = 0; i < appCount; i++)
4444
{

src/NSmartProxy.Infrastructure/Shared/NSPVersion.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
public sealed class NSPVersion
33
{
44
public const string NO_TOKEN_STRING = "notoken";
5-
public const string NSmartProxyClientName = "NSmartProxy Client v1.2.7204.3336";
6-
public const string NSmartProxyServerName = "NSmartProxy Server v1.2.7204.3336";
5+
public const string NSmartProxyClientName = "NSmartProxy Client v1.3.7231.7118";
6+
public const string NSmartProxyServerName = "NSmartProxy Server v1.3.7231.7118";
77
}

src/NSmartProxy.Infrastructure/Shared/NSPVersion.tt

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
public sealed class NSPVersion
1212
{
1313
public const string NO_TOKEN_STRING = "notoken";
14-
public const string NSmartProxyClientName = "NSmartProxy Client v1.2.<#=v1#>.<#=v2#>";
15-
public const string NSmartProxyServerName = "NSmartProxy Server v1.2.<#=v1#>.<#=v2#>";
14+
public const string NSmartProxyClientName = "NSmartProxy Client v1.3.<#=v1#>.<#=v2#>";
15+
public const string NSmartProxyServerName = "NSmartProxy Server v1.3.<#=v1#>.<#=v2#>";
1616
}

src/NSmartProxy/Extension/HttpServer_APIs.cs

+23-13
Original file line numberDiff line numberDiff line change
@@ -455,27 +455,37 @@ public NSPClientConfig GetServerClientConfig(string userId = null)
455455

456456
[API]
457457
[Secure]
458-
public void SetServerClientConfig(string userId, string config)
458+
public void SetServerClientConfig(string userName, string config)
459459
{
460460
NSPClientConfig nspClientConfig = null;
461-
try
461+
if (String.IsNullOrWhiteSpace(config))//用户如果清空了配置则客户端会自行使用自己的配置文件
462462
{
463-
nspClientConfig = config.ToObject<NSPClientConfig>();
464-
nspClientConfig.UseServerControl = true;
465-
nspClientConfig.ProviderAddress = HttpContext.Request.Url.Host;
466-
nspClientConfig.ProviderWebPort = ServerContext.ServerConfig.WebAPIPort;
467-
// nspClientConfig.ConfigPort = ServerContext.ServerConfig.ConfigPort;
468-
// nspClientConfig.ReversePort = ServerContext.ServerConfig.ReversePort;
463+
Dbop.SetConfig(userName, "");
469464
}
470-
catch (Exception e)
465+
else
471466
{
472-
throw new Exception("配置格式不正确。");
467+
try
468+
{
469+
nspClientConfig = config.ToObject<NSPClientConfig>();
470+
nspClientConfig.UseServerControl = true;
471+
//nspClientConfig.ProviderAddress = HttpContext.Request.Url.Host;
472+
// nspClientConfig.ProviderWebPort = ServerContext.ServerConfig.WebAPIPort;
473+
// nspClientConfig.ConfigPort = ServerContext.ServerConfig.ConfigPort;
474+
// nspClientConfig.ReversePort = ServerContext.ServerConfig.ReversePort;
475+
}
476+
catch (Exception e)
477+
{
478+
throw new Exception("配置格式不正确。");
479+
}
480+
481+
Dbop.SetConfig(userName, nspClientConfig.ToJsonString());
473482
}
474483

475-
Dbop.SetConfig(userId, nspClientConfig.ToJsonString());
476484
//重置客户端(给客户端发送重定向请求让客户端主动重启)
477-
//var userid = Dbop.Get(userId)?.ToObject<User>().userId;
478-
//ServerContext.CloseAllSourceByClient(int.Parse(userid));
485+
var userid = Dbop.Get(userName)?.ToObject<User>().userId;
486+
//var popClientAsync = await ServerContext.Clients[userid].AppMap.First().Value.PopClientAsync();
487+
488+
ServerContext.CloseAllSourceByClient(int.Parse(userid));
479489

480490
//ServerContext.CloseAllSourceByClient();
481491
//return new NSPClientConfig();

src/NSmartProxy/Web/main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//TODO 调试用
2-
//var basepath = "/";//api根地址,这里需要和配置文件一致
3-
var basepath = "http://localhost:12309/"; //调试时请把地址改成这个
2+
var basepath = "/";//api根地址,这里需要和配置文件一致
3+
//var basepath = "http://localhost:12309/"; //调试时请把地址改成这个
44

55
//hashchange事件,路由是如此实现的
66
(function () {

src/NSmartProxy/Web/users.js

+2
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ function formatJson(json, options) {
460460
}
461461

462462
function isJSON(str) {
463+
if (str == "") return "";
464+
463465
if (typeof str == 'string') {
464466
try {
465467
var obj = JSON.parse(str);

src/build.cmd

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
rem windows only
2-
rem NSP v1.2
2+
rem NSP v1.3
33
@ECHO off
44

5-
set Ver=v1.2_final5
5+
set Ver=v1.3_alpha
66
set BuildPath=%~dp0../build
77

88
set nsp_client_path=%BuildPath%/nspclient_%Ver%

0 commit comments

Comments
 (0)