Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "MasterMsgHandler.h"
  8. #include "IGameList.h"
  9. #include "serverpage.h"
  10. #include <VGUI_Controls.h>
  11. #include <VGUI_IVGui.h>
  12. //-----------------------------------------------------------------------------
  13. // Purpose: Constructor
  14. //-----------------------------------------------------------------------------
  15. CMasterMsgHandler::CMasterMsgHandler( IGameList *baseobject, HANDLERTYPE type, void *typeinfo /*= NULL*/ )
  16. : CMsgHandler( type, typeinfo )
  17. {
  18. m_pGameList = baseobject;
  19. }
  20. //-----------------------------------------------------------------------------
  21. // Purpose: Process cracked message
  22. //-----------------------------------------------------------------------------
  23. bool CMasterMsgHandler::Process( netadr_t *from, CMsgBuffer *msg )
  24. {
  25. // Skip the control character
  26. msg->ReadByte();
  27. // Skip the return character
  28. msg->ReadByte();
  29. // Get the batch ID
  30. int unique = msg->ReadLong();
  31. // Remainder of message length is 6 byte IP addresses
  32. int nNumAddresses = msg->GetCurSize() - msg->GetReadCount();
  33. assert( !( nNumAddresses % 6 ) );
  34. // Each address is 6 bytes long
  35. nNumAddresses /= 6;
  36. while (nNumAddresses-- > 0)
  37. {
  38. serveritem_t server;
  39. memset(&server, 0, sizeof(server));
  40. for (int i = 0; i < 4; i++)
  41. {
  42. server.ip[i] = msg->ReadByte();
  43. }
  44. server.port = msg->ReadShort();
  45. server.port = (server.port & 0xff) << 8 | (server.port & 0xff00) >> 8; // roll your own ntohs
  46. server.received = 0;
  47. server.listEntry = NULL;
  48. server.doNotRefresh = false;
  49. server.hadSuccessfulResponse = false;
  50. server.map[0] = 0;
  51. server.gameDir[0] = 0;
  52. m_pGameList->AddNewServer(server);
  53. }
  54. if (!unique)
  55. {
  56. m_pGameList->ListReceived(false, 0);
  57. }
  58. else
  59. {
  60. // wait until we've refreshed the list before getting next batch of servers
  61. m_pGameList->ListReceived(true, unique);
  62. }
  63. return true;
  64. }