首页
社区
课程
招聘
[旧帖] [求助]这是一段服务端的代码,求大大们帮我注释! 0.00雪花
发表于: 2009-2-14 22:40 3147

[旧帖] [求助]这是一段服务端的代码,求大大们帮我注释! 0.00雪花

2009-2-14 22:40
3147
// User.cpp: implementation of the CUser class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "versionmanager.h"
#include "versionmanagerdlg.h"
#include "User.h"

#pragma warning(disable : 4786)                // Visual C++ Only
#include <set>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CUser::CUser()
{

}

CUser::~CUser()
{

}

void CUser::Initialize()
{
        m_pMain = (CVersionManagerDlg*)AfxGetMainWnd();

        CIOCPSocket2::Initialize();
}

void CUser::CloseProcess()
{

        CIOCPSocket2::CloseProcess();
}

void CUser::Parsing(int len, char *pData)
{
        int index = 0, send_index = 0, i=0, client_version = 0;
        char buff[2048]; memset( buff, 0x00, 2048 );
        BYTE command = GetByte( pData, index );

        switch( command ) {
        case LS_VERSION_REQ:
                SetByte( buff, LS_VERSION_REQ, send_index );
                SetShort( buff, m_pMain->m_nLastVersion, send_index );
                Send( buff, send_index );
                break;
        case LS_SERVERLIST:
                m_pMain->m_DBProcess.LoadUserCountList();                // 扁裹捞啊 ^^;
                SetByte( buff, LS_SERVERLIST, send_index );
                SetByte( buff, m_pMain->m_nServerCount, send_index );
                for(i=0; i<m_pMain->m_ServerList.size(); i++) {               
                        SetShort( buff, strlen(m_pMain->m_ServerList[i]->strServerIP), send_index );
                        SetString( buff, m_pMain->m_ServerList[i]->strServerIP, strlen(m_pMain->m_ServerList[i]->strServerIP), send_index );
                        SetShort( buff, strlen(m_pMain->m_ServerList[i]->strServerName), send_index );
                        SetString( buff, m_pMain->m_ServerList[i]->strServerName, strlen( m_pMain->m_ServerList[i]->strServerName ), send_index );                       
                        SetShort( buff, m_pMain->m_ServerList[i]->sUserCount, send_index);   // 扁裹捞啊 ^^;
                }
                Send( buff, send_index );
                break;
        case LS_DOWNLOADINFO_REQ:
                client_version = GetShort( pData, index );
                SendDownloadInfo( client_version );
                break;
        case LS_LOGIN_REQ:
                LogInReq( pData+index );
                break;
        case LS_MGAME_LOGIN:
                MgameLogin( pData+index );
                break;
        }
}
void CUser::LogInReq(char *pBuf)
{
        int index = 0, idlen=0, pwdlen = 0, send_index = 0, result = 0, serverno = 0;
        BOOL bCurrentuser = FALSE;
        char send_buff[256]; memset( send_buff, 0x00, 256 );
        char serverip[20]; memset( serverip, 0x00, 20 );
        char accountid[MAX_ID_SIZE+1], pwd[32];
        memset( accountid, NULL, MAX_ID_SIZE+1 );
        memset( pwd, NULL, 32);

        idlen = GetShort( pBuf, index );
        if( idlen > MAX_ID_SIZE || idlen <= 0)
                goto fail_return;
        GetString( accountid, pBuf, idlen, index );
        pwdlen = GetShort( pBuf, index );
        if( pwdlen > 32 || pwdlen < 0)
                goto fail_return;
        GetString( pwd, pBuf, pwdlen, index );

        result = m_pMain->m_DBProcess.AccountLogin( accountid, pwd );
        SetByte( send_buff, LS_LOGIN_REQ, send_index );
        if( result == 1 ) { // success
                bCurrentuser = m_pMain->m_DBProcess.IsCurrentUser( accountid, serverip, serverno );
                if( bCurrentuser ) {
                        result = 0x05;                // Kick out
                        SetByte( send_buff, result, send_index );
                        SetShort( send_buff, strlen(serverip), send_index );
                        SetString( send_buff, serverip, strlen(serverip), send_index );
                        SetShort( send_buff, serverno, send_index );
                }
                else
                        SetByte( send_buff, result, send_index );
        }
        else
                SetByte( send_buff, result, send_index );
        Send( send_buff, send_index );

        return;
fail_return:
        SetByte( send_buff, LS_LOGIN_REQ, send_index );
        SetByte( send_buff, 0x02, send_index );                                // id, pwd 捞惑...
        Send( send_buff, send_index );
}

void CUser::MgameLogin(char *pBuf)
{
        int index = 0, idlen=0, pwdlen = 0, send_index = 0, result = 0;
        char send_buff[256]; memset( send_buff, 0x00, 256 );
        char accountid[MAX_ID_SIZE+1], pwd[32];
        memset( accountid, NULL, MAX_ID_SIZE+1 );
        memset( pwd, NULL, 32);

        idlen = GetShort( pBuf, index );
        if( idlen > MAX_ID_SIZE || idlen <= 0)
                goto fail_return;
        GetString( accountid, pBuf, idlen, index );
        pwdlen = GetShort( pBuf, index );
        if( pwdlen > 32 )
                goto fail_return;
        GetString( pwd, pBuf, pwdlen, index );

        result = m_pMain->m_DBProcess.MgameLogin( accountid, pwd );
        SetByte( send_buff, LS_MGAME_LOGIN, send_index );
        SetByte( send_buff, result, send_index );
        Send( send_buff, send_index );

        return;
fail_return:
        SetByte( send_buff, LS_MGAME_LOGIN, send_index );
        SetByte( send_buff, 0x02, send_index );                                // login fail...
        Send( send_buff, send_index );
}

void CUser::SendDownloadInfo(int version)
{
        int send_index = 0, filecount = 0;
        _VERSION_INFO *pInfo = NULL;
        std::set <string>        downloadset;
        char buff[2048]; memset( buff, 0x00, 2048 );

        std::map <string, _VERSION_INFO*>::iterator        Iter1, Iter2;
        Iter1 = m_pMain->m_VersionList.m_UserTypeMap.begin();
        Iter2 = m_pMain->m_VersionList.m_UserTypeMap.end();
        for( ; Iter1 != Iter2; Iter1++ ) {
                pInfo = (*Iter1).second;
                if( pInfo->sVersion > version )
                        downloadset.insert(pInfo->strCompName);
        }

        SetByte( buff, LS_DOWNLOADINFO_REQ, send_index );
        SetShort( buff, strlen( m_pMain->m_strFtpUrl), send_index );
        SetString( buff, m_pMain->m_strFtpUrl, strlen( m_pMain->m_strFtpUrl), send_index );
        SetShort( buff, strlen( m_pMain->m_strFilePath), send_index );
        SetString( buff, m_pMain->m_strFilePath, strlen( m_pMain->m_strFilePath), send_index );
        SetShort( buff, downloadset.size(), send_index );
       
        std::set <string>::iterator filenameIter1, filenameIter2;
        filenameIter1 = downloadset.begin();
        filenameIter2 = downloadset.end();
        for(; filenameIter1 != filenameIter2; filenameIter1++ ) {
                SetShort( buff, strlen( (*filenameIter1).c_str() ), send_index );
                SetString( buff, (char*)((*filenameIter1).c_str()), strlen( (*filenameIter1).c_str() ), send_index );
        }
        Send( buff, send_index );
}

另外,哪句可以改IP协议的封包格式呢

[课程]FART 脱壳王!加量不加价!FART作者讲授!

收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 235
活跃值: (10)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
2
看了一眼,貌似是

对请求 版本信息,服务器列表,下载请求,登录的服务器端处理

ip协议封包?

这程序貌似只是应用层封包。。。只是应用层自己的协议而已,根据客户端封包的第一位来区别是什么请求。
2009-2-15 00:26
0
游客
登录 | 注册 方可回帖
返回
//