Skip to content

Commit

Permalink
push for further testting
Browse files Browse the repository at this point in the history
  • Loading branch information
notchyves committed Aug 5, 2024
1 parent 3808207 commit dbfae36
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/minecraft/network/protocol.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
#include "protocol.h"

std::string ToHexString(const unsigned char* data, size_t length) {
std::ostringstream oss;
oss << std::hex << std::setfill('0');
for (size_t i = 0; i < length; ++i) {
oss << std::setw(2) << static_cast<int>(data[i]);
}
return oss.str();
}

void ProtocolManager::Init(RakPeerInterface* peer) {
Packet* packet;
while ((packet = peer->Receive())) {
int packetType = packet->data[0];

Logger::Info("Received packet with ID: " + std::to_string(packetType));

switch (packetType) {
case 0:
ProtocolManager::PingPacketCallback(peer, packet);
case 1:
ProtocolManager::PingPacketCallback(peer, packet);
}
ProtocolManager::PingPacketCallback(peer, packet);

peer->DeallocatePacket(packet);
}
};

void ProtocolManager::PingPacketCallback(RakPeerInterface* peer, Packet* packet) {
PingPacket* pingPacket = reinterpret_cast<PingPacket*>(packet);

PingPacket pongPacket;
pongPacket.packetType = 1;
pongPacket.clientTimestamp = pingPacket->clientTimestamp;

peer->Send(reinterpret_cast<const char*>(&pongPacket), sizeof(PingPacket), HIGH_PRIORITY, RELIABLE_ORDERED, 0, packet->systemAddress, false);
Logger::Info("send a pong");
};
std::string hexData = ToHexString(packet->data, packet->length);
Logger::Info("packet data: " + hexData);
};
2 changes: 2 additions & 0 deletions src/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <vector>
#include <filesystem>
#include <string>
#include <iomanip>
#include <sstream>

#include <RakPeerInterface.h>
#include <RakNetTypes.h>
Expand Down

0 comments on commit dbfae36

Please sign in to comment.