Files
pvvmud/worldsrv/worldclimanager.C
2025-03-05 08:37:43 +01:00

171 lines
4.9 KiB
C

/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "pvvmud.H"
#include <iostream.h>
#include "worldclimanager.H"
static int currGOSCliManagerId = 0;
CWorldCliManager::CWorldCliManager(CWorldSrv * worldSrv, CWorldCliProtocol * protocol):CManager(protocol){
char name[16];
m_worldSrv = worldSrv;
m_id = ++currGOSCliManagerId;
m_quit = FALSE;
m_masterCell = NULL;
sprintf(name,"Client %i",m_id);
getProtocol()->setName(name);
setName(name);
}
CWorldCliManager::~CWorldCliManager(){
// Unregister all listeners in world
changeMasterCell(-1);
}
CWorldSrvObject * CWorldCliManager::getMasterCell(){
return m_masterCell;
}
///////////////////////////////////////////////////////////////////////////////
// Message in
///////////////////////////////////////////////////////////////////////////////
// changeMasterCell
// Arguments :
// newMasterCellId : New master cell or -1 to unregister all listeners
//
void CWorldCliManager::changeMasterCell(DWORD newMasterCellId){
CWorldSrvObject* newMasterCell = NULL;
// Find oldCells
cout << "Change MasterCell from : ";
if (m_masterCell != NULL) cout << m_masterCell->getObjectId();
else cout << "-1";
cout << " to " << newMasterCellId << "\nOld cells:";
CIntArray oldCells;
if (m_masterCell != NULL){
cout << " " << m_masterCell->getObjectId();
oldCells.add( m_masterCell->getObjectId() );
CCellPVS * pvs = m_masterCell->getPVS();
if (pvs != NULL){
CObjectListItem * item = pvs->getFirstPVCell();
while (item != NULL){
DWORD cellId = ((CPVCell*)item->getObject())->getCellId();
cout << " " << cellId;
oldCells.add( cellId );
item = item->getNext();
}
}
}
// Find newCells
cout << "\nNew cells:";
CIntArray newCells;
if (newMasterCellId != ID_UNKNOWN){
cout << " " << newMasterCellId;
newCells.add( newMasterCellId );
newMasterCell = (CWorldSrvObject*)getWorld()->getObject(newMasterCellId);
CCellPVS * pvs = newMasterCell->getPVS();
if (pvs != NULL){
CObjectListItem * item = pvs->getFirstPVCell();
while (item != NULL){
DWORD cellId = ((CPVCell*)item->getObject())->getCellId();
cout << " " << cellId;
newCells.add( cellId );
item = item->getNext();
}
}
}
cout << "\n";
CIntArray addCells = newCells.substracSet( oldCells );
CIntArray updateCells = oldCells.unionSet( newCells );
CIntArray deleteCells = oldCells.substracSet( newCells );
int num,ii;
CWorldSrvObject * cell;
cout << "Delete cells: ";
num = deleteCells.getNumElements();
for (ii = 0; ii < num; ii++) cout << " " << deleteCells.get(ii);
cout << "\nAdd cells: ";
num = addCells.getNumElements();
for (ii = 0; ii < num; ii++) cout << " " << addCells.get(ii);
cout << "\nUpdate cells: ";
num = updateCells.getNumElements();
for (ii = 0; ii < num; ii++) cout << " " << updateCells.get(ii);
cout << "\n";
m_masterCell = newMasterCell;
num = updateCells.getNumElements();
while (num-- > 0){
cell = (CWorldSrvObject*)getWorld()->getObject(updateCells.get(num));
if (cell != NULL) cell->updateListener(this);
}
num = addCells.getNumElements();
while (num-- > 0){
cell = (CWorldSrvObject*)getWorld()->getObject(addCells.get(num));
if (cell != NULL) cell->addListener(this);
}
num = deleteCells.getNumElements();
while (num-- > 0){
cell = (CWorldSrvObject*)getWorld()->getObject(deleteCells.get(num));
if (cell != NULL) cell->removeListener(this);
}
}
void CWorldCliManager::recivePing(BYTE sequenceNumber){
DWORD time = getWorld()->getTime();
cdebug << "Send pong: sequence number " << (int)sequenceNumber
<< " server time : " << time << endl;
getProtocol()->sendPong(sequenceNumber,time);
}
///////////////////////////////////////////////////////////////////////////////
// Message out
void CWorldCliManager::sendAnimation(CWorldAnimation * animation){
getProtocol()->sendAnimation(animation);
}
///////////////////////////////////////////////////////////////////////////////
// Utility functions
void CWorldCliManager::quit(){
cout << "Client marked quit\n";
m_quit = TRUE;
}
int CWorldCliManager::getQuit(){
return m_quit;
}