Example #1
0
 /// <summary>
 /// HTTP服务
 /// </summary>
 /// <param name="server">HTTP 注册管理服务</param>
 /// <param name="host">TCP 服务端口信息</param>
 /// <param name="isSSL">是否安全服务</param>
 /// <param name="isStart">是否启动服务</param>
 internal Server(HttpRegister.Server server, ref HostPort host, bool isSSL, bool isStart = true)
 {
     this.RegisterServer = server;
     this.host           = host;
     IsSSL       = isSSL;
     DomainCount = 1;
     if (isStart)
     {
         start();
     }
 }
Example #2
0
        public UIViewController GetViewController()
        {
            var network = new BooleanElement("Enable", EnableNetwork);

            var host = new EntryElement("Host Name", "name", HostName);

            host.KeyboardType = UIKeyboardType.ASCIICapable;

            var port = new EntryElement("Port", "name", HostPort.ToString());

            port.KeyboardType = UIKeyboardType.NumberPad;

            var sort = new BooleanElement("Sort Names", SortNames);

            var root = new RootElement("Options")
            {
                new Section("Remote Server")
                {
                    network, host, port
                },
                new Section("Display")
                {
                    sort
                }
            };

            var dv = new DialogViewController(root, true)
            {
                Autorotate = true
            };

            dv.ViewDisappearing += delegate {
                EnableNetwork = network.Value;
                HostName      = host.Value;
                ushort p;
                if (UInt16.TryParse(port.Value, out p))
                {
                    HostPort = p;
                }
                else
                {
                    HostPort = -1;
                }
                SortNames = sort.Value;

                var defaults = NSUserDefaults.StandardUserDefaults;
                defaults.SetBool(EnableNetwork, "network.enabled");
                defaults.SetString(HostName ?? String.Empty, "network.host.name");
                defaults.SetInt(HostPort, "network.host.port");
                defaults.SetBool(SortNames, "display.sort");
            };

            return(dv);
        }
Example #3
0
        /// <summary>
        /// 主机名称转换成IP地址
        /// </summary>
        /// <returns>是否转换成功</returns>
        public bool HostToIpAddress()
        {
            IPAddress ipAddress = HostPort.HostToIPAddress(Host);

            if (ipAddress == null)
            {
                return(false);
            }
            Host = ipAddress.ToString();
            return(true);
        }
Example #4
0
 static void Main(string[] args)
 {
     port = StartServerThread();
     Console.WriteLine(port);
     if (args.Length > 0)
     {
         var peer = new HostPort(args[0]);
         peers.Add(peer);
         Cmd command = new Cmd(port, Cmd.GETPEERS);
         SendCommand(peer, command);
     }
 }
Example #5
0
        /// <summary>
        /// TCP 服务客户端
        /// </summary>
        /// <param name="attribute">TCP服务调用配置</param>
        /// <param name="verify">获取客户端请求线程调用类型</param>
        /// <param name="log">日志接口</param>
        /// <param name="isCallQueue">是否提供独占的 TCP 服务器端同步调用队列</param>
        internal ServerBase(attributeType attribute, Func <System.Net.Sockets.Socket, bool> verify, ILog log, bool isCallQueue)
            : base(attribute, attribute.GetReceiveBufferSize, attribute.GetSendBufferSize, attribute.GetServerSendBufferMaxSize, log)
        {
            this.verify = verify;
            if (isCallQueue)
            {
                CallQueue = new ServerCallCanDisposableQueue();
            }
            Port      = attribute.Port;
            IpAddress = HostPort.HostToIPAddress(attribute.Host, Log);
            int binaryDeSerializeMaxArraySize = attribute.GetBinaryDeSerializeMaxArraySize;

            BinaryDeSerializeConfig = AutoCSer.Net.TcpOpenServer.ServerAttribute.GetBinaryDeSerializeConfig(binaryDeSerializeMaxArraySize <= 0 ? AutoCSer.BinarySerialize.DeSerializer.DefaultConfig.MaxArraySize : binaryDeSerializeMaxArraySize);
        }
        /// <summary>
        /// Callback for transport selection change event
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="args">Selection Changed Event Arguments</param>
        public void OnTransportChanged(object sender, SelectionChangedEventArgs args)
        {
            // This prevent null exception
            if (App.CurrentAccount == null)
            {
                return;
            }

            var transportText = TransportComboBox.SelectedItem as TextBlock;

            App.CurrentAccount.Transport = transportText.Text;
            string transport = transportText.Text.ToLower();

            // Must check if HostPortBox exists before accessing it
            // When a users un-registers, this method is called before the HostPortBox is initialized
            if (transport == "tcp")
            {
                HostPort = App.CurrentAccount.HostPort = 5060;
                if (HostPortBox != null)
                {
                    HostPortBox.IsReadOnly = true;
                    HostPortBox.Background = Brushes.LightGray;
                    HostPortBox.Foreground = Brushes.Black;
                }
            }
            else if (transport == "tls")
            {
                HostPort = App.CurrentAccount.HostPort = 5061;
                if (HostPortBox != null)
                {
                    HostPortBox.IsReadOnly = true;
                    HostPortBox.Background = Brushes.LightGray;
                    HostPortBox.Foreground = Brushes.Black;
                }
            }
            else if (transport == "udp")
            {
                HostPort = App.CurrentAccount.HostPort = 5060;
                if (HostPortBox != null)
                {
                    HostPortBox.IsReadOnly = false;
                    HostPortBox.Background = Brushes.White;
                }
            }
            if (HostPortBox != null)
            {
                HostPortBox.Text = HostPort.ToString();
            }
        }
Example #7
0
 /// <summary>
 /// 服务更新
 /// </summary>
 /// <param name="serverSet"></param>
 void TcpRegister.IClient.OnServerChange(TcpRegister.ServerSet serverSet)
 {
     if (serverSet != null)
     {
         TcpRegister.ServerLog server    = serverSet.Server;
         IPAddress             ipAddress = HostPort.HostToIPAddress(server.Host, Log);
         if (server.Port != Port || !ipAddress.Equals(IpAddress))
         {
             Host      = server.Host;
             IpAddress = ipAddress;
             Port      = server.Port;
         }
         createSocket();
     }
 }
        /// <summary>
        /// 服务更新
        /// </summary>
        /// <param name="serverSet"></param>
        internal void OnServerChange(TcpRegister.ServerSet serverSet)
        {
            TcpRegister.ServerLog server    = serverSet.Server;
            IPAddress             ipAddress = HostPort.HostToIPAddress(server.Host, CommandClient.Log);

            if (server.Port == Port && ipAddress.Equals(IpAddress))
            {
                TryCreateSocket();
            }
            else
            {
                Host = server.Host;
                createSocket(IpAddress = ipAddress, Port = server.Port, Interlocked.Increment(ref CreateVersion));
            }
        }
Example #9
0
        public override void SetBasicPropertyValues()
        {
            base.SetBasicPropertyValues();

            //默认ModuleNumber由ID决定
            ModuleNumber = ID;
            ResourceProperty propertyValue;

            for (int i = 0; i < ListProperties.Count; i++)
            {
                propertyValue = ListProperties[i];
                switch (propertyValue.PropertyID)
                {
                case S1110Consts.PROPERTYID_HOSTADDRESS:
                    propertyValue.Value = HostAddress;
                    break;

                case S1110Consts.PROPERTYID_HOSTNAME:
                    propertyValue.Value = HostName;
                    break;

                case S1110Consts.PROPERTYID_HOSTPORT:
                    propertyValue.Value = HostPort.ToString();
                    break;

                case S1110Consts.PROPERTYID_CONTINENT:
                    propertyValue.Value = Continent;
                    break;

                case S1110Consts.PROPERTYID_COUNTRY:
                    propertyValue.Value = Country;
                    break;

                case S1110Consts.PROPERTYID_MODULENUMBER:
                    propertyValue.Value = ModuleNumber.ToString();
                    break;

                case S1110Consts.PROPERTYID_ENABLEDISABLE:
                    propertyValue.Value = IsEnabled ? "1" : "0";
                    break;

                case S1110Consts.PROPERTYID_MACHINE:
                    propertyValue.Value = MachineObjID.ToString();
                    break;
                }
            }
        }
Example #10
0
        /// <summary>
        /// TCP 服务客户端
        /// </summary>
        /// <param name="attribute">TCP服务调用配置</param>
        /// <param name="verify">获取客户端请求线程调用类型</param>
        /// <param name="log">日志接口</param>
        /// <param name="callQueueCount">独占的 TCP 服务器端同步调用队列数量</param>
        /// <param name="isCallQueueLink">是否提供独占的 TCP 服务器端同步调用队列(低优先级)</param>
        /// <param name="isSynchronousVerifyMethod">验证函数是否同步调用</param>
        internal ServerBase(ServerBaseAttribute attribute, Func <System.Net.Sockets.Socket, bool> verify, ILog log, int callQueueCount, bool isCallQueueLink, bool isSynchronousVerifyMethod)
            : base(attribute, attribute.GetReceiveBufferSize, attribute.GetSendBufferSize, attribute.GetServerSendBufferMaxSize, log)
        {
            this.verify = verify;
            if (callQueueCount > 0)
            {
                if (callQueueCount == 1)
                {
                    CallQueue = new ServerCallCanDisposableQueue(true, Log);
                    if (isCallQueueLink)
                    {
                        CallQueueLink = CallQueue.CreateLink();
                    }
                }
                else
                {
                    CallQueueArray = new KeyValue <ServerCallCanDisposableQueue, Threading.QueueTaskLinkThread <ServerCallBase> .LowPriorityLink> [Math.Min(callQueueCount, 256)];
                    if (isCallQueueLink)
                    {
                        for (int index = 0; index != CallQueueArray.Length; ++index)
                        {
                            ServerCallCanDisposableQueue callQueue = new ServerCallCanDisposableQueue(true, Log);
                            CallQueueArray[index].Set(callQueue, callQueue.CreateLink());
                        }
                        CallQueueLink = CallQueueArray[0].Value;
                    }
                    else
                    {
                        for (int index = 0; index != CallQueueArray.Length; ++index)
                        {
                            CallQueueArray[index].Key = new ServerCallCanDisposableQueue(true, Log);
                        }
                    }
                    CallQueue = CallQueueArray[0].Key;
                }
            }
            ServerAttribute.Set(attribute);
            Port      = attribute.Port;
            IpAddress = HostPort.HostToIPAddress(attribute.Host, Log);
            int binaryDeSerializeMaxArraySize = attribute.GetBinaryDeSerializeMaxArraySize;

            BinaryDeSerializeConfig = AutoCSer.Net.TcpOpenServer.ServerAttribute.GetBinaryDeSerializeConfig(binaryDeSerializeMaxArraySize <= 0 ? AutoCSer.BinarySerialize.DeSerializer.DefaultConfig.MaxArraySize : binaryDeSerializeMaxArraySize);
            VerifyMethodCount       = isSynchronousVerifyMethod ? Server.DefaultVerifyMethodCount : (byte)(Server.DefaultVerifyMethodCount + 1);
        }
Example #11
0
        static void Register()
        {
            SerializableTypeRegister.RegisterType(typeof(Vector3), (byte)SerilizeType.Vector3, Vector3SerializeFunction, Vector3DeserializeFunction);
            SerializableTypeRegister.RegisterType(typeof(Vector2), (byte)SerilizeType.Vector2, Vector2SerializeFunction, Vector2DeserializeFunction);
            SerializableTypeRegister.RegisterType(typeof(Quaternion), (byte)SerilizeType.Quaternion, QuaternionSerializeFunction, QuaternionDeserializeFunction);

            SerializableTypeRegister.RegisterType(typeof(HostPort), (byte)SerilizeType.HostPort, (stream, customObject) => {
                HostPort obj = (HostPort)customObject;
                obj.Serilize(stream);
            }, stream => {
                HostPort ret = new HostPort();
                ret.Deserilize(stream);
                return(ret);
            });


            SerializableTypeRegister.RegisterType(typeof(LobbyRoom), (int)SerilizeType.LobbyRoom, (stream, customObject) => {
                LobbyRoom obj = (LobbyRoom)customObject;
                obj.Serilize(stream);
            }, stream => {
                LobbyRoom ret = new LobbyRoom();
                ret.Deserilize(stream);
                return(ret);
            });


            SerializableTypeRegister.RegisterType(typeof(GameRoom), (int)SerilizeType.GameRoom, (stream, customObject) => {
                GameRoom obj = (GameRoom)customObject;
                obj.Serilize(stream);
            }, stream => {
                GameRoom ret = new GameRoom();
                ret.Deserilize(stream);
                return(ret);
            });

            SerializableTypeRegister.RegisterType(typeof(RoomPlayer), (int)SerilizeType.Player, (stream, customObject) => {
                RoomPlayer obj = (RoomPlayer)customObject;
                obj.Serilize(stream);
            }, stream => {
                RoomPlayer ret = new RoomPlayer();
                ret.Deserilize(stream);
                return(ret);
            });
        }
Example #12
0
        /// <summary>
        /// TCP 服务客户端
        /// </summary>
        /// <param name="attribute">TCP服务调用配置</param>
        /// <param name="log">日志接口</param>
        /// <param name="maxInputSize">最大输入数据字节数</param>
        internal Client(TcpServer.ServerBaseAttribute attribute, ILog log, int maxInputSize)
            : base(attribute, attribute.ClientSendBufferMaxSize, log)
        {
            this.Host = attribute.Host;
            this.Port = attribute.Port;
            IpAddress = HostPort.HostToIPAddress(this.Host, Log);

            this.maxInputSize = maxInputSize <= 0 ? int.MaxValue : maxInputSize;
            outputStream      = (outputSerializer = BinarySerializer.YieldPool.Default.Pop() ?? new BinarySerializer()).SetTcpServer();

            SubBuffer.Pool.GetPool(attribute.GetSendBufferSize).Get(ref Buffer);
            if (attribute.IsRemoteExpression)
            {
                remoteExpressionServerNodeIdChecker = new RemoteExpressionServerNodeIdChecker {
                    Client = this
                }
            }
            ;
        }
Example #13
0
 /// <summary>
 /// 启动服务
 /// </summary>
 protected void start()
 {
     try
     {
         IPAddress ipAddress = HostPort.HostToIPAddress(host.Host, RegisterServer.TcpServer.Log);
         socket = new System.Net.Sockets.Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
         socket.Bind(new IPEndPoint(ipAddress, host.Port));
         socket.Listen(int.MaxValue);
         socketHandle.Set(0);
         AutoCSer.Threading.ThreadPool.TinyBackground.FastStart(GetSocket);
         if (host.Port == 0)
         {
             RegisterServer.TcpServer.Log.Add(AutoCSer.Log.LogType.Warn, "HTTP 服务端口为 0");
         }
     }
     catch (Exception error)
     {
         Dispose();
         RegisterServer.TcpServer.Log.Add(AutoCSer.Log.LogType.Error, error, "HTTP 服务器端口 " + host.Host + ":" + host.Port.toString() + " TCP连接失败)");
     }
 }
Example #14
0
        /// <summary>
        /// 启动TCP服务
        /// </summary>
        /// <param name="host">TCP服务端口信息</param>
        /// <returns>HTTP服务启动状态</returns>
        private RegisterState start(ref HostPort host)
        {
            RegisterState state = RegisterState.TcpError;

            Http.Server httpServer = null;
            Monitor.Enter(hostLock);
            try
            {
                if (hosts.TryGetValue(host, out httpServer))
                {
                    if (!httpServer.IsSSL)
                    {
                        ++httpServer.DomainCount;
                        return(RegisterState.Success);
                    }
                    httpServer = null;
                    state      = RegisterState.SslMatchError;
                }
                else
                {
                    state      = RegisterState.CreateServerError;
                    httpServer = new Http.Server(this, ref host, false);
                    if (httpServer.IsStart)
                    {
                        hosts.Add(host, httpServer);
                        return(RegisterState.Success);
                    }
                }
            }
            catch (Exception error)
            {
                server.Log.Add(AutoCSer.Log.LogType.Error, error);
            }
            finally { Monitor.Exit(hostLock); }
            if (httpServer != null)
            {
                httpServer.Dispose();
            }
            return(state);
        }
Example #15
0
 private static void AddPeer(HostPort newpeer)
 {
     lock (peers)
     {
         if (!peers.Contains(newpeer))
         {
             peers.Add(newpeer);
             ThreadPool.QueueUserWorkItem(o =>
             {
                 lock (peers)
                 {
                     foreach (var peer in peers)
                     {
                         Cmd cmd = new Cmd(port, Cmd.ADDPEER);
                         cmd.Add("peer", newpeer);
                         SendCommand(peer, cmd);
                     }
                 }
             });
         }
     }
 }
        public override async Task <IDictionary <string, string> > SaveSetting()
        {
            var uiWorkflow   = IoC.Resolve <IUiWorkflow>();
            var textService  = IoC.Resolve <ITextService>();
            var savePassword = false;

            if (string.IsNullOrWhiteSpace(AuthPassword))
            {
                savePassword = (await DialogCoordinator.Instance.ShowMessageAsync(uiWorkflow,
                                                                                  textService.Compile("MailDistributor.Strategy.Smtp.Save.EncryptPassword.Title", CultureInfo.CurrentUICulture, out _).ToString(),
                                                                                  textService.Compile("MailDistributor.Strategy.Smtp.Save.EncryptPassword.Message", CultureInfo.CurrentUICulture, out _).ToString()
                                                                                  )) == MessageDialogResult.Affirmative;
            }

            return(new Dictionary <string, string>()
            {
                { nameof(Host), Host },
                { nameof(HostPort), HostPort.ToString() },
                { nameof(AuthUserName), AuthUserName },
                { nameof(AuthPassword), savePassword ? AuthPassword : null },
            });
        }
Example #17
0
 /// <summary>
 /// 服务更新
 /// </summary>
 /// <param name="serverSet"></param>
 void TcpRegister.IClient.OnServerChange(TcpRegister.ServerSet serverSet)
 {
     if (serverSet != null)
     {
         TcpRegister.ServerInfo server = serverSet.Server.Server;
         IPAddress ipAddress           = HostPort.HostToIPAddress(server.Host, Log);
         if (server.Port == Port && ipAddress.Equals(IpAddress))
         {
             if (!server.IsCheckRegister)
             {
                 createSocket();
             }
         }
         else
         {
             Host      = server.Host;
             IpAddress = ipAddress;
             Port      = server.Port;
             createSocket();
         }
     }
 }
Example #18
0
        public override void SetBasicPropertyValues()
        {
            base.SetBasicPropertyValues();

            ResourceProperty propertyValue;

            for (int i = 0; i < ListProperties.Count; i++)
            {
                propertyValue = ListProperties[i];
                switch (propertyValue.PropertyID)
                {
                case S1110Consts.PROPERTYID_HOSTADDRESS:
                    propertyValue.Value = HostAddress;
                    break;

                case S1110Consts.PROPERTYID_HOSTNAME:
                    propertyValue.Value = HostName;
                    break;

                case S1110Consts.PROPERTYID_HOSTPORT:
                    propertyValue.Value = HostPort.ToString();
                    break;

                case S1110Consts.PROPERTYID_CONTINENT:
                    propertyValue.Value = Continent;
                    break;

                case S1110Consts.PROPERTYID_COUNTRY:
                    propertyValue.Value = Country;
                    break;

                case 11:
                    propertyValue.Value = LogPath;
                    break;
                }
            }
        }
Example #19
0
 /// <summary>
 /// 服务更新
 /// </summary>
 /// <param name="serverSet"></param>
 void TcpRegister.IClient.OnServerChange(TcpRegister.ServerSet serverSet)
 {
     if (serverSet == null)
     {
         SocketWait.PulseReset();
     }
     else
     {
         TcpRegister.ServerInfo server = serverSet.Server.Server;
         IPAddress ipAddress           = HostPort.HostToIPAddress(server.Host, Log);
         if (server.Port == Port && ipAddress.Equals(IpAddress))
         {
             if (!server.IsCheckRegister)
             {
                 TryCreateSocket();
             }
         }
         else
         {
             Host = server.Host;
             createSocket(IpAddress = ipAddress, Port = server.Port, Interlocked.Increment(ref CreateVersion));
         }
     }
 }
Example #20
0
 /// <summary>
 /// 停止TCP服务
 /// </summary>
 /// <param name="host">TCP服务端口信息</param>
 private void stop(ref HostPort host)
 {
     Http.Server httpServer;
     Monitor.Enter(hostLock);
     try
     {
         if (hosts.TryGetValue(host, out httpServer))
         {
             if (--httpServer.DomainCount == 0)
             {
                 hosts.Remove(host);
             }
             else
             {
                 httpServer = null;
             }
         }
     }
     finally { Monitor.Exit(hostLock); }
     if (httpServer != null)
     {
         httpServer.Dispose();
     }
 }
Example #21
0
        public UIViewController GetViewController()
        {
            var network = new BooleanElement("Enable", EnableNetwork);

            var host = new EntryElement("Host Name", "name", HostName);

            host.KeyboardType = UIKeyboardType.ASCIICapable;

            var port = new EntryElement("Port", "name", HostPort.ToString());

            port.KeyboardType = UIKeyboardType.NumberPad;

            var sort = new BooleanElement("Sort Names", SortNames);

            var repeat      = new BooleanElement("Repeat", Repeat);
            var repeatCount = new EntryElement("Repeat Count", "repeat", RepeatCount.ToString());

            var autoStart = new BooleanElement("Auto Start", AutoStart);
            var autoExit  = new BooleanElement("Auto Exit", TerminateAfterExecution);

            var root = new RootElement("Options")
            {
                new Section("Remote Server")
                {
                    network, host, port
                },
                new Section("Display")
                {
                    sort
                },
                new Section("Repeat")
                {
                    repeat, repeatCount
                },
                new Section("Misc")
                {
                    autoStart, autoExit
                }
            };

            var dv = new DialogViewController(root, true)
            {
                Autorotate = true
            };

            dv.ViewDisappearing += delegate {
                EnableNetwork = network.Value;
                HostName      = host.Value;
                ushort p;
                if (UInt16.TryParse(port.Value, out p))
                {
                    HostPort = p;
                }
                else
                {
                    HostPort = -1;
                }
                SortNames = sort.Value;

                int r;
                if (Int32.TryParse(repeatCount.Value, out r))
                {
                    RepeatCount = r;
                }
                else
                {
                    RepeatCount = 0;
                }
                Repeat = repeat.Value;

                AutoStart = autoStart.Value;
                TerminateAfterExecution = autoExit.Value;

                var defaults = NSUserDefaults.StandardUserDefaults;
                defaults.SetBool(EnableNetwork, "network.enabled");
                defaults.SetString(HostName ?? String.Empty, "network.host.name");
                defaults.SetInt(HostPort, "network.host.port");
                defaults.SetBool(SortNames, "display.sort");
                defaults.SetBool(Repeat, "repeat.enabled");
                defaults.SetInt(RepeatCount, "repeat.count");
                defaults.SetBool(AutoStart, "misc.autostart");
                defaults.SetBool(TerminateAfterExecution, "misc.autoexit");
            };

            return(dv);
        }
Example #22
0
 public override void OnReceive(object session, Stream stream)
 {
     this.Result             = (JoinRoomResult)stream.ReadInt();
     this.RoomServerHostPort = stream.ReadObject <HostPort>();
 }
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (ProviderName != null)
         {
             hashCode = hashCode * 59 + ProviderName.GetHashCode();
         }
         if (HostName != null)
         {
             hashCode = hashCode * 59 + HostName.GetHashCode();
         }
         if (HostPort != null)
         {
             hashCode = hashCode * 59 + HostPort.GetHashCode();
         }
         if (HostSsl != null)
         {
             hashCode = hashCode * 59 + HostSsl.GetHashCode();
         }
         if (HostTls != null)
         {
             hashCode = hashCode * 59 + HostTls.GetHashCode();
         }
         if (HostNoCertCheck != null)
         {
             hashCode = hashCode * 59 + HostNoCertCheck.GetHashCode();
         }
         if (BindDn != null)
         {
             hashCode = hashCode * 59 + BindDn.GetHashCode();
         }
         if (BindPassword != null)
         {
             hashCode = hashCode * 59 + BindPassword.GetHashCode();
         }
         if (SearchTimeout != null)
         {
             hashCode = hashCode * 59 + SearchTimeout.GetHashCode();
         }
         if (AdminPoolMaxActive != null)
         {
             hashCode = hashCode * 59 + AdminPoolMaxActive.GetHashCode();
         }
         if (AdminPoolLookupOnValidate != null)
         {
             hashCode = hashCode * 59 + AdminPoolLookupOnValidate.GetHashCode();
         }
         if (UserPoolMaxActive != null)
         {
             hashCode = hashCode * 59 + UserPoolMaxActive.GetHashCode();
         }
         if (UserPoolLookupOnValidate != null)
         {
             hashCode = hashCode * 59 + UserPoolLookupOnValidate.GetHashCode();
         }
         if (UserBaseDN != null)
         {
             hashCode = hashCode * 59 + UserBaseDN.GetHashCode();
         }
         if (UserObjectclass != null)
         {
             hashCode = hashCode * 59 + UserObjectclass.GetHashCode();
         }
         if (UserIdAttribute != null)
         {
             hashCode = hashCode * 59 + UserIdAttribute.GetHashCode();
         }
         if (UserExtraFilter != null)
         {
             hashCode = hashCode * 59 + UserExtraFilter.GetHashCode();
         }
         if (UserMakeDnPath != null)
         {
             hashCode = hashCode * 59 + UserMakeDnPath.GetHashCode();
         }
         if (GroupBaseDN != null)
         {
             hashCode = hashCode * 59 + GroupBaseDN.GetHashCode();
         }
         if (GroupObjectclass != null)
         {
             hashCode = hashCode * 59 + GroupObjectclass.GetHashCode();
         }
         if (GroupNameAttribute != null)
         {
             hashCode = hashCode * 59 + GroupNameAttribute.GetHashCode();
         }
         if (GroupExtraFilter != null)
         {
             hashCode = hashCode * 59 + GroupExtraFilter.GetHashCode();
         }
         if (GroupMakeDnPath != null)
         {
             hashCode = hashCode * 59 + GroupMakeDnPath.GetHashCode();
         }
         if (GroupMemberAttribute != null)
         {
             hashCode = hashCode * 59 + GroupMemberAttribute.GetHashCode();
         }
         if (UseUidForExtId != null)
         {
             hashCode = hashCode * 59 + UseUidForExtId.GetHashCode();
         }
         if (Customattributes != null)
         {
             hashCode = hashCode * 59 + Customattributes.GetHashCode();
         }
         return(hashCode);
     }
 }
        /// <summary>
        /// Returns true if OrgApacheJackrabbitOakSecurityAuthenticationLdapImplLdapIdentiProperties instances are equal
        /// </summary>
        /// <param name="other">Instance of OrgApacheJackrabbitOakSecurityAuthenticationLdapImplLdapIdentiProperties to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(OrgApacheJackrabbitOakSecurityAuthenticationLdapImplLdapIdentiProperties other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     ProviderName == other.ProviderName ||
                     ProviderName != null &&
                     ProviderName.Equals(other.ProviderName)
                     ) &&
                 (
                     HostName == other.HostName ||
                     HostName != null &&
                     HostName.Equals(other.HostName)
                 ) &&
                 (
                     HostPort == other.HostPort ||
                     HostPort != null &&
                     HostPort.Equals(other.HostPort)
                 ) &&
                 (
                     HostSsl == other.HostSsl ||
                     HostSsl != null &&
                     HostSsl.Equals(other.HostSsl)
                 ) &&
                 (
                     HostTls == other.HostTls ||
                     HostTls != null &&
                     HostTls.Equals(other.HostTls)
                 ) &&
                 (
                     HostNoCertCheck == other.HostNoCertCheck ||
                     HostNoCertCheck != null &&
                     HostNoCertCheck.Equals(other.HostNoCertCheck)
                 ) &&
                 (
                     BindDn == other.BindDn ||
                     BindDn != null &&
                     BindDn.Equals(other.BindDn)
                 ) &&
                 (
                     BindPassword == other.BindPassword ||
                     BindPassword != null &&
                     BindPassword.Equals(other.BindPassword)
                 ) &&
                 (
                     SearchTimeout == other.SearchTimeout ||
                     SearchTimeout != null &&
                     SearchTimeout.Equals(other.SearchTimeout)
                 ) &&
                 (
                     AdminPoolMaxActive == other.AdminPoolMaxActive ||
                     AdminPoolMaxActive != null &&
                     AdminPoolMaxActive.Equals(other.AdminPoolMaxActive)
                 ) &&
                 (
                     AdminPoolLookupOnValidate == other.AdminPoolLookupOnValidate ||
                     AdminPoolLookupOnValidate != null &&
                     AdminPoolLookupOnValidate.Equals(other.AdminPoolLookupOnValidate)
                 ) &&
                 (
                     UserPoolMaxActive == other.UserPoolMaxActive ||
                     UserPoolMaxActive != null &&
                     UserPoolMaxActive.Equals(other.UserPoolMaxActive)
                 ) &&
                 (
                     UserPoolLookupOnValidate == other.UserPoolLookupOnValidate ||
                     UserPoolLookupOnValidate != null &&
                     UserPoolLookupOnValidate.Equals(other.UserPoolLookupOnValidate)
                 ) &&
                 (
                     UserBaseDN == other.UserBaseDN ||
                     UserBaseDN != null &&
                     UserBaseDN.Equals(other.UserBaseDN)
                 ) &&
                 (
                     UserObjectclass == other.UserObjectclass ||
                     UserObjectclass != null &&
                     UserObjectclass.Equals(other.UserObjectclass)
                 ) &&
                 (
                     UserIdAttribute == other.UserIdAttribute ||
                     UserIdAttribute != null &&
                     UserIdAttribute.Equals(other.UserIdAttribute)
                 ) &&
                 (
                     UserExtraFilter == other.UserExtraFilter ||
                     UserExtraFilter != null &&
                     UserExtraFilter.Equals(other.UserExtraFilter)
                 ) &&
                 (
                     UserMakeDnPath == other.UserMakeDnPath ||
                     UserMakeDnPath != null &&
                     UserMakeDnPath.Equals(other.UserMakeDnPath)
                 ) &&
                 (
                     GroupBaseDN == other.GroupBaseDN ||
                     GroupBaseDN != null &&
                     GroupBaseDN.Equals(other.GroupBaseDN)
                 ) &&
                 (
                     GroupObjectclass == other.GroupObjectclass ||
                     GroupObjectclass != null &&
                     GroupObjectclass.Equals(other.GroupObjectclass)
                 ) &&
                 (
                     GroupNameAttribute == other.GroupNameAttribute ||
                     GroupNameAttribute != null &&
                     GroupNameAttribute.Equals(other.GroupNameAttribute)
                 ) &&
                 (
                     GroupExtraFilter == other.GroupExtraFilter ||
                     GroupExtraFilter != null &&
                     GroupExtraFilter.Equals(other.GroupExtraFilter)
                 ) &&
                 (
                     GroupMakeDnPath == other.GroupMakeDnPath ||
                     GroupMakeDnPath != null &&
                     GroupMakeDnPath.Equals(other.GroupMakeDnPath)
                 ) &&
                 (
                     GroupMemberAttribute == other.GroupMemberAttribute ||
                     GroupMemberAttribute != null &&
                     GroupMemberAttribute.Equals(other.GroupMemberAttribute)
                 ) &&
                 (
                     UseUidForExtId == other.UseUidForExtId ||
                     UseUidForExtId != null &&
                     UseUidForExtId.Equals(other.UseUidForExtId)
                 ) &&
                 (
                     Customattributes == other.Customattributes ||
                     Customattributes != null &&
                     Customattributes.Equals(other.Customattributes)
                 ));
        }
Example #25
0
        public string PrepareConfig(HostsViewModel hosts, bool isLoadBalancePrepare = false)
        {
            string config     = ConfigTemplate;
            string appVersion = VersionTracking.CurrentVersion;

            string version_path = Path.Combine(
                App.Instance.DataPathParent,
                "version_" + appVersion);

            string gfwlist_path = Path.Combine(App.Instance.DataPathParent, "gfw_list");
            string cn_ips_path  = Path.Combine(App.Instance.DataPathParent, "cn_ips_list");
            string cert_path    = Path.Combine(App.Instance.DataPathParent, "cacert");

            if (!File.Exists(version_path))
            {
                File.WriteAllText(version_path, "TrojanPlus App Version: " + appVersion);

                File.WriteAllText(gfwlist_path, Resx.TextResource.gfwlist);
                File.WriteAllText(cn_ips_path, Resx.TextResource.cn_mainland_ips);
                File.WriteAllText(cert_path, Resx.TextResource.cacert);
            }

            config = config.Replace("${run_type}", "client_tun");
            config = config.Replace("${remote_addr}", HostAddress);
            config = config.Replace("${remote_port}", HostPort.ToString());
            config = config.Replace("${password}", Password);

            config = config.Replace("${udp_timeout}", "10");
            config = config.Replace("${udp_socket_buf}", "16384");
            config = config.Replace("${udp_recv_buf}", "4096");

            config = config.Replace("${log_level}", EnableDebugLog ? "0" : "5");

            config = config.Replace("${ssl.verify}", SSLVerify.ToLowerString());
            config = config.Replace("${ssl.verify_hostname}", SSLVerify.ToLowerString());
            config = config.Replace("${ssl.ssl_shutdown_wait_time}", "3");
            config = config.Replace("${ssl.sni}", HostAddress);
            config = config.Replace("${ssl.cert}", cert_path);

            config = config.Replace("${tcp.fast_open}", EnableTCPFastOpen ? "true" : "false");
            config = config.Replace("${tcp.connect_time_out}", "5");

            config = config.Replace("${experimental.pipeline_num}", EnablePipeline ? "5" : "0");
            config = config.Replace("${experimental.pipeline_ack_window}", "100");

            if (!isLoadBalancePrepare && LoadBalance.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < LoadBalance.Count; i++)
                {
                    var h = hosts.FindHostByName(LoadBalance[i]);
                    if (h != null && h.EnablePipeline)
                    {
                        string loadConfig = h.PrepareConfig(hosts, true);
                        string path       = Path.Combine(App.Instance.DataPathParent, "balance_config" + i);
                        File.WriteAllText(path, loadConfig);

                        if (sb.Length > 0)
                        {
                            sb.Append(",");
                        }

                        sb.Append($"\"{path}\"");
                    }
                }

                config = config.Replace("${experimental.pipeline_loadbalance_configs}", sb.ToString());
            }
            else
            {
                config = config.Replace("${experimental.pipeline_loadbalance_configs}", string.Empty);
                if (isLoadBalancePrepare)
                {
                    config = config.Replace("${tun.tun_fd}", "-1");
                }
            }

            config = config.Replace("${tun.net_ip}", TunNetIP);
            config = config.Replace("${tun.mtu}", TunMtu.ToString());

            config = config.Replace("${dns.udp_socket_buf}", "8192");
            config = config.Replace("${dns.udp_recv_buf}", "1024");

            config = config.Replace("${dns.up_dns_server}", UpStreamNS);
            config = config.Replace("${dns.up_gfw_dns_server}", GFWUpStreamNS);

            config = config.Replace("${dns.gfwlist}", gfwlist_path);
            config = config.Replace("${route.cn_mainland_ips_file}", cn_ips_path);
            config = config.Replace("${route.proxy_type}", ((int)Route).ToString());

            string proxy_ips_path = Path.Combine(App.Instance.DataPathParent, "proxy_ips");
            string white_ips_path = Path.Combine(App.Instance.DataPathParent, "white_ips");

            File.WriteAllText(proxy_ips_path, string.Empty);
            File.WriteAllText(white_ips_path, string.Empty);

            config = config.Replace("${route.proxy_ips}", proxy_ips_path);
            config = config.Replace("${route.white_ips}", white_ips_path);

            return(config);
        }
Example #26
0
        public string GetField(int field)
        {
            switch (field)
            {
            case 0: return(HostName);

            case 1: return(GameName);

            case 2: return(GameVersion);

            case 3: return(MapName);

            case 4: return(GameType);

            case 5: return(GameVariant);

            case 6: return(NumPlayers.ToString());

            case 7: return(MaxPlayers.ToString());

            case 8: return(GameMode);

            case 9: return((Password ? 1 : 0).ToString());

            case 10: return(TimeLimit.ToString());

            case 11: return(RoundTime.ToString());

            case 12: return(HostPort.ToString());

            case 13: return((Dedicated ? 1 : 0).ToString());

            case 14: return((Ranked ? 1 : 0).ToString());

            case 15: return((AntiCheat ? 1 : 0).ToString());

            case 16: return(OS);

            case 17: return((BattleRecorder ? 1 : 0).ToString());

            case 18: return(BRIndex);

            case 19: return(BRDownload);

            case 20: return((Voip ? 1 : 0).ToString());

            case 21: return((AutoBalance ? 1 : 0).ToString());

            case 22: return((FriendlyFire ? 1 : 0).ToString());

            case 23: return(TKMode);

            case 24: return(StartDelay.ToString());

            case 25: return(SpawnTime.ToString("0.000000", CultureInfo.InvariantCulture));

            case 26: return(ServerText);

            case 27: return(ServerLogo);

            case 28: return(CommunityWebsite);

            case 29: return(ScoreLimit.ToString());

            case 30: return(TicketRatio.ToString());

            case 31: return(TeamRatio.ToString("0.000000", CultureInfo.InvariantCulture));

            case 32: return(Team1Name);

            case 33: return(Team2Name);

            case 34: return((CoopEnabled ? 1 : 0).ToString());

            case 35: return((Pure ? 1 : 0).ToString());

            case 36: return(MapSize.ToString());

            case 37: return((Unlocks ? 1 : 0).ToString());

            case 38: return(Fps.ToString());

            case 39: return((Plasma ? 1 : 0).ToString());

            case 40: return(ReservedSlots.ToString());

            case 41: return(CoopBotRatio.ToString());

            case 42: return(CoopBotCount.ToString());

            case 43: return(CoopBotDifficulty.ToString());

            case 44: return((NoVehicles ? 1 : 0).ToString());

            default:
                return("");
            }
        }
Example #27
0
        private static void SendCommand(HostPort peer, Cmd cmd)
        {
            var cmdJson = JsonConvert.SerializeObject(cmd);

            SendCommand(peer, cmdJson);
        }