This commit is contained in:
MarcEricMartel 2023-11-24 13:42:53 -05:00
parent d7bd36d134
commit c1aa321f2b
2 changed files with 28 additions and 10 deletions

View File

@ -29,13 +29,13 @@ void netprot::Serialize(Input* in, char* buf[], uint32_t* buflen) {
Keys keys = in->keys;
uint8_t keys8 = // Reste un bit.
keys.forward & 0b10000000 |
keys.backward & 0b01000000 |
keys.left & 0b00100000 |
keys.right & 0b00010000 |
keys.jump & 0b00001000 |
keys.shoot & 0b00000100 |
keys.block & 0b00000010;
(keys.forward? 0b10000000: 0) |
(keys.backward? 0b01000000: 0) |
(keys.left? 0b00100000: 0) |
(keys.right? 0b00010000: 0) |
(keys.jump? 0b00001000: 0) |
(keys.shoot? 0b00000100: 0) |
(keys.block? 0b00000010: 0);
memcpy(*buf + sizeof(uint64_t) * 2 + 1, &keys8, sizeof(uint8_t));
@ -431,6 +431,8 @@ bool netprot::Deserialize(Input* in, char* buf, uint32_t *buflen) {
(uint64_t)diff[5] << 16 |
(uint64_t)diff[6] << 8 |
(uint64_t)diff[7];
std::cout << in->timestamp << ": ";
memcpy(diff, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t));
in->sid =
@ -443,6 +445,8 @@ bool netprot::Deserialize(Input* in, char* buf, uint32_t *buflen) {
(uint64_t)diff[6] << 8 |
(uint64_t)diff[7];
std::cout << in->sid << ": ";
uint8_t keys = 0;
memcpy(&keys, &buf[1 + sizeof(uint64_t) * 2], sizeof(uint8_t));
in->keys.forward = keys & 0b10000000;
@ -453,6 +457,16 @@ bool netprot::Deserialize(Input* in, char* buf, uint32_t *buflen) {
in->keys.shoot = keys & 0b00000100;
in->keys.block = keys & 0b00000010;
std::cout << (int)keys << ": "
<< (in->keys.forward ? "F" : "_")
<< (in->keys.backward ? "B" : "_")
<< (in->keys.left ? "L" : "_")
<< (in->keys.right ? "R" : "_")
<< (in->keys.jump ? "J" : "_")
<< (in->keys.shoot ? "S" : "_")
<< (in->keys.block ? "B" : "_")
<< ": ";
uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2], sizeof(uint8_t) * 12);
uint32_t vec[3] = {
@ -471,6 +485,8 @@ bool netprot::Deserialize(Input* in, char* buf, uint32_t *buflen) {
memcpy(&in->direction, vec, sizeof(uint32_t) * 3);
in->direction.Afficher();
*buflen = sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 3;
return true;

View File

@ -52,14 +52,16 @@ void Connection::getPacks(SOCKET sock) {
Input in;
while (true) {
lsPck = recvPacksFrom(sock, &m_buf, m_addr);
for (auto& pck : lsPck) {
uint32_t bsize = m_buf.len - (pck - m_buf.ptr);
switch (netprot::getType(pck, 1)) {
using enum netprot::PACKET_TYPE;
case INPUT:
if (Deserialize(&in, pck, &bsize))
if (Deserialize(&in, pck, &bsize)) {
m_input_manifest[in.timestamp] = in;
if (in.keys.forward == true)
std::cout << "!!!!";
}
break;
default: break;
}
@ -71,7 +73,7 @@ void Connection::getPacks(SOCKET sock) {
void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*> conns) {
while (m_last_out < m_output_manifest.size()) {
Output out = m_output_manifest.at(m_last_out++);
std::cout << "bip";
for (auto& [key, conn] : conns) {
if (m_playinfo.id == conn->GetHash(true))
continue;