sources/interface.cpp

branch
protocol5
changeset 159
970d58a01e8b
parent 151
267ef11bd3ba
parent 156
ce66d7e374bf
child 160
cf514fa0f1cc
equal deleted inserted replaced
155:9f71f854474a 159:970d58a01e8b
166 ::timeout(0); 166 ::timeout(0);
167 m_inputHistory.clear(); 167 m_inputHistory.clear();
168 m_inputHistory << ""; 168 m_inputHistory << "";
169 m_outputLines.clear(); 169 m_outputLines.clear();
170 m_outputLines << ColoredLine(); 170 m_outputLines << ColoredLine();
171 m_session.set_interface(this); 171 m_session.setInterface(this);
172 resetTitle(); 172 resetTitle();
173 173
174 if (::has_colors()) 174 if (::has_colors())
175 { 175 {
176 ::start_color(); 176 ::start_color();
228 228
229 // ------------------------------------------------------------------------------------------------- 229 // -------------------------------------------------------------------------------------------------
230 // 230 //
231 void Interface::safeDisconnect(std::function<void(bool)> afterwards) 231 void Interface::safeDisconnect(std::function<void(bool)> afterwards)
232 { 232 {
233 if (m_session.is_active()) 233 if (m_session.isActive())
234 { 234 {
235 m_disconnectCallback = afterwards; 235 m_disconnectCallback = afterwards;
236 setInputState(INPUTSTATE_CONFIRM_DISCONNECTION); 236 setInputState(INPUTSTATE_CONFIRM_DISCONNECTION);
237 } 237 }
238 else 238 else
478 // 478 //
479 void Interface::updateStatusBar() 479 void Interface::updateStatusBar()
480 { 480 {
481 String text; 481 String text;
482 482
483 switch (m_session.state()) 483 switch (m_session.getState())
484 { 484 {
485 case RCON_DISCONNECTED: 485 case RCON_DISCONNECTED:
486 text = "Disconnected."; 486 text = "Disconnected.";
487 break; 487 break;
488 488
493 493
494 case RCON_CONNECTED: 494 case RCON_CONNECTED:
495 { 495 {
496 String adminText; 496 String adminText;
497 497
498 if (m_session.num_admins() == 0) 498 if (m_session.getAdminCount() == 0)
499 { 499 {
500 adminText = "No other admins"; 500 adminText = "No other admins";
501 } 501 }
502 else 502 else
503 { 503 {
504 adminText.sprintf("%d other admin%s", m_session.num_admins(), 504 adminText.sprintf("%d other admin%s", m_session.getAdminCount(),
505 m_session.num_admins() != 1 ? "s" : ""); 505 m_session.getAdminCount() != 1 ? "s" : "");
506 } 506 }
507 507
508 text.sprintf("%s | %s | %s", 508 text.sprintf("%s | %s | %s",
509 m_session.address().to_string(IPAddress::WITH_PORT).chars(), 509 m_session.address().to_string(IPAddress::WITH_PORT).chars(),
510 m_session.level().chars(), 510 m_session.getLevel().chars(),
511 adminText.chars()); 511 adminText.chars());
512 } 512 }
513 break; 513 break;
514 } 514 }
515 515
516 if (not text.isEmpty()) 516 if (not text.isEmpty())
517 text += " | "; 517 text += " | ";
518 518
519 text += "Ctrl+N to connect, Ctrl+Q to "; 519 text += "Ctrl+N to connect, Ctrl+Q to ";
520 text +=(m_session.state() == RCON_DISCONNECTED) ? "quit" : "disconnect"; 520 text +=(m_session.getState() == RCON_DISCONNECTED) ? "quit" : "disconnect";
521 521
522 if (text != m_statusBarText) 522 if (text != m_statusBarText)
523 { 523 {
524 m_statusBarText = text; 524 m_statusBarText = text;
525 m_needStatusBarRender = true; 525 m_needStatusBarRender = true;
773 if (m_inputState == INPUTSTATE_NORMAL 773 if (m_inputState == INPUTSTATE_NORMAL
774 and m_cursorPosition > 0 774 and m_cursorPosition > 0
775 and(space == -1 or space >= m_cursorPosition)) 775 and(space == -1 or space >= m_cursorPosition))
776 { 776 {
777 String start = getCurrentInput().mid(0, m_cursorPosition); 777 String start = getCurrentInput().mid(0, m_cursorPosition);
778 m_session.request_tab_complete(start); 778 m_session.requestTabCompletion(start);
779 } 779 }
780 } 780 }
781 break; 781 break;
782 782
783 case '\n': 783 case '\n':
807 807
808 case INPUTSTATE_PASSWORD: 808 case INPUTSTATE_PASSWORD:
809 if (m_inputState == INPUTSTATE_PASSWORD and not getCurrentInput().isEmpty()) 809 if (m_inputState == INPUTSTATE_PASSWORD and not getCurrentInput().isEmpty())
810 { 810 {
811 m_session.disconnect(); 811 m_session.disconnect();
812 m_session.set_password(getCurrentInput()); 812 m_session.setPassword(getCurrentInput());
813 m_session.connect(m_remoteAddress); 813 m_session.connect(m_remoteAddress);
814 setInputState(INPUTSTATE_NORMAL); 814 setInputState(INPUTSTATE_NORMAL);
815 } 815 }
816 break; 816 break;
817 817
819 if (getCurrentInput()[0] == '/') 819 if (getCurrentInput()[0] == '/')
820 { 820 {
821 handleCommand(getCurrentInput()); 821 handleCommand(getCurrentInput());
822 flushInput(); 822 flushInput();
823 } 823 }
824 else if (m_session.send_command(getCurrentInput())) 824 else if (m_session.sendCommand(getCurrentInput()))
825 { 825 {
826 flushInput(); 826 flushInput();
827 } 827 }
828 break; 828 break;
829 } 829 }
1005 1005
1006 if (m_remoteAddress.port == 0) 1006 if (m_remoteAddress.port == 0)
1007 m_remoteAddress.port = 10666; 1007 m_remoteAddress.port = 10666;
1008 1008
1009 m_session.disconnect(); 1009 m_session.disconnect();
1010 m_session.set_password(password); 1010 m_session.setPassword(password);
1011 m_session.connect(m_remoteAddress); 1011 m_session.connect(m_remoteAddress);
1012 } 1012 }
1013 1013
1014 // ------------------------------------------------------------------------------------------------- 1014 // -------------------------------------------------------------------------------------------------
1015 // 1015 //
1077 } 1077 }
1078 1078
1079 if (address.port == 0) 1079 if (address.port == 0)
1080 address.port = 10666; 1080 address.port = 10666;
1081 1081
1082 m_session.set_password(args[1]); 1082 m_session.setPassword(args[1]);
1083 m_session.disconnect(); 1083 m_session.disconnect();
1084 m_session.connect(m_remoteAddress = address); 1084 m_session.connect(m_remoteAddress = address);
1085 } 1085 }
1086 } 1086 }
1087 else if (command == "disconnect") 1087 else if (command == "disconnect")

mercurial