]> git.tdb.fi Git - r2c2.git/blobdiff - source/network/server.cpp
Fix remaining exception class names
[r2c2.git] / source / network / server.cpp
index b3f4662a05079814bb618062245e0a6215ed8b70..c0a69463622d17d5f8b65fb55fd886692994ee36 100644 (file)
@@ -1,10 +1,3 @@
-/* $Id$
-
-This file is part of R²C²
-Copyright © 2009-2011  Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
 #include <msp/net/inet.h>
 #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<TrainStatus *>(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());
        }