Version19.81.1

This commit is contained in:
Antonio Cañas Vargas 2019-12-02 09:57:17 +01:00
parent 2428e91bdd
commit b342f2cafd
4 changed files with 108 additions and 18 deletions

View File

@ -108,6 +108,7 @@ cp -f /home/acanas/swad/swad/swad /var/www/cgi-bin/
#include "swad_global.h"
#include "swad_hierarchy.h"
#include "swad_ID.h"
#include "swad_match.h"
#include "swad_notice.h"
#include "swad_notification.h"
#include "swad_password.h"
@ -4670,6 +4671,9 @@ int swad__playMatch (struct soap *soap,
struct swad__playMatchOutput *playMatchOut) // output
{
int ReturnCode;
struct Match Match;
struct Game Game;
bool ICanPlayThisMatchBasedOnGrps;
/***** Initializations *****/
Gbl.soap = soap;
@ -4683,8 +4687,68 @@ int swad__playMatch (struct soap *soap,
"Bad web service key",
"Web service key does not exist in database");
// TODO: Write the code
playMatchOut->matchCode = matchCode;
/***** Get match data from database *****/
Match.MchCod = (long) matchCode;
if (Match.MchCod <= 0)
return soap_sender_fault (Gbl.soap,
"Bad match code",
"Match code must be a integer greater than 0");
Mch_GetDataOfMatchByCod (&Match);
/***** Get game data from database *****/
Game.GamCod = Match.GamCod;
if (Game.GamCod <= 0)
return soap_sender_fault (Gbl.soap,
"Bad game code",
"Game code must be a integer greater than 0");
Gam_GetDataOfGameByCod (&Game);
/***** Check if course code is correct *****/
Gbl.Hierarchy.Crs.CrsCod = (long) Game.CrsCod;
if (Gbl.Hierarchy.Crs.CrsCod <= 0)
return soap_sender_fault (Gbl.soap,
"Bad course code",
"Course code must be a integer greater than 0");
/***** Get some of my data *****/
if (!API_GetSomeUsrDataFromUsrCod (&Gbl.Usrs.Me.UsrDat,Gbl.Hierarchy.Crs.CrsCod))
return soap_receiver_fault (Gbl.soap,
"Can not get user's data from database",
"User does not exist in database");
Gbl.Usrs.Me.Logged = true;
Gbl.Usrs.Me.Role.Logged = Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role;
/***** Check if I am a student in the course *****/
switch (Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role)
{
case Rol_STD:
// OK. I am a student to the course
break;
default:
return soap_receiver_fault (Gbl.soap,
"Request forbidden",
"Requester must be a student in the course");
}
/***** Can I play this match? *****/
ICanPlayThisMatchBasedOnGrps = Mch_CheckIfICanPlayThisMatchBasedOnGrps (Match.MchCod);
if (!ICanPlayThisMatchBasedOnGrps)
return soap_receiver_fault (Gbl.soap,
"Request forbidden",
"Requester can not join this match");
/***** Join match *****/
if (Match.Status.Playing)
{
if (Match.Status.QstInd < Mch_AFTER_LAST_QUESTION) // Unfinished
/* Update players */
playMatchOut->matchCode = Mch_RegisterMeAsPlayerInMatch (&Match) ? matchCode : // > 0 ==> OK
-1; // < 0 ==> can not join this match
else
playMatchOut->matchCode = 0; // == 0 ==> wait
}
else // Not being played
playMatchOut->matchCode = 0; // == 0 ==> wait
return SOAP_OK;
}

View File

@ -490,7 +490,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - *
En OpenSWAD:
ps2pdf source.ps destination.pdf
*/
#define Log_PLATFORM_VERSION "SWAD 19.81 (2019-12-01)"
#define Log_PLATFORM_VERSION "SWAD 19.81.1 (2019-12-01)"
#define CSS_FILE "swad19.78.1.css"
#define JS_FILE "swad19.70.js"
/*
@ -498,7 +498,8 @@ ps2pdf source.ps destination.pdf
// TODO: Impedir la creación y edición de proyectos si no son editables.
// TODO: En cada juego, poder listar los resultados en una tabla como la de resultados globales
Version 19.81: Dec 01, 2019 New API functions related to games and matches. (247540 lines)
Version 19.81.1: Dec 01, 2019 API function playMatch finished. (247620 lines)
Version 19.81: Dec 01, 2019 New (some unfinished) API functions related to games and matches. (247540 lines)
Version 19.80.7: Nov 29, 2019 Changes in match results. (247242 lines)
Version 19.80.6: Nov 28, 2019 Changes in match results and test results. (247245 lines)
Version 19.80.5: Nov 28, 2019 Total grade is always displayed in results. (247278 lines)

View File

@ -189,7 +189,6 @@ static void Mch_RemoveOldPlayers (void);
static void Mch_UpdateMatchAsBeingPlayed (long MchCod);
static void Mch_SetMatchAsNotBeingPlayed (long MchCod);
static bool Mch_GetIfMatchIsBeingPlayed (long MchCod);
static void Mch_RegisterMeAsPlayerInMatch (long MchCod);
static void Mch_GetNumPlayers (struct Match *Match);
static double Mch_ComputeScore (unsigned NumQsts);
@ -2238,18 +2237,21 @@ static void Mch_ShowRightColumnStd (struct Match *Match)
/***** Bottom row *****/
if (Match->Status.Playing)
{
if (Match->Status.QstInd < Mch_AFTER_LAST_QUESTION) // Unfinished
if (Match->Status.QstInd < Mch_AFTER_LAST_QUESTION) // Match not over
{
HTM_DIV_Begin ("class=\"MCH_BOTTOM\"");
/***** Update players ******/
Mch_RegisterMeAsPlayerInMatch (Match->MchCod);
/* Show current question and possible answers */
Mch_ShowQuestionAndAnswersStd (Match);
if (Mch_RegisterMeAsPlayerInMatch (Match))
/* Show current question and possible answers */
Mch_ShowQuestionAndAnswersStd (Match);
else
Ale_ShowAlert (Ale_ERROR,"You can not join this match.");
HTM_DIV_End ();
}
else // Match over
Mch_ShowWaitImage (Txt_Please_wait_);
}
else // Not being played
Mch_ShowWaitImage (Txt_Please_wait_);
@ -2976,14 +2978,6 @@ static bool Mch_GetIfMatchIsBeingPlayed (long MchCod)
MchCod) != 0);
}
static void Mch_RegisterMeAsPlayerInMatch (long MchCod)
{
/***** Insert me as match player *****/
DB_QueryREPLACE ("can not insert match player",
"REPLACE mch_players (MchCod,UsrCod) VALUES (%ld,%ld)",
MchCod,Gbl.Usrs.Me.UsrDat.UsrCod);
}
static void Mch_GetNumPlayers (struct Match *Match)
{
/***** Get number of players who are playing a match *****/
@ -2994,6 +2988,36 @@ static void Mch_GetNumPlayers (struct Match *Match)
Match->MchCod);
}
/*****************************************************************************/
/******************* Register me as a player in a match **********************/
/*****************************************************************************/
// Return true on success
bool Mch_RegisterMeAsPlayerInMatch (struct Match *Match)
{
/***** Trivial check: match code must be > 0 *****/
if (Match->MchCod <= 0)
return false;
/***** Trivial check: match must be being played *****/
if (!Match->Status.Playing) // Not playing
return false;
/***** Trivial check: match must not be over *****/
if (Match->Status.QstInd >= Mch_AFTER_LAST_QUESTION) // Finished
return false;
/***** Trivial check: only a student can join a match *****/
if (Gbl.Usrs.Me.Role.Logged != Rol_STD) // I am not logged as student
return false;
/***** Insert me as match player *****/
DB_QueryREPLACE ("can not insert match player",
"REPLACE mch_players (MchCod,UsrCod) VALUES (%ld,%ld)",
Match->MchCod,Gbl.Usrs.Me.UsrDat.UsrCod);
return true;
}
/*****************************************************************************/
/********************** Get code of match being played ***********************/
/*****************************************************************************/

View File

@ -111,6 +111,7 @@ void Mch_ForwardMatch (void);
unsigned Mch_GetNumMchsInGame (long GamCod);
bool Mch_CheckIfICanPlayThisMatchBasedOnGrps (long MchCod);
bool Mch_RegisterMeAsPlayerInMatch (struct Match *Match);
void Mch_GetMatchBeingPlayed (void);
void Mch_JoinMatchAsStd (void);