1
1
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2
2
/* If you are missing that file, acquire a complete release at teeworlds.com. */
3
#include <algorithm> // sort
3
#include <algorithm> // sort TODO: remove this
5
5
#include <base/math.h>
6
6
#include <base/system.h>
26
26
CServerBrowser *m_pThis;
28
28
SortWrap(CServerBrowser *t, SortFunc f) : m_pfnSort(f), m_pThis(t) {}
29
bool operator()(int a, int b) { return (m_pThis->*m_pfnSort)(a, b); }
29
bool operator()(int a, int b) { return (g_Config.m_BrSortOrder ? (m_pThis->*m_pfnSort)(b, a) : (m_pThis->*m_pfnSort)(a, b)); }
32
32
CServerBrowser::CServerBrowser()
285
285
if(g_Config.m_BrSort == IServerBrowser::SORT_NAME)
286
std::sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareName));
286
std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareName));
287
287
else if(g_Config.m_BrSort == IServerBrowser::SORT_PING)
288
std::sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortComparePing));
288
std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortComparePing));
289
289
else if(g_Config.m_BrSort == IServerBrowser::SORT_MAP)
290
std::sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareMap));
290
std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareMap));
291
291
else if(g_Config.m_BrSort == IServerBrowser::SORT_NUMPLAYERS)
292
std::sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this,
292
std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this,
293
293
g_Config.m_BrFilterSpectators ? &CServerBrowser::SortCompareNumPlayers : &CServerBrowser::SortCompareNumClients));
294
294
else if(g_Config.m_BrSort == IServerBrowser::SORT_GAMETYPE)
295
std::sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareGametype));
297
// invert the list if requested
298
if(g_Config.m_BrSortOrder)
300
for(i = 0; i < m_NumSortedServers/2; i++)
302
int Temp = m_pSortedServerlist[i];
303
m_pSortedServerlist[i] = m_pSortedServerlist[m_NumSortedServers-i-1];
304
m_pSortedServerlist[m_NumSortedServers-i-1] = Temp;
295
std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareGametype));
309
298
for(i = 0; i < m_NumSortedServers; i++)
399
387
pEntry->m_Info.m_NetAddr = Addr;
401
389
pEntry->m_Info.m_Latency = 999;
402
net_addr_str(&Addr, pEntry->m_Info.m_aAddress, sizeof(pEntry->m_Info.m_aAddress));
390
net_addr_str(&Addr, pEntry->m_Info.m_aAddress, sizeof(pEntry->m_Info.m_aAddress), true);
403
391
str_copy(pEntry->m_Info.m_aName, pEntry->m_Info.m_aAddress, sizeof(pEntry->m_Info.m_aName));
405
393
// check if it's a favorite
507
495
/* do the broadcast version */
508
496
Packet.m_ClientID = -1;
509
497
mem_zero(&Packet, sizeof(Packet));
510
Packet.m_Address.type = NETTYPE_ALL|NETTYPE_LINK_BROADCAST;
498
Packet.m_Address.type = m_pNetClient->NetType()|NETTYPE_LINK_BROADCAST;
511
499
Packet.m_Flags = NETSENDFLAG_CONNLESS;
512
500
Packet.m_DataSize = sizeof(Buffer);
513
501
Packet.m_pData = Buffer;
539
527
if(g_Config.m_Debug)
541
529
char aAddrStr[NETADDR_MAXSTRSIZE];
542
net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr));
530
net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr), true);
544
532
str_format(aBuf, sizeof(aBuf),"requesting server info from %s", aAddrStr);
545
533
m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client_srvbrowse", aBuf);
680
668
if(g_Config.m_Debug)
682
670
char aAddrStr[NETADDR_MAXSTRSIZE];
683
net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr));
671
net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr), true);
685
673
str_format(aBuf, sizeof(aBuf), "added fav, %s", aAddrStr);
686
674
m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client_srvbrowse", aBuf);
735
723
CServerBrowser *pSelf = (CServerBrowser *)pUserData;
738
725
char aAddrStr[128];
739
726
char aBuffer[256];
740
for(i = 0; i < pSelf->m_NumFavoriteServers; i++)
727
for(int i = 0; i < pSelf->m_NumFavoriteServers; i++)
742
net_addr_str(&pSelf->m_aFavoriteServers[i], aAddrStr, sizeof(aAddrStr));
729
net_addr_str(&pSelf->m_aFavoriteServers[i], aAddrStr, sizeof(aAddrStr), true);
743
730
str_format(aBuffer, sizeof(aBuffer), "add_favorite %s", aAddrStr);
744
731
pConfig->WriteLine(aBuffer);