-
-
Notifications
You must be signed in to change notification settings - Fork 176
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
Conversation
Removed engine initialization in info tests
Fix duplicate info tests
|
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? |
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.
Checked only half, will look other part a bit later.
rehlds/HLTV/common/InfoString.cpp
Outdated
@@ -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); |
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.
This looks wrong, Q_strnlcpy do n-1 inside.
rehlds/HLTV/common/InfoString.cpp
Outdated
@@ -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); |
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.
Same as above.
rehlds/engine/host_cmd.cpp
Outdated
s++; | ||
} | ||
|
||
*s = '0'; |
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.
Should be '\0'. May be because of this pure =0 is better? Why testing didn't catched this one?
rehlds/engine/info.cpp
Outdated
// 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) |
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.
EXT_FUNC removal, probably ok, just curious, will be fine?
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.
Checked again, it used in pmove, not only in engfuncs via proxy.
rehlds/engine/info.cpp
Outdated
|
||
// skip key | ||
while (*s != '\\') | ||
s++; |
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.
Can get past end of the string.
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 proceeded from the fact that buffer has already been checked for correctness. But can add for better reliability.
Something of these:
|
rehlds/public/strtools.h
Outdated
Q_strncpy(dest, src, n - 1); | ||
dest[n - 1] = '\0'; | ||
Q_strncpy(dest, src, n); | ||
dest[n] = '\0'; |
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.
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.
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 consider this way is more logical. All functions of this family takes maximum string length, not the buffer size.
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.
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.
May be use this one naming/signature?
|
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? |
467eb48
to
bdbb0c7
Compare
bdbb0c7
to
f6dad3b
Compare
I'd recommend not breaking compatibility with sv_rehlds_userinfo_transmitted_fields |
rehlds/engine/info.cpp
Outdated
s++; | ||
|
||
if (keyLen < lookupLen) | ||
continue; |
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 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?
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'm copied the default engine behaviour. But since duplicate keys will be checked, we can change this to exact match.
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.
You are right, it was so before. I think we should change this.
rehlds/engine/info.cpp
Outdated
|
||
for (auto& field : g_info_important_fields) { | ||
if (!Q_strncmp(key, field.name, keyLen)) | ||
return true; |
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.
Same here, "top" will be considered as important.
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.
Yes, you are right. I'm forgot to recheck it.
rehlds/engine/info.cpp
Outdated
{ | ||
if (key[0] == '_') { | ||
Con_Printf("%s: private keys couldn't be transmitted.\n", __FUNCTION__); | ||
continue; |
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.
It will spam in console each time. Would be good to output key name at least.
rehlds/engine/info.cpp
Outdated
|
||
if (Q_strlen(key) >= MAX_KV_LEN) { | ||
Con_Printf("%s: keys and values must be < %i characters\n", __FUNCTION__, MAX_KV_LEN); | ||
continue; |
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 same.
rehlds/engine/info.cpp
Outdated
char add[512], valueBuf[32]; | ||
size_t userInfoLength = 0; | ||
|
||
for (auto field : g_info_transmitted_fields) |
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.
Can I suggest to rename it to g_info_transmit_fields
?
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.
sv_rehlds_userinfo_transmitted_fields probably should be renamed too.
About |
May be |
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. |
@WPMGPRoSToTeMa, good idea, but this can lead to problems when used improperly. |
That's very useful. I'm in fact using that feature (hardcoded blocking of |
Yes, this is the desired (not by me) effect.
I am also not welcome the idea of blocking |
rehlds/engine/info.cpp
Outdated
qboolean Info_IsKeyImportant(const char *key) | ||
{ | ||
if (key[0] == '*') | ||
return true; | ||
|
||
for (auto& field : g_info_important_fields) { | ||
if (!Q_strcmp(key, field.name)) |
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.
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.
rehlds/engine/info.cpp
Outdated
|
||
existingKeys[existingKeysNum].start = key; | ||
existingKeys[existingKeysNum].len = keyLen; | ||
existingKeysNum++; |
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.
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.
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.
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.
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.
Thought about this, probably non-default value is used often in CS, so we can leave it as it is.
ce3b7eb
to
60b201e
Compare
60b201e
to
625b962
Compare
c3027e9
to
fca78f0
Compare
fca78f0
to
3294ecf
Compare
Tests was fixed. |
I have made a lot of changes and hope all potencial bugs was fixed. Waiting for reviews.