*guttural scream*
This commit is contained in:
parent
48078182a1
commit
88a8553608
@ -531,25 +531,7 @@ bool netprot::Deserialize(Output* out, char* buf, uint32_t *buflen) {
|
||||
|
||||
memcpy(&out->direction, vec, sizeof(uint32_t) * 3);
|
||||
|
||||
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(uint32_t) * 3], 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(&out->direction, vec, sizeof(uint32_t) * 3);
|
||||
|
||||
memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 6], sizeof(uint8_t) * 12);
|
||||
uint32_t vec2[3] = {
|
||||
(uint32_t)subvec[0] << 24 |
|
||||
(uint32_t)subvec[1] << 16 |
|
||||
@ -971,9 +953,8 @@ netprot::Packet netprot::makePack(void* ptr, PACKET_TYPE type) {
|
||||
std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf) {
|
||||
std::vector<char*> lsPck;
|
||||
int len = 0, end = 0;
|
||||
bool pck_received = false;
|
||||
char * cursor = nullptr, * next = buf->ptr, * last = buf->ptr;
|
||||
const char footer[sizeof(uint64_t) + sizeof(uint8_t)] = { '\0', '\0', '\0', '\0', '\0' };
|
||||
const char footer[sizeof(uint32_t)] = { '\0', '\r', '\0', '\n' };
|
||||
|
||||
while (true) {
|
||||
int bytes = recv(sock, &buf->ptr[len], buf->len - len, 0);
|
||||
@ -982,6 +963,23 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf) {
|
||||
len += bytes;
|
||||
end = len;
|
||||
|
||||
for (int x = 0; x < len; ++x)
|
||||
switch (buf->ptr[x]) {
|
||||
case '\0':
|
||||
std::putchar('n');
|
||||
break;
|
||||
case '\r':
|
||||
std::putchar('i');
|
||||
break;
|
||||
case '\n':
|
||||
std::putchar('a');
|
||||
break;
|
||||
default:
|
||||
std::putchar(buf->ptr[x]);
|
||||
break;
|
||||
}
|
||||
std::puts("");
|
||||
|
||||
while (true) {
|
||||
int cmp = 0;
|
||||
|
||||
@ -991,14 +989,16 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf) {
|
||||
if (end < 0)
|
||||
break;
|
||||
|
||||
cursor = (char*)memchr(next, '\0', end);
|
||||
next = cursor + 1;
|
||||
cursor = (char*)memchr(next, '\r', end);
|
||||
|
||||
if (cursor) {
|
||||
cmp = memcmp(cursor, &footer, sizeof(uint64_t) + sizeof(uint8_t));
|
||||
cursor--;
|
||||
next = cursor + 1;
|
||||
|
||||
cmp = memcmp(cursor, footer, sizeof(uint32_t));
|
||||
if (cmp == 0) {
|
||||
lsPck.push_back(last);
|
||||
cursor += sizeof(uint64_t) + sizeof(uint8_t);
|
||||
cursor += sizeof(uint32_t);
|
||||
last = cursor;
|
||||
next = cursor + 1;
|
||||
}
|
||||
@ -1010,9 +1010,6 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf) {
|
||||
};
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < buf->len; ++x)
|
||||
std::putchar(buf->ptr[x]);
|
||||
std::puts("");
|
||||
}
|
||||
|
||||
template <>
|
||||
|
@ -183,19 +183,21 @@ namespace netprot {
|
||||
|
||||
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);
|
||||
memset(&buf->ptr[buf->len], '\0', sizeof(uint64_t) + sizeof(uint8_t));
|
||||
buf->len += sizeof(uint64_t) + sizeof(uint8_t);
|
||||
memcpy(&buf->ptr[buf->len], footer, sizeof(uint32_t));
|
||||
buf->len += sizeof(uint32_t);
|
||||
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;
|
||||
netprot::Serialize(pack, &buf->ptr, &buf->len);
|
||||
memset(&buf->ptr[buf->len], '\0', sizeof(uint64_t) + sizeof(uint8_t));
|
||||
buf->len += sizeof(uint64_t) + sizeof(uint8_t);
|
||||
memcpy(&buf->ptr[buf->len], footer, sizeof(uint32_t));
|
||||
buf->len += sizeof(uint32_t);
|
||||
sendto(sock, buf->ptr, buf->len, 0, (sockaddr*)&addr, sizeof(addr));
|
||||
buf->rstLen();
|
||||
}
|
||||
|
@ -140,21 +140,24 @@ int Server::Ready() {
|
||||
LoginInfo* log = (LoginInfo*)pck.ptr;
|
||||
|
||||
log->sid = getUniqueId();
|
||||
log->tid = 0; // TODO: À changer si on implemente un mode en equipe.
|
||||
log->tid = 1145389380; // TODO: À changer si on implemente un mode en equipe.
|
||||
|
||||
Log(str.append(" Nom: ").append(log->name), false, false);
|
||||
str.clear();
|
||||
|
||||
Log(str.append(log->name).append(" SID: [").append(std::to_string(log->sid).append("]")), false, false);
|
||||
|
||||
sendPack<LoginInfo>(sock, log, &m_buf.ptr, &m_buf.len);
|
||||
//using namespace std::chrono_literals;
|
||||
//std::this_thread::sleep_for(100ms);
|
||||
|
||||
sendPack<LoginInfo>(sock, log, &m_buf);
|
||||
|
||||
play.id = getUniqueId();
|
||||
strcpy(play.name, log->name);
|
||||
|
||||
play.tid = log->tid;
|
||||
|
||||
sendPack<GameInfo>(sock, &m_game, &m_buf.ptr, &m_buf.len);
|
||||
sendPack<GameInfo>(sock, &m_game, &m_buf);
|
||||
std::unique_ptr<Connection> conn = std::make_unique<Connection>(sock, sockad, *log, play);
|
||||
|
||||
for (auto& [key, player] : m_players) {
|
||||
|
@ -69,6 +69,11 @@ int Connector::Connect(const char* srv_addr, std::string name) {
|
||||
|
||||
netprot::sendPack(m_sock_tcp, &log, &bf);
|
||||
|
||||
memset(bf.ptr, '\0', BUFFER_LENGTH);
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
std::this_thread::sleep_for(100ms);
|
||||
|
||||
bool ready = false;
|
||||
int errors = 0;
|
||||
std::vector<char*> lsPck;
|
||||
|
Loading…
Reference in New Issue
Block a user