Skip to content
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

Info code refactoring #604

Merged
merged 19 commits into from
May 4, 2018
Merged

Info code refactoring #604

merged 19 commits into from
May 4, 2018

Conversation

theAsmodai
Copy link
Collaborator

I have made a lot of changes and hope all potencial bugs was fixed. Waiting for reviews.

@WPMGPRoSToTeMa
Copy link
Contributor

sv_rehlds_userinfo_transmitted_fields default value meaning changed. Can this break some games?

@theAsmodai
Copy link
Collaborator Author

I'm added default keys used in Half-Life. Don't know any mods that using custom keys. If you think rehlds should transmit all fields by default, how would you suggest to implement it?

Copy link
Collaborator

@LevShisterov LevShisterov left a comment

Choose a reason for hiding this comment

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

Checked only half, will look other part a bit later.

@@ -81,7 +81,7 @@ bool InfoString::SetString(char *string)
return false;
}

Q_strnlcpy(m_String, string, m_MaxSize);
Q_strnlcpy(m_String, string, m_MaxSize - 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks wrong, Q_strnlcpy do n-1 inside.

@@ -95,7 +95,7 @@ void InfoString::SetMaxSize(unsigned int maxSize)
if (m_String)
{
if (maxSize > Q_strlen(m_String)) {
Q_strnlcpy(newBuffer, m_String, maxSize);
Q_strnlcpy(newBuffer, m_String, maxSize - 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above.

s++;
}

*s = '0';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be '\0'. May be because of this pure =0 is better? Why testing didn't catched this one?

// Searches the string for the given
// key and returns the associated value, or an empty string.
const char* EXT_FUNC Info_ValueForKey(const char *s, const char *key)
const char* Info_ValueForKey(const char *s, const char *lookup)
Copy link
Collaborator

Choose a reason for hiding this comment

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

EXT_FUNC removal, probably ok, just curious, will be fine?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Checked again, it used in pmove, not only in engfuncs via proxy.


// skip key
while (*s != '\\')
s++;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can get past end of the string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I proceeded from the fact that buffer has already been checked for correctness. But can add for better reliability.

@WPMGPRoSToTeMa
Copy link
Contributor

how would you suggest to implement it?

Something of these:

sv_rehlds_userinfo_transmitted_fields "all"
sv_rehlds_userinfo_transmitted_fields "compat"
sv_rehlds_userinfo_transmitted_fields "legacy"
sv_rehlds_userinfo_transmitted_fields "old"
sv_rehlds_userinfo_transmitted_fields "\..."
sv_rehlds_userinfo_transmitted_fields "\all..."
sv_rehlds_userinfo_transmitted_fields "\...all"

Q_strncpy(dest, src, n - 1);
dest[n - 1] = '\0';
Q_strncpy(dest, src, n);
dest[n] = '\0';
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is, probably, not a good idea, because function goes beoynd specified size. You can just add description to a function, that it is copy n-1 chars and adds a newline in the end.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I consider this way is more logical. All functions of this family takes maximum string length, not the buffer size.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

May be use this one naming/signature?

@LevShisterov
Copy link
Collaborator

sv_rehlds_userinfo_transmitted_fields - empty value should work as before. So in case mod needs some custom info fields, server operator can set empty value for the cvar.

@theAsmodai
Copy link
Collaborator Author

I would like to add protection against wrong usage of sv_rehlds_userinfo_transmitted_fields. In my version empty value mean that only critical engine fields will be transmitted. So, cstrike owners can remove topcolor and bottomcolor since they are not used. Maybe we can add an additional cvar to on/off this option?

@IgnacioFDM
Copy link
Contributor

I'd recommend not breaking compatibility with sv_rehlds_userinfo_transmitted_fields

s++;

if (keyLen < lookupLen)
continue;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think Info_RemoveKey should remove exact keys, here for example and here (shouldn't remove password_test too). Possibly write a test for this also?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm copied the default engine behaviour. But since duplicate keys will be checked, we can change this to exact match.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You are right, it was so before. I think we should change this.


for (auto& field : g_info_important_fields) {
if (!Q_strncmp(key, field.name, keyLen))
return true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, "top" will be considered as important.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, you are right. I'm forgot to recheck it.

{
if (key[0] == '_') {
Con_Printf("%s: private keys couldn't be transmitted.\n", __FUNCTION__);
continue;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It will spam in console each time. Would be good to output key name at least.


if (Q_strlen(key) >= MAX_KV_LEN) {
Con_Printf("%s: keys and values must be < %i characters\n", __FUNCTION__, MAX_KV_LEN);
continue;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The same.

char add[512], valueBuf[32];
size_t userInfoLength = 0;

for (auto field : g_info_transmitted_fields)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can I suggest to rename it to g_info_transmit_fields?

Copy link
Collaborator

Choose a reason for hiding this comment

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

sv_rehlds_userinfo_transmitted_fields probably should be renamed too.

@LevShisterov
Copy link
Collaborator

LevShisterov commented Apr 18, 2018

About sv_rehlds_userinfo_transmitted_fields cvar and g_info_important_fields, I have a word from a side that some server ops wish to block *hltv and *sid sending to hide steamids, etc. So, probably mark these as not forced and include in default value?

@WPMGPRoSToTeMa
Copy link
Contributor

May be model should also be blockable due to #342.

@theAsmodai
Copy link
Collaborator Author

theAsmodai commented Apr 18, 2018

About sv_rehlds_userinfo_transmitted_fields cvar and g_info_important_fields, I have a word from a side that some server ops wish to block *hltv and *sid sending to hide steamids, etc. So, probably mark these as not forced and include in default value?

I think it's a bad idea. *sid blocking will break avatars showing on clients. And anyway hiding of steamid is a bad idea because it was designed as public identificator of players.

@theAsmodai
Copy link
Collaborator Author

@WPMGPRoSToTeMa, good idea, but this can lead to problems when used improperly.

@IgnacioFDM
Copy link
Contributor

@WPMGPRoSToTeMa

That's very useful. I'm in fact using that feature (hardcoded blocking of model) in my personal branch

@LevShisterov
Copy link
Collaborator

*sid blocking will break avatars showing on clients.

Yes, this is the desired (not by me) effect.

anyway hiding of steamid is a bad idea because it was designed as public identificator of players.

I am also not welcome the idea of blocking status and other steamid sources. But, still, we are open source, why not let people to shoot in the leg? Anyway, it's up to you, I don't care about this.

qboolean Info_IsKeyImportant(const char *key)
{
if (key[0] == '*')
return true;

for (auto& field : g_info_important_fields) {
if (!Q_strcmp(key, field.name))
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is possible to just do a char comparision at the end of the key for a '\' after a successfull Q_strncmp (in previous variant of that code). Then you woudn't do a copy of the key. Also, you can prefill g_info_important_fields with key lengths and then just do a len comparision before Q_strncmp. But I am ok with current variant too, so at your discretion.


existingKeys[existingKeysNum].start = key;
existingKeys[existingKeysNum].len = keyLen;
existingKeysNum++;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, one more thing: you should somehow assure that you will not go past existingKeys border. I think it should be incoming buffer length checking at the function start.

Copy link
Collaborator Author

@theAsmodai theAsmodai Apr 23, 2018

Choose a reason for hiding this comment

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

Ok. And the last question: should sv_rehlds_userinfo_transmitted_fields be renamed or not? I'm created wiki page https://github.com/dreamstalker/rehlds/wiki/Userinfo-keys and later I will will set the correct default value and description for this cvar.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thought about this, probably non-default value is used often in CS, so we can leave it as it is.

@theAsmodai theAsmodai force-pushed the info_refactoring branch 2 times, most recently from ce3b7eb to 60b201e Compare April 23, 2018 16:13
@theAsmodai theAsmodai force-pushed the info_refactoring branch 3 times, most recently from c3027e9 to fca78f0 Compare April 23, 2018 21:35
@theAsmodai
Copy link
Collaborator Author

Tests was fixed.

@theAsmodai theAsmodai merged commit f324df8 into master May 4, 2018
@theAsmodai theAsmodai deleted the info_refactoring branch May 4, 2018 20:38
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.

5 participants