Important alert: (current site time 7/15/2013 10:28:43 AM EDT)
 

VB icon

datatrans (raw game engine)

Email
Submitted on: 2/8/2004 9:13:35 PM
By: buhhmann  
Level: Beginner
User Rating: By 1 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 9592
author picture
(About the author)
 
     You can send data to a server where it will be stored in a file. Then, once created, another party can download this data with the same script. That is a primitive and easy to understand concept for a data exchange engine for round based strategy games for example.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: datatrans (raw game engine)
// Description:You can send data to a server where it will be stored in a file. Then, once created, another party can download this data with the same script.
That is a primitive and easy to understand concept for a data exchange engine for round based strategy games for example.
// By: buhhmann
//
// Inputs:Params: dat (the data), pak (the file), act (the action), mod (optional fwrite-mode)
//
// Returns:Return an error code if something went wrong, or 'OK' when dataupload was successfull, or a timestring plus the content of the file.
//
// Side Effects:That is very basic code and has surely some securityholes!!!!
Also once a file is created it will not be deleted automatically!
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1270&lngWId=8//for details.//**************************************

<?
//Params: dat (the data), pak (the file), act (the action), mod (optional fwrite-mode)
//=============================SETTINGS=================================//
$dir = "./";//Where to save the datapacket...
$maxdat = 2500;//Maximum bytes per datapacket
$fe = ".dp";//FileExtension:Prevents scriptupload etc!
//=============================SECURITY=================================//
if($act==""){echo "ERROR:ACT";exit;}
if($dat=="" && $act=="w"){echo "ERROR:DAT-ACT";exit;}
if($pak==""){echo "ERROR:PAK";exit;}
if(strlen($dat)>$maxdat){echo "ERROR:DATLEN";exit;}
if($mod<>"a"){$mod="w";}
//==============================SCRIPT==================================//
//Action: Read
if($act=="r"){
 $data=file_get_contents($dir.$pak.$fe);
 if(!$data){echo "ERROR:NODATA";exit;}
 echo filemtime($dir.$pak.$fe).":".$data;
}
//Action: Write
if($act=="w"){
 if(!$fh = fopen($dir.$pak.$fe,$mod)){echo "ERROR:FOPEN";exit;}
 if(!fwrite($fh,$dat)){echo "ERROR:FWRITE";exit;}
 fclose($fh);
 echo "OK";
}
?>


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

7/29/2004 5:20:44 AM

thanks forword
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.