ChatPacket.cpp
Upload User: whzytd4
Upload Date: 2022-08-01
Package Size: 7346k
Code Size: 2k
Category:

WinSock-NDIS

Development Platform:

Visual C++

  1. // ChatPacket.cpp: implementation of the CChatPacket class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "ChatPacket.h"
  6. #ifdef _DEBUG
  7. #undef THIS_FILE
  8. static char THIS_FILE[]=__FILE__;
  9. #define new DEBUG_NEW
  10. #endif
  11. //////////////////////////////////////////////////////////////////////
  12. // Construction/Destruction
  13. //////////////////////////////////////////////////////////////////////
  14. //IMPLEMENT_DYNCREATE(CChatPacket, CObject)
  15. IMPLEMENT_SERIAL(CChatPacket, CObject, 1 )
  16. CChatPacket::CChatPacket()
  17. {
  18. Init();
  19. }
  20. CChatPacket::~CChatPacket()
  21. {
  22. }
  23. /*
  24.  * 初始化
  25.  */
  26. void CChatPacket::Init(void)
  27. {
  28. m_type = UNKNOWN; //为知类型
  29. m_strMsg = _T(""); //清空
  30. m_pUserList = NULL; //清空
  31. m_time = CTime::GetCurrentTime();
  32. }
  33. /*
  34.  * 序列化
  35.  */
  36. void CChatPacket::Serialize(CArchive& ar)
  37. {
  38. CObject::Serialize(ar);//调用基类的序列化函数
  39. if (ar.IsStoring())//发送数据
  40. {
  41. BYTE byType = m_type;
  42. ar << byType; //包的类型
  43. ar << m_strMsg; //消息
  44. long  lTime = m_time.GetTime(); //日期和时间
  45. ar << lTime;
  46. }else//接收数据
  47. {
  48. BYTE byType;
  49. ar >> byType;
  50. m_type = (PACKETTYPE)byType; //包的类型
  51. ar >> m_strMsg; //消息
  52. long lTime;
  53. ar >> lTime; //日期和时间
  54. m_time = CTime((time_t)lTime);
  55. }
  56. m_UserInfo.Serialize(ar); //序列化用户信息
  57. m_OfflineUserInfo.Serialize(ar); //序列化离线用户信息
  58. if (m_type == USERLIST && NULL != m_pUserList)//序列化用户列表
  59. {
  60. m_pUserList->Serialize(ar);
  61. }
  62. }