Jump to content
MakeWebGames

Recommended Posts

Posted

Hello MWG Community!

I'm new to the community, so just introducing myself. So, I'm Dan, 21, UK, been developing games since I found the passion for it at 15, I use PHP/MySQL as my main language but also know some JS/Ajax/jQuery and mostly specialise in Virtual Pets/Adoptables and RPG/MMO games, both text and realtime. I prefer to use OO programming over procedural since finding the love of Objects, but I'm known to adapt my programming to fit both if needed.

I have a few interested parties who want me to develop an adoptable game (product) so they can run their own, so that is my current project right now.

I like to contribute when I join a new community, so I will post some of my own references or code below, if anyone finds them useful, let me know and I will move then to the correct forums for accessibility.

Resource Contributions

OpenGameArt.org - Found this a while ago, it has some good free game art resources.

Code Contributions

This small functions I use to clear out overflow of a large int, useful for games that has big game money.

When an Int is too large, you may see something like E+13 on the end, this function turns it back into a full INT

function intOverflow( $int ){
return number_format( $int, 0, '.', '' );
}

 

This function I use in ranking systems in my games, it'll take your rank and add st, nd, rd or th to it. (1st, 234th, 88th)

function makeOrdinal( $rank )
{
   $last= substr( $rank, -1 );
   $seclast = substr( $rank, -2, -1 );

   if( $last > 3 || $last == 0 )$ext = 'th';
   else if( $last == 3 )        $ext = 'rd';
   else if( $last == 2 )        $ext = 'nd';
   else                         $ext = 'st';

   if( $last == 1 && $seclast == 1) $ext = 'th'; # Avoid 11st
   if( $last == 2 && $seclast == 1) $ext = 'th'; # Avoid 12nd
   if( $last == 3 && $seclast == 1) $ext = 'th'; # Avoid 13rd

   return $rank.$ext;
}

 

And here is one I use for secure hashing (Due to md5 and sha1 being cracked)

function hash( $value, $method = '' )
{
   	switch( $method )
   	{
       	case 'extreme':
           	return hash( 'whirlpool', $value );
       	break;

       	default:
           	return hash( 'sha256', $value );
   	}
}

 

I have lots more, but I'll wait and post them in the correct forums some other time ^^

Regards,

Dan :thumbup:

Posted

Seen as were showing has function, mine is:

 

function hashme($hashtype = 'whirlpool', $tohash, $salt = '') {
if(!$hashtype) { echo'Error! No hash type selected!'; return false; }
	if(!$tohash) { echo'Error! No hashing to do!'; return false; }
		if(!$salt) { echo'Error! No salt added!'; return false; }
			return hash($hashtype, ($salt.$tohash.$salt));
}
Posted

Djkanna, whilst I agree what I have posted isn't in it's most simplistic of form, these functions I took out of one of my classes, which is why they're bigger. It's my way of keeping things simple by having my "reusable" code in one place.

Take this for example, as you can see above, I actually forgot to Salt my hashing, which is a big mistake, luckily for me, I only have to update that one function to fix my error, whereas you would have to go over all your files where you have used hashing to add it in. The simplicity for me comes in here because my mistakes are quick and easy to fix ;) I guess this is more a conflict of preference. ^^

I also use $method and a switch to group outcome control, so to speak, like this..

 

public function formatDate( $stamp, $method )
{
   	switch( $method )
   	{
       	case 'full': return date( 'd F Y - l h:i A', $stamp ); break;
       	case 'date': return date( 'd F Y', $stamp ); break;
       	case 'time': return date( 'h:i A', $stamp ); break;
       	default: return date( $this->customDateFormat, $stamp );
   	}
}

--------
echo $dateClass->formatDate( time(), 'full' );
echo $dateClass->formatDate( time(), 'date' );
echo $dateClass->formatDate( time(), 'time' );

# Or whenever I need something different...

$dateClass->customDateFormat = 'd-m-y';
echo $dateClass->formatDate( time() );

 

Thanks all for the welcomes :thumbsup:

Posted

Oh no don't get me wrong I'd use a function for it but both yours and Dannys(especially) seem to be over the top :P

Plus I would only use it twice maybe three times in the whole script so not so bad :)

Posted
And here is one I use for secure hashing (Due to md5 and sha1 being cracked)

Could you explain that statement?

personally i use sha256 with salt but i don't see the need in a fuction it would be easier to simple do the existing hash function

hash('sha256', $email.'$password'.$endingsalt)

A silly plan of mine once was to make sha 256 look like whirlpool therefore if people were to grab a users hash somehow then they would be trying to decipher whirlpool rather than sha256.

Posted

personally i use sha256 with salt but i don't see the need in a fuction it would be easier to simple do the existing hash function

hash('sha256', $email.'$password'.$endingsalt)
<3

A silly plan of mine once was to make sha 256 look like whirlpool therefore if people were to grab a users hash somehow then they would be trying to decipher whirlpool rather than sha256.

Good plan :rolleyes:

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...