Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: disable join button in online players window when the company is an AI #9369

Merged

Conversation

SamuXarick
Copy link
Contributor

@SamuXarick SamuXarick commented Jun 13, 2021

Motivation / Problem

In the Online Players window, the Join Company button is displayed for AI companies. Clicking on it as an admin would move the admin to that company. Clicking on it as a client does send a command over the network only to be forbidden to be joined.

Description

This fix disables the Join Company button for AI companies.

Limitations

I am assuming the company_id exists at that point. If the company doesn't exist, Company::Get(company_id) is gonna crash

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@@ -1894,7 +1894,7 @@ struct NetworkClientListWindow : Window {

if (_network_server) this->buttons[line_count].emplace_back(new CompanyButton(SPR_ADMIN, STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_TOOLTIP, COLOUR_RED, company_id, &NetworkClientListWindow::OnClickCompanyAdmin, company_id == COMPANY_SPECTATOR));
this->buttons[line_count].emplace_back(chat_button);
if (own_ci->client_playas != company_id) this->buttons[line_count].emplace_back(new CompanyButton(SPR_JOIN, STR_NETWORK_CLIENT_LIST_JOIN_TOOLTIP, COLOUR_ORANGE, company_id, &NetworkClientListWindow::OnClickCompanyJoin));
if (own_ci->client_playas != company_id && (company_id == COMPANY_SPECTATOR || !Company::Get(company_id)->is_ai)) this->buttons[line_count].emplace_back(new CompanyButton(SPR_JOIN, STR_NETWORK_CLIENT_LIST_JOIN_TOOLTIP, COLOUR_ORANGE, company_id, &NetworkClientListWindow::OnClickCompanyJoin));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you mention yourself, admins can join it just fine. So I guess we should add that exception in here too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

join console command doesn't allow joining AI company, even for admins.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is just hateful. What did the console ever do to the admins? Tssk.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some talk on IRC, lets disable it instead of removing. That is simply moving this change, as CompanyButton has an additional parameter to indicate disabled state. See line 1895 for an example.

@SamuXarick SamuXarick force-pushed the disallow-admin-to-join-ai-companies branch from 3e343ba to cbed44f Compare June 15, 2021 10:47
@SamuXarick SamuXarick changed the title Fix: don't show join button in online players window when the company is an AI Fix: disable join button in online players window when the company is an AI Jun 15, 2021
@TrueBrain TrueBrain merged commit d0bcb98 into OpenTTD:master Jun 15, 2021
@SamuXarick SamuXarick deleted the disallow-admin-to-join-ai-companies branch June 15, 2021 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants