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.

176 lines
3.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: queries server for the command list, and then use QueryCommand() to see
  4. // if the server supports this command.
  5. //
  6. // $NoKeywords: $
  7. //=============================================================================
  8. #include <ctype.h> // isspace() define
  9. #include <string.h>
  10. #include "CMDList.h"
  11. #include "Iresponse.h"
  12. #include "Socket.h"
  13. #include "proto_oob.h"
  14. #include "DialogGameInfo.h"
  15. #include "inetapi.h"
  16. #include "TokenLine.h"
  17. #include "dialogkickplayer.h"
  18. extern void v_strncpy(char *dest, const char *src, int bufsize);
  19. typedef enum
  20. {
  21. NONE = 0,
  22. INFO_REQUESTED,
  23. INFO_RECEIVED
  24. } RCONSTATUS;
  25. typedef enum
  26. {
  27. FS,
  28. PAK
  29. } MAP_TYPES;
  30. CCMDList::CCMDList(IResponse *target,serveritem_t &server, const char *rconPassword) {
  31. memcpy(&m_Server, &server,sizeof(serveritem_t));
  32. m_bGotCommands = false;
  33. m_pResponseTarget=target;
  34. v_strncpy(m_szRconPassword,rconPassword,100);
  35. m_pRcon = new CRcon(this , server,rconPassword);
  36. m_pRcon->SendRcon("cmdlist");
  37. m_CMDList.RemoveAll();
  38. }
  39. CCMDList::~CCMDList() {
  40. delete m_pRcon;
  41. }
  42. //-----------------------------------------------------------------------------
  43. // Purpose:
  44. //-----------------------------------------------------------------------------
  45. void CCMDList::RunFrame()
  46. {
  47. if(m_pRcon)
  48. {
  49. m_pRcon->RunFrame();
  50. }
  51. }
  52. void CCMDList::ServerResponded()
  53. {
  54. char store[2048];
  55. strcpy(store, m_pRcon->RconResponse());
  56. char *cur=store;
  57. char *next=NULL;
  58. char *cmd=NULL;
  59. bool cmd_end=false;
  60. // response format:
  61. //Command List
  62. //--------------
  63. //_unloadmodule
  64. // ...
  65. // writeip
  66. //--------------
  67. //125 Total Commands
  68. //CmdList ? for syntax
  69. while(cur!=NULL)
  70. {
  71. if(next!=NULL)
  72. {
  73. cur++;
  74. }
  75. next=strchr(cur,'\n');
  76. if(next!=NULL)
  77. {
  78. *next='\0';
  79. }
  80. if( strncmp(cur,"Command List",12) && strncmp(cur,"-------------",13)
  81. && strncmp(cur,"Total Commands",14) && strncmp(cur,"CmdList ? for syntax",20) )
  82. {
  83. char *removeWhiteSpace=cur;
  84. while(!isspace(*removeWhiteSpace) && removeWhiteSpace<next)
  85. {
  86. removeWhiteSpace++;
  87. }
  88. *removeWhiteSpace='\0';
  89. cmd = new char[strlen(cur)];
  90. if(cmd)
  91. {
  92. strcpy(cmd,cur);
  93. m_CMDList.AddToTail(cmd);
  94. }
  95. }
  96. else if ( ! strncmp(cur,"CmdList ? for syntax",20))
  97. {
  98. cmd_end=true;
  99. }
  100. cur=next;
  101. }
  102. if( cmd_end )
  103. {
  104. m_bGotCommands = true;
  105. m_pResponseTarget->ServerResponded();
  106. }
  107. }
  108. void CCMDList::ServerFailedToRespond()
  109. {
  110. //m_pResponseTarget->ServerFailedToRespond();
  111. }
  112. serveritem_t &CCMDList::GetServer()
  113. {
  114. return m_Server;
  115. }
  116. bool CCMDList::QueryCommand(char *cmd)
  117. {
  118. if(!m_bGotCommands)
  119. return false;
  120. for(int i=0;i<m_CMDList.Count();i++)
  121. {
  122. char *cmd_in = m_CMDList[i];
  123. if(!stricmp(cmd,m_CMDList[i]))
  124. break;
  125. }
  126. if(i!=m_CMDList.Count())
  127. {
  128. return true;
  129. }
  130. else
  131. return false;
  132. }
  133. bool CCMDList::GotCommands()
  134. {
  135. return m_bGotCommands;
  136. }
  137. void CCMDList::SetPassword(const char *newPass)
  138. {
  139. m_pRcon->SetPassword(newPass);
  140. m_bGotCommands = false;
  141. m_CMDList.RemoveAll();
  142. m_pRcon->SendRcon("cmdlist");
  143. }