aboutsummaryrefslogtreecommitdiff
path: root/src/demoserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/demoserver.cpp')
-rw-r--r--src/demoserver.cpp60
1 files changed, 48 insertions, 12 deletions
diff --git a/src/demoserver.cpp b/src/demoserver.cpp
index 800d282e..c4f8c158 100644
--- a/src/demoserver.cpp
+++ b/src/demoserver.cpp
@@ -233,9 +233,39 @@ void DemoServer::handle_packet(AOPacket packet)
QString packet = "CT#DEMO#" + tr("min_wait is deprecated. Use the client Settings for minimum wait instead!") + "#1#%";
client_sock->write(packet.toUtf8());
}
+ else if (contents[1].startsWith("/debug"))
+ {
+ QStringList args = contents[1].split(" ");
+ if (args.size() > 1)
+ {
+ bool ok;
+ int toggle = args.at(1).toInt(&ok);
+ if (ok && (toggle == 0 || toggle == 1)) {
+ debug_mode = toggle == 1;
+ QString packet = "CT#DEMO#" + tr("Setting debug mode to %1").arg(static_cast<int>(debug_mode)) + "#1#%";
+ client_sock->write(packet.toUtf8());
+ // Debug mode disabled?
+ if (!debug_mode) {
+ // Reset the timer
+ client_sock->write("TI#4#1#0#%");
+ client_sock->write("TI#4#3#0#%");
+ }
+ }
+ else
+ {
+ QString packet = "CT#DEMO#" + tr("Valid values are 1 or 0!") + "#1#%";
+ client_sock->write(packet.toUtf8());
+ }
+ }
+ else
+ {
+ QString packet = "CT#DEMO#" + tr("Set debug mode using /debug 1 to enable, and /debug 0 to disable, which will use the fifth timer (TI#4) to show the remaining time until next demo line.") + "#1#%";
+ client_sock->write(packet.toUtf8());
+ }
+ }
else if (contents[1].startsWith("/help"))
{
- QString packet = "CT#DEMO#" + tr("Available commands:\nload, reload, play, pause, max_wait, help") + "#1#%";
+ QString packet = "CT#DEMO#" + tr("Available commands:\nload, reload, play, pause, max_wait, debug, help") + "#1#%";
client_sock->write(packet.toUtf8());
}
}
@@ -321,8 +351,8 @@ void DemoServer::reset_state()
client_sock->write("LE##%");
// Reset timers
- client_sock->write("TI#0#3#0#%");
client_sock->write("TI#0#1#0#%");
+ client_sock->write("TI#0#3#0#%");
client_sock->write("TI#1#1#0#%");
client_sock->write("TI#1#3#0#%");
client_sock->write("TI#2#1#0#%");
@@ -359,19 +389,25 @@ void DemoServer::playback()
AOPacket wait_packet = AOPacket(current_packet);
int duration = wait_packet.get_contents().at(0).toInt();
- if (max_wait != -1) {
- if (duration + elapsed_time > max_wait) {
- duration = qMax(0, max_wait - elapsed_time);
- // Skip the difference on the timers
- emit skip_timers(wait_packet.get_contents().at(0).toInt() - duration);
- }
- else if (timer->interval() != 0 && duration + elapsed_time > timer->interval()) {
- duration = qMax(0, timer->interval() - elapsed_time);
- emit skip_timers(wait_packet.get_contents().at(0).toInt() - duration);
- }
+ // Max wait reached
+ if (max_wait != -1 && duration + elapsed_time > max_wait) {
+ duration = qMax(0, max_wait - elapsed_time);
+ qDebug() << "Max_wait of " << max_wait << " reached. Forcing duration to " << duration << "ms";
+ // Skip the difference on the timers
+ emit skip_timers(wait_packet.get_contents().at(0).toInt() - duration);
+ }
+ // Manual user skip, such as with >
+ else if (timer->remainingTime() > 0) {
+ qDebug() << "Timer of interval " << timer->interval() << " is being skipped. Forcing to skip " << timer->remainingTime() << "ms on TI# clocks";
+ emit skip_timers(timer->remainingTime());
}
elapsed_time += duration;
timer->start(duration);
+ if (debug_mode) {
+ client_sock->write("TI#4#2#%");
+ QString debug_timer = "TI#4#0#" + QString::number(duration) + "#%";
+ client_sock->write(debug_timer.toUtf8());
+ }
}
else {
QString end_packet = "CT#DEMO#" + tr("Reached the end of the demo file. Send /play or > in OOC to restart, or /load to open a new file.") + "#1#%";