[6067] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Benjamin Wuest |
---|
| 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | /* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_NETWORK module |
---|
| 18 | For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput |
---|
| 19 | */ |
---|
| 20 | #define DEBUG_MODULE_NETWORK |
---|
| 21 | |
---|
[6190] | 22 | #include "factory.h" |
---|
| 23 | #include "network_stream.h" |
---|
| 24 | |
---|
[6067] | 25 | /* include your own header */ |
---|
[6116] | 26 | #include "network_game_manager.h" |
---|
[6067] | 27 | |
---|
| 28 | |
---|
| 29 | /* using namespace std is default, this needs to be here */ |
---|
| 30 | using namespace std; |
---|
| 31 | |
---|
| 32 | /*! |
---|
| 33 | * Standard constructor |
---|
| 34 | */ |
---|
[6116] | 35 | NetworkGameManager::NetworkGameManager() |
---|
[6067] | 36 | { |
---|
| 37 | /* set the class id for the base object */ |
---|
| 38 | this->setClassID(CL_ENTITY_MANAGER, "EntityManager"); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | /*! |
---|
| 42 | * Standard destructor |
---|
| 43 | */ |
---|
[6116] | 44 | NetworkGameManager::~NetworkGameManager() |
---|
[6067] | 45 | { |
---|
[6190] | 46 | for ( int i = 0; i<inBuffer.size(); i++) |
---|
| 47 | { |
---|
| 48 | if ( inBuffer[i].buffer ) |
---|
| 49 | delete inBuffer[i].buffer; |
---|
| 50 | if ( outBuffer[i].buffer ) |
---|
| 51 | delete outBuffer[i].buffer; |
---|
| 52 | } |
---|
[6067] | 53 | } |
---|
| 54 | |
---|
| 55 | |
---|
[6190] | 56 | void NetworkGameManager::writeBytes(const byte* data, int length, int sender) |
---|
[6067] | 57 | { |
---|
| 58 | } |
---|
| 59 | |
---|
[6116] | 60 | int NetworkGameManager::readBytes(byte* data, int maxLength, int * reciever) |
---|
[6067] | 61 | { |
---|
| 62 | } |
---|
| 63 | |
---|
[6116] | 64 | void NetworkGameManager::writeDebug() const |
---|
[6067] | 65 | { |
---|
| 66 | } |
---|
| 67 | |
---|
[6116] | 68 | void NetworkGameManager::readDebug() const |
---|
[6067] | 69 | { |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | /*! |
---|
| 74 | * Checks whether this is connected to a server or a client |
---|
| 75 | * and afterwards creates the needed entity if possible |
---|
| 76 | * @param classID: The ID of the class of which an entity should be created |
---|
| 77 | */ |
---|
[6116] | 78 | void NetworkGameManager::createEntity(int classID) |
---|
[6067] | 79 | { |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | /*! |
---|
| 83 | * Checks whether this is connected to a server or a client |
---|
| 84 | * and afterwards removes the specified entity |
---|
| 85 | * @param uniqueID: The ID of the entity object which should be removed |
---|
| 86 | */ |
---|
[6116] | 87 | void NetworkGameManager::removeEntity(int uniqueID) |
---|
[6067] | 88 | { |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | /*! |
---|
| 94 | * Creates the needed entity on the server if possible |
---|
| 95 | * @param classID: The ID of the class of which an entity should be created |
---|
| 96 | */ |
---|
[6116] | 97 | void NetworkGameManager::requestCreateEntity(int classID) |
---|
[6067] | 98 | { |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | /*! |
---|
| 102 | * Removes the specified entity on the server |
---|
| 103 | * @param uniqueID: The ID of the entity object which should be removed |
---|
| 104 | */ |
---|
[6116] | 105 | void NetworkGameManager::requestRemoveEntity(int uniqueID) |
---|
[6067] | 106 | { |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | /*! |
---|
| 110 | * Creates the needed entity if possible |
---|
| 111 | * This function is called if this is a server |
---|
| 112 | * @param classID: The ID of the class of which an entity should be created |
---|
| 113 | */ |
---|
[6116] | 114 | void NetworkGameManager::executeCreateEntity(int classID) |
---|
[6067] | 115 | { |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | /*! |
---|
| 119 | * Removes the specified entity |
---|
| 120 | * This function is called if this is a server |
---|
| 121 | * @param uniqueID: The ID of the entity object which should be removed |
---|
| 122 | */ |
---|
[6116] | 123 | void NetworkGameManager::executeRemoveEntity(int uniqueID) |
---|
[6067] | 124 | { |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | /*! |
---|
| 128 | * Checks whether it is possible to create an entity of a given class |
---|
| 129 | * @return: true if the entity can be created, false otherwise |
---|
| 130 | */ |
---|
[6116] | 131 | bool NetworkGameManager::canCreateEntity(int classID) |
---|
[6067] | 132 | { |
---|
[6190] | 133 | return true; |
---|
[6067] | 134 | } |
---|
[6190] | 135 | |
---|
| 136 | /*! |
---|
| 137 | * Sends the Entities to the new connected client |
---|
| 138 | * @param userID: The ID of the user |
---|
| 139 | */ |
---|
| 140 | void NetworkGameManager::sendEntityList( int userID ) |
---|
| 141 | { |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | /** |
---|
| 145 | * Creates a buffer for user n |
---|
| 146 | * @param n The ID of the user |
---|
| 147 | */ |
---|
| 148 | void NetworkGameManager::resizeBufferVector( int n ) |
---|
| 149 | { |
---|
| 150 | for ( int i = inBuffer.size(); i<=n; i++) |
---|
| 151 | { |
---|
| 152 | clientBuffer inBuf; |
---|
| 153 | clientBuffer outBuf; |
---|
| 154 | |
---|
| 155 | inBuf.length = 0; |
---|
| 156 | outBuf.length = 0; |
---|
| 157 | |
---|
| 158 | inBuf.maxLength = 5*1014; |
---|
| 159 | outBuf.maxLength = 5*1024; |
---|
| 160 | |
---|
| 161 | inBuf.buffer = new byte[5*1014]; |
---|
| 162 | outBuf.buffer = new byte[5*1014]; |
---|
| 163 | |
---|
| 164 | inBuffer.push_back(inBuf); |
---|
| 165 | outBuffer.push_back(outBuf); |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | /** |
---|
| 170 | * Creates the entity on this host |
---|
| 171 | * @param classID: ClassID of the entity to create |
---|
| 172 | * @param uniqueID: Unique ID to assign to the synchronizeable |
---|
| 173 | * @param owner: owner of this synchronizealbe |
---|
| 174 | */ |
---|
| 175 | void NetworkGameManager::doCreateEntity( ClassID classID, int uniqueID, int owner ) |
---|
| 176 | { |
---|
[6197] | 177 | //BaseObject * b = Factory::fabricate( classID ); |
---|
| 178 | BaseObject * b = NULL; |
---|
[6190] | 179 | |
---|
| 180 | if ( b->isA(CL_SYNCHRONIZEABLE) ) |
---|
| 181 | { |
---|
| 182 | Synchronizeable * s = dynamic_cast<Synchronizeable*>(b); |
---|
| 183 | s->setUniqueID( uniqueID ); |
---|
| 184 | s->setOwner( owner ); |
---|
| 185 | this->networkStream->connectSynchronizeable( *s ); |
---|
| 186 | } |
---|
| 187 | else |
---|
| 188 | { |
---|
| 189 | PRINTF(1)("Class with ID %d is not a synchronizeable!", (int)classID); |
---|
| 190 | delete b; |
---|
| 191 | } |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | /** |
---|
| 195 | * Removes a entity on this host |
---|
| 196 | * @param uniqueID: unique ID assigned with the entity to remove |
---|
| 197 | */ |
---|
| 198 | void NetworkGameManager::doRemoveEntity( int uniqueID ) |
---|
| 199 | { |
---|
| 200 | SynchronizeableList::const_iterator it,e; |
---|
| 201 | it = this->networkStream->getSyncBegin(); |
---|
| 202 | e = this->networkStream->getSyncEnd(); |
---|
| 203 | |
---|
| 204 | while ( it != e ) |
---|
| 205 | { |
---|
| 206 | if ( (*it)->getUniqueID() == uniqueID ) |
---|
| 207 | { |
---|
| 208 | delete *it; |
---|
| 209 | break; |
---|
| 210 | } |
---|
| 211 | } |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | /** |
---|
| 215 | * Tell the synchronizeable that a user's synchronizeable is out of sync |
---|
| 216 | * @param uniqueID: unique ID assigned with the entity which is out of sync |
---|
| 217 | * @param userID: user ID who's synchronizeable is out of sync |
---|
| 218 | */ |
---|
| 219 | void NetworkGameManager::doRequestSync( int uniqueID, int userID ) |
---|
| 220 | { |
---|
| 221 | SynchronizeableList::const_iterator it,e; |
---|
| 222 | it = this->networkStream->getSyncBegin(); |
---|
| 223 | e = this->networkStream->getSyncEnd(); |
---|
| 224 | |
---|
| 225 | while ( it != e ) |
---|
| 226 | { |
---|
| 227 | if ( (*it)->getUniqueID() == uniqueID ) |
---|
| 228 | { |
---|
| 229 | (*it)->requestSync( userID ); |
---|
| 230 | break; |
---|
| 231 | } |
---|
| 232 | } |
---|
| 233 | } |
---|