void ChatPanel::SetChannel( Channel* chan ) { ASSERT_LOGIC( this, _T( "this==null" ) ); ASSERT_LOGIC( m_type == CPT_Channel, _T( "Not of type channel" ) ); if (( chan == 0 ) && ( m_channel != 0 ) ) { // causes weird crash. StatusMessage( _( "Chat closed." ) ); m_channel->uidata.panel = 0; } if ( m_show_nick_list && (m_nicklist != 0) ) { m_nicklist->ClearUsers(); } if ( chan != 0 ) { chan->uidata.panel = this; // m_chat_log.SetTarget( sett().GetDefaultServer(), chan->GetName() ); } m_channel = chan; //set back to false so when we rejoin this channel SetTopic doesn;t update the chan icon if ( !m_channel ) m_topic_set = false; }
void ChatPanel::SetChannel(Channel* chan) { ASSERT_LOGIC(this, "this==null"); ASSERT_LOGIC(m_type == CPT_Channel, "Not of type channel"); if ((chan == 0) && (m_channel != 0)) { m_channel->uidata.panel = 0; } if (m_nicklist != nullptr) { m_nicklist->ClearUsers(); UpdateUserCountLabel(); } if (chan != 0) { chan->uidata.panel = this; if (chan != m_channel) { SetLogFile(TowxString(chan->GetName())); } } m_channel = chan; //set back to false so when we rejoin this channel SetTopic doesn;t update the chan icon if (!m_channel) m_topic_set = false; }
int NickListCtrl::CompareUserStatus(DataType user1, DataType user2) { ASSERT_LOGIC(user1 != 0, "user1 = 0"); ASSERT_LOGIC(user2 != 0, "user2 = 0"); int u1 = 0, u2 = 0; if (user1->GetStatus().bot) u1 += 1000; if (user2->GetStatus().bot) u2 += 1000; if (user1->GetStatus().moderator) u1 += 100; if (user2->GetStatus().moderator) u2 += 100; if (user1->GetStatus().in_game) u1 += -10; if (user2->GetStatus().in_game) u2 += -10; // inverse the order if (u1 < u2) return -1; if (u1 > u2) return 1; return 0; }
UnitSyncMap SpringUnitSync::GetMapEx( const wxString& mapname ) { wxLogDebugFunc( _T("") ); int i = GetMapIndex( mapname ); ASSERT_LOGIC( i >= 0, _T("Map does not exist") ); return GetMapEx( i ); }
void IServer::_RemoveChannel(const std::string& name) { Channel* c = &m_channels.GetChannel(name); m_channels.RemoveChannel(name); ASSERT_LOGIC(c != 0, "IServer::_RemoveChannel(\"" + name + "\"): GetChannel returned NULL pointer"); delete c; }
void IServer::_RemoveBattle(const int& id) { IBattle* b = &battles_iter->GetBattle(id); m_battles.RemoveBattle(id); ASSERT_LOGIC(b != 0, "IServer::_RemoveBattle(): GetBattle returned NULL pointer"); delete b; }
//! @brief Open a new chat tab with a private chat //! //! @param nick The user to whom the chatwindow should be opened to void MainWindow::OpenPrivateChat(const User& user, bool doFocus) { ASSERT_LOGIC(m_chat_tab != 0, "m_chat_tab"); m_func_tabs->SetSelection(PAGE_CHAT); ChatPanel* cp = m_chat_tab->AddChatPanel(user); if (doFocus) cp->FocusInputBox(); }
bool DataList::Rename(const std::string& old_name, const std::string& new_name) { // check that new name is not used up. if (nodes.find(BA::to_lower_copy(new_name)) != nodes.end()) return false; nodes_iterator i = nodes.find(BA::to_lower_copy(old_name)); if (i == nodes.end()) return false; PNode node = i->second; ASSERT_LOGIC(node.Ok(), "Internal TDF tree consistency (1)"); ASSERT_LOGIC(node->Name().Lower() == old_name.Lower(), "Internal TDF tree consistency (2)"); node->name = BA::to_lower_copy(new_name); nodes.erase(i); bool inserted = nodes.insert(std::pair<std::string, PNode>(BA::to_lower_copy(node->name), node)).second; ASSERT_LOGIC(inserted, "DataList::Rename failed"); return inserted; }
void IBattle::SetHostMap(const std::string& _mapname, const std::string& _hash) { ASSERT_LOGIC(!_mapname.empty(), _T("Battle with empty map name!")); const std::string mapname(_mapname); const std::string hash(_hash); if ( mapname != m_host_map.name || hash != m_host_map.hash ) { m_map_loaded = false; m_host_map.name = mapname; m_host_map.hash = hash; } }
void IBattle::SetLocalMap(const std::string& mapname) { ASSERT_LOGIC(!mapname.empty(), _T("Battle with empty map name!")); LSL::UnitsyncMap map = LSL::usync().GetMap(mapname); if ( map.name != m_local_map.name || map.hash != m_local_map.hash ) { m_local_map = map; m_map_loaded = true; if ( IsFounderMe() ) {// save all rects infos //TODO } } }
void SocketEvents::OnSocketEvent(wxSocketEvent& event) { Socket* sock = (Socket*)event.GetClientData(); try { ASSERT_LOGIC( sock != 0, _T("sock = 0") ); } catch (...) { return; } if ( event.GetSocketEvent() == wxSOCKET_INPUT ) { m_net_class.OnDataReceived( sock ); } else if ( event.GetSocketEvent() == wxSOCKET_LOST ) { m_net_class.OnDisconnected( sock ); } else if ( event.GetSocketEvent() == wxSOCKET_CONNECTION ) { m_net_class.OnConnected( sock ); } else { try { ASSERT_LOGIC( false, _T("Unknown socket event.")); } catch (...) { return; }; } }
wxBitmap& IconsCollection::GetFractionBmp(const std::string& modName, int fractionId) { wxASSERT(-1 < fractionId); wxASSERT(modName.empty() == false); if (!LSL::usync().GameExists(modName)){ // game doesn't exist, dl needed?! return BMP_EMPTY; } const auto sides = LSL::usync().GetSides(modName); //This can happen whenever in time, so must be caught in release build too if (sides.empty()) { wxLogWarning("IconsCollection::GetFractionBmp(): sides.empty()"); return BMP_EMPTY; } ASSERT_LOGIC(fractionId < static_cast<int>(sides.size()), "LSL::usync().GetSides() < fractionID!"); std::string sideName; sideName = sides[fractionId]; const std::string cacheString = modName + "_" + sideName; //Check if image already in cache if (m_cachedFractionBmps.find(cacheString) != m_cachedFractionBmps.end()) { return m_cachedFractionBmps[cacheString]; //Create one and add to cache } else { try { const LSL::UnitsyncImage img = LSL::usync().GetSidePicture(modName, sideName); m_cachedFractionBmps[cacheString] = img.wxbitmap(); } catch (...) { //unitsync can fail! ASSERT_LOGIC(false, "LSL::usync().GetSidePicture() failed!"); } return m_cachedFractionBmps[cacheString]; } }
void BattleListTab::OnListJoin(wxListEvent& event) { try { ASSERT_LOGIC(m_battle_list != 0, "m_battle_list = 0"); } catch (...) { return; } if (event.GetIndex() < 0) return; int id = m_battle_list->GetSelectedData()->GetBattleId(); DoJoin(serverSelector().GetServer().battles_iter->GetBattle(id)); }
/// find by name. unused. PNode DataList::Find(const std::string& str) { if (str == "..") return Parent(); if (str == ".") return this; nodes_iterator i = nodes.find(BA::to_lower_copy(str)); if (i != nodes.end()) { ASSERT_LOGIC(BA::to_lower_copy(i->second->Name()) == BA::to_lower_copy(str), "Internal TDF tree consistency (3)"); return i->second; } return NULL; }
void SimpleServerEvents::OnBattleAddBot( int battleid, const wxString& nick, UserBattleStatus status ) { wxLogDebugFunc( _T("") ); try { Battle& battle = m_serv.GetBattle( battleid ); battle.OnBotAdded( nick, status ); User& bot = battle.GetUser( nick ); ASSERT_LOGIC( &bot != 0, _T("Bot null after add.") ); // ui().OnUserJoinedBattle( battle, bot ); } catch (assert_exception) {} }
void BattleListTab::OnJoin( wxCommandEvent& /*unused*/ ) { try { ASSERT_LOGIC( m_battle_list != 0, _T( "m_battle_list = 0" ) ); } catch ( ... ) { return; } if ( m_battle_list->GetSelectedIndex() < 0 ) return; int id = m_battle_list->GetSelectedData()->GetBattleId(); DoJoin( serverSelector().GetServer().battles_iter->GetBattle( id ) ); }
void BattleListTab::OnJoin(wxCommandEvent& /*unused*/) { try { ASSERT_LOGIC(m_battle_list != 0, "m_battle_list = 0"); } catch (...) { return; } if (m_battle_list->GetSelectedIndex() < 0) return; const IBattle* battle = m_battle_list->GetSelectedData(); assert(battle != NULL); const int id = battle->GetBattleId(); DoJoin(serverSelector().GetServer().battles_iter->GetBattle(id)); }
void ChatPanel::SetServer(IServer* serv) { ASSERT_LOGIC(m_type == CPT_Server, "Not of type server"); if (m_nicklist != nullptr) { m_nicklist->ClearUsers(); UpdateUserCountLabel(); } if (serv != 0) { SetLogFile(_T("server")); serv->uidata.panel = this; if (m_server != nullptr) { m_server->uidata.panel = 0; } m_server = serv; } }
void SimpleServerEvents::OnNewUser( const wxString& nick, const wxString& country, int cpu, const wxString& id ) { wxLogDebugFunc( _T("") ); try { ASSERT_LOGIC( !m_serv.UserExists( nick ), _T("New user from server, but already exists!") ); } catch (...) { return; } User& user = m_serv._AddUser( nick ); user.SetCountry( country ); user.SetCpu( cpu ); user.SetID( id ); // ui().OnUserOnline( user ); }
void SinglePlayerTab::OnAddBot(wxCommandEvent& /*unused*/) { AddBotDialog dlg(this, m_battle, true); if (dlg.ShowModal() == wxID_OK) { UserBattleStatus bs; bs.owner = m_battle.GetMe().GetNick(); bs.aishortname = STD_STRING(dlg.GetAIShortName()); bs.airawname = STD_STRING(dlg.GetAiRawName()); bs.aiversion = STD_STRING(dlg.GetAIVersion()); bs.aitype = dlg.GetAIType(); bs.team = m_battle.GetFreeTeam(); bs.ally = m_battle.GetFreeAlly(); bs.colour = m_battle.GetNewColour(); User& bot = m_battle.OnBotAdded(STD_STRING(dlg.GetNick()), bs); ASSERT_LOGIC(&bot != 0, "bot == 0"); m_minimap->UpdateMinimap(); } }
wxBitmap& IconsCollection::GetFractionBmp(const std::string& gameName, size_t fractionId) { if (gameName.empty() || !LSL::usync().GameExists(gameName)) { wxLogWarning("SideIcon %zu for game %s not found!", fractionId, gameName.c_str()); // game doesn't exist, dl needed?! return BMP_EMPTY; } const auto sides = LSL::usync().GetSides(gameName); //This can happen whenever in time, so must be caught in release build too if (sides.empty()) { wxLogWarning("IconsCollection::GetFractionBmp(): sides.empty()"); return BMP_EMPTY; } if (fractionId >= sides.size()) { wxLogWarning("Invalid side requested: %s:%d", gameName.c_str(), fractionId); return BMP_EMPTY; } std::string sideName; sideName = sides[fractionId]; const std::string cacheString = gameName + "_" + sideName; //Check if image already in cache if (m_cachedFractionBmps.find(cacheString) != m_cachedFractionBmps.end()) { return m_cachedFractionBmps[cacheString]; //Create one and add to cache } else { try { const LSL::UnitsyncImage img = LSL::usync().GetSidePicture(gameName, sideName); m_cachedFractionBmps[cacheString] = img.wxbitmap(); } catch (...) { //unitsync can fail! ASSERT_LOGIC(false, "LSL::usync().GetSidePicture() failed!"); } return m_cachedFractionBmps[cacheString]; } }
void ChatPanel::SetUser( const User* usr ) { ASSERT_LOGIC( m_type == CPT_User, _T( "Not of type user" ) ); if (( usr == 0 ) && ( m_user != 0 ) ) { StatusMessage( _( "Chat closed." ) ); m_user->uidata.panel = 0; m_chan_opts_button->SetBitmapLabel( icons().GetBitmap(icons().ICON_EMPTY) ); } else if ( usr != 0 ) usr->uidata.panel = this; m_user = usr; if ( m_user ) { m_chan_opts_button->SetBitmapLabel( icons().GetBitmap(icons().GetUserListStateIcon(m_user->GetStatus(),false, m_user->GetBattle() != 0 ) ) ); } // if ( m_user ) // m_chat_log.SetTarget( sett().GetDefaultServer(), usr->GetNick() ); }
void ServerEvents::OnNewUser( const wxString& nick, const wxString& country, int cpu, const wxString& id ) { wxLogDebugFunc( _T("") ); try { ASSERT_LOGIC( !m_serv.UserExists( nick ), _T("New user from server, but already exists!") ); } catch (...) { return; } User& user = m_serv._AddUser( nick ); if ( useractions().DoActionOnUser( UserActions::ActNotifLogin, nick ) ) actNotifBox( SL_MAIN_ICON, nick + _(" is online") ); user.SetCountry( country ); user.SetCpu( cpu ); user.SetID( id ); ui().OnUserOnline( user ); }
void ChatPanel::SetUser(const User* usr) { ASSERT_LOGIC(m_type == CPT_User, "Not of type user"); if (usr == NULL) { if (m_user != NULL) { m_user->uidata.panel = 0; if (m_chan_opts_button != NULL) { m_chan_opts_button->SetBitmapLabel(icons().GetBitmap(icons().ICON_EMPTY)); } } } else { usr->uidata.panel = this; if (m_chan_opts_button != NULL) { const wxBitmap icon = icons().GetBitmap(icons().GetUserListStateIcon(usr->GetStatus(), false, usr->GetBattle() != 0)); m_chan_opts_button->SetBitmapLabel(icon); } } m_user = usr; }
void ChatPanel::SetUser(User* usr) { ASSERT_LOGIC(m_type == CPT_User, "Not of type user"); if (usr == NULL) { if (m_user != NULL) { m_user->panel = nullptr; if (m_chan_opts_button != NULL) { m_chan_opts_button->SetBitmapLabel(IconsCollection::Instance()->BMP_EMPTY); } } } else { usr->panel = this; if (m_chan_opts_button != NULL) { const wxBitmap icon = IconsCollection::Instance()->GetUserListStateIcon(usr->GetStatus(), false, usr->GetBattle() != 0); m_chan_opts_button->SetBitmapLabel(icon); } } m_user = usr; }
void ChatPanel::SetServer( Server* serv ) { ASSERT_LOGIC( m_type == CPT_Server, _T( "Not of type server" ) ); if (( serv == 0 ) && ( m_server != 0 ) ){ StatusMessage( _( "Chat closed." ) ); m_server->uidata.panel = 0; if ( m_nicklist ) { m_nicklist->StopTimer(); m_nicklist->Clear(); } } else if ( serv != 0 ){ serv->uidata.panel = this; if ( m_nicklist ) m_nicklist->StartTimer(); } m_server = serv; // if ( m_server ){ // m_chat_log.SetTarget( sett().GetDefaultServer(), _( "_SERVER" ) ); // } }
ChatPanel& BattleRoomTab::GetChatPanel() { slLogDebugFunc(""); ASSERT_LOGIC(m_chat != 0, "m_chat = 0"); return *m_chat; }
BattleroomListCtrl& BattleRoomTab::GetPlayersListCtrl() { ASSERT_LOGIC(m_players != 0, "m_players = 0"); return *m_players; }
//! @brief Open a new chat tab with a channel chat //! //! @param channel The channel name //! @note This does NOT join the chatt. //! @sa Server::JoinChannel OpenPrivateChat void MainWindow::OpenChannelChat(Channel& channel, bool doFocus) { ASSERT_LOGIC(m_chat_tab != 0, "m_chat_tab"); m_chat_tab->AddChatPanel(channel, doFocus); }
ChatPanel& MainChatTab::ServerChat() { ASSERT_LOGIC(m_server_chat != 0, "m_server_chat = 0"); return *m_server_chat; }