Connection changes

This commit is contained in:
Kae 2024-08-13 16:23:01 +10:00
parent b39072f071
commit 8bef4abdbc
5 changed files with 23 additions and 12 deletions

View File

@ -360,7 +360,7 @@ void ClientApplication::update() {
m_guiContext->cleanup();
m_edgeKeyEvents.clear();
m_input->reset();
m_input->update();
}
void ClientApplication::render() {

View File

@ -404,10 +404,10 @@ ClientConnectPacket::ClientConnectPacket() {}
ClientConnectPacket::ClientConnectPacket(ByteArray assetsDigest, bool allowAssetsMismatch, Uuid playerUuid,
String playerName, String playerSpecies, WorldChunks shipChunks, ShipUpgrades shipUpgrades,
bool introComplete, String account)
bool introComplete, String account, Json info)
: assetsDigest(std::move(assetsDigest)), allowAssetsMismatch(allowAssetsMismatch), playerUuid(std::move(playerUuid)),
playerName(std::move(playerName)), playerSpecies(std::move(playerSpecies)), shipChunks(std::move(shipChunks)),
shipUpgrades(std::move(shipUpgrades)), introComplete(std::move(introComplete)), account(std::move(account)) {}
shipUpgrades(std::move(shipUpgrades)), introComplete(std::move(introComplete)), account(std::move(account)), info(std::move(info)) {}
void ClientConnectPacket::readLegacy(DataStream& ds) {
ds.read(assetsDigest);
@ -419,6 +419,7 @@ void ClientConnectPacket::readLegacy(DataStream& ds) {
ds.read(shipUpgrades);
ds.read(introComplete);
ds.read(account);
info = Json();
}
void ClientConnectPacket::read(DataStream& ds) {

View File

@ -310,7 +310,7 @@ struct ClientConnectPacket : PacketBase<PacketType::ClientConnect> {
ClientConnectPacket();
ClientConnectPacket(ByteArray assetsDigest, bool allowAssetsMismatch, Uuid playerUuid, String playerName,
String playerSpecies, WorldChunks shipChunks, ShipUpgrades shipUpgrades, bool introComplete,
String account);
String account, Json info = {});
void readLegacy(DataStream& ds) override;
void read(DataStream& ds) override;

View File

@ -111,10 +111,11 @@ Maybe<String> UniverseClient::connect(UniverseConnection connection, bool allowA
}
}
connection.packetSocket().setLegacy(m_legacyServer);
connection.pushSingle(make_shared<ClientConnectPacket>(Root::singleton().assets()->digest(), allowAssetsMismatch, m_mainPlayer->uuid(), m_mainPlayer->name(),
auto clientConnect = make_shared<ClientConnectPacket>(Root::singleton().assets()->digest(), allowAssetsMismatch, m_mainPlayer->uuid(), m_mainPlayer->name(),
m_mainPlayer->species(), m_playerStorage->loadShipData(m_mainPlayer->uuid()), m_mainPlayer->shipUpgrades(),
m_mainPlayer->log()->introComplete(), account));
m_mainPlayer->log()->introComplete(), account);
clientConnect->info = JsonObject{ {"brand", "OpenStarbound"} };
connection.pushSingle(std::move(clientConnect));
connection.sendAll(timeout);
connection.receiveAny(timeout);

View File

@ -1584,7 +1584,7 @@ void UniverseServer::acceptConnection(UniverseConnection connection, Maybe<HostA
compressedSocket->setCompressionStreamEnabled(useCompressionStream);
String remoteAddressString = remoteAddress ? toString(*remoteAddress) : "local";
Logger::info("UniverseServer: Awaiting connection info from {}, {} client", remoteAddressString, legacyClient ? "Starbound" : "OpenStarbound");
Logger::info("UniverseServer: Awaiting connection info from {} ({} client)", remoteAddressString, legacyClient ? "vanilla" : "custom");
connection.receiveAny(clientWaitLimit);
auto clientConnect = as<ClientConnectPacket>(connection.pullSingle());
@ -1597,7 +1597,6 @@ void UniverseServer::acceptConnection(UniverseConnection connection, Maybe<HostA
}
bool administrator = false;
String accountString = !clientConnect->account.empty() ? strf("'{}'", clientConnect->account) : "<anonymous>";
auto connectionFail = [&](String message) {
@ -1669,14 +1668,24 @@ void UniverseServer::acceptConnection(UniverseConnection connection, Maybe<HostA
}
}
Logger::info("UniverseServer: Logged in account '{}' as player '{}' from address {}",
accountString, clientConnect->playerName, remoteAddressString);
String connectionLog = strf("UniverseServer: Logged in account '{}' as player '{}' from address {}",
accountString, clientConnect->playerName, remoteAddressString);
if (Json& info = clientConnect->info) {
if (Json brand = info.get("brand", "custom"))
connectionLog += strf(" ({} client)", brand.toString());
if (info.getBool("legacy", false))
connection.packetSocket().setLegacy(legacyClient = true);
}
Logger::log(LogLevel::Info, connectionLog.utf8Ptr());
mainLocker.lock();
WriteLocker clientsLocker(m_clientsLock);
if (auto clashId = getClientForUuid(clientConnect->playerUuid)) {
if (administrator) {
doDisconnection(*clashId, "Duplicate Uuid joined and is Administrator so has priority.");
doDisconnection(*clashId, "Duplicate UUID joined and is Administrator so has priority.");
} else {
connectionFail("Duplicate player UUID");
return;