mirror of https://github.com/acanas/swad-core.git
Version18.135
This commit is contained in:
parent
7c1b62b584
commit
f5f48cd08e
|
@ -644,6 +644,13 @@ CREATE TABLE IF NOT EXISTS gam_matches (
|
|||
UNIQUE INDEX(MchCod),
|
||||
INDEX(GamCod));
|
||||
--
|
||||
-- Table gam_mch_being_played: stores the current matches being played
|
||||
--
|
||||
CREATE TABLE IF NOT EXISTS gam_mch_being_played (
|
||||
MchCod INT NOT NULL,
|
||||
TS TIMESTAMP,
|
||||
UNIQUE INDEX(MchCod));
|
||||
--
|
||||
-- Table gam_players: stores the current match players
|
||||
--
|
||||
CREATE TABLE IF NOT EXISTS gam_players (
|
||||
|
|
|
@ -2154,11 +2154,11 @@ struct Act_Actions Act_Actions[Act_NUM_ACTIONS] =
|
|||
/* ActResMchTch */{1785,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_NEW_TAB,Gam_GetMatchBeingPlayed ,Gam_RequestStartResumeMatchTch ,NULL},
|
||||
/* ActCurMchTch */{1789,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_2ND_TAB,Gam_GetMatchBeingPlayed ,Gam_CurrentStatusMatchTch ,NULL},
|
||||
/* ActNxtMchTch */{1672,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_2ND_TAB,Gam_GetMatchBeingPlayed ,Gam_NextStatusMatchTch ,NULL},
|
||||
/* ActRefMchTch */{1788,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_AJAX_RFRESH,Gam_GetMatchBeingPlayed ,Gam_RefreshNumPlayersMatchTch ,NULL},
|
||||
/* ActRefMchTch */{1788,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_AJAX_RFRESH,Gam_GetMatchBeingPlayed ,Gam_RefreshMatchTch ,NULL},
|
||||
/* ActShoMchTch */{1786,-1,TabUnk,ActSeeAllGam ,0x230,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_ShowFinishedMatchResults ,NULL},
|
||||
|
||||
/* ActPlyMchStd */{1780,-1,TabUnk,ActSeeAllGam ,0x008, 0, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_NEW_TAB,Gam_GetMatchBeingPlayed ,Gam_ShowMatchToMeAsStd ,NULL},
|
||||
/* ActRefMchStd */{1782,-1,TabUnk,ActSeeAllGam ,0x008, 0, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_AJAX_RFRESH,Gam_GetMatchBeingPlayed ,Gam_RefreshCurrentMatchStd ,NULL},
|
||||
/* ActRefMchStd */{1782,-1,TabUnk,ActSeeAllGam ,0x008, 0, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_AJAX_RFRESH,Gam_GetMatchBeingPlayed ,Gam_RefreshMatchStd ,NULL},
|
||||
/* ActAnsMchQstStd */{1651,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_2ND_TAB,Gam_GetMatchBeingPlayed ,Gam_ReceiveQstAnsFromStd ,NULL},
|
||||
|
||||
/* ActFrmNewGam */{1652,-1,TabUnk,ActSeeAllGam ,0x238,0x200, 0, 0, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,NULL ,Gam_RequestCreatOrEditGame ,NULL},
|
||||
|
|
|
@ -458,10 +458,14 @@ En OpenSWAD:
|
|||
ps2pdf source.ps destination.pdf
|
||||
*/
|
||||
|
||||
#define Log_PLATFORM_VERSION "SWAD 18.134 (2019-07-16)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 18.135 (2019-07-17)"
|
||||
#define CSS_FILE "swad18.132.2.css"
|
||||
#define JS_FILE "swad18.130.2.js"
|
||||
/*
|
||||
Version 18.135: Jul 17, 2019 A match is put in pause for students when the teacher closes the tab. (243707 lines)
|
||||
1 change necessary in database:
|
||||
CREATE TABLE IF NOT EXISTS gam_mch_being_played (MchCod INT NOT NULL,TS TIMESTAMP,UNIQUE INDEX(MchCod));
|
||||
|
||||
Version 18.134: Jul 17, 2019 Changes resuming a match. (243641 lines)
|
||||
2 changes necessary in database:
|
||||
UPDATE actions SET Txt='Mostrar pregunta siguiente en partida (como profesor)' WHERE ActCod='1672' AND Language='es';
|
||||
|
|
|
@ -1401,6 +1401,22 @@ mysql> DESCRIBE gam_matches;
|
|||
"UNIQUE INDEX(MchCod),"
|
||||
"INDEX(GamCod)");
|
||||
|
||||
/***** Table gam_mch_being_played *****/
|
||||
/*
|
||||
mysql> DESCRIBE gam_mch_being_played;
|
||||
+--------+-----------+------+-----+-------------------+-----------------------------+
|
||||
| Field | Type | Null | Key | Default | Extra |
|
||||
+--------+-----------+------+-----+-------------------+-----------------------------+
|
||||
| MchCod | int(11) | NO | PRI | NULL | |
|
||||
| TS | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
|
||||
+--------+-----------+------+-----+-------------------+-----------------------------+
|
||||
2 rows in set (0.01 sec)
|
||||
*/
|
||||
DB_CreateTable ("CREATE TABLE IF NOT EXISTS gam_mch_being_played ("
|
||||
"MchCod INT NOT NULL,"
|
||||
"TS TIMESTAMP,"
|
||||
"UNIQUE INDEX(MchCod))");
|
||||
|
||||
/***** Table gam_players *****/
|
||||
/*
|
||||
mysql> DESCRIBE gam_players;
|
||||
|
|
118
swad_game.c
118
swad_game.c
|
@ -92,6 +92,7 @@ struct Match
|
|||
time_t QstStartTimeUTC;
|
||||
bool ShowingAnswers;
|
||||
bool Finished;
|
||||
bool BeingPlayed;
|
||||
} Status;
|
||||
};
|
||||
|
||||
|
@ -192,7 +193,9 @@ static void Gam_PutBigButton (Act_Action_t NextAction,long MchCod,
|
|||
const char *Icon,const char *Txt);
|
||||
|
||||
static void Gam_RemoveOldPlayers (void);
|
||||
static void Gam_RemoveAllPlayersInMatch (long MchCod);
|
||||
static void Gam_UpdateMatchAsBeingPlayed (long MchCod);
|
||||
static void Gam_SetMatchAsNotBeingPlayed (long MchCod);
|
||||
static bool Gam_GetIfMatchIsBeingPlayed (long MchCod);
|
||||
static void Gam_RegisterMeAsPlayerInMatch (long MchCod);
|
||||
static void Gam_GetAndShowNumPlayersInMatch (long MchCod);
|
||||
static unsigned Gam_GetNumPlayers (long MchCod);
|
||||
|
@ -2779,6 +2782,7 @@ void Gam_GetDataOfMatchByCod (struct Match *Match)
|
|||
Match->Status.QstStartTimeUTC = (time_t) 0;
|
||||
Match->Status.ShowingAnswers = false;
|
||||
Match->Status.Finished = false;
|
||||
Match->Status.BeingPlayed = false;
|
||||
}
|
||||
|
||||
/***** Free structure that stores the query result *****/
|
||||
|
@ -3041,6 +3045,12 @@ static void Gam_GetMatchDataFromRow (MYSQL_RES *mysql_res,
|
|||
|
||||
/* Get whether the match is finished or not (row(10)) */
|
||||
Match->Status.Finished = (row[10][0] == 'Y');
|
||||
|
||||
/***** Get whether the match is being played or not *****/
|
||||
if (Match->Status.Finished)
|
||||
Match->Status.BeingPlayed = false;
|
||||
else
|
||||
Match->Status.BeingPlayed = Gam_GetIfMatchIsBeingPlayed (Match->MchCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3343,6 +3353,10 @@ static void Gam_UpdateMatchBeingPlayed (struct Match *Match)
|
|||
Match->Status.Finished ? 'Y' :
|
||||
'N',
|
||||
Match->MchCod,Gbl.Hierarchy.Crs.CrsCod);
|
||||
|
||||
if (Match->Status.Finished)
|
||||
/* Update match as not being played */
|
||||
Gam_SetMatchAsNotBeingPlayed (Match->MchCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3383,10 +3397,6 @@ void Gam_CurrentStatusMatchTch (void)
|
|||
/* Update match status in database */
|
||||
Gam_UpdateMatchBeingPlayed (&Match);
|
||||
}
|
||||
|
||||
/* Remove all players in this match */
|
||||
if (Match.Status.Finished)
|
||||
Gam_RemoveAllPlayersInMatch (Match.MchCod);
|
||||
}
|
||||
|
||||
/***** Show current match status *****/
|
||||
|
@ -3467,10 +3477,6 @@ void Gam_NextStatusMatchTch (void)
|
|||
|
||||
/* Update match status in database */
|
||||
Gam_UpdateMatchBeingPlayed (&Match);
|
||||
|
||||
/* Remove all players in this match */
|
||||
if (Match.Status.Finished)
|
||||
Gam_RemoveAllPlayersInMatch (Match.MchCod);
|
||||
}
|
||||
|
||||
/***** Show current match status *****/
|
||||
|
@ -3493,10 +3499,16 @@ static void Gam_ShowMatchStatusForTch (struct Match *Match)
|
|||
{
|
||||
/***** Show current match status *****/
|
||||
if (Match->Status.Finished)
|
||||
/* Show alert */
|
||||
Gam_ShowAlertFinishedMatch ();
|
||||
else // Unfinished match
|
||||
/***** Show current question and possible answers *****/
|
||||
{
|
||||
/* Show current question and possible answers */
|
||||
Gam_PlayGameShowQuestionAndAnswers (Match);
|
||||
|
||||
/* Update match as being played */
|
||||
Gam_UpdateMatchAsBeingPlayed (Match->MchCod);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -3635,30 +3647,57 @@ static void Gam_PutBigButton (Act_Action_t NextAction,long MchCod,
|
|||
|
||||
static void Gam_RemoveOldPlayers (void)
|
||||
{
|
||||
/***** Remove players who have left matches *****/
|
||||
DB_QueryDELETE ("can not remove old match players",
|
||||
"DELETE FROM gam_players"
|
||||
" WHERE TS<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)",
|
||||
Cfg_SECONDS_TO_REFRESH_GAME*5);
|
||||
/***** Delete matches not being played *****/
|
||||
DB_QueryDELETE ("can not update matches as not being played",
|
||||
"DELETE FROM gam_mch_being_played"
|
||||
" WHERE TS<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)",
|
||||
Cfg_SECONDS_TO_REFRESH_GAME*3);
|
||||
|
||||
/***** Delete players who have left matches *****/
|
||||
DB_QueryDELETE ("can not update match players",
|
||||
"DELETE FROM gam_players"
|
||||
" WHERE TS<FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)",
|
||||
Cfg_SECONDS_TO_REFRESH_GAME*3);
|
||||
}
|
||||
|
||||
static void Gam_RemoveAllPlayersInMatch (long MchCod)
|
||||
static void Gam_UpdateMatchAsBeingPlayed (long MchCod)
|
||||
{
|
||||
/***** Insert me as match player *****/
|
||||
DB_QueryREPLACE ("can not set match as being played",
|
||||
"REPLACE gam_mch_being_played (MchCod) VALUE (%ld)",
|
||||
MchCod);
|
||||
}
|
||||
|
||||
static void Gam_SetMatchAsNotBeingPlayed (long MchCod)
|
||||
{
|
||||
/***** Delete all match players ******/
|
||||
DB_QueryDELETE ("can not delete match players",
|
||||
DB_QueryDELETE ("can not update match players",
|
||||
"DELETE FROM gam_players"
|
||||
" WHERE MchCod=%ld",
|
||||
MchCod);
|
||||
|
||||
/***** Delete match as being played ******/
|
||||
DB_QueryDELETE ("can not set match as not being played",
|
||||
"DELETE FROM gam_mch_being_played"
|
||||
" WHERE MchCod=%ld",
|
||||
MchCod);
|
||||
}
|
||||
|
||||
static bool Gam_GetIfMatchIsBeingPlayed (long MchCod)
|
||||
{
|
||||
/***** Get if a match is being played or not *****/
|
||||
return
|
||||
(bool) (DB_QueryCOUNT ("can not get if match is being played",
|
||||
"SELECT COUNT(*) FROM gam_mch_being_played"
|
||||
" WHERE MchCod=%ld",
|
||||
MchCod) != 0);
|
||||
}
|
||||
|
||||
static void Gam_RegisterMeAsPlayerInMatch (long MchCod)
|
||||
{
|
||||
/***** Insert me as match player *****/
|
||||
DB_QueryREPLACE ("can not insert match player",
|
||||
"REPLACE gam_players"
|
||||
" (MchCod,UsrCod)"
|
||||
" VALUES"
|
||||
" (%ld,%ld)",
|
||||
"REPLACE gam_players (MchCod,UsrCod) VALUES (%ld,%ld)",
|
||||
MchCod,Gbl.Usrs.Me.UsrDat.UsrCod);
|
||||
}
|
||||
|
||||
|
@ -3725,23 +3764,33 @@ void Gam_ShowMatchToMeAsStd (void)
|
|||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/************ Refresh number of players for a teacher via AJAX ***************/
|
||||
/****************** Refresh match for a teacher via AJAX *********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Gam_RefreshNumPlayersMatchTch (void)
|
||||
void Gam_RefreshMatchTch (void)
|
||||
{
|
||||
struct Match Match;
|
||||
|
||||
if (!Gbl.Session.IsOpen) // If session has been closed, do not write anything
|
||||
return;
|
||||
|
||||
/***** Get data of the match from database *****/
|
||||
Match.MchCod = Gbl.Games.MchCodBeingPlayed;
|
||||
Gam_GetDataOfMatchByCod (&Match);
|
||||
|
||||
/***** Get and show number of players *****/
|
||||
Gam_GetAndShowNumPlayersInMatch (Gbl.Games.MchCodBeingPlayed);
|
||||
Gam_GetAndShowNumPlayersInMatch (Match.MchCod);
|
||||
|
||||
/***** Update match as being played *****/
|
||||
if (Match.Status.BeingPlayed)
|
||||
Gam_UpdateMatchAsBeingPlayed (Match.MchCod);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*************** Refresh current game for a student via AJAX *****************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Gam_RefreshCurrentMatchStd (void)
|
||||
void Gam_RefreshMatchStd (void)
|
||||
{
|
||||
struct Match Match;
|
||||
|
||||
|
@ -3787,17 +3836,7 @@ static void Gam_ShowMatchStatusForStd (struct Match *Match)
|
|||
Gam_RemoveOldPlayers ();
|
||||
Gam_RegisterMeAsPlayerInMatch (Match->MchCod);
|
||||
|
||||
if (Match->Status.QstInd == 0) // Not yet started
|
||||
{
|
||||
fprintf (Gbl.F.Out,"<div class=\"GAM_PLAY_STD_WAIT_CONTAINER\">"
|
||||
"<img src=\"%s/wait.gif\""
|
||||
" alt=\"Please wait\" title=\"%s\""
|
||||
" class=\"GAM_PLAY_STD_WAIT_IMAGE\" />"
|
||||
"</div>",
|
||||
Cfg_URL_ICON_PUBLIC,
|
||||
"Por favor, espere a que el juego comience..."); // TODO: Need translation!!!!!
|
||||
}
|
||||
else
|
||||
if (Match->Status.BeingPlayed)
|
||||
{
|
||||
/***** Show question *****/
|
||||
/* Write number of question */
|
||||
|
@ -3894,6 +3933,13 @@ static void Gam_ShowMatchStatusForStd (struct Match *Match)
|
|||
|
||||
fprintf (Gbl.F.Out,"</div>");
|
||||
}
|
||||
else // Not being played
|
||||
fprintf (Gbl.F.Out,"<div class=\"GAM_PLAY_STD_WAIT_CONTAINER\">"
|
||||
"<img src=\"%s/wait.gif\""
|
||||
" alt=\"Please wait...\" title=\"Please wait...\"" // TODO: Need translation!!!!!
|
||||
" class=\"GAM_PLAY_STD_WAIT_IMAGE\" />"
|
||||
"</div>",
|
||||
Cfg_URL_ICON_PUBLIC);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -130,8 +130,8 @@ void Gam_ShowFinishedMatchResults (void);
|
|||
|
||||
void Gam_GetMatchBeingPlayed (void);
|
||||
void Gam_ShowMatchToMeAsStd (void);
|
||||
void Gam_RefreshNumPlayersMatchTch (void);
|
||||
void Gam_RefreshCurrentMatchStd (void);
|
||||
void Gam_RefreshMatchTch (void);
|
||||
void Gam_RefreshMatchStd (void);
|
||||
|
||||
void Gam_ReceiveQstAnsFromStd (void);
|
||||
|
||||
|
|
|
@ -684,6 +684,7 @@ static void Lay_WriteScriptInit (void)
|
|||
break;
|
||||
case ActNewMchTch:
|
||||
case ActResMchTch:
|
||||
case ActCurMchTch:
|
||||
case ActNxtMchTch:
|
||||
case ActPlyMchStd:
|
||||
case ActAnsMchQstStd:
|
||||
|
@ -800,15 +801,17 @@ static void Lay_WriteScriptParamsAJAX (void)
|
|||
Act_GetActCod (ActRefOldSocPubUsr),
|
||||
Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
|
||||
break;
|
||||
/* Parameters related with match refreshing */
|
||||
/* Parameters related with match refreshing (for teachers) */
|
||||
case ActNewMchTch:
|
||||
case ActResMchTch:
|
||||
case ActCurMchTch:
|
||||
case ActNxtMchTch:
|
||||
fprintf (Gbl.F.Out,"var RefreshParamNxtActGam = \"act=%ld\";\n"
|
||||
"var RefreshParamMchCod = \"MchCod=%ld\";\n",
|
||||
Act_GetActCod (ActRefMchTch),
|
||||
Gbl.Games.MchCodBeingPlayed);
|
||||
break;
|
||||
/* Parameters related with match refreshing (for students) */
|
||||
case ActPlyMchStd:
|
||||
case ActAnsMchQstStd:
|
||||
fprintf (Gbl.F.Out,"var RefreshParamNxtActGam = \"act=%ld\";\n"
|
||||
|
|
Loading…
Reference in New Issue