X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fnetwork%2Fserver.cpp;h=df40b3f11ea23d03bf9ca1cb2bb3cdb36b36d6f5;hb=2d44923e135a119fde31a7a50e5fcd3e400e4f41;hp=43d22ffef9016f26b376e691d840840bea13a940;hpb=fadc35133b1ebbd98af948c1fa529dcde6fddcfd;p=r2c2.git diff --git a/source/network/server.cpp b/source/network/server.cpp index 43d22ff..df40b3f 100644 --- a/source/network/server.cpp +++ b/source/network/server.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of R²C² -Copyright © 2009-2010 Mikkosoft Productions, Mikko Rasa +Copyright © 2009-2011 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ @@ -77,6 +77,10 @@ void Server::train_added(Train &train) pkt.loco_type = train.get_locomotive_type().get_article_number().str(); pkt.name = train.get_name(); send(pkt); + + TrainStatus *status = new TrainStatus(train); + status->set_tag("server:status"); + status->signal_changed.connect(sigc::bind<0>(sigc::mem_fun(this, &Server::train_status_changed), sigc::ref(train))); } void Server::train_control_changed(const Train &train, const string &control, float value) @@ -117,8 +121,17 @@ template void Server::send(const P &pkt) { for(vector::const_iterator i=connections.begin(); i!=connections.end(); ++i) - if(!(*i)->stale) - (*i)->comm.send(pkt); + if(!(*i)->stale && (*i)->comm.is_handshake_done()) + { + try + { + (*i)->comm.send(pkt); + } + catch(...) + { + (*i)->stale = true; + } + } } @@ -185,10 +198,11 @@ void Server::Connection::handshake_done() pkt.functions = train.get_functions(); comm.send(pkt); } + if(TrainStatus *status = dynamic_cast(train.get_tagged_ai("server:status"))) { TrainStatusPacket pkt; pkt.address = train.get_address(); - pkt.status = train.get_status(); + pkt.status = status->get_status(); comm.send(pkt); } if(train.get_route())