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; Keys keys = in->keys;
uint8_t keys8 = // Reste un bit. uint8_t keys8 = // Reste un bit.
keys.forward & 0b10000000 | (keys.forward? 0b10000000: 0) |
keys.backward & 0b01000000 | (keys.backward? 0b01000000: 0) |
keys.left & 0b00100000 | (keys.left? 0b00100000: 0) |
keys.right & 0b00010000 | (keys.right? 0b00010000: 0) |
keys.jump & 0b00001000 | (keys.jump? 0b00001000: 0) |
keys.shoot & 0b00000100 | (keys.shoot? 0b00000100: 0) |
keys.block & 0b00000010; (keys.block? 0b00000010: 0);
memcpy(*buf + sizeof(uint64_t) * 2 + 1, &keys8, sizeof(uint8_t)); memcpy(*buf + sizeof(uint64_t) * 2 + 1, &keys8, sizeof(uint8_t));
@ -432,6 +432,8 @@ bool netprot::Deserialize(Input* in, char* buf, uint32_t *buflen) {
(uint64_t)diff[6] << 8 | (uint64_t)diff[6] << 8 |
(uint64_t)diff[7]; (uint64_t)diff[7];
std::cout << in->timestamp << ": ";
memcpy(diff, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t)); memcpy(diff, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t));
in->sid = in->sid =
(uint64_t)diff[0] << 56 | (uint64_t)diff[0] << 56 |
@ -443,6 +445,8 @@ bool netprot::Deserialize(Input* in, char* buf, uint32_t *buflen) {
(uint64_t)diff[6] << 8 | (uint64_t)diff[6] << 8 |
(uint64_t)diff[7]; (uint64_t)diff[7];
std::cout << in->sid << ": ";
uint8_t keys = 0; uint8_t keys = 0;
memcpy(&keys, &buf[1 + sizeof(uint64_t) * 2], sizeof(uint8_t)); memcpy(&keys, &buf[1 + sizeof(uint64_t) * 2], sizeof(uint8_t));
in->keys.forward = keys & 0b10000000; 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.shoot = keys & 0b00000100;
in->keys.block = keys & 0b00000010; 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 }; 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); memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2], sizeof(uint8_t) * 12);
uint32_t vec[3] = { 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); memcpy(&in->direction, vec, sizeof(uint32_t) * 3);
in->direction.Afficher();
*buflen = sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 3; *buflen = sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 3;
return true; return true;

View File

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