113 lines
2.9 KiB
C
113 lines
2.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 <iostream>
|
|
#include "pvvmud.H"
|
|
#include "worldsrvmanager.H"
|
|
#include "msgserver.H"
|
|
#include "msgsrvcli.H"
|
|
|
|
|
|
CWorldSrvManager::CWorldSrvManager(CWorldSrv * worldSrv, CWorldSrvProtocol * protocol):CManager(protocol){
|
|
m_worldSrv = worldSrv;
|
|
m_quit = FALSE;
|
|
getProtocol()->setName("Server");
|
|
|
|
m_pingPong = new CPingPong(MAXPINGPONG);
|
|
m_pingCounter = 0;
|
|
m_pingCounterMax = 0;
|
|
|
|
}
|
|
|
|
CWorldSrvManager::~CWorldSrvManager(){
|
|
delete m_pingPong;
|
|
}
|
|
|
|
CWorldSrv * CWorldSrvManager::getWorldSrv(){
|
|
return m_worldSrv;
|
|
}
|
|
|
|
CWorldSrvWorld * CWorldSrvManager::getWorld(){
|
|
return m_worldSrv->getWorld();
|
|
}
|
|
|
|
CWorldSrvProtocol * CWorldSrvManager::getProtocol(){
|
|
return (CWorldSrvProtocol*)getCommunicate();
|
|
}
|
|
|
|
void CWorldSrvManager::quit(){
|
|
cout << "Server marked quit\n";
|
|
m_quit = TRUE;
|
|
}
|
|
|
|
int CWorldSrvManager::getQuit(){
|
|
return m_quit;
|
|
}
|
|
|
|
void CWorldSrvManager::hello(){
|
|
cout << "Hello from server\n";
|
|
CWorldSrvProtocol * protocol = getProtocol();
|
|
protocol->sendMessage(new CMsgServerLogin( m_worldSrv->getAddress() ),TRUE);
|
|
|
|
sendPing();
|
|
}
|
|
|
|
void CWorldSrvManager::GOSInfo(CInetAddress & gosAddress){
|
|
cout << "GOS address from server\n";
|
|
m_worldSrv->setGOS(gosAddress);
|
|
}
|
|
|
|
void CWorldSrvManager::sendPing(){
|
|
|
|
m_pingCounter++;
|
|
|
|
if (m_pingCounter > m_pingCounterMax){
|
|
if (m_pingCounterMax < MAXPINGPONG)
|
|
m_pingCounterMax = m_pingCounter;
|
|
m_pingCounter = 0;
|
|
|
|
DWORD sendTime = getWorld()->getTime();
|
|
|
|
BYTE sequenceNumber = m_pingPong->sendPing(sendTime);
|
|
|
|
cout << "PING: " << (int)sequenceNumber
|
|
<< " time " << sendTime << endl;
|
|
|
|
CWorldSrvProtocol * protocol = getProtocol();
|
|
protocol->sendMessage(new CMsgPing( sequenceNumber ),TRUE);
|
|
}
|
|
|
|
}
|
|
|
|
void CWorldSrvManager::pong(BYTE sequenceNumber, DWORD serverTime){
|
|
DWORD reciveTime = getWorld()->getTime();
|
|
|
|
long timediff = m_pingPong->recivePong(reciveTime,sequenceNumber,serverTime);
|
|
|
|
cout << "PONG: sequence number " << (int)sequenceNumber
|
|
<< " serverTime " << serverTime
|
|
<< " recive time " << reciveTime
|
|
<< " time diff " << timediff << endl;
|
|
|
|
cout << "Ping info " << *m_pingPong << endl;
|
|
|
|
getWorld()->fixTime(timediff);
|
|
|
|
}
|