🐶
This commit is contained in:
		| @@ -954,7 +954,6 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf) { | ||||
| 	std::vector<char*> lsPck; | ||||
| 	int len = 0, end = 0; | ||||
| 	char * cursor = nullptr, * next = buf->ptr, * last = buf->ptr; | ||||
| 	const char footer[sizeof(uint32_t)] = { '\0', '\r', '\0', '\n' }; | ||||
|  | ||||
| 	while (true) { | ||||
| 		int bytes = recv(sock, &buf->ptr[len], buf->len - len, 0); | ||||
| @@ -978,7 +977,7 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf) { | ||||
| 				cursor--; | ||||
| 				next = cursor + 1; | ||||
|  | ||||
| 				cmp = memcmp(cursor, footer, sizeof(uint32_t)); | ||||
| 				cmp = memcmp(cursor, Footer, sizeof(uint32_t)); | ||||
| 				if (cmp == 0) { | ||||
| 					lsPck.push_back(last); | ||||
| 					cursor += sizeof(uint32_t); | ||||
| @@ -996,45 +995,45 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf) { | ||||
| } | ||||
|  | ||||
| template <> | ||||
| void netprot::sendPack<netprot::Packet>(SOCKET sock, Packet* pack, char** buf, uint32_t* buflen) { | ||||
| void netprot::sendPack<netprot::Packet>(SOCKET sock, Packet* pack, Buffer* buf) { | ||||
| 	switch (pack->type) { | ||||
| 	case PACKET_TYPE::INPUT: | ||||
| 		sendPack<Input>(sock, (Input*)pack->ptr, buf, buflen); | ||||
| 		sendPack<Input>(sock, (Input*)pack->ptr, buf); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::OUTPUT: | ||||
| 		sendPack<Output>(sock, (Output*)pack->ptr, buf, buflen); | ||||
| 		sendPack<Output>(sock, (Output*)pack->ptr, buf); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::SYNC: | ||||
| 		sendPack<Sync>(sock, (Sync*)pack->ptr, buf, buflen); | ||||
| 		sendPack<Sync>(sock, (Sync*)pack->ptr, buf); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::TEAMINF: | ||||
| 		sendPack<TeamInfo>(sock, (TeamInfo*)pack->ptr, buf, buflen); | ||||
| 		sendPack<TeamInfo>(sock, (TeamInfo*)pack->ptr, buf); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::PLAYINF: | ||||
| 		sendPack<PlayerInfo>(sock, (PlayerInfo*)pack->ptr, buf, buflen); | ||||
| 		sendPack<PlayerInfo>(sock, (PlayerInfo*)pack->ptr, buf); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::LOGINF: | ||||
| 		sendPack<LoginInfo>(sock, (LoginInfo*)pack->ptr, buf, buflen); | ||||
| 		sendPack<LoginInfo>(sock, (LoginInfo*)pack->ptr, buf); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::CHUNKMOD: | ||||
| 		//sendPack<ChunkMod>(sock, (ChunkMod*)pack->ptr, buf, buflen); | ||||
| 		//sendPack<ChunkMod>(sock, (ChunkMod*)pack->ptr, buf); | ||||
| 	case PACKET_TYPE::PLAYERMOD: | ||||
| 		//sendPack<PlayerMod>(sock, (PlayerMod*)pack->ptr, buf, buflen); | ||||
| 		//sendPack<PlayerMod>(sock, (PlayerMod*)pack->ptr, buf); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::PICKUPMOD: | ||||
| 		//sendPack<PickupMod>(sock, (PickupMod*)pack->ptr, buf, buflen); | ||||
| 		//sendPack<PickupMod>(sock, (PickupMod*)pack->ptr, buf); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::GAMEINFO: | ||||
| 		sendPack<GameInfo>(sock, (GameInfo*)pack->ptr, buf, buflen); | ||||
| 		sendPack<GameInfo>(sock, (GameInfo*)pack->ptr, buf); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::ENDINFO: | ||||
| 		//sendPack<EndInfo>(sock, (EndInfo*)pack->ptr, buf, buflen); | ||||
| 		//sendPack<EndInfo>(sock, (EndInfo*)pack->ptr, buf); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::CHAT: | ||||
| 		sendPack<Chat>(sock, (Chat*)pack->ptr, buf, buflen); | ||||
| 		sendPack<Chat>(sock, (Chat*)pack->ptr, buf); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::ERRLOG: | ||||
| 		sendPack<ErrorLog>(sock, (ErrorLog*)pack->ptr, buf, buflen); | ||||
| 		sendPack<ErrorLog>(sock, (ErrorLog*)pack->ptr, buf); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::LAST_PACK: [[fallthrough]]; | ||||
| 	case PACKET_TYPE::ERR: [[fallthrough]]; | ||||
| @@ -1044,46 +1043,46 @@ void netprot::sendPack<netprot::Packet>(SOCKET sock, Packet* pack, char** buf, u | ||||
| } | ||||
|  | ||||
| template <> | ||||
| void netprot::sendPackTo<netprot::Packet>(SOCKET sock, Packet* pack, char** buf, uint32_t* buflen, sockaddr_in* sockad) { | ||||
| void netprot::sendPackTo<netprot::Packet>(SOCKET sock, Packet* pack, Buffer* buf, sockaddr_in* sockad) { | ||||
| 	switch (pack->type) { | ||||
| 	case PACKET_TYPE::INPUT: | ||||
| 		sendPackTo<Input>(sock, (Input*)pack->ptr, buf, buflen, sockad); | ||||
| 		sendPackTo<Input>(sock, (Input*)pack->ptr, buf, sockad); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::OUTPUT: | ||||
| 		sendPackTo<Output>(sock, (Output*)pack->ptr, buf, buflen, sockad); | ||||
| 		sendPackTo<Output>(sock, (Output*)pack->ptr, buf, sockad); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::SYNC: | ||||
| 		sendPackTo<Sync>(sock, (Sync*)pack->ptr, buf, buflen, sockad); | ||||
| 		sendPackTo<Sync>(sock, (Sync*)pack->ptr, buf, sockad); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::TEAMINF: | ||||
| 		sendPackTo<TeamInfo>(sock, (TeamInfo*)pack->ptr, buf, buflen, sockad); | ||||
| 		sendPackTo<TeamInfo>(sock, (TeamInfo*)pack->ptr, buf, sockad); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::PLAYINF: | ||||
| 		sendPackTo<PlayerInfo>(sock, (PlayerInfo*)pack->ptr, buf, buflen, sockad); | ||||
| 		sendPackTo<PlayerInfo>(sock, (PlayerInfo*)pack->ptr, buf, sockad); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::LOGINF: | ||||
| 		sendPackTo<LoginInfo>(sock, (LoginInfo*)pack->ptr, buf, buflen, sockad); | ||||
| 		sendPackTo<LoginInfo>(sock, (LoginInfo*)pack->ptr, buf, sockad); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::CHUNKMOD: | ||||
| 		//sendPackTo<ChunkMod>(sock, (ChunkMod*)pack->ptr, buf, buflen, sockad); | ||||
| 		//sendPackTo<ChunkMod>(sock, (ChunkMod*)pack->ptr, buf, sockad); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::PLAYERMOD: | ||||
| 		//sendPackTo<PlayerMod>(sock, (PlayerMod*)pack->ptr, buf, buflen, sockad); | ||||
| 		//sendPackTo<PlayerMod>(sock, (PlayerMod*)pack->ptr, buf, sockad); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::PICKUPMOD: | ||||
| 		//sendPackTo<PickupMod>(sock, (PickupMod*)pack->ptr, buf, buflen, sockad); | ||||
| 		//sendPackTo<PickupMod>(sock, (PickupMod*)pack->ptr, buf, sockad); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::GAMEINFO: | ||||
| 		sendPackTo<GameInfo>(sock, (GameInfo*)pack->ptr, buf, buflen, sockad); | ||||
| 		sendPackTo<GameInfo>(sock, (GameInfo*)pack->ptr, buf, sockad); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::ENDINFO: | ||||
| 		//sendPackTo<EndInfo>(sock, (EndInfo*)pack->ptr, buf, buflen, sockad); | ||||
| 		//sendPackTo<EndInfo>(sock, (EndInfo*)pack->ptr, buf, sockad); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::CHAT: | ||||
| 		sendPackTo<Chat>(sock, (Chat*)pack->ptr, buf, buflen, sockad); | ||||
| 		sendPackTo<Chat>(sock, (Chat*)pack->ptr, buf, sockad); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::ERRLOG: | ||||
| 		sendPackTo<ErrorLog>(sock, (ErrorLog*)pack->ptr, buf, buflen, sockad); | ||||
| 		sendPackTo<ErrorLog>(sock, (ErrorLog*)pack->ptr, buf, sockad); | ||||
| 		return; | ||||
| 	case PACKET_TYPE::LAST_PACK: [[fallthrough]]; | ||||
| 	case PACKET_TYPE::ERR: [[fallthrough]]; | ||||
|   | ||||
| @@ -31,6 +31,8 @@ namespace netprot { | ||||
| 		PACKET_TYPE type = PACKET_TYPE::ERR; | ||||
| 	}; | ||||
|  | ||||
| 	inline const char Footer[sizeof(uint32_t)] = { '\0', '\r', '\0', '\n' }; | ||||
|  | ||||
| 	struct Keys { | ||||
| 		bool forward,  | ||||
| 			 backward,  | ||||
| @@ -165,39 +167,37 @@ namespace netprot { | ||||
| 	template <class T> | ||||
| 	void sendPack(SOCKET sock, T* pack, char** buf, uint32_t* buflen) { | ||||
| 		netprot::Serialize(pack, buf, buflen); | ||||
| 		memset(&buf[*buflen], '\0', sizeof(uint64_t) + sizeof(uint8_t)); | ||||
| 		buflen += (sizeof(uint64_t) + sizeof(uint8_t)); | ||||
| 		memcpy(*buf + *buflen, Footer, sizeof(uint32_t)); | ||||
| 		*buflen += sizeof(Footer); | ||||
| 		send(sock, *buf, *buflen, 0); | ||||
| 		*buflen = BUFFER_LENGTH; | ||||
| 	} | ||||
|  | ||||
| 	template <class T> | ||||
| 	void sendPackTo(SOCKET sock, T* pack, char** buf, uint32_t* buflen, sockaddr_in* sockad) { | ||||
| 		sockaddr_in addr = *sockad; | ||||
| 		const sockaddr_in addr = *sockad; | ||||
| 		netprot::Serialize(pack, buf, buflen); | ||||
| 		memset(&buf[*buflen], '\0', sizeof(uint64_t) + sizeof(uint8_t)); | ||||
| 		buflen += (sizeof(uint64_t) + sizeof(uint8_t)); | ||||
| 		memcpy(*buf + *buflen, Footer, sizeof(uint32_t)); | ||||
| 		*buflen += sizeof(Footer); | ||||
| 		sendto(sock, *buf, *buflen, 0, (sockaddr*)&addr, sizeof(addr)); | ||||
| 		*buflen = BUFFER_LENGTH; | ||||
| 	} | ||||
|  | ||||
| 	template <class T> | ||||
| 	void sendPack(SOCKET sock, T* pack, Buffer* buf) { | ||||
| 		const char footer[sizeof(uint32_t)] = { '\0', '\r', '\0', '\n' }; | ||||
| 		netprot::Serialize(pack, &buf->ptr, &buf->len); | ||||
| 		memcpy(&buf->ptr[buf->len], footer, sizeof(uint32_t)); | ||||
| 		buf->len += sizeof(uint32_t); | ||||
| 		memcpy(&buf->ptr[buf->len], Footer, sizeof(uint32_t)); | ||||
| 		buf->len += sizeof(Footer); | ||||
| 		send(sock, buf->ptr, buf->len, 0); | ||||
| 		buf->rstLen(); | ||||
| 	} | ||||
|  | ||||
| 	template <class T> | ||||
| 	void sendPackTo(SOCKET sock, T* pack, Buffer* buf, sockaddr_in* sockad) { | ||||
| 		const char footer[sizeof(uint32_t)] = { '\0', '\r', '\0', '\n' }; | ||||
| 		sockaddr_in addr = *sockad; | ||||
| 		const sockaddr_in addr = *sockad; | ||||
| 		netprot::Serialize(pack, &buf->ptr, &buf->len); | ||||
| 		memcpy(&buf->ptr[buf->len], footer, sizeof(uint32_t)); | ||||
| 		buf->len += sizeof(uint32_t); | ||||
| 		memcpy(&buf->ptr[buf->len], Footer, sizeof(uint32_t)); | ||||
| 		buf->len += sizeof(Footer); | ||||
| 		sendto(sock, buf->ptr, buf->len, 0, (sockaddr*)&addr, sizeof(addr)); | ||||
| 		buf->rstLen(); | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user