made server resend gameinfo just when it changed and fixed match counter

This commit is contained in:
oy 2012-08-03 18:46:57 +02:00
parent d61d25677b
commit f9427a3aa3
6 changed files with 43 additions and 38 deletions

View file

@ -588,7 +588,7 @@ void CGameContext::OnClientEnter(int ClientID)
for(int i = 0; i < MAX_CLIENTS; ++i)
{
if(i == ClientID || !Server()->ClientIngame(i))
if(i == ClientID || !m_apPlayers[i] || !Server()->ClientIngame(i))
continue;
// new info for others

View file

@ -38,9 +38,10 @@ IGameController::IGameController(CGameContext *pGameServer)
// info
m_GameFlags = 0;
m_pGameType = "unknown";
m_MatchNum = (str_length(g_Config.m_SvMaprotation) && g_Config.m_SvMatchesPerMap) ? g_Config.m_SvMatchesPerMap : 0;
m_ScoreLimit = g_Config.m_SvScorelimit;
m_TimeLimit = g_Config.m_SvTimelimit;
m_GameInfo.m_MatchCurrent = m_MatchCount+1;
m_GameInfo.m_MatchNum = (str_length(g_Config.m_SvMaprotation) && g_Config.m_SvMatchesPerMap) ? g_Config.m_SvMatchesPerMap : 0;
m_GameInfo.m_ScoreLimit = g_Config.m_SvScorelimit;
m_GameInfo.m_TimeLimit = g_Config.m_SvTimelimit;
// map
m_aMapWish[0] = 0;
@ -407,8 +408,8 @@ void IGameController::DoWincheckMatch()
if(IsTeamplay())
{
// check score win condition
if((m_ScoreLimit > 0 && (m_aTeamscore[TEAM_RED] >= m_ScoreLimit || m_aTeamscore[TEAM_BLUE] >= m_ScoreLimit)) ||
(m_TimeLimit > 0 && (Server()->Tick()-m_GameStartTick) >= m_TimeLimit*Server()->TickSpeed()*60))
if((m_GameInfo.m_ScoreLimit > 0 && (m_aTeamscore[TEAM_RED] >= m_GameInfo.m_ScoreLimit || m_aTeamscore[TEAM_BLUE] >= m_GameInfo.m_ScoreLimit)) ||
(m_GameInfo.m_TimeLimit > 0 && (Server()->Tick()-m_GameStartTick) >= m_GameInfo.m_TimeLimit*Server()->TickSpeed()*60))
{
if(m_aTeamscore[TEAM_RED] != m_aTeamscore[TEAM_BLUE] || m_GameFlags&GAMEFLAG_SURVIVAL)
EndMatch();
@ -436,8 +437,8 @@ void IGameController::DoWincheckMatch()
}
// check score win condition
if((m_ScoreLimit > 0 && Topscore >= m_ScoreLimit) ||
(m_TimeLimit > 0 && (Server()->Tick()-m_GameStartTick) >= m_TimeLimit*Server()->TickSpeed()*60))
if((m_GameInfo.m_ScoreLimit > 0 && Topscore >= m_GameInfo.m_ScoreLimit) ||
(m_GameInfo.m_TimeLimit > 0 && (Server()->Tick()-m_GameStartTick) >= m_GameInfo.m_TimeLimit*Server()->TickSpeed()*60))
{
if(TopscoreCount == 1)
EndMatch();
@ -456,10 +457,17 @@ void IGameController::ResetGame()
m_GameStartTick = Server()->Tick();
m_SuddenDeath = 0;
m_MatchNum = (str_length(g_Config.m_SvMaprotation) && g_Config.m_SvMatchesPerMap) ? g_Config.m_SvMatchesPerMap : 0;
m_ScoreLimit = g_Config.m_SvScorelimit;
m_TimeLimit = g_Config.m_SvTimelimit;
UpdateGameInfo(-1);
int MatchNum = (str_length(g_Config.m_SvMaprotation) && g_Config.m_SvMatchesPerMap) ? g_Config.m_SvMatchesPerMap : 0;
if(MatchNum == 0)
m_MatchCount = 0;
bool GameInfoChanged = (m_GameInfo.m_MatchCurrent != m_MatchCount+1) || (m_GameInfo.m_MatchNum != MatchNum) ||
(m_GameInfo.m_ScoreLimit != g_Config.m_SvScorelimit) || (m_GameInfo.m_TimeLimit != g_Config.m_SvTimelimit);
m_GameInfo.m_MatchCurrent = m_MatchCount+1;
m_GameInfo.m_MatchNum = MatchNum;
m_GameInfo.m_ScoreLimit = g_Config.m_SvScorelimit;
m_GameInfo.m_TimeLimit = g_Config.m_SvTimelimit;
if(GameInfoChanged)
UpdateGameInfo(-1);
// do team-balancing
DoTeamBalance();
@ -685,10 +693,10 @@ void IGameController::Snap(int SnappingClient)
return;
pGameInfo->m_GameFlags = m_GameFlags;
pGameInfo->m_ScoreLimit = m_ScoreLimit;
pGameInfo->m_TimeLimit = m_TimeLimit;
pGameInfo->m_MatchNum = m_MatchNum;
pGameInfo->m_MatchCurrent = m_MatchCount+1;
pGameInfo->m_ScoreLimit = m_GameInfo.m_ScoreLimit;
pGameInfo->m_TimeLimit = m_GameInfo.m_TimeLimit;
pGameInfo->m_MatchNum = m_GameInfo.m_MatchNum;
pGameInfo->m_MatchCurrent = m_GameInfo.m_MatchCurrent;
}
}
@ -726,8 +734,8 @@ void IGameController::Tick()
case IGS_END_MATCH:
// start next match
CycleMap();
StartMatch();
m_MatchCount++;
StartMatch();
break;
case IGS_WARMUP_GAME:
case IGS_GAME_RUNNING:
@ -835,31 +843,24 @@ const char *IGameController::GetTeamName(int Team) const
void IGameController::UpdateGameInfo(int ClientID)
{
CNetMsg_Sv_GameInfo GameInfoMsg;
GameInfoMsg.m_GameFlags = m_GameFlags;
GameInfoMsg.m_ScoreLimit = m_GameInfo.m_ScoreLimit;
GameInfoMsg.m_TimeLimit = m_GameInfo.m_TimeLimit;
GameInfoMsg.m_MatchNum = m_GameInfo.m_MatchNum;
GameInfoMsg.m_MatchCurrent = m_GameInfo.m_MatchCurrent;
if(ClientID == -1)
{
for(int i = 0; i < MAX_CLIENTS; ++i)
{
if(!GameServer()->m_apPlayers[i] || GameServer()->m_apPlayers[i]->IsDummy())
if(!GameServer()->m_apPlayers[i] || !Server()->ClientIngame(i))
continue;
GameInfoMsg.m_GameFlags = m_GameFlags;
GameInfoMsg.m_ScoreLimit = m_ScoreLimit;
GameInfoMsg.m_TimeLimit = m_TimeLimit;
GameInfoMsg.m_MatchNum = m_MatchNum;
GameInfoMsg.m_MatchCurrent = m_MatchCount+1;
Server()->SendPackMsg(&GameInfoMsg, MSGFLAG_VITAL|MSGFLAG_NORECORD, i);
}
}
else
{
GameInfoMsg.m_GameFlags = m_GameFlags;
GameInfoMsg.m_ScoreLimit = m_ScoreLimit;
GameInfoMsg.m_TimeLimit = m_TimeLimit;
GameInfoMsg.m_MatchNum = m_MatchNum;
GameInfoMsg.m_MatchCurrent = m_MatchCount+1;
Server()->SendPackMsg(&GameInfoMsg, MSGFLAG_VITAL|MSGFLAG_NORECORD, ClientID);
}
}
// map
@ -886,7 +887,7 @@ void IGameController::CycleMap()
if(!str_length(g_Config.m_SvMaprotation))
return;
if(m_MatchCount < m_MatchNum-1)
if(m_MatchCount < m_GameInfo.m_MatchNum-1)
{
if(g_Config.m_SvMatchSwap)
GameServer()->SwapTeams();

View file

@ -107,9 +107,13 @@ protected:
// info
int m_GameFlags;
const char *m_pGameType;
int m_MatchNum;
int m_ScoreLimit;
int m_TimeLimit;
struct CGameInfo
{
int m_MatchCurrent;
int m_MatchNum;
int m_ScoreLimit;
int m_TimeLimit;
} m_GameInfo;
void UpdateGameInfo(int ClientID);

View file

@ -88,8 +88,8 @@ bool CGameControllerCTF::OnEntity(int Index, vec2 Pos)
void CGameControllerCTF::DoWincheckMatch()
{
// check score win condition
if((m_ScoreLimit > 0 && (m_aTeamscore[TEAM_RED] >= m_ScoreLimit || m_aTeamscore[TEAM_BLUE] >= m_ScoreLimit)) ||
(m_TimeLimit > 0 && (Server()->Tick()-m_GameStartTick) >= m_TimeLimit*Server()->TickSpeed()*60))
if((m_GameInfo.m_ScoreLimit > 0 && (m_aTeamscore[TEAM_RED] >= m_GameInfo.m_ScoreLimit || m_aTeamscore[TEAM_BLUE] >= m_GameInfo.m_ScoreLimit)) ||
(m_GameInfo.m_TimeLimit > 0 && (Server()->Tick()-m_GameStartTick) >= m_GameInfo.m_TimeLimit*Server()->TickSpeed()*60))
{
if(m_SuddenDeath)
{

View file

@ -31,7 +31,7 @@ int CGameControllerLMS::OnCharacterDeath(CCharacter *pVictim, CPlayer *pKiller,
void CGameControllerLMS::DoWincheckRound()
{
// check for time based win
if(m_TimeLimit > 0 && (Server()->Tick()-m_GameStartTick) >= m_TimeLimit*Server()->TickSpeed()*60)
if(m_GameInfo.m_TimeLimit > 0 && (Server()->Tick()-m_GameStartTick) >= m_GameInfo.m_TimeLimit*Server()->TickSpeed()*60)
{
for(int i = 0; i < MAX_CLIENTS; ++i)
{

View file

@ -25,7 +25,7 @@ void CGameControllerSUR::DoWincheckRound()
++Count[GameServer()->m_apPlayers[i]->GetTeam()];
}
if(Count[TEAM_RED]+Count[TEAM_BLUE] == 0 || (m_TimeLimit > 0 && (Server()->Tick()-m_GameStartTick) >= m_TimeLimit*Server()->TickSpeed()*60))
if(Count[TEAM_RED]+Count[TEAM_BLUE] == 0 || (m_GameInfo.m_TimeLimit > 0 && (Server()->Tick()-m_GameStartTick) >= m_GameInfo.m_TimeLimit*Server()->TickSpeed()*60))
{
++m_aTeamscore[TEAM_BLUE];
++m_aTeamscore[TEAM_RED];