Skip to content

Commit 1f3c181

Browse files
committed
Minor fixes, also make PR a LobbyProtocol for some reason
1 parent 1203e47 commit 1f3c181

4 files changed

Lines changed: 24 additions & 27 deletions

File tree

src/network/protocols/playing_room.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "utils/hit_processor.hpp"
5858
#include "modes/capture_the_flag.hpp"
5959
#include "utils/chat_manager.hpp"
60+
#include "network/protocols/game_events_protocol.hpp"
6061

6162
namespace
6263
{
@@ -205,7 +206,7 @@ void PlayingRoom::updateRoom(int ticks)
205206
{
206207
World* w = World::getWorld();
207208
bool world_started = m_play_state.load() >= WAIT_FOR_WORLD_LOADED &&
208-
m_state.load() <= RACING && m_server_has_loaded_world.load();
209+
m_play_state.load() <= RACING && m_server_has_loaded_world.load();
209210
bool all_players_in_world_disconnected = (w != NULL && world_started);
210211
int sec = getSettings()->getKickIdlePlayerSeconds();
211212
if (world_started)
@@ -243,7 +244,7 @@ void PlayingRoom::updateRoom(int ticks)
243244
if (w && w->getKart(i)->hasFinishedRace())
244245
continue;
245246
// Don't kick in game GUI server host so he can idle in game
246-
if (m_process_type == PT_CHILD && isClientServerHost(peer))
247+
if (getLobby()->isChildClientServerHost(peer))
247248
continue;
248249
Log::info("ServerLobby", "%s %s has been idle ingame for more than"
249250
" %d seconds, kick.",
@@ -282,7 +283,7 @@ void PlayingRoom::updateRoom(int ticks)
282283
getHitProcessor()->punishSwatterHits();
283284
}
284285
}
285-
if (m_state.load() == WAITING_FOR_START_GAME) {
286+
if (m_play_state.load() == WAITING_FOR_START_GAME) {
286287
sec = getSettings()->getKickIdleLobbyPlayerSeconds();
287288
auto peers = STKHost::get()->getPeers();
288289
for (auto peer: peers)
@@ -292,7 +293,7 @@ void PlayingRoom::updateRoom(int ticks)
292293
!peer->isDisconnected() && NetworkConfig::get()->isWAN())
293294
{
294295
// Don't kick in game GUI server host so he can idle in the lobby
295-
if (m_process_type == PT_CHILD && isClientServerHost(peer))
296+
if (getLobby()->isChildClientServerHost(peer))
296297
continue;
297298
std::string peer_name = "";
298299
if (peer->hasPlayerProfiles())
@@ -306,14 +307,14 @@ void PlayingRoom::updateRoom(int ticks)
306307
}
307308

308309
if (w)
309-
m_game_progress = w->getGameStartedProgress();
310+
setGameStartedProgress(w->getGameStartedProgress());
310311
else
311-
m_game_progress = { std::numeric_limits<uint32_t>::max(), std::numeric_limits<uint32_t>::max() };
312+
resetGameStartedProgress();
312313

313314
if (w && w->getPhase() == World::RACE_PHASE)
314-
m_playing_track = (RaceManager::get()->getTrackName());
315+
storePlayingTrack(RaceManager::get()->getTrackName());
315316
else
316-
m_playing_track = "";
317+
storePlayingTrack("");
317318

318319
// Reset server to initial state if no more connected players
319320
if (m_rs_state.load() == RS_WAITING)
@@ -329,7 +330,7 @@ void PlayingRoom::updateRoom(int ticks)
329330

330331
STKHost::get()->updatePlayers();
331332
if (m_rs_state.load() == RS_NONE &&
332-
(m_state.load() > WAITING_FOR_START_GAME/* ||
333+
(m_play_state.load() > WAITING_FOR_START_GAME/* ||
333334
m_game_setup->isGrandPrixStarted()*/) &&
334335
(STKHost::get()->getPlayersInGame() == 0 ||
335336
all_players_in_world_disconnected))
@@ -372,7 +373,7 @@ void PlayingRoom::updateRoom(int ticks)
372373

373374
// Reset for ranked server if in kart / track selection has only 1 player
374375
if (getSettings()->isRanked() &&
375-
m_state.load() == SELECTING &&
376+
m_play_state.load() == SELECTING &&
376377
STKHost::get()->getPlayersInGame() == 1)
377378
{
378379
NetworkString* back_lobby = getNetworkString(2);
@@ -391,8 +392,6 @@ void PlayingRoom::updateRoom(int ticks)
391392

392393
switch (m_play_state.load())
393394
{
394-
case SET_PUBLIC_ADDRESS:
395-
case REGISTER_SELF_ADDRESS:
396395
case WAITING_FOR_START_GAME:
397396
case WAIT_FOR_WORLD_LOADED:
398397
case WAIT_FOR_RACE_STARTED:
@@ -450,9 +449,6 @@ void PlayingRoom::updateRoom(int ticks)
450449
m_rs_state.store(RS_ASYNC_RESET);
451450
}
452451
break;
453-
case ERROR_LEAVE:
454-
case EXITING:
455-
break;
456452
}
457453
} // updateRoom
458454
//-----------------------------------------------------------------------------
@@ -769,7 +765,6 @@ void PlayingRoom::asynchronousUpdateRoom()
769765
} // asynchronousUpdateRoom
770766
//-----------------------------------------------------------------------------
771767

772-
773768
/** Calls the corresponding method from LobbyAssetManager
774769
* whenever server is reset or game mode is changed. */
775770
[[deprecated("Asset managers should be separate for different rooms.")]]
@@ -780,6 +775,7 @@ void PlayingRoom::updateMapsForMode()
780775
);
781776
} // updateMapsForMode
782777
//-----------------------------------------------------------------------------
778+
783779
NetworkString* PlayingRoom::getLoadWorldMessage(
784780
std::vector<std::shared_ptr<NetworkPlayerProfile> >& players,
785781
bool live_join) const
@@ -1481,7 +1477,7 @@ void PlayingRoom::clientInGameWantsToBackLobby(Event* event)
14811477
return;
14821478
}
14831479

1484-
if (m_process_type == PT_CHILD && isClientServerHost(event->getPeer()))
1480+
if (getLobby()->isChildClientServerHost(event->getPeer()))
14851481
{
14861482
// For child server the remaining client cannot go on player when the
14871483
// server owner quited the game (because the world will be deleted), so
@@ -1569,7 +1565,7 @@ void PlayingRoom::clientSelectingAssetsWantsToBackLobby(Event* event)
15691565
return;
15701566
}
15711567

1572-
if (m_process_type == PT_CHILD && isClientServerHost(event->getPeer()))
1568+
if (getLobby()->isChildClientServerHost(event->getPeerSP()))
15731569
{
15741570
NetworkString* back_to_lobby = getNetworkString(2);
15751571
back_to_lobby->setSynchronous(true);

src/network/protocols/playing_room.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "utils/lobby_context.hpp"
2424
#include "network/packet_types.hpp"
2525
#include "network/kart_data.hpp"
26+
#include "network/protocols/lobby_protocol.hpp"
2627

2728
#include <algorithm>
2829
#include <atomic>
@@ -38,7 +39,7 @@ class GameInfo;
3839
class NetworkItemManager;
3940

4041

41-
class PlayingRoom: public LobbyContextUser
42+
class PlayingRoom: public LobbyProtocol, public LobbyContextUser
4243
{
4344
private:
4445
std::atomic<ServerPlayState> m_play_state;
@@ -171,11 +172,6 @@ class PlayingRoom: public LobbyContextUser
171172
void addLiveJoinPlaceholder(
172173
std::vector<std::shared_ptr<NetworkPlayerProfile> >& players) const;
173174

174-
std::pair<uint32_t, uint32_t> getGameStartedProgress() const
175-
{ return m_game_progress; }
176-
177-
std::string getPlayingTrack() const { return m_playing_track; }
178-
179175
public: // were public before and SL doesn't call them
180176

181177
void setTimeoutFromNow(int seconds);

src/network/protocols/server_lobby.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ bool ServerLobby::notifyEventAsynchronous(Event* event)
314314
Log::info("ServerLobby", "Message of type %d received.",
315315
message_type);
316316

317-
auto& room = getRoomForPeer(event->getPeerSP());
317+
auto room = getRoomForPeer(event->getPeerSP());
318318

319319
switch(message_type)
320320
{
@@ -598,7 +598,7 @@ void ServerLobby::update(int ticks)
598598
room->updateRoom(ticks);
599599

600600
setGameStartedProgress(m_rooms[0]->getGameStartedProgress());
601-
storePlayingTrack(m_rooms[0]->getPlayingTrack());
601+
storePlayingTrack(m_rooms[0]->getPlayingTrackIdent());
602602
} // update
603603

604604
//-----------------------------------------------------------------------------
@@ -1009,7 +1009,7 @@ bool ServerLobby::handleAssetsAndAddonScores(std::shared_ptr<STKPeer> peer,
10091009
peer->setAvailableKartsTracks(client_karts, client_maps);
10101010
peer->setAddonsScores(addons_scores);
10111011

1012-
if (m_process_type == PT_CHILD && isClientServerHost(peer))
1012+
if (isChildClientServerHost(peer))
10131013
{
10141014
// Update child process addons list too so player can choose later
10151015
getAssetManager()->updateAddons();

src/network/protocols/server_lobby.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ class ServerLobby : public LobbyProtocol, public LobbyContextUser
313313
bool isChildProcess() { return m_process_type == PT_CHILD; }
314314

315315
bool isClientServerHost(const std::shared_ptr<STKPeer>& peer);
316+
bool isChildClientServerHost(const std::shared_ptr<STKPeer>& peer)
317+
{
318+
return isChildProcess() && isClientServerHost(peer);
319+
}
320+
316321
bool canIgnoreControllerEvents() const;
317322
bool isPeerInGame(const std::shared_ptr<STKPeer>& peer) const;
318323
bool hasAnyGameStarted() const;

0 commit comments

Comments
 (0)