-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PlayerNetID helper #99
Conversation
The check is now performed in GetPlayerIndex function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code changes look good. I'm tempted to approve this, though I probably need to take another look over it first to see how the new exception may impact behaviour. It's possible an uncaught exception could have pretty bad consequences, depending on where it may occur.
client/OPUNetTransportLayer.cpp
Outdated
auto playerIndex = PlayerNetID::GetPlayerIndex(sourcePlayerNetID); | ||
// Make sure index is valid | ||
if (playerIndex >= MaxRemotePlayers) { | ||
continue; // Discard packet | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is, how does the code behave when an exception is thrown.
If you think it is safer, we can pull the out of bounds check from the code and merge. It means we probably cannot close issue #96 though. I'm not in a particular hurry to merge though if you want to spend time reviewing in depth. |
Hmm, that might not be a bad idea. While looking over the code, it occurs to me there are uses where bounds checking matters, and where it doesn't matter. In particular, the logging code should just output whatever the value is, even if it's wrong. Especially if it's wrong. Currently the error check would prevent that output. It may be easier to change the max number of players from 6 to 8. At least in terms of internal buffers, even if the UI still limits things to 6. const int MaxRemotePlayers = 8; There isn't a whole lot of wasted memory from that, since the array of player info is the following relatively small sized struct, which only needs an extra 2 copies. struct PeerInfo
{
int playerNetID;
int status;
sockaddr_in address;
bool bReturnJoinPacket;
}; In small cases like this, the extra data memory could end up being less than extra code memory needed to implement the check and error message. |
I'm not too concerned with memory usage as I suspect either solution would be imperceptible to the end user. It might make sense to focus on readability. Setting In several places, the code iterates through the entire We could add a new function called We could add a If this isn't easy to solve here, I'd rather just remove the check for now and merge if the rest looks good. We can leave the issue open and resolve later if it is an impasse. |
I had also thought about having two get functions, for either checks or unchecked reading. Of course you'd still need to sort the calls into the correct form, and determine if proper exception handling is being done. I'm kind of thinking remove the check for now so all the other changes can be merged in. There was some good stuff in the other code, and I don't want a large change set sitting open to accumulate merge commits with other stuff. In terms of setting players to 8, the underlying network code is perfectly capable of handling that. It's only the game engine and UI that limit it. Those can both potentially be updated. As for the iteration, I believe the send functions are checked so it doesn't send to players that don't exist. There may be some slight inefficiency in iterating over the entries, but I doubt it would ever be noticeable. Changing to |
OK, this should have restored original behaviour in handling invalid packets within the Receive function. The merge commit was a bear. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll bet it was.
Changes look good. I expect this will function the same as it did before.
I'm not great at bit manipulation, so probably bears a fair amount of scrutiny.