]> git.tdb.fi Git - r2c2.git/blobdiff - source/network/server.cpp
Set speed slider range from the advertised top speed of the train
[r2c2.git] / source / network / server.cpp
index 73cee24a4f0c2f5d7676b98a507be2f25dcce6fd..aced6f7202f2e6dc894af1ec686fb4fb51a1c72f 100644 (file)
@@ -34,6 +34,9 @@ Server::Server(Layout &l):
        listen_sock.signal_data_available.connect(sigc::mem_fun(this, &Server::incoming_connection));
 }
 
+Server::~Server()
+{ }
+
 void Server::use_event_dispatcher(IO::EventDispatcher &ed)
 {
        event_disp = &ed;
@@ -56,7 +59,7 @@ void Server::driver_state_changed()
        send(pkt);
 }
 
-void Server::emergency(const string &msg)
+void Server::emergency(Block *, const string &msg)
 {
        EmergencyPacket pkt;
        pkt.message = msg;
@@ -75,9 +78,8 @@ void Server::train_added(Train &train)
        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)));
+       if(!train.get_ai_of_type<TrainStatus>())
+               new TrainStatus(train);
 }
 
 void Server::train_control_changed(const Train &train, const string &control, float value)
@@ -107,14 +109,13 @@ void Server::train_ai_event(const Train &train, TrainAI &, const TrainAI::Messag
                        pkt.route = route->get_name();
                send(pkt);
        }
-}
-
-void Server::train_status_changed(const Train &train, const string &status)
-{
-       TrainStatusPacket pkt;
-       pkt.address = train.get_address();
-       pkt.status = status;
-       send(pkt);
+       else if(ev.type=="status-changed")
+       {
+               TrainStatusPacket pkt;
+               pkt.address = train.get_address();
+               pkt.status = ev.value.value<std::string>();
+               send(pkt);
+       }
 }
 
 template<typename P>
@@ -159,7 +160,7 @@ void Server::Connection::handshake_done()
                comm.send(pkt);
        }
 
-       const set<Route *> &routes = server.layout.get_routes();
+       const set<Route *> &routes = server.layout.get_all<Route>();
        for(set<Route *>::const_iterator i=routes.begin(); i!=routes.end(); ++i)
                if(!(*i)->is_temporary())
                {
@@ -198,14 +199,14 @@ 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")))
+               if(TrainStatus *status = train.get_ai_of_type<TrainStatus>())
                {
                        TrainStatusPacket pkt;
                        pkt.address = train.get_address();
                        pkt.status = status->get_status();
                        comm.send(pkt);
                }
-               if(TrainRouter *router = dynamic_cast<TrainRouter *>(train.get_tagged_ai("router")))
+               if(TrainRouter *router = train.get_ai_of_type<TrainRouter>())
                {
                        TrainRoutePacket pkt;
                        pkt.address = train.get_address();