| [1056] | 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 | *      Oliver Scheuss, (C) 2007 | 
|---|
|  | 24 | *   Co-authors: | 
|---|
|  | 25 | *      ... | 
|---|
|  | 26 | * | 
|---|
|  | 27 | */ | 
|---|
| [514] | 28 |  | 
|---|
| [217] | 29 | // | 
|---|
|  | 30 | // Dummy client to test ConnectionManager, PacketBuffer, ClientConnection and other classes | 
|---|
|  | 31 | // | 
|---|
|  | 32 | // Author: Oliver Scheuss | 
|---|
|  | 33 |  | 
|---|
|  | 34 | #include <iostream> | 
|---|
|  | 35 | #include <string> | 
|---|
|  | 36 | #include <enet/enet.h> | 
|---|
| [777] | 37 |  | 
|---|
|  | 38 | #include "util/Sleep.h" | 
|---|
| [285] | 39 | #include "PacketManager.h" | 
|---|
| [781] | 40 | #include "PacketTypes.h" | 
|---|
| [285] | 41 | #include "ClientConnection.h" | 
|---|
| [217] | 42 |  | 
|---|
|  | 43 | using namespace network; | 
|---|
|  | 44 |  | 
|---|
|  | 45 | int main(){ | 
|---|
|  | 46 | network::PacketGenerator pck; | 
|---|
|  | 47 |  | 
|---|
|  | 48 | std::cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl; | 
|---|
|  | 49 | std::string str; | 
|---|
|  | 50 | std::getline(std::cin, str); | 
|---|
|  | 51 | std::cout << "You entered: " << str << std::endl; | 
|---|
|  | 52 | if(str.compare("")==0) | 
|---|
|  | 53 | str="127.0.0.1"; | 
|---|
|  | 54 |  | 
|---|
|  | 55 | ClientConnection client = ClientConnection(55556, str); | 
|---|
|  | 56 |  | 
|---|
|  | 57 | client.createConnection(); | 
|---|
| [285] | 58 |  | 
|---|
| [217] | 59 | if(client.waitEstablished(10000)) | 
|---|
|  | 60 | std::cout << "Connection established" << std::endl; | 
|---|
|  | 61 | else | 
|---|
|  | 62 | std::cout << "Connection failed" << std::endl; | 
|---|
| [285] | 63 |  | 
|---|
| [660] | 64 | ENetPacket *packet;  //FIXME: unused var! | 
|---|
| [217] | 65 | ENetEvent event; | 
|---|
| [285] | 66 |  | 
|---|
|  | 67 |  | 
|---|
|  | 68 |  | 
|---|
| [217] | 69 | for(int i=0; i<10; i++){ | 
|---|
| [777] | 70 | // weihnachtsmann bringt packete | 
|---|
|  | 71 | // extend the packet and append the string foo to it | 
|---|
|  | 72 | // send packet to peer on channel id 0 | 
|---|
| [217] | 73 | client.addPacket(pck.chatMessage("test")); | 
|---|
| [777] | 74 | // keep the timeout very small for low delay | 
|---|
| [217] | 75 | if(client.sendPackets(&event)){ | 
|---|
|  | 76 | std::cout << "successfully sent: " << event.type << std::endl; | 
|---|
|  | 77 | }else{ | 
|---|
|  | 78 | std::cout << "failed sending" << std::endl; | 
|---|
|  | 79 | } | 
|---|
| [777] | 80 | //    usleep(1000000); | 
|---|
| [217] | 81 | } | 
|---|
| [446] | 82 | usleep(1000000); | 
|---|
| [777] | 83 | // now disconnect | 
|---|
| [217] | 84 | if(client.closeConnection()) | 
|---|
|  | 85 | std::cout << "Connection successfully closed" << std::endl; | 
|---|
|  | 86 | else | 
|---|
|  | 87 | std::cout << "Connection closing failed" << std::endl; | 
|---|
|  | 88 |  | 
|---|
| [777] | 89 | // 3 seconds timeout | 
|---|
| [217] | 90 | return 0; | 
|---|
|  | 91 | } | 
|---|
|  | 92 |  | 
|---|