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.

906 lines
24 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // The copyright to the contents herein is the property of Valve, L.L.C.
  4. // The contents may be used and/or copied only with the written permission of
  5. // Valve, L.L.C., or in accordance with the terms and conditions stipulated in
  6. // the agreement/contract under which the contents have been supplied.
  7. //
  8. // Purpose:
  9. //
  10. // $Workfile: $
  11. // $Date: $
  12. //
  13. //-----------------------------------------------------------------------------
  14. // $Log: $
  15. //
  16. // $NoKeywords: $
  17. //=============================================================================
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <stdarg.h>
  21. #include <assert.h>
  22. // base vgui interfaces
  23. #include <VGUI_Controls.h>
  24. #include <VGUI_IInput.h>
  25. #include <VGUI_ISurface.h>
  26. #include <VGUI_IScheme.h>
  27. #include <VGUI_IVGui.h>
  28. #include <VGUI_MouseCode.h>
  29. #include "filesystem.h"
  30. // vgui controls
  31. #include <VGUI_Button.h>
  32. #include <VGUI_CheckButton.h>
  33. #include <VGUI_ComboBox.h>
  34. #include <VGUI_FocusNavGroup.h>
  35. #include <VGUI_Frame.h>
  36. #include <VGUI_KeyValues.h>
  37. #include <VGUI_ListPanel.h>
  38. #include <VGUI_MessageBox.h>
  39. #include <VGUI_Panel.h>
  40. #include <VGUI_PropertySheet.h>
  41. #include <VGUI_ToggleButton.h>
  42. #include <VGUI_QueryBox.h>
  43. // serverbrowser headers
  44. #include "inetapi.h"
  45. //#include "msgbuffer.h"
  46. #include "proto_oob.h"
  47. #include "ServerContextMenu.h"
  48. #include "socket.h"
  49. #include "util.h"
  50. #include "vinternetdlg.h"
  51. #include "dialogcvarchange.h"
  52. //#include "ModList.h"
  53. #include "DialogGameInfo.h"
  54. #include "ConfigPanel.h"
  55. // game list
  56. #include "FavoriteGames.h"
  57. #include "GamePanelInfo.h"
  58. // tracker stuff
  59. //#include "Tracker.h"
  60. #include "TrackerProtocol.h"
  61. //#include "OnlineStatus.h"
  62. // interface to game engine / tracker
  63. #include "IRunGameEngine.h"
  64. using namespace vgui;
  65. static VInternetDlg *s_InternetDlg = NULL;
  66. CSysModule * g_hTrackerNetModule = NULL;
  67. //-----------------------------------------------------------------------------
  68. // Purpose: Constructor
  69. //-----------------------------------------------------------------------------
  70. VInternetDlg::VInternetDlg( unsigned int userid ) : Frame(NULL, "VInternetDlg")
  71. {
  72. s_InternetDlg = this;
  73. m_iUserID=userid;
  74. m_bLoggedIn=false;
  75. MakePopup();
  76. m_pSavedData = NULL;
  77. // create the controls
  78. m_pContextMenu = new CServerContextMenu(this);
  79. // m_pContextMenu->SetVisible(false);
  80. m_pFavoriteGames = new CFavoriteGames(this);
  81. SetMinimumSize(570, 550);
  82. m_pGameList = m_pFavoriteGames;
  83. // property sheet
  84. m_pTabPanel = new PropertySheet(this, "GameTabs");
  85. m_pTabPanel->SetTabWidth(150);
  86. // m_pTabPanel->SetScrolling(true);
  87. m_pTabPanel->AddPage(m_pFavoriteGames, "My Servers");
  88. m_pTabPanel->AddActionSignalTarget(this);
  89. m_pStatusLabel = new Label(this, "StatusLabel", "");
  90. LoadControlSettings("Admin\\DialogAdminServer.res");
  91. m_pStatusLabel->SetText("");
  92. // Setup tracker objects
  93. // tracker doc
  94. //g_pTrackerDoc = new CTrackerDoc();
  95. // create the networking
  96. /*m_pServerSession = new CServerSession();
  97. // load networking dll
  98. char szDLL[_MAX_PATH];
  99. // now load the net interface so we can use it
  100. g_pFullFileSystem->GetLocalPath("Friends/TrackerNET.dll", szDLL);
  101. g_pFullFileSystem->GetLocalCopy(szDLL);
  102. g_hTrackerNetModule = Sys_LoadModule(szDLL);
  103. CreateInterfaceFn netFactory = Sys_GetFactory(g_hTrackerNetModule);
  104. m_pNet = (ITrackerNET *)netFactory(TRACKERNET_INTERFACE_VERSION, NULL);
  105. m_pNet->Initialize(27030, 27100);
  106. m_iServerAddr=m_pNet->GetNetAddress("tracker3.valvesoftware.com:1200");
  107. // uncomment this to do the "tracker" magic
  108. //SendInitialLogin();
  109. */
  110. // load filters
  111. LoadFilters();
  112. // load window settings
  113. LoadDialogState(this, "AdminServer");
  114. // let us be ticked every frame
  115. ivgui()->AddTickSignal(this->GetVPanel());
  116. }
  117. //-----------------------------------------------------------------------------
  118. // Purpose: Destructor
  119. //-----------------------------------------------------------------------------
  120. VInternetDlg::~VInternetDlg()
  121. {
  122. // set a flag indicating the threads should kill themselves
  123. // m_pNet->Shutdown(false);
  124. // m_pNet->deleteThis();
  125. // m_pNet = NULL;
  126. Sys_UnloadModule(g_hTrackerNetModule);
  127. }
  128. //-----------------------------------------------------------------------------
  129. // Purpose: Called once to set up
  130. //-----------------------------------------------------------------------------
  131. void VInternetDlg::Initialize()
  132. {
  133. SetTitle("Admin", true);
  134. SetVisible(false);
  135. }
  136. //-----------------------------------------------------------------------------
  137. // Purpose:
  138. // Input : serverID -
  139. // Output : serveritem_t
  140. //-----------------------------------------------------------------------------
  141. serveritem_t &VInternetDlg::GetServer(unsigned int serverID)
  142. {
  143. return m_pGameList->GetServer(serverID);
  144. }
  145. //-----------------------------------------------------------------------------
  146. // Purpose:
  147. //-----------------------------------------------------------------------------
  148. void VInternetDlg::Open( void )
  149. {
  150. m_pTabPanel->RequestFocus();
  151. // if serverbrowser file is not there we will try to transfer the favorites list.
  152. FileHandle_t f = g_pFullFileSystem->Open("AdminServer.vdf", "rb");
  153. if (f)
  154. {
  155. g_pFullFileSystem->Close( f );
  156. }
  157. surface()->SetMinimized(GetVPanel(), false);
  158. SetVisible(true);
  159. RequestFocus();
  160. m_pTabPanel->RequestFocus();
  161. MoveToFront();
  162. }
  163. //-----------------------------------------------------------------------------
  164. // Purpose: relayouts the dialogs controls
  165. //-----------------------------------------------------------------------------
  166. void VInternetDlg::PerformLayout()
  167. {
  168. BaseClass::PerformLayout();
  169. int x, y, wide, tall;
  170. GetClientArea(x, y, wide, tall);
  171. // game list in middle
  172. m_pTabPanel->SetBounds(8, y + 8, GetWide() - 16, tall - (28));
  173. x += 4;
  174. // status text along bottom
  175. m_pStatusLabel->SetBounds(x + 2, (tall - y) + 40, wide - 6, 20);
  176. m_pStatusLabel->SetContentAlignment(Label::a_northwest);
  177. Repaint();
  178. }
  179. //-----------------------------------------------------------------------------
  180. // Purpose:
  181. //-----------------------------------------------------------------------------
  182. void VInternetDlg::OnClose()
  183. {
  184. // bug here if you exit before logging in.
  185. SaveDialogState(this, "AdminServer");
  186. SaveFilters();
  187. Frame::OnClose();
  188. }
  189. //-----------------------------------------------------------------------------
  190. // Purpose: Loads filter settings from disk
  191. //-----------------------------------------------------------------------------
  192. void VInternetDlg::LoadFilters()
  193. {
  194. // free any old filters
  195. if (m_pSavedData)
  196. {
  197. m_pSavedData->deleteThis();
  198. }
  199. m_pSavedData = new KeyValues ("Filters");
  200. if (!m_pSavedData->LoadFromFile(g_pFullFileSystem, "Admin\\AdminServer.vdf", true, "PLATFORM"))
  201. {
  202. // file not successfully loaded, create the default key
  203. m_pSavedData->FindKey("List", true);
  204. m_pSavedData->FindKey("List/Default", true);
  205. m_pSavedData->SetString("DefaultFilter", "Default");
  206. }
  207. // load favorite servers
  208. KeyValues *favorites = m_pSavedData->FindKey("Favorites", true);
  209. m_bSaveRcon= m_pSavedData->FindKey("SaveRcon", true)->GetInt();
  210. m_pFavoriteGames->LoadFavoritesList(favorites,m_bSaveRcon);
  211. m_bAutoRefresh= m_pSavedData->FindKey("AutoRefresh", true)->GetInt();
  212. if(!m_bAutoRefresh)
  213. {
  214. m_iRefreshTime=0;
  215. }
  216. else
  217. {
  218. m_iRefreshTime= m_pSavedData->FindKey("RefreshTime", true)->GetInt();
  219. }
  220. m_bGraphs= m_pSavedData->FindKey("ShowGraphs", true)->GetInt();
  221. if(!m_bGraphs)
  222. {
  223. m_iGraphsRefreshTime=0;
  224. }
  225. else
  226. {
  227. m_iGraphsRefreshTime= m_pSavedData->FindKey("GraphsRefreshTime", true)->GetInt();
  228. }
  229. m_bDoLogging= m_pSavedData->FindKey("GetLogs", true)->GetInt();
  230. m_pTabPanel->SetActivePage(m_pFavoriteGames);
  231. }
  232. //-----------------------------------------------------------------------------
  233. // Purpose:
  234. //-----------------------------------------------------------------------------
  235. void VInternetDlg::SaveFilters()
  236. {
  237. // get the favorites list
  238. KeyValues *favorites = m_pSavedData->FindKey("Favorites", true);
  239. m_pFavoriteGames->SaveFavoritesList(favorites,m_bSaveRcon);
  240. m_pSavedData->SaveToFile(g_pFullFileSystem, "Admin\\AdminServer.vdf", "PLATFORM");
  241. }
  242. void VInternetDlg::SetConfig(bool autorefresh,bool savercon,int refreshtime,bool graphs,int graphsrefreshtime,bool getlogs)
  243. {
  244. m_bAutoRefresh=autorefresh;
  245. m_bDoLogging = getlogs;
  246. m_bSaveRcon=savercon;
  247. if(m_bAutoRefresh)
  248. {
  249. m_iRefreshTime=refreshtime;
  250. }
  251. else
  252. {
  253. m_iRefreshTime=0;
  254. }
  255. m_bGraphs = graphs;
  256. if(graphs)
  257. {
  258. m_iGraphsRefreshTime=graphsrefreshtime;
  259. }
  260. else
  261. {
  262. m_iGraphsRefreshTime=0;
  263. }
  264. m_pSavedData->SetInt("AutoRefresh",autorefresh);
  265. m_pSavedData->SetInt("SaveRcon",savercon);
  266. m_pSavedData->SetInt("RefreshTime",refreshtime);
  267. m_pSavedData->SetInt("GraphsRefreshTime",graphsrefreshtime);
  268. m_pSavedData->SetInt("ShowGraphs",graphs);
  269. m_pSavedData->SetInt("GetLogs",getlogs);
  270. }
  271. //-----------------------------------------------------------------------------
  272. // Purpose: Updates status test at bottom of window
  273. // Input : *fmt -
  274. // ... -
  275. //-----------------------------------------------------------------------------
  276. void VInternetDlg::UpdateStatusText(const char *fmt, ...)
  277. {
  278. if ( !m_pStatusLabel )
  279. return;
  280. char str[ 1024 ];
  281. va_list argptr;
  282. va_start( argptr, fmt );
  283. vsprintf( str, fmt, argptr );
  284. va_end( argptr );
  285. m_pStatusLabel->SetText( str );
  286. }
  287. //-----------------------------------------------------------------------------
  288. // Purpose: returns a pointer to a static instance of this dialog
  289. // Output : VInternetDlg
  290. //----------------------------------------------------------------------------
  291. VInternetDlg *VInternetDlg::GetInstance()
  292. {
  293. return s_InternetDlg;
  294. }
  295. //-----------------------------------------------------------------------------
  296. // Purpose:
  297. // Output : CServerContextMenu
  298. //-----------------------------------------------------------------------------
  299. CServerContextMenu *VInternetDlg::GetContextMenu()
  300. {
  301. return m_pContextMenu;
  302. }
  303. //-----------------------------------------------------------------------------
  304. // Purpose: begins the process of joining a server from a game list
  305. // the game info dialog it opens will also update the game list
  306. //-----------------------------------------------------------------------------
  307. CDialogGameInfo *VInternetDlg::JoinGame(IGameList *gameList, unsigned int serverIndex)
  308. {
  309. // open the game info dialog, then mark it to attempt to connect right away
  310. CDialogGameInfo *gameDialog = OpenGameInfoDialog(gameList, serverIndex);
  311. // set the dialog name to be the server name
  312. gameDialog->Connect();
  313. return gameDialog;
  314. }
  315. //-----------------------------------------------------------------------------
  316. // Purpose: joins a game by a specified IP, not attached to any game list
  317. //-----------------------------------------------------------------------------
  318. CDialogGameInfo *VInternetDlg::JoinGame(int serverIP, int serverPort, const char *titleName)
  319. {
  320. // open the game info dialog, then mark it to attempt to connect right away
  321. CDialogGameInfo *gameDialog = OpenGameInfoDialog(serverIP, serverPort, titleName);
  322. // set the dialog name to be the server name
  323. gameDialog->Connect();
  324. return gameDialog;
  325. }
  326. //-----------------------------------------------------------------------------
  327. // Purpose: opens a game info dialog from a game list
  328. //-----------------------------------------------------------------------------
  329. CDialogGameInfo *VInternetDlg::OpenGameInfoDialog(IGameList *gameList, unsigned int serverIndex)
  330. {
  331. CDialogGameInfo *gameDialog = new CDialogGameInfo(gameList, serverIndex);
  332. serveritem_t &server = gameList->GetServer(serverIndex);
  333. gameDialog->Run(server.name);
  334. return gameDialog;
  335. }
  336. //-----------------------------------------------------------------------------
  337. // Purpose: opens a game info dialog by a specified IP, not attached to any game list
  338. //-----------------------------------------------------------------------------
  339. CDialogGameInfo *VInternetDlg::OpenGameInfoDialog(int serverIP, int serverPort, const char *titleName)
  340. {
  341. CDialogGameInfo *gameDialog = new CDialogGameInfo(NULL, 0, serverIP, serverPort);
  342. gameDialog->Run(titleName);
  343. return gameDialog;
  344. }
  345. //-----------------------------------------------------------------------------
  346. // Purpose: Save position and window size of a dialog from the .vdf file.
  347. // Input : *dialog - panel we are setting position and size
  348. // *dialogName - name of dialog in the .vdf file
  349. //-----------------------------------------------------------------------------
  350. void VInternetDlg::SaveDialogState(Panel *dialog, const char *dialogName)
  351. {
  352. // write the size and position to the document
  353. int x, y, wide, tall;
  354. dialog->GetBounds(x, y, wide, tall);
  355. KeyValues *data;
  356. data = m_pSavedData->FindKey(dialogName, true);
  357. data->SetInt("x", x);
  358. data->SetInt("y", y);
  359. data->SetInt("w", wide);
  360. data->SetInt("t", tall);
  361. }
  362. //-----------------------------------------------------------------------------
  363. // Purpose: Load position and window size of a dialog from the .vdf file.
  364. // Input : *dialog - panel we are setting position and size
  365. // *dialogName - name of dialog in the .vdf file
  366. //-----------------------------------------------------------------------------
  367. void VInternetDlg::LoadDialogState(Panel *dialog, const char *dialogName)
  368. {
  369. // read the size and position from the document
  370. KeyValues *data;
  371. data = m_pSavedData->FindKey(dialogName, true);
  372. // calculate defaults, center of the screen
  373. int x, y, wide, tall, dwide, dtall;
  374. int nx, ny, nwide, ntall;
  375. vgui::surface()->GetScreenSize(wide, tall);
  376. dialog->GetSize(dwide, dtall);
  377. x = (int)((wide - dwide) * 0.5);
  378. y = (int)((tall - dtall) * 0.5);
  379. // set dialog
  380. nx = data->GetInt("x", x);
  381. ny = data->GetInt("y", y);
  382. nwide = data->GetInt("w", dwide);
  383. ntall = data->GetInt("t", dtall);
  384. // make sure it's on the screen. If it isn't, move it over so it is.
  385. if (nx + nwide > wide)
  386. {
  387. nx = wide - nwide;
  388. }
  389. if (ny + ntall > tall)
  390. {
  391. ny = tall - ntall;
  392. }
  393. if (nx < 0)
  394. {
  395. nx = 0;
  396. }
  397. if (ny < 0)
  398. {
  399. ny = 0;
  400. }
  401. dialog->SetBounds(nx, ny, nwide, ntall);
  402. }
  403. //-----------------------------------------------------------------------------
  404. // Purpose:
  405. // Input : *dest -
  406. // *src -
  407. // bufsize -
  408. //-----------------------------------------------------------------------------
  409. void v_strncpy(char *dest, const char *src, int bufsize)
  410. {
  411. if (src == dest)
  412. return;
  413. strncpy(dest, src, bufsize - 1);
  414. dest[bufsize - 1] = 0;
  415. }
  416. void VInternetDlg::ConfigPanel()
  417. {
  418. CConfigPanel *config = new CConfigPanel(m_bAutoRefresh,m_bSaveRcon,m_iRefreshTime,m_bGraphs,m_iGraphsRefreshTime,m_bDoLogging);
  419. config->Run();
  420. }
  421. void VInternetDlg::OnManageServer(int serverID)
  422. {
  423. int i;
  424. serveritem_t &server = m_pFavoriteGames->GetServer(serverID);
  425. netadr_t addr;
  426. memcpy(addr.ip,server.ip,4);
  427. addr.port=(server.port & 0xff) << 8 | (server.port & 0xff00) >> 8;
  428. addr.type=NA_IP;
  429. const char *netString = net->AdrToString(&addr);
  430. char tabName[20];
  431. for(i=0;i<m_pTabPanel->GetNumPages();i++)
  432. {
  433. m_pTabPanel->GetTabTitle(i,tabName,20);
  434. if(!stricmp(netString,tabName))
  435. {
  436. break;
  437. }
  438. }
  439. if(i==m_pTabPanel->GetNumPages())
  440. {
  441. if(m_bSaveRcon)
  442. { // rcons are being saved
  443. if(strlen(server.rconPassword)>0)
  444. { // this rcon password is already saved :)
  445. ManageServer(serverID,server.rconPassword);
  446. return;
  447. }
  448. }
  449. // otherwise ask for an rcon password
  450. CDialogCvarChange *box = new CDialogCvarChange();
  451. char id[5];
  452. _snprintf(id,5,"%i",serverID);
  453. box->AddActionSignalTarget(this);
  454. box->SetTitle("Enter Rcon Password",true);
  455. box->SetLabelText("CvarNameLabel","");
  456. box->SetLabelText("PasswordLabel","Password:");
  457. box->MakePassword();
  458. box->Activate(id, "","rconpassword","Enter Rcon Password for this Server");
  459. }
  460. else
  461. {
  462. m_pTabPanel->SetActivePage(m_pTabPanel->GetPage(i));
  463. }
  464. }
  465. void VInternetDlg::OnPlayerDialog(vgui::KeyValues *data)
  466. {
  467. const char *type=data->GetString("type");
  468. const char *playerName=data->GetString("player");
  469. if(!stricmp(type,"rconpassword"))
  470. {
  471. const char *value=data->GetString("value");
  472. serveritem_t &server = m_pFavoriteGames->GetServer(atoi(playerName)); // we encode the serverid in the name field :)
  473. strncpy(server.rconPassword,value,sizeof(server.rconPassword)); // save this password
  474. ManageServer(atoi(playerName),value);
  475. }
  476. }
  477. void VInternetDlg::ManageServer(int serverID,const char *pass)
  478. {
  479. serveritem_t &server = m_pFavoriteGames->GetServer(serverID);
  480. netadr_t addr;
  481. memcpy(addr.ip,server.ip,4);
  482. addr.port=(server.port & 0xff) << 8 | (server.port & 0xff00) >> 8;
  483. addr.type=NA_IP;
  484. m_pGamePanelInfo = new CGamePanelInfo(this,"Current Server",server.gameDir,m_iRefreshTime,m_iGraphsRefreshTime,m_bDoLogging);
  485. m_pTabPanel->AddPage(m_pGamePanelInfo,net->AdrToString(&addr) );
  486. m_pGamePanelInfo->ChangeGame(server,pass);
  487. m_pTabPanel->SetActivePage(m_pGamePanelInfo);
  488. }
  489. void VInternetDlg::UpdateServer(serveritem_t &server)
  490. {
  491. m_pFavoriteGames->UpdateServer(server);
  492. }
  493. void VInternetDlg::OnDeleteServer(int chosenPanel)
  494. {
  495. Panel *delPanel =m_pTabPanel->GetPage(chosenPanel);
  496. m_pTabPanel->DeletePage(delPanel);
  497. InvalidateLayout();
  498. Repaint();
  499. }
  500. vgui::PropertySheet *VInternetDlg::GetTabPanel()
  501. {
  502. return m_pTabPanel;
  503. }
  504. void VInternetDlg::OnOpenContextMenu()
  505. {
  506. // CServerContextMenu *menu = VInternetDlg::GetInstance()->GetContextMenu();
  507. // no selected rows, so don't display default stuff in menu
  508. if( m_pTabPanel->GetActiveTab()->IsCursorOver() ||
  509. m_pFavoriteGames->IsCursorOver() )
  510. {
  511. m_pContextMenu->ShowMenu(this, -1, false, false, false,false);
  512. }
  513. }
  514. void VInternetDlg::OnTick()
  515. {
  516. //FIX ME!!!
  517. return;
  518. /*
  519. // get the latest raw messages
  520. IBinaryBuffer *buf;
  521. CNetAddress address;
  522. while ((buf = m_pNet->GetIncomingRawData(address)) != NULL)
  523. {
  524. //ReceivedRawData(buf, address);
  525. buf->Release();
  526. }
  527. // get all the latest messages
  528. IReceiveMessage *recv;
  529. while ((recv = m_pNet->GetIncomingData()) != NULL)
  530. {
  531. // make sure the message is valid
  532. if (!CheckMessageValidity(recv))
  533. return;
  534. // record the reception
  535. // m_iLastReceivedTime = m_iTime;
  536. // find the message id in the dispatch table
  537. int dataName = recv->GetMsgID();
  538. switch(dataName)
  539. {
  540. case TSVC_CHALLENGE:
  541. {
  542. int ChallengeKey;
  543. int status = COnlineStatus::ONLINE;
  544. int heartbeatRate =10000;//GetHeartBeatRate();
  545. recv->ReadInt("challenge", ChallengeKey);
  546. recv->ReadUInt("sessionID", m_iSessionID);
  547. // respond to the challenge
  548. ISendMessage *reply = CreateServerMessage(TCLS_RESPONSE);
  549. reply->SetSessionID( m_iSessionID );
  550. reply->WriteInt("challenge", ChallengeKey);
  551. reply->WriteUInt("sessionID", m_iSessionID);
  552. reply->WriteInt("status", status);
  553. reply->WriteInt("build", 1994);
  554. reply->WriteInt("hrate", heartbeatRate); // heartbeat rate to expect
  555. //m_iPreviousHeartBeatRateSentToServer = heartbeatRate;
  556. // reset the login timeout
  557. //m_iLoginTimeout = system()->getTimeMillis() + COnlineStatus::SERVERCONNECT_TIMEOUT;
  558. m_pNet->SendMessage(reply, NET_RELIABLE);
  559. }
  560. break;
  561. case TSVC_LOGINOK:
  562. {
  563. int newStatus;
  564. recv->ReadInt("status", newStatus);
  565. m_bLoggedIn=true;
  566. SearchForFriend(0, "[email protected]", "", "", "");
  567. }
  568. break;
  569. case TSVC_FRIENDSFOUND:
  570. {
  571. //char name[60];
  572. int serverID,sessionID;
  573. recv->ReadInt("uid",m_iRemoteUID);
  574. recv->ReadInt("serverid",serverID);
  575. recv->ReadInt("sessionID",sessionID);
  576. // create the message to the server
  577. ISendMessage *msg = CreateServerMessage(TCLS_ROUTETOFRIEND);
  578. // write in the redirection info
  579. msg->WriteInt("rID", TCL_MESSAGE);
  580. msg->WriteUInt("rUserID", m_iRemoteUID);
  581. msg->WriteUInt("rSessionID", sessionID);
  582. msg->WriteUInt("rServerID", serverID);
  583. msg->WriteBlob("rData", "Hello", 5);
  584. m_pNet->SendMessage(msg, NET_RELIABLE);
  585. // lets log off
  586. msg = CreateServerMessage(TCLS_HEARTBEAT);
  587. msg->WriteInt("status", COnlineStatus::OFFLINE);
  588. m_pNet->SendMessage(msg, NET_RELIABLE);
  589. // m_pNet->Shutdown(true);
  590. // m_pNet->deleteThis();
  591. // SendStatusToServer(COnlineStatus::OFFLINE);
  592. }
  593. break;
  594. default:
  595. {
  596. while(recv->AdvanceField())
  597. {
  598. char data[512];
  599. const char *nm=recv->GetFieldName();
  600. recv->ReadString(nm, data, 512);
  601. }
  602. }
  603. break;
  604. // { TSVC_CHALLENGE, CServerSession::ReceivedMsg_Challenge },
  605. // { TSVC_LOGINOK, CServerSession::ReceivedMsg_LoginOK },
  606. // { TSVC_LOGINFAIL, CServerSession::ReceivedMsg_LoginFail },
  607. // { TSVC_DISCONNECT, CServerSession::ReceivedMsg_Disconnect },
  608. // { TSVC_FRIENDS, CServerSession::ReceivedMsg_Friends },
  609. // { TSVC_FRIENDUPDATE, CServerSession::ReceivedMsg_FriendUpdate },
  610. // { TSVC_GAMEINFO, CServerSession::ReceivedMsg_GameInfo },
  611. // { TSVC_HEARTBEAT, CServerSession::ReceivedMsg_Heartbeat },
  612. // { TSVC_PINGACK, CServerSession::ReceivedMsg_PingAck },
  613. //default:
  614. // break;
  615. }
  616. //ReceivedData(recv);
  617. m_pNet->ReleaseMessage(recv);
  618. }
  619. // get the latest fails
  620. while ((recv = m_pNet->GetFailedMessage()) != NULL)
  621. {
  622. m_pNet->ReleaseMessage(recv);
  623. }
  624. // now let it update itself
  625. m_pNet->RunFrame();
  626. */
  627. }
  628. void VInternetDlg::SearchForFriend(unsigned int uid, const char *email, const char *username, const char *firstname, const char *lastname)
  629. {
  630. ISendMessage *msg = CreateServerMessage(TCLS_FRIENDSEARCH);
  631. msg->WriteUInt("uid", uid);
  632. msg->WriteString("Email", email);
  633. msg->WriteString("UserName", username);
  634. msg->WriteString("FirstName", firstname);
  635. msg->WriteString("LastName", lastname);
  636. m_pNet->SendMessage(msg, NET_RELIABLE);
  637. }
  638. ISendMessage *VInternetDlg::CreateServerMessage(int msgID)
  639. {
  640. ISendMessage *msg = m_pNet->CreateMessage(msgID);
  641. msg->SetNetAddress(GetServerAddress());
  642. msg->SetSessionID(m_iSessionID);
  643. msg->SetEncrypted(true);
  644. return msg;
  645. }
  646. CNetAddress VInternetDlg::GetServerAddress()
  647. {
  648. return m_iServerAddr;// m_pNet->GetNetAddress("tracker.valvesoftware.com:1200");
  649. }
  650. //-----------------------------------------------------------------------------
  651. // Purpose: Sends the first pack in the login sequence
  652. //-----------------------------------------------------------------------------
  653. void VInternetDlg::SendInitialLogin()
  654. {
  655. // assert(m_iLoginState == LOGINSTATE_WAITINGTORECONNECT || m_iLoginState == LOGINSTATE_DISCONNECTED);
  656. m_iSessionID = 0;
  657. // stop searching for alternate servers
  658. // m_bServerSearch = false;
  659. // int desiredStatus = COnlineStatus::ONLINE;
  660. // setup the login message
  661. /* ISendMessage *loginMsg = m_pNet->CreateMessage(TCLS_LOGIN);
  662. loginMsg->SetNetAddress(GetServerAddress());
  663. loginMsg->SetEncrypted(true);
  664. loginMsg->SetSessionID(0);
  665. // const char *adr= GetServerAddress().ToStaticString();
  666. loginMsg->WriteUInt("uid", 36283);
  667. loginMsg->WriteString("email", "[email protected]");
  668. loginMsg->WriteString("password", "mrorange");
  669. loginMsg->WriteInt("status", desiredStatus);
  670. m_pNet->SendMessage(loginMsg, NET_RELIABLE);
  671. */
  672. // set the current status to be a connecting message
  673. // m_iStatus = COnlineStatus::CONNECTING;
  674. // m_iLoginState = LOGINSTATE_AWAITINGCHALLENGE;
  675. // record the time (for timeouts)
  676. // m_iLoginTimeout = system()->getTimeMillis() + COnlineStatus::SERVERCONNECT_TIMEOUT;
  677. }
  678. //-----------------------------------------------------------------------------
  679. // Purpose: Checks to see if the current message is valid
  680. // replies with a message telling the sender if it's not
  681. //-----------------------------------------------------------------------------
  682. bool VInternetDlg::CheckMessageValidity(IReceiveMessage *dataBlock)
  683. {
  684. int msgID = dataBlock->GetMsgID();
  685. if (msgID == TSVC_FRIENDS || msgID == TSVC_GAMEINFO || msgID == TSVC_HEARTBEAT || msgID == TSVC_FRIENDUPDATE)
  686. {
  687. // see if the server really knows us
  688. if (/*m_iStatus < COnlineStatus::ONLINE ||*/ m_iSessionID != dataBlock->SessionID())
  689. {
  690. // the server thinks we're still logged on to it
  691. // tell the server we're actually logged off from it
  692. ISendMessage *msg = m_pNet->CreateReply(TCLS_HEARTBEAT, dataBlock);
  693. // tell it we're the sessionID it thinks we are
  694. msg->SetSessionID(dataBlock->SessionID());
  695. msg->WriteInt("status", 0);
  696. m_pNet->SendMessage(msg, NET_RELIABLE);
  697. return false;
  698. }
  699. }
  700. return true;
  701. }
  702. //-----------------------------------------------------------------------------
  703. // Purpose: Message map
  704. //-----------------------------------------------------------------------------
  705. MessageMapItem_t VInternetDlg::m_MessageMap[] =
  706. {
  707. // MAP_MESSAGE( VInternetDlg, "PageChanged", OnGameListChanged ),
  708. MAP_MESSAGE_INT( VInternetDlg, "Manage", OnManageServer, "serverID" ),
  709. MAP_MESSAGE_PARAMS( VInternetDlg, "CvarChangeValue", OnPlayerDialog ),
  710. MAP_MESSAGE_INT( VInternetDlg, "DeleteServer", OnDeleteServer, "panelid" ),
  711. MAP_MESSAGE( VInternetDlg, "OpenContextMenu", OnOpenContextMenu ),
  712. };
  713. IMPLEMENT_PANELMAP(VInternetDlg, vgui::Frame);