Beispiel #1
0
void ChatControlerFrame::OnFrameDestroy(wxCloseEvent &event) {
    //ChatPanel *chat(it->second);
    if (m_controler) {
        wxNotebook *panel = dynamic_cast<wxNotebook *>(*(GetChildren().begin()));
        if (panel)
            for(int i = panel->GetPageCount(); --i >= 0; ) {
                ChatPanel *chat = dynamic_cast<ChatPanel *>(panel->GetPage(i));
                if (chat)
                    m_controler->RemoveReference(chat->GetOtherJid());
            }
        m_controler->NullTabs();
    }
    //ChatPanel *panel = dynamic_cast<ChatPanel *>(*(GetChildren().begin()));
    //if (panel){
    //  PRU_LOG2("OnFrameDestroy", panel->GetOtherJid().Str());
    //  //good
    //  if (m_comtroler)
    //    m_controler->RemoveReference(panel->GetOtherJid());
    //} else{
    //  //bad
    //}
    //PRU_LOG2("OnFrameDestroy", others_jid.Str());
    /*if (m_controler)
      m_controler->RemoveReference(others_jid);*/
    event.Skip();
}
void MainChatTab::RejoinChannels()
{
	for ( unsigned int i = 0; i < m_chat_tabs->GetPageCount(); i++ )
	{
		ChatPanel* tmp = ( ChatPanel* )m_chat_tabs->GetPage( i );
		if ( tmp->GetPanelType() == CPT_Channel )
		{

			// TODO: This will not rejoin passworded channels.
			wxString name = m_chat_tabs->GetPageText( i );
			bool alreadyin = false;
			try
			{
				serverSelector().GetServer().GetChannel( name ).GetMe();
				alreadyin = true;
			}
			catch ( ... ) {}
			if ( !alreadyin )
			{
				serverSelector().GetServer().JoinChannel( name, _T( "" ) );
				tmp->SetChannel( &serverSelector().GetServer().GetChannel( name ) );
			}

		} else if ( tmp->GetPanelType() == CPT_User )
		{

			wxString name = m_chat_tabs->GetPageText( i );
			if ( serverSelector().GetServer().UserExists( name ) ) tmp->SetUser( &serverSelector().GetServer().GetUser( name ) );

		}
	}
}
Beispiel #3
0
//! @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();
}
void MainChatTab::BroadcastMessage( const wxString& message )
{
	// spam the message in all channels
	for ( unsigned int i = 0; i < m_chat_tabs->GetPageCount(); i++ )
	{
		ChatPanel* tmp = ( ChatPanel* )m_chat_tabs->GetPage( i );
		tmp->StatusMessage( message );
	}
}
Beispiel #5
0
IServer::~IServer()
{
    if (panel != nullptr) {
        ChatPanel* tmp = panel;
        panel = nullptr;
        tmp->SetServer(NULL);
    }
    Reset();
    delete battles_iter;
}
ChatPanel* MainChatTab::GetUserChatPanel( const wxString& user )
{
	for ( unsigned int i = 0; i < m_chat_tabs->GetPageCount(); i++ ) {
		ChatPanel* tmp = ( ChatPanel* )m_chat_tabs->GetPage( i );
		if ( tmp->GetPanelType() == CPT_User ) {
			wxString name = m_chat_tabs->GetPageText( i );
			if ( name.Lower() == user.Lower() ) return ( ChatPanel* )m_chat_tabs->GetPage( i );
		}
	}
	return 0;
}
Beispiel #7
0
ChatPanel *ChatControler::GetChatFor(buzz::Jid jid, bool create) {
    std::string bare(jid.BareJid().Str());
    ChatMap::iterator it = m_chat_map.find(bare);
    bool exists = (it != m_chat_map.end());

    if (exists) {
        //////////////////////////////
        // Tabs
        ChatPanel *chat(it->second);
        for(int i = m_tabs->GetPageCount(); --i >= 0; )
            if (chat == m_tabs->GetPage(i)) {
                // TODO: Set an image showing some kind of highlight
                //m_tabs->SetSelection(i);
                break;
            }
        m_tabs->Refresh();
        return chat;
        // Tabs
        //////////////////////////////
        //return it->second;
    } else if (create) {
        //////////////////////////////
        // Tabs
        if (!m_tabs) {
            //wxFrame *frame = new wxFrame(m_parent, wxID_ANY, StdToWx(bare));
            wxFrame *frame = new ChatControlerFrame(this, m_parent, wxID_ANY, StdToWx(bare));
            m_tabs = new wxNotebook(frame, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxCLIP_CHILDREN);
            m_tabs->PushEventHandler(g_mouse_event_fowarder_delayed);


            frame->SetIcon(wxIcon(wxT("imgs/icon/cim.png"), wxBITMAP_TYPE_PNG));
            frame->Show(true);
        }
        // Tabs
        //////////////////////////////


        ChatPanel *chat = new ChatPanel(m_tabs, jid);
        m_tabs->Connect(chat->GetId(), wxEVT_RIGHT_DOWN, wxMouseEventHandler(ChatControlerFrame::OnRightClick));

        // TODO: Set an image showing some kind of highlight
        m_tabs->AddPage(chat, StdToWx(bare));

        //Connect(chat->GetId(), wxEVT_CLOSE_WINDOW, wxCloseEventHandler(ChatControler::OnFrameDestroy));
        //chat->PushEventHandler(this);

        m_chat_map[bare] = chat;
        m_tabs->Refresh();
        return chat;
    } else {
        return NULL;
    }
}
void MainChatTab::OnTabClose( wxAuiNotebookEvent& event )
{
	int selection = event.GetSelection();
	ChatPanel* panel = ( ChatPanel* )m_chat_tabs->GetPage( selection );
	if ( panel )
	{
		panel->Part();
		if( panel->IsServerPanel() )
            m_server_chat = 0;
	}

}
void MainChatTab::UpdateNicklistHighlights()
{
	for ( unsigned int i = 0; i < m_chat_tabs->GetPageCount(); i++ ) {
		ChatPanel* tmp = ( ChatPanel* )m_chat_tabs->GetPage( i );
		if ( tmp->GetPanelType() == CPT_Channel ) {
			tmp->UpdateNicklistHighlights();
		}
	}
	if ( m_server_chat != 0 )
	{
		m_server_chat->UpdateNicklistHighlights();
	}
}
Beispiel #10
0
void GUI::Chat::OnChansClick(wxCommandEvent &e)
{
	GUI::ChatChannelsDialog *channels = new GUI::ChatChannelsDialog(this);
	
	if (channels->ShowModal() && !channels->channel.IsEmpty())
	{
		ChatPanel *p = new ChatPanel(this->tabs, -1, channels->channel);
		this->tabs->AddPage(p, wxT(channels->channel), true);
		p->DoJoin(this->info);

	}

	channels->Destroy();
}
Beispiel #11
0
void MainWindow::OnTabsChanged(wxAuiNotebookEvent& event)
{
	int newsel = event.GetSelection();

	if (newsel == 0 || newsel == 1) {
		if (!ui().IsConnected() && ui().IsMainWindowCreated())
			ui().Connect();
	}

	ChatPanel* panel = ui().GetActiveChatPanel(); //set input focus to edit field on tab change
	if (panel != NULL) {
		panel->SetFocus();
	}
}
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 );
	}
}
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("") );
	}
}
Beispiel #14
0
void ChatControlerFrame::OnRightClick(wxMouseEvent& event) {
    if (m_controler) {
        wxNotebook *tabs = m_controler->GetTabs();
        if (tabs) {
            int tab = tabs->HitTest(event.GetPosition());
            if (tab != wxNOT_FOUND) {
                ChatPanel *chat = dynamic_cast<ChatPanel *>(tabs->GetPage(tab));
                if (chat) {
                    m_controler->RemoveReference(chat->GetOtherJid());
                    tabs->DeletePage(tab);
                }
            }
        }
    }
}
ChatPanel* MainChatTab::AddChatPanel( const User& user )
{
	for ( unsigned int i = 0; i < m_chat_tabs->GetPageCount(); i++ ) {
		if ( m_chat_tabs->GetPageText( i ) == user.GetNick() ) {
			ChatPanel* tmp = ( ChatPanel* )m_chat_tabs->GetPage( i );
			if ( tmp->GetPanelType() == CPT_User ) {
				m_chat_tabs->SetSelection( i );
				tmp->SetUser( &user );
				return tmp;
			}
		}
	}
	int selection = m_chat_tabs->GetSelection();
	ChatPanel* chat = new ChatPanel( m_chat_tabs, user, m_imagelist );
	m_chat_tabs->InsertPage( m_chat_tabs->GetPageCount() - 1, chat, user.GetNick(), true, wxBitmap( userchat_xpm ) );
	if ( selection > 0 ) m_chat_tabs->SetSelection( selection );
	return chat;
}
Beispiel #16
0
void MainWindow::ShowTab(const unsigned int idx)
{
	if (idx < m_tab_names.GetCount()) {
		m_func_tabs->SetSelection(idx);
		switch (idx) {
			case PAGE_JOIN: {
				GetJoinTab().SetFocus();
				ChatPanel* p = GetJoinTab().GetActiveChatPanel();
				if (p != NULL) {
					p->FocusInputBox();
				}
				return;
			}
			default:
				break;
		};
	} else
		wxLogError(_T("tab selection oob: %d"), idx);
}
ChatPanel* MainChatTab::AddChatPanel( Server& server, const wxString& name )
{

	for ( unsigned int i = 0; i < m_chat_tabs->GetPageCount(); i++ ) {
		//if ( m_chat_tabs->GetPageText( i ) == name ) {
		if ( true ) { // wipe all old server tabs
			ChatPanel* tmp = ( ChatPanel* )m_chat_tabs->GetPage( i );
			if ( tmp->GetPanelType() == CPT_Server ) {
				m_chat_tabs->DeletePage( i );
				i--;
			}
		}
	}

	ChatPanel* chat = new ChatPanel( m_chat_tabs, server, m_imagelist );
	m_server_chat = chat;
	m_chat_tabs->InsertPage( m_chat_tabs->GetPageCount() - 1, chat, name, true, wxBitmap( server_xpm ) );
	return chat;
}
ChatPanel* MainChatTab::AddChatPanel( Channel& channel, bool doFocus )
{

	for ( unsigned int i = 0; i < m_chat_tabs->GetPageCount(); i++ ) {
		if ( m_chat_tabs->GetPageText( i ) == channel.GetName() ) {
			ChatPanel* tmp = ( ChatPanel* )m_chat_tabs->GetPage( i );
			if ( tmp->GetPanelType() == CPT_Channel ) {
				if ( doFocus )
					m_chat_tabs->SetSelection( i );
				tmp->SetChannel( &channel );
				return tmp;
			}
		}
	}

	ChatPanel* chat = new ChatPanel( m_chat_tabs, channel, m_imagelist );
	m_chat_tabs->InsertPage( m_chat_tabs->GetPageCount() - 1, chat, channel.GetName(), doFocus, wxBitmap( channel_xpm ) );
	if ( doFocus )
		chat->FocusInputBox();
	return chat;
}
void MainChatTab::LeaveChannels()
{
	for ( unsigned int i = 0; i < m_chat_tabs->GetPageCount(); i++ ) {
		ChatPanel* tmp = ( ChatPanel* )m_chat_tabs->GetPage( i );
		if ( tmp->GetPanelType() == CPT_Channel )
		{
			tmp->StatusMessage( _( "Disconnected from server, chat closed." ) );
			tmp->SetChannel( 0 );
		} else if ( tmp->GetPanelType() == CPT_User )
		{
			tmp->StatusMessage( _( "Disconnected from server, chat closed." ) );
			tmp->SetUser( 0 );
		}
	}
}
//=====================================================================================
bool Client::Run( void )
{
	if( !socket->Advance() )
		return false;

	Socket::Packet inPacket;
	if( socket->ReadPacket( inPacket ) )
	{
		switch( inPacket.GetType() )
		{
			case Socket::Packet::GAME_STATE:
			{
				if( !board || !board->SetGameState( inPacket ) )
					return false;
				boardStateReceived = true;
				TellUserWhosTurnItIs();
				break;
			}
			case Socket::Packet::GAME_MOVE:
			{
				wxInt32 sourceID, destinationID;
				if( board->UnpackMove( inPacket, sourceID, destinationID ) )
				{
					Board::MoveSequence moveSequence;
					if( !board->FindMoveSequence( sourceID, destinationID, moveSequence ) )
						return false;
					if( !board->ApplyMoveSequence( moveSequence, true ) )
						return false;
					TellUserWhosTurnItIs();	
				}
				break;
			}
			case Socket::Packet::SCORE_BONUS:
			{
				wxInt32 participant;
				wxInt64 scoreBonus;
				Board::UnpackScoreBonus( inPacket, participant, scoreBonus );

				board->ApplyScoreBonus( participant, scoreBonus );

				break;
			}
			case Socket::Packet::ASSIGN_COLOR:
			{
				wxInt32 data = *( wxInt32* )inPacket.GetData();
				if( inPacket.ByteSwap() )
					data = wxINT32_SWAP_ALWAYS( data );
				color = data;
				wxString textColor;
				Board::ParticipantText( color, textColor );
				wxGetApp().GetFrame()->SetTitle( "Chinese Checkers -- " + textColor );
				break;
			}
			case Socket::Packet::PARTICIPANTS:
			{
				if( board )
					return false;
				wxInt32 data = *( wxInt32* )inPacket.GetData();
				if( inPacket.ByteSwap() )
					data = wxINT32_SWAP_ALWAYS( data );
				int participants = data;
				board = new Board( participants, true );
				board->SetEventHandler( this );
				Bind( Board::BEGIN_BOARD_THINKING, &Client::OnBoardThinking, this );
				Bind( Board::UPDATE_BOARD_THINKING, &Client::OnBoardThinking, this );
				Bind( Board::END_BOARD_THINKING, &Client::OnBoardThinking, this );
				break;
			}
			case Socket::Packet::DROPPED_CLIENT:
			{
				wxInt32 color = *( wxInt32* )inPacket.GetData();
				if( inPacket.ByteSwap() )
					color = wxINT32_SWAP_ALWAYS( color );
				wxString textColor;
				Board::ParticipantText( color, textColor );
				wxString message = wxT( "The player for color " ) + textColor + wxT( " has been dropped by the server, probably due to connection failure.  The game will halt at this player's turn until another client joins the game." );
				wxMessageBox( message, wxT( "Dropped Client" ), wxOK | wxCENTRE, wxGetApp().GetFrame() );
				break;
			}
			case Socket::Packet::BEGIN_COMPUTER_THINKING:
			case Socket::Packet::UPDATE_COMPUTER_THINKING:
			case Socket::Packet::END_COMPUTER_THINKING:
			{
				UpdateThinkingStatus( inPacket );
				break;
			}
			case Socket::Packet::CHAT_MESSAGE:
			{
				int color;
				wxString message;
				if( ChatPanel::UnpackChatMessage( inPacket, message, color ) )
				{
					wxAuiPaneInfo* foundPaneInfo = nullptr;
					if( wxGetApp().GetFrame()->IsPanelInUse( "Chat Panel", &foundPaneInfo ) )
					{
						ChatPanel* chatPanel = ( ChatPanel* )foundPaneInfo->window;
						chatPanel->ReceiveChatMessage( message, color );
					}
				}
				break;
			}
		}
	}

	// If we're an computer participant, go run the AI logic.
	while( type == COMPUTER )
	{
		// There's nothing for us to do until the board is created, and we have to have a brain.
		if( !board || !brain || !boardStateReceived )
			break;

		// Wait until it's our turn.
		if( !board->IsParticipantsTurn( color ) )
		{
			movePacketSent = false;
			break;
		}

		// Wait for our turn to take affect if we've already taken it.
		if( movePacketSent )
			break;

		// Wait for all animations to settle before taking our turn.
		if( board->AnyPieceInMotion() )
			break;
			
		// If someone has just won the game, don't submit any moves; the game is over.
		if( board->DetermineWinner() != Board::NONE )
			break;
		
		// Okay, it's time to make our move.
		Board::Move move;
		if( !brain->FindGoodMoveForWhosTurnItIs( board, move ) )
		{
			wxString textColor;
			Board::ParticipantText( color, textColor );
			wxString message = wxT( "The computer player for color " ) + textColor + wxT( " is stumped and sadly can't continue the game." );
			wxMessageBox( message, wxT( "The Computer Is Stupid" ), wxOK | wxCENTRE, wxGetApp().GetFrame() );
			return false;
		}
		
		// Submit our move!
		Socket::Packet outPacket;
		Board::PackMove( outPacket, move.sourceID, move.destinationID );
		socket->WritePacket( outPacket );
		movePacketSent = true;
		break;
	}

	// Gather final points during animation before declaring the winner, if any.
	if( board && !board->AnyPieceInMotion() && !gameOver )
	{
		int winner = board->DetermineWinner();
		if( winner != Board::NONE )
		{
			gameOver = true;

			if( color != winner )
			{
				wxString winnerText;
				Board::ParticipantText( winner, winnerText );
				wxMessageBox( wxT( "Player " ) + winnerText + wxT( " wins!" ), wxT( "The game is over!" ), wxOK | wxCENTRE, wxGetApp().GetFrame() );
			}
			else if( type == COMPUTER || wxYES == wxMessageBox( wxT( "You won!  Would you like to record your score in the database?" ), wxT( "You win!" ), wxYES_NO | wxCENTRE, wxGetApp().GetFrame() ) )
			{
				Mongo::WinEntry winEntry;
				winEntry.dateOfWin.SetToCurrent();
				winEntry.turnCount = board->GetTurnCount( color );
				winEntry.opponentCount = board->GetOpponentCount( color );
				board->GetScore( color, winEntry.score );
				if( type == HUMAN )
					winEntry.winnerName = wxGetTextFromUser( "Please enter your name for the record.", "Name Entry", wxEmptyString, wxGetApp().GetFrame() );
				else
					winEntry.winnerName = "Chinese Checkers AI";

				Mongo* mongo = new Mongo();
				if( !mongo->Connect() || !mongo->InsertWinEntry( winEntry ) )
					wxMessageBox( wxT( "Database communication failed." ), wxT( "Error" ), wxICON_ERROR | wxCENTRE, wxGetApp().GetFrame() );
				delete mongo;
			}
		}
	}

	return true;
}