SyncClientHandlers.cpp   SyncClientHandlers.cpp 
skipping to change at line 27 skipping to change at line 27
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "SyncClientHandlers.hpp" #include "SyncClientHandlers.hpp"
#include "SyncClient.hpp" #include "SyncClient.hpp"
#include "SyncMessages.hpp" #include "SyncMessages.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "StelMovementMgr.hpp"
#include "StelObserver.hpp" #include "StelObserver.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelPropertyMgr.hpp"
using namespace SyncProtocol; using namespace SyncProtocol;
ClientHandler::ClientHandler() ClientHandler::ClientHandler()
: client(NULL) : client(Q_NULLPTR)
{ {
core = StelApp::getInstance().getCore(); core = StelApp::getInstance().getCore();
} }
ClientHandler::ClientHandler(SyncClient *client) ClientHandler::ClientHandler(SyncClient *client)
: client(client) : client(client)
{ {
Q_ASSERT(client); Q_ASSERT(client);
core = StelApp::getInstance().getCore(); core = StelApp::getInstance().getCore();
} }
ClientErrorHandler::ClientErrorHandler(SyncClient *client) ClientErrorHandler::ClientErrorHandler(SyncClient *client)
: ClientHandler(client) : ClientHandler(client)
{ {
} }
bool ClientErrorHandler::handleMessage(QDataStream &stream, SyncRemotePeer &peer) bool ClientErrorHandler::handleMessage(QDataStream &stream, SyncProtocol::t PayloadSize dataSize, SyncRemotePeer &peer)
{ {
ErrorMessage msg; ErrorMessage msg;
bool ok = msg.deserialize(stream,peer.msgHeader.dataSize); bool ok = msg.deserialize(stream,dataSize);
peer.peerLog("Received error message from server: " + msg.message); peer.peerLog("Received error message from server: " + msg.message);
client->emitError(msg.message); client->emitServerError(msg.message);
//we don't drop the connection here, we let the remote end do that //we don't drop the connection here, we let the remote end do that
return ok; return ok;
} }
ClientAuthHandler::ClientAuthHandler(SyncClient *client) ClientAuthHandler::ClientAuthHandler(SyncClient *client)
: ClientHandler(client) : ClientHandler(client)
{ {
connect(this, SIGNAL(authenticated()),client,SIGNAL(connected())); connect(this, SIGNAL(authenticated()),client,SIGNAL(connected()));
} }
bool ClientAuthHandler::handleMessage(QDataStream &stream, SyncRemotePeer & peer) bool ClientAuthHandler::handleMessage(QDataStream &stream, SyncProtocol::tP ayloadSize dataSize, SyncRemotePeer &peer)
{ {
//get message type //get message type
SyncMessageType type = SyncMessageType(peer.msgHeader.msgType); SyncMessageType type = SyncMessageType(peer.msgHeader.msgType);
if(type == SERVER_CHALLENGE) if(type == SERVER_CHALLENGE)
{ {
if(peer.isAuthenticated) if(peer.isAuthenticated())
{ {
//we are already authenticated, another challenge is an error //we are already authenticated, another challenge is an error
qWarning()<<"[SyncClient] received server challenge when not expecting one"; qWarning()<<"[SyncClient] received server challenge when not expecting one";
return false; return false;
} }
ServerChallenge msg; ServerChallenge msg;
bool ok = msg.deserialize(stream,peer.msgHeader.dataSize); bool ok = msg.deserialize(stream,dataSize);
if(!ok) if(!ok)
{ {
qWarning()<<"[SyncClient] invalid server challenge r eceived"; qWarning()<<"[SyncClient] invalid server challenge r eceived";
return false; return false;
} }
//check challenge for validity //check challenge for validity
if(msg.protocolVersion != SYNC_PROTOCOL_VERSION) if(msg.protocolVersion != SYNC_PROTOCOL_VERSION)
{ {
skipping to change at line 133 skipping to change at line 135
peer.writeMessage(response); peer.writeMessage(response);
return true; return true;
} }
else if (type == SERVER_CHALLENGERESPONSEVALID) else if (type == SERVER_CHALLENGERESPONSEVALID)
{ {
//this message has no data body, no need to deserialize //this message has no data body, no need to deserialize
if(peer.authResponseSent) if(peer.authResponseSent)
{ {
//we authenticated correctly, yay! //we authenticated correctly, yay!
peer.isAuthenticated = true; peer.authenticated = true;
qDebug()<<"[SyncClient] Connection authenticated"; qDebug()<<"[SyncClient] Connection authenticated";
emit authenticated(); emit authenticated();
return true; return true;
} }
else else
{ {
//we got a confirmation without sending a response, error //we got a confirmation without sending a response, error
qWarning()<<"[SyncClient] Got SERVER_CHALLENGERESPON SEVALID message without awaiting it"; qWarning()<<"[SyncClient] Got SERVER_CHALLENGERESPON SEVALID message without awaiting it";
return false; return false;
} }
} }
else else
{ {
//should never happen except the message type<-->handler con fig was somehow messed up //should never happen except the message type<-->handler con fig was somehow messed up
Q_ASSERT(false); Q_ASSERT(false);
return false; return false;
} }
} }
bool ClientAliveHandler::handleMessage(QDataStream &stream, SyncRemotePeer &peer) bool ClientAliveHandler::handleMessage(QDataStream &stream, SyncProtocol::t PayloadSize dataSize, SyncRemotePeer &peer)
{ {
Alive p; Alive p;
return p.deserialize(stream,peer.msgHeader.dataSize); return p.deserialize(stream,dataSize);
} }
bool ClientTimeHandler::handleMessage(QDataStream &stream, SyncRemotePeer & peer) bool ClientTimeHandler::handleMessage(QDataStream &stream, SyncProtocol::tP ayloadSize dataSize, SyncRemotePeer &peer)
{ {
Time msg; Time msg;
bool ok = msg.deserialize(stream,peer.msgHeader.dataSize); bool ok = msg.deserialize(stream, dataSize);
if(!ok) if(!ok)
return false; return false;
//set time variables, time rate first because it causes a resetSync which we overwrite //set time variables, time rate first because it causes a resetSync which we overwrite
core->setTimeRate(msg.timeRate); core->setTimeRate(msg.timeRate);
core->setJD(msg.jDay); core->setJD(msg.jDay);
//This is needed for compensation of network delay. Requires system clocks of client/server to be calibrated to the same values. //This is needed for compensation of network delay. Requires system clocks of client/server to be calibrated to the same values.
core->setMilliSecondsOfLastJDUpdate(msg.lastTimeSyncTime); core->setMilliSecondsOfLastJDUpdate(msg.lastTimeSyncTime);
return true; return true;
} }
bool ClientLocationHandler::handleMessage(QDataStream &stream, SyncRemotePe er &peer) bool ClientLocationHandler::handleMessage(QDataStream &stream, SyncProtocol ::tPayloadSize dataSize, SyncRemotePeer &peer)
{ {
Location msg; Location msg;
bool ok = msg.deserialize(stream,peer.msgHeader.dataSize); bool ok = msg.deserialize(stream,dataSize);
if(!ok) if(!ok)
return false; return false;
//replicated from StelCore::moveObserverTo //replicated from StelCore::moveObserverTo
//first, emit a locationChanged like StelCore does
emit core->locationChanged(msg.stelLocation);
if(msg.totalDuration>0.0) if(msg.totalDuration>0.0)
{ {
//for optimal results, the network latency should be subtrac ted from the timeToGo... //for optimal results, the network latency should be subtrac ted from the timeToGo...
StelLocation curLoc = core->getCurrentLocation(); StelLocation curLoc = core->getCurrentLocation();
if (core->getCurrentObserver()->isTraveling()) if (core->getCurrentObserver()->isTraveling())
{ {
// Avoid using a temporary location name to create a nother temporary one (otherwise it looks like loc1 -> loc2 -> loc3 etc..) // Avoid using a temporary location name to create a nother temporary one (otherwise it looks like loc1 -> loc2 -> loc3 etc..)
curLoc.name = "."; curLoc.name = ".";
} }
skipping to change at line 209 skipping to change at line 208
//create a spaceship observer //create a spaceship observer
SpaceShipObserver* newObs = new SpaceShipObserver(curLoc, ms g.stelLocation, msg.totalDuration,msg.timeToGo); SpaceShipObserver* newObs = new SpaceShipObserver(curLoc, ms g.stelLocation, msg.totalDuration,msg.timeToGo);
core->setObserver(newObs); core->setObserver(newObs);
newObs->update(0); newObs->update(0);
} }
else else
{ {
//create a normal observer //create a normal observer
core->setObserver(new StelObserver(msg.stelLocation)); core->setObserver(new StelObserver(msg.stelLocation));
} }
emit core->targetLocationChanged(msg.stelLocation);
emit core->locationChanged(core->getCurrentLocation());
return true; return true;
} }
ClientSelectionHandler::ClientSelectionHandler() ClientSelectionHandler::ClientSelectionHandler()
{ {
objMgr = &StelApp::getInstance().getStelObjectMgr(); objMgr = &StelApp::getInstance().getStelObjectMgr();
} }
bool ClientSelectionHandler::handleMessage(QDataStream &stream, SyncRemoteP eer &peer) bool ClientSelectionHandler::handleMessage(QDataStream &stream, SyncProtoco l::tPayloadSize dataSize, SyncRemotePeer &peer)
{ {
Selection msg; Selection msg;
bool ok = msg.deserialize(stream, peer.msgHeader.dataSize); bool ok = msg.deserialize(stream, dataSize);
if(!ok) if(!ok)
return false; return false;
qDebug()<<msg;
//lookup the objects from their names //lookup the objects from their names
//this might cause problems if 2 objects of different types have the same name! //this might cause problems if 2 objects of different types have the same name!
QList<StelObjectP> selection; QList<StelObjectP> selection;
for(QList<QString>::iterator it = msg.selectedObjectNames.begin(); i t!=msg.selectedObjectNames.end();++it) for(QList< QPair<QString,QString> >::iterator it = msg.selectedObjec ts.begin(); it!=msg.selectedObjects.end();++it)
{ {
StelObjectP obj = objMgr->searchByName(*it); StelObjectP obj = objMgr->searchByID(it->first, it->second);
if(!obj.isNull()) if(obj)
selection.append(obj); selection.append(obj);
else
qWarning()<<"Object not found"<<it->first<<it->secon
d;
}
if(selection.isEmpty())
objMgr->unSelect();
else
{
//set selection
objMgr->setSelectedObject(selection,StelModule::ReplaceSelec
tion);
}
return true;
}
ClientStelPropertyUpdateHandler::ClientStelPropertyUpdateHandler(bool skipG
uiProps, const QStringList &excludeProps)
{
propMgr = StelApp::getInstance().getStelPropertyManager();
QString pattern("^(");
//construct a regular expression for the excludes
bool first = true;
foreach(QString str, excludeProps)
{
QString tmp = QRegularExpression::escape(str);
// replace escaped asterisks with the regex "all"
tmp.replace("\\*",".*");
if(!first)
{
pattern += '|';
}
first = false;
pattern += tmp;
}
if(skipGuiProps)
{
if(!first)
{
pattern += '|';
}
first = false;
//this is an attempt to filter out the GUI related propertie
s
pattern += "(actionShow_.*(Window_Global|_dialog))"; //most
dialogs follow one of these patterns
pattern += "|actionShow_Scenery3d_storedViewDialog"; //add o
ther dialogs here
}
//finish the pattern
pattern += ")$";
filter.setPattern(pattern);
if(!filter.isValid())
qWarning()<<"Invalid StelProperty filter:"<<filter.errorStri
ng();
else
qDebug()<<"Constructed regex"<<filter;
filter.optimize();
}
bool ClientStelPropertyUpdateHandler::handleMessage(QDataStream &stream, Sy
ncProtocol::tPayloadSize dataSize, SyncRemotePeer &peer)
{
StelPropertyUpdate msg;
bool ok = msg.deserialize(stream, dataSize);
if(!ok)
return false;
qDebug()<<msg;
QRegularExpressionMatch match = filter.match(msg.propId);
if(match.hasMatch())
{
//filtered property
qDebug()<<"Filtered"<<msg;
return true;
} }
propMgr->setStelPropertyValue(msg.propId,msg.value);
return true;
}
ClientViewHandler::ClientViewHandler()
{
mvMgr = core->getMovementMgr();
}
//set selection bool ClientViewHandler::handleMessage(QDataStream &stream, SyncProtocol::tP
objMgr->setSelectedObject(selection,StelModule::ReplaceSelection); ayloadSize dataSize, SyncRemotePeer &peer)
{
View msg;
bool ok = msg.deserialize(stream, dataSize);
if(!ok) return false;
mvMgr->setViewDirectionJ2000(core->altAzToJ2000(msg.viewAltAz, StelC
ore::RefractionOff));
return true;
}
ClientFovHandler::ClientFovHandler()
{
mvMgr = core->getMovementMgr();
}
bool ClientFovHandler::handleMessage(QDataStream &stream, SyncProtocol::tPa
yloadSize dataSize, SyncRemotePeer &peer)
{
Fov msg;
bool ok = msg.deserialize(stream, dataSize);
if(!ok) return false;
mvMgr->zoomTo(msg.fov, 0.0f);
return true; return true;
} }
 End of changes. 27 change blocks. 
24 lines changed or deleted 141 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/