The random rantings of a concerned programmer.

Archive for January, 2007

Untitled

January 14th, 2007 | Category: Uncategorized

lol, so I started moving the output of Rhubarb’s PHP scripts from HTML (eww) to XML (*scream*). XML is, by nature, a bitch to work with. And my benchmarks show that there wasn’t any performance gains from converting the forums, though the XML output is like 1/3 the size of the HTML output (which is really handy).

The only real good thing was that it really helped refactor the code, since the PHP only handles the raw data processing, and all the formatting is left to the XSL scripts on the client. Let’s take a look at before-and-after (at the cost of breaking the margins of my journal):

BEFORE:

<?php /* processing section culled, since its basically the same */ ?>

<small><a href="login.php">Main Page</a> | <a href="discuss.php">Forum Index</a><br></small>
<br>
<form method="post">
<div class="forum_reply">
<input type="hidden" name="post" value="<?php echo $post_id; ?>">
<input type="hidden" name="spam" value="pls">
<table border="0" cellpadding="0" cellspacing="0">
<tr><td>Subject:<td><input type="text" name="sub" size="18" class="txt">
<tr><td>Name:<td><input type="text" name="nam" size="18" class="txt">
<tr><td>Email:<td><input type="text" name="lnk" size="18" class="txt">
</table>
<textarea name="msg" cols="40" rows="5"></textarea>
<br><input type="submit" value="Post" class="btn">
</div>
</form>

<table border="0" width="75%">

<?php 
	function output_post( $reply, $post_id, $post_time, $post_sub, $post_nam, $post_lnk, $post_msg ) {
?>
	<tr><td>
	<table cellpadding="0" cellspacing="0" width="100%" class="forum_post">
	<tr>
	<td><?php echo $post_id; ?></td>
	<td><small><?php 
		echo( "<font color='0000FF'>$post_sub</font>  " );
		if( $post_lnk != "" ) {
			if ( substr($post_lnk,0,7) != "http://" ) $prefix="mailto:";
			echo( "by <A HREF='$prefix$post_lnk'>$post_nam</A>" );
		} 	
		else echo( " by $post_nam " ); ?></small></td>
	<td align="right"><small><?php if( $reply ) { ?><a href="discuss.php?post=<?php echo $post_id; ?>">Reply</a><?php } ?></small></td>
	</tr><tr>
	<td><td><small><?php echo date( "r", $post_time ); ?></small></td>
	</tr><tr>
	<td colspan="3"><br><?php echo $post_msg; ?></td>
	</tr>
	</table>
	<br>
	</td></tr>

<?php
	}

	function output_topic_head( $post_id, $post_last, $post_sub, $post_nam, $post_cnt, $post_msg ) {
		if ( $post_sub == "" ) $post_sub = "(No Subject)";
?>
	<tr class="forum_topic">
	<td><?php echo $post_id; ?></td>
	<td><a href="discuss.php?post=<?php echo $post_id; ?>"><?php echo $post_sub ?></a> <small>by <?php echo $post_nam; ?></small></td>
	<td><?php echo $post_cnt; ?> replies</td>
	</tr>
<?php
	}

	if ( $post_id == 0 ) { 
		// output thread table or something
		$query = "SELECT * FROM forum WHERE thread=0 ORDER BY lastpost DESC LIMIT $FRONT_PAGE_POST_VIEW";
		$result = mysql_query( $query, $link )
			or $error .= "MySQL query failed - couldn't fetch page content. ($query)<br>";

		while ( $line = mysql_fetch_array( $result ) ) {
			output_topic_head( $line['id'], $line['lastpost'], $line['subject'], $line['name'], 
					$line['replycount'], $line['body'] );
		}

		mysql_free_result( $result );		

	} else {
	
		mysql_free_result( $result );
				
		$query = "SELECT * FROM forum WHERE thread=$post_id OR id=$post_id ORDER BY id";
		$result = mysql_query( $query, $link )
			or $error .= "MySQL error - couldn't fetch thread contents. ($query)<br>";
	
		while ( $line = mysql_fetch_array( $result, MYSQL_ASSOC ) ) {
			output_post( $reply, $line['id'], $line['time'], $line['subject'], $line['name'], 
					$line['link'], $line['body'] );
		}
	
		mysql_free_result( $result );
	}
?>

</table>

<font color="FF0000"><b><?php echo $error; ?></b></font>
<font color="0000FF"><b><?php echo $notice; ?></b></font>

AFTER:

<?php
	$FRONT_PAGE_POST_VIEW = 25;
	$MAX_POST_LENGTH = 1024;

	$link = get_connection();

	$post_id = (int) $_GET['post'];

	echo( '<forum>' );

	if ( $post_id == 0 ) {
		echo( "<topicview>" );

		// display topic list
		$query = "SELECT * FROM forum WHERE thread=0 ORDER BY lastpost DESC LIMIT $FRONT_PAGE_POST_VIEW";
		$result = mysql_query( $query, $link )
			or die( "Query failed: $query: " . mysql_error() );

		while ( $line = mysql_fetch_array( $result, MYSQL_ASSOC ) ) {
			echo( "<topic>" );
			echo( "<id>" . $line['id'] . "</id>" );
			echo( "<name>" . $line['name'] . "</name>" );
			echo( "<subject>" . $line['subject'] . "</subject>" );
			echo( "<replies>" . $line['replycount'] . "</replies>" );
			echo( "</topic>" );
		}

		mysql_free_result( $result );

		echo( "</topicview>" );

	}
	else {
		// display thread.
		echo( "<postview>" );
		echo( "<id>$post_id</id>" );

		$query = "SELECT * FROM forum WHERE thread=$post_id OR id=$post_id ORDER BY id";
		$result = mysql_query( $query, $link )
			or die( "Query failed: $query: " . mysql_error() );

		while ( $line = mysql_fetch_array( $result, MYSQL_ASSOC ) ) {
			echo( "<reply>" );
			echo( "<id>" . $line['id'] . "</id>" );
			echo( "<name>" . $line['name'] . "</name>" );
			echo( "<subject>" . $line['subject'] . "</subject>" );
			echo( "<timestamp>" . $line['time'] . "</timestamp>" );
			echo( "<time>" . date( "r", $line['time'] ) . "</time>" );
			if ( $line['link'] ) {
				if ( substr( $line['link'],0,7 ) != "http://" ) $prefix="mailto:";
				else $prefix = "";
				echo( "<link>$prefix" . $line['link'] . "</link>" );
			} // don't output this node if there isn't a link.
			echo( "<body><![CDATA[" . $line['body'] . "]]></body>" );
			echo( "</reply>" );
		}

		mysql_free_result( $result );

		echo( "</postview>" );
	}

	echo( '</forum>' );

	mysql_close( $link );
?>

Hurr. Time to figure out the XML layout for the rest of the stuff :3

3 comments

Untitled

January 02nd, 2007 | Category: Uncategorized

1) its for the forced tutorial you go through when you start the game. includes explanations of the game mechanics and stuff, basically answers all the questions I’ve been asked before by other people etc.

2) no it can’t be accessed yet lols. I need a day or two more (lol, discovered I didn’t code the script wizard yet, and I needs it) before its all done. should be nice.

3) lol that picture is gonna break my margins

3 comments

(Untitled)

January 01st, 2007 | Category: Uncategorized

lol editors

Before I had to manually input the link points by hand, basically by manually grabbing them in MS Paint. That was such a shitty method, so I’m going back and re-doing my content creation stuff. To make links on the maps, you just… click on the map to set the x,y position and the size. Pretty nifty. I’m also working on some of the artwork, as shown in the picture. I hope I can find an artist next semester so I don’t have to worry about drawing if I continue the project.

There’s also a cool wizard for setting what scripts are executed when you click on the link which pops up in a small toolbox window. That was a nightmarish day wrestling with javascript, so the toolbox could interact with the main window (like, for links which move the player to a new map, the toolbox’ll show a list of maps to move to, etc context sensitive).

I need to figure out the editors for monsters, items, and encounters, and then I think I’ll have an editor for everything I’ve implemented thus far. At that point, I’ll throw in some more content and start working on quests. Hooray!

Comments are off for this post