Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
## Code Guidelines

This file provides guidance when working with code in this repository.

## Conversation Guidelines
- Primary Objective: Engage in honest, insight-driven dialogue that advances understanding.

### Core Principles
- Intellectual honesty: Share genuine insights without unnecessary flattery or dismissiveness
- Critical engagement: Push on important considerations rather than accepting ideas at face value
- Balanced evaluation: Present both positive and negative opinions only when well-reasoned and warranted
- Directional clarity: Focus on whether ideas move us forward or lead us astray

### What to Avoid
- Sycophantic responses or unwarranted positivity
- Dismissing ideas without proper consideration
- Superficial agreement or disagreement
- Flattery that doesn't serve the conversation

### Success Metric
The only currency that matters: Does this advance or halt productive thinking? If we're heading down an unproductive path, point it out directly.

## C++23 Modernization Guidelines

When working on the MUD codebase, follow these modern C++23 practices:

### Required Modern Features
- **Strings**: Use `fmt::format` instead of printf family, `std::string_view` for parameters, `std::string` for owned strings
- **Containers**: Use `std::vector`, `std::array`, `std::span` instead of C arrays, `std::unordered_map` for hash tables
- **Memory**: Smart pointers (`std::unique_ptr`, `std::shared_ptr`) instead of raw pointers, RAII for all resources
- **Algorithms**: `std::ranges` and `std::views` instead of manual loops, range-based for loops
- **Error Handling**: `std::expected` instead of error codes, `std::optional` for nullable values
- **Enums**: `magic_enum` for enum-to-string conversion
- **JSON**: `nlohmann/json` for all JSON processing
- **CLI**: `cxxopts` for command line argument parsing
- **Testing**: `Catch2` for unit tests and test-driven development
- **Constants**: Named constants (`constexpr`/`constinit`) instead of bare numbers (magic numbers)

### Forbidden Legacy Practices
- No `printf`, `sprintf`, `char*` manipulation, `malloc`/`free`, `NULL`, C-style casts, `#define` constants
- No manual memory management or C-style arrays
- No bare numbers/magic numbers - use named constants

### Code Cleanup Requirements
- Remove unused `#include` headers from legacy code
- Replace magic numbers with named constants
- Clean up commented-out code and obsolete functions

### Code Style Examples
```cpp
// ✅ Modern string handling
void send_message(std::string_view msg, std::span<const Player> recipients) {
auto formatted = fmt::format("Message: {}", msg);
for (const auto& player : recipients) {
player.send(formatted);
}
}

// ✅ Named constants instead of magic numbers
constexpr int MAX_PLAYERS_PER_ROOM = 50;
constexpr std::chrono::seconds SAVE_INTERVAL{300};

// ✅ Modern error handling
auto parse_command(std::string_view input) -> std::expected<Command, ParseError> {
if (input.empty()) return std::unexpected(ParseError::EmptyInput);
// ... parsing logic
return Command{cmd_name, args};
}

// ✅ Modern ranges
auto online_players = all_players
| std::views::filter(&Player::is_online)
| std::views::transform(&Player::get_name);
```

### Required Libraries
- Standard: `<ranges>`, `<span>`, `<expected>`, `<string_view>`
- External: `libfmt`, `nlohmann/json`, `magic_enum`, `cxxopts`, `spdlog`, `Catch2`
7 changes: 5 additions & 2 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ jobs:
- uses: jwlawson/actions-setup-cmake@v1.13
with:
build-version: 3.22.0
- run: cmake .
- run: make
- run: cmake -B build -G Ninja
- run: cmake --build build
- run: mv lib.default lib
- run: build/tests
- run: build/fierymud --check
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ cbuild/
.venv
__pycache__
.aider*
.cache/
.serena/
156 changes: 156 additions & 0 deletions Analysis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# FieryMUD Comprehensive Analysis Report

## 📊 **Executive Summary**

**Codebase Scale**: 108 C++ files, ~80K+ LOC
**Architecture**: Modern C++23 MUD server with legacy CircleMUD foundations
**Overall Health**: ⚡ **Good** with modernization opportunities

---

## 🏗️ **Architecture Overview**

### **Core Systems**
- **Main Loop**: `main.cpp` → `comm.cpp` - robust networking & game loop
- **Command Processing**: `interpreter.cpp` - privilege-based dispatch system
- **World Management**: `db.cpp` - JSON-based persistence & zone loading
- **Object Lifecycle**: `handler.cpp` - centralized game object management

### **Key Subsystems**
- **Classes**: Warrior, Cleric, Sorcerer, Rogue (`class.cpp`, specialized files)
- **Magic**: Circle-based memorization system (`spell_mem.cpp`)
- **Combat**: Turn-based mechanics (`fight.cpp`)
- **Scripting**: DG Scripts for dynamic content (`dg_*.cpp`)
- **OLC**: In-game content editing (`*edit.cpp`)

---

## 📈 **Quality Assessment**

### **Strengths** ✅
- **Modern C++23** standards adoption
- **Comprehensive STL usage** (string, vector, containers)
- **Excellent documentation** via CLAUDE.md
- **Professional formatting** with fmt library
- **JSON serialization** replacing legacy formats
- **Robust testing** framework (Catch2)

### **Areas for Improvement** ⚠️
- **16 TODO/FIXME** items identified requiring attention
- **Buffer function usage** (`strcpy`, `sprintf`) in legacy components
- **Memory management** patterns could benefit from RAII
- **Cyclomatic complexity** in some combat/spell logic

---

## 🔒 **Security Analysis**

### **Risk Level**: 🟨 **Medium**

### **Identified Concerns**
1. **Buffer Functions**: Use of `strcpy`/`sprintf` in `dg_olc.cpp`
- **Impact**: Potential buffer overflows
- **Recommendation**: Replace with safer alternatives (`fmt`, `std::string`)

2. **Password Handling**: Basic encryption patterns detected
- **Location**: `players.cpp:structs.hpp`
- **Status**: Uses crypt(3) - acceptable but could modernize

3. **Input Validation**: Command processing appears robust
- **Privilege System**: Well-implemented access controls
- **Command Dispatch**: Centralized validation through `interpreter.cpp`

### **Positive Security Features**
- No obvious SQL injection vectors (JSON-based persistence)
- Privilege-based command system
- Input sanitization patterns present

---

## ⚡ **Performance Characteristics**

### **Efficiency Metrics**
- **Loop Count**: 1,897 iterations across 108 files
- **Algorithmic Complexity**: One O(n²) reference in `magic.cpp`
- **Memory Usage**: Mixed C/C++ patterns, room for optimization

### **Performance Strengths**
- **Modern STL**: Efficient container usage
- **Networking**: Robust socket handling in `comm.cpp`
- **Game Loop**: Well-structured main loop architecture

### **Optimization Opportunities**
- **String Operations**: Heavy string processing could benefit from string_view
- **Combat System**: Complex calculations could use caching
- **Database Access**: JSON parsing optimization potential

---

## 🏛️ **Architectural Patterns**

### **Design Patterns Identified**
- **Strategy Pattern**: Found in spell parsing, movement systems
- **Observer Pattern**: Event system implementation
- **Factory Pattern**: Character/object creation systems

### **Architectural Quality**
- **Separation of Concerns**: Well-defined module boundaries
- **Modularity**: Clear subsystem organization
- **Extensibility**: Plugin-friendly design patterns
- **Legacy Integration**: Smooth CircleMUD evolution

### **Modernization Opportunities**
- **RAII Adoption**: More consistent resource management
- **Template Usage**: Generic programming opportunities
- **Const-Correctness**: Additional const usage possible

---

## 📋 **Priority Recommendations**

### **High Priority** 🔴
1. **Security Hardening**
- Replace buffer functions in `dg_olc.cpp`
- Audit input validation paths
- Consider password hash modernization

2. **Code Quality**
- Address 16 TODO/FIXME items
- Standardize memory management patterns
- Improve cyclomatic complexity in complex functions

### **Medium Priority** 🟡
3. **Performance Optimization**
- Profile and optimize O(n²) algorithms
- Implement string operation optimizations
- Cache frequently computed values

4. **Architecture Enhancement**
- Increase RAII usage
- Template-based generic programming
- Enhanced const-correctness

### **Low Priority** 🟢
5. **Documentation & Testing**
- Expand test coverage
- API documentation improvements
- Code commenting standards

---

## 🎯 **Overall Assessment**

**FieryMUD represents a well-architected, modern C++ MUD server with strong foundations.** The codebase demonstrates excellent evolution from legacy CircleMUD origins while embracing modern C++23 standards.

**Key Success Factors:**
- Solid architectural patterns
- Modern language features adoption
- Comprehensive testing framework
- Well-documented development practices

**Strategic Focus Areas:**
- Security hardening (buffer functions)
- Performance optimization opportunities
- Continued modernization journey

**Recommendation**: Continue current development trajectory with focused attention on security improvements and performance optimization.
Loading
Loading