[Tutorial] Post to your vBulletin forum using an in-game function
#1

This takes quite a bit of setting up, but could be useful nonetheless.
I for one have /report post details on my forum so I can keep track of what's happening when not in-game.

First you need a webhost with a vBulletin forum (I haven't had chance to figure out for SMF/phpBB yet, sorry!). Create a .php file called 'post_from_ingame.php' containing what's below and place it in your forum root directory (usually something like /forum/)

PHP Code:
<?php
    date_default_timezone_set 
("Europe/Amsterdam"); // Server time
    
require './global.php';
    require 
'./includes/class_dm.php';
    require 
'./includes/class_dm_threadpost.php';
    require 
'./includes/functions_databuild.php';
    
$threaddm = new vB_DataManager_Thread_FirstPost($vbulletinERRTYPE_STANDARD);
    
$post_userid 0// Guest
    
$userid 0// No user
    
$user_name $_POST['name'] . ' (SA-MP)';
    
$allow_smilie '1';
    
$visible '1';
    
    
$forum_id = !!!!!CHANGE_ME!!!!!; // Set the board id here. For example, my 'report discussions' board is ID 28, so I'd put 28. forum/forumdisplay.php?28-Report-discussion (28 is the ID)
    
    //Thread post formatting
    
$post_text = (string)strip_tags('In-game name:[indent]    ' $_POST['name'] .'[/indent]    
    Server time:[indent]    ' 
strftime("%l:%M:%S %p") . '    [/indent]    
    Explanation:[indent]' 
. (string)strip_tags($_POST['posttext']) . '[/indent]');
    
//$_POST['posttext'] - posttext is what is sent in-game
    //format(string, sizeof(string), "name=%s&posttext=%s", name, params);
    
    //Thread title formatting
    //$title = 'New post from in-game';
    
$title '[' strftime("%H:%M:%S") . '] Report from ' $_POST['name'];
    
$threaddm->do_set('forumid'$forum_id);
    
$threaddm->do_set('postuserid'$post_userid);
    
$threaddm->do_set('userid'$userid);
    
$threaddm->do_set('username'$user_name);
    
$threaddm->do_set('pagetext'$post_text);
    
$threaddm->do_set('title'$title);
    
$threaddm->do_set('allowsmilie'$allow_smilie);
    
$threaddm->do_set('visible'$visible);
    
$threaddm->save();
    
build_forum_counters($forum_id);
    
    die(
"Report posted!");
?>
pawn Code:
#include a_http
Add this to your script under any function you wish to use; I used dcmd:
pawn Code:
new string[128];
new name[32];
GetPlayerName(playerid, name, 32);
format(string, sizeof(string), "name=%s&posttext=%s", name, params);
HTTP(playerid, HTTP_POST, "link-to-post_from_ingame.php-file", string, "MyHTMLError");
If you want to change what is sent to the forum, you can change format(string, sizeof(string), "name=%s&posttext=%s", name, params);. For example:
pawn Code:
if(Kills[playerid] == 500) format(string, sizeof(string), "name=%s&kills=%d", name, Kills[playerid]);
If you do customise it, be sure to edit the post_from_ingame.php file:
PHP Code:
$post_text = (string)strip_tags('$_POST['name'] . ' just got 500 kills! 
Well done to him!'
); // Thread post
$title '[' strftime("%H:%M:%S") . '] - ' $_POST['name'] . ' just got 500 kills!'// Thread title 
Be sure to change the link-to-post_from_ingame.php-file part!
(My example would be domain.com/forum/post_from_ingame.php - you don't need the preceding http://)

And the MyHTMLError function:

pawn Code:
forward MyHTMLError(index, response_code, data[]);
public MyHTMLError(index, response_code, data[])
{
    new
        buffer[ 128 ];
    if(response_code == 200) //Did the request succeed?
    {
        //Yes!
        format(buffer, sizeof(buffer), "%s", data);
        SendClientMessage(index, 0xFFFFFFFF, buffer);
    }
}
die("Report posted!"); in the PHP file will send "Report posted!" to the game server, which will then be formatted as 'buffer' and sent to index (the player).

Edit config.php in /forum_root/includes and add this to the bottom:
PHP Code:
define('SKIP_REFERRER_CHECK'true); 
And now simply execute your function and voila!

Preview of my script:
Reply
#2

Nice, keep up the good work, rep+
Reply
#3

Wow, thanks. Rep+
Reply
#4

Nice idea !
Reply
#5

This seems like it would be incredibly insecure. Anyone with a bit of knowledge could call the PHP script with random POST data.

(And apparently you have money to buy vBulletin and expensive addons, but no money to buy a domain. Seems totally legit.)
Reply
#6

I do have money to buy a domain, actually; we've had to migrate hosts twice because of bandwidth usage so we're not buying a set domain until we know we're staying.

And yes, it is insecure, but until I find a way to whitelist an IP as a POST referrer, it's going to have to be insecure.
As long as it's not made blatantly clear that there's no protection against POST data, people aren't going to try to send POST requests.

That's like me putting in random credit card numbers. It can work in my favour, but it's not very likely unless someone gives the details out.
Reply
#7

this is actually awsome. well done mate and thanks alot useful.
Reply
#8

can this work for smf?
Reply
#9

I could probably get it to work for SMF; I'll take a look at SMF and MyBB soon.
Reply
#10

Quote:
Originally Posted by [FMJ]PowerSurge
View Post
I do have money to buy a domain, actually; we've had to migrate hosts twice because of bandwidth usage so we're not buying a set domain until we know we're staying.

And yes, it is insecure, but until I find a way to whitelist an IP as a POST referrer, it's going to have to be insecure.
As long as it's not made blatantly clear that there's no protection against POST data, people aren't going to try to send POST requests.

That's like me putting in random credit card numbers. It can work in my favour, but it's not very likely unless someone gives the details out.
Doesnt it just take 5 minutes to change the target of a domain to the new host?

About security: you could just add a security key to the post data, that needs to be the same as some defined key in the php.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)