26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ |
29 */ |
30 |
30 |
|
31 #include <curses.h> |
31 #include <string.h> |
32 #include <string.h> |
32 #include <time.h> |
33 #include <time.h> |
33 #include "interface.h" |
34 #include "interface.h" |
34 #include "network/rconsession.h" |
35 #include "network/rconsession.h" |
35 #include "network/ipaddress.h" |
36 #include "network/ipaddress.h" |
36 #include "coloredline.h" |
37 #include "coloredline.h" |
|
38 BEGIN_ZFC_NAMESPACE |
37 |
39 |
38 static const int g_pageSize = 10; |
40 static const int g_pageSize = 10; |
39 |
41 |
40 // ------------------------------------------------------------------------------------------------- |
42 // ------------------------------------------------------------------------------------------------- |
41 // |
43 // |
139 } |
141 } |
140 |
142 |
141 // ------------------------------------------------------------------------------------------------- |
143 // ------------------------------------------------------------------------------------------------- |
142 // |
144 // |
143 Interface::Interface() : |
145 Interface::Interface() : |
144 Session (this) |
146 Session (this), |
|
147 InputCursor (0), |
|
148 CursorPosition (0), |
|
149 InputPanning (0), |
|
150 NeedRefresh (false), |
|
151 NeedStatusBarRender (false), |
|
152 NeedInputRender (false), |
|
153 NeedOutputRender (false), |
|
154 NeedNicklistRender (false), |
|
155 OutputScroll (0), |
|
156 CurrentInputState (INPUTSTATE_NORMAL), |
|
157 DisconnectConfirmFunction (NULL) |
145 { |
158 { |
146 #ifdef XCURSES |
159 #ifdef XCURSES |
147 ::Xinitscr(argc, argv); |
160 ::Xinitscr(argc, argv); |
148 #else |
161 #else |
149 ::initscr(); |
162 ::initscr(); |
217 render_titlebar(); |
230 render_titlebar(); |
218 } |
231 } |
219 |
232 |
220 // ------------------------------------------------------------------------------------------------- |
233 // ------------------------------------------------------------------------------------------------- |
221 // |
234 // |
222 void Interface::safe_disconnect (Function<void()> afterwards) |
235 void Interface::safe_disconnect (std::function<void()> afterwards) |
223 { |
236 { |
224 if (Session.is_active()) |
237 if (Session.is_active()) |
225 { |
238 { |
226 DisconnectConfirmFunction = afterwards; |
239 DisconnectConfirmFunction = afterwards; |
227 set_input_state (INPUTSTATE_CONFIRM_DISCONNECTION); |
240 set_input_state (INPUTSTATE_CONFIRM_DISCONNECTION); |
441 int y = LINES - 2; |
456 int y = LINES - 2; |
442 |
457 |
443 // If we're inputting a password, replace it with asterisks |
458 // If we're inputting a password, replace it with asterisks |
444 if (CurrentInputState == INPUTSTATE_PASSWORD) |
459 if (CurrentInputState == INPUTSTATE_PASSWORD) |
445 { |
460 { |
446 for (char& ch : displayString) |
461 for (int i = 0; i < displayString.length(); ++i) |
447 ch = '*'; |
462 displayString[i] = '*'; |
448 } |
463 } |
449 |
464 |
450 // Ensure the cursor is within bounds |
465 // Ensure the cursor is within bounds |
451 CursorPosition = clamp (CursorPosition, 0, displayString.length()); |
466 CursorPosition = clamp (CursorPosition, 0, displayString.length()); |
452 |
467 |
521 { |
536 { |
522 adminText.sprintf ("%d other admin%s", Session.num_admins(), |
537 adminText.sprintf ("%d other admin%s", Session.num_admins(), |
523 Session.num_admins() != 1 ? "s" : ""); |
538 Session.num_admins() != 1 ? "s" : ""); |
524 } |
539 } |
525 |
540 |
526 text.sprintf ("%s | %s | %s", Session.address().to_string (IP_WITH_PORT).chars(), |
541 text.sprintf ("%s | %s | %s", |
527 Session.level().chars(), adminText.chars()); |
542 Session.address().to_string (IPAddress::WITH_PORT).chars(), |
|
543 Session.level().chars(), |
|
544 adminText.chars()); |
528 } |
545 } |
529 break; |
546 break; |
530 } |
547 } |
531 |
548 |
532 if (not text.is_empty()) |
549 if (not text.is_empty()) |
948 va_end (args); |
965 va_end (args); |
949 } |
966 } |
950 |
967 |
951 // ------------------------------------------------------------------------------------------------- |
968 // ------------------------------------------------------------------------------------------------- |
952 // |
969 // |
953 void Interface::print_to_console (String a) |
970 void Interface::print_to_console (String message) |
954 { |
971 { |
955 // Zandronum sometimes sends color codes as "\\c" and sometimes as "\x1C". |
972 // Zandronum sometimes sends color codes as "\\c" and sometimes as "\x1C". |
956 // Let's correct that on our end and hope this won't cause conflicts. |
973 // Let's correct that on our end and hope this won't cause conflicts. |
957 a.replace ("\\c", "\x1C"); |
974 message.replace ("\\c", "\x1C"); |
958 |
975 |
959 for (char ch : a) |
976 for (int i = 0; i < message.length(); ++i) |
960 { |
977 { |
|
978 char ch = message[i]; |
|
979 |
961 if (ch == '\n') |
980 if (ch == '\n') |
962 { |
981 { |
963 OutputLines.last().finalize(); |
982 OutputLines.last().finalize(); |
964 OutputLines << ColoredLine(); |
983 OutputLines << ColoredLine(); |
965 continue; |
984 continue; |