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); } }
public WorldServer(Guid id, ScsTcpEndPoint endpoint, int accountLimit, string worldGroup) { Id = id; Endpoint = endpoint; AccountLimit = accountLimit; WorldGroup = worldGroup; }
/// <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; }
/// <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; }
public WorldServerDTO(Guid id, ScsTcpEndPoint endpoint, int accountLimit) { ConnectedAccounts = new Dictionary <string, long>(); ConnectedCharacters = new Dictionary <string, long>(); Id = id; Endpoint = endpoint; AccountLimit = accountLimit; }
/// <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; }
/// <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; }
public SslScsTcpClient(ScsTcpEndPoint serverEndPoint, X509Certificate2 serverCertificate , string sslHostAddress , SslScsAuthMode authenticationMechanism , X509Certificate clientCertificate , RemoteCertificateValidationCallback validateCertificate) : this(serverEndPoint, serverCertificate, sslHostAddress, authenticationMechanism, clientCertificate) { _validateCertificate = validateCertificate; }
/// <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; }
/// <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(); }
/// <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; }
/// <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(); }
/// <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(); }
/// <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(); }
/// <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); }
/// <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(); }
/// <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); }
/// <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); }
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."); } } }
/// <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); }
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); } }
/// <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; }
/// <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; }
/// <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; }
/// <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; }
/// <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; }
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) { }
/// <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; }
/// <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;
/// <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; }