- Timestamp:
- Dec 13, 2007, 6:02:07 PM (17 years ago)
- Location:
- code/branches/FICN/src/network
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/network/Client.cc
r496 r514 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 1 28 // 2 29 // C++ Implementation: Client … … 90 117 return client_connection.sendPackets(); 91 118 } 92 119 93 120 /** 94 121 * submits a chat message to the server … … 133 160 } 134 161 135 /** 162 /** 136 163 * Sends out all the packets queued by addXXX 137 164 */ … … 147 174 return false; 148 175 } 149 176 150 177 /** 151 178 * Performs a GameState update … … 160 187 return; 161 188 } 162 189 163 190 void Client::processGamestate( GameStateCompressed *data){ 164 191 gamestate.pushGameState(*data); … … 167 194 return; 168 195 } 169 196 170 197 void Client::processClassid(classid *clid){ 171 198 orxonox::Identifier *id; … … 175 202 return; 176 203 } 177 204 178 205 void Client::processChat( chat *data){ 179 206 std::cout << "Server: " << data->message << std::endl; 180 207 } 181 208 182 209 } -
code/branches/FICN/src/network/ClientConnection.cc
r448 r514 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 1 28 // 2 29 // C++ Interface: ClientConnection … … 58 85 return getPacket(address); 59 86 } 60 87 61 88 bool ClientConnection::queueEmpty(){ 62 89 return buffer.isEmpty(); -
code/branches/FICN/src/network/ClientInformation.cc
r446 r514 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 * ... 23 * Co-authors: 24 * ... 25 * 26 */ 27 1 28 // 2 29 // C++ Implementation: ClientInformation 3 30 // 4 // Description: 31 // Description: 5 32 // 6 33 // … … 41 68 // this->preve = pref; 42 69 // } 43 // 70 // 44 71 // ClientInformation::ClientInformation(ClientInformation *prev, ClientInformation *next){ 45 72 // this->nexte = next; -
code/branches/FICN/src/network/ConnectionManager.cc
r505 r514 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 1 28 // 2 29 // C++ Interface: ConnectionManager … … 24 51 25 52 boost::thread_group network_threads; 26 53 27 54 ConnectionManager::ConnectionManager(ClientInformation *head){ 28 55 quit=false; … … 52 79 return NULL; 53 80 } 54 81 55 82 ENetPacket *ConnectionManager::getPacket(int &clientID){ 56 83 ENetAddress address; … … 82 109 return true; 83 110 } 84 111 85 112 bool ConnectionManager::addPacket(ENetPacket *packet, int clientID){ 86 113 if(enet_peer_send(head_->findClient(clientID)->getPeer(), clientID, packet)!=0) … … 88 115 return true; 89 116 } 90 117 91 118 bool ConnectionManager::addPacketAll(ENetPacket *packet){ 92 119 for(ClientInformation *i=head_->next(); i!=0; i=i->next()){ … … 105 132 return false; 106 133 } 107 134 108 135 bool ConnectionManager::sendPackets(){ 109 136 ENetEvent event; … … 155 182 enet_host_destroy(server); 156 183 } 157 184 158 185 void ConnectionManager::disconnectClients(){ 159 186 ENetEvent event; … … 190 217 // return clientDisconnect(*peer); 191 218 // } 192 193 194 219 220 221 195 222 bool ConnectionManager::clientDisconnect(ENetPeer *peer){ 196 223 return head_->removeClient(peer); … … 205 232 return true; 206 233 } 207 234 208 235 int ConnectionManager::getClientID(ENetPeer peer){ 209 236 return getClientID(peer.address); 210 237 } 211 238 212 239 int ConnectionManager::getClientID(ENetAddress address){ 213 240 return head_->findClient(&address)->getID(); 214 241 } 215 242 216 243 ENetPeer *ConnectionManager::getClientPeer(int clientID){ 217 244 return head_->findClient(clientID)->getPeer(); 218 245 } 219 246 220 247 void ConnectionManager::syncClassid(int clientID){ 221 248 int i=0; … … 235 262 sendPackets(); 236 263 } 237 264 238 265 } -
code/branches/FICN/src/network/GameStateClient.cc
r505 r514 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 * ... 23 * Co-authors: 24 * ... 25 * 26 */ 27 1 28 #include "GameStateClient.h" 2 29 … … 52 79 sync.data = data; 53 80 data+=sync.length; 54 81 55 82 if(it->objectID!=sync.objectID){ 56 83 // bad luck ;) … … 73 100 ++it; 74 101 } 75 102 76 103 return true; 77 104 } … … 117 144 uLongf length=normsize; 118 145 retval = uncompress( dest, &length, a.data, (uLong)compsize ); 119 146 120 147 switch ( retval ) { 121 148 case Z_OK: std::cout << "successfully compressed" << std::endl; break; … … 124 151 case Z_DATA_ERROR: std::cout << "data corrupted" << std::endl; break; 125 152 } 126 153 127 154 GameState gamestate; 128 155 gamestate.id = a.id; … … 130 157 gamestate.data = dest; 131 158 gamestate.diffed = a.diffed; 132 159 133 160 return gamestate; 134 161 } -
code/branches/FICN/src/network/GameStateManager.cc
r436 r514 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 1 28 // 2 29 // C++ Implementation: GameStateManager 3 30 // 4 // Description: 31 // Description: 5 32 // 6 33 // … … 47 74 48 75 /** 49 * This function goes through the whole list of synchronisables and 76 * This function goes through the whole list of synchronisables and 50 77 * saves all the synchronisables to a flat "list". 51 78 * @return struct of type gamestate containing the size of the whole gamestate and a pointer linking to the flat list … … 61 88 // struct for return value of Synchronisable::getData() 62 89 syncData sync; 63 90 64 91 GameState *retval=new GameState; //return value 65 92 retval->id=id; 66 93 // reserve a little memory and increase it later on 67 94 retval->data = (unsigned char*)malloc(1); 68 95 69 96 // offset of memory functions 70 97 int offset=0; … … 77 104 // allocate additional space 78 105 retval->data = (unsigned char *)realloc((void *)retval->data, totalsize); 79 106 80 107 // run Synchronisable::getData with offset and additional place for 3 ints in between (for ids and length) 81 108 sync=it->getData(retval->data+offset+3*sizeof(int)); … … 140 167 unsigned char* dest = (unsigned char*)malloc( buffer ); 141 168 int retval; 142 retval = compress( dest, &buffer, a->data, (uLong)size ); 143 169 retval = compress( dest, &buffer, a->data, (uLong)size ); 170 144 171 switch ( retval ) { 145 172 case Z_OK: std::cout << "successfully compressed" << std::endl; break; … … 148 175 case Z_DATA_ERROR: std::cout << "data corrupted" << std::endl; break; 149 176 } 150 177 151 178 GameStateCompressed compressedGamestate; 152 179 compressedGamestate.compsize = buffer; … … 155 182 compressedGamestate.data = dest; 156 183 compressedGamestate.diffed = a->diffed; 157 184 158 185 return compressedGamestate; 159 186 } -
code/branches/FICN/src/network/PacketBuffer.cc
r337 r514 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 1 28 // C++ PacketBuffer 2 29 // d -
code/branches/FICN/src/network/PacketBufferTestExt.cc
r367 r514 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 * ... 23 * Co-authors: 24 * ... 25 * 26 */ 27 1 28 #include <string> 2 29 #include <iostream> -
code/branches/FICN/src/network/PacketDecoder.cc
r440 r514 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 * Dumeni Manatschal, (C) 2007 23 * Co-authors: 24 * ... 25 * 26 */ 27 1 28 /* 2 29 * Class contains functions to determine and decode incomming packages 3 30 * ->don't read this without the class PacketGenerator, since they belong together 4 * 31 * 5 32 * Autor: Dumeni Manatschal 6 * 33 * 7 34 */ 8 35 … … 58 85 ack* a = new ack; 59 86 *a = *(ack*)packet->data; //press pattern of ack on new data 60 61 //clean memory 62 enet_packet_destroy( packet ); 63 87 88 //clean memory 89 enet_packet_destroy( packet ); 90 64 91 printAck( a ); //debug info 65 92 } … … 69 96 mouse* mouseMove = new mouse; 70 97 //copy data of packet->data to new struct 71 *mouseMove = *(mouse*)packet->data; 72 73 //clean memory 74 enet_packet_destroy( packet ); 75 98 *mouseMove = *(mouse*)packet->data; 99 100 //clean memory 101 enet_packet_destroy( packet ); 102 76 103 printMouse( mouseMove ); //debug info 77 104 } … … 81 108 keyboard* key = new keyboard; 82 109 *key = *(keyboard*)packet->data; //see above 83 84 //clean memory 85 enet_packet_destroy( packet ); 86 110 111 //clean memory 112 enet_packet_destroy( packet ); 113 87 114 printKey( key ); //debug info 88 115 … … 94 121 chatting->id = (int)*packet->data; //first copy id into new struct 95 122 //since the chat message is a char*, allocate the memory needed 96 char* reserve = new char[packet->dataLength-4]; 123 char* reserve = new char[packet->dataLength-4]; 97 124 //copy the transmitted bytestream into the new generated char*, 98 //note the lenght of the message is represented as "packet->dataLength-sizeof( int )" 125 //note the lenght of the message is represented as "packet->dataLength-sizeof( int )" 99 126 memcpy( &reserve[0], packet->data+sizeof(int), packet->dataLength-sizeof(int) ); 100 127 //put pointer of chatting struct to the begining of the new generated char* 101 128 chatting->message = reserve; 102 103 //clean memory 104 enet_packet_destroy( packet ); 105 129 130 //clean memory 131 enet_packet_destroy( packet ); 132 106 133 processChat( chatting, clientId ); //debug info 107 134 108 135 } 109 136 … … 126 153 //copy the GameStateCompressed data 127 154 memcpy( (void*)(currentState->data), (const void*)(data+4*sizeof( int ) + sizeof(bool)), currentState->compsize ); 128 155 129 156 //clean memory 130 157 enet_packet_destroy( packet ); -
code/branches/FICN/src/network/PacketGenerator.cc
r437 r514 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 * Dumeni Manatschal, (C) 2007 23 * Co-authors: 24 * ... 25 * 26 */ 27 1 28 /* 2 29 *Class generates packets that can be send by enet 3 30 * ->don't read this without the class PacketDecoder, since they belong together 4 * 31 * 5 32 * Autor: Dumeni Manatschal 6 * 33 * 7 34 */ 8 35 … … 26 53 ackreq->id = ACK; 27 54 ackreq->a = state; 28 55 29 56 ENetPacket *packet = enet_packet_create( ackreq , sizeof( *ackreq ), reliable ); 30 57 31 58 return packet; 32 59 } … … 39 66 mousemove->x = x; 40 67 mousemove->y = y; 41 68 42 69 ENetPacket *packet = enet_packet_create( mousemove , sizeof( *mousemove ), reliable ); 43 70 44 71 return packet; 45 72 } … … 51 78 key->id = KEYBOARD; 52 79 key->press = press; 53 80 54 81 ENetPacket *packet = enet_packet_create( key , sizeof( *key ), reliable ); 55 82 56 83 return packet; 57 84 } … … 64 91 memcpy( &trans[1], (const void*)message, strlen( message ) + 1); 65 92 ENetPacket *packet = enet_packet_create( trans , sizeof( int ) + strlen( message ) + 1, reliable ); 66 93 67 94 return packet; 68 95 } … … 71 98 ENetPacket* PacketGenerator::gstate( GameStateCompressed* states, int reliable ) 72 99 { 73 int* gid = new int; 100 int* gid = new int; 74 101 *gid = GAMESTATE; //first assign the correct enet id 75 102 int totalLen = 4*sizeof( int ) + sizeof(bool) + states->compsize; //calculate the total size of the datastream memory … … 87 114 //create an enet packet with the generated bytestream 88 115 ENetPacket *packet = enet_packet_create( data , totalLen, reliable ); 89 116 90 117 return packet; 91 118 } -
code/branches/FICN/src/network/dummyclient.cc
r445 r514 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 1 28 //o 2 29 // Dummy client to test ConnectionManager and PacketBuffer classes -
code/branches/FICN/src/network/dummyclient2.cc
r446 r514 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 1 28 // 2 29 // Dummy client to test ConnectionManager, PacketBuffer, ClientConnection and other classes -
code/branches/FICN/src/network/dummyserver.cc
r445 r514 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 1 28 // 2 29 // Dummy server to test ConnectionManager and PacketBuffer classes
Note: See TracChangeset
for help on using the changeset viewer.