[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 | |
---|
| 29 | #ifndef _ServerList_ |
---|
| 30 | #define _ServerList_ |
---|
| 31 | |
---|
| 32 | #include <list> |
---|
| 33 | #include <string> |
---|
[7568] | 34 | #include <network/packet/ServerInformation.h> |
---|
[7565] | 35 | |
---|
| 36 | /* methods necessary */ |
---|
[10622] | 37 | namespace orxonox |
---|
| 38 | { |
---|
[8937] | 39 | /* HELPER STRUCTURES */ |
---|
[10622] | 40 | struct ServerListElem |
---|
[8937] | 41 | { |
---|
| 42 | /* server information (name, IP, etc) */ |
---|
| 43 | packet::ServerInformation ServerInfo; |
---|
| 44 | |
---|
| 45 | /* peer pointer */ |
---|
| 46 | ENetPeer* peer; |
---|
| 47 | }; |
---|
| 48 | |
---|
| 49 | struct ServerListSearchResult |
---|
| 50 | { |
---|
| 51 | /* list element found */ |
---|
| 52 | ServerListElem result; |
---|
| 53 | |
---|
| 54 | /* successful search */ |
---|
| 55 | bool success; |
---|
| 56 | }; |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | |
---|
[7565] | 62 | /** This class is keeps a list of game servers |
---|
| 63 | * and some info about them. |
---|
| 64 | */ |
---|
[10622] | 65 | class ServerList |
---|
[7565] | 66 | { public: |
---|
| 67 | /** constructor */ |
---|
| 68 | ServerList(); |
---|
| 69 | |
---|
| 70 | /** destructor */ |
---|
| 71 | ~ServerList(); |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | /* BASIC MANIPULATION */ |
---|
| 75 | /** \param toadd the server to add. |
---|
[10622] | 76 | * |
---|
[7565] | 77 | * Add server to the game server list |
---|
| 78 | */ |
---|
[8937] | 79 | int addServer( packet::ServerInformation toadd, |
---|
| 80 | ENetPeer *peer ); |
---|
[7565] | 81 | |
---|
| 82 | /** \param name Name of the server to remove |
---|
[10622] | 83 | * |
---|
| 84 | * Remove server by name |
---|
[7565] | 85 | */ |
---|
| 86 | bool delServerByName( std::string name ); |
---|
| 87 | |
---|
| 88 | /** \param address IP address of the server to remove |
---|
[10622] | 89 | * |
---|
[7565] | 90 | * Remove server by address |
---|
| 91 | */ |
---|
| 92 | bool delServerByAddress( std::string address ); |
---|
| 93 | |
---|
[10622] | 94 | bool setNameByAddress( std::string address, std::string name ); |
---|
[7565] | 95 | |
---|
[10622] | 96 | bool setClientsByAddress( std::string address, int clientNumber ); |
---|
[7565] | 97 | |
---|
[8937] | 98 | /* SEARCHING */ |
---|
[10622] | 99 | /* \param address The address of the server that is to be |
---|
[8937] | 100 | * found |
---|
| 101 | * \return A struct containing a result of the search and a boolean |
---|
| 102 | * that is only true if the search was successful |
---|
[10622] | 103 | * |
---|
[8937] | 104 | * Find and return the list handle of a given address. |
---|
| 105 | */ |
---|
| 106 | ServerListSearchResult |
---|
| 107 | findServerByAddress( std::string address ); |
---|
| 108 | |
---|
| 109 | |
---|
[10622] | 110 | /* \param name The name of the server that is to be |
---|
[8937] | 111 | * found |
---|
| 112 | * \return The struct containing the list entry of the server |
---|
[10622] | 113 | * |
---|
[8937] | 114 | * Find and return the list handle of a given name. |
---|
| 115 | */ |
---|
| 116 | ServerListSearchResult |
---|
| 117 | findServerByName( std::string name ); |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | /* SORTING */ |
---|
[7565] | 121 | /** sort by name */ |
---|
| 122 | void sortByName(); |
---|
[10622] | 123 | |
---|
[7565] | 124 | /** sort by ping */ |
---|
| 125 | void sortByPing(); |
---|
| 126 | |
---|
| 127 | /** the list of servers for internal storage */ |
---|
[8937] | 128 | std::list<ServerListElem> serverlist; |
---|
[7651] | 129 | private: |
---|
[7565] | 130 | }; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | #endif /*_ServerList_*/ |
---|