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.

74 lines
2.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "ServerInfoMsgHandler.h"
  8. #include "serverinfo.h"
  9. #include "info.h"
  10. extern void v_strncpy(char *dest, const char *src, int bufsize);
  11. //-----------------------------------------------------------------------------
  12. // Purpose: Constructor
  13. //-----------------------------------------------------------------------------
  14. CServerInfoMsgHandlerDetails::CServerInfoMsgHandlerDetails( CServerInfo *baseobject, HANDLERTYPE type, void *typeinfo /*= NULL*/ )
  15. : CMsgHandler( type, typeinfo )
  16. {
  17. m_pServerInfo = baseobject;
  18. }
  19. //-----------------------------------------------------------------------------
  20. // Purpose: Process cracked message
  21. //-----------------------------------------------------------------------------
  22. bool CServerInfoMsgHandlerDetails::Process( netadr_t *from, CMsgBuffer *msg )
  23. {
  24. // Skip the control character
  25. msg->ReadByte();
  26. // get response name
  27. const char *str = msg->ReadString();
  28. if ( !str || !str[0] )
  29. return false;
  30. // get infostring
  31. str = msg->ReadString();
  32. if ( !str || !str[0] )
  33. return false;
  34. char info[ 2048 ];
  35. strncpy( info, str, 2047 );
  36. info[2047] = 0;
  37. char name[256], map[256], gamedir[256], desc[256];
  38. v_strncpy(name, Info_ValueForKey(info, "hostname"), 255);
  39. v_strncpy(map, Info_ValueForKey(info, "map"), 255);
  40. v_strncpy(gamedir, Info_ValueForKey(info, "gamedir"), 255);
  41. strlwr(gamedir);
  42. v_strncpy(desc, Info_ValueForKey(info, "description"), 255);
  43. int players = atoi(Info_ValueForKey(info, "players"));
  44. int maxplayers = atoi(Info_ValueForKey(info, "max"));
  45. char serverType = *Info_ValueForKey(info, "type");
  46. bool password = atoi(Info_ValueForKey(info, "password"));
  47. m_pServerInfo->UpdateServer(from, // index of server
  48. (serverType == 'p'),
  49. name,
  50. map,
  51. gamedir,
  52. desc,
  53. players,
  54. maxplayers,
  55. msg->GetTime(), // receive time
  56. password
  57. );
  58. return true;
  59. }