Last change
on this file since 351 was
346,
checked in by rgrieder, 17 years ago
|
- adjusted the entire source to compile under windows visual studio too:
- added some ugly conversions
- changed some illegal code pieces (gcc however accepted it)
- added a few files from reto's framework to evade linker errors (no more dynamic linking)
- inserted some 'return true' to justify the return type
- excluded the levelLoader in the orxonox.cc (couldn't make it work, parsing error)
- wrote about 5 code #branches to compensate for missing usleep() under windows
|
File size:
1.1 KB
|
Rev | Line | |
---|
[196] | 1 | // |
---|
| 2 | // Dummy server to test ConnectionManager and PacketBuffer classes |
---|
| 3 | // |
---|
| 4 | // Author: Oliver Scheuss |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | #include <iostream> |
---|
[341] | 8 | #include <enet/enet.h> |
---|
[285] | 9 | #include "ConnectionManager.h" |
---|
| 10 | #include "PacketManager.h" |
---|
[196] | 11 | |
---|
[346] | 12 | // workaround for usleep(int) under windows |
---|
| 13 | #ifdef WIN32 |
---|
| 14 | #include "winbase.h" |
---|
| 15 | #endif |
---|
| 16 | |
---|
| 17 | |
---|
[196] | 18 | using namespace network; |
---|
| 19 | |
---|
| 20 | int main(){ |
---|
| 21 | ConnectionManager server = ConnectionManager(); |
---|
| 22 | bool quit=false; |
---|
| 23 | ENetPacket *packet; |
---|
[204] | 24 | ENetEvent event; |
---|
[196] | 25 | server.createListener(); |
---|
[285] | 26 | |
---|
[204] | 27 | PacketDecoder dec; |
---|
[285] | 28 | |
---|
[196] | 29 | while(!quit){ |
---|
| 30 | if(server.queueEmpty()) |
---|
[346] | 31 | // under windows, use Sleep(milliseconds) instead of usleep(microseconds) |
---|
| 32 | // Warning: Sleep(1) is ten times longer than usleep(100)! |
---|
| 33 | #ifdef WIN32 |
---|
| 34 | Sleep(1); |
---|
| 35 | #else |
---|
[196] | 36 | usleep(100); |
---|
[346] | 37 | #endif |
---|
[196] | 38 | else{ |
---|
[204] | 39 | ENetAddress addr; |
---|
| 40 | packet=server.getPacket(addr); |
---|
[196] | 41 | if(packet==NULL){ |
---|
| 42 | // there was some error |
---|
| 43 | //std::cout << "null pointer" << std::endl; |
---|
| 44 | quit=true; |
---|
| 45 | } |
---|
[204] | 46 | else{ |
---|
| 47 | //std::cout << "We received: " << packet->data << std::endl; |
---|
| 48 | dec.elaborate(packet, 1); |
---|
| 49 | } |
---|
[196] | 50 | } |
---|
| 51 | } |
---|
| 52 | server.quitListener(); |
---|
| 53 | return 0; |
---|
| 54 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.