2023-06-20 04:33:09 +00:00
|
|
|
#include "StarClientContext.hpp"
|
|
|
|
#include "StarJsonExtra.hpp"
|
|
|
|
#include "StarDataStreamExtra.hpp"
|
|
|
|
|
|
|
|
namespace Star {
|
|
|
|
|
|
|
|
DataStream& operator>>(DataStream& ds, ShipUpgrades& upgrades) {
|
|
|
|
ds.read(upgrades.shipLevel);
|
|
|
|
ds.read(upgrades.maxFuel);
|
|
|
|
ds.read(upgrades.crewSize);
|
|
|
|
ds.read(upgrades.fuelEfficiency);
|
|
|
|
ds.read(upgrades.shipSpeed);
|
|
|
|
ds.read(upgrades.capabilities);
|
|
|
|
return ds;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataStream& operator<<(DataStream& ds, ShipUpgrades const& upgrades) {
|
|
|
|
ds.write(upgrades.shipLevel);
|
|
|
|
ds.write(upgrades.maxFuel);
|
|
|
|
ds.write(upgrades.crewSize);
|
|
|
|
ds.write(upgrades.fuelEfficiency);
|
|
|
|
ds.write(upgrades.shipSpeed);
|
|
|
|
ds.write(upgrades.capabilities);
|
|
|
|
return ds;
|
|
|
|
}
|
|
|
|
|
2023-07-22 12:31:04 +00:00
|
|
|
ClientContext::ClientContext(Uuid serverUuid, Uuid playerUuid) {
|
2024-02-19 15:55:19 +00:00
|
|
|
m_serverUuid = std::move(serverUuid);
|
|
|
|
m_playerUuid = std::move(playerUuid);
|
|
|
|
m_rpc = std::make_shared<JsonRpc>();
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
m_netGroup.addNetElement(&m_orbitWarpActionNetState);
|
|
|
|
m_netGroup.addNetElement(&m_playerWorldIdNetState);
|
|
|
|
m_netGroup.addNetElement(&m_isAdminNetState);
|
|
|
|
m_netGroup.addNetElement(&m_teamNetState);
|
|
|
|
m_netGroup.addNetElement(&m_shipUpgrades);
|
|
|
|
m_netGroup.addNetElement(&m_shipCoordinate);
|
|
|
|
}
|
|
|
|
|
|
|
|
Uuid ClientContext::serverUuid() const {
|
|
|
|
return m_serverUuid;
|
|
|
|
}
|
|
|
|
|
2023-07-22 12:31:04 +00:00
|
|
|
Uuid ClientContext::playerUuid() const {
|
|
|
|
return m_playerUuid;
|
|
|
|
}
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
CelestialCoordinate ClientContext::shipCoordinate() const {
|
|
|
|
return m_shipCoordinate.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
Maybe<pair<WarpAction, WarpMode>> ClientContext::orbitWarpAction() const {
|
|
|
|
return m_orbitWarpActionNetState.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
WorldId ClientContext::playerWorldId() const {
|
|
|
|
return m_playerWorldIdNetState.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientContext::isAdmin() const {
|
|
|
|
return m_isAdminNetState.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityDamageTeam ClientContext::team() const {
|
|
|
|
return m_teamNetState.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonRpcInterfacePtr ClientContext::rpcInterface() const {
|
|
|
|
return m_rpc;
|
|
|
|
}
|
|
|
|
|
|
|
|
WorldChunks ClientContext::newShipUpdates() {
|
|
|
|
return take(m_newShipUpdates);
|
|
|
|
}
|
|
|
|
|
|
|
|
ShipUpgrades ClientContext::shipUpgrades() const {
|
|
|
|
return m_shipUpgrades.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientContext::readUpdate(ByteArray data) {
|
|
|
|
if (data.empty())
|
|
|
|
return;
|
|
|
|
|
2024-02-19 15:55:19 +00:00
|
|
|
DataStreamBuffer ds(std::move(data));
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
m_rpc->receive(ds.read<ByteArray>());
|
|
|
|
|
|
|
|
auto shipUpdates = ds.read<ByteArray>();
|
|
|
|
if (!shipUpdates.empty())
|
2024-02-19 15:55:19 +00:00
|
|
|
m_newShipUpdates.merge(DataStreamBuffer::deserialize<WorldChunks>(std::move(shipUpdates)), true);
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
m_netGroup.readNetState(ds.read<ByteArray>());
|
|
|
|
}
|
|
|
|
|
|
|
|
ByteArray ClientContext::writeUpdate() {
|
|
|
|
return m_rpc->send();
|
|
|
|
}
|
|
|
|
|
2024-04-21 20:07:59 +00:00
|
|
|
void ClientContext::setConnectionId(ConnectionId connectionId) {
|
|
|
|
m_connectionId = connectionId;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectionId ClientContext::connectionId() const {
|
|
|
|
return m_connectionId;
|
|
|
|
}
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
}
|