OSdata.com |
Building a game open source code This is the actual source code from a new web game. See the game at thissideofsanity.com and read how this was built starting at example code.
This is example code from the SlamZee project and This Side of Sanity, released under Apache License 2.0.
Copyright 2013 Milo (for software), Distribution and website handled by Strazbick.com
Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
This narrative uses anchor links so that you can follow the building of this software in chronological order. Go to software explanation to start reading. Go to thissideofsanity.com to see the working software.
This is example code from the SlamZee project and This Side of Sanity, released under Apache License 2.0.
Visitor authorization functions.
<?php /* FILE NAME /visitorauthorization.php */ require_once('./php/databasefunctions.php'); /******************************/ /* NonceCharacter */ /* generate a nonce character */ /******************************/ function NonceCharacter() { $randomnumber = rand(1,36); if ( $randomnumber == 1 ) return '1'; /* the number */ elseif ( $randomnumber == 2 ) return '2'; elseif ( $randomnumber == 3 ) return '3'; elseif ( $randomnumber == 4 ) return '4'; elseif ( $randomnumber == 5 ) return '5'; elseif ( $randomnumber == 6 ) return '6'; elseif ( $randomnumber == 7 ) return '7'; elseif ( $randomnumber == 8 ) return '8'; elseif ( $randomnumber == 9 ) return '9'; elseif ( $randomnumber == 10 ) return '0'; /* the number */ elseif ( $randomnumber == 11 ) return 'A'; elseif ( $randomnumber == 12 ) return 'B'; elseif ( $randomnumber == 13 ) return 'C'; elseif ( $randomnumber == 14 ) return 'D'; elseif ( $randomnumber == 15 ) return 'E'; elseif ( $randomnumber == 16 ) return 'F'; elseif ( $randomnumber == 17 ) return 'G'; elseif ( $randomnumber == 18 ) return 'H'; elseif ( $randomnumber == 19 ) return 'I'; /* the letter */ elseif ( $randomnumber == 20 ) return 'J'; elseif ( $randomnumber == 21 ) return 'K'; elseif ( $randomnumber == 22 ) return 'L'; elseif ( $randomnumber == 23 ) return 'M'; elseif ( $randomnumber == 24 ) return 'N'; elseif ( $randomnumber == 25 ) return 'O'; /* the letter */ elseif ( $randomnumber == 26 ) return 'P'; elseif ( $randomnumber == 27 ) return 'Q'; elseif ( $randomnumber == 28 ) return 'R'; elseif ( $randomnumber == 29 ) return 'S'; elseif ( $randomnumber == 30 ) return 'T'; elseif ( $randomnumber == 31 ) return 'U'; elseif ( $randomnumber == 32 ) return 'V'; elseif ( $randomnumber == 33 ) return 'W'; elseif ( $randomnumber == 34 ) return 'X'; elseif ( $randomnumber == 35 ) return 'Y'; else /* default case */ return 'Z'; } /* END NonceCharacter */ /******************************/ /* NonceGenerator */ /* generate a number used once */ /******************************/ function NonceGenerator() { $noncestring = NonceCharacter().NonceCharacter().NonceCharacter().NonceCharacter().NonceCharacter().NonceCharacter().NonceCharacter().NonceCharacter().NonceCharacter().NonceCharacter().NonceCharacter().NonceCharacter().NonceCharacter().NonceCharacter().NonceCharacter().NonceCharacter(); return $noncestring; } /* END NonceGenerator */ /******************************/ /* SetAdminFlag */ /******************************/ function SetAdminFlag( $currentuser ) { global $adminflag; /* VALIDATE ADMIN */ if (($currentuser == 'Milo') OR ($currentuser == 'michaelm')) $adminflag = true; else $adminflag = false; } /* END SetAdminFlag*/ /******************************/ /* RegisterNewVisitor */ /* called from newregistration.php ProcessRegistrationForm */ /******************************/ function RegisterNewVisitor($accountname, $passwd, $firstname, $lastname,$gender,$birthdate,$email) // register new person with db // return true or error message { // connect to db $conn = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$conn) { echo 'Could not connect to database server - please try later.'; return false; } // check if username is unique $testname = strtolower($accountname); // actually don't need any info other than existence in data base, so just get the account name $result = mysql_query("select accountname from accounts where lower(accountname) ='$testname'"); if (!$result) { echo '<br>Could not execute query'; /*return false;*/ } if (mysql_num_rows($result)>0) { echo 'That screen name is taken - Choose another one.'; require_once('./php/newregistration.php'); DisplayRegistrationForm(); /* located in newregistration.php */ return false; } // check if email is unique $testemail = strtolower($email); // actually don't need any info other than existence in data base, so just get the email $result = mysql_query("select email from accounts where lower(email) ='$testemail'"); if (!$result) { echo '<br>Could not execute query'; /*return false;*/ } if (mysql_num_rows($result)>0) { echo 'That email is taken - Choose another one.'; require_once('./php/newregistration.php'); DisplayRegistrationForm(); /* located in newregistration.php */ return false; } if ($firstname == "") $firstname = "NULL"; if ($lastname == "") $lastname = "NULL"; $datearray = getdate(); $year = $datearray['year']; $month = $datearray['mon']; $monthday = $datearray['mday']; if ($month < 10) $firstpart = $year."-0".$month; else $firstpart = $year."-".$month; if ($monthday < 10) $secondpart = "-0".$monthday; else $secondpart = "-".$monthday; $todaydate = $firstpart.$secondpart; $currentdatetime = date('Y-m-d H:i:s', time()); // if ok, put in db $query = "insert into accounts values (NULL, '$accountname', '$email', password('$passwd'), '$firstname', '$lastname', '$gender', '$birthdate', '$todaydate', '$currentdatetime')"; $result = mysql_query($query); if (!$result) { echo 'Could not register you in visitor database - please try again later.'; /*echo "<br>SQL query is ".$query; /* TESTING */ /*echo "<br>SQL error is ".mysql_error().' SQL error number '.mysql_errno(); /* TESTING */ return false; } return true; } /* END RegisterNewVisitor */ /******************************/ /* LoginVisitor */ /* this routine is misnamed */ /* actually checks that the email and */ /* passsword MATCH for an account */ /* called by login.php */ /* called from newregistration.php */ /* called from ChangePassword in visitorauthorization.php */ /******************************/ function LoginVisitor($email, $password) // check username and password with db // if yes, return true // else return false { // attempt to connect to db $conn = ConnectCelebDataBase(0); /* located in databasefunctions.php */ if (!$conn) return -1; // check if username is unique $result = mysql_query("select * from accounts where email ='$email' and password = password('$password')"); if (!$result) return -2; if (mysql_num_rows($result)>0) return 0; else return -3; } /* END LoginVisitor */ /******************************/ /* ChangePasswordDataBase */ /* called from changepassword.php */ /******************************/ function ChangePasswordDataBase($username, $oldpassword, $newpassword) // change password for username/oldpassword to newpassword // return true or false { // if the old password is right // change their password to newpassword and return true // else return false $result = LoginVisitor($email, $oldpassword); /* located in visitorauthorization.php - actually checks to see that the account name and password are a valid match*/ if ($result == 0) { $result = mysql_query( "update accounts set password = password('$newpassword') where email = '$email'"); if (!$result) return false; // not changed else return true; // changed successfully } else { echo "<p style=\"color:#ff0000\">old password was wrong</p>"; return false; // old password was wrong } } /* END ChangePasswordDataBase */ ?>
Add integer fields to the data base for money, credits, and tokens, with each defaulting to one.
Modify function RegisterNewVisitor
:
$query = "insert into accounts values (NULL, '$accountname', '$email', password('$passwd'), '$firstname', '$lastname', '$gender', '$birthdate', '$todaydate', '$currentdatetime', 'P',0,0,1, NULL)";
OSdata.com is used in more than 300 colleges and universities around the worldFind out how to get similar high web traffic and search engine placement. |
OSdata.com is used in more than 300 colleges and universities around the world |
Tweets by @osdata |
A web site on dozens of operating systems simply cant be maintained by one person. This is a cooperative effort. If you spot an error in fact, grammar, syntax, or spelling, or a broken link, or have additional information, commentary, or constructive criticism, please e-mail Milo. If you have any extra copies of docs, manuals, or other materials that can assist in accuracy and completeness, please send them to Milo, PO Box 1361, Tustin, CA, USA, 92781.
Click here for our privacy policy.
previous page | next page |
This web site handcrafted on Macintosh computers using Tom Benders Tex-Edit Plus and served using FreeBSD .
Names and logos of various OSs are trademarks of their respective owners.
Copyright © 2013 Milo
Last Updated: November 21, 2013
Created: September 9, 2013
previous page | next page |