Add remote stats + player functionality via BisectHosting StarbaseAPI#1
Add remote stats + player functionality via BisectHosting StarbaseAPI#1ImKringle wants to merge 7 commits intoMinidoracat:mainfrom
Conversation
Summary of ChangesHello @ImKringle, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the bot's flexibility by introducing an optional integration with the Bisect Hosting Starbase API. This allows the bot to operate more effectively in environments where direct local file access or system resource monitoring might be restricted, such as on managed game hosting platforms. By leveraging the Bisect API, the bot can now remotely retrieve player connection logs and server resource metrics, providing a more versatile and robust solution for server status reporting. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds optional integration with the BisectHosting Starbase API to fetch server statistics and player logs remotely. However, a potential Denial of Service (DoS) vulnerability was identified in the way remote log files are handled, as the bot currently downloads and processes entire log files in memory, which could lead to memory exhaustion. Additionally, the implementation could benefit from improvements in maintainability by removing code duplication and hardcoded values, and enhanced robustness through more specific exception handling.
| except Exception: | ||
| starbase_stats = None |
There was a problem hiding this comment.
Catching a broad Exception can hide unexpected errors and make debugging difficult. It's better to catch more specific exceptions that you expect from the network request, such as requests.exceptions.RequestException. This will prevent the bot from silently ignoring other unrelated errors. This also applies to the try...except block in _format_starbase_resources on line 296.
| def _read_remote_full(self) -> list[str]: | ||
| """遠端抓取完整檔案內容(Starbase),並回傳行列表。""" | ||
| try: | ||
| raw = self._starbase_fetcher() if self._starbase_fetcher else "" | ||
| except Exception as e: | ||
| logger.error("Failed to fetch remote PlayerConnectedLog via Starbase: %s", e) | ||
| return [] | ||
| if not raw: | ||
| return [] | ||
| # 直接解析全檔內容,不做 tail(避免遺漏) | ||
| normalized = raw.replace("\r\n", "\n").replace("\r", "\n") | ||
| return [line for line in normalized.split("\n") if line] |
There was a problem hiding this comment.
The _read_remote_full method currently fetches and processes entire PlayerConnectedLog.txt files into memory. This poses a significant Denial of Service (DoS) vulnerability, as large log files could lead to memory exhaustion and bot crashes, especially given the frequent update cycle. An attacker could exacerbate this by rapidly increasing log size. It is crucial to implement a more memory-efficient approach, such as using an API endpoint that supports tailing or range requests, or processing the log file via streaming to avoid loading the entire content into memory. Furthermore, the current broad Exception catch can mask specific network-related issues; consider handling more specific exceptions like requests.exceptions.RequestException for robust error management.
| server_id = settings.starbase_id | ||
|
|
||
| def _fetch_remote_log() -> str: | ||
| url = f"https://games.bisecthosting.com/api/client/servers/{server_id}/files/contents" |
| def _fetch_remote_log() -> str: | ||
| url = f"https://games.bisecthosting.com/api/client/servers/{server_id}/files/contents" | ||
| headers = {"Authorization": f"Bearer {token}"} | ||
| params = {"file": "HumanitZServer/PlayerConnectedLog.txt"} |
| url = f"https://games.bisecthosting.com/api/client/servers/{server_id}/files/contents" | ||
| headers = {"Authorization": f"Bearer {token}"} | ||
| params = {"file": "HumanitZServer/PlayerConnectedLog.txt"} | ||
| import requests |
| self._use_starbase_stats: bool = bool( | ||
| getattr(settings, "starbase_token", None) and getattr(settings, "starbase_id", None) | ||
| ) |
There was a problem hiding this comment.
| mem_str = f"{mem_bytes/1024/1024/1024:.2f} GB" | ||
| disk_str = f"{disk_bytes/1024/1024/1024:.2f} GB" |
There was a problem hiding this comment.
The value for converting bytes to gigabytes is calculated inline using division. To improve readability and maintainability, it's better to use exponentiation (1024**3) and ideally define this as a constant (e.g., _BYTES_PER_GB = 1024**3) at the module level.
| mem_str = f"{mem_bytes/1024/1024/1024:.2f} GB" | |
| disk_str = f"{disk_bytes/1024/1024/1024:.2f} GB" | |
| mem_str = f"{mem_bytes / (1024**3):.2f} GB" | |
| disk_str = f"{disk_bytes / (1024**3):.2f} GB" |
|
Hey @ImKringle, thanks for putting this together! The Starbase API integration is a great idea — it fills a real gap for Bisect users who don't have local file access. The docs updates (both languages!) and backward compatibility are appreciated. I've done a thorough review and have some feedback below. I've split it into must-fix items (blocking merge) and suggestions (nice-to-have, can be addressed later). 🔴 Must Fix (Blocking)1. 2. # server_status.py — _fetch_starbase_resources()
assert settings.starbase_token and settings.starbase_idPython's if not settings.starbase_token or not settings.starbase_id:
raise RuntimeError("Starbase credentials not configured")3. Silent exception swallowing (no logging) except Exception:
starbase_stats = None # completely silentWhen the Starbase API returns 401/403/500/timeout, there's zero indication in logs. This makes debugging nearly impossible. 4. Unused imports in from typing import Callable, Awaitable, Optional # Awaitable is unused
import requests # never used in this file→ Remove 5. 6. # Before
starbase_fetcher: Optional[Callable[[], str]] = None
# After
starbase_fetcher: Callable[[], str] | None = NoneAnd you can drop the 7. if getattr(settings, "starbase_token", None) and getattr(settings, "starbase_id", None):Since you've added if settings.starbase_token and settings.starbase_id:8. Starbase tokens should have placeholder validation 💡 Suggestions (Non-blocking)These are improvements I'd recommend but they don't need to be in this PR:
Overall this is a solid first contribution with a clear use case. Once the blocking items above are addressed, I'd be happy to merge. Let me know if you have any questions! 🙌 |
Saw this in the Discord for HumanitZ and figured I'd add a method for the Bisect users to use this as well, as the Players/Stats are able to be derived from specific endpoints at https://games.bisecthosting.com/docs :
Changes:
Notes:
Testing:
Apologies if any comments for ZH are inaccurate, not fluent so AI handled those. Feel free to fix them so they actually read accurately 😅