Beispiel #1
0
void CInMapDraw::GotNetMsg(const unsigned char* msg)
{
	const int playerID = msg[2];

	if ((playerID < 0) || (playerID >= playerHandler->ActivePlayers())) {
		return;
	}
	const CPlayer* sender = playerHandler->Player(playerID);
	if (sender == NULL) {
		return;
	}

	switch (msg[3]) {
		case NET_POINT: {
			const float3 pos(*(short*) &msg[4], 0, *(short*) &msg[6]);
			const bool fromLua = msg[8];
			const string label = (char*) &msg[9];
			if (!fromLua || allowLuaMapDrawing) {
				LocalPoint(pos, label, playerID);
			}
			break;
		}
		case NET_LINE: {
			const float3 pos1(*(short*) &msg[4], 0, *(short*) &msg[6]);
			const float3 pos2(*(short*) &msg[8], 0, *(short*) &msg[10]);
			const bool fromLua = msg[12];
			if (!fromLua || allowLuaMapDrawing) {
				LocalLine(pos1, pos2, playerID);
			}
			break;
		}
		case NET_ERASE: {
			float3 pos(*(short*) &msg[4], 0, *(short*) &msg[6]);
			LocalErase(pos, playerID);
			break;
		}
	}
}
void CInMapDraw::GotNetMsg(const unsigned char* msg)
{
	const int playerID = msg[2];

	switch (msg[3]) {
		case NET_POINT: {
			float3 pos(*(short*) &msg[4], 0, *(short*) &msg[6]);
			const string label = (char*) &msg[8];
			LocalPoint(pos, label, playerID);
			break;
		}
		case NET_LINE: {
			float3 pos1(*(short*) &msg[4], 0, *(short*) &msg[6]);
			float3 pos2(*(short*) &msg[8], 0, *(short*) &msg[10]);
			LocalLine(pos1, pos2, playerID);
			break;
		}
		case NET_ERASE: {
			float3 pos(*(short*) &msg[4], 0, *(short*) &msg[6]);
			LocalErase(pos, playerID);
			break;
		}
	}
}
Beispiel #3
0
int CInMapDraw::GotNetMsg(boost::shared_ptr<const netcode::RawPacket> &packet)
{
	int playerID = -1;

	try {
		netcode::UnpackPacket pckt(packet, 2);

		unsigned char uPlayerID;
		pckt >> uPlayerID;
		if (uPlayerID >= playerHandler->ActivePlayers()) {
			throw netcode::UnpackPacketException("Invalid player number");
		}
		playerID = uPlayerID;

		const CPlayer* sender = playerHandler->Player(playerID);

		unsigned char drawType;
		pckt >> drawType;

		switch (drawType) {
			case MAPDRAW_POINT: {
				short int x,z;
				pckt >> x;
				pckt >> z;
				const float3 pos(x, 0, z);
				unsigned char fromLua;
				pckt >> fromLua;
				string label;
				pckt >> label;
				if (!fromLua || allowLuaMapDrawing) {
					LocalPoint(pos, label, playerID);
				}
				break;
			}
			case MAPDRAW_LINE: {
				short int x1,z1,x2,z2;
				pckt >> x1;
				pckt >> z1;
				pckt >> x2;
				pckt >> z2;
				const float3 pos1(x1, 0, z1);
				const float3 pos2(x2, 0, z2);
				unsigned char fromLua;
				pckt >> fromLua;
				if (!fromLua || allowLuaMapDrawing) {
					LocalLine(pos1, pos2, playerID);
				}
				break;
			}
			case MAPDRAW_ERASE: {
				short int x,z;
				pckt >> x;
				pckt >> z;
				float3 pos(x, 0, z);
				LocalErase(pos, playerID);
				break;
			}
		}
	} catch (netcode::UnpackPacketException &e) {
		logOutput.Print("Got invalid MapDraw: %s", e.err.c_str());
		playerID = -1;
	}

	return playerID;
}