Ejemplo n.º 1
0
        public void Start(int port)
        {
            if (port < 1 || port > 65535)
            {
                throw new ArgumentOutOfRangeException(nameof(port));
            }

            if (_listenningStatus == ServerStatusType.None)
            {
                try
                {
                    _socket?.Dispose();
                }
                catch (Exception ex)
                {
                    if (_showFail)
                    {
                        Debug.Fail(ex.Message, ex.StackTrace);
                    }
                }
                finally
                {
                    _socket = null;
                }
                _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                {
                    ReceiveTimeout    = DefaultReceiveTimeout,
                    SendTimeout       = DefaultSendTimeout,
                    ReceiveBufferSize = DefaultReceiveBufferSize,
                    SendBufferSize    = DefaultSendBufferSize
                };

                try
                {
                    IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, port);
                    _socket.Bind(localEndPoint);
                    _socket.Listen((int)SocketOptionName.MaxConnections);
                    _socket.BeginAccept(new AsyncCallback(AcceptCallback), null);
                    _listenningStatus = ServerStatusType.Listening;
                }
                catch (Exception ex)
                {
                    if (_showFail)
                    {
                        Debug.Fail(ex.Message, ex.StackTrace);
                    }
                    _listenningStatus = ServerStatusType.PortError;
                }
                finally
                {
                    CallChangeStatus();
                }
            }
        }
        public static void SetStatus(ServerStatusType type, int time, int nextTime)
        {
            ServerStatus.Status   = type;
            ServerStatus.Time     = time;
            ServerStatus.NextTime = nextTime;

            if (ServerStatus.OnServerStatusChanged != null)
            {
                ServerStatus.OnServerStatusChanged(type, time, nextTime);
            }
        }
Ejemplo n.º 3
0
        private static void OnServerStatusChanged(ServerStatusType type, int time, int args)
        {
            switch (type)
            {
            case ServerStatusType.SHUTDOWN_STARTED:
                ClientConnectionManager.SendShutdownStartedMessageToConnections(LogicMath.Max(time - TimeUtil.GetTimestamp(), 0));
                break;

            case ServerStatusType.MAINTENANCE:
                ClientConnectionManager.DisconnectConnections();
                break;
            }
        }
Ejemplo n.º 4
0
 private static void OnServerStatusChanged(ServerStatusType type, int time, int nextTime)
 {
     for (int i = 1; i < EnvironmentSettings.SERVER_TYPE_COUNT; i++)
     {
         for (int j = 0, count = Core.Network.ServerManager.GetServerCount(i); j < count; j++)
         {
             ServerMessageManager.SendMessage(new ServerStatusMessage
             {
                 Type     = type,
                 Time     = time,
                 NextTime = nextTime
             }, i, j);
         }
     }
 }
Ejemplo n.º 5
0
        private NodeServerDataModel SetData(string packageName, ServerStatusType status, string error, string url, ServerType serverType)
        {
            NodeServerDataModel node = null;

            if (_packages.ContainsKey(packageName))
            {
                node = _packages[packageName];
            }
            else
            {
                node = new NodeServerDataModel();
            }
            node.PackageName = packageName;
            node.Status      = status;
            node.Url         = url;
            node.Error       = error;
            node.ServerType  = serverType;
            return(node);
        }
Ejemplo n.º 6
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    Tag = null;
                    _listenningStatus = ServerStatusType.None;
                }

                foreach (var client in _clients.ToArray())
                {
                    client.Dispose();
                }
                _clients.Clear();
                try
                {
                    _socket?.Dispose();
                }
                catch (Exception ex)
                {
                    if (_showFail)
                    {
                        Debug.Fail(ex.Message, ex.StackTrace);
                    }
                }
                finally
                {
                    _socket            = null;
                    OnChangeStatus     = null;
                    OnClientConnect    = null;
                    OnClientDisconnect = null;
                    OnReceive          = null;
                }
                _disposedValue = true;
            }
        }
Ejemplo n.º 7
0
 internal void StopFinalize()
 {
     lock (syncObjectClients) _clients.Clear();
     try
     {
         _socket?.Dispose();
     }
     catch (Exception ex)
     {
         if (_showFail)
         {
             Debug.Fail(ex.Message, ex.StackTrace);
         }
     }
     finally
     {
         _socket = null;
         if (_listenningStatus != ServerStatusType.None)
         {
             _listenningStatus = ServerStatusType.None;
             CallChangeStatus();
         }
     }
 }
Ejemplo n.º 8
0
 internal ServerStatusArgs(ServerStatusType serverStatus)
 {
     Status = serverStatus;
 }