Skip to content

Commit

Permalink
1.3_alpha released.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmoonlight committed Apr 22, 2020
1 parent 394029a commit a055ca4
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 26 deletions.
13 changes: 9 additions & 4 deletions src/NSmartProxy.ClientRouter/Router.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ public async Task Start(bool AlwaysReconnect = false, Action<ClientModel> comple
_waiter = new TaskCompletionSource<object>();
Router.TimeStamp = Guid.NewGuid();

var appIdIpPortConfig = ClientConfig.Clients;

int clientId = 0;




//0.5 处理登录/重登录/匿名登录逻辑
try
Expand Down Expand Up @@ -204,7 +204,11 @@ public async Task Start(bool AlwaysReconnect = false, Action<ClientModel> comple
}
else
{
//ip地址和端口还原,服务端给的配置里的端口和ip地址需要作废。
var originConfig = ClientConfig;
ClientConfig = configResult.Data;
ClientConfig.ProviderAddress = originConfig.ProviderAddress;
ClientConfig.ProviderWebPort = originConfig.ProviderWebPort;
}
}
else
Expand All @@ -219,6 +223,7 @@ public async Task Start(bool AlwaysReconnect = false, Action<ClientModel> comple

}

//var appIdIpPortConfig = ClientConfig.Clients;
//0 获取服务器端口配置
try
{
Expand Down Expand Up @@ -262,7 +267,7 @@ public async Task Start(bool AlwaysReconnect = false, Action<ClientModel> 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)
//{
Expand All @@ -274,7 +279,7 @@ public async Task Start(bool AlwaysReconnect = false, Action<ClientModel> comple
List<string> tunnelstrs = new List<string>();
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}";

Expand Down
2 changes: 1 addition & 1 deletion src/NSmartProxy.Data/Models/ClientModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down
4 changes: 2 additions & 2 deletions src/NSmartProxy.Infrastructure/Shared/NSPVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
4 changes: 2 additions & 2 deletions src/NSmartProxy.Infrastructure/Shared/NSPVersion.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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#>";
}
36 changes: 23 additions & 13 deletions src/NSmartProxy/Extension/HttpServer_APIs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
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>();
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<User>().userId;
//ServerContext.CloseAllSourceByClient(int.Parse(userid));
var userid = Dbop.Get(userName)?.ToObject<User>().userId;
//var popClientAsync = await ServerContext.Clients[userid].AppMap.First().Value.PopClientAsync();

ServerContext.CloseAllSourceByClient(int.Parse(userid));

//ServerContext.CloseAllSourceByClient();
//return new NSPClientConfig();
Expand Down
4 changes: 2 additions & 2 deletions src/NSmartProxy/Web/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//TODO 调试用
//var basepath = "/";//api根地址,这里需要和配置文件一致
var basepath = "http://localhost:12309/"; //调试时请把地址改成这个
var basepath = "/";//api根地址,这里需要和配置文件一致
//var basepath = "http://localhost:12309/"; //调试时请把地址改成这个

//hashchange事件,路由是如此实现的
(function () {
Expand Down
2 changes: 2 additions & 0 deletions src/NSmartProxy/Web/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ function formatJson(json, options) {
}

function isJSON(str) {
if (str == "") return "";

if (typeof str == 'string') {
try {
var obj = JSON.parse(str);
Expand Down
4 changes: 2 additions & 2 deletions src/build.cmd
Original file line number Diff line number Diff line change
@@ -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%
Expand Down

0 comments on commit a055ca4

Please sign in to comment.