X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=inline;f=source%2Fnetwork%2Fserver.cpp;h=c0a69463622d17d5f8b65fb55fd886692994ee36;hb=621c5c938d70ba0d155e0eda91a708db0a52c0dc;hp=b3f4662a05079814bb618062245e0a6215ed8b70;hpb=e8d06e16ab1679eb87e21cbfa788eea02144927d;p=r2c2.git diff --git a/source/network/server.cpp b/source/network/server.cpp index b3f4662..c0a6946 100644 --- a/source/network/server.cpp +++ b/source/network/server.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of R²C² -Copyright © 2009-2011 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - #include #include "libr2c2/driver.h" #include "libr2c2/route.h" @@ -77,6 +70,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) @@ -194,10 +191,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()) @@ -232,7 +230,7 @@ void Server::Connection::receive(const TrainControlPacket &pkt) Train &train = server.layout.get_train(pkt.address); train.set_control(pkt.control, pkt.value); } - catch(const Exception &e) + catch(const exception &e) { error(e.what()); } @@ -247,7 +245,7 @@ void Server::Connection::receive(const TrainFunctionPacket &pkt) if(((pkt.functions^train.get_functions())>>i)&1) train.set_function(i, (pkt.functions>>i)&1); } - catch(const Exception &e) + catch(const exception &e) { error(e.what()); } @@ -266,7 +264,7 @@ void Server::Connection::receive(const TrainRoutePacket &pkt) train.set_route(&route); } } - catch(const Exception &e) + catch(const exception &e) { error(e.what()); }