commit af40aa2b4523a217c3bd7ac70da4a30091d69b32 Author: DESKTOP-VVOCIJO\PC Date: Fri Mar 13 12:37:59 2026 +0900 Genesis Game Server Project Setup diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c5b41fe --- /dev/null +++ b/.gitignore @@ -0,0 +1,274 @@ +# Created by https://www.toptal.com/developers/gitignore/api/aspnetcore +# Edit at https://www.toptal.com/developers/gitignore?templates=aspnetcore + +### ASPNETCore ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/ + +# End of https://www.toptal.com/developers/gitignore/api/aspnetcore \ No newline at end of file diff --git a/GameServer.slnx b/GameServer.slnx new file mode 100644 index 0000000..877889f --- /dev/null +++ b/GameServer.slnx @@ -0,0 +1,3 @@ + + + diff --git a/GameServer/Controllers/CharacterController.cs b/GameServer/Controllers/CharacterController.cs new file mode 100644 index 0000000..43bcaf1 --- /dev/null +++ b/GameServer/Controllers/CharacterController.cs @@ -0,0 +1,35 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using GameServer.Data; // DbContext가 있는 폴더 +using GameServer.Models; // Model이 있는 폴더 + +namespace GameServer.Controllers +{ + [ApiController] + [Route("myGame")] // 접속 주소: /myGame + public class CharacterController : ControllerBase + { + private readonly AppDbContext _context; + + // DB 연결 도구(Context)를 가져옵니다. + public CharacterController(AppDbContext context) + { + _context = context; + } + + // 플레이어블 캐릭터 목록 + [HttpGet("playableCharacters")] + public async Task GetPlayableCharacters() + { + List list = await _context.Characters + .Where(x => x.CharacterType == "PLAYABLE") + .ToListAsync(); + + return Ok(new ApiResponse> + { + Data = list, + Count = list.Count + }); + } + } +} \ No newline at end of file diff --git a/GameServer/Controllers/UserController.cs b/GameServer/Controllers/UserController.cs new file mode 100644 index 0000000..2889542 --- /dev/null +++ b/GameServer/Controllers/UserController.cs @@ -0,0 +1,62 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using GameServer.Data; // DbContext가 있는 폴더 +using GameServer.Models; // Model이 있는 폴더 + +namespace GameServer.Controllers +{ + [ApiController] + [Route("myGame")] // 접속 주소: /myGame + public class UserController : ControllerBase + { + private readonly AppDbContext _context; + + // DB 연결 도구(Context)를 가져옵니다. + public UserController(AppDbContext context) + { + _context = context; + } + + // 모든 유저들의 캐릭터 목록 + [HttpGet("userCharacters")] + public async Task GetAllUserCharacters() + { + List list = await _context.UserCharacters.ToListAsync(); + + return Ok(new ApiResponse> + { + Data = list, + Count = list.Count + }); + } + + // 특정 유저의 캐릭터 목록 + [HttpGet("userCharacters/{user_no}")] + public async Task GetUserCharacters(int user_no) + { + List list = await _context.UserCharacters + .Where(x => x.UserNo == user_no) + .ToListAsync(); + + return Ok(new ApiResponse> + { + Data = list, + Count = list.Count + }); + } + + // 새 캐릭터 저장하기 + [HttpPost("create")] + public async Task CreatePlayer([FromBody] UserCharacterModel newUserCharacter) + { + _context.UserCharacters.Add(newUserCharacter); + await _context.SaveChangesAsync(); + + return Ok(new ApiResponse + { + Data = newUserCharacter, + Message = "캐릭터 생성 완료!" + }); + } + } +} \ No newline at end of file diff --git a/GameServer/Controllers/WeatherForecastController.cs b/GameServer/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..25d70f7 --- /dev/null +++ b/GameServer/Controllers/WeatherForecastController.cs @@ -0,0 +1,28 @@ +using Microsoft.AspNetCore.Mvc; + +namespace GameServer.Controllers +{ + [ApiController] + [Route("myGame")] + public class WeatherForecastController : ControllerBase + { + // 서버 메모리에 임시로 저장할 데이터 (나중에 DB로 바꿀 부분) + private static int _tempData = 100; + + // 데이터 로드 + [HttpGet("data")] + public IActionResult GetCores() + { + // 유니티에게 JSON 형태로 데이터를 보냄 + return Ok(new { data = _tempData, message = "데이터 로드 성공!" }); + } + + // 데이터 수정 + [HttpPost("add-data")] + public IActionResult AddCore([FromBody] int value) + { + _tempData = value; + return Ok(new { data = _tempData, message = $"{value}로 데이터 수정 완료!" }); + } + } +} diff --git a/GameServer/Data/AppDbContext.cs b/GameServer/Data/AppDbContext.cs new file mode 100644 index 0000000..469ef3d --- /dev/null +++ b/GameServer/Data/AppDbContext.cs @@ -0,0 +1,15 @@ +using Microsoft.EntityFrameworkCore; +using GameServer.Models; + +namespace GameServer.Data +{ + public class AppDbContext : DbContext + { + public AppDbContext(DbContextOptions options) : base(options) + { + + } + public DbSet UserCharacters { get; set; } + public DbSet Characters { get; set; } + } +} diff --git a/GameServer/GameServer.csproj b/GameServer/GameServer.csproj new file mode 100644 index 0000000..54d13dd --- /dev/null +++ b/GameServer/GameServer.csproj @@ -0,0 +1,18 @@ + + + + net9.0 + enable + enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + diff --git a/GameServer/GameServer.http b/GameServer/GameServer.http new file mode 100644 index 0000000..4bf14ed --- /dev/null +++ b/GameServer/GameServer.http @@ -0,0 +1,6 @@ +@GameServer_HostAddress = http://localhost:5281 + +GET {{GameServer_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/GameServer/Models/ApiResponse.cs b/GameServer/Models/ApiResponse.cs new file mode 100644 index 0000000..26fd1d3 --- /dev/null +++ b/GameServer/Models/ApiResponse.cs @@ -0,0 +1,9 @@ +namespace GameServer.Models +{ + public class ApiResponse + { + public T? Data { get; set; } // 실제 데이터 (단일 객체 혹은 리스트) + public int? Count { get; set; } // 배열일 경우 개수 (선택사항) + public string Message { get; set; } = "Success"; + } +} diff --git a/GameServer/Models/CharacterModel.cs b/GameServer/Models/CharacterModel.cs new file mode 100644 index 0000000..cbc97cf --- /dev/null +++ b/GameServer/Models/CharacterModel.cs @@ -0,0 +1,17 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace GameServer.Models +{ + [Table("tb_character")] + public class CharacterModel + { + [Key] + [Column("character_code")] + public string CharacterCode { get; set; } = string.Empty; + + [Required] + [Column("character_type")] + public string CharacterType { get; set; } = string.Empty; + } +} diff --git a/GameServer/Models/UserCharacterModel.cs b/GameServer/Models/UserCharacterModel.cs new file mode 100644 index 0000000..cfb6dde --- /dev/null +++ b/GameServer/Models/UserCharacterModel.cs @@ -0,0 +1,39 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace GameServer.Models +{ + [Table("tb_user_characters")] + public class UserCharacterModel + { + [Key] + [Column("user_character_no")] + public int UserCharacterNo { get; set; } + + [Required] + [Column("user_no")] + public int UserNo { get; set; } = 0; + + [Column("character_code")] + public string CharacterCode { get; set; } = string.Empty; + + [Column("lv")] + public int Lv { get; set; } = 0; + + [Column("str_stat")] + public int StrStat { get; set; } = 0; + + [Column("int_stat")] + public int IntStat { get; set; } = 0; + + [Column("max_hp")] + public int MaxHp { get; set; } = 0; + + [Column("max_mp")] + public int MaxMp { get; set; } = 0; + + [Column("default_control")] + public bool DefaultControl { get; set; } = false; + + } +} diff --git a/GameServer/Program.cs b/GameServer/Program.cs new file mode 100644 index 0000000..fb813b2 --- /dev/null +++ b/GameServer/Program.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore; +using GameServer.Data; +using Scalar.AspNetCore; + +var builder = WebApplication.CreateBuilder(args); + +// appsettings.json에서 연결 문자열(Connection String) 가져오기 +var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); + +// MariaDB(Pomelo) 엔진 등록 +builder.Services.AddDbContext(options => + options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString))); + +builder.Services.AddControllers(); +builder.Services.AddOpenApi(); + +var app = builder.Build(); + +if (app.Environment.IsDevelopment()) +{ + app.MapOpenApi(); + app.MapScalarApiReference(); +} + +app.UseHttpsRedirection(); +app.UseAuthorization(); +app.MapControllers(); + +app.Run(); \ No newline at end of file diff --git a/GameServer/Properties/launchSettings.json b/GameServer/Properties/launchSettings.json new file mode 100644 index 0000000..1946956 --- /dev/null +++ b/GameServer/Properties/launchSettings.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "http://localhost:5281", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "https://localhost:7134;http://localhost:5281", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/GameServer/WeatherForecast.cs b/GameServer/WeatherForecast.cs new file mode 100644 index 0000000..2833c3e --- /dev/null +++ b/GameServer/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace GameServer +{ + public class WeatherForecast + { + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/GameServer/appsettings.Development.json b/GameServer/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/GameServer/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/GameServer/appsettings.json b/GameServer/appsettings.json new file mode 100644 index 0000000..ad36ff7 --- /dev/null +++ b/GameServer/appsettings.json @@ -0,0 +1,12 @@ +{ + "ConnectionStrings": { + "DefaultConnection": "Server=nackjoonpc.iptime.org;Port=3363;Database=myGame;Uid=root;Pwd=!skrwns8023!;" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..80d5694 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Genesis_GameServer + +유니티 게임(Genesis) 서버 +