Files
DevilutionX/Source/dvlnet/tcp_client.h
T
Gleb MazovetskiyandClaude Fable 5 ac2d7fc731 Replace libfmt with std::format
- `fmt::format` with literal format strings -> `std::format`.
- `fmt::format(fmt::runtime(...))` -> `FormatRuntime` in the new
  `utils/format.hpp`, a std::vformat wrapper that is also safe under the
  P2905 lvalue requirement of `std::make_format_args`.
- `fmt::dynamic_format_arg_store` (Lua logging) -> a small hand-rolled
  per-field formatter over `std::variant`, returning `std::expected`.
- `fmt::format_int` -> `std::to_chars`.
- `fmt::join` -> manual joins at the two call sites.
- SDL_audiolib: new patch that rewrites aulib_log.h to use std::format
  and drops the fmt dependency from its CMakeLists.
- The `-static-libstdc++` guard now keys off
  `DEVILUTIONX_STATIC_SDL_AUDIOLIB` instead of `DEVILUTIONX_STATIC_LIBFMT`.
- libfmt removed from CMake, vcpkg, Brewfile, CI workflows,
  Dockerfiles, packaging scripts, UWP project, and docs.
- macOS bumped to 13.3+, iOS to 16.3+ (required for `<format>`)
- Amiga m68k: provide `__cmpdf2`, which is missing from the hard-float
  libgcc multilib but referenced via libstdc++'s long double paths.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-07-22 00:00:04 +02:00

57 lines
1.5 KiB
C++

#pragma once
#include <memory>
#include <string>
#include <asio/ts/buffer.hpp>
#include <asio/ts/internet.hpp>
#include <asio/ts/io_context.hpp>
#include <asio/ts/net.hpp>
#include <asio_handle_exception.hpp>
#include "dvlnet/base.h"
#include "dvlnet/frame_queue.h"
#include "dvlnet/packet.h"
#include "dvlnet/tcp_server.h"
namespace devilution::net {
class tcp_client : public base {
public:
int create(std::string_view addrstr) override;
int join(std::string_view addrstr) override;
std::expected<void, PacketError> poll() override;
std::expected<void, PacketError> send(packet &pkt) override;
void DisconnectNet(plr_t plr) override;
bool SNetLeaveGame(net::leaveinfo_t type) override;
~tcp_client() override;
std::string make_default_gamename() override;
protected:
bool IsGameHost() override;
private:
frame_queue recv_queue;
buffer_t recv_buffer = buffer_t(frame_queue::max_frame_size);
asio::io_context ioc;
asio::ip::tcp::resolver resolver = asio::ip::tcp::resolver(ioc);
asio::ip::tcp::socket sock = asio::ip::tcp::socket(ioc);
std::unique_ptr<tcp_server> local_server; // must be declared *after* ioc
std::optional<PacketError> ioHandlerResult;
void HandleReceive(const asio::error_code &error, size_t bytesRead);
void StartReceive();
void HandleSend(const asio::error_code &error, size_t bytesSent);
void HandleTcpErrorCode();
void RaiseIoHandlerError(const PacketError &error);
};
} // namespace devilution::net