Raised This Month: $32 Target: $400
 8% 

Web server extension


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
devicenull
Veteran Member
Join Date: Mar 2004
Location: CT
Old 03-29-2008 , 16:13   Web server extension
Reply With Quote #1

I'm wondering who would be interested in having a HTTP(S) server available from within plugins. I have a fairly simple proof of concept one done now, but if there is interest I can finish the coding for it and release it..

The extension is really just a wrapper around shttpd

Examples of what I have so far:
Simple fastdownload server
Code:
#include <shttpd>
#include <sourcemod>

new Handle:server;
public OnPluginStart()
{
        server = shttpd_init("8888");
        shttpd_set_option(server,"root","/data/srcds/cstrike/addons/webroot");                shttpd_set_option(server,"aliases","/maps=/data/srcds/cstrike/maps/,/sounds=/data/srcds/cstrike/sounds");
}
public OnGameFrame()
{
        shttpd_poll(server);
}
Simple "Hello World" website:
Code:
#include <shttpd>
#include <sourcemod>
public myhandler(Handle:test)
{
        shttpd_printf(test,"Hello world");
}

new Handle:server;
public OnPluginStart()
{
        server = shttpd_init("8888");
        shttpd_register_url(server,"/gaben",myhandler);
}

public OnGameFrame()
{
        shttpd_poll(server);
}
Simple PHP server (Note that this is not really recommended.. just more amusing to see that I could do it)
Code:
#include <shttpd>
#include <sourcemod>
new Handle:server;
public OnPluginStart()
{
	server = shttpd_init("9999");
	shttpd_set_option(server,"root","/data/srcds/cstrike/addons/webroot");
	shttpd_set_option(server,"cgi_ext","php");
	shttpd_set_option(server,"cgi_interp","/usr/bin/php-cgi");
	shttpd_set_option(server,"mime_types",".php=text/html");
}

public OnGameFrame()
{
	shttpd_poll(server);
}
Notes: If it's released, shttpd_poll will be automatically called. I plan on restricting it to ports above 1024 (To go lower would require srcds to run as root, which is not the smartest idea).
__________________
Various bits of semi-useful code in a bunch of languages: http://code.devicenull.org/
devicenull is offline
genipalla
Member
Join Date: Feb 2007
Location: Albania
Old 04-24-2008 , 19:07   Re: Web server extension
Reply With Quote #2

you should use port 8080 its a more comman port for internet servers, and lowers the chance of the side server from being blocked
__________________

CS SOURCE
genipalla is offline
maitredede
Senior Member
Join Date: May 2005
Old 05-26-2008 , 08:21   Re: Web server extension
Reply With Quote #3

You should make it configurable with vars, since you could have multiple servers on one machine...
You can code a full web server admin tool with this...
And plugins can define their own webinterface...

I suggest make it threaded, to avoid gameplay issues...
__________________
make brain && make install
maitredede is offline
BAILOPAN
Join Date: Jan 2004
Old 05-31-2008 , 20:44   Re: Web server extension
Reply With Quote #4

I would assume devicenull knows these things, he is providing a wrapper around an existing (multithreaded) library.
__________________
egg
BAILOPAN is offline
chundo
Senior Member
Join Date: May 2008
Old 06-03-2008 , 22:29   Re: Web server extension
Reply With Quote #5

That's pretty cool. I could see someone (possibly me) building a web console plugin for SourceMod using this. Update configs, manage bans, etc from the web, with results instantly applied. I assume it's fairly lightweight and doesn't noticeably impact performance? If so I'd say definitely flesh it out a bit and release it.
chundo is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:03.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode