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.

115 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "ServerListCompare.h"
  8. #include "server.h"
  9. #include "serverpage.h"
  10. #include <VGUI_ListPanel.h>
  11. #include <VGUI_KeyValues.h>
  12. //-----------------------------------------------------------------------------
  13. // Purpose: List password column sort function
  14. //-----------------------------------------------------------------------------
  15. int __cdecl PasswordCompare(vgui::ListPanel *pPanel, const ListPanelItem &item1, const ListPanelItem &item2 )
  16. {
  17. serveritem_t &s1 = CServerPage::GetInstance()->GetServer(item1.userData);
  18. serveritem_t &s2 = CServerPage::GetInstance()->GetServer(item2.userData);
  19. if (s1.password < s2.password)
  20. return 1;
  21. else if (s1.password > s2.password)
  22. return -1;
  23. return 0;
  24. }
  25. //-----------------------------------------------------------------------------
  26. // Purpose: Ping comparison function
  27. //-----------------------------------------------------------------------------
  28. int __cdecl PingCompare(vgui::ListPanel *pPanel, const vgui::ListPanelItem &item1, const vgui::ListPanelItem &item2 )
  29. {
  30. serveritem_t &s1 = CServerPage::GetInstance()->GetServer(item1.userData);
  31. serveritem_t &s2 = CServerPage::GetInstance()->GetServer(item2.userData);
  32. int ping1 = s1.ping;
  33. int ping2 = s2.ping;
  34. if ( ping1 < ping2 )
  35. return -1;
  36. else if ( ping1 > ping2 )
  37. return 1;
  38. return 0;
  39. }
  40. //-----------------------------------------------------------------------------
  41. // Purpose: Map comparison function
  42. //-----------------------------------------------------------------------------
  43. int __cdecl MapCompare(vgui::ListPanel *pPanel, const vgui::ListPanelItem &item1, const vgui::ListPanelItem &item2 )
  44. {
  45. serveritem_t &s1 = CServerPage::GetInstance()->GetServer(item1.userData);
  46. serveritem_t &s2 = CServerPage::GetInstance()->GetServer(item2.userData);
  47. return stricmp(s1.map, s2.map);
  48. }
  49. //-----------------------------------------------------------------------------
  50. // Purpose: Game dir comparison function
  51. //-----------------------------------------------------------------------------
  52. int __cdecl GameCompare(vgui::ListPanel *pPanel, const vgui::ListPanelItem &item1, const vgui::ListPanelItem &item2 )
  53. {
  54. serveritem_t &s1 = CServerPage::GetInstance()->GetServer(item1.userData);
  55. serveritem_t &s2 = CServerPage::GetInstance()->GetServer(item2.userData);
  56. // make sure we haven't added the same server to the list twice
  57. assert(p1->userData != p2->userData);
  58. return stricmp(s1.gameDescription, s2.gameDescription);
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Purpose: Server name comparison function
  62. //-----------------------------------------------------------------------------
  63. int __cdecl ServerNameCompare(vgui::ListPanel *pPanel, const vgui::ListPanelItem &item1, const vgui::ListPanelItem &item2 )
  64. {
  65. serveritem_t &s1 = CServerPage::GetInstance()->GetServer(item1.userData);
  66. serveritem_t &s2 = CServerPage::GetInstance()->GetServer(item2.userData);
  67. return stricmp(s1.name, s2.name);
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Purpose: Player number comparison function
  71. //-----------------------------------------------------------------------------
  72. int __cdecl PlayersCompare(vgui::ListPanel *pPanel, const vgui::ListPanelItem &item1, const vgui::ListPanelItem &item2 )
  73. {
  74. serveritem_t &s1 = CServerPage::GetInstance()->GetServer(item1.userData);
  75. serveritem_t &s2 = CServerPage::GetInstance()->GetServer(item2.userData);
  76. int s1p = s1.players;
  77. int s1m = s1.maxPlayers;
  78. int s2p = s2.players;
  79. int s2m = s2.maxPlayers;
  80. // compare number of players
  81. if (s1p > s2p)
  82. return -1;
  83. if (s1p < s2p)
  84. return 1;
  85. // compare max players if number of current players is equal
  86. if (s1m > s2m)
  87. return -1;
  88. if (s1m < s2m)
  89. return 1;
  90. return 0;
  91. }