Commit 6f1aa79c authored by nanahira's avatar nanahira

readme

parent c3b4b1d3
Pipeline #43208 passed with stages
in 1 minute and 2 seconds
# srvpro2 # SRVPro2
It's finally here! > Next-generation YGOPro server with direct ocgcore control
\ No newline at end of file
SRVPro2 is the modern successor to SRVPro, implementing a complete YGOPro server in TypeScript with direct ocgcore (WebAssembly) control, modular architecture, and advanced features like disconnect/reconnect support.
## ✨ Features
- 🎮 **Direct ocgcore Control** - Uses WebAssembly (koishipro-core.js) to directly interact with ocgcore instead of proxying through ygopro
- 🔄 **Advanced Reconnect System** - Two-stage reconnect with deck verification and complete state reconstruction
- 🧵 **Multi-threaded Architecture** - Each room runs in an isolated Worker thread for better performance and crash isolation
- 🏗️ **Modular Design** - Clean separation of concerns with TransportModule, RoomModule, FeatsModule, and JoinHandlerModule
- 📦 **Full Protocol Support** - Complete implementation of YGOPro network protocol via ygopro-msg-encode
- 🔧 **Extensible** - Easy to add new features through middleware and module system
## 🏛️ Architecture
### Core Differences from SRVPro
| Aspect | SRVPro (v1) | SRVPro2 (v2) |
|--------|-------------|--------------|
| **Architecture** | Network proxy | Direct control |
| **ocgcore Access** | Indirect (via ygopro subprocess) | Direct (via WASM) |
| **Process Model** | Multi-process (Node.js + ygopro) | Single-process multi-threaded |
| **Communication** | TCP/IP networking | In-memory message passing |
| **State Query** | Message inference only | Full query API available |
| **Reconnect** | Simple (swap connections) | Advanced (state reconstruction) |
### Architecture Diagram
```
┌──────────────────────────────────────────────┐
│ SRVPro2 (Node.js Process) │
│ │
│ ┌──────────────────────────────────────┐ │
│ │ Main Thread │ │
│ │ - Network I/O (WebSocket) │ │
│ │ - Room Management │ │
│ │ - Client Handling │ │
│ └──────────┬───────────────────────────┘ │
│ │ │
│ ┌──────────┴───────────┬──────────────┐ │
│ │ Worker Thread 1 │ Worker 2 │ │
│ │ (Room A) │ (Room B) │ │
│ │ ┌────────────────┐ │ ┌──────────┐ │ │
│ │ │ ocgcore.wasm │ │ │ ocgcore │ │ │
│ │ │ (Game Engine) │ │ │ ... │ │ │
│ │ └────────────────┘ │ └──────────┘ │ │
│ └──────────────────────┴──────────────┘ │
└──────────────────────────────────────────────┘
```
### Module Structure
- **TransportModule**: WebSocket transport and client connection management
- **RoomModule**: Core game room logic (replicating ygopro functionality)
- **FeatsModule**: Extended features (welcome messages, reconnect, player status notifications, etc.)
- **JoinHandlerModule**: Room joining and matchmaking logic
## 🚀 Getting Started
### Prerequisites
- Node.js 18+ (for Worker threads support)
- TypeScript 5.x
- YGOPro game resources (scripts, databases)
### Installation
```bash
npm install
```
### Configuration
1. Generate configuration template:
```bash
npm run gen:config-example
```
2. Copy and edit the configuration:
```bash
cp config.example.yaml config.yaml
# Edit config.yaml with your settings
```
### Build and Run
```bash
# Development
npm run dev
# Production
npm run build
npm start
```
## 🔧 Configuration
Key configuration options (see `config.example.yaml` for full list):
- `WELCOME`: Welcome message shown to players joining rooms
- `RECONNECT_TIMEOUT`: Disconnect timeout before reconnect expires (default: 180000ms)
- `NO_RECONNECT`: Set to disable reconnect feature
- Standard YGOPro settings (port, timeout, banlist, etc.)
After modifying `src/config.ts`, regenerate the example config:
```bash
npm run gen:config-example
```
## 📚 Key Features
### Disconnect/Reconnect System
Unlike SRVPro's connection-swap approach, SRVPro2 implements a sophisticated two-stage reconnect:
1. **Pre-reconnect**: Client enters room lobby, verifies deck
2. **Full reconnect**: Complete game state reconstruction using ocgcore query APIs
The system supports both passive reconnect (network loss) and kick reconnect (logging in from another device).
### Direct State Query
Because SRVPro2 controls ocgcore directly, it can query any game state at any time:
```typescript
// Query complete field state
const field = await room.ocgcore.queryFieldInfo();
const player0LP = field.field.lp0;
// Query specific card
const card = await room.ocgcore.queryCard({
player: 0,
location: LOCATION_MZONE,
sequence: 0,
queryFlag: QUERY_ATTACK | QUERY_DEFENSE
});
```
This enables features impossible in proxy-based architectures.
## 🛠️ Development
### Project Structure
```
src/
├── client/ # Client connection handling
├── feats/ # Extended features (welcome, reconnect, etc.)
├── join-handlers/ # Room joining logic
├── room/ # Core room and game logic
├── transport/ # WebSocket transport
├── ocgcore-worker/ # Worker thread for ocgcore
├── utility/ # Helper functions
└── config.ts # Configuration definitions
```
### Coding Guidelines
See [AGENTS.md](./AGENTS.md) for detailed development guidelines, including:
- Module organization principles
- Import/export conventions
- Middleware patterns
- Event handling best practices
### Adding New Features
New features should be implemented as modules in `FeatsModule`:
```typescript
// src/feats/my-feature.ts
export class MyFeature {
constructor(private ctx: Context) {
// Register middleware
this.ctx.middleware(SomeEvent, async (event, client, next) => {
// Your logic
return next();
});
}
}
// src/feats/feats-module.ts
export const FeatsModule = createAppContext<ContextState>()
.provide(MyFeature) // Add your module
.define();
```
## 🤝 Contributing
Contributions are welcome. When contributing:
1. Follow the coding guidelines in AGENTS.md
2. Test your changes thoroughly
3. Update documentation as needed
4. Ensure `npm run build` completes successfully
## 📄 License
MIT License - see LICENSE file for details
## 🙏 Acknowledgments
- **YGOPro Team** - Original game engine and protocol
- **SRVPro** - Foundation and inspiration for this project
- **koishipro-core.js** - WASM wrapper for ocgcore
- **nfkit** - IoC container and event system
- **yuzuthread** - Worker thread management
## 📖 Related Projects
- [ygopro](https://github.com/Fluorohydride/ygopro) - Original YGOPro server
- [koishipro-core.js](https://github.com/purerosefallen/koishipro-core.js) - WASM ocgcore wrapper
- [ygopro-msg-encode](https://github.com/purerosefallen/ygopro-msg-encode) - YGOPro protocol library
---
**SRVPro2** - Built with ❤️ by Nanahira
{ {
"name": "myproject", "name": "srvpro2",
"description": "myproject-desc", "description": "Next-generation YGOPro server with direct ocgcore control via WASM and modern TypeScript architecture",
"version": "1.0.0", "version": "1.0.0",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
...@@ -14,15 +14,22 @@ ...@@ -14,15 +14,22 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://code.moenext.com/nanahira/myproject.git" "url": "https://code.moenext.com/nanahira/srvpro2.git"
}, },
"author": "Nanahira <nanahira@momobako.com>", "author": "Nanahira <nanahira@momobako.com>",
"license": "MIT", "license": "MIT",
"keywords": [], "keywords": [
"ygopro",
"yugioh",
"ocgcore",
"server",
"wasm",
"typescript"
],
"bugs": { "bugs": {
"url": "https://code.moenext.com/nanahira/myproject/issues" "url": "https://code.moenext.com/nanahira/srvpro2/issues"
}, },
"homepage": "https://code.moenext.com/nanahira/myproject", "homepage": "https://code.moenext.com/nanahira/srvpro2",
"jest": { "jest": {
"moduleFileExtensions": [ "moduleFileExtensions": [
"js", "js",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment