Jump to content
MakeWebGames

My Engine


POG1

Recommended Posts

I am working on a game and i have decided to have everything work from the index file and use the switch function. I was wondering if there is a better way of how i done it..

 

<?
$allowed = array(town,inventory,mailbox,bank);

if(preg_match('/^[a-zA-Z0-9_]/',$page)( { echo '<h2>Page Error</h2>'; endPage(); die(0); }
if (in_array($page, $allowed)) {

switch($page) {

	case 'town': include("town.php"); break;

	case 'inventory': include("inventory.php"); break;

	case 'mailbox': include("mailbox.php"); break;

	case 'bank': include(bank.php"); break;
               // more here
}

}
?>


 

Would it be safe to just use.

include($page.'.php');

Link to comment
Share on other sites

Re: My Engine

I have another dilemma. I am working on a system that looks in the database and if the page is there it won't display it.

The database feild will contain values like.. forum-mailbox-town-events

I have used explode to seperate them into an array and i can add to the pages, but i can not take them away.

Can someone please help me or tell me what i need? i was thinking of a function to delete a selected array then to put it back together with implode

Link to comment
Share on other sites

Guest Anonymous

Re: My Engine

True using , (comma) as a separator...

Then... Have a look at http://nyna.co.uk/set-extensions.txt

The FIND_IN_SET already in the MySQL function library, however it was missing ADD_TO_SET and REMOVE_FROM_SET.

BTW, the reason this is linked - is I so I can update my one copy from time to time without having to repost in a dozen odd forums and hundreds of topics.

Link to comment
Share on other sites

Guest Anonymous

Re: My Engine

Basically you past each definition that you need - the CREATE FUNCTION ... RETURN ... ; into phpMyAdmin

Try adding ADD_TO_SET

Then you can perform:

SELECT ADD_TO_SET('A', 'B,C')

which means... you can create a field in a table with a comma separated list (CSV field):

csv_field: VARCHAR(250) DEFAULT NULL

then you can do tricks like:

UPDATE table SET csv_field = ADD_TO_SET('A', csv_field) WHERE !FIND_IN_SET('A', csv_field);

*** BEWARE *** These functions are NOT fast -- But they do work. I use them a lot, but I have highly optimal queries and look at very small row-sets.

Running these functions on tables with several million fields WILL stall your database.

Link to comment
Share on other sites

Re: My Engine

Thanks for that, the add works a treat!

does this look ok to you?

if(isset($_GET['block']) AND $user_class->staff == 1){

$block = preg_replace("/[^a-zA-Z0-9]/","",strip_tags(trim($_POST['block'])))

$r = mysql_fetch_array(mysql_query("SELECT disabledpages FROM serverconfig"));

$pageArray = explode(",",$r['disabledpages']);

if(in_array($block,$pageArray)) {

// unblock page

$result = mysql_query(sprintf("UPDATE serverconfig SET disabledpages = REMOVE_FROM_SET('%s',disabledpages)",$block));

}

else {

// block page

$result = mysql_query(sprintf("UPDATE serverconfig SET disabledpages = ADD_TO_SET('%s',disabledpages)",$block));

}

}

Also when i try to add the remove function i get an error

Link to comment
Share on other sites

Guest Anonymous

Re: My Engine

DROP FUNCTION IF EXISTS ADD_TO_SET;

should be sufficient

Although... I seldom drop them. Once they are installed, I can forget them.

Interesting usage though -- Not my preferred method, but at least it does demonstrate the technique which can easily be used in all sorts of areas.

Link to comment
Share on other sites

Re: My Engine

I have another simple query. I added a table into the database and the pages that are disabled depending on status; hospital, jail, staff and admin. I was wondering what would be the best way, all i can think of is keep setting the same variable with a number of if functions. Here is what i got, i don't want the script to be very slow and there probably would be a better and faster way to do what i need, can someone give some pointers or help? please :)

 

$validPage = (preg_match('/^[a-z]+$/',$_GET['page']) AND isset($_GET['page']) AND file_exists($dir.'/'.$_GET['page'].'.php')) ? $_GET['page'] : index ;
$pageArray = explode(",",$serverCheck['disabledpages']);
$validPage = (in_array($validPage,$pageArray) AND $user_class->staff != 1) ? errorpage : $validPage ;
Link to comment
Share on other sites

  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...