コード例 #1
0
 public void UnregisterWorldserver(string groupName, ScsTcpEndPoint endpoint)
 {
     try
     {
         if (ServerCommunicationHelper.Instance.WorldserverGroups.Any(g => g.GroupName == groupName) &&
             ServerCommunicationHelper.Instance.WorldserverGroups.SingleOrDefault(g => g.GroupName == groupName).Servers.Any(w => w.Endpoint.Equals(endpoint)))
         {
             //servergroup does exist with the given ipaddress
             RemoveWorldFromWorldserver(endpoint, groupName);
         }
         else if (!ServerCommunicationHelper.Instance.WorldserverGroups.Any(g => g.GroupName == groupName) &&
                  !ServerCommunicationHelper.Instance.WorldserverGroups.Any(sgi => sgi.Servers.Any(w => w.Endpoint.Equals(endpoint))))
         {
             //servergroup doesnt exist and world is not in a group named like the given servergroup and in no other
             Logger.Log.InfoFormat($"World with address {endpoint} has already been unregistered before.");
         }
         else if (!ServerCommunicationHelper.Instance.WorldserverGroups.Any(g => g.GroupName == groupName) &&
                  ServerCommunicationHelper.Instance.WorldserverGroups.Any(sgi => sgi.Servers.Any(w => w.Endpoint.Equals(endpoint))))
         {
             //servergroup does not exist but world does run in a different servergroup
             WorldserverGroupDTO worldserverGroupDTO = ServerCommunicationHelper.Instance.WorldserverGroups.SingleOrDefault(sgi => sgi.Servers.Any(w => w.Endpoint.Equals(endpoint)));
             RemoveWorldFromWorldserver(endpoint, worldserverGroupDTO.GroupName);
         }
     }
     catch (Exception ex)
     {
         Logger.Log.Error($"Registering world {endpoint} failed.", ex);
     }
 }
コード例 #2
0
 public WorldServer(Guid id, ScsTcpEndPoint endpoint, int accountLimit, string worldGroup)
 {
     Id           = id;
     Endpoint     = endpoint;
     AccountLimit = accountLimit;
     WorldGroup   = worldGroup;
 }
コード例 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="serverEndPoint"></param>
 /// <param name="serverCert"></param>
 /// <param name="clientCert"></param>
 /// <param name="nombreServerCert"></param>
 public ScsTcpSslClient(ScsTcpEndPoint serverEndPoint, X509Certificate2 serverCert, X509Certificate2 clientCert, string nombreServerCert)
 {
     _serverEndPoint   = serverEndPoint;
     _serverCert       = serverCert;
     _clientCert       = clientCert;
     _nombreServerCert = nombreServerCert;
 }
コード例 #4
0
ファイル: SslScsTcpServer.cs プロジェクト: SariSultan/scs
 /// <summary>
 /// Creates a new ScsTcpServer object.
 /// </summary>
 /// <param name="endPoint">The endpoint address of the server to listen incoming connections</param>
 /// <param name="serverCert"></param>
 /// <param name="clientCerts"></param>
 /// <param name="authMode"></param>
 public ScsSslTcpServer(ScsTcpEndPoint endPoint, X509Certificate serverCert, List <X509Certificate2> clientCerts, SslScsAuthMode authMode)
 {
     _endPoint    = endPoint;
     _serverCert  = serverCert;
     _clientCerts = clientCerts;
     _authMode    = authMode;
 }
コード例 #5
0
 public WorldServerDTO(Guid id, ScsTcpEndPoint endpoint, int accountLimit)
 {
     ConnectedAccounts   = new Dictionary <string, long>();
     ConnectedCharacters = new Dictionary <string, long>();
     Id           = id;
     Endpoint     = endpoint;
     AccountLimit = accountLimit;
 }
コード例 #6
0
ファイル: SslScsTcpClient.cs プロジェクト: SariSultan/scs
 /// <summary>
 ///
 /// </summary>
 /// <param name="serverEndPoint">The endpoint address to connect to the server</param>
 /// <param name="serverCertificate">The server certificate (public key only)</param>
 /// <param name="sslHostAddress">SSL Host address that will be used for authentication</param>
 /// <param name="authenticationMechanism">The used authentication mechanism</param>
 /// <param name="clientCertificate">The client certificate (public and private keys)
 /// This is optional and it is used in case of mutual authentication</param>
 public SslScsTcpClient(ScsTcpEndPoint serverEndPoint, X509Certificate2 serverCertificate
                        , string sslHostAddress
                        , SslScsAuthMode authenticationMechanism
                        , X509Certificate clientCertificate)
     : this(serverEndPoint, serverCertificate, sslHostAddress, authenticationMechanism)
 {
     _clientCertificate = clientCertificate;
 }
コード例 #7
0
ファイル: ScsTcpSslClient.cs プロジェクト: abdulfseg/scs
 /// <summary>
 ///
 /// </summary>
 /// <param name="serverEndPoint"></param>
 /// <param name="serverCert"></param>
 /// <param name="clientCert"></param>
 /// <param name="nombreServerCert"></param>
 /// <param name="remoteCertificateFalidatonCallback"></param>
 /// <param name="localCertificateSelectionCallback"></param>
 public ScsTcpSslClient(ScsTcpEndPoint serverEndPoint, X509Certificate2Collection clientCert, string nombreServerCert, int pingTimeout, Func <object, X509Certificate, X509Chain, SslPolicyErrors, bool> remoteCertificateFalidatonCallback, Func <object, string, X509CertificateCollection, X509Certificate, string[], X509Certificate> localCertificateSelectionCallback) : base(pingTimeout)
 {
     _serverEndPoint   = serverEndPoint;
     _clientCerts      = clientCert;
     _nombreServerCert = nombreServerCert;
     _remoteCertificateFalidatonCallback = remoteCertificateFalidatonCallback;
     _localCertificateSelectionCallback  = localCertificateSelectionCallback;
 }
コード例 #8
0
ファイル: SslScsTcpClient.cs プロジェクト: SariSultan/scs
 public SslScsTcpClient(ScsTcpEndPoint serverEndPoint, X509Certificate2 serverCertificate
                        , string sslHostAddress
                        , SslScsAuthMode authenticationMechanism
                        , X509Certificate clientCertificate
                        , RemoteCertificateValidationCallback validateCertificate)
     : this(serverEndPoint, serverCertificate, sslHostAddress, authenticationMechanism, clientCertificate)
 {
     _validateCertificate = validateCertificate;
 }
コード例 #9
0
ファイル: SslScsTcpClient.cs プロジェクト: SariSultan/scs
 /// <summary>
 /// Creates a new ScsTcpClient object.
 /// </summary>
 /// <param name="serverEndPoint">The endpoint address to connect to the server</param>
 /// <param name="serverCertificate">The server certificate (public key only)</param>
 /// <param name="sslHostAddress">SSL Host address that will be used for authentication</param>
 /// <param name="authenticationMechanism">The used authentication mechanism</param>
 public SslScsTcpClient(ScsTcpEndPoint serverEndPoint, X509Certificate2 serverCertificate
                        , string sslHostAddress
                        , SslScsAuthMode authenticationMechanism = SslScsAuthMode.ServerAuth
                        )
 {
     _serverEndPoint             = serverEndPoint;
     _serverCertificate          = serverCertificate;
     _sslHostAddress             = sslHostAddress;
     _sslAuthenticationMechanism = authenticationMechanism;
 }
コード例 #10
0
        /// <summary>
        /// Creates a new TcpCommunicationChannel object.
        ///
        /// </summary>
        /// <param name="clientSocket">A connected Socket object that is
        ///             used to communicate over network</param>
        public TcpCommunicationChannel(Socket clientSocket)
        {
            this._clientSocket         = clientSocket;
            this._clientSocket.NoDelay = true;
            IPEndPoint ipEndPoint = (IPEndPoint)this._clientSocket.RemoteEndPoint;

            this._remoteEndPoint = new ScsTcpEndPoint(ipEndPoint.Address.ToString(), ipEndPoint.Port);
            this._buffer         = new byte[4096];
            this._syncLock       = new object();
        }
コード例 #11
0
 /// <summary>
 /// Creates a new TcpConnectionListener for given endpoint.
 /// </summary>
 /// <param name="endPoint">The endpoint address of the server to listen incoming connections</param>
 /// <param name="serverCert"></param>
 /// <param name="clientCerts"></param>
 /// <param name="authMode"></param>
 /// <param name="validationCallback"></param>
 public TcpSslConnectionListener(ScsTcpEndPoint endPoint, X509Certificate serverCert
                                 , List <X509Certificate2> clientCerts
                                 , SslScsAuthMode authMode
                                 , RemoteCertificateValidationCallback validationCallback = null)
 {
     _endPoint           = endPoint;
     _serverCertificate  = serverCert;
     _clientCertificates = clientCerts;
     _authMode           = authMode;
     _validationCallback = validationCallback;
 }
コード例 #12
0
        /// <summary>
        /// Creates a new TcpCommunicationChannel object.
        /// </summary>
        public TcpSslCommunicationChannel(TcpClient client, SslStream sslStream)
        {
            _client         = client;
            _client.NoDelay = true;
            _sslStream      = sslStream;
            var endpoint = (IPEndPoint)client.Client.RemoteEndPoint;

            _remoteEndPoint = new ScsTcpEndPoint(endpoint.Address.ToString(), endpoint.Port);
            _buffer         = new byte[ReceiveBufferSize];
            _syncLock       = new object();
        }
コード例 #13
0
        /// <summary>
        /// Creates a new TcpCommunicationChannel object.
        /// </summary>
        /// <param name="clientSocket">A connected Socket object that is
        /// used to communicate over network</param>
        public TcpCommunicationChannel(Socket clientSocket)
        {
            _clientSocket = clientSocket;
            _clientSocket.NoDelay = true;

            var ipEndPoint = (IPEndPoint)_clientSocket.RemoteEndPoint;
            _remoteEndPoint = new ScsTcpEndPoint(ipEndPoint.Address.ToString(), ipEndPoint.Port);

            _buffer = new byte[ReceiveBufferSize];
            _syncLock = new object();
        }
コード例 #14
0
        /// <summary>
        /// Creates a new TcpCommunicationChannel object.
        /// </summary>
        /// <param name="endpoint"></param>
        /// <param name="client"></param>
        /// <param name="stream"></param>
        public TcpSslCommunicationChannel(ScsTcpEndPoint endpoint, TcpClient client, SslStream stream)
        {
            _client         = client;
            _client.NoDelay = true;

            _sslStream = stream;

            _remoteEndPoint = endpoint;

            _buffer   = new byte[ReceiveBufferSize];
            _syncLock = new object();
        }
コード例 #15
0
        /// <summary>
        /// Creates a new TcpCommunicationChannel object.
        /// </summary>
        /// <param name="clientSocket">
        /// A connected Socket object that is used to communicate over network
        /// </param>
        public TcpCommunicationChannel(Socket clientSocket)
        {
            _clientSocket         = clientSocket;
            _clientSocket.NoDelay = true;
            IPEndPoint ipEndPoint = (IPEndPoint)_clientSocket.RemoteEndPoint;

            _remoteEndPoint     = new ScsTcpEndPoint(ipEndPoint.Address, ipEndPoint.Port);
            _buffer             = new byte[RECEIVE_BUFFER_SIZE];
            _syncLock           = new object();
            _highPriorityBuffer = new ConcurrentQueue <byte[]>();
            _lowPriorityBuffer  = new ConcurrentQueue <byte[]>();
            CancellationToken cancellationToken = _sendCancellationToken.Token;

            _sendTask = StartSendingAsync(SendInterval, new TimeSpan(0, 0, 0, 0, 10), cancellationToken);
        }
コード例 #16
0
        /// <summary>
        /// Creates a new TcpCommunicationChannel object.
        /// </summary>
        /// <param name="clientSocket">A connected Socket object that is
        /// used to communicate over network</param>
        public TcpCommunicationChannel(Socket clientSocket)
        {
            _clientSocket         = clientSocket;
            _clientSocket.NoDelay = true;

            var ipEndPoint = (IPEndPoint)_clientSocket.RemoteEndPoint;

            _remoteEndPoint = new ScsTcpEndPoint(ipEndPoint.Address.ToString(), ipEndPoint.Port);

            _buffer   = new byte[ReceiveBufferSize];
            _syncLock = new object();

            // Registered event for timer
            _timerConnect.Elapsed += _timerConnect_Elapsed;
            _timerConnect.Start();
        }
コード例 #17
0
        /// <summary>
        /// Creates a new TcpCommunicationChannel object.
        /// </summary>
        /// <param name="clientSocket">
        /// A connected Socket object that is used to communicate over network
        /// </param>
        public TcpCommunicationChannel(Socket clientSocket)
        {
            _clientSocket         = clientSocket;
            _clientSocket.NoDelay = true;
            IPEndPoint ipEndPoint = (IPEndPoint)_clientSocket.RemoteEndPoint;

            _remoteEndPoint     = new ScsTcpEndPoint(ipEndPoint.Address, ipEndPoint.Port);
            _buffer             = new byte[RECEIVE_BUFFER_SIZE];
            _syncLock           = new object();
            _highPriorityBuffer = new ConcurrentQueue <byte[]>();
            _lowPriorityBuffer  = new ConcurrentQueue <byte[]>();
            CancellationToken cancellationToken = _sendCancellationToken.Token;

            // initialize lagging mode
            bool isLagMode = string.Equals(ConfigurationManager.AppSettings["LagMode"], "true", StringComparison.CurrentCultureIgnoreCase);

            _sendTask = StartSendingAsync(SendInterval, new TimeSpan(0, 0, 0, 0, isLagMode ? 1000 : 10), cancellationToken);
        }
コード例 #18
0
        /// <summary>
        /// Creates a new TcpCommunicationChannel object.
        /// </summary>
        /// <param name="clientSocket">
        /// A connected Socket object that is used to communicate over network
        /// </param>
        public TcpCommunicationChannel(Socket clientSocket)
        {
            _clientSocket         = clientSocket;
            _clientSocket.NoDelay = true;
            IPEndPoint ipEndPoint = (IPEndPoint)_clientSocket.RemoteEndPoint;

            _remoteEndPoint     = new ScsTcpEndPoint(ipEndPoint.Address, ipEndPoint.Port);
            _buffer             = new byte[ReceiveBufferSize];
            _highPriorityBuffer = new ConcurrentQueue <byte[]>();
            _lowPriorityBuffer  = new ConcurrentQueue <byte[]>();
            CancellationToken cancellationToken = _sendCancellationToken.Token;

            // initialize lagging mode
            bool isLagMode = string.Equals(ConfigurationManager.AppSettings["LagMode"], "true", StringComparison.CurrentCultureIgnoreCase);

            Observable.Interval(new TimeSpan(0, 0, 0, 0, isLagMode ? 1000 : 10))
            .Subscribe(s => SendInterval(), cancellationToken);
        }
コード例 #19
0
        private void RemoveWorldFromWorldserver(ScsTcpEndPoint endpoint, string groupName)
        {
            WorldserverDTO worldserverToRemove = ServerCommunicationHelper.Instance.WorldserverGroups
                                                 .SingleOrDefault(g => g.GroupName == groupName).Servers.SingleOrDefault(w => w.Endpoint.Equals(endpoint));

            ServerCommunicationHelper.Instance.WorldserverGroups.SingleOrDefault(g => g.GroupName == groupName).Servers.Remove(worldserverToRemove);
            ServerCommunicationHelper.Instance.Worldservers.Remove(worldserverToRemove);
            Logger.Log.InfoFormat($"World {worldserverToRemove.Id} with address {endpoint} has been unregistered successfully.");

            if (!ServerCommunicationHelper.Instance.WorldserverGroups.SingleOrDefault(g => g.GroupName == groupName)?.Servers.Any() ?? false)
            {
                WorldserverGroupDTO worldserverGroup = ServerCommunicationHelper.Instance.WorldserverGroups.SingleOrDefault(g => g.GroupName == groupName);

                if (worldserverGroup != null)
                {
                    ServerCommunicationHelper.Instance.WorldserverGroups.Remove(worldserverGroup);
                    Logger.Log.InfoFormat($"World server group {groupName} has been removed as no world was left.");
                }
            }
        }
コード例 #20
0
        /// <summary>
        /// Creates a new TcpCommunicationChannel object.
        /// </summary>
        /// <param name="clientSocket">
        /// A connected Socket object that is used to communicate over network
        /// </param>
        public TcpCommunicationChannel(Socket clientSocket)
        {
            _clientSocket         = clientSocket;
            _clientSocket.NoDelay = true;

            // initialize lagging mode
            bool isLagMode = System.Configuration.ConfigurationManager.AppSettings["LagMode"].ToLower() == "true";

            var ipEndPoint = (IPEndPoint)_clientSocket.RemoteEndPoint;

            _remoteEndPoint = new ScsTcpEndPoint(ipEndPoint.Address.ToString(), ipEndPoint.Port);

            _buffer   = new byte[ReceiveBufferSize];
            _syncLock = new object();

            _highPriorityBuffer = new ConcurrentQueue <byte[]>();
            _lowPriorityBuffer  = new ConcurrentQueue <byte[]>();
            CancellationToken cancellationToken = _sendCancellationToken.Token;

            _sendTask = StartSending(SendInterval, new TimeSpan(0, 0, 0, 0, isLagMode ? 1000 : 10), cancellationToken);
        }
コード例 #21
0
        private bool CheckGeneralLog(NetworkClient client)
        {
            ScsTcpEndPoint currentEndpoint = client.RemoteEndPoint as ScsTcpEndPoint;

            if (GeneralLog.Any())
            {
                foreach (var item in GeneralLog.Where(cl => cl.Key.Equals(currentEndpoint.IpAddress) && (DateTime.Now - cl.Value).Seconds > 3).ToList())
                {
                    GeneralLog.Remove(item.Key);
                }
            }

            if (GeneralLog.ContainsKey(currentEndpoint.IpAddress))
            {
                return(false);
            }
            else
            {
                GeneralLog.Add(currentEndpoint.IpAddress, DateTime.Now);
                return(true);
            }
        }
コード例 #22
0
 /// <summary>
 /// Creates a new ScsTcpClient object.
 /// </summary>
 /// <param name="serverEndPoint">The endpoint address to connect to the server</param>
 public ScsTcpClient(ScsTcpEndPoint serverEndPoint)
 {
     _serverEndPoint = serverEndPoint;
 }
コード例 #23
0
ファイル: ScsTcpServer.cs プロジェクト: aerzy/OpenNos
 /// <summary>
 /// Creates a new ScsTcpServer object.
 /// </summary>
 /// <param name="endPoint">The endpoint address of the server to listen incoming connections</param>
 public ScsTcpServer(ScsTcpEndPoint endPoint)
 {
     _endPoint = endPoint;
 }
コード例 #24
0
 /// <summary>
 /// Creates a new TcpConnectionListener for given endpoint.
 ///
 /// </summary>
 /// <param name="endPoint">The endpoint address of the server to listen incoming connections</param>
 public TcpConnectionListener(ScsTcpEndPoint endPoint)
 {
     this._endPoint = endPoint;
 }
コード例 #25
0
        /// <summary>
        /// 实例化CastleService
        /// </summary>
        /// <param name="config"></param>
        public CastleService(CastleServiceConfiguration config)
        {
            this.config = config;

            if (string.Compare(config.Host, "any", true) == 0)
            {
                config.Host = IPAddress.Loopback.ToString();
                epServer    = new ScsTcpEndPoint(config.Port);
            }
            else
            {
                epServer = new ScsTcpEndPoint(config.Host, config.Port);
            }

            this.server = ScsServerFactory.CreateServer(epServer);
            this.server.ClientConnected    += server_ClientConnected;
            this.server.ClientDisconnected += server_ClientDisconnected;
            this.server.WireProtocolFactory = new CustomWireProtocolFactory(config.Compress, config.Encrypt);

            //服务端注入内存处理
            this.container          = new SimpleServiceContainer(CastleFactoryType.Local);
            this.container.OnError += error => { if (OnError != null)
                                                 {
                                                     OnError(error);
                                                 }
            };
            this.container.OnLog += (log, type) => { if (OnLog != null)
                                                     {
                                                         OnLog(log, type);
                                                     }
            };

            //实例化SmartThreadPool
            var stp = new STPStartInfo
            {
                IdleTimeout      = config.Timeout * 1000,
                MaxWorkerThreads = Math.Max(config.MaxCalls, 10),
                MinWorkerThreads = 5,
                ThreadPriority   = ThreadPriority.Normal,
                WorkItemPriority = WorkItemPriority.Normal
            };

            //创建线程池
            smart = new SmartThreadPool(stp);
            smart.Start();

            //创建并发任务组
            var group = smart.CreateWorkItemsGroup(2);

            group.Start();

            //实例化调用者
            var status = new ServerStatusService(server, config, container);

            this.caller = new ServiceCaller(group, status);

            //判断是否启用httpServer
            if (config.HttpEnabled)
            {
                //设置默认的解析器
                IHttpApiResolver resolver = new DefaultApiResolver();

                //判断是否配置了HttpType
                if (config.HttpType != null && typeof(IHttpApiResolver).IsAssignableFrom(config.HttpType))
                {
                    resolver = Activator.CreateInstance(config.HttpType) as IHttpApiResolver;
                }

                var httpCaller = new HttpServiceCaller(group, config, container);

                //刷新服务委托
                status.OnRefresh += () => httpCaller.InitCaller(resolver);

                //初始化调用器
                httpCaller.InitCaller(resolver);

                var handler = new HttpServiceHandler(httpCaller);
                var factory = new HttpRequestHandlerFactory(handler);
                this.httpServer = new HTTPServer(factory, config.HttpPort);
            }

            //绑定事件
            MessageCenter.Instance.OnError += Instance_OnError;
        }
コード例 #26
0
 /// <summary>
 /// Creates a new ScsTcpClient object.
 /// </summary>
 /// <param name="serverEndPoint">The endpoint address to connect to the server</param>
 public ScsTcpClient(ScsTcpEndPoint serverEndPoint, int pingTimeout) : base(pingTimeout)
 {
     _serverEndPoint = serverEndPoint;
 }
コード例 #27
0
ファイル: ScsTcpSslClient.cs プロジェクト: abdulfseg/scs
 public ScsTcpSslClient(ScsTcpEndPoint serverEndPoint, X509Certificate2 clientCert, string nombreServerCert, int pingTimeout,
                        Func <object, X509Certificate, X509Chain, SslPolicyErrors, bool> remoteCertificateFalidatonCallback,
                        Func <object, string, X509CertificateCollection, X509Certificate, string[], X509Certificate> localCertificateSelectionCallback)
     : this(serverEndPoint, new X509Certificate2Collection(clientCert), nombreServerCert, pingTimeout, remoteCertificateFalidatonCallback, localCertificateSelectionCallback)
 {
 }
コード例 #28
0
 /// <summary>
 /// Creates a new ScsTcpClient object.
 /// </summary>
 /// <param name="serverEndPoint">The endpoint address to connect to the server</param>
 /// <param name="existingSocketInformation">The existing socket information.</param>
 public ScsTcpClient(ScsTcpEndPoint serverEndPoint, SocketInformation?existingSocketInformation)
 {
     _serverEndPoint            = serverEndPoint;
     _existingSocketInformation = existingSocketInformation;
 }
コード例 #29
0
 /// <summary>
 /// Creates a new TcpConnectionListener for given endpoint.
 /// </summary>
 /// <param name="endPoint">The endpoint address of the server to listen incoming connections</param>
 public TcpConnectionListener(ScsTcpEndPoint endPoint) => _endPoint = endPoint;
コード例 #30
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="endPoint"></param>
 /// <param name="serverCert"></param>
 /// <param name="clientCert"></param>
 public ScsTcpSslServer(ScsTcpEndPoint endPoint, X509Certificate2 serverCert, List <X509Certificate2> clientCerts)
 {
     _endPoint    = endPoint;
     _serverCert  = serverCert;
     _clientCerts = clientCerts;
 }