Genesis Game Server Project Setup
This commit is contained in:
35
GameServer/Controllers/CharacterController.cs
Normal file
35
GameServer/Controllers/CharacterController.cs
Normal 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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
62
GameServer/Controllers/UserController.cs
Normal file
62
GameServer/Controllers/UserController.cs
Normal 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 = "캐릭터 생성 완료!"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
28
GameServer/Controllers/WeatherForecastController.cs
Normal file
28
GameServer/Controllers/WeatherForecastController.cs
Normal 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}로 데이터 수정 완료!" });
|
||||
}
|
||||
}
|
||||
}
|
||||
15
GameServer/Data/AppDbContext.cs
Normal file
15
GameServer/Data/AppDbContext.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
18
GameServer/GameServer.csproj
Normal file
18
GameServer/GameServer.csproj
Normal 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>
|
||||
6
GameServer/GameServer.http
Normal file
6
GameServer/GameServer.http
Normal file
@@ -0,0 +1,6 @@
|
||||
@GameServer_HostAddress = http://localhost:5281
|
||||
|
||||
GET {{GameServer_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
9
GameServer/Models/ApiResponse.cs
Normal file
9
GameServer/Models/ApiResponse.cs
Normal 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";
|
||||
}
|
||||
}
|
||||
17
GameServer/Models/CharacterModel.cs
Normal file
17
GameServer/Models/CharacterModel.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
39
GameServer/Models/UserCharacterModel.cs
Normal file
39
GameServer/Models/UserCharacterModel.cs
Normal 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
29
GameServer/Program.cs
Normal 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();
|
||||
23
GameServer/Properties/launchSettings.json
Normal file
23
GameServer/Properties/launchSettings.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
GameServer/WeatherForecast.cs
Normal file
13
GameServer/WeatherForecast.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
8
GameServer/appsettings.Development.json
Normal file
8
GameServer/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
12
GameServer/appsettings.json
Normal file
12
GameServer/appsettings.json
Normal 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": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user