MegaAntiCheat / masterbase

API/Data Platform for Ingesting, Storing, and Serving Data through Postgres, and Litestar
11 stars 1 forks source link

Connecting to server without port triggers error #92

Open megascatterbomb opened 1 month ago

megascatterbomb commented 1 month ago

It is possible to connect to servers without specifying a port; doing so will default to 27015. When this occurs, the IP without port will be passed to masterbase/app.py L88 and fail because there is no : to split against.

This could also be fixed by forcing the client-backend to specify the port in the request, but to maximize compatibility with older versions of the client the masterbase should assume a default of 27015.

fake_ip = unquote(fake_ip)
if not fake_ip.startswith("169"):
    to_resolve, port = fake_ip.split(":") # fails here
    fake_ip = f"{resolve_hostname(to_resolve)}:{port}"
start_session_helper(engine, steam_id, str(_session_id), demo_name, fake_ip, map)
INFO:     172.18.0.1:58868 - "GET /session_id?api_key=REDACTED&fake_ip=114.23.117.138&map=vsh_distillery&demo_name=demo2024-09-23_13-03-21.dem HTTP/1.1" 500 Internal Server Error
ERROR - 2024-09-23 01:03:28,841 - app - app - Exception occurred!
Traceback (most recent call last):
  File "/home/.venv/lib/python3.11/site-packages/litestar/middleware/_internal/exceptions/middleware.py", line 159, in __call__
    await self.app(scope, receive, capture_response_started)
  File "/home/.venv/lib/python3.11/site-packages/litestar/_asgi/asgi_router.py", line 99, in __call__
    await asgi_app(scope, receive, send)
  File "/home/.venv/lib/python3.11/site-packages/litestar/routes/http.py", line 80, in handle
    response = await self._get_response_for_request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/.venv/lib/python3.11/site-packages/litestar/routes/http.py", line 132, in _get_response_for_request
    return await self._call_handler_function(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/.venv/lib/python3.11/site-packages/litestar/routes/http.py", line 152, in _call_handler_function
    response_data, cleanup_group = await self._get_response_data(
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/.venv/lib/python3.11/site-packages/litestar/routes/http.py", line 203, in _get_response_data
    data = route_handler.fn(**parsed_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/masterbase/app.py", line 88, in session_id
    to_resolve, port = fake_ip.split(":")
    ^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 2, got 1)