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

80
TODO.md
View file

@ -3,9 +3,9 @@
This file tracks completed work, pending bugs, enhancements, and feature ideas for the PetBot project.
## 📊 Summary
- **✅ Completed**: 14 items
- **🐛 Bugs**: 1 item
- **🔧 Enhancements**: 5 items
- **✅ Completed**: 17 items
- **🐛 Bugs**: 0 items
- **🔧 Enhancements**: 3 items
- **💡 Ideas**: 10 items
- **📋 Total**: 30 items tracked
@ -74,6 +74,24 @@ This file tracks completed work, pending bugs, enhancements, and feature ideas f
- Updated help system with web interface integration
- Enhanced project documentation for contributors
- [x] **Implement automated database backup system**
- Complete backup management system with BackupManager class
- Automated scheduling with daily, weekly, and monthly backups
- Backup compression using gzip for space efficiency
- Retention policies (7 daily, 4 weekly, 12 monthly backups)
- IRC admin commands for backup management (!backup, !restore, !backups, !backup_stats, !backup_cleanup)
- Comprehensive testing suite and integration documentation
- Database integrity verification and safe restore procedures
- [x] **IRC connection monitoring and auto-reconnect functionality**
- Advanced IRC connection manager with robust state tracking
- Health monitoring system with ping/pong heartbeat (60s intervals)
- Exponential backoff reconnection (1s to 5min with jitter)
- Connection statistics and monitoring commands (!status, !uptime, !ping, !reconnect, !connection_stats)
- Graceful error handling and recovery from network interruptions
- Comprehensive test suite covering 11 scenarios including edge cases
- Integration with existing bot architecture and module system
### Low Priority Completed ✅
- [x] **Create CLAUDE.md file documenting development patterns and conventions**
- Comprehensive development guide for AI-assisted development
@ -85,32 +103,54 @@ This file tracks completed work, pending bugs, enhancements, and feature ideas f
## 🐛 KNOWN BUGS
### Medium Priority Bugs 🔴
- [ ] **IRC connection monitoring and auto-reconnect functionality**
- Bot may lose connection without proper recovery
- Need robust reconnection logic with exponential backoff
- Monitor connection health and implement graceful reconnection
- [x] **IRC connection monitoring and auto-reconnect functionality**
- ✅ Bot may lose connection without proper recovery
- ✅ Need robust reconnection logic with exponential backoff
- ✅ Monitor connection health and implement graceful reconnection
- ✅ Implemented comprehensive IRC connection manager with state tracking
- ✅ Added health monitoring with ping/pong system
- ✅ Created exponential backoff with jitter for reconnection attempts
- ✅ Added connection statistics and monitoring commands
- ✅ Comprehensive test suite with 11 test scenarios
---
## 🔧 ENHANCEMENTS NEEDED
### High Priority Enhancements 🟠
- [ ] **Implement automated database backup system**
- Regular automated backups of SQLite database
- Backup rotation and retention policies
- Recovery procedures and testing
- [x] **Implement automated database backup system**
- ✅ Regular automated backups of SQLite database (daily, weekly, monthly)
- ✅ Backup rotation and retention policies (7 daily, 4 weekly, 12 monthly)
- ✅ Recovery procedures and testing (restore with confirmation)
- ✅ Compression support (gzip) for space efficiency
- ✅ IRC admin commands for backup management
- ✅ Automated scheduling with cleanup
- [ ] **Conduct security audit of web interface and IRC bot**
- Review all user input validation
- Audit authentication and authorization mechanisms
- Test for common web vulnerabilities (XSS, CSRF, injection attacks)
- Review IRC bot security practices
- [x] **Conduct security audit of web interface and IRC bot**
- ✅ Review all user input validation
- ✅ Audit authentication and authorization mechanisms
- ✅ Test for common web vulnerabilities (XSS, CSRF, injection attacks)
- ✅ Review IRC bot security practices
- ✅ Identified 23 security vulnerabilities (5 critical, 8 high, 7 medium, 3 low)
- ✅ Created comprehensive security report in issues.txt
- [ ] **Address security vulnerabilities from audit**
- Fix XSS vulnerabilities by implementing HTML escaping
- Add HTTP security headers (CSP, X-Frame-Options, etc.)
- Implement web interface authentication and authorization
- Fix path traversal vulnerabilities
- Add input validation and sanitization
- See issues.txt for complete list and remediation priorities
### Medium Priority Enhancements 🟡
- [ ] **Add rate limiting to prevent command spam and abuse**
- Implement per-user rate limiting on IRC commands
- Web interface request throttling
- Graceful handling of rate limit violations
- [x] **Add rate limiting to prevent command spam and abuse**
- ✅ Implemented comprehensive token bucket rate limiting system
- ✅ Per-user rate limiting on IRC commands with category-based limits
- ✅ Web interface request throttling with IP-based tracking
- ✅ Graceful handling of rate limit violations with user-friendly messages
- ✅ Admin commands for monitoring and management (!rate_stats, !rate_user, !rate_unban, !rate_reset)
- ✅ Automatic cleanup of old violations and expired bans
- ✅ Central configuration system with single admin user control
- [ ] **Implement comprehensive error logging and monitoring system**
- Structured logging with appropriate log levels