Exemplo n.º 1
0
void WriteTeamstatHistory(CDemoReader& reader, unsigned team, const std::string& file)
{
    const DemoFileHeader header = reader.GetFileHeader();
    const std::vector< std::vector<TeamStatistics> >& statvec = reader.GetTeamStats();
    if (team < statvec.size())
    {
        int time = 0;
        std::ofstream out(file.c_str());
        out << "Team Statistics for " << team << std::endl;
        out << "Time[sec];MetalUsed;EnergyUsed;MetalProduced;EnergyProduced;MetalExcess;EnergyExcess;"
            << "EnergyReceived;MetalSent;EnergySent;DamageDealt;DamageReceived;"
            << "UnitsProduced;UnitsDied;UnitsReceived;UnitsSent;nitsCaptured;"
            << "UnitsOutCaptured;UnitsKilled" << std::endl;
        for (unsigned i = 0; i < statvec[team].size(); ++i)
        {
            PrintSep(out, time);
            PrintSep(out, statvec[team][i].metalUsed);
            PrintSep(out, statvec[team][i].energyUsed);
            PrintSep(out, statvec[team][i].metalProduced);
            PrintSep(out, statvec[team][i].energyProduced);
            PrintSep(out, statvec[team][i].metalExcess);
            PrintSep(out, statvec[team][i].energyExcess);
            PrintSep(out, statvec[team][i].metalReceived);
            PrintSep(out, statvec[team][i].energyReceived);
            PrintSep(out, statvec[team][i].metalSent);
            PrintSep(out, statvec[team][i].energySent);
            PrintSep(out, statvec[team][i].damageDealt);
            PrintSep(out, statvec[team][i].damageReceived);
            PrintSep(out, statvec[team][i].unitsProduced);
            PrintSep(out, statvec[team][i].unitsDied);
            PrintSep(out, statvec[team][i].unitsReceived);
            PrintSep(out, statvec[team][i].unitsSent);
            PrintSep(out, statvec[team][i].unitsCaptured);
            PrintSep(out, statvec[team][i].unitsOutCaptured);
            PrintSep(out, statvec[team][i].unitsKilled);
            out << std::endl;
            time += header.teamStatPeriod;
        }
    }
    else
    {
        std::wcout << L"Invalid teamnumber" << std::endl;
        exit(1);
    }
};
Exemplo n.º 2
0
void TrafficDump(CDemoReader& reader, bool trafficStats)
{
    InitCommandNames();
    std::vector<unsigned> trafficCounter(NETMSG_LAST, 0);
    int frame = 0;
    int cmdId = 0;
    while (!reader.ReachedEnd())
    {
        netcode::RawPacket* packet;
        packet = reader.GetData(3.402823466e+38f);
        if (packet == NULL)
            continue;
        assert(packet->data[0]<NETMSG_LAST);
        trafficCounter[packet->data[0]] += packet->length;
        const unsigned char* buffer = packet->data;
        char buf[16]; // FIXME: cba to look up how to format numbers with iostreams
        sprintf(buf, "%06d ", frame);
        std::cout << buf;
        const int cmd = (unsigned char)buffer[0];
        switch (cmd)
        {
        case NETMSG_AICOMMAND:
            std::cout << "AICOMMAND: Playernum: " << (unsigned)buffer[3];
            std::cout << " Length: " << (unsigned)packet->length;
            std::cout << " AI id: " << (unsigned)buffer[4];
            std::cout << " UnitId: " << *((short*)(buffer + 5));
            cmdId = *((int*)(buffer + 7));
            std::cout << " CommandId: " << GetCommandName(cmdId) << "(" << cmdId << ")";
            std::cout << " Options: " << (unsigned)buffer[11];
            std::cout << " Parameters:";
            for (unsigned short i = 12; i < packet->length; i += 4) {
                std::cout << " " << *((float*)(buffer + i));
            }
            std::cout << std::endl;
            break;
        case NETMSG_AICOMMANDS: {
            std::cout << "AICOMMANDS: Playernum: " << (unsigned)buffer[3];
            std::cout << " Length: " << (unsigned)packet->length;
            std::cout << " AI id: " << (unsigned)buffer[4];
            std::cout << " Pair: " << (unsigned)buffer[5];
            unsigned int sameid = *((unsigned int*)(buffer + 6));
            std::cout << " SameID: " << sameid;
            unsigned int sameopt = (unsigned)buffer[10];
            std::cout << " SameOpt: " << sameopt;
            unsigned short samesize = *((unsigned short*)(buffer + 11));
            std::cout << " SameSize: " << samesize;
            short uidc = *((short*)(buffer + 13));
            std::cout << " UnitIDCount: " << uidc;
            for (unsigned int i = 0; i < uidc; ++i) {
                std::cout << " " << *((short*)(buffer + 15 + i * 2));
            }
            short cidc = *((short*)(buffer + 15 + uidc * 2));
            int startp = 15 + uidc * 2 + 2;
            std::cout << " CmdIDCount: " << cidc;
            for (unsigned int i = 0; i < cidc; ++i) {
                if (sameid == 0) {
                    std::cout << " " << *((unsigned int*)(buffer + startp));
                    startp += 4;
                }
                if (sameopt == 0xFF) {
                    std::cout << " " << (unsigned)buffer[startp];
                    startp += 1;
                }
                if (sameopt == 0xFFFF) {
                    std::cout << " " << *((unsigned short*)(buffer + startp));
                    startp += 2;
                }
            }
            std::cout << std::endl;
            break;
        }
        case NETMSG_PLAYERNAME:
            std::cout << "PLAYERNAME: Playernum: " << (unsigned)buffer[2] << " Name: " << buffer+3 << std::endl;
            break;
        case NETMSG_SETPLAYERNUM:
            std::cout << "SETPLAYERNUM: Playernum: " << (unsigned)buffer[1] << std::endl;
            break;
        case NETMSG_QUIT:
            std::cout << "QUIT" << std::endl;
            break;
        case NETMSG_STARTPLAYING:
            std::cout << "STARTPLAYING" << std::endl;
            break;
        case NETMSG_STARTPOS:
            std::cout << "STARTPOS: Playernum: " << (unsigned)buffer[1] << " Team: " << (unsigned)buffer[2] << " Readyness: " << (unsigned)buffer[3] << std::endl;
            break;
        case NETMSG_SYSTEMMSG:
            std::cout << "SYSTEMMSG: Player: " << (unsigned)buffer[3] << " Msg: " << (char*)(buffer+4) << std::endl;
            break;
        case NETMSG_CHAT:
            std::cout << "CHAT: Player: " << (unsigned)buffer[2] << " Msg: " << (char*)(buffer+4) << std::endl;
            break;
        case NETMSG_KEYFRAME:
            std::cout << "KEYFRAME: " << *(int*)(buffer+1) << std::endl;
            ++frame;
            if (*(int*)(buffer+1) != frame) {
                std::cout << "keyframe mismatch!" << std::endl;
            }
            break;
        case NETMSG_NEWFRAME:
            std::cout << "NEWFRAME" << std::endl;
            ++frame;
            break;
        case NETMSG_PLAYERINFO:
            std::cout << "NETMSG_PLAYERINFO: Player:" << (int)buffer[1] << " Ping: " << *(uint16_t*)&buffer[6] << std::endl;
            break;
        case NETMSG_LUAMSG:
        {
            std::cout << "LUAMSG length:" << packet->length << " Player:" << (unsigned)buffer[3] << " Script: " << *(uint16_t*)&buffer[4] << " Mode: " << (unsigned)buffer[6] << " Msg: ";
            PrintBinary(&packet->data[7], packet->length);
            std::cout << std::endl;
            break;
        }
        case NETMSG_TEAM:
            std::cout << "TEAM Playernum:" << (int)buffer[1] << " Action:";
            switch (buffer[2]) {
            case TEAMMSG_GIVEAWAY:
                std::cout << "GIVEAWAY";
                break;
            case TEAMMSG_RESIGN:
                std::cout << "RESIGN";
                break;
            case TEAMMSG_TEAM_DIED:
                std::cout << "TEAM_DIED";
                break;
            case TEAMMSG_JOIN_TEAM:
                std::cout << "JOIN_TEAM";
                break;
            default:
                std::cout << (int)buffer[2];
            }
            std::cout << " Parameter:" << (int)buffer[3] << std::endl;
            break;
        case NETMSG_COMMAND:
            std::cout << "COMMAND Playernum:" << (int)buffer[3] << " Size: " << *(unsigned short*)(buffer+1) << std::endl;
            if (*(unsigned short*)(buffer+1) != packet->length)
                std::cout << "      packet length error: expected: " <<  *(unsigned short*)(buffer+1) << " got: " << packet->length << std::endl;
            break;
        case NETMSG_SELECT:
            std::cout << "NETMGS_SELECT: Playernum: " << (unsigned)buffer[3];
            std::cout << " Length: " << (unsigned)packet->length;
            std::cout << " Unit IDs:";
            for (unsigned short i = 4; i < packet->length; i += 2) {
                std::cout << " " << *((short*)(buffer + i));
            }
            std::cout << std::endl;
            break;
        case NETMSG_GAMEOVER:
            std::cout << "NETMSG_GAMEOVER" << std::endl;
            break;
        case NETMSG_MAPDRAW:
            std::cout << "NETMSG_MAPDRAW" << std::endl;
            break;
        case NETMSG_PATH_CHECKSUM:
            std::cout << "NETMSG_PATH_CHECKSUM" << std::endl;
            break;
        case NETMSG_INTERNAL_SPEED:
            std::cout << "NETMSG_INTERNAL_SPEED" << std::endl;
            break;
        case NETMSG_PLAYERLEFT:
            std::cout << "NETMSG_PLAYERLEFT" << std::endl;
            break;
        case NETMSG_GAMEDATA:
            std::cout << "NETMSG_GAMEDATA" << std::endl;
            break;
        case NETMSG_CREATE_NEWPLAYER:
            std::cout << "NETMSG_CREATE_NEWPLAYER" << std::endl;
            break;
        case NETMSG_GAMEID:
            std::cout << "NETMSG_GAMEID" << std::endl;
            break;
        case NETMSG_RANDSEED:
            std::cout << "NETMSG_RANDSEED" << std::endl;
            break;
        case NETMSG_SHARE:
            std::cout << "NETMSG_SHARE: Playernum: " << (unsigned)buffer[1];
            std::cout << " Team: " << (unsigned)buffer[2];
            std::cout << " ShareUnits: " << (unsigned)buffer[3];
            std::cout << " Metal: " << *(float*)(buffer + 4);
            std::cout << " Energy: " << *(float*)(buffer + 8);
            std::cout << std::endl;
            break;
        case NETMSG_CCOMMAND:
            std::cout << "NETMSG_CCOMMAND: " << std::endl;
            break;
        case NETMSG_PAUSE:
            std::cout << "NETMSG_PAUSE: Player " << (unsigned)buffer[1] << " paused: " << (unsigned)buffer[2] << std::endl;
            break;
        case NETMSG_SYNCRESPONSE:
            std::cout << "NETMSG_SYNCRESPONSE: " << std::endl;
            break;
        case NETMSG_DIRECT_CONTROL:
            std::cout << "NETMSG_DIRECT_CONTROL: " << std::endl;
            break;
        case NETMSG_SETSHARE:
            std::cout << "NETMSG_SETSHARE: " << std::endl;
            break;
        default:
            std::cout << "MSG: " << cmd << std::endl;
        }
        delete packet;
    }

    // how many times did each message appear
    for (unsigned i = 0; i != trafficCounter.size(); ++i)
    {
        if (trafficStats && trafficCounter[i] > 0)
            std::cout << "Msg " << i << ": " << trafficCounter[i] << std::endl;
    }
}
Exemplo n.º 3
0
void TrafficDump(CDemoReader& reader, bool trafficStats)
{
	InitCommandNames();

	std::vector<unsigned> trafficCounter(55, 0);
	int frame = 0;
	int cmdId = 0;
	while (!reader.ReachedEnd())
	{
		netcode::RawPacket* packet;
		packet = reader.GetData(3.40282347e+38f);
		if (packet == 0)
			continue;
		trafficCounter[packet->data[0]] += packet->length;
		const unsigned char* buffer = packet->data;
		char buf[16]; // FIXME: cba to look up how to format numbers with iostreams
		sprintf(buf, "%06d ", frame);
		std::cout << buf;
		switch ((unsigned char)buffer[0])
		{
			case NETMSG_AICOMMAND:
				std::cout << "AICOMMAND: Playernum: " << (unsigned)buffer[3];
				std::cout << " Length: " << (unsigned)packet->length;
				std::cout << " UnitId: " << *((short*)(buffer + 4));
				cmdId = *((int*)(buffer + 6));
				std::cout << " CommandId: " << GetCommandName(cmdId) << "(" << cmdId << ")";
				std::cout << " Options: " << (unsigned)buffer[10];
				std::cout << " Parameters:";
				for (unsigned short i = 11; i < packet->length; i += 4) {
					std::cout << " " << *((float*)(buffer + i));
				}
				std::cout << std::endl;
				break;
			case NETMSG_PLAYERNAME:
				std::cout << "PLAYERNAME: Playernum: " << (unsigned)buffer[2] << " Name: " << buffer+3 << std::endl;
				break;
			case NETMSG_SETPLAYERNUM:
				std::cout << "SETPLAYERNUM: Playernum: " << (unsigned)buffer[1] << std::endl;
				break;
			case NETMSG_QUIT:
				std::cout << "QUIT" << std::endl;
				break;
			case NETMSG_STARTPLAYING:
				std::cout << "STARTPLAYING" << std::endl;
				break;
			case NETMSG_STARTPOS:
				std::cout << "STARTPOS: Playernum: " << (unsigned)buffer[1] << " Team: " << (unsigned)buffer[2] << " Readyness: " << (unsigned)buffer[3] << std::endl;
				break;
			case NETMSG_SYSTEMMSG:
				std::cout << "SYSTEMMSG: Player: " << (unsigned)buffer[3] << " Msg: " << (char*)(buffer+4) << std::endl;
				break;
			case NETMSG_CHAT:
				std::cout << "CHAT: Player: " << (unsigned)buffer[2] << " Msg: " << (char*)(buffer+4) << std::endl;
				break;
			case NETMSG_KEYFRAME:
				std::cout << "KEYFRAME: " << *(int*)(buffer+1) << std::endl;
				++frame;
				if (*(int*)(buffer+1) != frame) {
					std::cout << "keyframe mismatch!" << std::endl;
				}
				break;
			case NETMSG_NEWFRAME:
				std::cout << "NEWFRAME" << std::endl;
				++frame;
				break;
			case NETMSG_PLAYERINFO:
				std::cout << "NETMSG_PLAYERINFO: Player:" << (int)buffer[1] << " Ping: " << *(uint16_t*)&buffer[6] << std::endl;
				break;
			case NETMSG_LUAMSG:
				std::cout << "LUAMSG length:" << packet->length << std::endl;
				break;
			case NETMSG_TEAM:
				std::cout << "TEAM Playernum:" << (int)buffer[1] << " Action:";
				switch (buffer[2]) {
					case TEAMMSG_GIVEAWAY: std::cout << "GIVEAWAY"; break;
					case TEAMMSG_RESIGN: std::cout << "RESIGN"; break;
					case TEAMMSG_TEAM_DIED: std::cout << "TEAM_DIED"; break;
					case TEAMMSG_JOIN_TEAM: std::cout << "JOIN_TEAM"; break;
					default: std::cout << (int)buffer[2];
				}
				std::cout << " Parameter:" << (int)buffer[3] << std::endl;
				break;
			case NETMSG_COMMAND:
				std::cout << "COMMAND Playernum:" << (int)buffer[3] << " Size: " << *(unsigned short*)(buffer+1) << std::endl;
				if (*(unsigned short*)(buffer+1) != packet->length)
					std::cout << "      packet length error: expected: " <<  *(unsigned short*)(buffer+1) << " got: " << packet->length << std::endl;
				break;
			default:
				std::cout << "MSG: " << (unsigned)buffer[0] << std::endl;
		}
		delete packet;
	}

	// how many times did each message appear
	for (unsigned i = 0; i != trafficCounter.size(); ++i)
	{
		if (trafficStats && trafficCounter[i] > 0)
			std::cout << "Msg " << i << ": " << trafficCounter[i] << std::endl;
	}
}