OnlineUser.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "StdAfx.h"
  2. #include "OnlineUser.h"
  3. COnlineUser::COnlineUser(void)
  4. {
  5. }
  6. COnlineUser::~COnlineUser(void)
  7. {
  8. }
  9. void COnlineUser::InsertOnlineUser(IN DWORD dwConnId, IN LPCTSTR lpAccount)
  10. {
  11. if ( IsAccountExist(lpAccount) != -1 )
  12. return;
  13. OnlineUser tagOnlineUser;
  14. tagOnlineUser.m_dwConnID = dwConnId;
  15. _stprintf_s(tagOnlineUser.m_szAccount, _T("%s"), lpAccount);
  16. m_OnlineUser.push_back(tagOnlineUser);
  17. }
  18. DWORD COnlineUser::IsAccountExist(IN LPCTSTR lpAccount )
  19. {
  20. BOOL bExist = FALSE;
  21. vector<OnlineUser>::iterator it = m_OnlineUser.begin();
  22. for ( ; it != m_OnlineUser.end(); it++ )
  23. {
  24. if ( _tcscmp(it->m_szAccount, lpAccount ) == 0 )
  25. {
  26. bExist = TRUE;
  27. break;
  28. }
  29. }
  30. return bExist ? it->m_dwConnID : -1;
  31. }
  32. BOOL COnlineUser::IsAccountExist(IN LPCTSTR lpAccount, OUT DWORD& dwConnId)
  33. {
  34. BOOL bExist = FALSE;
  35. vector<OnlineUser>::iterator it = m_OnlineUser.begin();
  36. for ( ; it != m_OnlineUser.end(); it++ )
  37. {
  38. if ( _tcscmp(it->m_szAccount, lpAccount ) == 0 )
  39. {
  40. dwConnId = it->m_dwConnID;
  41. bExist = TRUE;
  42. break;
  43. }
  44. }
  45. return bExist;
  46. }
  47. BOOL COnlineUser::IsConnIDExist(IN DWORD dwConnId)
  48. {
  49. BOOL bExist = FALSE;
  50. vector<OnlineUser>::iterator it = m_OnlineUser.begin();
  51. for ( ; it != m_OnlineUser.end(); it++ )
  52. {
  53. if ( dwConnId == it->m_dwConnID )
  54. {
  55. bExist = TRUE;
  56. break;
  57. }
  58. }
  59. return bExist;
  60. }
  61. void COnlineUser::EraseOnlineUser(IN DWORD dwConnId)
  62. {
  63. vector<OnlineUser>::iterator it = m_OnlineUser.begin();
  64. for ( ; it != m_OnlineUser.end(); )
  65. {
  66. if ( dwConnId == it->m_dwConnID )
  67. {
  68. it = m_OnlineUser.erase(it);
  69. break;
  70. }
  71. else
  72. {
  73. it++;
  74. }
  75. }
  76. }