Browse Source

修改ip范围列表

denny 2 years ago
parent
commit
a88d5aa532
2 changed files with 78 additions and 7 deletions
  1. 75 4
      src/InteractionCenter/VinnoServerService.cs
  2. 3 3
      src/Plugin/ServerListPlugin.cs

+ 75 - 4
src/InteractionCenter/VinnoServerService.cs

@@ -15,6 +15,7 @@ using WingServerCommon.Config.Parameters;
 using System.Net;
 using Newtonsoft.Json;
 using WingServerCommon.Mapper;
+using WingInterfaceLibrary.DTO.DistributedServerInfo;
 
 namespace WingCloudServer.InteractionCenter
 {
@@ -32,7 +33,7 @@ namespace WingCloudServer.InteractionCenter
         private ITokenDBService _tokenDBService;
 
         /// <summary>
-        /// 默认构é€
+        /// 默认构�
         /// </summary>
         public VinnoServerService()
         {
@@ -133,7 +134,7 @@ namespace WingCloudServer.InteractionCenter
         }
 
         /// <summary>
-        /// åˆ�å§‹åŒ
+        /// åˆ�å§‹åŒ
         /// </summary>
         public override void Load(JsonRpcClientPool jsonRpcClientPool)
         {
@@ -145,7 +146,7 @@ namespace WingCloudServer.InteractionCenter
         }
 
         /// <summary>
-        /// 加载ServerInfo到内å­
+        /// 加载ServerInfo到内存
         /// </summary>
         /// <returns></returns>
         private void LoadDBServerInfo()
@@ -232,7 +233,7 @@ namespace WingCloudServer.InteractionCenter
         }
 
         /// <summary>
-        /// 测速接å�
+        /// 测速接�
         /// </summary>
         /// <returns></returns>
         public async Task<EchoResult> EchoAsync()
@@ -240,5 +241,75 @@ namespace WingCloudServer.InteractionCenter
             var echoResult = new EchoResult();
             return await Task.FromResult(echoResult);
         }
+
+        /// <summary>
+        /// 更新�务器IP列表信� 
+        /// </summary>
+        /// <param name="request">请求对象</param>
+        /// <returns>是��功</returns>
+        public async Task<bool> UpdateServerIPListAsync(UpdateServerIPListRequest request)
+        {
+            if (string.IsNullOrEmpty(request.Name) || string.IsNullOrEmpty(request.IpRange)) {
+                Logger.WriteLineError($"UpdateServerIPListAsync Empty Error");
+                return false;
+            }
+            var ipRanges = request.IpRange.Split(new char[2] { '\r', '\n' });
+            ipRanges = ipRanges.Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
+            var ipRangeList = new List<IPAddressInfoDTO>();
+            foreach (var ip in ipRanges)
+            {
+                var newIpRange = ip.Split('\t');
+                if (newIpRange.Length < 2)
+                {
+                    continue;
+                }
+                var startIp = newIpRange[0];
+                var endIp = newIpRange[1];
+                var longStartIp = IpToLong(startIp);
+                var longEndIp = IpToLong(endIp);
+                var ipAddressInfo = new IPAddressInfoDTO() 
+                {
+                    StartIp = startIp,
+                    EndIp = endIp,
+                    LongStartIP = longStartIp,
+                    LongEndIP = longEndIp
+                };
+                ipRangeList.Add(ipAddressInfo);
+            }
+            var dbRequest = new UpdateServerIPListRequest() {
+                Name = request.Name,
+                IpRange = request.IpRange
+            };
+            var result = await _distributedServerInfoDBService.UpdateDistributedServerIPListAsync(dbRequest);
+            return result;
+        }
+
+        /// <summary>
+        /// Ip转Long
+        /// </summary>
+        /// <param name="ip"></param>
+        /// <returns></returns>
+        private long IpToLong(string ip)
+        {
+            try
+            {
+                if (System.Net.IPAddress.TryParse(ip, out IPAddress ipAddress))
+                {
+                    char[] separator = new char[] { '.' };
+                    string[] items = ip.Split(separator);
+                    var ipLong = long.Parse(items[0]) << 24 | long.Parse(items[1]) << 16 | long.Parse(items[2]) << 8 | long.Parse(items[3]);
+                    return ipLong;
+                }
+                else
+                {
+                    Logger.WriteLineWarn($"IpToLong failed, err ip formatter, ip: {ip}");
+                }
+            }
+            catch (Exception ex)
+            {
+                Logger.WriteLineWarn($"IpToLong failed, ip: {ip}, ex:{ex}");
+            }
+            return 0;
+        }
     }
 }

+ 3 - 3
src/Plugin/ServerListPlugin.cs

@@ -129,7 +129,7 @@ namespace WingCloudServer.Plugin
                             var extendList = new List<ServerInfoExtend>();
                             foreach(var item in serverInformationList) {
                                 //计算最短距离
-                                double beelineDistanceTemp = GetDistance(locationInfo.location.lat, locationInfo.location.lng, item.lat, item.lng);
+                                double beelineDistanceTemp = GetDistance(locationInfo.location.lat, locationInfo.location.lng, 0,0);//item.lat, item.lng);
                                 var extendInfo = new ServerInfoExtend() {
                                     Name = item.Name,
                                     Host = item.ServerUrl,
@@ -335,12 +335,12 @@ namespace WingCloudServer.Plugin
         /// <summary>
         /// 纬度
         /// </summary>
-        public string lat { get; set;}
+        public double lat { get; set;}
 
         /// <summary>
         /// 经度
         /// </summary>
-        public string lng { get; set;}
+        public double lng { get; set;}
     }
 
     /// <summary>