Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/masterserver/src/modules/masterserver/ServerList.cpp @ 7565

Last change on this file since 7565 was 7565, checked in by smerkli, 14 years ago

Initial check-in of the master server code. Nowhere near completion yet, just for backup purposes now.

File size: 2.5 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 ServerList::addServer( ServerInformation *toadd )
42  { this->serverlist.push_back( toadd ); 
43    return 0;
44  }
45
46  bool ServerList::delServerByName( std::string name )
47  { 
48    /* get an iterator */
49    list<ServerInformation *>::iterator i;
50
51    /* loop through list elements */
52    for( i = serverlist.begin(); i != serverlist.end(); ++i ) 
53      if( (*i)->serverName_ == name )
54      { /* found this name, remove and quit */
55        this->serverlist.remove( i );
56        return true;
57      }
58    return false;
59  }
60
61  bool ServerList::delServerByAddress( std::string address )
62  { 
63    /* get an iterator */
64    list<ServerInformation *>::iterator i;
65
66    /* loop through list elements */
67    for( i=serverlist.begin(); i != serverlist.end(); ++i ) 
68      if( (*i)->serverIP_ == address )
69      { /* found this name, remove and quit */
70        this->serverlist.remove( i );
71        return true;
72      }
73    return false;
74  }
75
76
77  /* sort by name */
78  bool sub_compare_names( ServerInformation *no1, ServerInformation *no2 )
79  { return no1->serverName_ > no2->serverName_; }
80
81  void ServerList::sortByName()
82  { 
83    this->serverlist.sort( sub_compare_names ); 
84  }
85 
86  /* sort by ping */
87  bool sub_compare_pings( ServerInformation *no1, ServerInformation *no2 )
88  { TODO return no1->serverName_ > no2->serverName_; }
89
90  void ServerList::sortByPing()
91  {
92    this->serverlist.sort( sub_compare_pings ); 
93  }
94
95}
Note: See TracBrowser for help on using the repository browser.