A irc game where you explore and capture pets
Find a file
megaproxy e4d4205cd8 Fix critical experience system race condition and level down bug
CRITICAL BUG FIXES:
- Fix race condition causing pets to go down levels after gaining experience
- Replace dangerous double database updates with single atomic transaction
- Add comprehensive input validation to prevent negative experience awards
- Implement proper transaction isolation with BEGIN IMMEDIATE for concurrency

KEY IMPROVEMENTS:
- Single atomic UPDATE eliminates race conditions between concurrent experience awards
- Added extensive input validation (negative values, type checking, reasonable caps)
- Proper transaction handling with rollback on errors
- Removed deprecated _handle_level_up function that caused stale data issues
- Enhanced calculate_level_from_exp with infinite loop protection
- Added overflow protection for extreme level calculations

TECHNICAL DETAILS:
- Experience awards now use BEGIN IMMEDIATE transaction isolation
- All stat calculations and level updates happen in single atomic operation
- Input validation prevents negative experience and excessive amounts (>10,000)
- Pet isolation ensures no interference between different players' pets
- Comprehensive error handling with proper rollback on database errors
- Preserved HP percentage on level up while giving full HP bonus

This fixes the reported issue where players' pets would mysteriously lose levels
after gaining experience, which was caused by concurrent database updates
overwriting each other's level calculations.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-16 11:43:49 +00:00
.claude Add comprehensive startup script validation and enhanced pet system 2025-07-16 00:17:54 +00:00
backup_bots Add comprehensive web interface enhancements and encounter tracking 2025-07-14 16:32:25 +01:00
config Implement comprehensive pet healing system with revive items and database support 2025-07-16 11:32:01 +00:00
modules Add comprehensive NPC events system with community collaboration 2025-07-16 11:34:01 +00:00
plugins Initial commit: Complete PetBot IRC Game 2025-07-13 23:57:39 +01:00
src Fix critical experience system race condition and level down bug 2025-07-16 11:43:49 +00:00
.gitignore Update documentation - 2025-07-14 16:41 2025-07-14 16:41:48 +01:00
.version-control.py Add version control and changelog system 2025-07-14 00:01:54 +01:00
BACKUP_SYSTEM_INTEGRATION.md Implement comprehensive rate limiting system and item spawn configuration 2025-07-15 20:10:43 +00:00
CHANGELOG.md Update project documentation for web interface enhancements 2025-07-15 16:59:47 +01:00
CLAUDE.md Implement comprehensive rate limiting system and item spawn configuration 2025-07-15 20:10:43 +00:00
config.py Implement comprehensive rate limiting system and item spawn configuration 2025-07-15 20:10:43 +00:00
git_push.sh Update documentation - 2025-07-14 16:41 2025-07-14 16:41:48 +01:00
help.html Update help documentation with comprehensive pet healing system 2025-07-16 11:33:07 +00:00
install_prerequisites.py Implement comprehensive rate limiting system and item spawn configuration 2025-07-15 20:10:43 +00:00
install_prerequisites.sh Implement comprehensive rate limiting system and item spawn configuration 2025-07-15 20:10:43 +00:00
install_prerequisites_fixed.py Implement comprehensive rate limiting system and item spawn configuration 2025-07-15 20:10:43 +00:00
install_prerequisites_simple.sh Implement comprehensive rate limiting system and item spawn configuration 2025-07-15 20:10:43 +00:00
INSTALLATION.md Implement comprehensive rate limiting system and item spawn configuration 2025-07-15 20:10:43 +00:00
issues.txt Implement comprehensive rate limiting system and item spawn configuration 2025-07-15 20:10:43 +00:00
PROJECT_STATUS.md Fix database constraints and team builder save functionality 2025-07-14 21:10:28 +01:00
QUICKSTART.md Implement comprehensive rate limiting system and item spawn configuration 2025-07-15 20:10:43 +00:00
rate_limiting_config.json Implement comprehensive rate limiting system and item spawn configuration 2025-07-15 20:10:43 +00:00
README.md Update README with comprehensive feature descriptions and latest enhancements 2025-07-15 20:48:29 +00:00
README_git_script.md Update documentation - 2025-07-14 16:41 2025-07-14 16:41:48 +01:00
requirements.txt Implement comprehensive rate limiting system and item spawn configuration 2025-07-15 20:10:43 +00:00
reset_players.py Initial commit: Complete PetBot IRC Game 2025-07-13 23:57:39 +01:00
run_bot_debug.py Add comprehensive startup script validation and enhanced pet system 2025-07-16 00:17:54 +00:00
run_bot_with_reconnect.py Update bot and webserver integration for healing system support 2025-07-16 11:33:37 +00:00
start_petbot.sh Add comprehensive startup script validation and enhanced pet system 2025-07-16 00:17:54 +00:00
TODO.md Implement comprehensive team builder configuration system 2025-07-15 22:40:23 +00:00
TROUBLESHOOTING.md Implement comprehensive rate limiting system and item spawn configuration 2025-07-15 20:10:43 +00:00
webserver.py Update bot and webserver integration for healing system support 2025-07-16 11:33:37 +00:00

PetBot - IRC Pokemon-Style Pet Game Bot

A comprehensive IRC bot that brings Pokemon-style pet collecting and battling to your IRC channel! Players can catch pets, explore locations, battle wild creatures, earn achievements, and manage their collections through an integrated web interface.

🎮 Features

Core Gameplay

  • Pet Collection: Catch and collect different species of pets with varying rarities
  • Exploration: Travel between various themed locations with unique spawns
  • Battle System: Engage in turn-based battles with wild pets and gym leaders
  • Team Management: Build teams with drag-and-drop web interface and PIN verification
  • Achievement System: Unlock new areas by completing challenges and milestones
  • Item Collection: Discover 17+ useful items including healing potions, battle boosters, and treasure

Advanced Systems

  • Dynamic Weather: Real-time weather system affecting spawn rates and pet encounters
  • Web Interface: Modern responsive web dashboard with unified navigation
  • Enhanced Leaderboards: 8 different ranking categories (levels, experience, wealth, achievements, etc.)
  • Interactive Team Builder: Drag-and-drop team management with numbered slots (1-6)
  • Location-Based Spawns: Different pets spawn in different locations with weather modifiers
  • Level Progression: Pets gain experience, level up, and can be nicknamed
  • Type Effectiveness: Strategic battle system with type advantages
  • Gym Battle System: Challenge gym leaders and earn badges
  • Global Item Spawn Control: Admin-configurable spawn rates with global multipliers

Modern Web Features

  • Unified Navigation: Consistent navigation bar across all web pages
  • Player Profiles: Comprehensive player statistics and pet collections
  • Team Builder: Secure PIN-verified team changes with IRC delivery
  • Inventory Management: Visual item display with usage commands
  • Multi-Category Leaderboards: Interactive leaderboard switching
  • Responsive Design: Mobile-friendly interface design

Technical Features

  • Robust IRC Connection: Auto-reconnecting IRC client with health monitoring
  • Rate Limiting System: Token bucket rate limiting to prevent spam and abuse
  • Automated Backups: Comprehensive database backup system with retention policies
  • Security Monitoring: Security audit completed with 23 vulnerabilities identified
  • Modular Architecture: Clean, extensible codebase with proper separation of concerns
  • Async Database: SQLite with async operations and proper transaction handling
  • Background Tasks: Automated weather updates and system monitoring
  • Error Handling: Comprehensive error handling and user feedback

🚀 Quick Start

Prerequisites

  • Python 3.8+
  • SQLite3
  • Network access for IRC and web server

Installation

  1. Clone the repository:

    git clone ssh://git@192.168.1.249:2230/megaproxy/Petbot.git
    cd Petbot
    
  2. Install dependencies:

    pip install aiosqlite
    
  3. Configure the bot:

    cp config/settings.example.json config/settings.json
    # Edit config/settings.json with your IRC details
    
  4. Run the bot:

    python3 run_bot_debug.py
    

📋 Commands

Player Commands

  • !start - Begin your pet collecting journey
  • !explore - Search for wild pets in your current location
  • !catch <pet> - Attempt to catch a wild pet
  • !team - View your active team
  • !pets - View your complete collection (web link)
  • !travel <location> - Move to a different location
  • !weather - Check current weather effects
  • !achievements - View your progress and unlocked achievements

Battle Commands

  • !battle - Start a battle with a wild pet
  • !attack <move> - Use a move in battle
  • !flee - Attempt to escape from battle
  • !moves - View your active pet's moves

Pet Management

  • !activate <pet> - Activate a pet for battle
  • !deactivate <pet> - Move a pet to storage

Inventory Commands

  • !inventory / !inv / !items - View your collected items
  • !use <item> - Use a consumable item on your active pet

🌍 Locations

Available Areas

  • Starter Town: Peaceful starting area (Fire/Water/Grass pets)
  • Whispering Woods: Ancient forest (Grass/Nature pets)
  • Electric Canyon: Charged valley (Electric/Rock pets)
  • Crystal Caves: Underground caverns (Rock/Crystal pets)
  • Frozen Tundra: Icy wasteland (Ice/Water pets)
  • Dragon's Peak: Ultimate challenge (Fire/Rock/Ice pets)

Unlocking Locations

Locations are unlocked by completing achievements:

  • Pet Collector: Catch 5 pets total → Whispering Woods
  • Spark Collector: Catch 2 different Electric-type pets → Electric Canyon
  • Rock Hound: Catch 3 different Rock-type pets → Crystal Caves
  • Ice Breaker: Catch 5 different Water/Ice-type pets → Frozen Tundra
  • Dragon Tamer: Catch 15 pets total + 3 Fire-types → Dragon's Peak

Achievement Progression

  • Pet Collector (5 pets) → Unlock Whispering Woods
  • Nature Explorer (3 different Grass pets) → No location unlock
  • Advanced Trainer (10 pets) → No location unlock

🌤️ Weather System

Weather Types & Effects

  • Sunny: 1.5x Fire/Grass spawns (1-2 hours)
  • Rainy: 2.0x Water spawns (45-90 minutes)
  • Thunderstorm: 2.0x Electric spawns (30-60 minutes)
  • Blizzard: 1.7x Ice/Water spawns (1-2 hours)
  • Earthquake: 1.8x Rock spawns (30-90 minutes)
  • Calm: Normal spawns (1.5-3 hours)

Background System

  • Weather updates automatically every 5 minutes
  • Dynamic durations from 30 minutes to 3 hours
  • Location-specific weather patterns
  • Real-time spawn rate modifications

🎒 Item System

Item Categories

  • 🩹 Healing Items: Restore pet HP (Small/Large/Super Potions, Energy Berries)
  • ⚔️ Battle Items: Temporary combat boosts (Attack Boosters, Defense Crystals, Speed Elixirs)
  • 💎 Rare Items: Special materials (Fire/Water Stones, Lucky Charms, Ancient Fossils)
  • 🏛️ Location Items: Area-specific treasures (Shells, Mushrooms, Volcanic Glass, Ice Crystals)

Rarity Tiers

  • ○ Common: Frequently found items (15% spawn rate)
  • ◇ Uncommon: Moderately rare items (8-12% spawn rate)
  • ◆ Rare: Valuable items (3-6% spawn rate)
  • ★ Epic: Very rare items (2-3% spawn rate)
  • ✦ Legendary: Ultra-rare items (1% spawn rate)

Item Discovery

  • 30% chance to find items during !explore
  • Location-specific items only spawn in certain areas
  • Items stack in inventory with quantity tracking
  • Use consumable items with !use <item name>

🌐 Web Interface

Access the web dashboard at http://petz.rdx4.com/:

  • Player Profiles: Complete stats, pet collections, and inventories
  • Leaderboard: Top players by level and achievements
  • Locations Guide: All areas with spawn information
  • Help System: Complete command reference

🔧 Architecture

Core Components

  • Database Layer: Async SQLite with comprehensive schema
  • Game Engine: Core logic for pets, battles, weather
  • Module System: Pluggable command handlers
  • Web Server: Built-in HTTP server for dashboard
  • Battle Engine: Turn-based combat system

Key Files

  • src/database.py - Database operations and schema
  • src/game_engine.py - Core game logic and weather system
  • src/battle_engine.py - Combat mechanics
  • modules/ - Command handler modules
  • webserver.py - Web interface server
  • config/ - Configuration files

🐛 Recent Updates

v0.2.0 - Item Collection System

  • Complete item system with 16 unique items across 5 categories
  • Item discovery during exploration (30% chance)
  • Rarity tiers with symbols and colors (Common → Legendary)
  • Location-specific unique items and treasures
  • Inventory management with !inventory and !use commands
  • Web interface integration showing player inventories
  • Consumable items (healing potions, battle boosters, lucky charms)

v0.1.0 - Core Game & Weather System

  • Added background task for automatic weather updates
  • Changed weather durations from 2-6 hours to 30min-3hours
  • Implemented continuous weather coverage
  • Fixed database persistence on bot restart
  • Resolved individual player pages showing 'not found'
  • Corrected achievement count displays
  • Added specific travel requirement messages
  • Fixed locations page display
  • Implemented colored battle moves by type

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes
  4. Add tests if applicable
  5. Commit with descriptive messages
  6. Push and create a pull request

📝 License

This project is open source. Feel free to use, modify, and distribute.

🎯 Roadmap

  • PvP battles between players
  • Pet evolution system
  • Trading between players
  • Seasonal events
  • More pet types and locations
  • Mobile-responsive web interface

🐾 Support

For questions, bug reports, or feature requests, please open an issue on GitHub.


Built with ❤️ for IRC communities who love Pokemon-style games!