- Locomotive &loco = server.trfc_mgr.get_control().get_locomotive(pkt.address);
- for(unsigned i=0; i<9; ++i)
- if(((pkt.functions^loco.get_functions())>>i)&1)
- loco.set_function(i, (pkt.functions>>i)&1);
+ try
+ {
+ Locomotive &loco = server.trfc_mgr.get_control().get_locomotive(pkt.address);
+ for(unsigned i=0; i<9; ++i)
+ if(((pkt.functions^loco.get_functions())>>i)&1)
+ loco.set_function(i, (pkt.functions>>i)&1);
+ }
+ catch(const Exception &e)
+ {
+ error(e.what());
+ }
+}
+
+void Server::Connection::receive(const TrainRoutePacket &pkt)
+{
+ try
+ {
+ Locomotive &loco = server.trfc_mgr.get_control().get_locomotive(pkt.address);
+ Train &train = server.trfc_mgr.get_train_by_locomotive(loco);
+ if(pkt.route.empty())
+ train.set_route(0);
+ else
+ {
+ Route &route = server.trfc_mgr.get_layout().get_route(pkt.route);
+ train.set_route(&route);
+ }
+ }
+ catch(const Exception &e)
+ {
+ error(e.what());
+ }
+}
+
+void Server::Connection::error(const string &msg)
+{
+ ErrorPacket pkt;
+ pkt.message = msg;
+ comm.send(pkt);