Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ add_executable(L2GameServer
src/game/server/game_server.cpp
src/game/server/character_database_manager.cpp

# Game entities
src/game/entities/world_object.cpp
src/game/entities/creature.cpp
src/game/entities/player.cpp

# Game-specific networking
src/game/network/game_connection_manager.cpp
src/game/network/game_client_connection.cpp
Expand All @@ -116,18 +121,49 @@ add_executable(L2GameServer
src/game/packets/requests/create_char_request_packet.cpp
src/game/packets/requests/request_game_start.cpp
src/game/packets/requests/logout_packet.cpp
src/game/packets/requests/delete_char_packet.cpp
src/game/packets/requests/request_delete_character_packet.cpp
src/game/packets/requests/restore_char_packet.cpp
src/game/packets/requests/select_char_packet.cpp
src/game/packets/requests/enter_world_packet.cpp
src/game/packets/requests/no_op_packet.cpp
src/game/packets/requests/request_skill_cool_time.cpp
src/game/packets/requests/request_answer_join_pledge.cpp
src/game/packets/requests/request_item_list.cpp
src/game/packets/requests/request_show_mini_map.cpp
src/game/packets/requests/extended/request_manor_list.cpp

# Game response packets
src/game/packets/responses/ping_response.cpp
src/game/packets/responses/version_check_response.cpp
src/game/packets/responses/character_selection_info.cpp
src/game/packets/responses/new_character_success.cpp
src/game/packets/responses/character_create_success.cpp
src/game/packets/responses/character_selected.cpp
src/game/packets/responses/user_info.cpp
src/game/packets/responses/validate_location.cpp
src/game/packets/responses/item_list.cpp
src/game/packets/responses/skill_cool_time.cpp
src/game/packets/responses/shortcut_init.cpp
src/game/packets/responses/etc_status_update.cpp
src/game/packets/responses/ex_storage_max_count.cpp
src/game/packets/responses/quest_list.cpp
# Phase 3: Social/Clan packets
src/game/packets/responses/henna_info.cpp
src/game/packets/responses/pledge_skill_list.cpp
src/game/packets/responses/friend_list.cpp
src/game/packets/responses/pledge_show_member_list_all.cpp
src/game/packets/responses/pledge_status_changed.cpp
src/game/packets/responses/ask_join_pledge.cpp
src/game/packets/responses/npc_html_message.cpp
src/game/packets/responses/ex_send_manor_list.cpp
src/game/packets/responses/skill_list.cpp
src/game/packets/responses/status_update.cpp
src/game/packets/responses/char_info.cpp
# Phase 4: Welcome/System packets
src/game/packets/responses/system_message.cpp
src/game/packets/responses/ex_show_screen_message.cpp
src/game/packets/responses/action_failed.cpp
src/game/packets/responses/show_mini_map.cpp
)

target_link_libraries(L2GameServer L2Core)
Expand Down
21 changes: 21 additions & 0 deletions src/core/packets/packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,31 @@ std::vector<uint8_t> SendablePacket::serialize(bool withPadding)
std::vector<uint8_t> SendablePacket::serialize(bool withPadding, size_t alignment)
{
SendablePacketBuffer buffer;

// Write opcode automatically (handles both standard and extended packets)
writeOpcode(buffer);

// Write packet data
write(buffer);

return buffer.getData(withPadding, alignment);
}

// Helper method to write opcode (handles extended packets automatically)
void SendablePacket::writeOpcode(SendablePacketBuffer &buffer) const
{
uint16_t extendedPacketId = getExtendedPacketId();

if (extendedPacketId != 0) {
// Extended packet: write 0xFE prefix + 16-bit sub-opcode
buffer.writeUInt8(0xFE);
buffer.writeUInt16(extendedPacketId);
} else {
// Standard packet: write 8-bit opcode
buffer.writeUInt8(getPacketId());
}
}

// ReadablePacket factory method (basic implementation)
std::unique_ptr<ReadablePacket> ReadablePacket::createFromData(const std::vector<uint8_t> &data)
{
Expand Down
10 changes: 9 additions & 1 deletion src/core/packets/packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,19 @@ class SendablePacket

// Packet identification
virtual uint8_t getPacketId() const = 0;
virtual std::optional<uint16_t> getExPacketId() const = 0;

// Extended packet identification (returns 0 for standard packets)
virtual uint16_t getExtendedPacketId() const { return 0; }

// Legacy method for backward compatibility (deprecated - use getExtendedPacketId instead)
virtual std::optional<uint16_t> getExPacketId() const { return std::nullopt; }

// Write packet data to buffer
virtual void write(SendablePacketBuffer &buffer) = 0;

// Helper method to write opcode (handles extended packets automatically)
void writeOpcode(SendablePacketBuffer &buffer) const;

// Get serialized packet data
virtual std::vector<uint8_t> serialize(bool withPadding = false);
virtual std::vector<uint8_t> serialize(bool withPadding, size_t alignment);
Expand Down
22 changes: 22 additions & 0 deletions src/game/entities/creature.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "creature.hpp"

Creature::Creature(uint32_t objectId, const std::string& name)
: WorldObject(objectId)
, name_(name)
, level_(1)
, exp_(0)
, sp_(0)
, currentHp_(100.0)
, maxHp_(100.0)
, currentMp_(100.0)
, maxMp_(100.0)
, currentCp_(0.0)
, maxCp_(0.0)
, str_(10)
, dex_(10)
, con_(10)
, int_(10)
, wit_(10)
, men_(10)
{
}
75 changes: 75 additions & 0 deletions src/game/entities/creature.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#pragma once

#include "world_object.hpp"
#include <cstdint>
#include <string>

// Base class for all living entities (players, NPCs, monsters)
class Creature : public WorldObject
{
protected:
std::string name_;
uint32_t level_;
uint64_t exp_;
uint64_t sp_;

// Stats
double currentHp_;
double maxHp_;
double currentMp_;
double maxMp_;
double currentCp_;
double maxCp_;

// Base stats
uint32_t str_;
uint32_t dex_;
uint32_t con_;
uint32_t int_;
uint32_t wit_;
uint32_t men_;

public:
Creature(uint32_t objectId, const std::string& name);
virtual ~Creature() = default;

// Getters
const std::string& getName() const { return name_; }
uint32_t getLevel() const { return level_; }
uint64_t getExp() const { return exp_; }
uint64_t getSp() const { return sp_; }

double getCurrentHp() const { return currentHp_; }
double getMaxHp() const { return maxHp_; }
double getCurrentMp() const { return currentMp_; }
double getMaxMp() const { return maxMp_; }
double getCurrentCp() const { return currentCp_; }
double getMaxCp() const { return maxCp_; }

uint32_t getStr() const { return str_; }
uint32_t getDex() const { return dex_; }
uint32_t getCon() const { return con_; }
uint32_t getInt() const { return int_; }
uint32_t getWit() const { return wit_; }
uint32_t getMen() const { return men_; }

// Setters
void setName(const std::string& name) { name_ = name; }
void setLevel(uint32_t level) { level_ = level; }
void setExp(uint64_t exp) { exp_ = exp; }
void setSp(uint64_t sp) { sp_ = sp; }

void setCurrentHp(double hp) { currentHp_ = hp; }
void setMaxHp(double hp) { maxHp_ = hp; }
void setCurrentMp(double mp) { currentMp_ = mp; }
void setMaxMp(double mp) { maxMp_ = mp; }
void setCurrentCp(double cp) { currentCp_ = cp; }
void setMaxCp(double cp) { maxCp_ = cp; }

void setStr(uint32_t str) { str_ = str; }
void setDex(uint32_t dex) { dex_ = dex; }
void setCon(uint32_t con) { con_ = con; }
void setInt(uint32_t int_val) { int_ = int_val; }
void setWit(uint32_t wit) { wit_ = wit; }
void setMen(uint32_t men) { men_ = men; }
};
Loading