mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30:14 +00:00
Initial commit: wowee native WoW 3.3.5a client
This commit is contained in:
commit
ce6cb8f38e
147 changed files with 32347 additions and 0 deletions
43
include/network/packet.hpp
Normal file
43
include/network/packet.hpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace wowee {
|
||||
namespace network {
|
||||
|
||||
class Packet {
|
||||
public:
|
||||
Packet() = default;
|
||||
explicit Packet(uint16_t opcode);
|
||||
Packet(uint16_t opcode, const std::vector<uint8_t>& data);
|
||||
|
||||
void writeUInt8(uint8_t value);
|
||||
void writeUInt16(uint16_t value);
|
||||
void writeUInt32(uint32_t value);
|
||||
void writeUInt64(uint64_t value);
|
||||
void writeString(const std::string& value);
|
||||
void writeBytes(const uint8_t* data, size_t length);
|
||||
|
||||
uint8_t readUInt8();
|
||||
uint16_t readUInt16();
|
||||
uint32_t readUInt32();
|
||||
uint64_t readUInt64();
|
||||
float readFloat();
|
||||
std::string readString();
|
||||
|
||||
uint16_t getOpcode() const { return opcode; }
|
||||
const std::vector<uint8_t>& getData() const { return data; }
|
||||
size_t getReadPos() const { return readPos; }
|
||||
size_t getSize() const { return data.size(); }
|
||||
void setReadPos(size_t pos) { readPos = pos; }
|
||||
|
||||
private:
|
||||
uint16_t opcode = 0;
|
||||
std::vector<uint8_t> data;
|
||||
size_t readPos = 0;
|
||||
};
|
||||
|
||||
} // namespace network
|
||||
} // namespace wowee
|
||||
32
include/network/socket.hpp
Normal file
32
include/network/socket.hpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
namespace wowee {
|
||||
namespace network {
|
||||
|
||||
class Packet;
|
||||
|
||||
class Socket {
|
||||
public:
|
||||
virtual ~Socket() = default;
|
||||
|
||||
virtual bool connect(const std::string& host, uint16_t port) = 0;
|
||||
virtual void disconnect() = 0;
|
||||
virtual bool isConnected() const = 0;
|
||||
|
||||
virtual void send(const Packet& packet) = 0;
|
||||
virtual void update() = 0;
|
||||
|
||||
using PacketCallback = std::function<void(const Packet&)>;
|
||||
void setPacketCallback(PacketCallback callback) { packetCallback = callback; }
|
||||
|
||||
protected:
|
||||
PacketCallback packetCallback;
|
||||
};
|
||||
|
||||
} // namespace network
|
||||
} // namespace wowee
|
||||
31
include/network/tcp_socket.hpp
Normal file
31
include/network/tcp_socket.hpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include "network/socket.hpp"
|
||||
#include <sys/socket.h>
|
||||
|
||||
namespace wowee {
|
||||
namespace network {
|
||||
|
||||
class TCPSocket : public Socket {
|
||||
public:
|
||||
TCPSocket();
|
||||
~TCPSocket() override;
|
||||
|
||||
bool connect(const std::string& host, uint16_t port) override;
|
||||
void disconnect() override;
|
||||
bool isConnected() const override { return connected; }
|
||||
|
||||
void send(const Packet& packet) override;
|
||||
void update() override;
|
||||
|
||||
private:
|
||||
void tryParsePackets();
|
||||
size_t getExpectedPacketSize(uint8_t opcode);
|
||||
|
||||
int sockfd = -1;
|
||||
bool connected = false;
|
||||
std::vector<uint8_t> receiveBuffer;
|
||||
};
|
||||
|
||||
} // namespace network
|
||||
} // namespace wowee
|
||||
92
include/network/world_socket.hpp
Normal file
92
include/network/world_socket.hpp
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
#pragma once
|
||||
|
||||
#include "network/socket.hpp"
|
||||
#include "network/packet.hpp"
|
||||
#include "auth/rc4.hpp"
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
namespace wowee {
|
||||
namespace network {
|
||||
|
||||
/**
|
||||
* World Server Socket
|
||||
*
|
||||
* Handles WoW 3.3.5a world server protocol with RC4 header encryption.
|
||||
*
|
||||
* Key Differences from Auth Server:
|
||||
* - Outgoing: 6-byte header (2 bytes size + 4 bytes opcode, big-endian)
|
||||
* - Incoming: 4-byte header (2 bytes size + 2 bytes opcode, big-endian)
|
||||
* - Headers are RC4-encrypted after CMSG_AUTH_SESSION
|
||||
* - Packet bodies remain unencrypted
|
||||
* - Size field is payload size only (does NOT include header)
|
||||
*/
|
||||
class WorldSocket : public Socket {
|
||||
public:
|
||||
WorldSocket();
|
||||
~WorldSocket() override;
|
||||
|
||||
bool connect(const std::string& host, uint16_t port) override;
|
||||
void disconnect() override;
|
||||
bool isConnected() const override;
|
||||
|
||||
/**
|
||||
* Send a world packet
|
||||
* Automatically encrypts 6-byte header if encryption is enabled
|
||||
*
|
||||
* @param packet Packet to send
|
||||
*/
|
||||
void send(const Packet& packet) override;
|
||||
|
||||
/**
|
||||
* Update socket - receive data and parse packets
|
||||
* Should be called regularly (e.g., each frame)
|
||||
*/
|
||||
void update();
|
||||
|
||||
/**
|
||||
* Set callback for complete packets
|
||||
*
|
||||
* @param callback Function to call when packet is received
|
||||
*/
|
||||
void setPacketCallback(std::function<void(const Packet&)> callback) {
|
||||
packetCallback = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize RC4 encryption for packet headers
|
||||
* Must be called after CMSG_AUTH_SESSION before further communication
|
||||
*
|
||||
* @param sessionKey 40-byte session key from auth server
|
||||
*/
|
||||
void initEncryption(const std::vector<uint8_t>& sessionKey);
|
||||
|
||||
/**
|
||||
* Check if header encryption is enabled
|
||||
*/
|
||||
bool isEncryptionEnabled() const { return encryptionEnabled; }
|
||||
|
||||
private:
|
||||
/**
|
||||
* Try to parse complete packets from receive buffer
|
||||
*/
|
||||
void tryParsePackets();
|
||||
|
||||
int sockfd = -1;
|
||||
bool connected = false;
|
||||
bool encryptionEnabled = false;
|
||||
|
||||
// RC4 ciphers for header encryption/decryption
|
||||
auth::RC4 encryptCipher; // For outgoing headers
|
||||
auth::RC4 decryptCipher; // For incoming headers
|
||||
|
||||
// Receive buffer
|
||||
std::vector<uint8_t> receiveBuffer;
|
||||
|
||||
// Packet callback
|
||||
std::function<void(const Packet&)> packetCallback;
|
||||
};
|
||||
|
||||
} // namespace network
|
||||
} // namespace wowee
|
||||
Loading…
Add table
Add a link
Reference in a new issue