📄 ircclient.cpp
字号:
}
else if( strCommand == CString("366") )
{
}
else if( strCommand == CString("PRIVMSG") )
{
//someone send the message
//get the NickName from the strPrefix
//strPrefix == "cbkmis!mIRC@23.150.0.1"
//get the sender nick name
iEnd = strPrefix.Find(_T('!'));
if(iEnd != -1)
strWhoTalkToMe = strPrefix.Mid(0,iEnd);
else
strWhoTalkToMe = strPrefix;
/*iEnd = strPrefix.Find(_T('!'));
if(iEnd == -1)
{
strNickName = strPrefix;
}
strNickName = strPrefix.Mid(0,iEnd);
*/
//there are 2 case:
//1. is in the channel
//2. is someone send message to me
if( strParams[0] == '#' )
{
//1.the strParams format is: "#cbkmis :asdf"
iEnd = strParams.Find(_T(' '));
if(iEnd == -1)
{
//this is something wrong
return;
}
strChannel = strParams.Mid(0,iEnd);//??
//the words is:
strTem = strParams.Mid( iEnd+2,strParams.GetLength() );
//m_pView->m_ChannelRoom.m_strChannelMember = strChannel;
//m_pView->m_ChannelRoom.m_strContent = CString(_T("\r\n"))+strChannel;
#ifdef HF_DEBUG
m_pView->m_roomStatus.m_strContent += CString(_T("\r\n[#"));
m_pView->m_roomStatus.m_strContent += strChannel;
m_pView->m_roomStatus.m_strContent += CString("]");
m_pView->m_roomStatus.m_strContent += strTem;
m_pView->MyUpdateView();
#endif
//find the correspond room
CRoom* proomTem;
bTem = FALSE;
for(int i=0; i< m_pView->m_objlstRoomPtr.GetCount(); i++)
{
proomTem = (CRoom*) m_pView->m_objlstRoomPtr.GetAt(
m_pView->m_objlstRoomPtr.FindIndex(i) );
if(proomTem->m_iRoomType == HF_ROOM_TYPE_CHANNEL_PUBLIC &&
proomTem->m_strRoomName == strChannel )
{
//the room is already exist
proomTem->m_strContent += CString(_T("<"));
proomTem->m_strContent += strWhoTalkToMe;
proomTem->m_strContent += CString(_T(">"));
proomTem->m_strContent += strTem;
proomTem->m_strContent += CString(_T("\r\n"));
m_pView->MyUpdateView();
bTem = TRUE;
break;
}
}
if( bTem == FALSE)
{
//the room is not exist, and build one:
proomTem = new CRoom;
m_pView->m_objlstRoomPtr.AddHead( proomTem );
proomTem->m_iRoomType = HF_ROOM_TYPE_CHANNEL_PUBLIC;
proomTem->m_strRoomName = strChannel;
if(!m_pView->m_wndStatusBar.MySetIndicators())
{
TRACE0("Failed to set status bar indicators\n");
}
//write down the words
proomTem->m_strContent += CString(_T("<"));
proomTem->m_strContent += strWhoTalkToMe;
proomTem->m_strContent += CString(_T(">"));
proomTem->m_strContent += strTem;
proomTem->m_strContent += CString(_T("\r\n"));
m_pView->MyUpdateView();
}
}
else
{
//2.the strParams format is: "tempHF :asdf"
//<prefix> ::= <servername> | <nick> [ '!' <user> ] [ '@' <host> ]
/*/get the sender nick name
iEnd = strPrefix.Find(_T('!'));
if(iEnd != -1)
strWhoTalkToMe = strPrefix.Mid(0,iEnd);
else
strWhoTalkToMe = strPrefix;
*/
iEnd = strParams.Find(_T(' '));
if(iEnd == -1)
{
//this is something wrong
return;
}
strTem = strParams.Mid(1,iEnd);
//if(strTem == m_strMyNickName)
//the words is:
strTem = strParams.Mid( iEnd+2,strParams.GetLength() );
#ifdef HF_DEBUG
m_pView->m_roomStatus.m_strContent += CString(_T("\r\n<"));
m_pView->m_roomStatus.m_strContent += strWhoTalkToMe;
m_pView->m_roomStatus.m_strContent += CString(">");
m_pView->m_roomStatus.m_strContent += strTem;
m_pView->MyUpdateView();
#endif
//find the correspond room
CRoom* proomTem;
bTem = FALSE;
for(int i=0; i< m_pView->m_objlstRoomPtr.GetCount(); i++)
{
proomTem = (CRoom*) m_pView->m_objlstRoomPtr.GetAt(
m_pView->m_objlstRoomPtr.FindIndex(i) );
if(proomTem->m_iRoomType == HF_ROOM_TYPE_PRIVATE &&
proomTem->m_strRoomName == strWhoTalkToMe )
{
//the room is already exist
proomTem->m_strContent += CString(_T("<"));
proomTem->m_strContent += strWhoTalkToMe;
proomTem->m_strContent += CString(_T(">"));
proomTem->m_strContent += strTem;
proomTem->m_strContent += CString(_T("\r\n"));
m_pView->MyUpdateView();
bTem = TRUE;
break;
}
}
if( bTem == FALSE)
{
//the room is not exist, and build one:
proomTem = new CRoom;
m_pView->m_objlstRoomPtr.AddHead( proomTem );
proomTem->m_iRoomType = HF_ROOM_TYPE_PRIVATE;
proomTem->m_strRoomName = strWhoTalkToMe;
if(!m_pView->m_wndStatusBar.MySetIndicators())
{
TRACE0("Failed to set status bar indicators\n");
}
//write down the words
proomTem->m_strContent += CString(_T("<"));
proomTem->m_strContent += strWhoTalkToMe;
proomTem->m_strContent += CString(_T(">"));
proomTem->m_strContent += strTem;
proomTem->m_strContent += CString(_T("\r\n"));
m_pView->MyUpdateView();
}
}
//CString strHere;
//strHere = CString("<") + LPCTSTR(strPrefix) + CString(">") + strParams;
//m_pDoc->DisplayMsg( strHere );
}
else if( strCommand == CString("JOIN") )
{
//two case:
//1. I join one channel room the server ack
//2. Someone join the channel room , the server inform me
//get the sender nick name
iEnd = strPrefix.Find(_T('!'));
if(iEnd != -1)
strTem = strPrefix.Mid(0,iEnd);
else
strTem = strPrefix;
strParams = strParams.Mid(1,strParams.GetLength());
#ifdef HF_DEBUG
m_pView->m_roomStatus.m_strContent += CString(_T("\r\n***"));
m_pView->m_roomStatus.m_strContent += strPrefix;
m_pView->m_roomStatus.m_strContent += CString(" Has Joined the channel:");
m_pView->m_roomStatus.m_strContent += strParams;
m_pView->m_roomStatus.m_strContent += CString(_T("\r\n-"));
m_pView->MyUpdateView();
#endif
strParams.TrimRight();
strChannel = strParams;
if(strTem == m_strMyNickName)
{
//1. I join one channel room the server ack
//build one new Room:
//find the correspond room
CRoom* proomTem;
bTem = FALSE;
for(int i=0; i< m_pView->m_objlstRoomPtr.GetCount(); i++)
{
proomTem = (CRoom*) m_pView->m_objlstRoomPtr.GetAt(
m_pView->m_objlstRoomPtr.FindIndex(i) );
if(proomTem->m_iRoomType == HF_ROOM_TYPE_CHANNEL_PUBLIC &&
proomTem->m_strRoomName == strChannel )
{
//the room is already exist
bTem = TRUE;
break;
}
}
if( bTem == FALSE)
{
//the room is not exist, and build one:
proomTem = new CRoom;
m_pView->m_objlstRoomPtr.AddHead( proomTem );
proomTem->m_iRoomType = HF_ROOM_TYPE_CHANNEL_PUBLIC;
proomTem->m_strRoomName = strChannel;
if(!m_pView->m_wndStatusBar.MySetIndicators())
{
TRACE0("Failed to set status bar indicators\n");
}
}
}
else
{
//2. Someone join the channel room , the server inform me
//add the name to the channelMember
CRoom* proomTem;
//bTem = FALSE;
for(int i=0; i< m_pView->m_objlstRoomPtr.GetCount(); i++)
{
proomTem = (CRoom*) m_pView->m_objlstRoomPtr.GetAt(
m_pView->m_objlstRoomPtr.FindIndex(i) );
if(proomTem->m_iRoomType == HF_ROOM_TYPE_CHANNEL_PUBLIC &&
proomTem->m_strRoomName == strChannel )
{
proomTem->m_strChannelMember += CString(_T("\r\n"));
proomTem->m_strChannelMember += strTem;
break;
}
}
}
}
else if( strCommand == CString("QUIT") )
{
//quit and disconnect
m_pView->m_roomStatus.m_strContent += CString(_T("\r\n*** "));
m_pView->m_roomStatus.m_strContent += strPrefix;
m_pView->m_roomStatus.m_strContent += CString("Has Quit the channel.\r\n-");
m_pView->MyUpdateView();
}
else if( strCommand == CString("MODE") )
{
}
else if( strCommand == CString("TOPIC") )
{
m_pView->m_roomStatus.m_strContent += CString(_T("\r\n- The Topic is:"));
m_pView->m_roomStatus.m_strContent += strParams;
m_pView->m_roomStatus.m_strContent += CString("\r\n-");
m_pView->MyUpdateView();
}
else if( strCommand == CString("PART") )
{
//someone left the irc room
}
}
else
{
//"PING :irc2.cbkmis.boc"
//get the COMMAND:
iEnd = strMsg.Find(_T(' '));
if(iEnd == -1)
{
//this is not a command
return;
}
strCommand = strMsg.Mid(0,iEnd);
strParams = strMsg.Mid( iEnd+2,strMsg.GetLength() );
if( strCommand == CString("PING") )
{
//the server has send a ping messge, must send a pong messege back
DoPong( LPCSTR(strParams.Mid(0,strParams.GetLength())) );
m_pView->m_roomStatus.m_strContent += CString(_T("\r\nPING? PONG!\r\n-"));
m_pView->MyUpdateView();
}
else if( strCommand == CString("ERROR") )
{
//the server has send error message
m_pView->m_roomStatus.m_strContent += CString(_T("\r\nError!--"));
m_pView->m_roomStatus.m_strContent += strParams;
m_pView->m_roomStatus.m_strContent += CString("\r\n-");
m_pView->MyUpdateView();
}
}
}
void CIrcClient::ParseInputCommandStr(CString strText)
{
int iEnd;
CString strCommand,strParams;
//this input is a command
//get the command:
iEnd = strText.Find(_T(' '));
if(iEnd == -1)
{
//the input command like: '/list'
strCommand = strText.Mid(1,strText.GetLength());
strParams = CString(_T(""));
}
else
{
strCommand = strText.Mid(1,iEnd);
strParams = strText.Mid(iEnd+1,strText.GetLength());
strParams.TrimLeft();
strParams.TrimRight();
}
strCommand.MakeUpper();
strCommand.TrimLeft();
strCommand.TrimRight();
if( strCommand == CString(_T("JOIN")) )
{
DoJoin( LPCSTR(strParams) );
}
if( strCommand == CString(_T("LIST")) )
{
DoList();
}
if( strCommand == CString(_T("CLEAR")) || strCommand == CString(_T("CLS")) )
{
DoClear();
}
}
void CIrcClient::DoClear()
{
if(0 == m_pView->m_wndStatusBar.m_iActive )
{
//now the active room is 'Status'
m_pView->m_roomStatus.m_strContent = CString(_T(""));
m_pView->MyUpdateView();
}
else
{
//find the correspond room
CRoom* proomTem;
proomTem = (CRoom*) m_pView->m_objlstRoomPtr.GetAt(
m_pView->m_objlstRoomPtr.FindIndex(m_pView->m_wndStatusBar.m_iActive - 1) ); //!! the list 0, (0, 1, 2, ....)
//m_pView->m_objlstRoomPtr.FindIndex(pView->m_wndStatusBar.m_iActive) );
proomTem->m_strContent = CString(_T(""));
m_pView->MyUpdateView();
}
}
void CIrcClient::DoNames()
//void CIrcClient::DoNames(LPCSTR lpszChannel)
{
char buf[50];
int iTem;
if(m_pSocket == NULL) return;
sprintf(buf, "NAMES");
//sprintf(buf, "NAMES %s",lpszChannel);
iTem = strlen(buf);
buf[iTem] = 0x0d;
buf[iTem+1] = 0x0a;
buf[iTem+2] = 0x00;
m_pSocket->Send( (void*)buf, strlen(buf));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -