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

@ -504,6 +504,75 @@
</div>
</div>
<div class="section">
<div class="section-header">⚡ Rate Limiting & Fair Play</div>
<div class="section-content">
<div class="info-box">
<h4>🛡️ Rate Limiting System</h4>
<p>PetBot uses a sophisticated rate limiting system to ensure fair play and prevent spam. Commands are organized into categories with different limits:</p>
<ul>
<li><strong>Basic Commands</strong> (!help, !ping, !status) - 20 per minute, 5 burst capacity</li>
<li><strong>Gameplay Commands</strong> (!explore, !battle, !catch) - 10 per minute, 3 burst capacity</li>
<li><strong>Management Commands</strong> (!pets, !activate, !stats) - 5 per minute, 2 burst capacity</li>
<li><strong>Web Interface</strong> - 60 requests per minute, 10 burst capacity</li>
</ul>
</div>
<div class="info-box">
<h4>📊 How It Works</h4>
<ul>
<li><strong>Token Bucket Algorithm</strong> - You have a "bucket" of tokens that refills over time</li>
<li><strong>Burst Capacity</strong> - You can use multiple commands quickly up to the burst limit</li>
<li><strong>Refill Rate</strong> - Tokens refill based on the requests per minute limit</li>
<li><strong>Cooldown Period</strong> - Brief cooldown after hitting limits before trying again</li>
</ul>
</div>
<div class="info-box">
<h4>⚠️ Violations & Penalties</h4>
<ul>
<li><strong>3 violations</strong> - Warning threshold reached (logged)</li>
<li><strong>10 violations</strong> - Temporary 5-minute ban from all commands</li>
<li><strong>Admin Override</strong> - Admins can unban users and reset violations</li>
<li><strong>Automatic Cleanup</strong> - Old violations and bans are automatically cleared</li>
</ul>
</div>
<div class="command-grid">
<div class="command">
<div class="command-name">!rate_stats</div>
<div class="command-desc">View global rate limiting statistics (Admin only).</div>
<div class="command-example">Example: !rate_stats</div>
</div>
<div class="command">
<div class="command-name">!rate_user &lt;username&gt;</div>
<div class="command-desc">Check rate limiting status for a specific user (Admin only).</div>
<div class="command-example">Example: !rate_user playername</div>
</div>
<div class="command">
<div class="command-name">!rate_unban &lt;username&gt;</div>
<div class="command-desc">Manually unban a user from rate limiting (Admin only).</div>
<div class="command-example">Example: !rate_unban playername</div>
</div>
<div class="command">
<div class="command-name">!rate_reset &lt;username&gt;</div>
<div class="command-desc">Reset violations for a user (Admin only).</div>
<div class="command-example">Example: !rate_reset playername</div>
</div>
</div>
<div class="info-box">
<h4>💡 Tips for Smooth Gameplay</h4>
<ul>
<li><strong>Play Naturally</strong> - Normal gameplay rarely hits rate limits</li>
<li><strong>Use the Web Interface</strong> - Higher limits for browsing and pet management</li>
<li><strong>Spread Out Commands</strong> - Avoid rapid-fire command spamming</li>
<li><strong>Check Your Status</strong> - If you get rate limited, wait a moment before trying again</li>
</ul>
</div>
</div>
</div>
<div class="footer">
<p><strong>🎮 PetBot v0.2.0</strong> - Pokemon-style pet collecting for IRC</p>
<p>Catch pets • Battle gyms • Collect items • Earn badges • Explore locations</p>