logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
A great :idea: but I lack the ability to pull it off.

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related
View previous topic :: View next topic  
Author Message
Frang



Joined: 22 May 2005
Posts: 32

PostPosted: Tue Dec 13, 2005 5:02    Post subject: A great :idea: but I lack the ability to pull it off. Reply with quote

Someone I use to talk to on msn made a script for php that parsed their mysql data base and showed all the player names that was on, granted this would only be updated every so often but its still not a bad idea now if someone else could figure out how he done it then we could take it even farther and view crafting skills for those of us that have crafting in our mods or even have it so we can read and write messages to a bb board in game from our website.. if someone could figure out how to do this and post it for those of us with no database knowledge im sure me and alot of others would be greatful.
Back to top
View user's profile Send private message
cma_dev



Joined: 22 May 2005
Posts: 6

PostPosted: Tue Dec 13, 2005 16:29    Post subject: Reply with quote

I'm not familiar with php, but I know how to do it easily with ASP and .NET (C#, C++).

In fact, MySQL has a .NET connector API that's rather easy to use.

SharpDevelop provides a free .NET Developer Environment that is open source and Microsoft has a free "express" edition for developing ASP web pages and code.
Back to top
View user's profile Send private message
shadguy



Joined: 03 Jan 2005
Posts: 6
Location: Raleigh, NC

PostPosted: Tue Dec 13, 2005 17:29    Post subject: Reply with quote

You can hook into your OnClientEnter/OnClientExit events to update a Database of which characters are currently logged in and where. OnModuleLoad can clear the database to clean up after a crash. DN has had this feature implemented in this way for a long time, but we only make it available to users who've registered on our forums:

http://www.dreunoctem.com/index.php?act=status


As for displaying character character info to display skill levels and such, that's also very doable. Here's an example of something our server admin did one week when he got bored with Star Wars: Galaxies:

http://www.dreunoctem.com/index.php?act=clist&CODE=01&viewchar=gleniel%27s%27hadteg.bic&owner=shadguy

You should be able to look at the stats for any PC in our server vault, even if you haven't registered on DN [I think]. I can't tell you any specifics [or even where the code is], but I believe this works without using NWNX at all [it does use the same database infrastructure, but the character viewer has its own tables and support]. A cron job does a daily update of the database by parsing changed player bics once a day. I think it's all implmented as PHP and shell scripts.

-d.
_________________
Dreu Noctem
Back to top
View user's profile Send private message Visit poster's website
Vladiat0r



Joined: 17 Jun 2005
Posts: 25

PostPosted: Tue Dec 13, 2005 17:47    Post subject: Reply with quote

Lanthar had his for a while ( http://nwvault.ign.com/View.php?view=scripts.Detail&id=17 ), but I don't remember if it still works with latest nwn.

I've updated and spruced it up since then:
http://nwvault.ign.com/View.php?view=Scripts.Detail&id=2612
The /sql folder has the scripts to use NWNx/MySQL to pass the data to the webpage.
Back to top
View user's profile Send private message
Frang



Joined: 22 May 2005
Posts: 32

PostPosted: Wed Dec 14, 2005 5:28    Post subject: Reply with quote

anyone have a script/scripts they can show so I can see how the php code will query the database to retrieve the info? if I could figure that part out im sure I can come up with the setup I want.


thanks for the help and replies
Frang
Back to top
View user's profile Send private message
Enigma



Joined: 14 Dec 2005
Posts: 2

PostPosted: Wed Dec 14, 2005 6:22    Post subject: Reply with quote

shadguy wrote:

As for displaying character character info to display skill levels and such, that's also very doable. Here's an example of something our server admin did one week when he got bored with Star Wars: Galaxies:

http://www.dreunoctem.com/index.php?act=clist&CODE=01&viewchar=gleniel%27s%27hadteg.bic&owner=shadguy

You should be able to look at the stats for any PC in our server vault, even if you haven't registered on DN [I think]. I can't tell you any specifics [or even where the code is], but I believe this works without using NWNX at all [it does use the same database infrastructure, but the character viewer has its own tables and support]. A cron job does a daily update of the database by parsing changed player bics once a day. I think it's all implmented as PHP and shell scripts.


If anyone's interested, I will post the code for this. The script set consists of a character class and a function library for doing various binary operations. Basically, all you do is instantiate a character object with the path to the data file as the only parameter and it will parse it for you. You can then call the various instance methods like firstName(), lastName(), description(), etc to get at the values for the character. The rest of the script files are optional and are just for loading this into a DB table, handling updates of it, and parsing the various 2das and TLK files that certain strings are referenced in.
Back to top
View user's profile Send private message
Vladiat0r



Joined: 17 Jun 2005
Posts: 25

PostPosted: Wed Dec 14, 2005 7:06    Post subject: Reply with quote

Frang wrote:
anyone have a script/scripts they can show so I can see how the php code will query the database to retrieve the info? if I could figure that part out im sure I can come up with the setup I want.


thanks for the help and replies
Frang

The links I gave has a php script that show examples of how you can query the database.
Back to top
View user's profile Send private message
Frang



Joined: 22 May 2005
Posts: 32

PostPosted: Wed Dec 14, 2005 8:08    Post subject: Reply with quote

Quote:
If anyone's interested, I will post the code for this..


I would like to see the code for it.
Back to top
View user's profile Send private message
odenien



Joined: 26 Sep 2005
Posts: 37

PostPosted: Wed Dec 14, 2005 14:41    Post subject: Reply with quote

If you are doing PhP, then they have built-in mysql database functions to handle this. You end up making a sort of HTML page for the report. Though onEnter and onExit you have to update the players' table to show they are in/out of the game, but I am sure most player intensive mods arlready do something similar.

Below is the page for our PlayersIn.php. dbinfo2.inc.php is just a file that defines $username, $password and $database and is used constantly throughout the site.

Code:
<HTML>
<BODY TEXT="#C0C0C0" LINK="#FFFFFF" VLINK="#808080" ALINK="#808080" BGCOLOR=#000000>

<?
include("dbinfo2.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT playerid,player,tag,charlevel FROM aplayers WHERE timein > 0 ORDER BY tag";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();
?>

<b><center><font size=7>Forgotten Isles of Astoria Online List</font></center></b>
<a href="mainserver.php">main</a><br><br>

<P ALIGN="CENTER">
<table width=500><tr>
<th><a href="players.php">By Player/Character</a></th>
<th><a href="players2.php">By Date</a></th>
<th>Players In</th>
</tr></table>
</P><br>

<p align="CENTER"><table border="1" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Player</font></th>
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Character Level</font></th>
</tr>

<?
$i=0;
while ($i < $num) {
$playerid=mysql_result($result,$i,"playerid");
$player=mysql_result($result,$i,"player");
$tag=mysql_result($result,$i,"tag");
$charlevel=mysql_result($result,$i,"charlevel");
?>

<tr>
<td><font face="Arial, Helvetica, sans-serif">
<a href="playerupdate.php?shell=0&playerid=<? echo "$playerid"; ?>">
<? echo "$player"; ?></font></a></td>
<td><font face="Arial, Helvetica, sans-serif">
<a href="playerupdate.php?shell=0&playerid=<? echo "$playerid"; ?>">
<? echo "$tag"; ?></font></a></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$charlevel"; ?></font></td>
</tr>
<?
++$i;
}
echo "</table></p>";

if ($num == 0) {
   echo "<b><center><font size=5>No Players On</font></center></b><br>";
}

?>

</BODY>
</HTML>
Back to top
View user's profile Send private message MSN Messenger
Enigma



Joined: 14 Dec 2005
Posts: 2

PostPosted: Wed Dec 14, 2005 22:44    Post subject: Reply with quote

Frang wrote:
Quote:
If anyone's interested, I will post the code for this..


I would like to see the code for it.


Here you go.

http://www.dreunoctem.com/downloads/charparser.zip


(This is also in the README)
You will find a number of PHP files included in this. Only character.php and binaryfunctions.php are actually needed to parse character files. The remainder are used for loading the data into a MySQL database. This code is provided as-is and without any guarantees. You may use it for whatever you want.

character.php
----------------------
The Character class wraps a character data file. It consists of a bioware GFF parser that processes the entire binary file and convenience accessor functions for getting at various values in a character file. To use it, you just need to instantiate it, passing the path to the character file.

Ex. $character = new Character("/path/to/some/character.bic");

This will create a new instance and parse the character file. Depending on the size of the file, this may take a few seconds. You can then use the various accessor functions to get at values in the character file. Functions available are:

firstName()
lastName()
description()
age()
gender()
race()
subrace()
deity()
gold()
baseAttackBonus()
refSaveThrow()
willSaveThrow()
fortSaveThrow()
armorClass()
str()
dex()
int()
wis()
con()
cha()
hitPoints()
currentHitPoints()
maxHitPoints()
experience()
portrait()
goodEvil()
lawfulChaotic()
familiarName()
familiarType()
classList()
featList()
spellList()
skillList()

All functions except those ending in "List" return a single value. The List functions return an array of values that will vary in size depending on the level of the character.

featList() returns an array of integers. These are indices into feat.2da, which you must also process if you want to get the names for the feats.
spellList() returns an associative array with two integer values. The "spell" key is an index in spell.2da. The "level" key is the level of the spell.
skillList() returns an array of integers that represent the various skill levels. The indices of the array are indices into the skills 2da.

Included, you will find chartester.php, which you can edit in the path of a character file in and it will print out all of these values.


config.php
----------
This holds all the database and path settings used by the remaining files to do their processing. Set as appropriate.


2daextractor.php
----------------
This extracts all of the 2das from a HAK and returns them as an associative array. The keys of the array are the names of the 2das. Look at both parsefeat2da.php and parsespell2da.php for examples of how to use this. It will ONLY access 2das in an ERF-formatted file. The game files that hold the default 2das are not in a file of this format so it cannot parse them. You must put the 2da into a HAK or some other ERF-formatted file type first.

The key function here is:

extract2DAs($path)


parsefeat2da.php, parsespell2da.php
-----------------------------------
Both of these extract a particular 2da and process it. If you want to use these, you'll have to tailor the code that gets the path of the HAK (lines 12-29) to your needs. The existing code looks for a hak matching a particular name pattern and picks the newest version of it. The remainder of the code calls extract2DAs() on that path, grabs the 2da it wants, and inserts the desired fields into a database table.


tlkreader.php
-------------
This extracts all TLK entries from the specified file. The returned value from this is an associative array with two keys. The "header" key contains the header information for the file and the "elements" key contains all of the TLK elements as an array. See parsetlk.php for an example of how to use this.

The key function here is:

readTLK($path)


parsetlk.php
------------
This parses at most two tlk files: dialog.tlk and the newest tlk file in the tlk folder if it exists. All values are then loaded into a database table.


parsecharacters.php
-------------------
This processes each file in the servervault it's pointed at. It compares the md5 hash of the character file to that stored in the database. If it is different, it re-parses the character file. As part of processing a character file, it deletes the previous character record in the table. It then inserts a new one with the new values. Following this, it goes through the class list, feat list, and spell list and inserts records for those in the appropriate tables, pointing to this character record.







Table Structure
---------------
These scripts are designed for this table structure. If you make changes to the structure, you will need to modify the scripts accordingly.

--
-- Table structure for table `characterclasses`
--

CREATE TABLE `characterclasses` (
`owner` varchar(255) NOT NULL default '',
`file` varchar(32) NOT NULL default '',
`class` tinyint(4) unsigned NOT NULL default '0',
`level` tinyint(3) unsigned NOT NULL default '0',
KEY `file` (`file`,`owner`),
KEY `class` (`class`)
) TYPE=MyISAM;

-- --------------------------------------------------------

--
-- Table structure for table `characterfeats`
--

CREATE TABLE `characterfeats` (
`owner` varchar(255) NOT NULL default '',
`file` varchar(32) NOT NULL default '',
`feat` int(11) NOT NULL default '0',
KEY `feat` (`feat`),
KEY `file` (`file`,`owner`)
) TYPE=MyISAM;

-- --------------------------------------------------------

--
-- Table structure for table `characters`
--

CREATE TABLE `characters` (
`owner` varchar(255) default NULL,
`file` varchar(255) NOT NULL default '',
`md5hash` varchar(32) default NULL,
`date` timestamp(14) NOT NULL,
`FirstName` varchar(32) default NULL,
`LastName` varchar(32) default NULL,
`Portrait` varchar(32) default NULL,
`Description` longtext,
`Age` smallint(5) unsigned default NULL,
`Gender` tinyint(1) default NULL,
`Race` tinyint(3) unsigned default NULL,
`Subrace` varchar(16) default NULL,
`Deity` varchar(16) default NULL,
`Gold` int(10) unsigned default NULL,
`Experience` int(10) unsigned default NULL,
`CurrentHitPoints` smallint(6) default NULL,
`MaxHitPoints` smallint(6) default NULL,
`RefSaveThrow` tinyint(4) default NULL,
`WillSaveThrow` tinyint(4) default NULL,
`FortSaveThrow` tinyint(4) default NULL,
`ArmorClass` tinyint(4) default NULL,
`Str` tinyint(4) default NULL,
`Dex` tinyint(4) default NULL,
`Int` tinyint(4) default NULL,
`Wis` tinyint(4) default NULL,
`Con` tinyint(4) default NULL,
`Cha` tinyint(4) default NULL,
`GoodEvil` tinyint(4) default NULL,
`LawfulChaotic` tinyint(4) default NULL,
`FamiliarName` varchar(32) default NULL,
`FamiliarType` tinyint(3) default NULL,
KEY `md5hash` (`md5hash`),
KEY `file` (`file`),
KEY `owner` (`owner`),
KEY `Experience` (`Experience`)
) TYPE=MyISAM;

-- --------------------------------------------------------

--
-- Table structure for table `characterspells`
--

CREATE TABLE `characterspells` (
`owner` varchar(255) NOT NULL default '',
`file` varchar(32) NOT NULL default '',
`spell` int(11) unsigned NOT NULL default '0',
`level` tinyint(3) unsigned NOT NULL default '0',
KEY `file` (`file`,`owner`),
KEY `spell` (`spell`)
) TYPE=MyISAM;

-- --------------------------------------------------------

--
-- Table structure for table `feats`
--

CREATE TABLE `feats` (
`id` int(11) NOT NULL default '0',
`featstrref` int(11) NOT NULL default '0',
`descstrref` int(11) NOT NULL default '0',
`icon` varchar(32) NOT NULL default '',
`featuserfile` tinyint(1) NOT NULL default '0',
`descuserfile` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `featstrref` (`featstrref`),
KEY `descstrref` (`descstrref`),
KEY `featuserfile` (`featuserfile`),
KEY `descuserfile` (`descuserfile`)
) TYPE=MyISAM;

-- --------------------------------------------------------

--
-- Table structure for table `spells`
--

CREATE TABLE `spells` (
`id` int(11) NOT NULL default '0',
`spellstrref` int(11) NOT NULL default '0',
`descstrref` int(11) NOT NULL default '0',
`icon` varchar(32) NOT NULL default '',
`spelluserfile` tinyint(1) NOT NULL default '0',
`descuserfile` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `featstrref` (`spellstrref`),
KEY `descstrref` (`descstrref`),
KEY `featuserfile` (`spelluserfile`),
KEY `descuserfile` (`descuserfile`)
) TYPE=MyISAM;

-- --------------------------------------------------------

--
-- Table structure for table `tlk`
--

CREATE TABLE `tlk` (
`index` bigint(20) NOT NULL default '0',
`userfile` tinyint(1) NOT NULL default '0',
`language` smallint(6) NOT NULL default '0',
`string` longtext NOT NULL,
KEY `index` (`index`,`userfile`)
) TYPE=MyISAM;
Back to top
View user's profile Send private message
Frang



Joined: 22 May 2005
Posts: 32

PostPosted: Thu Dec 15, 2005 9:19    Post subject: Reply with quote

hey odenien anyway you can post the mysql table setup for this script?
Back to top
View user's profile Send private message
odenien



Joined: 26 Sep 2005
Posts: 37

PostPosted: Thu Dec 15, 2005 15:24    Post subject: Reply with quote

The player table is
Code:
CREATE TABLE aplayers (
            playerid        int unsigned NOT NULL auto_increment,
            player          varchar(64) NOT NULL default '',
            tag             varchar(64) NOT NULL default '',
            pubkey          varchar(8)  NOT NULL default '',
            ip              varchar(32) NOT NULL default '',
            laston          date NOT NULL default '0000-00-00',
            isdead          tinyint(4) NOT NULL default '0',
            timein          int(11) NOT NULL default '0',
            totaltime       int(4)  NOT NULL default '0',
            deathcount      int(11) NOT NULL default '0',
            goldamt         int(11) NOT NULL default 0,
            charlevel       int(4)  NOT NULL default 0,
            currentxp       int(11) NOT NULL default 0,
            injail          int(11) NOT NULL default '0',
            jailtime        int(11) NOT NULL default '0',
            PRIMARY KEY (playerid),
            KEY namekey (player,tag));


The onEnter SQL:
Code:
    sSQL = "UPDATE aplayers SET pubkey='" + pPubkey + "',ip='" + pIP +
            "',laston=CURDATE(),timein=UNIX_TIMESTAMP(),charlevel = " + IntToString (GetHitDice (oPC)) +
            ",currentxp=" + IntToString (GetXP (oPC)) +
            " WHERE playerid=" + IntToString (GetLocalInt (oPC, "PLAYERID"));
    if (DEBUG) WriteTimestampedLogEntry (sSQL);
    SQLExecDirect (sSQL);


The onExit SQL:
Code:
       sSQL = "UPDATE dmauth SET totaltime=(UNIX_TIMESTAMP()-timein)/60+totaltime,timein=0 WHERE playerid=" +
               IntToString (GetLocalInt (oPC, "PLAYERID"));
        if (DEBUG) WriteTimestampedLogEntry (sSQL);
        SQLExecDirect(sSQL);
Back to top
View user's profile Send private message MSN Messenger
Frang



Joined: 22 May 2005
Posts: 32

PostPosted: Fri Dec 16, 2005 20:34    Post subject: Reply with quote

nice....thanks everyone for sharing these great scripts now i have to sit down go over them and see if i can decide to use just one lol dont be surpised if after i get this setup and running that i have more then one of these installed.
Back to top
View user's profile Send private message
dougnoel



Joined: 21 Mar 2005
Posts: 27
Location: VA

PostPosted: Fri Jun 09, 2006 13:52    Post subject: Reply with quote

Enigma, I found your code very interesting. Thanks.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group