MirMsg.cpp
资源名称:盛大传奇外挂原代码.rar [点击查看]
上传用户:marco7834
上传日期:2010-02-24
资源大小:82k
文件大小:3k
源码类别:
游戏引擎
开发平台:
Visual C++
- // MirMsg.cpp: implementation of the MirMsg class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "MirMsg.h"
- #include "mircode.h"
- #include <stdio.h>
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CMirMsg::CMirMsg()
- {
- m_ConvBuffer = new char[MSGBUFFERSIZE];
- m_RecvBuffer = new char[MSGBUFFERSIZE];
- m_SendBuffer = new char[MSGBUFFERSIZE];
- m_msgflag = '1';
- }
- CMirMsg::~CMirMsg()
- {
- delete m_ConvBuffer;
- delete m_RecvBuffer;
- delete m_SendBuffer;
- }
- int CMirMsg::SendString( SOCKET s, char * string )
- {
- int ierr = 0;
- int ilen = strlen( string );
- ierr = send( s, string, ilen, 0 );
- if( ierr == ilen )
- {
- if( string[0] == '*' )
- return ierr;
- m_msgflag ++;
- if( m_msgflag > '9' )
- m_msgflag = '1';
- }
- return ierr;
- }
- int CMirMsg::RecvString( SOCKET s, char * string, int maxlen )
- {
- int ierr = 0;
- //char tmpBuffer[MSGLENGTH];
- ierr = recv( s, m_RecvBuffer, MSGBUFFERSIZE, 0 );
- if( ierr !=- 1 )
- {
- if( m_RecvBuffer[0] == '*' )
- {
- ierr --;
- memcpy( (void*)string, &m_RecvBuffer[1], ierr );
- }
- else
- {
- memcpy( (void*)string, m_RecvBuffer, ierr );
- }
- string[ierr] = ' ';
- }
- return ierr;
- }
- int CMirMsg::RecvMsg( SOCKET s, MMSG * pmsg )
- {
- int ierr;
- ierr = RecvString( s, m_RecvBuffer, MSGBUFFERSIZE );
- if( ierr == -1 )
- {
- return -1;
- }
- if( m_RecvBuffer[0] != '#' )
- {
- return 0;
- }
- if(m_RecvBuffer[ierr-1] == '!' )
- {
- m_RecvBuffer[ierr-1] = ' ';
- }
- ierr = UnGameCode( &m_RecvBuffer[1], (BYTE*)pmsg );
- return ierr;
- }
- int CMirMsg::RecvGateMsg( SOCKET s, MMSG * pmsg )
- {
- int ierr;
- ierr = RecvString( s, m_RecvBuffer, MSGLENGTH );
- if( ierr == -1 )
- {
- return -1;
- }
- if( m_RecvBuffer[0] != '<' )
- return 0;
- if( m_RecvBuffer[ierr-1] != '>' )
- return 0;
- m_RecvBuffer[ierr-1] = ' ';
- ierr = UnGateCode( &m_RecvBuffer[1], m_ConvBuffer );
- ierr = strlen( m_ConvBuffer );
- if( m_ConvBuffer[0] != '#' )
- return 0;
- if(m_ConvBuffer[ierr-1] == '!' )
- {
- m_ConvBuffer[ierr-1] = ' ';
- }
- ierr = UnGameCode( &m_ConvBuffer[1], (BYTE*)pmsg );
- return ierr;
- }
- int CMirMsg::SendMsg( SOCKET s, MMSG * pmsg )
- {
- int msize = 0;
- msize = strlen(pmsg->data ) + MSGHEADERSIZE;
- CodeGameCode( (BYTE*)pmsg, msize, (BYTE*)m_ConvBuffer );
- // if( pmsg->wCmd == 0xbc2 )
- // MessageBox( 0, m_ConvBuffer, 0, 0 );
- sprintf( m_SendBuffer , "#%c%s!",m_msgflag, m_ConvBuffer );
- return SendString( s, m_SendBuffer );
- }
- int CMirMsg::SendGateMsg( SOCKET s, MMSG * pmsg )
- {
- int msize = 0;
- msize = strlen(pmsg->data ) + MSGHEADERSIZE;
- CodeGameCode( (BYTE*)pmsg, msize, (BYTE*)m_ConvBuffer );
- sprintf( m_SendBuffer , "#%c%s!",m_msgflag, m_ConvBuffer );
- // MessageBox( 0, m_SendBuffer, 0, 0 );
- CodeGateCode( m_SendBuffer, m_ConvBuffer );
- sprintf( m_SendBuffer, "<%s>", m_ConvBuffer );
- return SendString( s, m_SendBuffer );
- }
- char CMirMsg::GetMsgFlag()
- {
- return m_msgflag;
- }