#include <msp/core/refptr.h>
#include <msp/net/inet.h>
#include <msp/net/resolve.h>
+#include "libr2c2/aicontrol.h"
#include "libr2c2/catalogue.h"
#include "libr2c2/driver.h"
#include "libr2c2/route.h"
send(pkt);
}
-void Server::train_ai_event(const Train &train, TrainAI &, const TrainAI::Message &ev)
+void Server::train_ai_event(const Train &train, TrainAI &ai, const TrainAI::Message &ev)
{
if(ev.type=="route-changed")
{
pkt.status = ev.value.value<std::string>();
send(pkt);
}
+ else if(ev.type=="target-speed-changed" || ev.type=="reverse-changed")
+ {
+ AIControl *control = dynamic_cast<AIControl *>(&ai);
+ if(control)
+ {
+ TrainAIControlPacket pkt;
+ pkt.address = train.get_address();
+ pkt.target_speed = control->get_target_speed();
+ pkt.reverse = control->get_reverse();
+ send(pkt);
+ }
+ }
}
template<typename P>
Server::Connection::Connection(Server &s, Net::StreamSocket *o):
server(s),
socket(o),
- comm(*socket, server.proto, *this)
+ comm(*socket, server.proto, *this),
+ stale(false)
{
socket->signal_end_of_file.connect(sigc::mem_fun(this, &Connection::end_of_file));
comm.signal_handshake_done.connect(sigc::mem_fun(this, &Connection::handshake_done));
pkt.name = train.get_name();
comm.send(pkt);
}
+ if(AIControl *control = train.get_ai_of_type<AIControl>())
+ {
+ TrainAIControlPacket pkt;
+ pkt.address = train.get_address();
+ pkt.target_speed = control->get_target_speed();
+ pkt.reverse = control->get_reverse();
+ comm.send(pkt);
+ }
for(unsigned j=0;; ++j)
{
const char *name = train.get_controller().enumerate_controls(j);
}
}
+void Server::Connection::receive(const TrainAIControlPacket &pkt)
+{
+ try
+ {
+ Train &train = server.layout.get_train(pkt.address);
+ train.ai_message(TrainAI::Message("set-target-speed", pkt.target_speed));
+ train.ai_message(TrainAI::Message("set-reverse", static_cast<bool>(pkt.reverse)));
+ }
+ catch(const exception &e)
+ {
+ error(e.what());
+ }
+}
+
void Server::Connection::receive(const TrainRoutePacket &pkt)
{
try