[514] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * |
---|
| 4 | * |
---|
| 5 | * License notice: |
---|
| 6 | * |
---|
| 7 | * This program is free software; you can redistribute it and/or |
---|
| 8 | * modify it under the terms of the GNU General Public License |
---|
| 9 | * as published by the Free Software Foundation; either version 2 |
---|
| 10 | * of the License, or (at your option) any later version. |
---|
| 11 | * |
---|
| 12 | * This program is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * GNU General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
| 18 | * along with this program; if not, write to the Free Software |
---|
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 20 | * |
---|
| 21 | * Author: |
---|
| 22 | * Oliver Scheuss, (C) 2007 |
---|
| 23 | * Co-authors: |
---|
| 24 | * ... |
---|
| 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
[442] | 28 | // |
---|
| 29 | // Dummy server to test ConnectionManager and PacketBuffer classes |
---|
| 30 | // |
---|
| 31 | // Author: Oliver Scheuss |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | #include <iostream> |
---|
| 35 | #include <enet/enet.h> |
---|
| 36 | #include "ConnectionManager.h" |
---|
| 37 | #include "PacketManager.h" |
---|
| 38 | #include "ClientInformation.h" |
---|
| 39 | |
---|
[367] | 40 | #ifdef WIN32 |
---|
| 41 | #include <windows.h> |
---|
| 42 | #define usleep(x) Sleep((x)/1000) |
---|
| 43 | #else |
---|
| 44 | #include <unistd.h> |
---|
[442] | 45 | #endif |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | using namespace network; |
---|
| 49 | |
---|
| 50 | int main(){ |
---|
| 51 | bool quit=false; |
---|
| 52 | ENetPacket *packet; |
---|
| 53 | ClientInformation clients; |
---|
| 54 | ConnectionManager server = ConnectionManager(&clients); |
---|
| 55 | server.createListener(); |
---|
| 56 | |
---|
| 57 | PacketDecoder dec; |
---|
| 58 | |
---|
| 59 | while(!quit){ |
---|
| 60 | if(server.queueEmpty()) |
---|
| 61 | // Warning: usleep(100) is Sleep(100/1000) = Sleep(0), which is nothing! |
---|
[445] | 62 | usleep(1); |
---|
[442] | 63 | else{ |
---|
| 64 | ENetAddress addr; |
---|
| 65 | packet=server.getPacket(addr); |
---|
| 66 | if(packet==NULL){ |
---|
| 67 | // there was some error |
---|
| 68 | //std::cout << "null pointer" << std::endl; |
---|
| 69 | quit=true; |
---|
| 70 | } |
---|
| 71 | else{ |
---|
| 72 | //std::cout << "We received: " << packet->data << std::endl; |
---|
| 73 | dec.elaborate(packet, 1); |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | server.quitListener(); |
---|
| 78 | return 0; |
---|
| 79 | } |
---|