Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/network/ServerList.cc @ 7891

Last change on this file since 7891 was 7801, checked in by dafrick, 14 years ago

Merging presentation2 branch back to trunk.

File size: 2.6 KB
Line 
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
29#include "ServerList.h"
30
31namespace orxonox
32{ 
33  ServerList::ServerList()
34  { /* create a new list */ }
35
36  ServerList::~ServerList()
37  { /* delete the list */
38    serverlist.clear();
39  }
40
41  int 
42  ServerList::addServer( packet::ServerInformation toadd )
43  { this->serverlist.push_back( toadd ); 
44    return 0;
45  }
46
47  bool 
48  ServerList::delServerByName( std::string name )
49  { 
50    /* get an iterator */
51    std::list<packet::ServerInformation>::iterator i;
52
53    /* loop through list elements */
54    for( i = serverlist.begin(); i != serverlist.end(); ++i ) 
55      if( (*i).getServerName() == name )
56      { /* found this name, remove and quit */
57        this->serverlist.erase( i );
58        return true;
59      }
60    return false;
61  }
62
63  bool ServerList::delServerByAddress( std::string address )
64  { 
65    /* get an iterator */
66    std::list<packet::ServerInformation>::iterator i;
67
68    /* loop through list elements */
69    for( i=serverlist.begin(); i != serverlist.end(); ++i ) 
70      if( (*i).getServerIP() == address )
71      { /* found this name, remove and quit */
72        this->serverlist.erase( i );
73        return true;
74      }
75    return false;
76  }
77
78
79  /* sort by name */
80  bool sub_compare_names( packet::ServerInformation no1, 
81    packet::ServerInformation no2 )
82  { return no1.getServerName() > no2.getServerName(); }
83
84  void ServerList::sortByName()
85  { 
86    this->serverlist.sort( sub_compare_names ); 
87  }
88 
89  /* sort by ping */
90  bool sub_compare_pings( packet::ServerInformation no1, 
91    packet::ServerInformation no2 )
92  { 
93    /* TODO */
94    return no1.getServerName() > no2.getServerName();
95  }
96
97  void ServerList::sortByPing()
98  {
99    this->serverlist.sort( sub_compare_pings ); 
100  }
101
102}
Note: See TracBrowser for help on using the repository browser.