MCPcopy Create free account
hub / github.com/ddnet/ddnet / CanJoinTeam

Method CanJoinTeam

src/game/server/teams.cpp:384–444  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

382}
383
384bool CGameTeams::CanJoinTeam(int ClientId, int Team, char *pError, int ErrorSize) const
385{
386 int CurrentTeam = m_Core.Team(ClientId);
387
388 if(ClientId < 0 || ClientId >= MAX_CLIENTS)
389 {
390 str_format(pError, ErrorSize, "Invalid client ID: %d", ClientId);
391 return false;
392 }
393 if(!IsValidTeamNumber(Team) && Team != TEAM_SUPER)
394 {
395 str_format(pError, ErrorSize, "Invalid team number: %d", Team);
396 return false;
397 }
398 if(Team != TEAM_SUPER && m_aTeamState[Team] > ETeamState::OPEN && !m_aPractice[Team] && !m_aTeamFlock[Team])
399 {
400 str_copy(pError, "This team started already", ErrorSize);
401 return false;
402 }
403 if(CurrentTeam == Team)
404 {
405 str_copy(pError, "You are in this team already", ErrorSize);
406 return false;
407 }
408 if(!Character(ClientId))
409 {
410 str_copy(pError, "You can't change teams while you are dead/a spectator.", ErrorSize);
411 return false;
412 }
413 if(Team == TEAM_SUPER && !Character(ClientId)->IsSuper())
414 {
415 str_copy(pError, "You can't join super team if you don't have super rights", ErrorSize);
416 return false;
417 }
418 if(Team != TEAM_SUPER && Character(ClientId)->m_DDRaceState != ERaceState::NONE && (m_aTeamState[CurrentTeam] < ETeamState::FINISHED || Team != 0))
419 {
420 str_copy(pError, "You have started racing already", ErrorSize);
421 return false;
422 }
423 // No cheating through noob filter with practice and then leaving team
424 if(m_aPractice[CurrentTeam] && !m_pGameContext->PracticeByDefault())
425 {
426 str_copy(pError, "You have used practice mode already", ErrorSize);
427 return false;
428 }
429
430 // you can not join a team which is currently in the process of saving,
431 // because the save-process can fail and then the team is reset into the game
432 if(Team != TEAM_SUPER && GetSaving(Team))
433 {
434 str_copy(pError, "This team is currently saving", ErrorSize);
435 return false;
436 }
437 if(CurrentTeam != TEAM_SUPER && GetSaving(CurrentTeam))
438 {
439 str_copy(pError, "Your team is currently saving", ErrorSize);
440 return false;
441 }

Callers 1

OnSetTeamNetMessageMethod · 0.45

Calls 5

str_formatFunction · 0.85
PracticeByDefaultMethod · 0.80
str_copyFunction · 0.50
TeamMethod · 0.45
IsSuperMethod · 0.45

Tested by

no test coverage detected