コード例 #1
0
ファイル: sIRC32.cpp プロジェクト: peekaye/Syllable-sIRC
void MainView::Update(void)
{
 			cout << "Updating textOutputView" << endl;	 					
// First we get the infomation taken from the IRC server and put into "buf" is added to the textOutputView
//	We then check the incoming data to see if it contains the PING command from the server.			
			int i;
			string bufstring;
			bufstring = buf;					
			i = bufstring.find("PING");
			cout << "Ping?\n" << endl;
			cout << i << endl;
			cout << bufstring << endl;
			if (i == -1) {
				cout << "No Ping" << endl;
				}
//	If it does we return the message "Pong nick\n", The Ping is sent from the server to check that 
//	we are still receiving messages
//	However due Ping being mentioned in the MOTD from freenode here is a dirty hack to get round this,
//	it only checks if the PING command is not equal to -1 (-1 is returned when Ping isn't mentioned)
//	and less then 80. (80 not 10 as it allows you to test the function by sending a PRIVMSG with Ping
//	embedded.					
			else if (i !=-1) {
				if (i < 80) {
					cout << "Yes Ping" << endl;
					sendmessage = "PONG " + nick + end;		
					messagetosend = 1;
					}
				else {
					cout << "No Ping" << endl;
					}
				}
//	Once the Ping command is done we now need to cut down the message to contain just the nick
//	of the sender and also the message itself.	Now this gets a little stuck with the MOTD from
//	the server so we only turn it on once we have joined a channel. (when erase = 1)
			if (erase ==1){
				string bufstring1;
				string bufstring2;						
				string bufstring3;							
				bufstring1 = buf;
				string find1 = "!";
				string::size_type pos = bufstring1.find (find1,0);
				string find2 = "#";									
				string::size_type pos1 = bufstring1.find (find2,0);
				int pos2, totallength;
				pos2 = pos1 - pos;				
				bufstring2 = bufstring1.erase (pos, pos2);	
				const char* bufchar;					
				bufchar = bufstring2.c_str();				
				textOutputView->Insert(bufchar, true);		
				}
			else {
				textOutputView->Insert(buf, true);	
				}
			if( m_CommThread )
			m_CommThread->PostMessage( MSG_TOLOOPER_START, m_CommThread, m_CommThread ); 											
		
}
コード例 #2
0
ファイル: sIRC32.cpp プロジェクト: peekaye/Syllable-sIRC
void MainView::SendMsg (void)
{
	textfrominput = textInputView->GetBuffer()[0].const_str();
	cout << "Text from input: " << textfrominput << endl;
	messagetosend = 1;		
	sendmessage = priv + channel + " :" + textfrominput + end;	
	Message *msg1 = new Message(MSG_TOLOOPER_START);
	Mail("Commthread", msg1);	
	string printinputmessage = nick + channel + " : " + textfrominput + end;	
	cout << printinputmessage << endl;	
	const char* msgupdate;
	msgupdate = printinputmessage.c_str();	
	textOutputView->Insert(msgupdate, true);
	textInputView->Clear(true);	
}