Implement comprehensive rate limiting system and item spawn configuration

Major Features Added:
- Complete token bucket rate limiting for IRC commands and web interface
- Per-user rate tracking with category-based limits (Basic, Gameplay, Management, Admin, Web)
- Admin commands for rate limit management (\!rate_stats, \!rate_user, \!rate_unban, \!rate_reset)
- Automatic violation tracking and temporary bans with cleanup
- Global item spawn multiplier system with 75% spawn rate reduction
- Central admin configuration system (config.py)
- One-command bot startup script (start_petbot.sh)

Rate Limiting:
- Token bucket algorithm with burst capacity and refill rates
- Category limits: Basic (20/min), Gameplay (10/min), Management (5/min), Web (60/min)
- Graceful violation handling with user-friendly error messages
- Admin exemption and override capabilities
- Background cleanup of old violations and expired bans

Item Spawn System:
- Added global_spawn_multiplier to config/items.json for easy adjustment
- Reduced all individual spawn rates by 75% (multiplied by 0.25)
- Admins can fine-tune both global multiplier and individual item rates
- Game engine integration applies multiplier to all spawn calculations

Infrastructure:
- Single admin user configuration in config.py
- Enhanced startup script with dependency management and verification
- Updated documentation and help system with rate limiting guide
- Comprehensive test suite for rate limiting functionality

Security:
- Rate limiting protects against command spam and abuse
- IP-based tracking for web interface requests
- Proper error handling and status codes (429 for rate limits)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
megaproxy 2025-07-15 20:10:43 +00:00
parent f8ac661cd1
commit 915aa00bea
28 changed files with 5730 additions and 57 deletions

View file

@ -365,6 +365,9 @@ class GameEngine:
except FileNotFoundError:
return None
# Get global spawn multiplier from config
global_multiplier = items_data.get("_config", {}).get("global_spawn_multiplier", 1.0)
# Get all possible items for this location
available_items = []
location_name = location["name"].lower().replace(" ", "_")
@ -375,22 +378,25 @@ class GameEngine:
if "locations" in item:
item_locations = item["locations"]
if "all" in item_locations or location_name in item_locations:
available_items.append(item)
# Apply global multiplier to spawn rate
item_copy = item.copy()
item_copy["effective_spawn_rate"] = item.get("spawn_rate", 0.1) * global_multiplier
available_items.append(item_copy)
if not available_items:
return None
# Calculate total spawn rates for this location
total_rate = sum(item.get("spawn_rate", 0.1) for item in available_items)
# Calculate total spawn rates for this location (using effective rates)
total_rate = sum(item.get("effective_spawn_rate", 0.1) for item in available_items)
# 30% base chance of finding an item
if random.random() > 0.3:
return None
# Choose item based on spawn rates
# Choose item based on effective spawn rates (with global multiplier applied)
chosen_item = random.choices(
available_items,
weights=[item.get("spawn_rate", 0.1) for item in available_items]
weights=[item.get("effective_spawn_rate", 0.1) for item in available_items]
)[0]
# Add item to player's inventory