OK,
I am working on a new mud, and i decided to pull some of the stuff away from the flat file system to MySQL. One of the things I was moving over is SysData file (i am using SmaugFuss as my base).
So I created my table.
CREATE TABLE `sysdata` (
`config` varchar(255) NOT NULL default '',
`value` varchar(255) NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=utf8
I then went into the load_systemdata function and proceded to rewrite it. which when done turned out to be (i trimed the ket loop so the post wouldn't be so big):
bool load_systemdata( SYSTEM_DATA * sys )
{
MYSQL_RES *result;
MYSQL_ROW row;
MYSQL mysqlconn;
char *cname;
log_string("Entered load_systemdata.");
if (!mysql_init(&mysqlconn))
{
log_string("For some reason, load_systemdata couldn't init a mysql connection. exitting");
return FALSE;
}
if (!mysql_real_connect(&mysqlconn, MY_SERVER,MY_USER, MY_PWD, MY_DB,0,NULL,0))
{
log_string("load_systemdata died connecting to the mysql server");
mysql_close(&mysqlconn);
return FALSE;
}
if (mysql_query(&mysqlconn, "SELECT * FROM sysdata") != 0)
{
log_string("MySQL queried failed.");
return FALSE;
}
result = mysql_store_result(&mysqlconn);
while ((row = mysql_fetch_row(result)))
{
cname = row[C_Sysdata_config];
bug( "Cname found to Be %s: Value found to be %s", cname, row[C_Sysdata_value]);
NKEY("MudName", sys->mud_name, row[C_Sysdata_value]);
NKEY("Highplayers", sys->alltimemax, atoi(row[C_Sysdata_value]));
NKEY("Highplayertime", sys->time_of_max, row[C_Sysdata_value]);
NKEY("CheckImmHostcase", sys->check_imm_host, (bool)row[C_Sysdata_value]);
NKEY("Nameresolving", sys->NO_NAME_RESOLVING, (bool)row[C_Sysdata_value]);
NKEY("Waitforauth", sys->WAIT_FOR_AUTH, (bool)row[C_Sysdata_value]);
NKEY("Wizlock", sys->wizlock, (bool)row[C_Sysdata_value]);
NKEY("Readallmail", sys->read_all_mail, atoi(row[C_Sysdata_value]));
NKEY("Readmailfreecase", sys->read_mail_free, atoi(row[C_Sysdata_value]));
NKEY("Writemailfree", sys->write_mail_free, atoi(row[C_Sysdata_value]));
}
update_timers( );
update_calendar( );
if( !sysdata.guild_overseer )
sysdata.guild_overseer = STRALLOC( "" );
if( !sysdata.guild_advisor )
sysdata.guild_advisor = STRALLOC( "" );
/* Here we free the memory used by the results */
mysql_free_result(result);
mysql_close(&mysqlconn);
bug( "PvP damage mod set to %d", sys->dam_plr_vs_plr);
bug( "Mud Name was set to %s", sys->mud_name);
return true;
}
Ok. Here is the problem i am running into. When reading the row information everything is correct, but once you put it into the sysdata variable it changes and becomes scewed. Here is the log file for the boot (again i trimed it up a bit).
....
Thu Feb 26 10:37:02 2009 :: Entered load_systemdata.
Thu Feb 26 10:37:03 2009 :: [*****] BUG: Cname found to Be MudName: Value found to be MySQL Mud
Thu Feb 26 10:37:03 2009 :: [*****] BUG: Cname found to Be Damplrvsplr: Value found to be 100
Thu Feb 26 10:37:03 2009 :: [*****] BUG: PvP damage mod set to 1
Thu Feb 26 10:37:03 2009 :: [*****] BUG: Mud Name was set to 1
....
Thu Feb 26 10:37:03 2009 :: Initializing socket
Thu Feb 26 10:37:03 2009 :: rom lack of air. Don't talk so much! ready on port 1073.
As you can see when i am dumping the information out directly from the row variable its right. but once i go through and add it into the sysdata struture variables they all become 1.
Also you probably will probably want to know what NKEY() is. It is the same as the KEY macro defined, but with some minor alterations.
#define KEY( literal, field, value ) \
if ( !str_cmp( word, (literal) ) ) \
{ \
(field) = (value); \
fMatch = TRUE; \
break; \
}
#define NKEY( literal, field, value ) \
if ( str_cmp( cname, (literal) ) ) \
{ \
(field) = (value); \
}
I do hope this makes sense and if any one happesn to know the correction to this problem i would greatly welcome the help. I am going to still play with it and try a few things while i wait for a response. |