Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
Donovan
Client



Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Sun Dec 03, 2006 3:40 pm Reply with quote

What I need specifically is a function to find out if a team has been attacked in the last 48 hrs.

If they have then they cannot submit a move order.

I have a tracking table that contains the ateam_id (Attack Team ID) and dteam_id (Defending Team ID) and a move_dt which is a Timestamp when the form was submitted. I have an action field that can either contain "Move", "Attack", or "MoveAttack"

What I have somewhat working is if there has been an Attack order submitted it will be written to the tracking table.

What I need to do is if a team submits their own move or attack order then the function will check the tracking table to see if an order has allready been submitted in the last 48 hours. If so their order is not allowed and they are directed to monitor the Titancore challenges in their team profile for an impending attack.

I assume I need to pass the team_id of the user submittimg the move to the function. Something like this to see if the team_id matches any of the dteam_id's. Then check if the move_dt (Timestamp) is less than the current date/time.

Code:
function verifymove($team_id){


$sql = "SELECT * FROM " . $prefix . "_eto_tracking WHERE dteam_id ='$team_id' AND move_dt >= DATE_SUB(current_timestamp, interval 2 day) ";
$result = $db->sql_query($sql);
if ($db->sql_numrows($result) > 0) {
   $verify = 1;
   OpenTable();
   echo 'Your unit is currently under attack. Monitor your challeges in Titancore for pending challenges';
   CloseTable();
}else{
   return $verify;

}
}
?>

So if it $verify returns 0, I continue with the move...correct?

My first attempt at making my code more modular. I will be using this same function in the MoveAttack page.
 
View user's profile Send private message Visit poster's website ICQ Number
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Mon Dec 04, 2006 1:54 am Reply with quote

I get so lost with these "game" questions. Guess I'm just an old fart!

Only you would know if the logic works, but to improve the safety of your code, add this line right before your if statement:

$verify = FALSE;

Also, what do you do with the $verify if it is 1? Unless you are using it somewhere there is no reason to bother setting it. If you need it returned also I would write the code like this:
Code:


function verifymove($team_id){

  $sql = "SELECT * FROM " . $prefix . "_eto_tracking WHERE dteam_id ='$team_id' AND move_dt >= DATE_SUB(current_timestamp, interval 2 day) ";
  $result = $db->sql_query($sql);
  $verify = FALSE;
  if ($db->sql_numrows($result) > 0) {
    $verify = TRUE;
    OpenTable();
    echo 'Your unit is currently under attack. Monitor your challeges in Titancore for pending challenges';
    CloseTable();
  }
  return $verify;
}
?>
 
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©