Bizarre problems with MySQL and Smaug Fuss

Posted by Pyromanci on Thu 26 Feb 2009 02:44 PM — 5 posts, 22,561 views.

#0
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.
USA #1
NKEY("MudName", sys->mud_name, row[C_Sysdata_value]);

This doesn't actually copy anything, it just sets sys->mud_name to be a pointer to row[C_Sysdata_value]. So, when that value changes, the pointer points to the same memory location, containing a new value.

You would need to actually copy strings in. atoi is effectively a copy, so numbers are ok.
USA #2
Oh, btw, it should be "bizarre", not "bazar" -- I thought you were talking about the Bazaar version control system at first :-)
#3
David,

Thanks for pointing that out and sorry, my spelling is horrid.

Based off what you said. I created a new macro.


#define NKEY( literal,  field, value ) \
if ( !str_cmp( cname, (literal) ) )    \
{                 	                   \
   (field) = (value);                  \
}

#define SKEY( literal,  field, value ) \
if ( !str_cmp( cname, (literal) ) )    \
{                 	                   \
   (field) = str_dup( (value) );       \
} 


now its actually doing whats i thought it would.
Australia Forum Administrator #4
Quote:

btw, it should be "bizarre", not "bazar"


Subject line amended by me to correct spelling. :)