[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  Compiling the server
. . -> [Subject]  Bizarre problems with MySQL and Smaug Fuss
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Bizarre problems with MySQL and Smaug Fuss

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Pyromanci   (7 posts)  [Biography] bio
Date Thu 26 Feb 2009 02:44 PM (UTC)
Message
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.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #1 on Thu 26 Feb 2009 02:50 PM (UTC)
Message
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.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #2 on Thu 26 Feb 2009 02:51 PM (UTC)
Message
Oh, btw, it should be "bizarre", not "bazar" -- I thought you were talking about the Bazaar version control system at first :-)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Pyromanci   (7 posts)  [Biography] bio
Date Reply #3 on Thu 26 Feb 2009 06:14 PM (UTC)
Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (21,323 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Fri 27 Feb 2009 06:56 PM (UTC)
Message
Quote:

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


Subject line amended by me to correct spelling. :)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


4,403 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]