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

Added built-in http server #511

Closed
wants to merge 1 commit into from
Closed

Added built-in http server #511

wants to merge 1 commit into from

Conversation

mgerhardy
Copy link

@mgerhardy mgerhardy commented Jul 2, 2021

This allows you to get a list of available maps on the server, get the status and download pk3s - might be useful for others.

pk3 download must get the sv_allowDownload and the download url configured

downloading works when talking to the /pk3 endpoint like this: curl http://localhost:8080/pk3/baseq3/my.pk3

  • http://localhost:8080/status
  • http://localhost:8080/maps
  • http://localhost:8080/pk3/[...]

Open / Maybe

  • Fuzzing the endpoints
  • Allow to customize css (file is http/style.css)

@NuclearMonster
Copy link
Member

You read my mind, I was literally thinking about doing this today but in the docker image. Not sure if it belongs in the engine package itself but it might.

@mgerhardy
Copy link
Author

mgerhardy commented Jul 2, 2021

Bildschirmfoto von 2021-07-02 13-52-02

@mgerhardy
Copy link
Author

I thought so, too - but imo it's also great to give direct access to the engine data. It would allow for a web based rcon view or online stats generator and all kind of funny things. But I've just written it because I never know the maps that are available on my server and I also can't remember the names - I need the pictures ;)

I also don't expect this to get merged, but as I said - others might find it useful and might extend it to be more useful.

}

static void HTTP_BodyHeader(char *buf, int size) {
// TODO: allow to customize stylesheet
Copy link

Choose a reason for hiding this comment

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

As much as I would like the whole header to be an external 'template' file that can customized, I don't think it's really needed unless there is a lot of people requesting it.

Q_strncpyz(imageName, "levelshots/unknownmap", sizeof(imageName));
}

Com_sprintf(imgLine, sizeof(imgLine), "\t\t<h1>%s</h1>\n\t\t<div class=\"img\"><img width=\"320\" height=\"240\" alt=\"%s\" src=\"maps/%s\" /></div>\n", mapName, mapName, imageName);
Copy link

Choose a reason for hiding this comment

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

Same comment as above with wanting this to be an external template.


HTTP_MapsAddMap(outputBuffer, sizeof(outputBuffer), sv_mapname->string);

Q_strcat(outputBuffer, sizeof(outputBuffer), "<table><tr><th>cl</th><th>score</th><th>ping</th><th>name</th><th>address</th><th>rate</th><tr>");
Copy link

Choose a reason for hiding this comment

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

Same as above with the external template.

ps = SV_GameClientNum(i);
s = NET_AdrToString(cl->netchan.remoteAddress);

Com_sprintf(buf, sizeof(buf), "<tr><td>%i</td><td>%i</td><td>%i</td><td>%s</td><td>%s</td><td>%i</td></tr>",
Copy link

Choose a reason for hiding this comment

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

Same as above with the external template.

if (listen(httpSocket, 5) < 0) {
closesocket(httpSocket);
httpSocket = INVALID_SOCKET;
return qfalse;
Copy link

Choose a reason for hiding this comment

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

I see a couple inconsistencies with style on new lines before returns. I personally like a new line before a return, but as long as it consistent, it doesn't matter which way you do it.

@mgerhardy
Copy link
Author

the css stuff can now get customized by providing the file http/style.css.

I've also added bearer token support - but please see the comments in the code about it.

And you can specify the interface to bind to, now.

this allows you to get a list of available maps on the server, get the status and download pk3s

pk3 download must get the sv_allowDownload and the download url configured

downloading works when talking to the /pk3 endpoint like this: curl http://localhost:8080/pk3/baseq3/my.pk3
@mgerhardy
Copy link
Author

Fixed a few valgrind reports - calling this done for now.

@mgerhardy
Copy link
Author

This is the new PR #558 - I've deleted the repo by accident.

This pull request was closed.
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.

3 participants