Skip to content

Conversation

@cybellereaper
Copy link

Refactor Racing module: Introduce helper functions for race validation and reward handling

Copy link
Member

@yungcomputerchair yungcomputerchair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR has a lot of issues that lead me to believe you didn't write this code yourself:

  • The formatting and design is very opinionated and doesn't factor in the style of the code at all. You use const references which are good in practice but aren't used anywhere else. It's strange that the comments were ripped out, too.
  • Your helpers are unsound, and one of them isn't even used at all. The build doesn't pass, either. There's no way you tested this code at all.

Sorry, but we can't accept this as it is.

Comment on lines 1 to 6
#include "Racing.hpp"

#include "db/Database.hpp"
#include "servers/CNShardServer.hpp"

#include "NPCManager.hpp"
#include "PlayerManager.hpp"
#include "Missions.hpp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our headers are organized into a hierarchy to avoid things like cyclic inclusion. These spaces exist to indicate that, so please don't remove them.


static void racingStart(CNSocket* sock, CNPacketData* data) {
auto req = (sP_CL2FE_REQ_EP_RACE_START*)data->buf;
namespace {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use a namespace to isolate the helpers, just make them static so they're local to the file. This is the pattern we use in the rest of the codebase.

Comment on lines -32 to -45
resp.iStartTick = 0; // ignored
resp.iStartTick = 0;
resp.iLimitTime = EPData[mapNum].maxTime;

sock->sendPacket(resp, P_FE2CL_REP_EP_RACE_START_SUCC);
}

static void racingGetPod(CNSocket* sock, CNPacketData* data) {
if (EPRaces.find(sock) == EPRaces.end())
return; // race not found
return;

auto req = (sP_CL2FE_REQ_EP_GET_RING*)data->buf;

if (EPRaces[sock].collectedRings.count(req->iRingLID))
return; // can't collect the same ring twice
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your formatter might have stripped these comments

Comment on lines +17 to +23
bool validateRaceStart(CNSocket* sock, int32_t startEcomID) {
if (NPCManager::NPCs.find(startEcomID) == NPCManager::NPCs.end())
return false; // starting line agent not found

if (NPCManager::NPCs.find(req->iStartEcomID) == NPCManager::NPCs.end())
return; // starting line agent not found
int mapNum = MAPNUM(NPCManager::NPCs[startEcomID]->instanceID);
return EPData.find(mapNum) != EPData.end() && EPData[mapNum].EPID != 0;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should validate that a player is not already in a race.
I would also recommend having an output argument for mapnum to avoid having to recalculate it in the packet handlers.

int mapNum = MAPNUM(NPCManager::NPCs[req->iStartEcomID]->instanceID);
if (EPData.find(mapNum) == EPData.end() || EPData[mapNum].EPID == 0)
return; // IZ not found
bool validateRaceEnd(CNSocket* sock, int32_t endEcomID) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're not actually using this helper in Racing::racingEnd :P

postRanking.Time = timeDiff;
postRanking.Timestamp = getTimestamp();
Database::postRaceRanking(postRanking);
handleRaceRanking(epInfo, plr, podsCollected, score, timeDiff, resp);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmmmm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants