Пример #1
0
void ChatPanel::Parted(User& who, const wxString& message)
{
	//    assert( m_type == CPT_Channel || m_type == CPT_Server || m_type == CPT_Battle || m_type == CPT_User );
	const bool me_parted = m_channel && &who == &m_channel->GetMe();
	const wxString nick = TowxString(who.GetNick());
	const bool wasactive = m_active_users.erase(nick) > 0;
	if (m_display_joinitem || (wasactive && !who.IsBot())) {
		OutputLine(_T( "** " ) + wxString::Format(_("%s left %s (%s)."), nick.c_str(), GetChatTypeStr().c_str(), message.c_str()), sett().GetChatColorJoinPart());
	}
	if (m_type == CPT_Channel) {
		if (m_channel == 0)
			return;
		if (me_parted) {
			m_channel->panel = nullptr;
			SetChannel(0);
			return;
		}
		if (m_display_joinitem) {
			// change the image of the tab to show new events
			SetIconHighlight(highlight_join_leave);
		}
	} else if (m_type == CPT_Server && me_parted)
		return;
	if (m_show_nick_list && (m_nicklist != nullptr)) {
		m_nicklist->RemoveUser(who);
		UpdateUserCountLabel();
	}
	// Also remove the User from the TextCompletionDatabase
	textcompletiondatabase.Delete_Mapping(TowxString(who.GetNick()));
}
Пример #2
0
void IBattle::OnUserRemoved( User& user )
{
	UserBattleStatus& bs = user.BattleStatus();
	if ( !bs.spectator ) {
		PlayerLeftTeam( bs.team );
		PlayerLeftAlly( bs.ally );
	}
	if ( !bs.spectator && !bs.IsBot() ) {
		if ( bs.ready ) m_players_ready--;
		if ( bs.sync ) m_players_sync--;
		if ( bs.ready && bs.sync ) m_players_ok--;
	}
	if ( IsFounderMe() && bs.spectator ) {
		m_opts.spectators--;
		SendHostInfo( HI_Spectators );
	}
	if ( &user == &GetMe() ) {
		OnSelfLeftBattle();
	}
	UserList::RemoveUser( user.GetNick() );
	if ( !bs.IsBot() )
		user.SetBattle( 0 );
	else {
		UserVecIter itor = m_internal_bot_list.find( user.GetNick());
		if ( itor != m_internal_bot_list.end() ) {
			m_internal_bot_list.erase( itor );
		}
	}
}
Пример #3
0
	void Execute(IRCServer *server, User *u, const std::vector<std::string> &params)
	{
		const std::string &channel = params[0];
		const std::string &targnick = params[1];
		std::string reason = params.size() > 2 ? params[2] : "";

		Channel *c = server->FindChannel(channel);
		User *target = server->FindUser(targnick);
		if (c == NULL)
			u->WriteNumeric(403, channel + " :No such channel");
		else if (target == NULL)
			u->WriteNumeric(401, targnick + " :No such nick/channel");
		else if (!target->IsOnChannel(c))
			u->WriteNumeric(441, target->GetNick() + " " + c->GetName() + " :They aren't on that channel");
		else
		{
			user_status *status = c->FindUserStatus(u);
			if (status == NULL || !status->HasMode(CMODE_OP))
				u->WriteNumeric(482, c->GetName() + " :You're not a channel operator");
			else
			{
				if (reason.length() > IRCServer::kicklen)
					reason = reason.substr(0, IRCServer::kicklen);
				c->Send(u->GetMask(), "KICK " + c->GetName() + " " + target->GetNick() + " :" + reason);

				u->Part(c);
				c->Part(u);
			}
		}
	}
Пример #4
0
void ChatPanel::Parted( User& who, const wxString& message )
{
//    assert( m_type == CPT_Channel || m_type == CPT_Server || m_type == CPT_Battle || m_type == CPT_User );
    bool me_parted = m_channel && &who == &m_channel->GetMe();
	if ( m_type == CPT_Channel ) {
		if ( m_channel == 0 ) return;
		if ( me_parted ) {
			m_channel->uidata.panel = 0;
			SetChannel( 0 );
			return;
		}
		if ( sett().GetDisplayJoinLeave( m_channel->GetName() ) ) {
          // change the image of the tab to show new events
          SetIconHighlight( highlight_join_leave );
		  OutputLine( _T( " ** " ) + who.GetNick() + _( " left the " ) + GetChatTypeStr() + _T( "( " ) + message + _T( " )." ), sett().GetChatColorJoinPart(), sett().GetChatFont() );
        }
	} else if ( m_type == CPT_Battle ) {
		if ( sett().GetDisplayJoinLeave( _T( "game/battle" ) ) )  {
		    OutputLine( _T( " ** " ) + who.GetNick() + _( " left the " ) + GetChatTypeStr() + _T( "( " ) + message + _T( " )." ), sett().GetChatColorJoinPart(), sett().GetChatFont() );
        }
	}
	else if ( m_type == CPT_Server && me_parted )
        return;
	if ( m_show_nick_list && ( m_nicklist != 0 ) )
	{
		unsigned int numusers = 0;
		if ( m_type == CPT_Channel ) numusers = GetChannel()->GetNumUsers();
		else if ( m_type == CPT_Server && m_server ) numusers = m_server->GetNumUsers();
		m_usercount_label->SetLabel( wxString::Format( _("%d users"), numusers ) );
		m_nicklist->RemoveUser( who );
	}
	// Also remove the User from the TextCompletionDatabase
	textcompletiondatabase.Delete_Mapping( who.GetNick() );
}
Пример #5
0
void NickListCtrl::AddUser(const User& user)
{
	const auto it = m_real_users_list.find(user.GetNick());
	if (it != m_real_users_list.end()) {
		wxLogWarning(_T( "User already in list." ));
		return;
	}
	m_real_users_list[user.GetNick()] = &user;
	DoUsersFilter();
}
Пример #6
0
void Battle::OnUserBattleStatusUpdated( User &user, UserBattleStatus status )
{
    if ( IsFounderMe() )
    {
			if ( ( &user != &GetMe() ) && !status.IsBot() && ( m_opts.rankneeded != UserStatus::RANK_1 ) && !status.spectator )
			{
				if ( m_opts.rankneeded > UserStatus::RANK_1 && user.GetStatus().rank < m_opts.rankneeded )
				{
					DoAction( _T("Rank limit autospec: ") + user.GetNick() );
					ForceSpectator( user, true );
				}
				else if ( m_opts.rankneeded < UserStatus::RANK_1 && user.GetStatus().rank > ( -m_opts.rankneeded - 1 ) )
				{
					DoAction( _T("Rank limit autospec: ") + user.GetNick() );
					ForceSpectator( user, true );
				}
			}
			UserBattleStatus previousstatus = user.BattleStatus();
			if ( m_opts.lockexternalbalancechanges )
			{
				if ( previousstatus.team != status.team )
				{
					 ForceTeam( user, previousstatus.team );
					 status.team = previousstatus.team;
				}
				if ( previousstatus.ally != status.ally )
				{
					ForceAlly( user, previousstatus.ally );
					status.ally = previousstatus.ally;
				}
			}
    }
		IBattle::OnUserBattleStatusUpdated( user, status );
    if ( status.handicap != 0 )
    {
		UiEvents::GetUiEventSender( UiEvents::OnBattleActionEvent ).SendEvent(
				UiEvents::OnBattleActionData( wxString(_T(" ")) , ( _T("Warning: user ") + user.GetNick() + _T(" got bonus ") ) << status.handicap )
			);
    }
		if ( IsFounderMe() )
		{
			if ( ShouldAutoStart() )
			{
				if ( sett().GetBattleLastAutoStartState() )
				{
					if ( !spring().IsRunning() ) StartHostedBattle();
				}
			}
		}
	if ( !GetMe().BattleStatus().spectator ) SetAutoUnspec(false); // we don't need auto unspec anymore
	ShouldAutoUnspec();
#ifndef SL_QT_MODE
	ui().OnUserBattleStatus( *this, user );
#endif
}
Пример #7
0
void IBattle::OnUserBattleStatusUpdated( User &user, UserBattleStatus status )
{

    UserBattleStatus previousstatus = user.BattleStatus();

    user.UpdateBattleStatus( status );
	unsigned int oldspeccount = m_opts.spectators;
	m_opts.spectators = 0;
	m_players_sync = 0;
	m_players_ready = 0;
	m_players_ok = 0;
	m_teams_sizes.clear();
	m_ally_sizes.clear();
	for ( unsigned int i = 0; i < GetNumUsers(); i++ )
	{
		User& loopuser = GetUser( i );
		UserBattleStatus& loopstatus = loopuser.BattleStatus();
		if ( loopstatus.spectator ) m_opts.spectators++;
		if ( !loopstatus.IsBot() )
		{
			if ( !loopstatus.spectator )
			{
				if ( loopstatus.ready && loopstatus.spectator ) m_players_ready++;
				if ( loopstatus.sync ) m_players_sync++;
				if ( loopstatus.ready && loopstatus.sync ) m_players_ok++;
				PlayerJoinedTeam( loopstatus.team );
				PlayerJoinedAlly( loopstatus.ally );
			}
		}
	}
	if ( oldspeccount != m_opts.spectators  )
	{
		if ( IsFounderMe() ) SendHostInfo( HI_Spectators );
	}
	if ( !status.IsBot() )
	{
		if ( ( status.ready && status.sync ) || status.spectator )
		{
			std::map<wxString, time_t>::iterator itor = m_ready_up_map.find( user.GetNick() );
			if ( itor != m_ready_up_map.end() )
			{
				m_ready_up_map.erase( itor );
			}
		}
		if ( ( !status.ready || !status.sync ) && !status.spectator )
		{
			std::map<wxString, time_t>::iterator itor = m_ready_up_map.find( user.GetNick() );
			if ( itor == m_ready_up_map.end() )
			{
				m_ready_up_map[user.GetNick()] = time(0);
			}
		}
	}
}
Пример #8
0
void ChatPanel::OnChannelJoin(User& who)
{
	//    assert( m_type == CPT_Channel || m_type == CPT_Server || m_type == CPT_Battle || m_type == CPT_User );
	if (m_show_nick_list && (m_nicklist != nullptr)) {
		m_nicklist->AddUser(who);
		UpdateUserCountLabel();
	}
	if (m_display_joinitem) {
		OutputLine(_T( "** " ) + wxString::Format(_("%s joined %s."), TowxString(who.GetNick()).c_str(), GetChatTypeStr().c_str()), sett().GetChatColorJoinPart());
	}
	// Also add the User to the TextCompletionDatabase
	textcompletiondatabase.Insert_Mapping(TowxString(who.GetNick()), TowxString(who.GetNick()));
}
Пример #9
0
void ChatPanel::OnChannelJoin( User& who )
{
//    assert( m_type == CPT_Channel || m_type == CPT_Server || m_type == CPT_Battle || m_type == CPT_User );
	if ( m_show_nick_list && (m_nicklist != 0) )
	{
		unsigned int numusers = 0;
		if ( m_type == CPT_Channel ) numusers = GetChannel()->GetNumUsers();
		else if ( m_type == CPT_Server && m_server ) numusers = m_server->GetNumUsers();
		m_usercount_label->SetLabel( wxString::Format( _("%d users"), numusers ) );
		m_nicklist->AddUser( who );
	}

	// Also add the User to the TextCompletionDatabase
	textcompletiondatabase.Insert_Mapping( who.GetNick(), who.GetNick() );
}
Пример #10
0
void IServer::Reset()
{
    m_users.Nullify();
    while (m_users.GetNumUsers() > 0) {
        try {
            User* u = &m_users.GetUser(0);
            m_users.RemoveUser(u->GetNick());
            delete u;
        } catch (std::runtime_error) {
        }
    }

    while (battles_iter->GetNumBattles() > 0) {
        battles_iter->IteratorBegin();
        IBattle* b = battles_iter->GetBattle();
        if (b != 0) {
            m_battles.RemoveBattle(b->GetBattleId());
            delete b;
        }
    }
    while (m_channels.GetNumChannels() > 0) {
        Channel* c = &m_channels.GetChannel(0);
        m_channels.RemoveChannel(c->GetName());
        delete c;
    }
}
bool NickDataViewCtrl::IsContainsRealUser(const User& user) const
{
	const auto it = m_real_users_list.find(user.GetNick());
	if (it == m_real_users_list.end()) {
		return false;
	}
	return true;
}
Пример #12
0
void ChatPanel::Joined(User& who)
{
	if (m_display_joinitem) {
		// change the image of the tab to show new events
		if (m_type == CPT_Channel) {
			SetIconHighlight(highlight_join_leave);
		}
		OutputLine(_T( "** " ) + wxString::Format(_("%s joined %s."), TowxString(who.GetNick()).c_str(), GetChatTypeStr().c_str()), sett().GetChatColorJoinPart());
	}

	if (m_show_nick_list && (m_nicklist != nullptr)) {
		m_nicklist->AddUser(who);
		UpdateUserCountLabel();
	}
	// Also add the User to the TextCompletionDatabase
	textcompletiondatabase.Insert_Mapping(TowxString(who.GetNick()), TowxString(who.GetNick()));
}
Пример #13
0
/// Should only be called if user isn't immediately kicked (ban / rank limit)
void AutoHost::OnUserAdded( User& user )
{
	m_userlist.Add( user.GetNick() );
	// do nothing if autohost functionality is disabled
	if ( !m_enabled )
		return;
	m_battle.DoAction( wxString::Format( _T( "Hi %s, this battle is in %s autohost mode. For help say !help" ), user.GetNick().c_str(), GetAppName().c_str() ) );
}
Пример #14
0
void Channel::DidAction( User& who, const std::string& action )
{
	slLogDebugFunc("");
	if ( uidata.panel == 0 ) {
		wxLogError( _T("OnChannelDidAction: ud->panel NULL") );
		return;
	}
	uidata.panel->DidAction( TowxString(who.GetNick()), TowxString(action ));
}
bool NickDataViewCtrl::AddRealUser(const User& user)
{
	if (IsContainsRealUser(user)) {
		return false;
	}

	m_real_users_list[user.GetNick()] = &user;
	return true;
}
Пример #16
0
void Channel::Said( User& who, const std::string& message )
{
	slLogDebugFunc("");
	if (uidata.panel == 0 ) {
		wxLogError( _T("OnChannelSaid: ud->panel NULL") );
		return;
	}
	uidata.panel->Said( TowxString(who.GetNick()), TowxString(message));
}
Пример #17
0
void ServerEvents::OnPrivateMessageEx(User& chan, User& who, const std::string& action)
{
	slLogDebugFunc("");
	try {
		if (!useractions().DoActionOnUser(UserActions::ActIgnorePM, TowxString(who.GetNick())))
			ui().OnUserSaidEx(chan, who, TowxString(action));
	} catch (std::runtime_error& except) {
	}
}
Пример #18
0
void Channel::Left( User& who, const std::string& reason )
{
	RemoveUser(who.GetNick());
	//wxLogDebugFunc( wxEmptyString );
	if ( uidata.panel == 0 ) {
		wxLogError( _T("OnUserLeftChannel: ud->panel NULL") );
		return;
	}
	uidata.panel->Parted( who, TowxString(reason));
}
Пример #19
0
void NickListCtrl::UserUpdated(const User& user)
{
	const auto it = m_real_users_list.find(user.GetNick());
	if (it == m_real_users_list.end()) {
		wxLogWarning(_T( "NickListCtrl::UserUpdated error, index == -1 ." ));
		return;
	}
	it->second = &user;
	DoUsersFilter();
}
bool NickDataViewCtrl::RemoveRealUser(const User& user)
{
	const auto it = m_real_users_list.find(user.GetNick());
	if (it == m_real_users_list.end()) {
		return false;
	}

	m_real_users_list.erase(it);
	return true;
}
Пример #21
0
void NickListCtrl::RemoveUser(const User& user)
{
	const auto it = m_real_users_list.find(user.GetNick());
	if (it == m_real_users_list.end()) {
		wxLogWarning(_T( "Didn't find the user to remove." ));
		return;
	}
	m_real_users_list.erase(it);
	RemoveItem(&user);
}
Пример #22
0
	void Execute(IRCServer *server, User *u, const std::vector<std::string> &params)
	{
		const std::string &target = params.size() > 0 ? params[0] : "";
		bool operonly = params.size() > 1 && params[1] == "o";

		if (operonly)
			;
		else if (target.empty())
		{
			for (std::map<std::string, User *, Sinkhole::less_ci>::iterator it = server->Users.begin(), it_end = server->Users.end(); it != it_end; ++it)
			{
				User *user = it->second;
				
				if (this->CanShow(u, user))
					this->WriteWho(server, u, user, NULL);
			}
		}
		else if (target[0] == '#' || target[0] == '&')
		{
			Channel *c = server->FindChannel(target);
			if (c != NULL)
			{
				const std::set<User *> &users = c->GetUsers();
				for (std::set<User *>::const_iterator it = users.begin(), it_end = users.end(); it != it_end; ++it)
				{
					User *user = *it;

					if (this->CanShow(u, user))
						this->WriteWho(server, u, user, c);
				}
			}
		}
		else
		{
			User *user = server->FindUser(target);
			if (user != NULL)
			{
				if (this->CanShow(u, user))
					this->WriteWho(server, u, user, NULL);
			}
			else
				for (std::map<std::string, User *, Sinkhole::less_ci>::iterator it = server->Users.begin(), it_end = server->Users.end(); it != it_end; ++it)
				{
					user = it->second;

					if (Sinkhole::match(user->GetNick(), target))
						if (this->CanShow(u, user))
							this->WriteWho(server, u, user, NULL);
				}
		}

		u->WriteNumeric(315, (!target.empty() ? target : "*") + " :End of /WHO list.");
	}
Пример #23
0
void ChatPanel::Joined( User& who )
{
	if ( m_type == CPT_Channel ) {
		if ( sett().GetDisplayJoinLeave( m_channel->GetName() ) ) {
      // change the image of the tab to show new events
      SetIconHighlight( highlight_join_leave );
      OutputLine( _T( " ** " ) + who.GetNick() + _( " joined the " ) + GetChatTypeStr() + _T( "." ), sett().GetChatColorJoinPart(), sett().GetChatFont() );
    }
	} else if ( m_type == CPT_Battle ) {
		if ( sett().GetDisplayJoinLeave( _T( "game/battle" ) ) ) { OutputLine( _T( " ** " ) + who.GetNick() + _( " joined the " ) + GetChatTypeStr() + _T( "." ), sett().GetChatColorJoinPart(), sett().GetChatFont() ); }
	}
	if ( m_show_nick_list && ( m_nicklist != 0 ) )
	{
		unsigned int numusers = 0;
		if ( m_type == CPT_Channel ) numusers = GetChannel()->GetNumUsers();
		else if ( m_type == CPT_Server && m_server ) numusers = m_server->GetNumUsers();
		m_usercount_label->SetLabel( wxString::Format( _("%d users"), numusers ) );
		m_nicklist->AddUser( who );
	}
	// Also add the User to the TextCompletionDatabase
	textcompletiondatabase.Insert_Mapping( who.GetNick(), who.GetNick() );
}
Пример #24
0
void MainChatTab::OnUserConnected( User& user )
{
	ChatPanel* panel = GetUserChatPanel( user.GetNick() );
	if ( panel != 0 )
	{
		panel->SetUser( &user );
		panel->OnUserConnected();
		//TODO enable send button (koshi)
	}
	if ( m_server_chat != 0 )
	{
		m_server_chat->OnChannelJoin( user );
	}
}
Пример #25
0
void MainChatTab::OnUserDisconnected( User& user )
{
	ChatPanel* panel = GetUserChatPanel( user.GetNick() );
	if ( panel != 0 )
	{
		panel->OnUserDisconnected();
		panel->SetUser( 0 );
		//TODO disable send button (koshi)
	}
	if ( m_server_chat != 0 )
	{
		m_server_chat->Parted( user, _T("") );
	}
}
Пример #26
0
///< quick hotfix for bans
/// returns true if user is banned (and hence has been kicked)
bool Battle::CheckBan(User &user)
{
    if (IsFounderMe())
    {
        if (m_banned_users.count(user.GetNick())>0
                || useractions().DoActionOnUser(UserActions::ActAutokick, user.GetNick() ) )
        {
            KickPlayer(user);
			UiEvents::GetUiEventSender( UiEvents::OnBattleActionEvent ).SendEvent(
					UiEvents::OnBattleActionData( wxString(_T(" ")) , user.GetNick()+_T(" is banned, kicking") )
				);
            return true;
        }
        else if (m_banned_ips.count(user.BattleStatus().ip)>0)
        {
			UiEvents::GetUiEventSender( UiEvents::OnBattleActionEvent ).SendEvent(
					UiEvents::OnBattleActionData( wxString(_T(" ")) , user.BattleStatus().ip+_T(" is banned, kicking") )
				);
            KickPlayer(user);
            return true;
        }
    }
    return false;
}
Пример #27
0
void AutoHost::OnUserRemoved( User& user )
{
    if ( m_userlist.Index( user.GetNick() ) != wxNOT_FOUND )//triggers assertion in arraystring otherwise
        m_userlist.Remove( user.GetNick() );
	// do nothing if autohost functionality is disabled
	if ( !m_enabled )
		return;

	if ( m_battle.GetNumUsers() == 1 && m_battle.IsLocked() )
	{
		m_battle.SetIsLocked( false );
		m_battle.DoAction( _T( "has auto-unlocked the battle." ) );
		m_battle.SendHostInfo( IBattle::HI_Locked );
	}
}
Пример #28
0
ChatPanel::ChatPanel( wxWindow* parent, const User& user, wxImageList* imaglist  ):
  wxPanel( parent, -1 ),
  m_show_nick_list( false ),
  m_nicklist(0),
  m_chat_tabs(( SLNotebook* )parent ),
  m_channel( 0 ),
  m_server( 0 ),
  m_user( &user ),
  m_battle( 0 ),
  m_type( CPT_User ),
  m_popup_menu( 0 ),
  m_chat_log(sett().GetDefaultServer(), user.GetNick()),
  m_icon_index( 3 ),
  m_imagelist( imaglist ),
  m_disable_append( false ),
  m_topic_set( false )
{
  GetAui().manager->AddPane( this, wxLEFT, _T("chatpanel-pm-") + user.GetNick() );
	CreateControls( );
	LoadLastLines();
	m_chatlog_text->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( ChatPanel::OnMouseDown ), 0, this );
	user.uidata.panel = this;

}
Пример #29
0
void SimpleServerEvents::AutoCheckCommandSpam( Battle& battle, User& user )
{
    wxString nick = user.GetNick();
    MessageSpamCheck info = m_spam_check[nick];
    time_t now = time( 0 );
    if ( info.lastmessage == now ) info.count++;
    else info.count = 0;
    info.lastmessage = now;
    m_spam_check[nick] = info;
    if ( info.count == 7 )
    {
			battle.DoAction( _T("is autokicking ") + nick + _T(" due to command spam.") );
			battle.KickPlayer( user );
    }
}
Пример #30
0
void BattleRoomTab::OnUserJoined( User& user )
{
	if ( !m_battle ) return;
	if ( !user.BattleStatus().IsBot() ) m_chat->Joined( user );
	m_players->AddUser( user );

	UpdateUser(user);

	if ( &user == &m_battle->GetMe() )
	{
		m_players->SetSelectedIndex ( m_players->GetIndexFromData( &user ) );
	}
	UpdateStatsLabels();

	UiEvents::GetStatusEventSender( UiEvents::addStatusMessage ).SendEvent(
			UiEvents::StatusData( wxString::Format(_("%s joined your active battle"), user.GetNick().c_str()), 1 ) );
}