Merge pull request #526 from AttorneyOnline/crystalwarrior/demo-reload
Add a /reload command that quickly reloads the current demo
This commit is contained in:
commit
bea9fc1a05
@ -25,6 +25,7 @@ public:
|
||||
private:
|
||||
void handle_packet(AOPacket packet);
|
||||
void load_demo(QString filename);
|
||||
void reset_state();
|
||||
|
||||
QTcpServer* tcp_server;
|
||||
QTcpSocket* client_sock = nullptr;
|
||||
|
@ -162,6 +162,7 @@ void DemoServer::handle_packet(AOPacket packet)
|
||||
load_demo(path);
|
||||
QString packet = "CT#DEMO#" + tr("Demo file loaded. Send /play or > in OOC to begin playback.") + "#1#%";
|
||||
client_sock->write(packet.toUtf8());
|
||||
reset_state();
|
||||
}
|
||||
else if (contents[1].startsWith("/play") || contents[1] == ">")
|
||||
{
|
||||
@ -220,6 +221,13 @@ void DemoServer::handle_packet(AOPacket packet)
|
||||
client_sock->write(packet.toUtf8());
|
||||
}
|
||||
}
|
||||
else if (contents[1].startsWith("/reload"))
|
||||
{
|
||||
load_demo(p_path);
|
||||
QString packet = "CT#DEMO#" + tr("Current demo file reloaded. Send /play or > in OOC to begin playback.") + "#1#%";
|
||||
client_sock->write(packet.toUtf8());
|
||||
reset_state();
|
||||
}
|
||||
else if (contents[1].startsWith("/min_wait"))
|
||||
{
|
||||
QString packet = "CT#DEMO#" + tr("min_wait is deprecated. Use the client Settings for minimum wait instead!") + "#1#%";
|
||||
@ -227,7 +235,7 @@ void DemoServer::handle_packet(AOPacket packet)
|
||||
}
|
||||
else if (contents[1].startsWith("/help"))
|
||||
{
|
||||
QString packet = "CT#DEMO#" + tr("Available commands:\nload, play, pause, max_wait, help") + "#1#%";
|
||||
QString packet = "CT#DEMO#" + tr("Available commands:\nload, reload, play, pause, max_wait, help") + "#1#%";
|
||||
client_sock->write(packet.toUtf8());
|
||||
}
|
||||
}
|
||||
@ -239,8 +247,11 @@ void DemoServer::load_demo(QString filename)
|
||||
demo_file.open(QIODevice::ReadOnly);
|
||||
if (!demo_file.isOpen())
|
||||
return;
|
||||
// Clear demo data
|
||||
demo_data.clear();
|
||||
// Set the demo filepath
|
||||
p_path = filename;
|
||||
// Process the demo file
|
||||
QTextStream demo_stream(&demo_file);
|
||||
demo_stream.setCodec("UTF-8");
|
||||
QString line = demo_stream.readLine();
|
||||
@ -304,6 +315,30 @@ void DemoServer::load_demo(QString filename)
|
||||
}
|
||||
}
|
||||
|
||||
void DemoServer::reset_state()
|
||||
{
|
||||
// Reset evidence list
|
||||
client_sock->write("LE##%");
|
||||
|
||||
// Reset timers
|
||||
client_sock->write("TI#0#3#0#%");
|
||||
client_sock->write("TI#0#1#0#%");
|
||||
client_sock->write("TI#1#1#0#%");
|
||||
client_sock->write("TI#1#3#0#%");
|
||||
client_sock->write("TI#2#1#0#%");
|
||||
client_sock->write("TI#2#3#0#%");
|
||||
client_sock->write("TI#3#1#0#%");
|
||||
client_sock->write("TI#3#3#0#%");
|
||||
client_sock->write("TI#4#1#0#%");
|
||||
client_sock->write("TI#4#3#0#%");
|
||||
|
||||
// Set the BG to default (also breaks up the message queue)
|
||||
client_sock->write("BN#default#wit#%");
|
||||
|
||||
// Stop the wait packet timer
|
||||
timer->stop();
|
||||
}
|
||||
|
||||
void DemoServer::playback()
|
||||
{
|
||||
if (demo_data.isEmpty())
|
||||
|
Loading…
Reference in New Issue
Block a user