コード例 #1
0
DWORD IRCMsgThread::Run() {
	onSysMsg(L"IRCMsgThread Start");
	iStatus=IRC_NORMAL;
	IRCMsgQueue.clear();
	unsigned int bufferlen;
	std::string recvstring,msg,umsg; //TwitchIRC use MultiByte
	while(!bKillThread ) { 	
		//Receive First
		bufferlen=0;		
		memset(buffer, 0, DEFAULT_BUFLEN);
		if(TheSocketPtr->recv_data((char*)buffer, bufferlen)) { //Disconnected
			iStatus=IRC_DISCONNECTED;
			break;
		}
		recvstring=std::string(buffer,bufferlen);
		//onDebugMsg(L"%ls",from_utf8(recvstring).c_str());
		if(recvstring.compare(":tmi.twitch.tv NOTICE * :Login unsuccessful\r\n")==0 || //Twitch
		   recvstring.compare(":tmi.twitch.tv NOTICE * :Error encountered while attempting login\r\n")==0 ){ //Justin
			Sleep(100); //Wait for logging
			onSysMsg(L"Login unsuccessful");
			iStatus=IRC_WRONGLOGIN;
			break;
		}//else if(recvstring.compare(":[email protected] PRIVMSG #append :break\r\n")==0){TheSocketPtr->CloseSocket();}
		//Basic parsing: make it into a string, check for PING, if not-send for further parsing.
		std::stringstream recvstr(recvstring);
		while( recvstr.tellg() < bufferlen ) {
			std::getline(recvstr,msg,'\n');
			//Old Style
			//:[email protected] PRIVMSG #ptken :what song is this ?
			//PING LAG1967655232
			//int colon_pos = (int)msg.find(":");
			//if (msg[0] != ':' && colon_pos > 0) msg=msg.substr(colon_pos); //if an irc message begins with " ", then trim the leading spaces   
			//
			//New Style
			// @color=#FF4500;display-name=Gm470520;emotes=;mod=0;room-id=47281189;subscriber=1;turbo=0;user-id=24255667;user-type= :[email protected] PRIVMSG #tetristhegrandmaster3 :這片到底在沖三小w
			int at_pos = (int)msg.find("@");
			if (msg[0] != '@' && at_pos > 0) msg=msg.substr(at_pos); //if an irc message begins with " ", then trim the leading spaces   
			if (msg[msg.length()-1]=='\r') msg=msg.substr(0,msg.length()-1); //trim the CR: getline only trim the LF		                   
			log(from_utf8(msg), LogType(RECEIVE)); //Although log file is in UTF8....using vswprintf
			//Ping Check
			umsg=msg.substr(0,5);
			ToUpperString(umsg);
            if (!umsg.compare("PING ")) sendRaw( L"PONG " + from_utf8(msg.substr(5)) ); // respond to PINGs //Reply Immediately 
			//Then parse the message
            else parseMessage(from_utf8(msg)); 
		}
		Sleep(100);
	}
	//Determine the reason to break the loop.
	if(!bKillThread) {
		if(iStatus==IRC_DISCONNECTED) onSysMsg(L"IRCMsgThread: Disconnect Unexpectedly");
		if(iStatus==IRC_WRONGLOGIN) onSysMsg(L"IRCMsgThread: Wrong Login Information");
	}
	else iStatus=IRC_CLOSED;
	//onDebugMsg(L"[Last Buffer]%ls",from_utf8(recvstring).c_str());
	onSysMsg(L"IRCMsgThread Close");
	thread=0;
	return 0;
}
コード例 #2
0
ファイル: HandleUpdater.cpp プロジェクト: fU9ANg/hacks
void CHandleMessage::handleGetVersion (Buf* p)
{
    cout << "CT_Version" << endl;

    if (p == NULL)
        return;

    MSG_HEAD* head = (MSG_HEAD*) p->ptr ();
    head->cLen = sizeof (MSG_HEAD);
    head->cType = ST_GetVersion;

    version v;

    string recvstr ((char*) head->cData ());
    v.ParseFromString (recvstr);

    cout << v.ver() << endl;

    p->reset ();
    SINGLE->bufpool.free (p);
}