void CIrcWnd::NoticeMessage( CString source, CString message ) { bool flag = false; Channel* curr_channel = m_channelselect.FindChannelByName( source ); if( curr_channel ) { AddInfoMessage( source, _T("-%s- %s"), source, message); flag = true; } POSITION pos1, pos2; for (pos1 = m_channelselect.channelPtrList.GetHeadPosition();( pos2 = pos1 ) != NULL;) { m_channelselect.channelPtrList.GetNext(pos1); curr_channel = (Channel*)(m_channelselect.channelPtrList).GetAt(pos2); Nick* curr_nick = m_nicklist.FindNickByName(curr_channel->name, source ); if( curr_nick) { AddInfoMessage( curr_channel->name, _T("-%s- %s"), source, message); flag = true; } } if( flag == false ) { if( m_channelselect.m_pCurrentChannel->type == 4 ) AddInfoMessage( m_channelselect.m_pCurrentChannel->name, _T("-%s- %s"), source, message); else AddStatus( _T("-%s- %s"), source, message ); } }
void CIrcWnd::AddInfoMessage(const CString& sChannelName, CString sLine, bool bShowChannel) { if (sChannelName.IsEmpty()) return; sLine += _T("\r\n"); Channel* pUpdateChannel = m_wndChanSel.FindChannelByName(sChannelName); if (!pUpdateChannel) { if (sChannelName.GetLength() >= 1 && sChannelName[0] == _T('#')) pUpdateChannel = m_wndChanSel.NewChannel(sChannelName, Channel::ctNormal); else if (sChannelName == thePrefs.GetIRCNick()) { // A 'Notice' message for myself - display in current channel window pUpdateChannel = m_wndChanSel.m_pCurrentChannel; if (pUpdateChannel && pUpdateChannel->m_eType == Channel::ctChannelList) pUpdateChannel = NULL; // channels list window -> open a new channel window } if (!pUpdateChannel) pUpdateChannel = m_wndChanSel.NewChannel(sChannelName, Channel::ctPrivate); } if (bShowChannel) m_wndChanSel.SelectChannel(pUpdateChannel); AddInfoMessage(pUpdateChannel, sLine); }
void CPocketSMDlg::AddToLastMessage(CString s) { if(size == 0) { AddInfoMessage(s); return; } msgList[(last+MSG_LIST_SIZE-1)%MSG_LIST_SIZE] += s; }
void CIrcWnd::AddInfoMessageF(const CString& sChannelName, CString sLine, ...) { if (sChannelName.IsEmpty()) return; va_list argptr; va_start(argptr, sLine); CString sTemp; sTemp.FormatV(sLine, argptr); va_end(argptr); AddInfoMessage(sChannelName, sTemp); }
void CChat::AddInfoMessage( const char * szInfo, ... ) { // Get the arguments char szBuffer[ MAX_MESSAGE_LEN ]; va_list args; va_start( args, szInfo ); vsnprintf( szBuffer, MAX_MESSAGE_LEN, szInfo, args ); va_end( args ); // Get the arguments AddInfoMessage( CColor( 24, 116, 205, 255 ), szBuffer ); }
/** * display SETUP dialog */ void CPocketSMDlg::OnButtonSetup() { int i; CString strBuf; // TODO: Add your control notification handler code here // m_TrayIcon.MinimiseToTray(this); if(m_dlgSetup->DoModal() == IDOK) { UpdateWindow(); if(m_bSetupOK) SendSIPRegister("0", 2); m_nFlag = 1; if(m_dlgSetup->getUserName().GetLength() > 0 && m_dlgSetup->getUserName().Find('@') > 0 && m_dlgSetup->getUserName().Find(':') < 0) { m_strUserName = m_dlgSetup->getUserName(); i = m_strUserName.Find('@'); if (i!=-1) { m_strUserPart = m_strUserName.Left(i); m_strSrvPart = m_strUserName.Right(m_strUserName.GetLength() - i - 1); } } else { AfxMessageBox(_T("SIP User ID is invalid.\r\nMust be like:\r\n\"[email protected]\"")); return; } if(m_dlgSetup->getPassword().GetLength() > 0) m_strPassword = m_dlgSetup->getPassword(); if(m_dlgSetup->getServerAddress().GetLength() > 0) m_strSipSrvAddress = m_dlgSetup->getServerAddress(); else m_strSipSrvAddress = m_strSrvPart; if(m_dlgSetup->getServerPort() > 0) m_nSipSrvPort = m_dlgSetup->getServerPort(); strBuf.Format(_T("<%s> registering ...\r\n outbound proxy:\r\n <%s:%d>\r\n"), m_strUserName, m_strSipSrvAddress, m_nSipSrvPort); AddInfoMessage(strBuf); UpdateDisplayedMessage(); if(SendSIPRegister("3600", 10) != 0) AddToLastMessage("Not registered. Please try again.\r\n"); else AddToLastMessage("Registered.\r\n"); UpdateDisplayedMessage(); } }
void CIrcWnd::AddStatus(CString sLine, bool bShowActivity, UINT uStatusCode) { Channel* pStatusChannel = m_wndChanSel.m_lstChannels.GetHead(); if (!pStatusChannel) return; sLine += _T("\r\n"); // This allows for us to add blank lines to the status.. if (sLine == _T("\r\n")) pStatusChannel->m_wndLog.AppendText(sLine); else if (sLine.GetLength() >= 1 && sLine[0] == _T('*')) { if (thePrefs.GetIRCAddTimeStamp()) AddColorLine(s_szTimeStampColorPrefix + CTime::GetCurrentTime().Format(TIME_STAMP_FORMAT), pStatusChannel->m_wndLog); AddColorLine(sLine, pStatusChannel->m_wndLog, STATUS_MSG_COLOR); } else if (uStatusCode >= 400) { if (thePrefs.GetIRCAddTimeStamp()) AddColorLine(s_szTimeStampColorPrefix + CTime::GetCurrentTime().Format(TIME_STAMP_FORMAT), pStatusChannel->m_wndLog); if (!(sLine.GetLength() >= 1 && sLine[0] == _T('-'))) sLine = _T("-Error- ") + sLine; AddColorLine(sLine, pStatusChannel->m_wndLog, INFO_MSG_COLOR); } else { if (thePrefs.GetIRCAddTimeStamp()) AddColorLine(s_szTimeStampColorPrefix + CTime::GetCurrentTime().Format(TIME_STAMP_FORMAT), pStatusChannel->m_wndLog); AddColorLine(sLine, pStatusChannel->m_wndLog); } if (m_wndChanSel.m_pCurrentChannel == pStatusChannel) return; if (bShowActivity) m_wndChanSel.SetActivity(pStatusChannel, true); if (uStatusCode >= 400) { if (!(sLine.GetLength() >= 1 && sLine[0] == _T('-'))) sLine = _T("-Error- ") + sLine; AddInfoMessage(m_wndChanSel.m_pCurrentChannel, sLine); } }
void CIrcWnd::ParseChangeMode( CString channel, CString changer, CString commands, CString params ) { try { if( commands.GetLength() == 2 ) { //Single mode change.. if(m_nicklist.m_sUserModeSettings.Find(commands[1]) != -1 ) { //This is a user mode change! m_nicklist.ChangeNickMode( channel, params, commands ); } if(m_channelselect.m_sChannelModeSettingsTypeA.Find(commands[1]) != -1 ) { //We do not use these messages yet.. But we can display them for the user to see //These modes always have a param and will add or remove a user from some type of list. m_channelselect.ChangeChanMode( channel, params, commands ); } if(m_channelselect.m_sChannelModeSettingsTypeB.Find(commands[1]) != -1 ) { //We do not use these messages yet.. But we can display them for the user to see //These modes will always have a param.. m_channelselect.ChangeChanMode( channel, params, commands ); } if(m_channelselect.m_sChannelModeSettingsTypeC.Find(commands[1]) != -1 ) { //We do not use these messages yet.. But we can display them for the user to see //These modes will only have a param if your setting it! m_channelselect.ChangeChanMode( channel, params, commands ); } if(m_channelselect.m_sChannelModeSettingsTypeD.Find(commands[1]) != -1 ) { //We do not use these messages yet.. But we can display them for the user to see //These modes will never have a param for it! m_channelselect.ChangeChanMode( channel, params, commands ); } if( !thePrefs.GetIrcIgnoreMiscMessage() ) AddInfoMessage( channel, GetResString(IDS_IRC_SETSMODE), changer, commands, params); return; } else if ( commands.GetLength() > 2 ) { //Multiple mode changes.. CString dir; dir = commands[0]; if( dir == _T("+") || dir == _T("-")) { //The mode must be either adding (+) or removing (-) int currModeIndex = 1; int currNameIndex = 0; int currNameBackIndex = params.Find( _T(" "), currNameIndex); CString currName = _T(""); while( currModeIndex < commands.GetLength()) { //There is another mode to process.. if(m_nicklist.m_sUserModeSettings.Find(commands[1]) != -1 ) { //This is a user mode change and must have a param! if( currNameBackIndex > currNameIndex ) { //There's a valid name to this mode change.. currName = params.Mid(currNameIndex, currNameBackIndex-currNameIndex); currNameIndex = currNameBackIndex +1; } else { //This should not happen! ASSERT(0); } m_nicklist.ChangeNickMode( channel, currName, dir + commands[currModeIndex]); //Move to the next param. currNameBackIndex = params.Find(_T(" "), currNameIndex+1); if( currNameBackIndex == -1) currNameBackIndex = params.GetLength(); } if(m_channelselect.m_sChannelModeSettingsTypeA.Find(commands[currModeIndex]) != -1) { //We do not use these messages yet.. But we can display them for the user to see //These modes always have a param and will add or remove a user from some type of list. if( currNameBackIndex > currNameIndex ) { //There's a valid name to this mode change.. currName = params.Mid(currNameIndex, currNameBackIndex-currNameIndex); currNameIndex = currNameBackIndex +1; } else { //This should not happen! ASSERT(0); } m_channelselect.ChangeChanMode( channel, currName, dir + commands[currModeIndex]); //Move to the next param. currNameBackIndex = params.Find(_T(" "), currNameIndex+1); if( currNameBackIndex == -1) currNameBackIndex = params.GetLength(); } if(m_channelselect.m_sChannelModeSettingsTypeB.Find(commands[currModeIndex]) != -1) { //We do not use these messages yet.. But we can display them for the user to see //These modes will always have a param.. if( currNameBackIndex > currNameIndex ) { //There's a valid name to this mode change.. currName = params.Mid(currNameIndex, currNameBackIndex-currNameIndex); currNameIndex = currNameBackIndex +1; } else { //This should not happen! ASSERT(0); } m_channelselect.ChangeChanMode( channel, currName, dir + commands[currModeIndex]); //Move to the next param. currNameBackIndex = params.Find(_T(" "), currNameIndex+1); if( currNameBackIndex == -1) currNameBackIndex = params.GetLength(); } if(m_channelselect.m_sChannelModeSettingsTypeC.Find(commands[currModeIndex]) != -1 ) { //We do not use these messages yet.. But we can display them for the user to see //These modes will only have a param if your setting it! if( dir == _T("+") ) { //We are setting a mode, find param if( currNameBackIndex > currNameIndex ) { //There's a valid name to this mode change.. currName = params.Mid(currNameIndex, currNameBackIndex-currNameIndex); currNameIndex = currNameBackIndex +1; } else { //This should not happen! ASSERT(0); } } else { //We are removing a mode, no params currName = _T(""); } m_channelselect.ChangeChanMode( channel, currName, dir + commands[currModeIndex]); if( dir == _T("+") ) { //Set this mode, so move to the next param. currNameBackIndex = params.Find(_T(" "), currNameIndex+1); if( currNameBackIndex == -1) currNameBackIndex = params.GetLength(); } } if(m_channelselect.m_sChannelModeSettingsTypeD.Find(commands[currModeIndex]) != -1 ) { //We do not use these messages yet.. But we can display them for the user to see //These modes will never have a param for it! currName = _T(""); m_channelselect.ChangeChanMode( channel, currName, dir + commands[currModeIndex]); } currModeIndex++; } if( !thePrefs.GetIrcIgnoreMiscMessage() ) AddInfoMessage( channel, GetResString(IDS_IRC_SETSMODE), changer, commands, params); } } } catch(...) { AddInfoMessage( channel, GetResString(IDS_IRC_NOTSUPPORTED)); ASSERT(0); } }
void CChat::ProcessInput( void ) { // Are we not connected? if( !pCore->GetNetworkModule() || !pCore->GetNetworkModule()->IsConnected() ) return; // Was anything entered? if( m_strInput.GetLength() > 0 ) { // Is the input a command? bool bIsCommand = (m_strInput.GetChar( 0 ) == CHAT_CMD_CHAR); // Internal cmds bool bHasUsedCmd = false; // Process internal commands if( bIsCommand ) { // std::string sInput = m_strInput.Get(); // Get the end of the command size_t sCommandEnd = sInput.find( " " ); // If we don't have a valid end use the end of the string if ( sCommandEnd == std::string::npos ) sCommandEnd = sInput.length(); // Get the command name std::string strCommand = sInput.substr( 1, (sCommandEnd - 1) ); // Get the command parameters std::string strParams; // Do we have any parameters? if( sCommandEnd < sInput.length() ) strParams = sInput.substr( (sCommandEnd + 1), sInput.length() ); if( strCommand == "q" || strCommand == "quit" || strCommand == "exit" ) { // Shutdown pCore->Shutdown(); return; } else if( strCommand == "disconnect" ) { // Are we connected? if( pCore->GetNetworkModule() && pCore->GetNetworkModule()->IsConnected() ) { // Disconnect from the network pCore->GetNetworkModule()->Disconnect(); // Stop multiplayer pCore->StopMultiplayer(); // Go back to main menu pCore->GetGUI()->GetMainMenu()->SetVisible( true ); } bHasUsedCmd = true; } else if( strCommand == "savepos" ) { bHasUsedCmd = true; // Are we spawned? if( pCore->GetPlayerManager()->GetLocalPlayer()->IsSpawned() ) { // CVector3 vecPosition; CVector3 vecRotation; bool bOnFoot = true; // Is the player on-foot? if( pCore->GetPlayerManager()->GetLocalPlayer()->GetState() == ePlayerState::PLAYERSTATE_ONFOOT ) { // Get the localplayer position pCore->GetPlayerManager()->GetLocalPlayer()->GetPosition( &vecPosition ); // Get the localplayer rotation pCore->GetPlayerManager()->GetLocalPlayer()->GetRotation( &vecRotation ); } else if( pCore->GetPlayerManager()->GetLocalPlayer()->GetState() == ePlayerState::PLAYERSTATE_DRIVER || pCore->GetPlayerManager()->GetLocalPlayer()->GetState() == ePlayerState::PLAYERSTATE_PASSENGER ) { // Get the vehicle position pCore->GetPlayerManager()->GetLocalPlayer()->GetVehicle()->GetPosition( &vecPosition ); // Get the vehicle rotation pCore->GetPlayerManager()->GetLocalPlayer()->GetVehicle()->GetRotation( &vecRotation ); // bOnFoot = false; } // Open the saved positions file FILE * pFile = fopen( SharedUtility::GetAbsolutePath( "data\\savedpositions.txt" ).Get(), "a" ); // Did the file open? if( pFile ) { // Get the localplayer pointer CLocalPlayer * pLocalPlayer = pCore->GetPlayerManager()->GetLocalPlayer(); // Save the player position fprintf( pFile, "%d, %f, %f, %f, %f, %f, %f // %s\n", (bOnFoot ? pLocalPlayer->GetModel () : pLocalPlayer->GetVehicle()->GetModel ()), vecPosition.fX, vecPosition.fY, vecPosition.fZ, vecRotation.fX, vecRotation.fY, vecRotation.fZ, strParams.c_str() ); // Close the saved positions file fclose( pFile ); // AddInfoMessage( (bOnFoot ? " -> Onfoot position saved!" : " -> Invehicle position saved!") ); } else { // AddInfoMessage( CColor( 255, 0, 0, 255 ), "Failed to open savedpositions.txt" ); } } } #ifdef DEBUG else if( strCommand == "lua" ) { bHasUsedCmd = true; if( CLua::Execute( strParams.c_str() ) ) AddInfoMessage( CColor( 50, 177, 94, 255 ), strParams.c_str() ); else AddInfoMessage( CColor( 178, 40, 86, 255 ), strParams.c_str() ); } #endif } // Have we used a command? if( bHasUsedCmd ) { // Add this command to the history AddToHistory(); // This is an internal command, don't pass it to the server! return; } // Is the network module instance valid? if( pCore->GetNetworkModule() ) { // Are we connected? if( pCore->GetNetworkModule()->IsConnected() ) { RakNet::BitStream bitStream; RakNet::RakString strInput; // Is this a command? if( bIsCommand ) { // Write 1 bitStream.Write1(); // Set the input minus the command character strInput = (GetInputText() + 1); } else { // Write 0 bitStream.Write0(); // Set the input strInput = GetInputText(); } // Write the input bitStream.Write( strInput ); // Call the client event CSquirrelArguments pArguments; pArguments.push( strInput.C_String () ); // Should we send this message? if ( pCore->GetClientScriptingManager()->GetEvents()->Call( "onClientChat", &pArguments ).GetInteger() == 1 ) { // Send it to the server pCore->GetNetworkModule()->Call( RPC_PLAYER_CHAT, &bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, true ); // Add this message to the history AddToHistory(); // Add the chat message for the localplayer if it's not a command if ( !bIsCommand ) AddChatMessage( pCore->GetPlayerManager()->GetLocalPlayer(), GetInputText() ); } } } } }
/** * timer handler */ void CPocketSMDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default CString servAddress; int nrBytes=1, nBufLen = 2047; UINT servPort; char pBuf[2048], oBuf[1024], c, c1; str from, body, res; CTime crtTime; if(nIDEvent == ID_TIMER_A && m_bSetupOK) { m_nCounter++; if(m_nCounter > 3000) { m_nCounter = 0; if(SendSIPRegister("3600", 10) != 0) { AddInfoMessage("Can not register again. Please restart\r\n"); UpdateDisplayedMessage(); } } res.s = oBuf; res.len = 1024; // check for MESSAGE messages nrBytes = m_pCSock->ReceiveFrom((void*)pBuf, nBufLen, servAddress, servPort); while(nrBytes > 7 && (strncmp(pBuf, "MESSAGE", 7) == 0)) { crtTime = CTime::GetCurrentTime(); pBuf[nrBytes] = 0; if(!m_sipMsg.isIdentic(pBuf, nrBytes)) { m_sipMsg.setSIPMsg(pBuf, nrBytes); if(!m_bTrayIcon && m_bDlgHide) { m_bTrayIcon = true; SetNewTrayIcon(); } if(m_sipMsg.getFrom(&from) == 0 && m_sipMsg.getBody(&body) == 0) { // build response m_sipMsg.buildResponse(&res, "SIP/2.0 200 OK\r\n", m_strIPAddress, m_nIPPort); // send response m_pCSock->SendTo(res.s, res.len, m_nSipSrvPort, (LPCTSTR)m_strSipSrvAddress); // display to user c = from.s[from.len]; from.s[from.len] = 0; c1 = body.s[body.len]; body.s[body.len] = 0; AddRecvMessage(from.s, body.s, crtTime); from.s[from.len] = c; body.s[body.len] = c1; UpdateDisplayedMessage(); PlaySound(TEXT("DOORBELL"), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC); //PlaySound (TEXT("bell.wav"), NULL, SND_SYNC); } else { // build response m_sipMsg.buildResponse(&res, "SIP/2.0 400 Bad request\r\n", m_strIPAddress, m_nIPPort); // send response m_pCSock->SendTo(res.s, res.len, m_nSipSrvPort, (LPCTSTR)m_strSipSrvAddress); // display to user AddInfoMessage("Wrong formatted MESSAGE received"); UpdateDisplayedMessage(); } } /*** else { m_strEditView = "Non MESSAGE received"; UpdateData(FALSE); } ***/ nrBytes = m_pCSock->ReceiveFrom((void*)pBuf, nBufLen, servAddress, servPort); } } else if(!m_bSetupOK) { //AddInfoMessage("Config params are not set!\r\nClick on 'Setup' to set them"); //UpdateDisplayedMessage(); } CDialog::OnTimer(nIDEvent); }
void CIrcWnd::ParseChangeMode(const CString& sChannel, const CString& sChanger, CString sCommands, const CString& sParams) { CString sCommandsOrig = sCommands; CString sParamsOrig = sParams; try { if( sCommands.GetLength() >= 2 ) { CString sDir; int iParamIndex = 0; while( !sCommands.IsEmpty() ) { if (sCommands[0] == _T('+') || sCommands[0] == _T('-')) { sDir = sCommands.Left(1); sCommands = sCommands.Right(sCommands.GetLength()-1); } if( !sCommands.IsEmpty() && !sDir.IsEmpty() ) { CString sCommand = sCommands.Left(1); sCommands = sCommands.Right(sCommands.GetLength()-1); if(m_wndNicks.m_sUserModeSettings.Find(sCommand) != -1 ) { //This is a user mode change and must have a param! CString sParam = sParams.Tokenize(_T(" "), iParamIndex); m_wndNicks.ChangeNickMode( sChannel, sParam, sDir + sCommand); } if(m_wndChanSel.m_sChannelModeSettingsTypeA.Find(sCommand) != -1) { //We do not use these messages yet.. But we can display them for the user to see //These modes always have a param and will add or remove a user from some type of list. CString sParam = sParams.Tokenize(_T(" "), iParamIndex); m_wndChanSel.ChangeChanMode( sChannel, sParam, sDir, sCommand); } if(m_wndChanSel.m_sChannelModeSettingsTypeB.Find(sCommand) != -1) { //We do not use these messages yet.. But we can display them for the user to see //These modes will always have a param.. CString sParam = sParams.Tokenize(_T(" "), iParamIndex); m_wndChanSel.ChangeChanMode( sChannel, sParam, sDir, sCommand); } if(m_wndChanSel.m_sChannelModeSettingsTypeC.Find(sCommand) != -1 ) { //We do not use these messages yet.. But we can display them for the user to see //These modes will only have a param if your setting it! CString sParam; if (sDir == _T("+")) sParam = sParams.Tokenize(_T(" "), iParamIndex); m_wndChanSel.ChangeChanMode( sChannel, sParam, sDir, sCommand); } if(m_wndChanSel.m_sChannelModeSettingsTypeD.Find(sCommand) != -1 ) { //We do not use these messages yet.. But we can display them for the user to see //These modes will never have a param for it! CString sParam; m_wndChanSel.ChangeChanMode( sChannel, sParam, sDir, sCommand); } } } if (!thePrefs.GetIRCIgnoreMiscMessages()) AddInfoMessageF(sChannel, GetResString(IDS_IRC_SETSMODE), sChanger, sCommandsOrig, sParamsOrig); } } catch(...) { AddInfoMessage(sChannel, GetResString(IDS_IRC_NOTSUPPORTED)); ASSERT(0); } }