Raised This Month: $12 Target: $400
 3% 

Web server extension


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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 13:31.


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