direction fonctionnelle!

This commit is contained in:
MarcEricMartel 2023-10-24 07:32:16 -04:00
parent 2c3abff96f
commit ffeb95d953
3 changed files with 59 additions and 9 deletions

View File

@ -44,6 +44,7 @@ typedef uint64_t Timestamp;
#include <cstdio>
#include <ctime>
#define addrlen_t int
#define popen _popen
#define pclose _pclose
@ -57,6 +58,7 @@ typedef uint64_t Timestamp;
#include <netinet/in.h>
#include <cstring>
#define addrlen_t unsigned int
#define SOCKET int
#define INVALID_SOCKET -1
#define closesocket close

View File

@ -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) {

View File

@ -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<uint64_t> 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<uint64_t>(lst.begin(), lst.end());