[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 | |
---|
| 31 | namespace 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 |
---|
[7657] | 42 | ServerList::addServer( packet::ServerInformation toadd ) |
---|
[7565] | 43 | { this->serverlist.push_back( toadd ); |
---|
| 44 | return 0; |
---|
| 45 | } |
---|
| 46 | |
---|
[7589] | 47 | bool |
---|
| 48 | ServerList::delServerByName( std::string name ) |
---|
[7565] | 49 | { |
---|
| 50 | /* get an iterator */ |
---|
[7657] | 51 | std::list<packet::ServerInformation>::iterator i; |
---|
[7565] | 52 | |
---|
| 53 | /* loop through list elements */ |
---|
| 54 | for( i = serverlist.begin(); i != serverlist.end(); ++i ) |
---|
[7657] | 55 | if( (*i).getServerName() == name ) |
---|
[7565] | 56 | { /* found this name, remove and quit */ |
---|
[7657] | 57 | this->serverlist.erase( i ); |
---|
[7565] | 58 | return true; |
---|
| 59 | } |
---|
| 60 | return false; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | bool ServerList::delServerByAddress( std::string address ) |
---|
| 64 | { |
---|
| 65 | /* get an iterator */ |
---|
[7657] | 66 | std::list<packet::ServerInformation>::iterator i; |
---|
[7565] | 67 | |
---|
| 68 | /* loop through list elements */ |
---|
| 69 | for( i=serverlist.begin(); i != serverlist.end(); ++i ) |
---|
[7657] | 70 | if( (*i).getServerIP() == address ) |
---|
[7565] | 71 | { /* found this name, remove and quit */ |
---|
[7657] | 72 | this->serverlist.erase( i ); |
---|
[7565] | 73 | return true; |
---|
| 74 | } |
---|
| 75 | return false; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | /* sort by name */ |
---|
[7657] | 80 | bool sub_compare_names( packet::ServerInformation no1, |
---|
| 81 | packet::ServerInformation no2 ) |
---|
| 82 | { return no1.getServerName() > no2.getServerName(); } |
---|
[7565] | 83 | |
---|
| 84 | void ServerList::sortByName() |
---|
| 85 | { |
---|
| 86 | this->serverlist.sort( sub_compare_names ); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | /* sort by ping */ |
---|
[7657] | 90 | bool sub_compare_pings( packet::ServerInformation no1, |
---|
| 91 | packet::ServerInformation no2 ) |
---|
[7589] | 92 | { |
---|
| 93 | /* TODO */ |
---|
[7657] | 94 | return no1.getServerName() > no2.getServerName(); |
---|
[7589] | 95 | } |
---|
[7565] | 96 | |
---|
| 97 | void ServerList::sortByPing() |
---|
| 98 | { |
---|
| 99 | this->serverlist.sort( sub_compare_pings ); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | } |
---|