Release Template files
This commit is contained in:
27
version/proserve-ReleaseTemplate/_api/session/debrief.php
Normal file
27
version/proserve-ReleaseTemplate/_api/session/debrief.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// include database and object files
|
||||
include_once '../config/init.php'; // contains $db
|
||||
include_once '../config/error.php';
|
||||
include_once '../objects/stats_object.php';
|
||||
|
||||
$sessionId = -1;
|
||||
|
||||
// read mandatory $_POST properties : ensure sessionId is passed in $_POST parameters
|
||||
if (isset($_POST['sessionId']))
|
||||
$sessionId = $_POST['sessionId'];
|
||||
else trigger_error( missing_parameter_error("sessionId") );
|
||||
|
||||
$userId = isset($_POST['userId']) ? $_POST['userId'] : -1;
|
||||
|
||||
// check sessionId is > 0
|
||||
//if ($sessionId > 0)
|
||||
//{
|
||||
// prepare user object
|
||||
$stats = new StatsObject($db);
|
||||
$stats->getStatsForSession($sessionId, $userId);
|
||||
|
||||
$stats_arr = $stats->getResultArray(true, "Stats_Collected_OK");
|
||||
print_r(json_encode($stats_arr)); // OK
|
||||
//}
|
||||
//else trigger_error("Invalid session id");
|
||||
?>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// include database and object files
|
||||
include_once '../config/init.php'; // contains $db
|
||||
include_once '../config/error.php';
|
||||
include_once '../objects/stats_object.php';
|
||||
|
||||
$stats = new StatsObject($db);
|
||||
$nb = $stats->fixDurations();
|
||||
|
||||
/*if ($nb == 0)
|
||||
echo "No session to be corrected.";
|
||||
else if ($nb == 1)
|
||||
echo $nb . " session has been corrected.";
|
||||
else
|
||||
echo $nb . " sessions have been corrected.";*/
|
||||
?>
|
||||
22
version/proserve-ReleaseTemplate/_api/session/get.php
Normal file
22
version/proserve-ReleaseTemplate/_api/session/get.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
// include database and object files
|
||||
include_once '../config/init.php'; // contains $db
|
||||
include_once '../config/error.php';
|
||||
include_once '../objects/db_session.php';
|
||||
|
||||
// prepare user object
|
||||
$gameSession = new GameSession($db);
|
||||
|
||||
// read mandatory $_POST properties : ensure sessionId is passed in $_POST parameters
|
||||
if (isset($_POST['sessionId']))
|
||||
$gameSession->id = $_POST['sessionId'];
|
||||
else trigger_error( missing_parameter_error("sessionId") );
|
||||
|
||||
// create the game session
|
||||
if ($gameSession->load())
|
||||
{
|
||||
$session_arr = $gameSession->getResultArray(true, "Session_Found");
|
||||
print_r(json_encode($session_arr)); // OK
|
||||
}
|
||||
else trigger_error("Error_Occured");
|
||||
?>
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
// include database and object files
|
||||
include_once '../config/init.php'; // contains $db
|
||||
include_once '../config/error.php';
|
||||
include_once '../objects/db_participates.php';
|
||||
|
||||
// prepare user object
|
||||
$participation = new UserInGameSession($db);
|
||||
$participation->userId = -1;
|
||||
|
||||
// read mandatory $_POST properties : ensure sessionId is passed in POST parameters
|
||||
if (isset($_POST['sessionId']))
|
||||
$participation->sessionId = $_POST['sessionId'];
|
||||
else trigger_error( missing_parameter_error("sessionId") );
|
||||
|
||||
if (isset($_POST['userId']))
|
||||
$participation->userId = $_POST['userId'];
|
||||
|
||||
$multiple = false;
|
||||
// get overall objectives for all users in session
|
||||
if ($participation->userId == -1)
|
||||
{
|
||||
$users = $participation->getAllUsersInSession();
|
||||
$nbUsers = count($users);
|
||||
if ($nbUsers > 1)
|
||||
{
|
||||
// multiple users for the session : get average of all users objectives
|
||||
$multiple = true;
|
||||
$firstElement = true;
|
||||
foreach ($users as $oneUserId)
|
||||
{
|
||||
$part = new UserInGameSession($db);
|
||||
$part->sessionId = $participation->sessionId;
|
||||
$part->userId = (int)$oneUserId; // contains userId
|
||||
|
||||
if ($part->load())
|
||||
{
|
||||
// if this is the participation for the first user, simply update the participation variable
|
||||
// otherwise, call add function to add this user's participation result to the overall one (participation variable)
|
||||
if ($firstElement)
|
||||
{
|
||||
$participation->copy($part);
|
||||
$firstElement = false;
|
||||
}
|
||||
else
|
||||
$participation->add($part);
|
||||
}
|
||||
}
|
||||
|
||||
// once loop is completed, calculate average score, precision, reactionTime and objective completion
|
||||
$participation->calculateAverages($nbUsers);
|
||||
}
|
||||
else if ($nbUsers == 1)
|
||||
$participation->userId = (int)$users[0];
|
||||
}
|
||||
|
||||
if (!$multiple && $participation->userId == -1)
|
||||
trigger_error( missing_parameter_error("userId") );
|
||||
|
||||
// if we got participation for multiple users OR if we successfully load it for a single one, then everything is good
|
||||
if ($multiple || (!$multiple && $participation->load()))
|
||||
{
|
||||
$participation_arr = $participation->getResultArray(true, "Results_Saved_OK");
|
||||
print_r(json_encode($participation_arr)); // OK
|
||||
}
|
||||
else trigger_error("User_Results_Not_Found");
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
// include database and object files
|
||||
include_once '../config/init.php'; // contains $db
|
||||
include_once '../config/error.php';
|
||||
include_once '../objects/db_participates.php';
|
||||
|
||||
// prepare user object
|
||||
$participation = new UserInGameSession($db);
|
||||
|
||||
// read mandatory $_POST properties : ensure sessionId and userId are passed in POST parameters
|
||||
if (isset($_POST['sessionId']))
|
||||
$participation->sessionId = $_POST['sessionId'];
|
||||
else trigger_error( missing_parameter_error("sessionId") );
|
||||
|
||||
if (isset($_POST['userId']))
|
||||
$participation->userId = $_POST['userId'];
|
||||
else trigger_error( missing_parameter_error("userId") );
|
||||
|
||||
// read other $_POST properties
|
||||
$participation->avatar = $_POST['avatar'] ?? "";
|
||||
$participation->weapon = $_POST['weapon'] ?? "";
|
||||
$participation->role = $_POST['role'] ?? 0;
|
||||
|
||||
// register user to the game session
|
||||
if ($participation->registerUser())
|
||||
{
|
||||
$participation_arr = $participation->getResultArray(true, "User_Registered_OK");
|
||||
print_r(json_encode($participation_arr)); // OK
|
||||
}
|
||||
else trigger_error("User_Already_Registered");
|
||||
?>
|
||||
33
version/proserve-ReleaseTemplate/_api/session/start.php
Normal file
33
version/proserve-ReleaseTemplate/_api/session/start.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
// include database and object files
|
||||
include_once '../config/init.php'; // contains $db
|
||||
include_once '../config/error.php';
|
||||
include_once '../objects/db_session.php';
|
||||
|
||||
// prepare user object
|
||||
$gameSession = new GameSession($db);
|
||||
|
||||
// read mandatory $_POST properties : ensure sessionType and sessionName are passed in $_POST parameters
|
||||
if (isset($_POST['sessionType']))
|
||||
$gameSession->sessionType = $_POST['sessionType'];
|
||||
else trigger_error( missing_parameter_error("sessionType") );
|
||||
|
||||
if (isset($_POST['sessionName']))
|
||||
$gameSession->sessionName = $_POST['sessionName'];
|
||||
else
|
||||
$gameSession->sessionName = uniqid("session_");
|
||||
|
||||
// read other $_POST properties for game session
|
||||
$gameSession->sessionDate = date('Y-m-d H:i:s');
|
||||
$gameSession->mapName = $_POST['mapName'];
|
||||
$gameSession->scenarioName = $_POST['scenarioName'];
|
||||
$gameSession->replayFileName = $gameSession->sessionName . date('Y-m-d_H-i-s');
|
||||
|
||||
// create the game session
|
||||
if ($gameSession->start())
|
||||
{
|
||||
$session_arr = $gameSession->getResultArray(true, "Session_In_Progress_OK");
|
||||
print_r(json_encode($session_arr)); // OK
|
||||
}
|
||||
else trigger_error("Error_Occured");
|
||||
?>
|
||||
27
version/proserve-ReleaseTemplate/_api/session/stop.php
Normal file
27
version/proserve-ReleaseTemplate/_api/session/stop.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// include database and object files
|
||||
include_once '../config/init.php'; // contains $db
|
||||
include_once '../config/error.php';
|
||||
include_once '../objects/db_session.php';
|
||||
|
||||
// prepare user object
|
||||
$gameSession = new GameSession($db);
|
||||
|
||||
// read mandatory $_POST properties : ensure sessionType and sessionName are passed in $_POST parameters
|
||||
if (isset($_POST['sessionId']))
|
||||
$gameSession->id = $_POST['sessionId'];
|
||||
else trigger_error( missing_parameter_error("sessionId") );
|
||||
|
||||
// read other $_POST properties for game session
|
||||
$gameSession->timeToFinish = $_POST['duration'];
|
||||
$gameSession->success = (strcasecmp( ($_POST['success'] ?? false), "true" ) == 0) ? 1 : 0;
|
||||
$gameSession->score = $_POST['score'];
|
||||
|
||||
// close the game session
|
||||
if ($gameSession->stop())
|
||||
{
|
||||
$session_arr = $gameSession->getResultArray(true, "Session_Stop_OK");
|
||||
print_r(json_encode($session_arr)); // OK
|
||||
}
|
||||
else trigger_error("Error_Occured");
|
||||
?>
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
// include database and object files
|
||||
include_once '../config/init.php'; // contains $db
|
||||
include_once '../config/error.php';
|
||||
include_once '../objects/db_participates.php';
|
||||
|
||||
// prepare user object
|
||||
$participation = new UserInGameSession($db);
|
||||
|
||||
// read mandatory $_POST properties : ensure sessionId and userId are passed in POST parameters
|
||||
if (isset($_POST['sessionId']))
|
||||
$participation->sessionId = $_POST['sessionId'];
|
||||
else trigger_error( missing_parameter_error("sessionId") );
|
||||
|
||||
if (isset($_POST['userId']))
|
||||
$participation->userId = $_POST['userId'];
|
||||
else trigger_error( missing_parameter_error("userId") );
|
||||
|
||||
// get overall objectives for all users in session
|
||||
if ($participation->userId == -1)
|
||||
{
|
||||
$users = $participation->getAllUsersInSession();
|
||||
if (count($users) >= 1)
|
||||
$participation->userId = $users[0];
|
||||
//else
|
||||
//{
|
||||
// foreach ($users as $userId)
|
||||
// {
|
||||
// $participation->userId = $userId;
|
||||
// $participation->load();
|
||||
// $participation->results = $results;
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
// load from database
|
||||
if ($participation->load())
|
||||
{
|
||||
// read other $_POST properties
|
||||
$participation->results = $_POST['results'] ?? "";
|
||||
|
||||
// update objectives of user in the game session
|
||||
if ($participation->updateObjectives())
|
||||
{
|
||||
$participation_arr = $participation->getResultArray(true, "Results_Saved_OK");
|
||||
print_r(json_encode($participation_arr)); // OK
|
||||
}
|
||||
else trigger_error("User_Results_Not_Saved");
|
||||
}
|
||||
else trigger_error("Couldn't find user with id " . $participation->userId . " in session with id " . $participation->sessionId . ".");
|
||||
|
||||
//function loadObjectivesForParticipation ()
|
||||
//{
|
||||
// if ($participation->load())
|
||||
// {
|
||||
// // read other $_POST properties
|
||||
// $participation->results = $results;
|
||||
//
|
||||
// // register user to the game session
|
||||
// if ($participation->updateObjectives())
|
||||
// {
|
||||
// $participation_arr = $participation->getResultArray(true, "Results_Saved_OK");
|
||||
// print_r(json_encode($participation_arr)); // OK
|
||||
// }
|
||||
// else trigger_error("User_Results_Not_Saved");
|
||||
// }
|
||||
// else trigger_error("Couldn't find user with id " . $participation->userId . " in session with id " . $participation->sessionId . ".");
|
||||
//}
|
||||
?>
|
||||
34
version/proserve-ReleaseTemplate/_api/session/userleave.php
Normal file
34
version/proserve-ReleaseTemplate/_api/session/userleave.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
// include database and object files
|
||||
include_once '../config/init.php'; // contains $db
|
||||
include_once '../config/error.php';
|
||||
include_once '../objects/db_participates.php';
|
||||
|
||||
// prepare user object
|
||||
$participation = new UserInGameSession($db);
|
||||
|
||||
// ensure sessionId and userId are passed in $_POST parameters
|
||||
if (isset($_POST['sessionId']))
|
||||
$participation->sessionId = $_POST['sessionId'];
|
||||
else trigger_error( missing_parameter_error("sessionId") );
|
||||
|
||||
if (isset($_POST['userId']))
|
||||
$participation->userId = $_POST['userId'];
|
||||
else trigger_error( missing_parameter_error("userId") );
|
||||
|
||||
if (isset($_POST['endStatus']))
|
||||
$participation->endStatus = $_POST['endStatus'];
|
||||
|
||||
// user leaves session
|
||||
if ($participation->userLeaves())
|
||||
{
|
||||
// update score and averages
|
||||
if ($participation->updateUserScores())
|
||||
{
|
||||
$participation_arr = $participation->getResultArray(true, "User_Left_OK");
|
||||
print_r(json_encode($participation_arr)); // OK
|
||||
}
|
||||
else trigger_error("Calculate_Score_Failed");
|
||||
}
|
||||
else trigger_error("Leave_Session_Failed");
|
||||
?>
|
||||
Reference in New Issue
Block a user