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

Fix Teeworlds server query, #3 #4

Merged
merged 1 commit into from
Nov 26, 2016

Conversation

illwieckz
Copy link
Contributor

Hi, this fixes the Teeworlds server query, it tries with the 3 known getinfo packets.

I renamed the -tee argument to -tees since I will work next on the -teem Teeworlds master query.

Since Teeworlds support was broken since many years, there is probably nobody that uses the -tee arg today.

@@ -511,3 +511,4 @@ gametype ALIENARENAM new extend Q2M
master query = empty full
master for gametype = ALIENARENAS
end

Copy link
Contributor

Choose a reason for hiding this comment

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

irelavent change, please remove from the commit.

@stevenh
Copy link
Contributor

stevenh commented Nov 16, 2014

Overall can you please update the formatting for the teeworld module as per the new style, which is based off:
https://www.freebsd.org/cgi/man.cgi?query=style&sektion=9

An example of this can be found in the dirty bomb module.

@illwieckz
Copy link
Contributor Author

-query_status_t deal_with_tee_packet( struct qserver *server, char *rawpkt, int pktlen )
+query_status_t deal_with_tee_packet( struct qserver *server, char *pkt, int pktlen )

This is still a raw packet please keep the old var name

That was because

-query_status_t deal_with_tee_packet( struct qserver *server, char *rawpkt, int pktlen )
+query_status_t deal_with_tee_packet( struct qserver *server, char *pkt, int pktlen )
-       char *pkt = rawpkt + 6;

Because the + 6 was not relevant anymore, I've only rename rawpkt this line to avoid renaming each occurrence in the whole file. So, I will rename pkt as rawpkt in the whole file.

Overall can you please update the formatting for the teeworld module as per the new style, which is based off:
https://www.freebsd.org/cgi/man.cgi?query=style&sektion=9
An example of this can be found in the dirty bomb module.

OK. Good idea.

+
irelavent change, please remove from the commit.

Yes, unfortunately, I see that pointless thing after my pull request so I did not rewrite the commit to not pollute the git history and the github history (because the commit name contains the issue number, each commit rewrite can appear in the issue #3 thread).

I've already deleted this useless line, so it will disappear in my next commit (master server).

I will propose a clean pull request with server support fix + new master server when master support will be finished.

The master server support is well underway, but I need a little help, cf. #5 😉

@leepa
Copy link

leepa commented Nov 16, 2014

You can delete the line and commit --amend to update your pull request.

@illwieckz
Copy link
Contributor Author

I rewritten the commit.

}

/* version */
version = strdup (rawpkt); rawpkt += strlen (rawpkt) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Each line should be on a separate new line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with that, I have done that for only one reason: mimic the existing code because it is a prudent way to do what others expect.


server->protocol_version = 0;

if (NULL == (tok = strtok(version, "."))) return -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

returns should be on a new line and NULL at the other side

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, also, -1 has a name, SYS_ERROR.

My big question is "how this code was accepted before?" 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

That should return PKT_ERROR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code is worse than I imagined. 😆

@stevenh
Copy link
Contributor

stevenh commented Nov 17, 2014

Thanks for fixing the issues, appreciate half of them are legacy code, but best to fix them as your going through :)

@stevenh
Copy link
Contributor

stevenh commented Nov 17, 2014

This pull request is for #3

@illwieckz
Copy link
Contributor Author

Hi, what do you think about renaming tee.c to teeworlds.c and qstat args to -teeworldss and -teeworldsm ? I see that newer games use complete name. Since the Teeworlds server support was broken since many years and the Teeworlds master support was never written before, there will not be many people complaining about it. 😄

@stevenh
Copy link
Contributor

stevenh commented Nov 19, 2014

I'd keep that change separate if we did it.
On 19/11/2014 07:42, Thomas Debesse wrote:

Hi, what do you think about renaming |tee.c| to |teeworlds.c| and
qstat args to |-teeworldss| and |-teeworldsm| ? I see that newer games
use complete name. Since the Teeworlds server support was broken since
many years and the Teeworlds master support was never written before,
there will not be many people complaining about it. 😄


Reply to this email directly or view it on GitHub
#4 (comment).

@illwieckz
Copy link
Contributor Author

OK, can you confirme it is safe to free this strdup : illwieckz@59661ba#diff-ba6f07c5675bc4ade962db2a9e368d8eR147 ?

@illwieckz
Copy link
Contributor Author

Hi, we are close to do it. I think the only one thing that prevent you to merge now is my question above, if you say yes, I will modify these lines and you will be able to merge after that.

@illwieckz illwieckz changed the title fix teeworld server query, #3 fix Teeworlds server query, #3 Jan 23, 2015
@illwieckz
Copy link
Contributor Author

Hi, I've updated.

The part with the useless strdup was rewritten, and I added an extra test to verify that the whole packet had a NULL end in it. In fact, all strnlen called on packet parts are called with a safe maxlength, so this extra test is probably not necessary.

@stevenh
Copy link
Contributor

stevenh commented Jan 24, 2015

Your strnlen tests where fine but add_rule uses strdup so if its not null terminated then "boom" ;-)

}

/* not null-terminated packet */
if (strnlen(rawpkt, rawpktlen) == rawpktlen && rawpkt[rawpktlen - 1] != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the strlen, surely that will always fail as the last byte is expected to be 0 hence the length with be rawpktlen - 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to test "there is no null before end" (length=maxlength) and "last is not null"

Just to verify:

$ cat a.c
#include <stdio.h>
#include <strings.h>

int main (void) {

    char tab1[3]={'a', 'b', 'c'};
    char tab2[3]={'a', 'b', 0};

    printf("not terminated: %d\n", strnlen(tab1, 3));
    printf("null terminated: %d\n", strnlen(tab2, 3));

}

$ gcc -o a a.c

$ ./a 
not terminated: 3
null terminated: 2

So, strnlen returns rawpktlen if not terminated string, first condition works and is sufficient, no need to test the last character.

So only:

if (strnlen(rawpkt, rawpktlen) == rawpktlen) {
    return (PKT_ERROR);
}

is needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

No you still need the null check as strnlen will return rawpktlen even if it wasn't null terminated.

@stevenh
Copy link
Contributor

stevenh commented Mar 31, 2015

Any update on this @illwieckz ?

@illwieckz
Copy link
Contributor Author

Hi @stevenh, I do not forget this, it's just that I do not have much time these days. I'll work on it soon. 😉

@stevenh
Copy link
Contributor

stevenh commented Mar 31, 2015

No problem just checking :)

@illwieckz
Copy link
Contributor Author

Just to say, I will probably be able to work on it in july or august. I’m not forgetting this, I’m just very busy. :-)

@illwieckz
Copy link
Contributor Author

Hi @stevenh, I modified my patch, if you want to test it you can do that:

qstat -default tees -f /tmp/teelist.txt

With this list as /tmp/teelist.txt.

/* if inf2 or inf3 */
if (last_char == '2' || last_char == '3') {
/* token, skip */
current += strnlen(current, end - current) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like you could simply these tests by switching to maintaining a "remaining" instead of having to constantly check against end - current?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I don't know why, but my question disappeared, I was asking if I can just do that:

current += strlen(current) + 1;

since I already checked that the packet is NULL-terminated.

@illwieckz illwieckz changed the title fix Teeworlds server query, #3 [WIP] fix Teeworlds server query, #3 Aug 20, 2015
@vorot93
Copy link
Contributor

vorot93 commented Sep 21, 2015

This PR is nearly 1 year old. Outline any remaining issues in PR's description perhaps?

@stevenh stevenh changed the title [WIP] fix Teeworlds server query, #3 Fix Teeworlds server query, #3 Nov 26, 2016
@stevenh stevenh merged commit cca1ab1 into Unity-Technologies:master Nov 26, 2016
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.

4 participants