mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
fix: build fail on windows
This commit is contained in:
@@ -96,10 +96,10 @@ void App::handle_argument(int argc, char** argv) {
|
||||
[&](ArgParser& p) {
|
||||
auto arg = p.require_next("-p");
|
||||
|
||||
auto r =
|
||||
std::from_chars(arg.begin(), arg.end(), m_argument.port);
|
||||
auto r = std::from_chars(arg.data(), arg.data() + arg.size(),
|
||||
m_argument.port);
|
||||
|
||||
if (r.ec != std::errc{} || r.ptr != arg.end()) {
|
||||
if (r.ec != std::errc{} || arg.data() + arg.size()) {
|
||||
throw std::runtime_error(
|
||||
std::format("Invalid port: {}", arg));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
#include "Cubed/config.hpp"
|
||||
#include "Cubed/gameplay/game_time.hpp"
|
||||
#include "Cubed/gameplay/packet.hpp"
|
||||
|
||||
#include <numbers>
|
||||
|
||||
using namespace std::chrono;
|
||||
using namespace std::chrono_literals;
|
||||
using namespace google::protobuf;
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
#include "Cubed/gameplay/client_world.hpp"
|
||||
#include "Cubed/tools/log.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
using namespace google::protobuf;
|
||||
namespace Cubed {
|
||||
NetworkClient::NetworkClient(ClientWorld& world)
|
||||
@@ -62,10 +65,10 @@ asio::awaitable<void> NetworkClient::read_loop() {
|
||||
asio::use_awaitable);
|
||||
}
|
||||
|
||||
constexpr auto& to_num = std::to_underlying<PacketEnum>;
|
||||
using std::to_underlying;
|
||||
Arena arena;
|
||||
switch (header.cmd) {
|
||||
case to_num(PacketEnum::LOGIN_RSP): {
|
||||
case std::to_underlying(PacketEnum::LOGIN_RSP): {
|
||||
auto* rsp = Arena::Create<LoginRsp>(&arena);
|
||||
Logger::info("Client: Receive Login rsp");
|
||||
if (decode_packet(*rsp, body_data, header)) {
|
||||
@@ -76,7 +79,7 @@ asio::awaitable<void> NetworkClient::read_loop() {
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case to_num(PacketEnum::CHUNK_DATA_RSP): {
|
||||
case std::to_underlying(PacketEnum::CHUNK_DATA_RSP): {
|
||||
ChunkDataRsp rsp;
|
||||
// Logger::info("Client: Receive Chunk Data rsp, size {}mb",
|
||||
// body_data.size() / 1024.0f / 1024);
|
||||
@@ -84,32 +87,32 @@ asio::awaitable<void> NetworkClient::read_loop() {
|
||||
m_world.receive_chunk(std::move(rsp));
|
||||
}
|
||||
} break;
|
||||
case to_num(PacketEnum::BLOCK_CHANGE_RSP): {
|
||||
case std::to_underlying(PacketEnum::BLOCK_CHANGE_RSP): {
|
||||
auto* rsp = Arena::Create<BlockChangeRsp>(&arena);
|
||||
Logger::info("Client: Receive Block Change rsp");
|
||||
if (decode_packet(*rsp, body_data, header)) {
|
||||
m_world.receive_block_change(*rsp);
|
||||
}
|
||||
} break;
|
||||
case to_num(PacketEnum::UPDATE_TIME): {
|
||||
case std::to_underlying(PacketEnum::UPDATE_TIME): {
|
||||
auto* rsp = Arena::Create<UpdateTime>(&arena);
|
||||
if (decode_packet(*rsp, body_data, header)) {
|
||||
m_world.receive_time(*rsp);
|
||||
}
|
||||
} break;
|
||||
case to_num(PacketEnum::PLAYER_INFO_RSP): {
|
||||
case std::to_underlying(PacketEnum::PLAYER_INFO_RSP): {
|
||||
auto* rsp = Arena::Create<PlayerInfoRsp>(&arena);
|
||||
if (decode_packet(*rsp, body_data, header)) {
|
||||
m_world.receive_remote_player(*rsp);
|
||||
}
|
||||
} break;
|
||||
case to_num(PacketEnum::LOGOUT_RSP): {
|
||||
case std::to_underlying(PacketEnum::LOGOUT_RSP): {
|
||||
auto* rsp = Arena::Create<LogoutRsp>(&arena);
|
||||
if (decode_packet(*rsp, body_data, header)) {
|
||||
m_world.receive_player_logout(*rsp);
|
||||
}
|
||||
} break;
|
||||
case to_num(PacketEnum::S2C_CLEAR_ALL_CHUNKS): {
|
||||
case std::to_underlying(PacketEnum::S2C_CLEAR_ALL_CHUNKS): {
|
||||
auto* rsp = Arena::Create<S2C_ClearAllChunks>(&arena);
|
||||
if (decode_packet(*rsp, body_data, header)) {
|
||||
if (rsp->clear()) {
|
||||
|
||||
@@ -53,10 +53,9 @@ asio::awaitable<void> Session::read_loop() {
|
||||
co_await asio::async_read(m_socket, asio::buffer(body_data),
|
||||
asio::use_awaitable);
|
||||
}
|
||||
constexpr auto& to_num = std::to_underlying<PacketEnum>;
|
||||
auto cmd_id = header.cmd;
|
||||
Arena arena;
|
||||
if (cmd_id == to_num(PacketEnum::LOGIN_REQ)) {
|
||||
if (cmd_id == std::to_underlying(PacketEnum::LOGIN_REQ)) {
|
||||
auto* req = Arena::Create<LoginReq>(&arena);
|
||||
Logger::info("Session: Receive Login req");
|
||||
if (decode_packet(*req, body_data, header)) {
|
||||
@@ -64,7 +63,7 @@ asio::awaitable<void> Session::read_loop() {
|
||||
shared_from_this());
|
||||
}
|
||||
}
|
||||
if (cmd_id == to_num(PacketEnum::PLAYER_POS)) {
|
||||
if (cmd_id == std::to_underlying(PacketEnum::PLAYER_POS)) {
|
||||
auto* pos = Arena::Create<PlayerPos>(&arena);
|
||||
if (decode_packet(*pos, body_data, header)) {
|
||||
m_server_world.sync_player_pos(pos->uuid(), pos->pos().x(),
|
||||
@@ -72,7 +71,7 @@ asio::awaitable<void> Session::read_loop() {
|
||||
pos->pos().z());
|
||||
}
|
||||
}
|
||||
if (cmd_id == to_num(PacketEnum::CHUNK_DATA_REQ)) {
|
||||
if (cmd_id == std::to_underlying(PacketEnum::CHUNK_DATA_REQ)) {
|
||||
auto* req = Arena::Create<ChunkDataReq>(&arena);
|
||||
// Logger::info("Session: Receive Chunk Data req");
|
||||
if (decode_packet(*req, body_data, header)) {
|
||||
@@ -81,14 +80,14 @@ asio::awaitable<void> Session::read_loop() {
|
||||
ChunkPos(req->pos().x(), req->pos().z()));
|
||||
}
|
||||
}
|
||||
if (cmd_id == to_num(PacketEnum::BLOCK_CHANGE_REQ)) {
|
||||
if (cmd_id == std::to_underlying(PacketEnum::BLOCK_CHANGE_REQ)) {
|
||||
auto* req = Arena::Create<BlockChangeReq>(&arena);
|
||||
Logger::info("Session: Receive Block Change req");
|
||||
if (decode_packet(*req, body_data, header)) {
|
||||
m_server_world.handle_block_change(*req);
|
||||
}
|
||||
}
|
||||
if (cmd_id == to_num(PacketEnum::LOGOUT_REQ)) {
|
||||
if (cmd_id == std::to_underlying(PacketEnum::LOGOUT_REQ)) {
|
||||
auto* req = Arena::Create<LogoutReq>(&arena);
|
||||
if (decode_packet(*req, body_data, header)) {
|
||||
m_server_world.handle_player_exit(req->uuid());
|
||||
|
||||
Reference in New Issue
Block a user