GameServerWeb.LiveHelpers (game_server_web v1.0.941)

Copy Markdown

Shared helpers for LiveView rate limiting and client IP extraction.

Summary

Functions

Check a rate limit bucket for the given IP.

Extract the client IP from a LiveView socket's connect_info.

Functions

check_rate_limit(ip, bucket_type \\ :general)

Check a rate limit bucket for the given IP.

Bucket types:

  • :auth — 10 requests per 60 seconds (matches the HTTP auth bucket)
  • :general — 120 requests per 60 seconds

Returns :ok or {:error, retry_after_ms}.

client_ip(socket)

Extract the client IP from a LiveView socket's connect_info.

Falls back to "unknown" when the socket has no peer data (e.g. during the initial static render or in tests).