thought this might be useful.
http://www.nwnx.org/...opic.php?t=2022Essentially:
One of the limitations we have with nwn at the moment, is that if you want to get information in and out of nwn, you need to rely upon nwn events such as
onClientEnter - which leaves you at the mercy of waiting for data to be returned in the database- to determine if the user has the appropriate access.
eg:
In the old' days, I used to integrate my Forum Shop with the game server. Anything purchased would be received in-game. (in-game currency was used)
To facilitate this, I had to run a php script every 5 minutes that transfered the items from the webSite database, to the game database.
The new thing I have developed as a proof of concept, shows how to implement WebServices with nwn.
<?php
$request = $_GET["request"];
if($request == "GetForumMemberID")
{
$MemberName = $_GET["membername"];
//echo $MemberName;
echo GetForumMemberID($MemberName);
exit;
}
if($request == "GetForumUserEmailByID")
{
$MemberID = $_GET["memberid"];
//echo $MemberName;
echo GetForumUserEmailByID($MemberID);
exit;
}
if($request == "GetForumUserEmailByUserName")
{
$MemberName = $_GET["membername"];
//echo $MemberName;
echo GetForumUserEmailByUserName($MemberName);
exit;
}
function GetForumMemberID($strUsername)
{
$username = "DB_User";
$password = "DB_Pass";
$con = mysql_connect("localhost",$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("your_db", $con);
$result = mysql_query("SELECT * FROM smf_members where member_name like '%".$strUsername."%' limit 1");
while($row = mysql_fetch_array($result))
{
return $row['id_member'];
}
mysql_close($con);
}
function GetForumUserEmailByID($ID)
{
$username = "DB_User";
$password = "DB_Pass";
$con = mysql_connect("localhost",$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("your_db", $con);
$result = mysql_query("SELECT email_address FROM smf_members where id_member = '".$ID."' limit 1");
while($row = mysql_fetch_array($result))
{
return $row['email_address'];
}
mysql_close($con);
}
function GetForumUserEmailByUserName($UserName)
{
$username = "DB_User";
$password = "DB_Pass";
$con = mysql_connect("localhost",$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("your_db", $con);
$result = mysql_query("SELECT email_address FROM smf_members where member_name like '%".$UserName."%' limit 1");
while($row = mysql_fetch_array($result))
{
return $row['email_address'];
}
mysql_close($con);
}
?>
Now - I can have a php file like this.
A nwnx Plugin Modification I have, allows me to query this php page, and look for the output, and then return it to nwn immediately.
(no waiting 5 minutes for scripts to run)
I have a function very much like this on my Forum / GameServer
function GetForumUserEmailByUserName($UserName)
{
$username = "DB_User";
$password = "DB_Pass";
$con = mysql_connect("localhost",$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("your_db", $con);
$result = mysql_query("SELECT email_address FROM smf_members where member_name like '%".$UserName."%' limit 1");
while($row = mysql_fetch_array($result))
{
return $row['email_address'];
}
mysql_close($con);
}
But instead of returning the users e-mail, it returns their member group.
I use this to grant features/items/subraces to specific user groups on my forums.
Heck - if they dont meet the membergroup requirements - the GAME even sends them an e-mail explaining why they are being booted.
(Using the above method to get their e-mail address: Assuming they are registered on the forum)
If the e-mail address comes back as blank - assumes they arent registered, or havent linked their account to the forum yet- so displays a message before booting them.
I would definitely recommend using nwnx - as it makes the possibilities almost limitless for your server.