MirCore.cpp
资源名称:盛大传奇外挂原代码.rar [点击查看]
上传用户:marco7834
上传日期:2010-02-24
资源大小:82k
文件大小:18k
源码类别:
游戏引擎
开发平台:
Visual C++
- #pragma comment( lib, "ws2_32.lib" )
- #include <winsock2.h>
- #include <windowsx.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include "mircode.h"
- typedef struct
- {
- union
- {
- DWORD dwFlag;
- struct
- {
- WORD wa;
- WORD wb;
- };
- };
- WORD wCmd;
- WORD w1;
- WORD w2;
- WORD w3;
- char data[1024];
- }MMSG;
- #define CGIP "61.152.97.21"
- #define ACCOUNT "johndragon"
- #define PASSWORD "shifully"
- #define WORDS "各个姐姐弟弟妹妹们,你们好,我是机器人,请多关照!!"
- char g_msgflag = '1';
- char rcBuffer[4096];
- typedef char TSTRING[256];
- TSTRING g_StringList[20];
- int g_pos_x, g_pos_y;
- char g_mapname[256];
- #define MSGHEADERSIZE 12
- #define MSGLENGTH 1024
- #define MSGQUEUELEN 256
- typedef char TMSGLINE[MSGLENGTH];
- enum _action
- {
- ACTION_STAND,
- ACTION_WALK,
- ACTION_ATTACK,
- ACTION_RUN,
- ACTION_TRUN,
- };
- typedef struct
- {
- int x;
- int y;
- int dir;
- int action;
- }ACTION_LAST;
- ACTION_LAST g_LastAction = {0, 0, 0, 0 };
- class CMsgQueue
- {
- public:
- CMsgQueue()
- {
- m_iGet = 0;
- m_iPut = 0;
- Clear();
- };
- virtual ~CMsgQueue()
- {
- Clear();
- };
- int NextPos( int now )
- {
- now++;
- if( now >= MSGQUEUELEN )
- now = 0;
- return now;
- }
- int PutMsg( char * pMsg )
- {
- int iNext = NextPos( m_iPut );
- if( pMsg == NULL )
- return 0;
- if( iNext == m_iGet )
- {
- return 0;
- }
- strcpy( m_Msgs[m_iPut], pMsg );
- m_iPut = iNext;
- return 1;
- };
- int GetMsg( char * pMsg )
- {
- if( m_iGet == m_iPut )
- return 0;
- strcpy( pMsg, m_Msgs[m_iGet] );
- // printf( "m_iPut = %d, m_iGet = %dn", m_iPut, m_iGet );
- m_iGet = NextPos( m_iGet );
- return 1;
- };
- int Clear()
- {
- memset( (void*)m_Msgs, 0, sizeof( TMSGLINE ) * MSGQUEUELEN );
- return 1;
- };
- private:
- TMSGLINE m_Msgs[MSGQUEUELEN];
- int m_iGet;
- int m_iPut;
- };
- CMsgQueue g_MsgQueue;
- HWND m_hSysLog = NULL;
- HWND m_hChatLog = NULL;
- HWND m_hMainDlg = NULL;
- int m_MaxLogLine = 100;
- BOOL InitMirCore( HWND hMainWnd, HWND hSysLog, HWND hChatLog, int MaxLogLine )
- {
- m_hSysLog = hSysLog;
- m_hChatLog = hChatLog;
- m_hMainDlg = hMainWnd;
- m_MaxLogLine = MaxLogLine;
- return TRUE;
- }
- void LogToList( HWND hList, char * line )
- {
- int cnt = 0;
- cnt = ListBox_GetCount( hList );
- if( cnt >= m_MaxLogLine )
- {
- ListBox_DeleteString( hList, 0 );
- cnt --;
- }
- ListBox_AddString( hList, line );
- ListBox_SetCurSel( hList, cnt );
- }
- void LogChat( char * line,... )
- {
- char szBuff[2048];
- va_list vl;
- va_start( vl, line );
- vsprintf( szBuff, line, vl );
- va_end( vl);
- LogToList( m_hChatLog, szBuff );
- }
- void LogSystem( char * line,... )
- {
- char szBuff[2048];
- va_list vl;
- va_start( vl, line );
- vsprintf( szBuff, line, vl );
- va_end( vl);
- LogToList( m_hSysLog, szBuff );
- }
- int ActionOk()
- {
- printf( "Action Ok!n" );
- switch( g_LastAction.action )
- {
- case ACTION_RUN:
- case ACTION_WALK:
- g_pos_x = g_LastAction.x;
- g_pos_y = g_LastAction.y;
- break;
- }
- g_LastAction.action = 0;
- return 1;
- }
- int ActionFail()
- {
- printf( "Action Fail!n" );
- g_LastAction.action = 0;
- return 1;
- }
- int CanDoAction()
- {
- if( g_LastAction.action == 0 )
- return 1;
- return 0;
- }
- int GetString( char * string )
- {
- int ilen = strlen( string );
- int i = 0;
- int cnt = 0;
- int sptr = 0;
- for( i =0;i < ilen;i ++ )
- {
- if( string[i] == '/' && i != 0 )
- {
- g_StringList[cnt][sptr] = ' ';
- sptr = 0;
- cnt++;
- }
- else
- {
- g_StringList[cnt][sptr] = string[i];
- sptr ++;
- }
- }
- if( sptr > 0 )
- {
- g_StringList[cnt][sptr] = ' ';
- cnt++;
- }
- return cnt;
- }
- int SendString( SOCKET s, char * string )
- {
- int ierr = 0;
- int ilen = strlen( string );
- // printf( "Send: %sn", string );
- ierr = send( s, string, strlen( string), 0 );
- if( ierr == ilen )
- {
- g_msgflag ++;
- if( g_msgflag > '9' )
- g_msgflag = '1';
- }
- return ierr;
- }
- int RecvString( SOCKET s, char * string, int maxlen )
- {
- int ierr = 0;
- char tmpBuffer[2048];
- ierr = recv( s, tmpBuffer, 2048, 0 );
- if( ierr !=- 1)
- {
- if( tmpBuffer[0] == '*' )
- {
- strcpy( string, &tmpBuffer[1]);
- ierr --;
- }
- else
- {
- strcpy( string, tmpBuffer );
- }
- string[ierr] = ' ';
- // printf( "Recv:%sn", string );
- }
- return ierr;
- }
- int RecvMsg( SOCKET s, MMSG * pmsg )
- {
- char tmpBuffer[2048];
- // char tmpBuffer2[2048];
- int ierr;
- ierr = RecvString( s, tmpBuffer, 2048 );
- if( ierr == -1 )
- {
- return -1;
- }
- if(tmpBuffer[ierr-1] == '!' )
- {
- tmpBuffer[ierr-1] = ' ';
- }
- UnGameCode( &tmpBuffer[1], (BYTE*)pmsg );
- if( pmsg->wCmd == 0x0a )
- {
- //printf( "Code is %sn", tmpBuffer );
- }
- return ierr;
- }
- int GetMsg( MMSG * pMsg )
- {
- char tmpBuffer[1024];
- int ilen = 0;
- if( g_MsgQueue.GetMsg( tmpBuffer ))
- {
- ilen = strlen( tmpBuffer );
- if( tmpBuffer[ilen-1] == '!' )
- {
- tmpBuffer[ilen-1] = ' ';
- }
- printf( "Msg: %sn", tmpBuffer );
- if( tmpBuffer[1] == '+' )
- {
- tmpBuffer[6] = ' ';
- printf( "GetWords %sn", tmpBuffer );
- if( stricmp( tmpBuffer, "#+GOOD" ) == 0 )
- {
- ActionOk();
- }
- else if( stricmp( tmpBuffer, "#+FAIL" ) == 0 )
- {
- ActionFail();
- }
- return 0;
- }
- UnGameCode( &tmpBuffer[1], (BYTE*)pMsg );
- return 1;
- }
- return 0;
- }
- int SetNoBlock( SOCKET s )
- {
- unsigned long mode = 1;
- if( ioctlsocket( s, FIONBIO, &mode ) == -1 )
- return 0;
- return 1;
- }
- int RecvGateMsg( SOCKET s, MMSG * pmsg )
- {
- char tmpBuffer[2048];
- char tmpBuffer2[2048];
- int ierr;
- ierr = RecvString( s, tmpBuffer, 2048 );
- if( ierr == -1 )
- {
- return -1;
- }
- tmpBuffer[ierr-1] = ' ';
- UnGateCode( &tmpBuffer[1], tmpBuffer2 );
- ierr = strlen( tmpBuffer2 );
- if(tmpBuffer2[ierr-1] == '!' )
- {
- tmpBuffer2[ierr-1] = ' ';
- }
- UnGameCode( &tmpBuffer2[1], (BYTE*)pmsg );
- return ierr;
- }
- int SendMsg( SOCKET s, MMSG * pmsg )
- {
- char tmpBuffer[2048];
- char tmpBuffer2[2048];
- int msize = 0;
- msize = strlen(pmsg->data ) + MSGHEADERSIZE;
- CodeGameCode( (BYTE*)pmsg, msize, (BYTE*)tmpBuffer );
- sprintf( tmpBuffer2, "#%c%s!",g_msgflag, tmpBuffer );
- return SendString( s,tmpBuffer2 );
- }
- int SendGateMsg( SOCKET s, MMSG * pmsg )
- {
- char tmpBuffer[2048];
- char tmpBuffer2[2048];
- int msize = 0;
- msize = strlen(pmsg->data ) + MSGHEADERSIZE;
- CodeGameCode( (BYTE*)pmsg, msize, (BYTE*)tmpBuffer );
- sprintf( tmpBuffer2, "#%c%s!",g_msgflag, tmpBuffer );
- CodeGateCode( tmpBuffer2, tmpBuffer );
- sprintf( tmpBuffer2, "<%s>", tmpBuffer );
- return SendString( s, tmpBuffer2 );
- }
- int SendWords( SOCKET s , char * word )
- {
- MMSG msg;
- memset( &msg, 0, sizeof( MMSG ));
- sprintf( msg.data, "#(%03d,%03d)-%s", g_pos_x, g_pos_y, word );
- msg.wCmd = 0xbd6;
- int erri;
- erri = SendMsg( s, &msg );
- return erri;
- }
- int TurnDirect( SOCKET s, int dir )
- {
- MMSG msg;
- char tmpBuffer[2048];
- int erri;
- memset( &msg, 0, sizeof( MMSG ));
- //msg.dwFlag = 0x6000e;
- msg.wa = g_pos_x;
- msg.wb = g_pos_y;
- msg.wCmd = 0xbc2;
- msg.w2 = dir;
- erri = SendMsg( s, &msg );
- if( erri == -1 )
- return -1;
- erri = RecvString( s, tmpBuffer, 256 );
- if( erri == -1 )
- return 0;
- //printf( "%sn", tmpBuffer );
- tmpBuffer[6] = ' ';
- if( stricmp( &tmpBuffer[1] ,"+GOOD") == 0 )
- {
- //g_pos_x += xofs_walk[dir];
- //g_pos_y += yofs_walk[dir];
- return 1;
- }
- return 0;
- }
- int xofs_walk[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
- int yofs_walk[] = { -1, -1, 0, 1, 1, 1, 0, -1 };
- int Walk( SOCKET s, int dir )
- {
- MMSG msg;
- char tmpBuffer[2048];
- int erri;
- int tx,ty;
- if( dir <0 || dir > 7 )
- return 0;
- tx = g_pos_x + xofs_walk[dir];
- ty = g_pos_y + yofs_walk[dir];
- memset( &msg, 0, sizeof( MMSG ));
- //msg.dwFlag = 0x6000e;
- msg.wa = tx;//g_pos_x;
- msg.wb = ty;//g_pos_y;
- msg.wCmd = 0xbc3;
- msg.w2 = dir;
- erri = SendMsg( s, &msg );
- if( erri == -1 )
- return -1;
- erri = RecvString( s, tmpBuffer, 256 );
- if( erri == -1 )
- return 0;
- // printf( "%sn", tmpBuffer );
- tmpBuffer[6] = ' ';
- if( stricmp( &tmpBuffer[1] ,"+GOOD") == 0 )
- {
- printf( "Good!!n" );
- g_pos_x = tx;// xofs_walk[dir];
- g_pos_y = ty;//+= yofs_walk[dir];
- return 1;
- }
- return 0;
- }
- int Run( SOCKET s, int dir )
- {
- MMSG msg;
- char tmpBuffer[2048];
- int erri;
- int tx,ty;
- if( dir <0 || dir > 7 )
- return 0;
- tx = g_pos_x + (xofs_walk[dir]*2);
- ty = g_pos_y + (yofs_walk[dir]*2);
- memset( &msg, 0, sizeof( MMSG ));
- msg.wa = tx;//g_pos_x;
- msg.wb = ty;//g_pos_y;
- msg.wCmd = 0xbc5;
- msg.w2 = dir;
- erri = SendMsg( s, &msg );
- if( erri == -1 )
- return 0;
- g_LastAction.action = ACTION_RUN;
- g_LastAction.x = tx;
- g_LastAction.y = ty;
- g_LastAction.dir = dir;
- return 1;
- }
- int Attack( SOCKET s, int dir )
- {
- MMSG msg;
- char tmpBuffer[2048];
- int erri;
- int tx,ty;
- if( dir <0 || dir > 7 )
- return 0;
- //tx = g_pos_x + (xofs_walk[dir]*2);
- //ty = g_pos_y + (yofs_walk[dir]*2);
- memset( &msg, 0, sizeof( MMSG ));
- //msg.dwFlag = 0x6000e;
- msg.wa = g_pos_x;
- msg.wb = g_pos_y;
- msg.wCmd = 0xbc8;
- msg.w2 = dir;
- erri = SendMsg( s, &msg );
- if( erri == -1 )
- return -1;
- erri = RecvString( s, tmpBuffer, 256 );
- if( erri == -1 )
- return 0;
- // printf( "%sn", tmpBuffer );
- tmpBuffer[6] = ' ';
- if( stricmp( &tmpBuffer[1] ,"+GOOD") == 0 )
- {
- printf( "Good!!n" );
- return 1;
- }
- return 0;
- }
- int GetMsgInfo( SOCKET s )
- {
- char tmpBuffer[2048];
- static char tmpLeft[4096] = "";
- char tmpMsg[2048];
- int ierr = 0;
- int iptr = 0;
- int i = 0;
- ierr = recv( s, tmpBuffer, 2048, 0 );
- if( ierr == -1 )
- return 0;
- if( ierr > 0 )
- {
- tmpBuffer[ierr] = ' ';
- printf( "Recv:%sn", tmpBuffer );
- printf( "Left:%sn", tmpLeft );
- strcat( tmpLeft, tmpBuffer );
- for( i = 0;i < (int)strlen( tmpLeft) ;i ++ )
- {
- if( tmpLeft[i] == '*' )
- continue;
- if( tmpLeft[i] == '#' )
- {
- iptr = i;
- }
- if( tmpLeft[i] == '!' )
- {
- memcpy( (void*)tmpMsg, (void*)&tmpLeft[iptr], i - iptr + 1 );
- tmpMsg[i-iptr+1] = ' ';
- if( !g_MsgQueue.PutMsg( tmpMsg ) )
- {
- break;
- }
- // printf( "Put msg: %sn", tmpMsg );
- iptr = 0;
- }
- }
- if( iptr > 0 )
- {
- memcpy( (void*)tmpBuffer, (void*)&tmpLeft[iptr], ierr - iptr );
- tmpBuffer[ierr - iptr] = ' ';
- strcpy( tmpLeft, tmpBuffer );
- }
- else
- {
- tmpLeft[0]=' ';
- }
- }
- return 1;
- }
- int GetMsgInfo2( char * s )
- {
- char tmpBuffer[2048];
- static char tmpLeft[4096] = "";
- static BOOL bLeft = FALSE;
- char tmpMsg[2048];
- int ierr = 0;
- int iptr = 0;
- int i = 0;
- //ierr = recv( s, tmpBuffer, 2048, 0 );
- ierr = strlen( s );
- if( ierr == -1 )
- return 0;
- if( ierr > 0 )
- {
- tmpBuffer[ierr] = ' ';
- strcat( tmpLeft, s );//tmpBuffer );
- for( i = 0;i < ierr;i ++ )
- {
- if( tmpLeft[i] == '*' )
- continue;
- if( tmpLeft[i] == '#' )
- {
- iptr = i;
- }
- if( tmpLeft[i] == '!' )
- {
- memcpy( (void*)tmpMsg, (void*)&tmpLeft[iptr], i - iptr + 1 );
- tmpMsg[i-iptr+1] = ' ';
- if( !g_MsgQueue.PutMsg( tmpMsg ) )
- {
- break;
- }
- iptr = 0;
- }
- }
- if( iptr > 0 )
- {
- memcpy( (void*)tmpBuffer, (void*)&tmpLeft[iptr], ierr - iptr );
- tmpBuffer[ierr - iptr] = ' ';
- strcpy( tmpLeft, tmpBuffer );
- }
- else
- {
- tmpLeft[0] = ' ';
- }
- printf( "%sn" , tmpLeft);
- }
- return 1;
- }
- int HandleAppearMsg( MMSG * pmsg )
- {
- char tmpBuffer[2048];
- char strs[200];
- UnNameCode( &pmsg->data[8], tmpBuffer );
- printf( "%s 出现在坐标 %d, %d 处n", tmpBuffer, pmsg->w1, pmsg->w2 );
- sprintf( strs, "%s 出现在坐标 %d, %d 处n", tmpBuffer, pmsg->w1, pmsg->w2 );
- SendWords( (SOCKET)pmsg->dwFlag, strs );
- printf( "Name code is %sn", pmsg->data );
- return 0;
- }
- int EnterGame( char * serverip, int port, char * charname, char * sid )
- {
- LPHOSTENT m_pHost;
- WSADATA m_wsaData;
- int m_SockFD;
- struct sockaddr_in ServAddr;
- char tmpBuffer[1024];
- char tmpBuffer2[1024];
- MMSG msg;
- int msize = 0;
- int mdir = 0;
- int mmmtime = 0;
- memset( &msg, 0, sizeof( MMSG ));
- WSAStartup(MAKEWORD(2,2), &m_wsaData);
- m_pHost = gethostbyname(serverip);
- m_SockFD = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- ServAddr.sin_family = AF_INET;
- ServAddr.sin_addr.s_addr = *(ULONG *)m_pHost->h_addr_list[0];
- ServAddr.sin_port = htons(port);
- printf( "正在连接游戏服务器...n" );
- int erri = connect(m_SockFD, (struct sockaddr *)&ServAddr, sizeof(ServAddr));
- if( erri == -1) return 0;
- printf( "游戏服务器连接成功!n" );
- sprintf( tmpBuffer, "**%s/%s/%s/20020522/0", ACCOUNT, charname, sid );
- CodeGameCode( (BYTE*)tmpBuffer, strlen( tmpBuffer ), (BYTE*)tmpBuffer2 );
- sprintf( tmpBuffer, "#%c%s!", g_msgflag, tmpBuffer2 );
- printf( "验证用户合法性...n", tmpBuffer );
- erri = SendString( m_SockFD, tmpBuffer );
- if( erri == -1 )
- return 0;
- printf( "接收用户守则...n" );
- erri = RecvMsg( m_SockFD, &msg );
- if( erri == -1 )
- return 0;
- //printf( "%sn", msg.data );
- erri = RecvString( m_SockFD, tmpBuffer, 2048 );
- if( erri > 0 )
- {
- printf( "%sn", tmpBuffer );
- }
- memset( &msg, 0, sizeof( MMSG ));
- msg.wCmd = 0x3fa;
- printf( "确认同意用户守则...n");
- erri = SendMsg( m_SockFD, &msg );
- if( erri == -1 )
- return -1;
- printf( "进入游戏!n" );
- SetNoBlock( m_SockFD );
- int bflag = 0;
- while( 1 )
- {
- Sleep( 600 );
- mmmtime ++;
- GetMsgInfo( m_SockFD );
- while( GetMsg( &msg ))//RecvMsg( m_SockFD, &msg );
- {
- if( msg.wCmd == 0x33 )
- {
- printf( "人物出现在地图 %s.map 坐标 ( %d, %d )n", msg.data ,msg.w1, msg.w2 );
- g_pos_x = msg.w1;
- g_pos_y = msg.w2;
- }
- if( msg.wCmd == 0x36 )
- {
- strcpy( g_mapname, msg.data );
- printf( "Location at map: %sn", msg.data );
- }
- if( msg.wCmd == 0x0a )
- {
- msg.dwFlag = m_SockFD;
- HandleAppearMsg( &msg );
- }
- printf( "%sn", msg.data );
- }
- //if( mdir == 6 )
- // SendWords( m_SockFD, WORDS );
- if( mmmtime > 50 )
- {
- if( CanDoAction())
- {
- printf( "跑步中!..n" );
- SendWords( m_SockFD, WORDS );
- Run( m_SockFD, mdir );
- mdir ++;
- if( mdir >= 8 )
- mdir = 0;
- }
- }
- printf( "Pos: %d, %dn", g_pos_x, g_pos_y );
- }
- closesocket(m_SockFD);
- WSACleanup();
- return 1;
- }
- int SelChar( char * serverip, int port, char * sid )
- {
- LPHOSTENT m_pHost;
- WSADATA m_wsaData;
- int m_SockFD;
- struct sockaddr_in ServAddr;
- // char tmpBuffer[1024];
- // char tmpBuffer2[1024];
- MMSG msg;
- int msize = 0;
- memset( &msg, 0, sizeof( MMSG ));
- WSAStartup(MAKEWORD(2,2), &m_wsaData);
- m_pHost = gethostbyname(serverip);
- m_SockFD = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- ServAddr.sin_family = AF_INET;
- ServAddr.sin_addr.s_addr = *(ULONG *)m_pHost->h_addr_list[0];
- ServAddr.sin_port = htons(port);
- printf( "连接角色服务器...n" );
- int erri = connect(m_SockFD, (struct sockaddr *)&ServAddr, sizeof(ServAddr));
- if( erri == -1) return 0;
- printf( "角色服务器连接成功!n" );
- printf( "验证用户SIDn" );
- msg.wCmd = 0x64;
- sprintf( msg.data, "%s/%s", ACCOUNT, sid );
- //printf( "Test String is:%sn", msg.data );
- erri = SendMsg( m_SockFD, &msg );
- if( erri == -1 )
- return 0;
- erri = RecvMsg( m_SockFD, &msg );
- if( erri == -1 )
- return 0;
- if( msg.wCmd != 0x208 )
- return 0;
- printf( "角色列表:%sn", msg.data );
- memset( &msg, 0, sizeof( MMSG ));
- msg.wCmd = 0x67;
- sprintf( msg.data, "%s/%s", ACCOUNT, "开福の名人" );
- erri = SendMsg( m_SockFD, &msg );
- if( erri == -1 )
- return 0;
- erri = RecvMsg( m_SockFD, &msg );
- if( erri == -1 )
- return 0;
- if( msg.wCmd != 0x20d )
- {
- return 0;
- }
- printf( "%sn", msg.data );
- GetString( msg.data );
- EnterGame( g_StringList[0], atoi(g_StringList[1]), "开福の名人", sid );
- closesocket(m_SockFD);
- WSACleanup();
- return 1;
- }
- int CrossGate( char * username, char * password, char * servername )
- {
- LPHOSTENT m_pHost;
- WSADATA m_wsaData;
- int m_SockFD;
- struct sockaddr_in ServAddr;
- char tmpBuffer[1024];
- char tmpBuffer2[1024];
- MMSG msg;
- int msize = 0;
- memset( &msg, 0, sizeof( MMSG ));
- WSAStartup(MAKEWORD(2,2), &m_wsaData);
- m_pHost = gethostbyname(CGIP);
- m_SockFD = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- ServAddr.sin_family = AF_INET;
- ServAddr.sin_addr.s_addr = *(ULONG *)m_pHost->h_addr_list[0];
- ServAddr.sin_port = htons(7000);
- int erri = connect(m_SockFD, (struct sockaddr *)&ServAddr, sizeof(ServAddr));
- printf( "连接账号验证服务器...n" );
- if( erri == -1) return 0;
- printf( "服务器连接成功!n" );
- erri = send( m_SockFD, "<mir152>", 8, 0 );
- printf( "发送版本信息:%sn", "<mir152>" );
- if( erri == -1 )
- {
- printf( "Error occured!n" );
- return 0;
- }
- erri = recv( m_SockFD, rcBuffer, 4096, 0 );
- if( erri == -1 )
- {
- return 0;
- }
- else
- {
- printf("验证客户端合法性...n" );
- //printf( "Get remote code: %sn", rcBuffer );
- rcBuffer[erri-1] = ' ';
- UnGateCode( &rcBuffer[1], tmpBuffer );
- //printf( "%sn", tmpBuffer );
- strcat( tmpBuffer, "/" );
- CodeGateCode( tmpBuffer, tmpBuffer2 );
- //printf( "%sn", tmpBuffer2 );
- sprintf( tmpBuffer, "<%s>", tmpBuffer2 );
- //printf( "Gen local code: %sn", tmpBuffer );
- }
- erri = send( m_SockFD, tmpBuffer, strlen( tmpBuffer), 0 );
- if( erri == -1 )
- return 0;
- erri = recv( m_SockFD, rcBuffer, 4096, 0 );
- if( erri == -1 )
- return 0;
- else
- rcBuffer[erri] = ' ';
- printf( "%sn", rcBuffer );
- if( stricmp( rcBuffer, "<pass>" ) == 0)
- {
- printf( "验证通过,开始验证用户名和密码n" );
- }
- msg.wCmd = 0x7d1;
- sprintf( msg.data, "%s/%s", ACCOUNT, PASSWORD );
- msize = MSGHEADERSIZE + strlen( msg.data );
- erri = SendGateMsg( m_SockFD, &msg );
- if( erri == -1 )
- return 0;
- //printf( "Password sended!n" );
- erri = RecvGateMsg( m_SockFD, &msg );
- if( erri == -1 )
- return 0;
- if( msg.wCmd == 0x211 )
- printf( "验证通过!n" );
- else
- return 0;
- msg.wCmd = 0x68;
- strcpy( msg.data, servername );
- erri = SendGateMsg( m_SockFD, &msg );
- if( erri == -1 )
- return 0;
- erri = RecvGateMsg( m_SockFD, &msg );
- if( erri == -1 )
- return 0;
- if( msg.wCmd != 0x212 )
- return 0;
- printf( "得到服务器地址:%sn", msg.data );
- GetString( msg.data );
- //printf( "%s %s %sn", g_StringList[0], g_StringList[1], g_StringList[2] );
- SelChar( g_StringList[0], atoi( g_StringList[1]), g_StringList[2] );
- closesocket(m_SockFD);
- WSACleanup();
- return 1;
- }