Example #1
0
 /// <summary>
 /// Disposes the socket and handles the disconnected user.
 /// </summary>
 public void Dispose()
 {
     if (Disposed)
     {
         return;
     }
     Disposed = true;
     ServerLogger.Connection($"{ConnectionData.Username} disconnected from the server. Connection [{ID}] closed.");
     if (_Socket != null)
     {
         _Socket.Dispose();
     }
     HandleDisconnect();
 }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConnectionCore"/> class.
        /// </summary>
        public ConnectionCore(int id, Socket handler, ConnectionController controller)
        {
            // Set the ID
            ID = id;

            // Set the ConnectionController
            Controller = controller;

            // Set the Socket
            _Socket = handler;

            // Start receiving information
            BeginReceive();

            // Set the IP in the ConnectionInformation
            ConnectionData = new ConnectionData(_Socket.RemoteEndPoint.ToString());

            // Log everything
            ServerLogger.Connection($"Accepted connection: {id} > {ConnectionData.ClientIP.ToString().Replace("::ffff:", "")}");
        }