~ubuntu-branches/ubuntu/trusty/teeworlds/trusty-updates

« back to all changes in this revision

Viewing changes to src/engine/client/serverbrowser.cpp

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2013-05-05 09:49:34 UTC
  • mfrom: (1.2.5)
  • Revision ID: package-import@ubuntu.com-20130505094934-uidw42ov1t0jlvrz
Tags: 0.6.2+dfsg-1
* New upstream release.
  - Update patches.
* Pass $CPPFLAGS to the build system.
* Switch to my @debian.org email address.
* Bump Standards-Version to 3.9.4, no changes needed.
* Change Vcs host to anonscm.debian.org.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
4
4
 
5
5
#include <base/math.h>
6
6
#include <base/system.h>
26
26
        CServerBrowser *m_pThis;
27
27
public:
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)); }
30
30
};
31
31
 
32
32
CServerBrowser::CServerBrowser()
283
283
 
284
284
        // sort
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));
296
 
 
297
 
        // invert the list if requested
298
 
        if(g_Config.m_BrSortOrder)
299
 
        {
300
 
                for(i = 0; i < m_NumSortedServers/2; i++)
301
 
                {
302
 
                        int Temp = m_pSortedServerlist[i];
303
 
                        m_pSortedServerlist[i] = m_pSortedServerlist[m_NumSortedServers-i-1];
304
 
                        m_pSortedServerlist[m_NumSortedServers-i-1] = Temp;
305
 
                }
306
 
        }
 
295
                std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareGametype));
307
296
 
308
297
        // set indexes
309
298
        for(i = 0; i < m_NumSortedServers; i++)
381
370
        }*/
382
371
 
383
372
        pEntry->m_GotInfo = 1;
384
 
        Sort();
385
373
}
386
374
 
387
375
CServerBrowser::CServerEntry *CServerBrowser::Add(const NETADDR &Addr)
399
387
        pEntry->m_Info.m_NetAddr = Addr;
400
388
 
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));
404
392
 
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)
540
528
        {
541
529
                char aAddrStr[NETADDR_MAXSTRSIZE];
542
 
                net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr));
 
530
                net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr), true);
543
531
                char aBuf[256];
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)
681
669
        {
682
670
                char aAddrStr[NETADDR_MAXSTRSIZE];
683
 
                net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr));
 
671
                net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr), true);
684
672
                char aBuf[256];
685
673
                str_format(aBuf, sizeof(aBuf), "added fav, %s", aAddrStr);
686
674
                m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client_srvbrowse", aBuf);
734
722
{
735
723
        CServerBrowser *pSelf = (CServerBrowser *)pUserData;
736
724
 
737
 
        int i;
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++)
741
728
        {
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);
745
732
        }