{"id":31039112,"url":"https://github.com/pianopia/online-game-server","last_synced_at":"2025-09-14T07:47:44.371Z","repository":{"id":311551109,"uuid":"1044032259","full_name":"pianopia/Online-Game-Server","owner":"pianopia","description":"Rust製リアルタイム通信ゲームサーバーの実装テンプレート","archived":false,"fork":false,"pushed_at":"2025-08-25T05:04:37.000Z","size":41,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-25T07:51:59.799Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pianopia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-25T04:57:11.000Z","updated_at":"2025-08-25T05:04:40.000Z","dependencies_parsed_at":"2025-08-25T07:52:03.377Z","dependency_job_id":"a21707b3-0c23-4137-ba19-7ce07fd664bc","html_url":"https://github.com/pianopia/Online-Game-Server","commit_stats":null,"previous_names":["pianopia/online-game-server"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/pianopia/Online-Game-Server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pianopia%2FOnline-Game-Server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pianopia%2FOnline-Game-Server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pianopia%2FOnline-Game-Server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pianopia%2FOnline-Game-Server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pianopia","download_url":"https://codeload.github.com/pianopia/Online-Game-Server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pianopia%2FOnline-Game-Server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275076528,"owners_count":25401315,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-14T02:00:10.474Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-14T07:47:43.513Z","updated_at":"2025-09-14T07:47:44.356Z","avatar_url":"https://github.com/pianopia.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Online Game Server - WebSocket \u0026 UDP with SQLite\n\nRustで構築された高性能なリアルタイムオンラインゲームサーバー。WebSocketとUDPの両方に対応し、SQLiteによるデータ永続化機能を提供します。\n\n## 🚀 主要機能\n\n### プロトコル対応\n- **WebSocket**: 安定した接続、簡単な実装、Webブラウザ対応\n- **UDP**: 低遅延通信、リアルタイムゲーム最適化、カスタム信頼性制御\n\n### データベース統合\n- **SQLite**: プレイヤーデータの永続化\n- **セッション管理**: 接続時間・プロトコル追跡\n- **イベントログ**: 全プレイヤーアクションの記録\n- **分析機能**: チャット履歴、ハイスコア、統計情報\n\n### ゲーム機能\n- 複数プレイヤー同時接続\n- リアルタイム移動・位置同期\n- チャット機能\n- アクションシステム（攻撃、アイテム取得）\n- スコアシステム\n- 自動切断検知\n\n### パフォーマンス\n- 非同期処理 (tokio)\n- 並行安全なクライアント管理\n- UDP用信頼性制御・再送機能\n- データベース非同期操作\n\n## 📦 セットアップ\n\n### 1. 必要条件\n```bash\n# Rustインストール\ncurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\nsource ~/.cargo/env\n\n# バージョン確認\nrustc --version\ncargo --version\n```\n\n### 2. ビルドと実行\n```bash\n# 依存関係のビルド\ncargo build\n\n# WebSocketサーバー起動（デフォルト）\ncargo run\n\n# UDPサーバー起動\nPROTOCOL=udp cargo run\n\n# カスタムデータベース\nDATABASE_URL=\"sqlite:custom.db\" cargo run\n```\n\n### 3. サーバー設定\n```bash\n# ポート変更\nPORT=9000 cargo run\n\n# プロトコル + ポート + DB\nPROTOCOL=udp PORT=8081 DATABASE_URL=\"sqlite:game_udp.db\" cargo run\n\n# デバッグログ\nRUST_LOG=debug cargo run\n```\n\n## 🎮 テストクライアント\n\n### Webブラウザクライアント\n```bash\n# WebSocket用\nopen test_client.html\n\n# UDP説明付き\nopen udp_test_client.html\n```\n\n### ネイティブUDPクライアント\n```bash\n# Pythonクライアント実行\npython3 native_udp_client.py\n\n# インタラクティブコマンド:\n# move \u003cx\u003e \u003cy\u003e  - プレイヤー移動\n# chat \u003cmsg\u003e    - チャット送信\n# attack        - 攻撃アクション\n# pickup        - アイテム取得\n# heartbeat     - ハートビート送信\n# quit          - 終了\n```\n\n### データベーステスト\n```bash\n# 統合テスト実行\ncargo run --bin test_database\n```\n\n## 🏗️ アーキテクチャ\n\n### モジュール構成\n```\nsrc/\n├── main.rs           # エントリーポイント、プロトコル選択\n├── server.rs         # WebSocketサーバー\n├── udp_server.rs     # UDPサーバー（UDP最適化）\n├── client.rs         # WebSocketクライアント処理\n├── game.rs           # ゲーム状態管理\n├── message.rs        # メッセージ定義・UDP拡張\n└── database.rs       # SQLite操作・永続化\n\nmigrations/\n└── 001_initial.sql   # データベーススキーマ\n\nテストファイル:\n├── test_client.html       # WebSocketクライアント\n├── udp_test_client.html   # UDP説明付きクライアント\n├── native_udp_client.py   # ネイティブUDPクライアント\n└── test_database.rs       # データベーステスト\n```\n\n### 主要依存関係\n- `tokio` - 非同期ランタイム\n- `tokio-tungstenite` - WebSocket実装\n- `sqlx` - SQLite非同期ORM\n- `serde` + `serde_json` - シリアライゼーション\n- `bincode` - UDP用バイナリシリアライゼーション\n- `dashmap` - 並行安全HashMap\n- `uuid` - プレイヤーID生成\n- `chrono` - 日時処理\n- `tracing` - ログ出力\n\n## 📡 プロトコル比較\n\n| 特徴 | WebSocket | UDP |\n|------|-----------|-----|\n| **遅延** | 10-30ms | 1-5ms |\n| **信頼性** | TCP保証 | カスタム制御 |\n| **順序保証** | あり | アプリ制御 |\n| **実装の簡単さ** | 簡単 | 複雑 |\n| **ブラウザ対応** | ネイティブ | 不可 |\n| **適用場面** | ターン制・チャット | FPS・アクション |\n\n## 🗃️ データベース機能\n\n### 自動機能\n- スキーマ自動マイグレーション\n- プレイヤーデータ自動同期\n- セッション追跡\n- イベント自動ログ\n- タイムアウト自動処理\n\n### 利用可能なデータ\n```sql\n-- トッププレイヤー\nSELECT name, score FROM players ORDER BY score DESC LIMIT 10;\n\n-- プロトコル別統計\nSELECT protocol, COUNT(*) FROM game_sessions GROUP BY protocol;\n\n-- 最近のイベント\nSELECT event_type, COUNT(*) FROM player_events \nWHERE timestamp \u003e datetime('now', '-1 day')\nGROUP BY event_type;\n```\n\n## 🔧 カスタマイズ\n\n### 新しいゲームアクション追加\n```rust\n// src/game.rs の handle_player_action に追加\nmatch action {\n    \"attack\" =\u003e {\n        // 攻撃処理\n        database.log_event(\u0026client_id, session_id, \"attack\", None).await?;\n    },\n    \"heal\" =\u003e {\n        // 回復処理（新規）\n        if let Some(client_ref) = self.clients.get(\u0026client_id) {\n            let mut client = client_ref.write().await;\n            client.player.health = (client.player.health + 20.0).min(100.0);\n            database.update_player_health(\u0026client_id, client.player.health).await?;\n        }\n    },\n    _ =\u003e {}\n}\n```\n\n### UDP信頼性制御のカスタマイズ\n```rust\n// src/udp_server.rs\nconst HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);\nconst CLIENT_TIMEOUT: Duration = Duration::from_secs(30);\nconst PACKET_RESEND_TIMEOUT: Duration = Duration::from_millis(100);\n```\n\n### データベース設定\n```rust\n// 環境変数での設定\nDATABASE_URL=sqlite:game.db           # ローカルファイル\nDATABASE_URL=sqlite::memory:          # インメモリ（テスト用）\nDATABASE_URL=sqlite:/path/to/game.db  # 絶対パス\n```\n\n## 📊 パフォーマンス\n\n### 同時接続\n- WebSocket: 1000+ 同時接続\n- UDP: 2000+ 同時接続（理論値）\n\n### レスポンス時間\n- WebSocket: 10-30ms（通常）\n- UDP: 1-5ms（通常）、10-50ms（パケットロス時）\n\n### データベース\n- SQLite: 非同期操作、接続プール\n- 移動ログ: UDP時は10分の1に間引き（負荷軽減）\n\n## 🐛 トラブルシューティング\n\n### よくある問題\n\n1. **データベースファイルが作成できない**\n   ```bash\n   # 権限確認\n   ls -la game.db\n   # 削除して再作成\n   rm game.db \u0026\u0026 cargo run\n   ```\n\n2. **ポートが使用中**\n   ```bash\n   # 別ポート使用\n   PORT=8081 cargo run\n   ```\n\n3. **UDP接続できない**\n   ```bash\n   # ファイアウォール確認\n   # macOSの場合\n   sudo pfctl -d\n   ```\n\n### デバッグ方法\n```bash\n# 全ログ\nRUST_LOG=debug cargo run\n\n# SQLクエリログ\nRUST_LOG=sqlx::query=debug cargo run\n\n# エラーのみ\nRUST_LOG=error cargo run\n```\n\n## 🚀 本番環境デプロイ\n\n### Docker使用\n```bash\n# イメージビルド\ndocker build -t game-server .\n\n# コンテナ実行\ndocker run -p 8080:8080 -v $(pwd)/data:/app/data game-server\n```\n\n### パフォーマンス最適化\n```bash\n# リリースビルド\ncargo build --release\n\n# 最適化実行\n./target/release/online-game-server\n```\n\n## 📚 詳細ドキュメント\n\n- [UDP実装詳細](UDP_README.md)\n- [データベース機能](DATABASE_README.md)\n- [WebSocket API仕様](WebSocket_API_Specification.md)\n\n## 🤝 貢献\n\n1. フォーク\n2. フィーチャーブランチ作成 (`git checkout -b feature/amazing-feature`)\n3. コミット (`git commit -m 'Add amazing feature'`)\n4. プッシュ (`git push origin feature/amazing-feature`)\n5. プルリクエスト作成\n\n## 📄 ライセンス\n\nこのプロジェクトはMITライセンスで公開されています。\n\n---\n\n**高性能・低遅延のリアルタイムゲームサーバーで、次世代のオンラインゲームを構築しましょう！** 🎮","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpianopia%2Fonline-game-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpianopia%2Fonline-game-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpianopia%2Fonline-game-server/lists"}