⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logparser.cpp

📁 The application wizard has created this SoccerDoctor application for you. This application not onl
💻 CPP
字号:
#include "StdAfx.h"
#include "LogParser.h"
#include "LogPlayer.h"
bool CV3LogParser::parseLog(CGZFile &logFile)
{
	short Mode;
	short_showinfo_t2 ShortShowInfo;
	short len;
	my_msginfo_t msg;
	char message[max_message_length_for_display];
	cycle_info_t cInfo;
	cInfo.valid = true;
	cInfo.cycle = 0;
	cInfo.msg = "";
	while( logFile.Good() ){ 
		logFile.Read(&Mode,sizeof(Mode));
		switch (ntohs(Mode)){
		case PM_MODE:
			logFile.Read(&(cInfo.show.pmode),sizeof(cInfo.show.pmode));
			break;

		case TEAM_MODE:
			logFile.Read(cInfo.show.team,sizeof(cInfo.show.team));
			break;

		case SHOW_MODE:
			logFile.Read(&ShortShowInfo,sizeof(ShortShowInfo));
			cInfo.show.ball = ShortShowInfo.ball;
			memcpy(cInfo.show.pos,ShortShowInfo.pos,sizeof(ShortShowInfo.pos));
			cInfo.show.time = ShortShowInfo.time;
			cInfo.cycle = ntohs(cInfo.show.time);
			cInfo.bSight = false;
			getLogPlayer()->addOneCycle(cInfo); // 把此周期加入
			cInfo.msg.Empty();
			break;
		case MSG_MODE:
			logFile.Read(&(msg.board),sizeof(msg.board));
			// read the string length
			logFile.Read(&len,sizeof(len));
            len = ntohs(len);
			logFile.Read(message,len);
			if( !strncmp(message,"Recv ",5)){
				cInfo.msg += message ; // 只有队员的命令对我们有用
				cInfo.msg += MSG_FOOTER ; // 用来表明命令结束
			}
			// read the message
			
			break;

		case PARAM_MODE:
			{
				server_params_t param;
				logFile.Read(&param,sizeof(param));
				getLogPlayer()->setServerParam(&param); // server_params
			}
			break;

		case PPARAM_MODE:
			{
				player_params_t param;
				logFile.Read(&param,sizeof(param));
				getLogPlayer()->setPlayerParam(&param); // player_params
			}
			break;

		case PT_MODE:
			{
				player_type_t type;
				logFile.Read(&type,sizeof(type));
				getLogPlayer()->addPlayerType(&type);
			}
			break;			
		default:
			return false;
		}
	} // while
	return true;
}

bool CSightLogParser::parseLog(CGZFile &logFile)
{
	cycle_info_t cInfo;

	cInfo.bSight = true;
	cInfo.valid = true;
	while( logFile.Good() ){ 
		logFile.Read(&(cInfo.sight),sizeof(cInfo.sight));
		cInfo.cycle = cInfo.sight.time;
		getLogPlayer()->addOneCycle(cInfo);
	}
	return true;
}

bool CDispinfo2Parser::parseDispinfo(BYTE *pData)
{
	dispinfo_t2 *pInfo = (dispinfo_t2 *)pData;
	switch ( ntohs(pInfo->mode)) {
	case SHOW_MODE:
		_cInfo.cycle = ntohs(pInfo->body.show.time);
		_cInfo.show = pInfo->body.show ;
		_cInfo.bSight = false;
		_cInfo.valid = true;
		getLogPlayer()->addOneCycle(_cInfo);
		_cInfo.msg.Empty(); // 清除本周期的消息
		return true;
	case MSG_MODE: {
		my_msginfo_t msg;
		msg.board = pInfo->body.msg.board;
		if( !strncmp(pInfo->body.msg.message,"Recv ",5) ){
			_cInfo.msg += pInfo->body.msg.message;
			_cInfo.msg += MSG_FOOTER ; // 用来表明命令结束
		}
		
		return false;
		}
	case PARAM_MODE:
		getLogPlayer()->setServerParam(&(pInfo->body.sparams));
		return false;
	case PPARAM_MODE:
		getLogPlayer()->setPlayerParam(&(pInfo->body.pparams));
		return false;
	case PT_MODE:
		getLogPlayer()->addPlayerType(&(pInfo->body.ptinfo));
		return false;
	default:
		break;
	};
	return false;
}

CLogParser* CLogParserFactory::getParser(CGZFile &logFile)
{
	char strHead[3];
	logFile.Read(strHead,3);
	if ((strHead[0] == 'U') && (strHead[1] == 'L') && (strHead[2] == 'G')){
		BYTE iVersion;
		logFile.Read(&iVersion,sizeof(iVersion));
		if( iVersion == 3 ){
			return &_V3LogParser ; // log version 3
		}
	}
	
	if ((strHead[0] == 'S') && (strHead[1] == 'L') && (strHead[2] == 'G')){
		return &_SightLogParser ; // my own sight log
	}
	
	return NULL ; // 没有对应的分析类
}

CDispinfoParser* CDispinfoParserFactory::getParser(UINT version)
{
	if( version == 2){
		return &_Dispinfo2Parser;
	}
	return NULL;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -