Skip to content

Commit 4b299f1

Browse files
committed
Only show joinable teams in the team picker
1 parent 090f82d commit 4b299f1

6 files changed

Lines changed: 89 additions & 8 deletions

File tree

‎include/StartupInfo.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class StartupInfo
3030

3131
bool hasConfiguration;
3232
bool autoConnect;
33+
char serverAllowedTeams[7];
3334
char serverName[80];
3435
int serverPort;
3536
bool useUDPconnection;

‎src/bzflag/JoinMenu.cxx‎

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,18 @@ JoinMenu::JoinMenu() : serverStartMenu(NULL), serverMenu(NULL)
8080
std::vector<std::string>& teams = team->getList();
8181
// these do not need to be in enum order, but must match getTeam() & setTeam()
8282
teams.push_back(std::string(Team::getName(AutomaticTeam)));
83-
teams.push_back(std::string(Team::getName(RogueTeam)));
84-
teams.push_back(std::string(Team::getName(RedTeam)));
85-
teams.push_back(std::string(Team::getName(GreenTeam)));
86-
teams.push_back(std::string(Team::getName(BlueTeam)));
87-
teams.push_back(std::string(Team::getName(PurpleTeam)));
88-
teams.push_back(std::string(Team::getName(ObserverTeam)));
83+
if(info->serverAllowedTeams[0] == '1')
84+
teams.push_back(std::string(Team::getName(RogueTeam)));
85+
if(info->serverAllowedTeams[1] == '1')
86+
teams.push_back(std::string(Team::getName(RedTeam)));
87+
if(info->serverAllowedTeams[2] == '1')
88+
teams.push_back(std::string(Team::getName(GreenTeam)));
89+
if(info->serverAllowedTeams[3] == '1')
90+
teams.push_back(std::string(Team::getName(BlueTeam)));
91+
if(info->serverAllowedTeams[4] == '1')
92+
teams.push_back(std::string(Team::getName(PurpleTeam)));
93+
if(info->serverAllowedTeams[5] == '1')
94+
teams.push_back(std::string(Team::getName(ObserverTeam)));
8995
team->update();
9096
setTeam(info->team);
9197
listHUD.push_back(team);
@@ -161,7 +167,26 @@ void JoinMenu::show()
161167
// set fields
162168
callsign->setString(info->callsign);
163169
password->setString(info->password);
170+
{
171+
std::vector<std::string>& teams = team->getList();
172+
teams.clear();
173+
teams.push_back(std::string(Team::getName(AutomaticTeam)));
174+
if (info->serverAllowedTeams[0] == '1')
175+
teams.push_back(std::string(Team::getName(RogueTeam)));
176+
if (info->serverAllowedTeams[1] == '1')
177+
teams.push_back(std::string(Team::getName(RedTeam)));
178+
if (info->serverAllowedTeams[2] == '1')
179+
teams.push_back(std::string(Team::getName(GreenTeam)));
180+
if (info->serverAllowedTeams[3] == '1')
181+
teams.push_back(std::string(Team::getName(BlueTeam)));
182+
if (info->serverAllowedTeams[4] == '1')
183+
teams.push_back(std::string(Team::getName(PurpleTeam)));
184+
if (info->serverAllowedTeams[5] == '1')
185+
teams.push_back(std::string(Team::getName(ObserverTeam)));
186+
team->update();
187+
}
164188
setTeam(info->team);
189+
updateTeamTexture();
165190

166191
server->setString(info->serverName);
167192
char buffer[10];
@@ -273,12 +298,27 @@ void JoinMenu::setFailedMessage(const char* msg)
273298

274299
TeamColor JoinMenu::getTeam() const
275300
{
276-
return team->getIndex() == 0 ? AutomaticTeam : TeamColor(team->getIndex() - 1);
301+
const int idx = team->getIndex();
302+
const std::vector<std::string> &list = team->getList();
303+
if (idx < 0 || idx >= (int)list.size())
304+
return AutomaticTeam;
305+
return Team::getTeam(list[idx]);
277306
}
278307

279308
void JoinMenu::setTeam(TeamColor teamcol)
280309
{
281-
team->setIndex(teamcol == AutomaticTeam ? 0 : int(teamcol) + 1);
310+
const std::string want = Team::getName(teamcol);
311+
const std::vector<std::string> &list = team->getList();
312+
for (size_t i = 0; i < list.size(); ++i)
313+
{
314+
if (list[i] == want)
315+
{
316+
team->setIndex((int)i);
317+
return;
318+
}
319+
}
320+
// fallback to Automatic if not found
321+
team->setIndex(0);
282322
}
283323

284324
void JoinMenu::setStatus(const char* msg, const std::vector<std::string> *)

‎src/bzflag/ServerMenu.cxx‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
const int ServerMenu::NumReadouts = 24;
3434
const int ServerMenu::NumItems = 10;
3535

36+
char ServerMenu::JoinableTeams[7] = { '1','1','1','1','1','1', '\0' };
37+
3638
ServerMenuDefaultKey::~ServerMenuDefaultKey()
3739
{
3840
delete serverListFilterMenu;
@@ -552,6 +554,11 @@ void ServerMenu::pick()
552554
char buf[60];
553555
std::vector<HUDuiControl*>& listHUD = getControls();
554556

557+
// reset JoinableTeams
558+
for (int i = 0; i < 6; ++i)
559+
JoinableTeams[i] = '1';
560+
JoinableTeams[6] = '\0';
561+
555562
const uint8_t maxes [] = { ping.maxPlayers, ping.rogueMax, ping.redMax, ping.greenMax,
556563
ping.blueMax, ping.purpleMax, ping.observerMax
557564
};
@@ -572,47 +579,65 @@ void ServerMenu::pick()
572579
((HUDuiLabel*)listHUD[1])->setLabel(buf);
573580

574581
if (ping.rogueMax == 0)
582+
{
575583
buf[0]=0;
584+
JoinableTeams[0]='0';
585+
}
576586
else if (ping.rogueMax >= ping.maxPlayers)
577587
sprintf(buf, "%d", ping.rogueCount);
578588
else
579589
sprintf(buf, "%d/%d", ping.rogueCount, ping.rogueMax);
580590
((HUDuiLabel*)listHUD[2])->setLabel(buf);
581591

582592
if (ping.redMax == 0)
593+
{
583594
buf[0]=0;
595+
JoinableTeams[1]='0';
596+
}
584597
else if (ping.redMax >= ping.maxPlayers)
585598
sprintf(buf, "%d", ping.redCount);
586599
else
587600
sprintf(buf, "%d/%d", ping.redCount, ping.redMax);
588601
((HUDuiLabel*)listHUD[3])->setLabel(buf);
589602

590603
if (ping.greenMax == 0)
604+
{
591605
buf[0]=0;
606+
JoinableTeams[2]='0';
607+
}
592608
else if (ping.greenMax >= ping.maxPlayers)
593609
sprintf(buf, "%d", ping.greenCount);
594610
else
595611
sprintf(buf, "%d/%d", ping.greenCount, ping.greenMax);
596612
((HUDuiLabel*)listHUD[4])->setLabel(buf);
597613

598614
if (ping.blueMax == 0)
615+
{
599616
buf[0]=0;
617+
JoinableTeams[3]='0';
618+
}
600619
else if (ping.blueMax >= ping.maxPlayers)
601620
sprintf(buf, "%d", ping.blueCount);
602621
else
603622
sprintf(buf, "%d/%d", ping.blueCount, ping.blueMax);
604623
((HUDuiLabel*)listHUD[5])->setLabel(buf);
605624

606625
if (ping.purpleMax == 0)
626+
{
607627
buf[0]=0;
628+
JoinableTeams[4]='0';
629+
}
608630
else if (ping.purpleMax >= ping.maxPlayers)
609631
sprintf(buf, "%d", ping.purpleCount);
610632
else
611633
sprintf(buf, "%d/%d", ping.purpleCount, ping.purpleMax);
612634
((HUDuiLabel*)listHUD[6])->setLabel(buf);
613635

614636
if (ping.observerMax == 0)
637+
{
615638
buf[0]=0;
639+
JoinableTeams[5]='0';
640+
}
616641
else if (ping.observerMax >= ping.maxPlayers)
617642
sprintf(buf, "%d", ping.observerCount);
618643
else
@@ -810,6 +835,8 @@ void ServerMenu::execute()
810835
info->serverName[sizeof(info->serverName) - 1] = '\0';
811836
info->serverPort = ntohs((unsigned short)
812837
serverList.getServers()[selectedIndex].ping.serverId.port);
838+
strncpy(info->serverAllowedTeams, JoinableTeams, sizeof(info->serverAllowedTeams) - 1);
839+
info->serverAllowedTeams[sizeof(info->serverAllowedTeams) - 1] = '\0';
813840

814841
// all done
815842
HUDDialogStack::get()->pop();

‎src/bzflag/ServerMenu.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class ServerMenu final : public HUDDialog
6464
{
6565
return &defaultKey;
6666
}
67+
6768
int getSelected() const;
6869
void setSelected(int, bool forcerefresh=false);
6970
void show() override;
@@ -114,6 +115,8 @@ class ServerMenu final : public HUDDialog
114115
int lastWidth, lastHeight;
115116

116117
static const int NumReadouts;
118+
119+
static char JoinableTeams[7];
117120
};
118121

119122

‎src/bzflag/bzflag.cxx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ void dumpResources()
610610

611611
BZDB.set("team", Team::getName(startupInfo.team));
612612
BZDB.set("server", startupInfo.serverName);
613+
BZDB.set("serverAllowedTeams", startupInfo.serverAllowedTeams);
613614
if (startupInfo.serverPort != ServerPort)
614615
BZDB.set("port", TextUtils::format("%d", startupInfo.serverPort));
615616
else
@@ -837,6 +838,13 @@ int main(int argc, char** argv)
837838
sizeof(startupInfo.serverName) - 1);
838839
startupInfo.serverName[sizeof(startupInfo.serverName) - 1] = '\0';
839840
}
841+
if (BZDB.isSet("serverAllowedTeams"))
842+
{
843+
// Flawfinder: ignore
844+
strncpy(startupInfo.serverAllowedTeams, BZDB.get("serverAllowedTeams").c_str(),
845+
sizeof(startupInfo.serverAllowedTeams) - 1);
846+
startupInfo.serverAllowedTeams[sizeof(startupInfo.serverAllowedTeams) - 1] = '\0';
847+
}
840848
if (BZDB.isSet("port"))
841849
startupInfo.serverPort = atoi(BZDB.get("port").c_str());
842850

‎src/game/StartupInfo.cxx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ StartupInfo::StartupInfo() : hasConfiguration(false),
2727
listServerURL(DefaultListServerURL),
2828
listServerPort(ServerPort + 1)
2929
{
30+
strcpy(serverAllowedTeams, "111111");
3031
strcpy(serverName, "");
3132
strcpy(callsign, "");
3233
strcpy(password, "");
@@ -39,6 +40,7 @@ StartupInfo::~StartupInfo()
3940
{
4041
hasConfiguration = false;
4142
autoConnect = false;
43+
memset(serverAllowedTeams, 0, 7);
4244
memset(serverName, 0, 80);
4345
serverPort = -1;
4446
useUDPconnection = false;

0 commit comments

Comments
 (0)