00001 //----------------------------------------------------------------------------------- 00002 // 00003 // Pro-Vocation Light Engine (PVLE) 00004 // Copyright (C) 2007-2009 Sukender, KinoX & Buzib 00005 // For more information, contact us : sukender@free.fr 00006 // 00007 // This program is free software; you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation; either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // For any use that is not compatible with the terms of the GNU 00013 // General Public License, please contact the authors for alternative 00014 // licensing options. 00015 // 00016 // This program is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU General Public License along 00022 // with this program; if not, write to the Free Software Foundation, Inc., 00023 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00024 // 00025 //----------------------------------------------------------------------------------- 00026 00027 #include <PVLE/Config.h> 00028 00029 #ifdef PVLE_NETWORKING 00030 00031 #include <PVLE/Network/PVLEGhostConnection.h> 00032 #include <PVLE/Game/PVLEPlayer.h> 00033 #include <PVLE/Game/PVLETeam.h> 00034 #include <boost/cast.hpp> 00035 00036 //TNL_IMPLEMENT_NETCONNECTION(PVLEGhostConnection, TNL::NetClassGroupGame, true); 00037 00038 TNL_IMPLEMENT_RPC(PVLEGhostConnection, rpcPlayerGhostInit, 00039 (TNL::S32 playerGhostId), (playerGhostId), 00040 TNL::NetClassGroupGameMask, TNL::RPCGuaranteed, TNL::RPCDirServerToClient, 0) 00041 { 00042 // Receiving Player ghost ID... 00043 ASSERT(pPlayerGhost == NULL); 00044 pPlayerGhost = boost::polymorphic_downcast<PVLEPlayer *>(resolveGhost(playerGhostId)); 00045 ASSERT(pPlayerGhost); 00046 } 00047 00048 00049 void PVLEGhostConnection::receiveControlEvent(const ControlEvent & ce) { 00050 ASSERT(pPlayerGhostParent); 00051 pPlayerGhostParent->getControlMapper().onControlEventReceived(ce); 00052 } 00053 00054 00055 void PVLEGhostConnection::onConnectionTerminated(TerminationReason reason, const char *edString) { 00056 TNL::GhostConnection::onConnectionTerminated(reason, edString); // Does nothing, but that's cleaner that way :) 00057 00058 resetGhosting(); 00059 00060 if (isConnectionToServer()) { 00061 // Client 00062 pPlayerGhost = NULL; // If created, the ghost has been / will be deleted by an RPC from server after the call to resetGhosting(). 00063 } else { 00064 // Server 00065 00066 // Remove (delete) the player from his/her team 00067 if (pPlayerGhostParent && pPlayerGhostParent->getTeam()) pPlayerGhostParent->getTeam()->removePlayer(pPlayerGhostParent); 00068 pPlayerGhostParent = NULL; 00069 } 00070 } 00071 00072 #endif // PVLE_NETWORKING