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

Wip: SS Central - whitelist, discord link #946

Open
wants to merge 40 commits into
base: master
Choose a base branch
from

Conversation

Furrior
Copy link
Collaborator

@Furrior Furrior commented Dec 31, 2024

Что этот PR делает

fixes #191 #65 #66

Почему это хорошо для игры

  • Игрокам проще привязывать дискорд так
  • Возможность иметь разные вайтлисты, не привязанные к порту

Изображения изменений

Тестирование

  • Привязка дс работает
  • Выдача вайтлиста через интервью работает

Changelog

🆑
add: Привязка дискорда через OAuth
tweak: Новая система белого списка
/:cl:

Summary by Sourcery

Implement Discord link via OAuth and a new whitelist system that uses SS Central.

New Features:

  • Players can now link their Discord accounts.
  • A new whitelist system is implemented, integrating with SS Central.

Tests:

  • Removed tests related to the old whitelist system.

Summary by Sourcery

Update the whitelist system to use SS Central, add Discord account linking via OAuth, and implement a blocking HTTP request method.

New Features:

  • Players can now link their Discord accounts via OAuth.
  • Implemented a new whitelist system that integrates with SS Central.

Tests:

  • Removed tests related to the old whitelist system.

Copy link

sourcery-ai bot commented Dec 31, 2024

Reviewer's Guide by Sourcery

This pull request implements two major features: linking Discord accounts via OAuth and integrating a new whitelist system using SS Central. In addition, it refactors HTTP request logging, updates donation level logic, and removes legacy code related to the old whitelist and donation systems.

Class Diagram for SScentral Subsystem

classDiagram
    class SScentral {
      +list discord_links
      +load_whitelist()
      +load_whitelist_callback(response)
      +get_player_discord_async(player)
      +get_player_discord_callback(player, response)
      +is_player_discord_linked(player)
      +is_player_whitelisted(ckey)
      +add_to_whitelist(ckey, added_by, duration_days)
      +whitelist_ban_player(ckey, admin, duration_days, reason)
      +verify_in_discord(player)
      +verify_in_discord_callback(player, response)
      +update_player_donate_tier_async(player)
      +update_player_donate_tier_callback(player, response)
      +get_player_donate_tier_blocking(player)
    }

    note for SScentral "Handles Discord link, whitelist, and donation tier updates via HTTP requests"

    class SSHttp {
      +create_async_request(method, endpoint, body, headers, callback)
      +make_blocking_request(method, endpoint, body, headers)
      +log_request(req)
      +log_response(res, id)
    }

    SScentral --> SSHttp : uses

    class GLOB {
      <<singleton>>
      +whitelist: list
    }
    SScentral ..> GLOB : updates whitelist entries

    %% End of SScentral class structure
Loading

File-Level Changes

Change Details Files
Refactored HTTP request handling and logging.
  • Extracted and centralized HTTP logging functionality into log_request and log_response procs.
  • Modified asynchronous and blocking HTTP request functions to use the new logging methods.
  • Replaced inline logging code with calls to the new logging procedures.
modular_bandastation/tts/code/SSHttp.dm
Updated client donation level logic and removed outdated database queries.
  • Replaced the old get_donator_level_from_db function with a simplified admin-based lookup.
  • Redefined donation level constants and updated related procedures for determining donator level.
  • Removed obsolete tier calculation and cooldown logic.
modular_bandastation/loadout/code/client.dm
Improved Discord account linking functionality.
  • Implemented linking of Discord accounts via OAuth in the new discord_link module.
  • Removed legacy client-side Discord verification code and updated UI messaging.
  • Updated display text and descriptions in the Discord configuration to simplify user experience.
modular_bandastation/discord/code/discord.dm
modular_bandastation/discord/_discord.dm
modular_bandastation/metaserver/code/discord_link.dm
Integrated SS Central for whitelist management and additional features.
  • Added a new SS Central subsystem handling whitelist loading, player Discord data retrieval, and donation tier updates.
  • Introduced procedures for adding to the whitelist, banning players from it, and verifying Discord linkage via SS Central endpoints.
  • Implemented new interview workflow modifications that leverage SS Central for whitelist verification.
  • Provided admin tooling for whitelist bans and cleaned up legacy whitelist modules.
modular_bandastation/metaserver/code/ss_central.dm
modular_bandastation/metaserver/code/interview.dm
modular_bandastation/metaserver/code/admin.dm
modular_bandastation/metaserver/_metaserver.dm
modular_bandastation/metaserver/code/donate.dm
modular_bandastation/whitelist220/_whitelist220.dm
modular_bandastation/whitelist220/_whitelist220.dme
modular_bandastation/whitelist220/code/whitelist220.dm

Assessment against linked issues

Issue Objective Addressed Explanation
#191 Implement Discord account linking functionality
#191 Create a new whitelist system integrated with SS Central

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions bot added the 💾 Изменение конфига Ф-ф-фуриор...? label Dec 31, 2024
@Furrior Furrior linked an issue Dec 31, 2024 that may be closed by this pull request
@Furrior
Copy link
Collaborator Author

Furrior commented Jan 1, 2025

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Furrior - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • The 'req' variable is undefined in this scope. This will cause runtime errors when logging responses. (link)

Overall Comments:

  • The make_blocking_request() implementation using UNTIL is dangerous and could cause server hangs/deadlocks. Consider making this fully asynchronous instead.
Here's what I looked at during the review
  • 🔴 General issues: 1 blocking issue, 1 other issue
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

modular_bandastation/tts/code/SSHttp.dm Outdated Show resolved Hide resolved
config/bandastation/bandastation_config.txt Show resolved Hide resolved
@Furrior
Copy link
Collaborator Author

Furrior commented Jan 1, 2025

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Furrior - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Hardcoded SS_CENTRAL_TOKEN found. (link)

Overall Comments:

  • The blocking HTTP request using UNTIL is dangerous and could freeze the game if the request hangs. Consider using async requests consistently throughout the codebase.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🔴 Security: 1 blocking issue
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

modular_bandastation/tts/code/SSHttp.dm Show resolved Hide resolved
modular_bandastation/tts/code/SSHttp.dm Outdated Show resolved Hide resolved
modular_bandastation/tts/code/SSHttp.dm Outdated Show resolved Hide resolved
config/bandastation/bandastation_config.txt Outdated Show resolved Hide resolved
@Furrior Furrior marked this pull request as ready for review January 1, 2025 09:15
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Furrior - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Hardcoded SS_CENTRAL_TOKEN found. (link)

Overall Comments:

  • The make_blocking_request() method using UNTIL is dangerous and could cause deadlocks. Consider making this fully async or adding additional safeguards if blocking behavior is absolutely required.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🔴 Security: 1 blocking issue
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

modular_bandastation/tts/code/SSHttp.dm Outdated Show resolved Hide resolved
config/bandastation/bandastation_config.txt Outdated Show resolved Hide resolved
@Furrior Furrior requested a review from Gaxeer January 1, 2025 09:21
@Furrior Furrior marked this pull request as ready for review February 1, 2025 20:50
@ss220app ss220app bot added the 📜 CL невалиден Этот чейнджлог не пройдет валидацию перед публикацией. Исправить или удалить, если не требуется label Feb 1, 2025
@Furrior
Copy link
Collaborator Author

Furrior commented Feb 4, 2025

Надо добавить поддержк донатов и чтоб тесты не падали, когда централ отключен

@Furrior Furrior marked this pull request as draft February 4, 2025 11:51
@Furrior Furrior marked this pull request as ready for review February 7, 2025 12:08
@Furrior
Copy link
Collaborator Author

Furrior commented Feb 7, 2025

Бля, ну, вроде, работает

var/list/data = json_decode(response.body)
var/login_endpoint = "[CONFIG_GET(string/ss_central_url)]/player/login?token=[data]"

to_chat(player, boxed_message("Авторизуйтесь в открывшемся окне и ожидайте 30 секунд.<br/>Если окно не открывается, можете открыть ссылку в браузере самостоятельно:<br/><a href='[login_endpoint]'>[login_endpoint]</a>."))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
to_chat(player, boxed_message("Авторизуйтесь в открывшемся окне и ожидайте 30 секунд.<br/>Если окно не открывается, можете открыть ссылку в браузере самостоятельно:<br/><a href='[login_endpoint]'>[login_endpoint]</a>."))
to_chat(player, boxed_message("Авторизуйтесь в открывшемся окне и ожидайте 30 секунд.<br/>Если окно не открывается, можете открыть ссылку в браузере самостоятельно:<br/><a href='[login_endpoint]'>Привязать дискорд.</a>."))


/// WARNING: only semi async - UNTIL based
/datum/controller/subsystem/central/proc/is_player_whitelisted(ckey)
. = (ckey in GLOB.whitelist)
Copy link
Collaborator

@Gaxeer Gaxeer Feb 7, 2025

Choose a reason for hiding this comment

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

не совсем понял зачем это, если ты всё равно делаешь запрос в любом случае, и если запрос зафейлен, то возвращаешь FALSE.

Copy link
Collaborator

@Gaxeer Gaxeer left a comment

Choose a reason for hiding this comment

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

Небольшие замечания написал, а в целом заебись всё сделано

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💾 Изменение конфига Ф-ф-фуриор...? 📜 CL невалиден Этот чейнджлог не пройдет валидацию перед публикацией. Исправить или удалить, если не требуется 🛡️ Stale Exempt ПР не может быть устаревшим. Но всем всё равно на него похуй.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Привязка Дискорда Синхронизировать бд
4 participants