Counter Strike : Global Offensive Source Code
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.

333 lines
9.9 KiB

  1. //========= Copyright � 1996-2001, Valve LLC, All rights reserved. ============
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "pch_serverbrowser.h"
  8. //-----------------------------------------------------------------------------
  9. // Purpose: List password column sort function
  10. //-----------------------------------------------------------------------------
  11. int __cdecl PasswordCompare(ListPanel *pPanel, const ListPanelItem &p1, const ListPanelItem &p2)
  12. {
  13. gameserveritem_t *s1 = ServerBrowserDialog().GetServer(p1.userData);
  14. gameserveritem_t *s2 = ServerBrowserDialog().GetServer(p2.userData);
  15. if ( !s1 && s2 )
  16. return -1;
  17. if ( !s2 && s1 )
  18. return 1;
  19. if ( !s1 && !s2 )
  20. return 0;
  21. if ( s1->m_bPassword < s2->m_bPassword )
  22. return 1;
  23. else if ( s1->m_bPassword > s2->m_bPassword )
  24. return -1;
  25. return 0;
  26. }
  27. //-----------------------------------------------------------------------------
  28. // Purpose: list column sort function
  29. //-----------------------------------------------------------------------------
  30. int __cdecl BotsCompare(ListPanel *pPanel, const ListPanelItem &p1, const ListPanelItem &p2)
  31. {
  32. gameserveritem_t *s1 = ServerBrowserDialog().GetServer(p1.userData);
  33. gameserveritem_t *s2 = ServerBrowserDialog().GetServer(p2.userData);
  34. if ( !s1 && s2 )
  35. return -1;
  36. if ( !s2 && s1 )
  37. return 1;
  38. if ( !s1 && !s2 )
  39. return 0;
  40. if ( s1->m_nBotPlayers < s2->m_nBotPlayers )
  41. return 1;
  42. else if ( s1->m_nBotPlayers > s2->m_nBotPlayers )
  43. return -1;
  44. return 0;
  45. }
  46. //-----------------------------------------------------------------------------
  47. // Purpose: list column sort function
  48. //-----------------------------------------------------------------------------
  49. int __cdecl SecureCompare(ListPanel *pPanel, const ListPanelItem &p1, const ListPanelItem &p2)
  50. {
  51. gameserveritem_t *s1 = ServerBrowserDialog().GetServer(p1.userData);
  52. gameserveritem_t *s2 = ServerBrowserDialog().GetServer(p2.userData);
  53. if ( !s1 && s2 )
  54. return -1;
  55. if ( !s2 && s1 )
  56. return 1;
  57. if ( !s1 && !s2 )
  58. return 0;
  59. if ( s1->m_bSecure < s2->m_bSecure )
  60. return 1;
  61. else if ( s1->m_bSecure > s2->m_bSecure )
  62. return -1;
  63. return 0;
  64. }
  65. //-----------------------------------------------------------------------------
  66. // Purpose: list column sort function
  67. //-----------------------------------------------------------------------------
  68. extern CUtlVector< gametypes_t > g_GameTypes;
  69. int __cdecl ModeCompare( ListPanel *pPanel, const ListPanelItem &p1, const ListPanelItem &p2 )
  70. {
  71. gameserveritem_t *s1 = ServerBrowserDialog().GetServer( p1.userData );
  72. gameserveritem_t *s2 = ServerBrowserDialog().GetServer( p2.userData );
  73. if ( !s1 && s2 )
  74. return -1;
  75. if ( !s2 && s1 )
  76. return 1;
  77. if ( !s1 && !s2 )
  78. return 0;
  79. // HACK: If we start looking at things other than prefix to determine mode (eg tags) this will break...
  80. // should make a 'GetModeForServerItem' shared func in that case...
  81. // ALSOHACK: Compare icons, not prefixes. Some game modes have alternate names (ba_ and jb_ are both jailbreak).
  82. const char* szIcon1 = NULL;
  83. const char* szIcon2 = NULL;
  84. FOR_EACH_VEC( g_GameTypes, i )
  85. {
  86. const gametypes_t& type = g_GameTypes[ i ];
  87. if ( StringHasPrefix( V_UnqualifiedFileName( s1->m_szMap ), type.m_szPrefix ) )
  88. szIcon1 = V_UnqualifiedFileName( type.m_szGametypeIcon );
  89. if ( StringHasPrefix( V_UnqualifiedFileName( s2->m_szMap ), type.m_szPrefix ) )
  90. szIcon2 = V_UnqualifiedFileName( type.m_szGametypeIcon );
  91. }
  92. if ( !szIcon1 && szIcon2 )
  93. return 1;
  94. if ( !szIcon2 && szIcon1 )
  95. return -1;
  96. if ( !szIcon1 && !szIcon2 )
  97. return 0;
  98. return V_stricmp( szIcon1, szIcon2 );
  99. }
  100. extern uint64 GetMapIDFromMapPath( const char *pMapPath );
  101. //-----------------------------------------------------------------------------
  102. // Purpose: list column sort function
  103. //-----------------------------------------------------------------------------
  104. int __cdecl WorkshopCompare( ListPanel *pPanel, const ListPanelItem &p1, const ListPanelItem &p2 )
  105. {
  106. gameserveritem_t *s1 = ServerBrowserDialog().GetServer( p1.userData );
  107. gameserveritem_t *s2 = ServerBrowserDialog().GetServer( p2.userData );
  108. if ( !s1 && s2 )
  109. return -1;
  110. if ( !s2 && s1 )
  111. return 1;
  112. if ( !s1 && !s2 )
  113. return 0;
  114. uint64 wsid1 = GetMapIDFromMapPath( s1->m_szMap );
  115. uint64 wsid2 = GetMapIDFromMapPath( s2->m_szMap );
  116. // No need to actually sort by id number... we really just want to group them. It does have the effect of sorting by age though...
  117. if ( wsid1 > wsid2 )
  118. return 1;
  119. else if ( wsid2 > wsid1 )
  120. return -1;
  121. return 0;
  122. }
  123. //-----------------------------------------------------------------------------
  124. // Purpose: list column sort function
  125. //-----------------------------------------------------------------------------
  126. int __cdecl IPAddressCompare(ListPanel *pPanel, const ListPanelItem &p1, const ListPanelItem &p2)
  127. {
  128. gameserveritem_t *s1 = ServerBrowserDialog().GetServer(p1.userData);
  129. gameserveritem_t *s2 = ServerBrowserDialog().GetServer(p2.userData);
  130. if ( !s1 && s2 )
  131. return -1;
  132. if ( !s2 && s1 )
  133. return 1;
  134. if ( !s1 && !s2 )
  135. return 0;
  136. if ( s1->m_NetAdr < s2->m_NetAdr )
  137. return -1;
  138. else if ( s2->m_NetAdr < s1->m_NetAdr )
  139. return 1;
  140. return 0;
  141. }
  142. //-----------------------------------------------------------------------------
  143. // Purpose: Ping comparison function
  144. //-----------------------------------------------------------------------------
  145. int __cdecl PingCompare(ListPanel *pPanel, const ListPanelItem &p1, const ListPanelItem &p2)
  146. {
  147. gameserveritem_t *s1 = ServerBrowserDialog().GetServer(p1.userData);
  148. gameserveritem_t *s2 = ServerBrowserDialog().GetServer(p2.userData);
  149. if ( !s1 && s2 )
  150. return -1;
  151. if ( !s2 && s1 )
  152. return 1;
  153. if ( !s1 && !s2 )
  154. return 0;
  155. int ping1 = s1->m_nPing;
  156. int ping2 = s2->m_nPing;
  157. if ( ping1 < ping2 )
  158. return -1;
  159. else if ( ping1 > ping2 )
  160. return 1;
  161. return 0;
  162. }
  163. //-----------------------------------------------------------------------------
  164. // Purpose: Map comparison function
  165. //-----------------------------------------------------------------------------
  166. int __cdecl MapCompare(ListPanel *pPanel, const ListPanelItem &p1, const ListPanelItem &p2)
  167. {
  168. gameserveritem_t *s1 = ServerBrowserDialog().GetServer(p1.userData);
  169. gameserveritem_t *s2 = ServerBrowserDialog().GetServer(p2.userData);
  170. if ( !s1 && s2 )
  171. return -1;
  172. if ( !s2 && s1 )
  173. return 1;
  174. if ( !s1 && !s2 )
  175. return 0;
  176. return Q_stricmp( V_UnqualifiedFileName( s1->m_szMap ), V_UnqualifiedFileName( s2->m_szMap ) );
  177. }
  178. //-----------------------------------------------------------------------------
  179. // Purpose: Game dir comparison function
  180. //-----------------------------------------------------------------------------
  181. int __cdecl GameCompare(ListPanel *pPanel, const ListPanelItem &p1, const ListPanelItem &p2)
  182. {
  183. gameserveritem_t *s1 = ServerBrowserDialog().GetServer(p1.userData);
  184. gameserveritem_t *s2 = ServerBrowserDialog().GetServer(p2.userData);
  185. if ( !s1 && s2 )
  186. return -1;
  187. if ( !s2 && s1 )
  188. return 1;
  189. if ( !s1 && !s2 )
  190. return 0;
  191. // make sure we haven't added the same server to the list twice
  192. Assert( p1.userData != p2.userData );
  193. return Q_stricmp( s1->m_szGameDescription, s2->m_szGameDescription );
  194. }
  195. //-----------------------------------------------------------------------------
  196. // Purpose: Server name comparison function
  197. //-----------------------------------------------------------------------------
  198. int __cdecl ServerNameCompare(ListPanel *pPanel, const ListPanelItem &p1, const ListPanelItem &p2)
  199. {
  200. gameserveritem_t *s1 = ServerBrowserDialog().GetServer(p1.userData);
  201. gameserveritem_t *s2 = ServerBrowserDialog().GetServer(p2.userData);
  202. if ( !s1 && s2 )
  203. return -1;
  204. if ( !s2 && s1 )
  205. return 1;
  206. if ( !s1 && !s2 )
  207. return 0;
  208. return Q_stricmp( s1->GetName(), s2->GetName() );
  209. }
  210. //-----------------------------------------------------------------------------
  211. // Purpose: Player number comparison function
  212. //-----------------------------------------------------------------------------
  213. int __cdecl PlayersCompare(ListPanel *pPanel, const ListPanelItem &p1, const ListPanelItem &p2)
  214. {
  215. gameserveritem_t *s1 = ServerBrowserDialog().GetServer(p1.userData);
  216. gameserveritem_t *s2 = ServerBrowserDialog().GetServer(p2.userData);
  217. if ( !s1 && s2 )
  218. return -1;
  219. if ( !s2 && s1 )
  220. return 1;
  221. if ( !s1 && !s2 )
  222. return 0;
  223. int s1p = MAX( 0, s1->m_nPlayers - s1->m_nBotPlayers );
  224. int s1m = MAX( 0, s1->m_nMaxPlayers - s1->m_nBotPlayers );
  225. int s2p = MAX( 0, s2->m_nPlayers - s2->m_nBotPlayers );
  226. int s2m = MAX( 0, s2->m_nMaxPlayers - s2->m_nBotPlayers );
  227. // compare number of players
  228. if ( s1p > s2p )
  229. return -1;
  230. if ( s1p < s2p )
  231. return 1;
  232. // compare max players if number of current players is equal
  233. if ( s1m > s2m )
  234. return -1;
  235. if ( s1m < s2m )
  236. return 1;
  237. return 0;
  238. }
  239. //-----------------------------------------------------------------------------
  240. // Purpose: Player number comparison function
  241. //-----------------------------------------------------------------------------
  242. int __cdecl LastPlayedCompare(ListPanel *pPanel, const ListPanelItem &p1, const ListPanelItem &p2)
  243. {
  244. gameserveritem_t *s1 = ServerBrowserDialog().GetServer( p1.userData );
  245. gameserveritem_t *s2 = ServerBrowserDialog().GetServer( p2.userData );
  246. if ( !s1 && s2 )
  247. return -1;
  248. if ( !s2 && s1 )
  249. return 1;
  250. if ( !s1 && !s2 )
  251. return 0;
  252. // compare number of players
  253. if ( s1->m_ulTimeLastPlayed > s2->m_ulTimeLastPlayed )
  254. return -1;
  255. if ( s1->m_ulTimeLastPlayed < s2->m_ulTimeLastPlayed )
  256. return 1;
  257. return 0;
  258. }
  259. //-----------------------------------------------------------------------------
  260. // Purpose: Tag comparison function
  261. //-----------------------------------------------------------------------------
  262. int __cdecl TagsCompare(ListPanel *pPanel, const ListPanelItem &p1, const ListPanelItem &p2)
  263. {
  264. gameserveritem_t *s1 = ServerBrowserDialog().GetServer(p1.userData);
  265. gameserveritem_t *s2 = ServerBrowserDialog().GetServer(p2.userData);
  266. if ( !s1 && s2 )
  267. return -1;
  268. if ( !s2 && s1 )
  269. return 1;
  270. if ( !s1 && !s2 )
  271. return 0;
  272. return Q_stricmp( s1->m_szGameTags, s2->m_szGameTags );
  273. }