OnlineUsersPage.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /****************************************************************/
  2. /* */
  3. /* OnlineUsersPage.cpp */
  4. /* */
  5. /* Implementation of the COnlineUsersPage class. */
  6. /* This class is a part of the FTP Server Application */
  7. /* */
  8. /* Programmed by LYFZ van der Meer */
  9. /* Copyright LYFZ Software Solutions 2002 */
  10. /* http://www.LYFZvandermeer.nl */
  11. /* */
  12. /* Last updated: 10 july 2002 */
  13. /* */
  14. /****************************************************************/
  15. #include "stdafx.h"
  16. #include "DBServer.h"
  17. #include "theDBServer.h"
  18. #include "OnlineUsersPage.h"
  19. #include "UserAccountsDlg.h"
  20. #include "DBServerDlg.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. extern CStringArray g_connuserarray;
  27. extern CStringArray g_logintimearray;
  28. extern CtheDBServer theServer;
  29. IMPLEMENT_DYNCREATE(COnlineUsersPage, CDialog)
  30. COnlineUsersPage::COnlineUsersPage() : CDialog(COnlineUsersPage::IDD)
  31. {
  32. //{{AFX_DATA_INIT(COnlineUsersPage)
  33. //}}AFX_DATA_INIT
  34. }
  35. COnlineUsersPage::~COnlineUsersPage()
  36. {
  37. }
  38. void COnlineUsersPage::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(COnlineUsersPage)
  42. DDX_Control(pDX, IDC_ONLINE_USERS, m_OnlineUsers);
  43. //}}AFX_DATA_MAP
  44. }
  45. BEGIN_MESSAGE_MAP(COnlineUsersPage, CDialog)
  46. //{{AFX_MSG_MAP(COnlineUsersPage)
  47. ON_WM_SIZE()
  48. ON_WM_CONTEXTMENU()
  49. ON_COMMAND(IDC_KICK_USER, OnKickUser)
  50. ON_COMMAND(IDC_EDIT_USER, OnEditUserAccount)
  51. ON_COMMAND(IDC_BLOCK_IP, OnBlockIp)
  52. //}}AFX_MSG_MAP
  53. END_MESSAGE_MAP()
  54. /********************************************************************/
  55. /* */
  56. /* Function name : OnInitDialog */
  57. /* Description : Called by the framework in response to the */
  58. /* WM_INITDIALOG message. */
  59. /* */
  60. /********************************************************************/
  61. BOOL COnlineUsersPage::OnInitDialog()
  62. {
  63. CDialog::OnInitDialog();
  64. m_OnlineUsers.InsertColumn(0, "ThreadID");
  65. m_OnlineUsers.InsertColumn(1, "IP地址");
  66. m_OnlineUsers.InsertColumn(2, "登陆时间");
  67. DWORD dwStyle = m_OnlineUsers.GetExtendedStyle();
  68. dwStyle |= LVS_EX_FULLROWSELECT;
  69. m_OnlineUsers.SetExtendedStyle(dwStyle);
  70. return TRUE;
  71. }
  72. /********************************************************************/
  73. /* */
  74. /* Function name : OnSize */
  75. /* Description : Handle WM_SIZE message */
  76. /* */
  77. /********************************************************************/
  78. void COnlineUsersPage::OnSize(UINT nType, int cx, int cy)
  79. {
  80. CDialog::OnSize(nType, cx, cy);
  81. if (IsWindow(::GetDlgItem(m_hWnd, IDC_ONLINE_USERS)))
  82. {
  83. CRect rect;
  84. GetClientRect(rect);
  85. m_OnlineUsers.MoveWindow(rect);
  86. m_OnlineUsers.SetColumnWidth(0, 0);
  87. m_OnlineUsers.SetColumnWidth(1, rect.Width()/2-2);
  88. m_OnlineUsers.SetColumnWidth(2, rect.Width()/2-2);
  89. }
  90. }
  91. /********************************************************************/
  92. /* */
  93. /* Function name : AddUser */
  94. /* Description : Add new connected user to list */
  95. /* */
  96. /********************************************************************/
  97. void COnlineUsersPage::AddUser(DWORD nThreadID, LPCTSTR lpszName, LPCTSTR lpszAddress)
  98. {
  99. /* CString strThreadID;
  100. strThreadID.Format("%d", nThreadID);
  101. LVFINDINFO info;
  102. info.flags = LVFI_PARTIAL|LVFI_STRING;
  103. info.psz = (LPCTSTR)strThreadID;
  104. int nIndex = m_OnlineUsers.FindItem(&info);
  105. if (nIndex == -1)
  106. {
  107. nIndex = m_OnlineUsers.InsertItem(0, strThreadID);
  108. }
  109. m_OnlineUsers.SetItemText(nIndex, 1, lpszName);
  110. m_OnlineUsers.SetItemText(nIndex, 2, lpszAddress);
  111. m_OnlineUsers.SetItemText(nIndex, 3, CTime::GetCurrentTime().Format("%H:%M:%S"));*/
  112. }
  113. /********************************************************************/
  114. /* */
  115. /* Function name : RemoveUser */
  116. /* Description : Remove disconnected user from list */
  117. /* */
  118. /********************************************************************/
  119. void COnlineUsersPage::RemoveUser(DWORD nThreadID)
  120. {
  121. LVFINDINFO info;
  122. CString strThreadID;
  123. strThreadID.Format("%d", nThreadID);
  124. info.flags = LVFI_PARTIAL|LVFI_STRING;
  125. info.psz = (LPCTSTR)strThreadID;
  126. int nIndex = m_OnlineUsers.FindItem(&info);
  127. if (nIndex != -1)
  128. {
  129. m_OnlineUsers.DeleteItem(nIndex);
  130. }
  131. }
  132. /********************************************************************/
  133. /* */
  134. /* Function name : OnContextMenu */
  135. /* Description : Show context menu */
  136. /* */
  137. /********************************************************************/
  138. void COnlineUsersPage::OnContextMenu(CWnd* pWnd, CPoint point)
  139. {
  140. // get selected user
  141. }
  142. /********************************************************************/
  143. /* */
  144. /* Function name : OnKickUser */
  145. /* Description : Close connection for this user(s) */
  146. /* */
  147. /********************************************************************/
  148. void COnlineUsersPage::OnKickUser()
  149. {
  150. }
  151. /********************************************************************/
  152. /* */
  153. /* Function name : OnEditUserAccount */
  154. /* Description : Change user rights of selected user */
  155. /* */
  156. /********************************************************************/
  157. void COnlineUsersPage::OnEditUserAccount()
  158. {
  159. }
  160. /********************************************************************/
  161. /* */
  162. /* Function name : OnBlockIp */
  163. /* Description : Change user rights of selected user */
  164. /* */
  165. /********************************************************************/
  166. void COnlineUsersPage::OnBlockIp()
  167. {
  168. }
  169. extern CtheDBServer *g_pWndServer;
  170. void COnlineUsersPage::RefreshData()
  171. {
  172. #ifdef CONNCOUNT_VERSION
  173. m_OnlineUsers.DeleteAllItems ();
  174. int i=0; CString strThreadID;
  175. for(i=0; i<g_logintimearray.GetSize (); i++)
  176. {
  177. strThreadID.Format("%d", i+1);
  178. m_OnlineUsers.InsertItem(i, strThreadID);
  179. m_OnlineUsers.SetItemText(i, 1, g_connuserarray.ElementAt (i));
  180. m_OnlineUsers.SetItemText(i, 2, g_logintimearray.ElementAt (i));
  181. }
  182. i=g_logintimearray.GetSize ();
  183. m_OnlineUsers.InsertItem(i, "");i++;
  184. strThreadID.Format("%d", g_logintimearray.GetSize());
  185. m_OnlineUsers.InsertItem(i, "");
  186. m_OnlineUsers.SetItemText(i, 1, "连接座席数:"+strThreadID);
  187. m_OnlineUsers.SetItemText(i, 2, "");
  188. g_pWndServer->m_CriticalSection.Unlock();
  189. #else
  190. m_OnlineUsers.DeleteAllItems ();
  191. g_pWndServer->m_CriticalSection.Lock();
  192. CConnectThread *pThread;
  193. CStringArray iparray;
  194. POSITION pos;
  195. pos=g_pWndServer->m_ThreadList.GetHeadPosition();
  196. int i=0; CString strThreadID;
  197. while(pos)
  198. {
  199. pThread=g_pWndServer->m_ThreadList.GetNext(pos);
  200. int nThreadID = pThread->m_nThreadID;
  201. strThreadID.Format("%d", nThreadID);
  202. m_OnlineUsers.InsertItem(i, strThreadID);
  203. m_OnlineUsers.SetItemText(i, 1, pThread->m_strRemoteHost);
  204. m_OnlineUsers.SetItemText(i, 2, pThread->m_LastDataTransferTime.Format("%H:%M:%S"));
  205. i++;
  206. if(g_localip==pThread->m_strRemoteHost)continue;
  207. if(::FindArray(&iparray, pThread->m_strRemoteHost)==-1)
  208. iparray.Add(pThread->m_strRemoteHost);
  209. }
  210. m_OnlineUsers.InsertItem(i, "");i++;
  211. strThreadID.Format("%d", iparray.GetSize());
  212. m_OnlineUsers.InsertItem(i, "");
  213. m_OnlineUsers.SetItemText(i, 1, "连接座席数:"+strThreadID);
  214. m_OnlineUsers.SetItemText(i, 2, "");
  215. g_pWndServer->m_CriticalSection.Unlock();
  216. #endif
  217. }