Skip to content

Commit 7becfb3

Browse files
committed
Use more real address in server
1 parent 02f8f6f commit 7becfb3

File tree

6 files changed

+26
-23
lines changed

6 files changed

+26
-23
lines changed

src/network/network_console.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ void mainLoop(STKHost* host)
9191
peer->kick();
9292
// ATM use permanently ban
9393
auto sl = LobbyProtocol::get<ServerLobby>();
94-
if (sl)
94+
// We don't support banning ipv6 address atm
95+
if (sl && peer->getIPV6Address().empty())
9596
sl->saveIPBanTable(peer->getAddress());
9697
}
9798
else
@@ -105,7 +106,7 @@ void mainLoop(STKHost* host)
105106
for (unsigned int i = 0; i < peers.size(); i++)
106107
{
107108
std::cout << peers[i]->getHostId() << ": " <<
108-
peers[i]->getAddress().toString() << " " <<
109+
peers[i]->getRealAddress() << " " <<
109110
peers[i]->getUserVersion() << std::endl;
110111
}
111112
}

src/network/protocol_manager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ void ProtocolManager::update(int ticks)
382382
}
383383
catch (std::exception& e)
384384
{
385-
const std::string& name = (*i)->getPeer()->getAddress().toString();
385+
const std::string& name = (*i)->getPeer()->getRealAddress();
386386
Log::error("ProtocolManager",
387387
"Synchronous event error from %s: %s", name.c_str(), e.what());
388388
Log::error("ProtocolManager", (*i)->data().getLogMessage().c_str());
@@ -441,7 +441,7 @@ void ProtocolManager::asynchronousUpdate()
441441
}
442442
catch (std::exception& e)
443443
{
444-
const std::string& name = (*i)->getPeer()->getAddress().toString();
444+
const std::string& name = (*i)->getPeer()->getRealAddress();
445445
Log::error("ProtocolManager", "Asynchronous event "
446446
"error from %s: %s", name.c_str(), e.what());
447447
Log::error("ProtocolManager",

src/network/protocols/game_events_protocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ bool GameEventsProtocol::notifyEvent(Event* event)
108108
if (!event->getPeer()->availableKartID(kart_id))
109109
{
110110
Log::warn("GameProtocol", "Wrong kart id %d from %s.",
111-
kart_id, event->getPeer()->getAddress().toString().c_str());
111+
kart_id, event->getPeer()->getRealAddress().c_str());
112112
return true;
113113
}
114114
float f = LobbyProtocol::get<ServerLobby>()

src/network/protocols/game_protocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void GameProtocol::handleControllerAction(Event *event)
205205
!peer->availableKartID(kart_id))
206206
{
207207
Log::warn("GameProtocol", "Wrong kart id %d from %s.",
208-
kart_id, peer->getAddress().toString().c_str());
208+
kart_id, peer->getRealAddress().c_str());
209209
return;
210210
}
211211

src/network/protocols/server_lobby.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,14 +1387,14 @@ void ServerLobby::liveJoinRequest(Event* event)
13871387
for (int id : used_id)
13881388
{
13891389
Log::info("ServerLobby", "%s live joining with reserved kart id %d.",
1390-
peer->getAddress().toString().c_str(), id);
1390+
peer->getRealAddress().c_str(), id);
13911391
peer->addAvailableKartID(id);
13921392
}
13931393
}
13941394
else
13951395
{
13961396
Log::info("ServerLobby", "%s spectating now.",
1397-
peer->getAddress().toString().c_str());
1397+
peer->getRealAddress().c_str());
13981398
}
13991399

14001400
std::vector<std::shared_ptr<NetworkPlayerProfile> > players =
@@ -1532,7 +1532,7 @@ void ServerLobby::finishedLoadingLiveJoinClient(Event* event)
15321532
if (!live_joined_in_time)
15331533
{
15341534
Log::warn("ServerLobby", "%s can't live-join in time.",
1535-
peer->getAddress().toString().c_str());
1535+
peer->getRealAddress().c_str());
15361536
rejectLiveJoin(peer.get(), BLR_NO_GAME_FOR_LIVE_JOIN);
15371537
return;
15381538
}
@@ -1553,12 +1553,12 @@ void ServerLobby::finishedLoadingLiveJoinClient(Event* event)
15531553
const RemoteKartInfo& rki = race_manager->getKartInfo(id);
15541554
addLiveJoiningKart(id, rki, m_last_live_join_util_ticks);
15551555
Log::info("ServerLobby", "%s succeeded live-joining with kart id %d.",
1556-
peer->getAddress().toString().c_str(), id);
1556+
peer->getRealAddress().c_str(), id);
15571557
}
15581558
if (peer->getAvailableKartIDs().empty())
15591559
{
15601560
Log::info("ServerLobby", "%s spectating succeeded.",
1561-
peer->getAddress().toString().c_str());
1561+
peer->getRealAddress().c_str());
15621562
spectator = true;
15631563
}
15641564

@@ -1631,7 +1631,7 @@ void ServerLobby::update(int ticks)
16311631
// Remove loading world too long (60 seconds) live join peer
16321632
Log::info("ServerLobby", "%s hasn't live-joined within"
16331633
" 60 seconds, remove it.",
1634-
peer->getAddress().toString().c_str());
1634+
peer->getRealAddress().c_str());
16351635
rki.makeReserved();
16361636
continue;
16371637
}
@@ -1642,7 +1642,7 @@ void ServerLobby::update(int ticks)
16421642
continue;
16431643
Log::info("ServerLobby", "%s %s has been idle for more than"
16441644
" %d seconds, kick.",
1645-
peer->getAddress().toString().c_str(),
1645+
peer->getRealAddress().c_str(),
16461646
StringUtils::wideToUtf8(rki.getPlayerName()).c_str(), sec);
16471647
peer->kick();
16481648
}
@@ -3010,7 +3010,7 @@ void ServerLobby::handleUnencryptedConnection(std::shared_ptr<STKPeer> peer,
30103010
Log::info("ServerLobby",
30113011
"New player %s with online id %u from %s with %s.",
30123012
StringUtils::wideToUtf8(npp->getName()).c_str(),
3013-
npp->getOnlineId(), peer->getAddress().toString().c_str(),
3013+
npp->getOnlineId(), peer->getRealAddress().c_str(),
30143014
peer->getUserVersion().c_str());
30153015
}
30163016
}
@@ -3727,7 +3727,7 @@ void ServerLobby::configPeersStartTime()
37273727
{
37283728
Log::warn("ServerLobby",
37293729
"Peer %s cannot catch up with max ping %d.",
3730-
peer->getAddress().toString().c_str(), max_ping);
3730+
peer->getRealAddress().c_str(), max_ping);
37313731
continue;
37323732
}
37333733
max_ping = std::max(peer->getAveragePing(), max_ping);
@@ -3802,7 +3802,7 @@ void ServerLobby::addWaitingPlayersToGame()
38023802
"New player %s with online id %u from %s with %s.",
38033803
StringUtils::wideToUtf8(profile->getName()).c_str(),
38043804
profile->getOnlineId(),
3805-
peer->getAddress().toString().c_str(),
3805+
peer->getRealAddress().c_str(),
38063806
peer->getUserVersion().c_str());
38073807
}
38083808
}
@@ -3868,7 +3868,7 @@ void ServerLobby::testBannedForIP(STKPeer* peer) const
38683868
const char* desc = (char*)sqlite3_column_text(stmt, 4);
38693869
Log::info("ServerLobby", "%s banned by IP: %s "
38703870
"(rowid: %d, description: %s).",
3871-
peer->getAddress().toString().c_str(), reason, row_id, desc);
3871+
peer->getRealAddress().c_str(), reason, row_id, desc);
38723872
kickPlayerWithReason(peer, reason);
38733873
}
38743874
ret = sqlite3_finalize(stmt);
@@ -3927,7 +3927,7 @@ void ServerLobby::testBannedForOnlineId(STKPeer* peer,
39273927
const char* desc = (char*)sqlite3_column_text(stmt, 2);
39283928
Log::info("ServerLobby", "%s banned by online id: %s "
39293929
"(online id: %u rowid: %d, description: %s).",
3930-
peer->getAddress().toString().c_str(), reason, online_id,
3930+
peer->getRealAddress().c_str(), reason, online_id,
39313931
row_id, desc);
39323932
kickPlayerWithReason(peer, reason);
39333933
}
@@ -4329,7 +4329,7 @@ void ServerLobby::clientInGameWantsToBackLobby(Event* event)
43294329
if (!w || !worldIsActive() || peer->isWaitingForGame())
43304330
{
43314331
Log::warn("ServerLobby", "%s try to leave the game at wrong time.",
4332-
peer->getAddress().toString().c_str());
4332+
peer->getRealAddress().c_str());
43334333
return;
43344334
}
43354335

@@ -4339,14 +4339,14 @@ void ServerLobby::clientInGameWantsToBackLobby(Event* event)
43394339
if (rki.getHostId() == peer->getHostId())
43404340
{
43414341
Log::info("ServerLobby", "%s left the game with kart id %d.",
4342-
peer->getAddress().toString().c_str(), id);
4342+
peer->getRealAddress().c_str(), id);
43434343
rki.setNetworkPlayerProfile(
43444344
std::shared_ptr<NetworkPlayerProfile>());
43454345
}
43464346
else
43474347
{
43484348
Log::error("ServerLobby", "%s doesn't exist anymore in server.",
4349-
peer->getAddress().toString().c_str());
4349+
peer->getRealAddress().c_str());
43504350
}
43514351
}
43524352
NetworkItemManager* nim =
@@ -4382,7 +4382,7 @@ void ServerLobby::clientSelectingAssetsWantsToBackLobby(Event* event)
43824382
{
43834383
Log::warn("ServerLobby",
43844384
"%s try to leave selecting assets at wrong time.",
4385-
peer->getAddress().toString().c_str());
4385+
peer->getRealAddress().c_str());
43864386
return;
43874387
}
43884388

src/network/stk_peer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
STKPeer::STKPeer(ENetPeer *enet_peer, STKHost* host, uint32_t host_id)
3838
: m_peer_address(enet_peer->address), m_host(host)
3939
{
40-
m_ipv6_address = getIPV6ReadableFromMappedAddress(&enet_peer->address);
40+
// We use 0.x.x.x ip to map to ipv6 address internally
41+
if (m_peer_address.getIP() < 16777216)
42+
m_ipv6_address = getIPV6ReadableFromMappedAddress(&enet_peer->address);
4143
m_enet_peer = enet_peer;
4244
m_host_id = host_id;
4345
m_connected_time = StkTime::getMonoTimeMs();

0 commit comments

Comments
 (0)