Click here to Skip to main content
12,066,893 members (53,483 online)
Click here to Skip to main content

Stats

392.2K views
24.7K downloads
161 bookmarked
Posted

A Complete FTP Server

, 30 May 2005
This article presents a fully functional implementation of a FTP server.
/****************************************************************/
/*																*/
/*  OnlineUsersPage.cpp											*/
/*																*/
/*  Implementation of the COnlineUsersPage class.				*/
/*	This class is a part of Quick 'n Easy FTP Server.			*/
/*																*/
/*  Programmed by Pablo van der Meer							*/
/*  Copyright Pablo Software Solutions 2005						*/
/*	http://www.pablosoftwaresolutions.com						*/
/*																*/
/*  Last updated: May 28, 2005									*/
/*																*/
/****************************************************************/


#include "stdafx.h"
#include "FTPServerApp.h"
#include "FTPServer.h"
#include "OnlineUsersPage.h"
#include "ApplicationDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern CFTPServer theServer;

IMPLEMENT_DYNCREATE(COnlineUsersPage, CDialog)

COnlineUsersPage::COnlineUsersPage() : CDialog(COnlineUsersPage::IDD)
{
	//{{AFX_DATA_INIT(COnlineUsersPage)
	//}}AFX_DATA_INIT
}

COnlineUsersPage::~COnlineUsersPage()
{
}

void COnlineUsersPage::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COnlineUsersPage)
	DDX_Control(pDX, IDC_ONLINE_USERS, m_OnlineUsers);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(COnlineUsersPage, CDialog)
	//{{AFX_MSG_MAP(COnlineUsersPage)
	ON_WM_SIZE()
	ON_WM_CONTEXTMENU()
	ON_COMMAND(IDC_KICK_USER, OnKickUser)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()



/********************************************************************/
/*																	*/
/* Function name : OnInitDialog										*/		
/* Description   : Called by the framework in response to the		*/
/*				   WM_INITDIALOG message.							*/
/*																	*/
/********************************************************************/
BOOL COnlineUsersPage::OnInitDialog() 
{
	CDialog::OnInitDialog();

	m_OnlineUsers.InsertColumn(0, "ThreadID");		
	m_OnlineUsers.InsertColumn(1, "Username");	
	m_OnlineUsers.InsertColumn(2, "IP Adress");	
	m_OnlineUsers.InsertColumn(3, "Login Time");
	
	DWORD dwStyle = m_OnlineUsers.GetExtendedStyle();
	dwStyle |= LVS_EX_FULLROWSELECT;
    m_OnlineUsers.SetExtendedStyle(dwStyle);
	return TRUE;
}


/********************************************************************/
/*																	*/
/* Function name : OnSize											*/		
/* Description   : Handle WM_SIZE message							*/
/*																	*/
/********************************************************************/
void COnlineUsersPage::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
	if (IsWindow(::GetDlgItem(m_hWnd, IDC_ONLINE_USERS)))
	{
		CRect rect;
		GetClientRect(rect);
		m_OnlineUsers.MoveWindow(rect);
		m_OnlineUsers.SetColumnWidth(0, 0);
		m_OnlineUsers.SetColumnWidth(1, rect.Width()/3-2);
		m_OnlineUsers.SetColumnWidth(2, rect.Width()/3-2);
		m_OnlineUsers.SetColumnWidth(3, rect.Width()/3-2);
	}	
}


/********************************************************************/
/*																	*/
/* Function name : AddUser											*/
/* Description   : Add new connected user to list					*/
/*																	*/
/********************************************************************/
void COnlineUsersPage::AddUser(DWORD nThreadID, LPCTSTR lpszName, LPCTSTR lpszAddress)
{
	CString strThreadID;
	strThreadID.Format("%d", nThreadID);

	LVFINDINFO info;
	
	info.flags = LVFI_PARTIAL|LVFI_STRING;
	info.psz = (LPCTSTR)strThreadID;

	int nIndex = m_OnlineUsers.FindItem(&info);
	if (nIndex == -1)
	{
		nIndex = m_OnlineUsers.InsertItem(0, strThreadID);
	}

	m_OnlineUsers.SetItemText(nIndex, 1, lpszName);
	m_OnlineUsers.SetItemText(nIndex, 2, lpszAddress);
	m_OnlineUsers.SetItemText(nIndex, 3, CTime::GetCurrentTime().Format("%H:%M:%S"));
	
}


/********************************************************************/
/*																	*/
/* Function name : RemoveUser										*/
/* Description   : Remove disconnected user from list				*/
/*																	*/
/********************************************************************/
void COnlineUsersPage::RemoveUser(DWORD nThreadID)
{
	LVFINDINFO info;
	
	CString strThreadID;
	strThreadID.Format("%d", nThreadID);

	info.flags = LVFI_PARTIAL|LVFI_STRING;
	info.psz = (LPCTSTR)strThreadID;

	int nIndex = m_OnlineUsers.FindItem(&info);
	if (nIndex != -1)
	{
		m_OnlineUsers.DeleteItem(nIndex);
	}
}


/********************************************************************/
/*																	*/
/* Function name : OnContextMenu									*/
/* Description   : Show context menu								*/
/*																	*/
/********************************************************************/
void COnlineUsersPage::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	// get selected user
	int nIndex = m_OnlineUsers.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); 
    if(nIndex == -1)
        return;

	CMenu menu;
	menu.LoadMenu(MAKEINTRESOURCE(IDR_ONLINE_MENU));
	menu.GetSubMenu(0)->TrackPopupMenu(0, point.x, point.y, this, NULL);			

}


/********************************************************************/
/*																	*/
/* Function name : OnKickUser										*/
/* Description   : Close connection for this user(s)				*/
/*																	*/
/********************************************************************/
void COnlineUsersPage::OnKickUser() 
{
	int nIndex = m_OnlineUsers.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); 
	while (nIndex != -1)
	{
		CString strThreadID = m_OnlineUsers.GetItemText(nIndex, 0);
		PostThreadMessage(atoi(strThreadID), WM_QUIT, 0 ,0);
		nIndex = m_OnlineUsers.GetNextItem(nIndex, LVNI_ALL | LVNI_SELECTED);
	}
}


void COnlineUsersPage::OnCancel() 
{
//	CDialog::OnCancel();
}

void COnlineUsersPage::OnOK() 
{
//	CDialog::OnOK();
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Pablo van der Meer
Web Developer
Netherlands Netherlands
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160208.1 | Last Updated 30 May 2005
Article Copyright 2002 by Pablo van der Meer
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid