Skip to content

Commit bea9fc1

Browse files
authored
Merge pull request #526 from AttorneyOnline/crystalwarrior/demo-reload
Add a /reload command that quickly reloads the current demo
2 parents 75da07d + 60daac3 commit bea9fc1

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

include/demoserver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class DemoServer : public QObject
2525
private:
2626
void handle_packet(AOPacket packet);
2727
void load_demo(QString filename);
28+
void reset_state();
2829

2930
QTcpServer* tcp_server;
3031
QTcpSocket* client_sock = nullptr;

src/demoserver.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ void DemoServer::handle_packet(AOPacket packet)
162162
load_demo(path);
163163
QString packet = "CT#DEMO#" + tr("Demo file loaded. Send /play or > in OOC to begin playback.") + "#1#%";
164164
client_sock->write(packet.toUtf8());
165+
reset_state();
165166
}
166167
else if (contents[1].startsWith("/play") || contents[1] == ">")
167168
{
@@ -220,14 +221,21 @@ void DemoServer::handle_packet(AOPacket packet)
220221
client_sock->write(packet.toUtf8());
221222
}
222223
}
224+
else if (contents[1].startsWith("/reload"))
225+
{
226+
load_demo(p_path);
227+
QString packet = "CT#DEMO#" + tr("Current demo file reloaded. Send /play or > in OOC to begin playback.") + "#1#%";
228+
client_sock->write(packet.toUtf8());
229+
reset_state();
230+
}
223231
else if (contents[1].startsWith("/min_wait"))
224232
{
225233
QString packet = "CT#DEMO#" + tr("min_wait is deprecated. Use the client Settings for minimum wait instead!") + "#1#%";
226234
client_sock->write(packet.toUtf8());
227235
}
228236
else if (contents[1].startsWith("/help"))
229237
{
230-
QString packet = "CT#DEMO#" + tr("Available commands:\nload, play, pause, max_wait, help") + "#1#%";
238+
QString packet = "CT#DEMO#" + tr("Available commands:\nload, reload, play, pause, max_wait, help") + "#1#%";
231239
client_sock->write(packet.toUtf8());
232240
}
233241
}
@@ -239,8 +247,11 @@ void DemoServer::load_demo(QString filename)
239247
demo_file.open(QIODevice::ReadOnly);
240248
if (!demo_file.isOpen())
241249
return;
250+
// Clear demo data
242251
demo_data.clear();
252+
// Set the demo filepath
243253
p_path = filename;
254+
// Process the demo file
244255
QTextStream demo_stream(&demo_file);
245256
demo_stream.setCodec("UTF-8");
246257
QString line = demo_stream.readLine();
@@ -304,6 +315,30 @@ void DemoServer::load_demo(QString filename)
304315
}
305316
}
306317

318+
void DemoServer::reset_state()
319+
{
320+
// Reset evidence list
321+
client_sock->write("LE##%");
322+
323+
// Reset timers
324+
client_sock->write("TI#0#3#0#%");
325+
client_sock->write("TI#0#1#0#%");
326+
client_sock->write("TI#1#1#0#%");
327+
client_sock->write("TI#1#3#0#%");
328+
client_sock->write("TI#2#1#0#%");
329+
client_sock->write("TI#2#3#0#%");
330+
client_sock->write("TI#3#1#0#%");
331+
client_sock->write("TI#3#3#0#%");
332+
client_sock->write("TI#4#1#0#%");
333+
client_sock->write("TI#4#3#0#%");
334+
335+
// Set the BG to default (also breaks up the message queue)
336+
client_sock->write("BN#default#wit#%");
337+
338+
// Stop the wait packet timer
339+
timer->stop();
340+
}
341+
307342
void DemoServer::playback()
308343
{
309344
if (demo_data.isEmpty())

0 commit comments

Comments
 (0)