Skip to content

Commit ec07897

Browse files
committed
Old slight cleanups
1 parent b2f1d12 commit ec07897

File tree

4 files changed

+44
-56
lines changed

4 files changed

+44
-56
lines changed

src/network/protocols/command_manager.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -3149,7 +3149,7 @@ void CommandManager::process_hitmsg(Context& context)
31493149
error(context, true);
31503150
return;
31513151
}
3152-
if (m_lobby->getHitProcessor()->m_show_teammate_hits)
3152+
if (m_lobby->getHitProcessor()->showTeammateHits())
31533153
msg = "Teammate hits are sent to all players";
31543154
else
31553155
msg = "Teammate hits are not sent";
@@ -3168,10 +3168,10 @@ void CommandManager::process_hitmsg_assign(Context& context)
31683168
}
31693169
if (argv[1] == "0")
31703170
{
3171-
m_lobby->getHitProcessor()->m_show_teammate_hits = false;
3171+
m_lobby->getHitProcessor()->setShowTeammateHits(false);
31723172
msg = "Teammate hits will not be sent";
31733173
} else {
3174-
m_lobby->getHitProcessor()->m_show_teammate_hits = true;
3174+
m_lobby->getHitProcessor()->setShowTeammateHits(true);
31753175
msg = "Teammate hits will be sent to all players";
31763176
}
31773177
m_lobby->sendStringToAllPeers(msg);
@@ -3187,7 +3187,7 @@ void CommandManager::process_teamhit(Context& context)
31873187
error(context, true);
31883188
return;
31893189
}
3190-
if (m_lobby->getHitProcessor()->m_teammate_hit_mode)
3190+
if (m_lobby->getHitProcessor()->isTeammateHitMode())
31913191
msg = "Teammate hits are punished";
31923192
else
31933193
msg = "Teammate hits are not punished";
@@ -3206,12 +3206,12 @@ void CommandManager::process_teamhit_assign(Context& context)
32063206
}
32073207
if (argv[1] == "0")
32083208
{
3209-
m_lobby->getHitProcessor()->m_teammate_hit_mode = false;
3209+
m_lobby->getHitProcessor()->setTeammateHitMode(false);
32103210
msg = "Teammate hits are not punished now";
32113211
}
32123212
else
32133213
{
3214-
m_lobby->getHitProcessor()->m_teammate_hit_mode = true;
3214+
m_lobby->getHitProcessor()->setTeammateHitMode(true);
32153215
msg = "Teammate hits are punished now";
32163216
}
32173217
m_lobby->sendStringToAllPeers(msg);

src/network/protocols/server_lobby.cpp

+6-40
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@
1818

1919
#include "network/protocols/server_lobby.hpp"
2020

21-
// #include "addons/addon.hpp"
22-
// #include "config/user_config.hpp"
2321
#include "items/network_item_manager.hpp"
24-
// #include "items/powerup_manager.hpp"
2522
#include "items/attachment.hpp"
26-
// #include "karts/controller/player_controller.hpp"
2723
#include "karts/kart_properties.hpp"
2824
#include "karts/kart_properties_manager.hpp"
2925
#include "karts/official_karts.hpp"
@@ -34,35 +30,25 @@
3430
#include "network/database_connector.hpp"
3531
#include "network/event.hpp"
3632
#include "network/game_setup.hpp"
37-
// #include "network/network.hpp"
3833
#include "network/network_config.hpp"
3934
#include "network/network_player_profile.hpp"
40-
// #include "network/peer_vote.hpp"
4135
#include "network/protocol_manager.hpp"
4236
#include "network/protocols/connect_to_peer.hpp"
43-
// #include "network/protocols/command_permissions.hpp"
4437
#include "network/protocols/game_protocol.hpp"
4538
#include "network/protocols/game_events_protocol.hpp"
4639
#include "network/protocols/ranking.hpp"
4740
#include "network/race_event_manager.hpp"
4841
#include "network/server_config.hpp"
49-
// #include "network/socket_address.hpp"
5042
#include "network/stk_host.hpp"
5143
#include "network/stk_ipv6.hpp"
5244
#include "network/stk_peer.hpp"
53-
// #include "online/online_profile.hpp"
5445
#include "online/request_manager.hpp"
5546
#include "online/xml_request.hpp"
56-
// #include "race/race_manager.hpp"
5747
#include "tracks/check_manager.hpp"
5848
#include "tracks/track.hpp"
5949
#include "tracks/track_manager.hpp"
6050
#include "utils/game_info.hpp"
6151
#include "utils/hit_processor.hpp"
62-
// #include "utils/log.hpp"
63-
// #include "utils/random_generator.hpp"
64-
// #include "utils/string_utils.hpp"
65-
// #include "utils/time.hpp"
6652
#include "utils/translation.hpp"
6753

6854
#include <algorithm>
@@ -171,7 +157,6 @@ ServerLobby::ServerLobby() : LobbyProtocol()
171157
m_troll_active = ServerConfig::m_troll_active;
172158

173159
m_hit_processor = std::make_shared<HitProcessor>(this);
174-
// feb16 remove this
175160

176161
m_available_teams = ServerConfig::m_init_available_teams;
177162

@@ -431,7 +416,6 @@ void ServerLobby::setup()
431416
m_winner_peer_id = 0;
432417
m_client_starting_time = 0;
433418
m_ai_count = 0;
434-
getHitProcessor()->m_collecting_teammate_hit_info = false;
435419
auto players = STKHost::get()->getPlayersForNewGame();
436420
if (m_game_setup->isGrandPrix() && !m_game_setup->isGrandPrixStarted())
437421
{
@@ -527,12 +511,8 @@ void ServerLobby::handleChat(Event* event)
527511
event->getPeer()->getConsecutiveMessages() >
528512
ServerConfig::m_chat_consecutive_interval / 2)
529513
{
530-
NetworkString* chat = getNetworkString();
531-
chat->setSynchronous(true);
532-
core::stringw warn = "Spam detected";
533-
chat->addUInt8(LE_CHAT).encodeString16(warn);
534-
event->getPeer()->sendPacket(chat, PRM_RELIABLE);
535-
delete chat;
514+
std::string msg = "Spam detected";
515+
sendStringToPeer(msg, event->getPeerSP());
536516
return;
537517
}
538518

@@ -547,12 +527,8 @@ void ServerLobby::handleChat(Event* event)
547527

548528
if (!StringUtils::startsWith(message_utf8, prefix))
549529
{
550-
NetworkString* chat = getNetworkString();
551-
chat->setSynchronous(true);
552-
core::stringw warn = "Don't try to impersonate others!";
553-
chat->addUInt8(LE_CHAT).encodeString16(warn);
554-
event->getPeer()->sendPacket(chat, PRM_RELIABLE);
555-
delete chat;
530+
std::string warn = "Don't try to impersonate others!";
531+
sendStringToPeer(warn, event->getPeerSP());
556532
return;
557533
}
558534

@@ -1163,7 +1139,7 @@ void ServerLobby::asynchronousUpdate()
11631139
// reset
11641140

11651141
// maybe this is not the best place for this?
1166-
getHitProcessor()->m_last_teammate_hit_msg = 0;
1142+
getHitProcessor()->resetLastHits();
11671143

11681144
if (m_end_voting_period.load() == 0)
11691145
return;
@@ -1930,17 +1906,7 @@ void ServerLobby::update(int ticks)
19301906
}
19311907
}
19321908
}
1933-
if (getHitProcessor()->m_teammate_swatter_punish.size() > 0)
1934-
{
1935-
// punish players who swattered teammates
1936-
for (auto& kart : getHitProcessor()->m_teammate_swatter_punish)
1937-
{
1938-
kart->getAttachment()->set(Attachment::ATTACH_ANVIL,
1939-
stk_config->time2Ticks(kart->getKartProperties()->getAnvilDuration()));
1940-
kart->adjustSpeed(kart->getKartProperties()->getAnvilSpeedFactor());
1941-
}
1942-
getHitProcessor()->m_teammate_swatter_punish.clear();
1943-
}
1909+
getHitProcessor()->punishSwatterHits();
19441910
}
19451911
}
19461912
if (m_state.load() == WAITING_FOR_START_GAME) {

src/utils/hit_processor.cpp

+25-6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ HitProcessor::HitProcessor(ServerLobby* lobby): m_lobby(lobby)
3232
m_teammate_hit_mode = ServerConfig::m_teammate_hit_mode;
3333
m_last_teammate_hit_msg = 0;
3434
m_teammate_swatter_punish.clear();
35+
36+
// This was also present in ServerLobby::setup(), I'm not sure why.
37+
// Return back if there are problems.
3538
m_collecting_teammate_hit_info = false;
3639
} // HitProcessor
3740
// ========================================================================
@@ -100,7 +103,7 @@ void HitProcessor::handleTeamMateHits()
100103
return;
101104

102105
// Show message?
103-
if (showTeamMateHits())
106+
if (showTeammateHits())
104107
{
105108
// prepare string
106109
int num_victims = 0;
@@ -131,7 +134,7 @@ void HitProcessor::handleTeamMateHits()
131134
}
132135
}
133136

134-
if (useTeamMateHitMode())
137+
if (isTeammateHitMode())
135138
{
136139
bool punished = false;
137140
// first check if we exploded at least one teammate
@@ -226,7 +229,7 @@ void HitProcessor::handleSwatterHit(unsigned int ownerID, unsigned int victimID,
226229
return;
227230

228231
// should we tell the world?
229-
if (showTeamMateHits() && success)
232+
if (showTeammateHits() && success)
230233
{
231234
std::string msg = StringUtils::insertValues(
232235
"%s%s just swattered teammate %s",
@@ -236,7 +239,7 @@ void HitProcessor::handleSwatterHit(unsigned int ownerID, unsigned int victimID,
236239
);
237240
sendTeamMateHitMsg(msg);
238241
}
239-
if (useTeamMateHitMode())
242+
if (isTeammateHitMode())
240243
{
241244
// remove swatter
242245
AbstractKart *owner = World::getWorld()->getKart(ownerID);
@@ -267,7 +270,7 @@ void HitProcessor::handleAnvilHit(unsigned int ownerID, unsigned int victimID)
267270
AbstractKart *owner = World::getWorld()->getKart(ownerID);
268271

269272
// should we tell the world?
270-
if (showTeamMateHits())
273+
if (showTeammateHits())
271274
{
272275
std::string msg = StringUtils::insertValues(
273276
"%s%s just gave an anchor to teammate %s",
@@ -277,7 +280,7 @@ void HitProcessor::handleAnvilHit(unsigned int ownerID, unsigned int victimID)
277280
);
278281
sendTeamMateHitMsg(msg);
279282
}
280-
if (useTeamMateHitMode())
283+
if (isTeammateHitMode())
281284
{
282285
if (owner->getAttachment()->getType() == Attachment::ATTACH_BOMB)
283286
{
@@ -309,4 +312,20 @@ void HitProcessor::handleAnvilHit(unsigned int ownerID, unsigned int victimID)
309312
}
310313
}
311314
} // handleAnvilHit
315+
//-----------------------------------------------------------------------------
316+
317+
void HitProcessor::punishSwatterHits()
318+
{
319+
if (m_teammate_swatter_punish.size() > 0)
320+
{
321+
// punish players who swattered teammates
322+
for (auto& kart : m_teammate_swatter_punish)
323+
{
324+
kart->getAttachment()->set(Attachment::ATTACH_ANVIL,
325+
stk_config->time2Ticks(kart->getKartProperties()->getAnvilDuration()));
326+
kart->adjustSpeed(kart->getKartProperties()->getAnvilSpeedFactor());
327+
}
328+
m_teammate_swatter_punish.clear();
329+
}
330+
} // punishSwatterHits
312331
//-----------------------------------------------------------------------------

src/utils/hit_processor.hpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ class HitProcessor
3535
public:
3636
HitProcessor(ServerLobby* lobby);
3737

38-
public: // feb16 remove todo revert to private
39-
// feb16 remove
38+
private:
4039
ServerLobby* m_lobby = nullptr;
4140

4241
bool m_show_teammate_hits; // Whether to show messages about team hits.
@@ -63,6 +62,10 @@ class HitProcessor
6362

6463
public:
6564
// handle cakes and bowls
65+
bool isTeammateHitMode() const { return m_teammate_hit_mode; }
66+
bool showTeammateHits() const { return m_show_teammate_hits; }
67+
void setTeammateHitMode(bool value) { m_teammate_hit_mode = value; }
68+
void setShowTeammateHits(bool value) { m_show_teammate_hits = value; }
6669
void setTeamMateHitOwner(unsigned int ownerID, uint16_t ticks_since_thrown = 0);
6770
void registerTeamMateHit(unsigned int kartID);
6871
void registerTeamMateExplode(unsigned int kartID);
@@ -74,8 +77,8 @@ class HitProcessor
7477
void handleAnvilHit(unsigned int ownerID, unsigned int victimID);
7578

7679
void sendTeamMateHitMsg(std::string& s);
77-
bool showTeamMateHits() const { return m_show_teammate_hits; }
78-
bool useTeamMateHitMode() const { return m_teammate_hit_mode; }
80+
void punishSwatterHits();
81+
void resetLastHits() { m_last_teammate_hit_msg = 0; }
7982
};
8083

8184

0 commit comments

Comments
 (0)