Genesis Game Server Project Setup

This commit is contained in:
2026-03-13 12:37:59 +09:00
commit af40aa2b45
17 changed files with 595 additions and 0 deletions

View File

@@ -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<IActionResult> GetPlayableCharacters()
{
List<CharacterModel> list = await _context.Characters
.Where(x => x.CharacterType == "PLAYABLE")
.ToListAsync();
return Ok(new ApiResponse<List<CharacterModel>>
{
Data = list,
Count = list.Count
});
}
}
}

View File

@@ -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<IActionResult> GetAllUserCharacters()
{
List<UserCharacterModel> list = await _context.UserCharacters.ToListAsync();
return Ok(new ApiResponse<List<UserCharacterModel>>
{
Data = list,
Count = list.Count
});
}
// 특정 유저의 캐릭터 목록
[HttpGet("userCharacters/{user_no}")]
public async Task<IActionResult> GetUserCharacters(int user_no)
{
List<UserCharacterModel> list = await _context.UserCharacters
.Where(x => x.UserNo == user_no)
.ToListAsync();
return Ok(new ApiResponse<List<UserCharacterModel>>
{
Data = list,
Count = list.Count
});
}
// 새 캐릭터 저장하기
[HttpPost("create")]
public async Task<IActionResult> CreatePlayer([FromBody] UserCharacterModel newUserCharacter)
{
_context.UserCharacters.Add(newUserCharacter);
await _context.SaveChangesAsync();
return Ok(new ApiResponse<UserCharacterModel>
{
Data = newUserCharacter,
Message = "캐릭터 생성 완료!"
});
}
}
}

View File

@@ -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}로 데이터 수정 완료!" });
}
}
}

View File

@@ -0,0 +1,15 @@
using Microsoft.EntityFrameworkCore;
using GameServer.Models;
namespace GameServer.Data
{
public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
{
}
public DbSet<UserCharacterModel> UserCharacters { get; set; }
public DbSet<CharacterModel> Characters { get; set; }
}
}

View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0" />
<PackageReference Include="Scalar.AspNetCore" Version="2.13.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,6 @@
@GameServer_HostAddress = http://localhost:5281
GET {{GameServer_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@@ -0,0 +1,9 @@
namespace GameServer.Models
{
public class ApiResponse<T>
{
public T? Data { get; set; } // 실제 데이터 (단일 객체 혹은 리스트)
public int? Count { get; set; } // 배열일 경우 개수 (선택사항)
public string Message { get; set; } = "Success";
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

29
GameServer/Program.cs Normal file
View File

@@ -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<AppDbContext>(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();

View File

@@ -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"
}
}
}
}

View File

@@ -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; }
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -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": "*"
}