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.

190 lines
4.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include <stdio.h>
  8. #include <KeyValues.h>
  9. #include <vgui_controls/ListPanel.h>
  10. int __cdecl PlayerNameCompare(const KeyValues *elem1, const KeyValues *elem2 )
  11. {
  12. if ( !elem1 || !elem2 ) // No meaningful comparison
  13. {
  14. return 0;
  15. }
  16. /* const char *name1 = elem1->GetString("name");
  17. const char *name2 = elem2->GetString("name");
  18. return stricmp(name1,name2);
  19. */
  20. return 0;
  21. }
  22. //-----------------------------------------------------------------------------
  23. // Purpose: Ping comparison function
  24. //-----------------------------------------------------------------------------
  25. int __cdecl PlayerPingCompare(const KeyValues *elem1, const KeyValues *elem2 )
  26. {
  27. vgui::ListPanelItem *p1, *p2;
  28. p1 = *(vgui::ListPanelItem **)elem1;
  29. p2 = *(vgui::ListPanelItem **)elem2;
  30. if ( !p1 || !p2 ) // No meaningful comparison
  31. {
  32. return 0;
  33. }
  34. int ping1 = p1->kv->GetInt("ping");
  35. int ping2 = p2->kv->GetInt("ping");
  36. if ( ping1 < ping2 )
  37. return -1;
  38. else if ( ping1 > ping2 )
  39. return 1;
  40. return 0;
  41. }
  42. //-----------------------------------------------------------------------------
  43. // Purpose: Ping comparison function
  44. //-----------------------------------------------------------------------------
  45. int __cdecl PlayerAuthCompare(const void *elem1, const void *elem2 )
  46. {
  47. vgui::ListPanelItem *p1, *p2;
  48. p1 = *(vgui::ListPanelItem **)elem1;
  49. p2 = *(vgui::ListPanelItem **)elem2;
  50. if ( !p1 || !p2 ) // No meaningful comparison
  51. {
  52. return 0;
  53. }
  54. const char *authid1 = p1->kv->GetString("authid");
  55. const char *authid2 = p2->kv->GetString("authid");
  56. return stricmp(authid1,authid2);
  57. }
  58. //-----------------------------------------------------------------------------
  59. // Purpose: Loss comparison function
  60. //-----------------------------------------------------------------------------
  61. int __cdecl PlayerLossCompare(const void *elem1, const void *elem2 )
  62. {
  63. vgui::ListPanelItem *p1, *p2;
  64. p1 = *(vgui::ListPanelItem **)elem1;
  65. p2 = *(vgui::ListPanelItem **)elem2;
  66. if ( !p1 || !p2 ) // No meaningful comparison
  67. {
  68. return 0;
  69. }
  70. int loss1 = p1->kv->GetInt("loss");
  71. int loss2 = p2->kv->GetInt("loss");
  72. if ( loss1 < loss2 )
  73. return -1;
  74. else if ( loss1 > loss2 )
  75. return 1;
  76. return 0;
  77. }
  78. //-----------------------------------------------------------------------------
  79. // Purpose: Frags comparison function
  80. //-----------------------------------------------------------------------------
  81. int __cdecl PlayerFragsCompare(const void *elem1, const void *elem2 )
  82. {
  83. vgui::ListPanelItem *p1, *p2;
  84. p1 = *(vgui::ListPanelItem **)elem1;
  85. p2 = *(vgui::ListPanelItem **)elem2;
  86. if ( !p1 || !p2 ) // No meaningful comparison
  87. {
  88. return 0;
  89. }
  90. int frags1 = p1->kv->GetInt("frags");
  91. int frags2 = p2->kv->GetInt("frags");
  92. if ( frags1 < frags2 )
  93. return -1;
  94. else if ( frags1 > frags2 )
  95. return 1;
  96. return 0;
  97. }
  98. //-----------------------------------------------------------------------------
  99. // Purpose: Player connection time comparison function
  100. //-----------------------------------------------------------------------------
  101. int __cdecl PlayerTimeCompare( vgui::ListPanel *pPanel, const vgui::ListPanelItem &item1, const vgui::ListPanelItem &item2 )
  102. {
  103. int h1 = 0, h2 = 0, m1 = 0, m2 = 0, s1 = 0, s2 = 0;
  104. float t1=0,t2=0;
  105. const char *time1 = item1.kv->GetString("time");
  106. const char *time2 = item2.kv->GetString("time");
  107. int numFields1 = sscanf(time1,"%i:%i:%i",&h1,&m1,&s1);
  108. int numFields2 = sscanf(time2,"%i:%i:%i",&h2,&m2,&s2);
  109. switch ( numFields1 )
  110. {
  111. case 2:
  112. s1 = m1;
  113. m1 = h1;
  114. h1 = 0;
  115. break;
  116. case 1:
  117. s1 = h1;
  118. m1 = 0;
  119. h1 = 0;
  120. break;
  121. case 0:
  122. s1 = 0;
  123. m1 = 0;
  124. h1 = 0;
  125. }
  126. switch ( numFields2 )
  127. {
  128. case 2:
  129. s2 = m2;
  130. m2 = h2;
  131. h2 = 0;
  132. break;
  133. case 1:
  134. s2 = h2;
  135. m2 = 0;
  136. h2 = 0;
  137. break;
  138. case 0:
  139. s2 = 0;
  140. m2 = 0;
  141. h2 = 0;
  142. }
  143. t1=(float)(h1*3600+m1*60+s1);
  144. t2=(float)(h2*3600+m2*60+s2);
  145. if ( t1 < t2 )
  146. return -1;
  147. else if ( t1 > t2 )
  148. return 1;
  149. return 0;
  150. }