diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h index cfb4fae..8060703 100644 --- a/SQCSim-common/define.h +++ b/SQCSim-common/define.h @@ -44,6 +44,7 @@ typedef uint64_t Timestamp; #include #include +#define addrlen_t int #define popen _popen #define pclose _pclose @@ -57,6 +58,7 @@ typedef uint64_t Timestamp; #include #include +#define addrlen_t unsigned int #define SOCKET int #define INVALID_SOCKET -1 #define closesocket close diff --git a/SQCSim-common/netprotocol.cpp b/SQCSim-common/netprotocol.cpp index d4edca2..b71662c 100644 --- a/SQCSim-common/netprotocol.cpp +++ b/SQCSim-common/netprotocol.cpp @@ -281,7 +281,61 @@ void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) { bool netprot::Deserialize(Input* in, char* buf, const uint32_t buflen) { - return false; + if (buflen <= sizeof(Input)) + return false; + + uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; + memcpy(diff, &buf[1], sizeof(uint64_t)); + in->timestamp = + (uint64_t)diff[0] << 56 | + (uint64_t)diff[1] << 48 | + (uint64_t)diff[2] << 40 | + (uint64_t)diff[3] << 32 | + (uint64_t)diff[4] << 24 | + (uint64_t)diff[5] << 16 | + (uint64_t)diff[6] << 8 | + (uint64_t)diff[7]; + + memcpy(diff, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t)); + in->sid = + (uint64_t)diff[0] << 56 | + (uint64_t)diff[1] << 48 | + (uint64_t)diff[2] << 40 | + (uint64_t)diff[3] << 32 | + (uint64_t)diff[4] << 24 | + (uint64_t)diff[5] << 16 | + (uint64_t)diff[6] << 8 | + (uint64_t)diff[7]; + + uint8_t keys = 0; + memcpy(&keys, &buf[2 + sizeof(uint64_t)], sizeof(uint8_t)); + in->keys.forward = keys && 0b10000000; + in->keys.backward = keys && 0b01000000; + in->keys.left = keys && 0b00100000; + in->keys.right = keys && 0b00010000; + in->keys.jump = keys && 0b00001000; + in->keys.shoot = keys && 0b00000100; + in->keys.block = keys && 0b00000010; + + uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 }; + memcpy(subvec, &buf[3 + sizeof(uint64_t)], sizeof(uint8_t) * 12); + uint32_t vec[3] = { + (uint32_t)subvec[0] << 24 | + (uint32_t)subvec[1] << 16 | + (uint32_t)subvec[2] << 8 | + (uint32_t)subvec[3], + (uint32_t)subvec[4] << 24 | + (uint32_t)subvec[5] << 16 | + (uint32_t)subvec[6] << 8 | + (uint32_t)subvec[7], + (uint32_t)subvec[8] << 24 | + (uint32_t)subvec[9] << 16 | + (uint32_t)subvec[10] << 8 | + (uint32_t)subvec[11]}; + + memcpy(&in->direction, vec, sizeof(uint32_t) * 3); + + return true; } bool netprot::Deserialize(Output* out, char* buf, const uint32_t buflen) { diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index 8324d23..9c647d8 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -104,16 +104,10 @@ int Server::Ready() { buildIdList(ID_LIST_SIZE); - - while (!readystart) { sockaddr_in sockad; -#ifdef _WIN32 - int addrlen = sizeof(sockad); -#else // maudit que c'est con, ça. - unsigned int addrlen = sizeof(sockad); -#endif + addrlen_t addrlen = sizeof(sockad); SOCKET sock = accept(m_sock_tcp, (sockaddr*)&sockad, &addrlen); @@ -223,7 +217,7 @@ void Server::Log(std::string str, bool is_error = false, bool is_fatal = false) void Server::buildIdList(size_t size) { std::set lst; - do lst.insert(((uint64_t)rand() << 25) % 8675309); // EIGHT SIX SEVENFIVE THREE AUGHT NIIIIIIiIIiiIiINE! + do lst.insert(((uint64_t)rand() << 32 | rand())); // EIGHT SIX SEVENFIVE THREE AUGHT NIIIIIIiIIiiIiINE! while (lst.size() < size); m_ids = std::vector(lst.begin(), lst.end());