bool ChatPanel::Say(const wxString& message) //FIXME: remove all parsing / tokenizing / ... to dedicated file { static const unsigned int flood_threshold = 5; slLogDebugFunc(""); wxStringTokenizer lines(message, _T('\n')); if (lines.CountTokens() > flood_threshold) { PasteDialog dl(this, wxString::Format(_("Are you sure you want to paste %d lines?"), lines.CountTokens())); switch (dl.ShowModal()) { case wxID_NO: return true; case PasteDialog::pasteButtonReturnCode: { wxString url = Paste2Pastebin(message); if (url != wxEmptyString && wxStringTokenizer(url, _T('\n')).CountTokens() <= flood_threshold) { Say(url); return true; } else { customMessageBoxModal(SL_MAIN_ICON, wxString::Format(_("Failed to post to %s"), _T("paste.springfiles.com"))); return false; } } default: break; } } while (lines.HasMoreTokens()) { wxString line = lines.GetNextToken(); wxLogDebug(_T( "line: %s" ), line.c_str()); if (line == "/help") { ui().ConsoleHelp(); return true; } if (line == "/channels") { ui().mw().ShowChannelChooser(); return true; } if (line == _T( "/ver" )) { //!this instance is not replaced with GetAppname for sake of help/debug online OutputLine(wxString::Format(_("You have %s."), GetSpringlobbyAgent()), sett().GetChatColorNormal()); return true; } if (line == _T( "/clear" )) { m_chatlog_text->SetValue(wxEmptyString); return true; } if (m_type == CPT_Channel) { if (m_channel == 0) { OutputError(_("You are not in channel or channel does not exist.")); return true; } if (line.StartsWith(_T( "/" ))) { if (m_channel->ExecuteSayCommand(STD_STRING(line))) return true; if (m_channel->GetServer().ExecuteSayCommand(STD_STRING(line))) return true; OutputError(wxString::Format(_("Command (%s) does not exist, use /help for a list of available commands."), line.c_str())); return true; } m_channel->Say(STD_STRING(line)); } else if (m_type == CPT_Battle) { if (m_battle == 0) { OutputError(_("You are not in battle or battle does not exist, use /help for a list of available commands.")); return true; } if (line.StartsWith(_T( "/" ))) { if (m_battle->ExecuteSayCommand(STD_STRING(line))) return true; if (m_battle->GetServer().ExecuteSayCommand(STD_STRING(line))) return true; OutputError(wxString::Format(_("Command (%s) does not exist, use /help for a list of available commands."), line.c_str())); return true; } m_battle->Say(STD_STRING(line)); } else if (m_type == CPT_User) { if (m_user == 0) { OutputError(_("User is offline.")); return true; } if (line.StartsWith(_T( "/" ))) { if (m_user->ExecuteSayCommand(STD_STRING(line))) return true; if (m_user->GetServer().ExecuteSayCommand(STD_STRING(line))) return true; OutputError(wxString::Format(_("Command (%s) does not exist, use /help for a list of available commands."), line.c_str())); return true; } m_user->Say(STD_STRING(line)); } else if (m_type == CPT_Server) { if (m_server == 0) { OutputError(_("Not connected to server")); return true; } if (line.StartsWith(_T( "/" ))) { if (m_server->ExecuteSayCommand(STD_STRING(line))) return true; OutputError(wxString::Format(_("Command (%s) does not exist, use /help for a list of available commands."), line.c_str())); return true; } m_server->SendCmd(STD_STRING(line), ""); OutputLine(_("Sent: \"") + line + _T("\""), sett().GetChatColorNormal()); } } return true; }
bool ChatPanel::Say( const wxString& message ) { static const unsigned int flood_threshold = 5; wxLogDebugFunc( message ); wxStringTokenizer lines( message, _T( '\n' ) ); if ( lines.CountTokens() > flood_threshold ) { PasteDialog dl ( this, wxString::Format( _( "Are you sure you want to paste %d lines?" ), lines.CountTokens() ) ); switch ( dl.ShowModal() ) { case wxID_NO : return true; case PasteDialog::pasteButtonReturnCode : { wxString url = Paste2Pastebin( message ); if ( url != wxEmptyString && wxStringTokenizer( url, _T( '\n' )).CountTokens() <= flood_threshold ) { Say( url ); return true; } else { customMessageBoxNoModal( SL_MAIN_ICON, _("Failed to post to pastebin.com.") ); return false; } } default: break; } } while ( lines.HasMoreTokens() ) { wxString line = lines.GetNextToken(); wxLogMessage( _T( "line: %s" ), line.c_str() ); if ( line.Find( '/' ) == 0 ) { if ( ui().ExecuteSayCommand( line ) ) return true; } if ( line == _T( "/ver" ) ) { //!this instance is not replaced with GetAppname for sake of help/debug online OutputLine( _( " You have SpringLobby v" ) + GetSpringLobbyVersion(), sett().GetChatColorNormal() , sett().GetChatFont() ); return true; } if ( line == _T( "/clear" ) ) { m_chatlog_text->SetValue( _T("") ); return true; } if ( m_type == CPT_Channel ) { if ( m_channel == 0 ) { OutputLine( _( " You are not in channel or channel does not exist." ), sett().GetChatColorError(), sett().GetChatFont() ); return true; } if ( line.StartsWith( _T( "/" ) ) ) { if ( m_channel->ExecuteSayCommand( line ) ) return true; if ( m_channel->GetServer().ExecuteSayCommand( line ) ) return true; OutputLine( wxString::Format( _( " Error: Command (%s) does not exist, use /help for a list of available commands." ), line.c_str() ), sett().GetChatColorError(), sett().GetChatFont() ); return true; } m_channel->Say( line ); } else if ( m_type == CPT_Battle ) { if ( m_battle == 0 ) { OutputLine( _( " You are not in battle or battle does not exist, use /help for a list of available commands." ), sett().GetChatColorError(), sett().GetChatFont() ); return true; } if ( line.StartsWith( _T( "/" ) ) ) { if ( m_battle->ExecuteSayCommand( line ) ) return true; if ( m_battle->GetServer().ExecuteSayCommand( line ) ) return true; OutputLine( wxString::Format( _( " Error: Command (%s) does not exist, use /help for a list of available commands." ), line.c_str() ), sett().GetChatColorError(), sett().GetChatFont() ); return true; } m_battle->Say( line ); } else if ( m_type == CPT_User ) { if ( m_user == 0 ) { OutputLine( _( " User is offline." ), sett().GetChatColorError(), sett().GetChatFont() ); return true; } if ( line.StartsWith( _T( "/" ) ) ) { if ( m_user->ExecuteSayCommand( line ) ) return true; if ( m_user->GetServer().ExecuteSayCommand( line ) ) return true; OutputLine( wxString::Format( _( " Error: Command (%s) does not exist, use /help for a list of available commands." ), line.c_str() ), sett().GetChatColorError(), sett().GetChatFont() ); return true; } m_user->Say( line ); } else if ( m_type == CPT_Server ) { if ( m_server == 0 ) return true; if ( line.StartsWith( _T( "/" ) ) ) { if ( m_server->ExecuteSayCommand( line ) ) return true; OutputLine( wxString::Format( _( " Error: Command (%s) does not exist, use /help for a list of available commands." ), line.c_str() ), sett().GetChatColorError(), sett().GetChatFont() ); return true; } //we need to disable the channel tab if leaving manually if (line.Upper().StartsWith( _T( "LEAVE" ) ) ) { wxString channame = line.AfterFirst(' ').BeforeFirst(' '); try { Channel& chan = m_server->GetChannel( channame ); chan.Leave(); chan.uidata.panel = 0; } catch( assert_exception ) {} } m_server->SendRaw( line ); OutputLine( _( " Sent: \"" ) + line + _( "\"" ), sett().GetChatColorNormal(), sett().GetChatFont() ); } } return true; }