|
@@ -223,7 +223,8 @@ void Door::time_thread_run(std::future<void> future) {
|
|
// log("TICK");
|
|
// log("TICK");
|
|
// logf << "TICK " << seconds_elapsed << std::endl;
|
|
// logf << "TICK " << seconds_elapsed << std::endl;
|
|
if (seconds_elapsed % 60 == 0) {
|
|
if (seconds_elapsed % 60 == 0) {
|
|
- time_left--;
|
|
|
|
|
|
+ if (time_left > 0)
|
|
|
|
+ time_left--;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -407,6 +408,9 @@ bool Door::haskey(void) {
|
|
if (hangup)
|
|
if (hangup)
|
|
return -2;
|
|
return -2;
|
|
|
|
|
|
|
|
+ if (time_left < 2)
|
|
|
|
+ return -3;
|
|
|
|
+
|
|
while (select_ret == -1) {
|
|
while (select_ret == -1) {
|
|
FD_ZERO(&socket_set);
|
|
FD_ZERO(&socket_set);
|
|
FD_SET(STDIN_FILENO, &socket_set);
|
|
FD_SET(STDIN_FILENO, &socket_set);
|
|
@@ -670,6 +674,9 @@ signed int Door::sleep_key(int secs) {
|
|
if (hangup)
|
|
if (hangup)
|
|
return -2;
|
|
return -2;
|
|
|
|
|
|
|
|
+ if (time_left < 2)
|
|
|
|
+ return -3;
|
|
|
|
+
|
|
while (select_ret == -1) {
|
|
while (select_ret == -1) {
|
|
FD_ZERO(&socket_set);
|
|
FD_ZERO(&socket_set);
|
|
FD_SET(STDIN_FILENO, &socket_set);
|
|
FD_SET(STDIN_FILENO, &socket_set);
|
|
@@ -692,6 +699,49 @@ signed int Door::sleep_key(int secs) {
|
|
return getkey();
|
|
return getkey();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+std::string Door::input_string(int max) {
|
|
|
|
+ std::string input;
|
|
|
|
+
|
|
|
|
+ // draw the input area.
|
|
|
|
+ *this << std::string(max, ' ');
|
|
|
|
+ *this << std::string(max, '\x08');
|
|
|
|
+
|
|
|
|
+ int c;
|
|
|
|
+
|
|
|
|
+ while (true) {
|
|
|
|
+ c = sleep_key(inactivity);
|
|
|
|
+ if (c < 0) {
|
|
|
|
+ input.clear();
|
|
|
|
+ return input;
|
|
|
|
+ }
|
|
|
|
+ if (c > 0x1000)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ if (isprint(c)) {
|
|
|
|
+ if (int(input.length()) < max) {
|
|
|
|
+ *this << char(c);
|
|
|
|
+ input.append(1, c);
|
|
|
|
+ } else {
|
|
|
|
+ // bell
|
|
|
|
+ *this << '\x07';
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ switch (c) {
|
|
|
|
+ case 0x08:
|
|
|
|
+ case 0x7f:
|
|
|
|
+ if (input.length() > 0) {
|
|
|
|
+ *this << "\x08 \x08";
|
|
|
|
+ // this->flush();
|
|
|
|
+ input.erase(input.length() - 1);
|
|
|
|
+ };
|
|
|
|
+ break;
|
|
|
|
+ case 0x0d:
|
|
|
|
+ return input;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Take given buffer and output it.
|
|
* Take given buffer and output it.
|
|
*
|
|
*
|