Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/masterserver2/src/libraries/network/ServerList.cc @ 8241

Last change on this file since 8241 was 8203, checked in by smerkli, 13 years ago

yay, works

File size: 2.7 KB
RevLine 
[7565]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Sandro 'smerkli' Merkli
24 *   Co-authors:
25 *      ...
26 *
27 */
28
[7589]29#include "ServerList.h"
[7565]30
31namespace orxonox
32{ 
33  ServerList::ServerList()
34  { /* create a new list */ }
35
36  ServerList::~ServerList()
37  { /* delete the list */
[7589]38    serverlist.clear();
[7565]39  }
40
[7589]41  int 
[8202]42  ServerList::addServer( packet::ServerInformation toadd,
43    ENetPeer *peer )
44  { 
45    ServerListElem toAdd;
46    toAdd.ServerInfo = toadd;
47    toAdd.peer = peer;
48
49    this->serverlist.push_back( toAdd ); 
[7565]50    return 0;
51  }
52
[7589]53  bool 
54  ServerList::delServerByName( std::string name )
[7565]55  { 
56    /* get an iterator */
[8202]57    std::list<ServerListElem>::iterator i;
[7565]58
59    /* loop through list elements */
60    for( i = serverlist.begin(); i != serverlist.end(); ++i ) 
[8202]61      if( (*i).ServerInfo.getServerName() == name )
[7565]62      { /* found this name, remove and quit */
[8203]63        this->serverlist.clear();
[7565]64        return true;
65      }
66    return false;
67  }
68
69  bool ServerList::delServerByAddress( std::string address )
70  { 
71    /* get an iterator */
[8202]72    std::list<ServerListElem>::iterator i;
[7565]73
74    /* loop through list elements */
[8202]75    for( i = serverlist.begin(); i != serverlist.end(); ++i ) 
76      if( (*i).ServerInfo.getServerIP() == address )
[7565]77      { /* found this name, remove and quit */
[7657]78        this->serverlist.erase( i );
[7565]79        return true;
80      }
81    return false;
82  }
83
84
85  /* sort by name */
[8202]86  bool sub_compare_names( ServerListElem no1, 
87    ServerListElem no2 )
88  { return no1.ServerInfo.getServerName() > no2.ServerInfo.getServerName(); }
[7565]89
90  void ServerList::sortByName()
91  { 
92    this->serverlist.sort( sub_compare_names ); 
93  }
94 
95  /* sort by ping */
[8202]96  bool sub_compare_pings( ServerListElem no1, 
97    ServerListElem no2 )
[7589]98  { 
[8202]99    return no1.ServerInfo.getServerName() > no2.ServerInfo.getServerName();
[7589]100  }
[7565]101
102  void ServerList::sortByPing()
103  {
104    this->serverlist.sort( sub_compare_pings ); 
105  }
106
107}
Note: See TracBrowser for help on using the repository browser.