닉네임 변경 프로토콜 작업 완료
This commit is contained in:
parent
d9a5d29628
commit
1a1c8f5e78
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Server.SQL
|
||||
|
|
@ -6,6 +7,7 @@ namespace Server.SQL
|
|||
[Table("dynamic_data", Schema = "gamedb")]
|
||||
public class DynamicData
|
||||
{
|
||||
[Key]
|
||||
public long id { get; set; }
|
||||
public string name { get; set; }
|
||||
public string value { get; set; }
|
||||
|
|
|
|||
|
|
@ -19,12 +19,14 @@ namespace Server.SQL
|
|||
|
||||
public bool buyCash(long buy)
|
||||
{
|
||||
if (buy == 0) { return true; }
|
||||
long freeCash = free_cash;
|
||||
long payCash = pay_cash;
|
||||
freeCash -= buy;
|
||||
if(freeCash < 0)
|
||||
{
|
||||
payCash -= freeCash;
|
||||
payCash += freeCash;
|
||||
freeCash = 0;
|
||||
}
|
||||
|
||||
if(payCash >= 0)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace Server.Service
|
|||
{
|
||||
private DeckChangeReq req;
|
||||
|
||||
public void SaveSQL()
|
||||
private void SaveSQL()
|
||||
{
|
||||
Statics.deckInfoSQL.SaveChanges();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace Server.Service
|
|||
{
|
||||
private EquipChangeReq req;
|
||||
|
||||
public void SaveSQL()
|
||||
private void SaveSQL()
|
||||
{
|
||||
Statics.equipmentrSQL.SaveChanges();
|
||||
Statics.deckUnitInfoSQL.SaveChanges();
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ namespace Server.Service
|
|||
user = new User();
|
||||
user.mail = req.mail;
|
||||
user.uuid = Guid.NewGuid().ToString();
|
||||
user.nickname = "NoName";
|
||||
user.nickname = Statics.dynamicDataSQL.SelectName("defaultNick").value;
|
||||
Statics.userSQL.Insert(user); //저장하고 유닛의 id를 얻어오기 위함.
|
||||
#endregion
|
||||
#region 초기 유닛 지급
|
||||
|
|
|
|||
|
|
@ -0,0 +1,83 @@
|
|||
using Server.System;
|
||||
using Newtonsoft.Json;
|
||||
using Server.SQL;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Server.Service
|
||||
{
|
||||
public class NicknameChange : AbstractService
|
||||
{
|
||||
private NicknameChangeReq req;
|
||||
private void SaveSQL()
|
||||
{
|
||||
Statics.userSQL.SaveChanges();
|
||||
}
|
||||
|
||||
public override string Process()
|
||||
{
|
||||
User user = Statics.userSQL.SelectUuid(req.uuid);
|
||||
string newNickname = req.newNickname;
|
||||
string regular = @"^[가-힣a-zA-Z0-9\s]*$";
|
||||
int buy;
|
||||
|
||||
//닉네임 체크
|
||||
//if(!Regex.IsMatch(newNickname, regular) || (newNickname.Length < 2 || newNickname.Length > 16) || user.nickname == newNickname)
|
||||
//{
|
||||
// //해당 데이터가 들어온다면 유저 정보와 같이 로그를 남기게 만들것
|
||||
// throw new RuntimeException("Nickname not allowed", Error.errordata);
|
||||
//}
|
||||
|
||||
//가격 체크
|
||||
if (user.nickname == Statics.dynamicDataSQL.SelectName("defaultNick").value)
|
||||
buy = 0;
|
||||
else
|
||||
buy = int.Parse(Statics.dynamicDataSQL.SelectName("nicknameCash").value);
|
||||
|
||||
//현재 충분한 제화가 있는지 확인
|
||||
if (!user.buyCash(buy))
|
||||
{
|
||||
throw new RuntimeException("Cache shortage", Error.nogold);
|
||||
}
|
||||
|
||||
user.nickname = newNickname;
|
||||
|
||||
SaveSQL();
|
||||
return makeResp(user);
|
||||
}
|
||||
|
||||
public override Protocol ProtocolValue() => Protocol.NicknameChange;
|
||||
|
||||
public override Req Requst(string json)
|
||||
{
|
||||
req = JsonConvert.DeserializeObject<NicknameChangeReq>(json);
|
||||
return req;
|
||||
}
|
||||
|
||||
private string makeResp(User user)
|
||||
{
|
||||
NicknameChangeResp resp = new NicknameChangeResp();
|
||||
resp.status = 200;
|
||||
resp.nickname = user.nickname;
|
||||
resp.cash = (ulong)(user.free_cash + user.pay_cash);
|
||||
return resp.ToJson();
|
||||
}
|
||||
}
|
||||
|
||||
public class NicknameChangeReq : Req
|
||||
{
|
||||
public string uuid;
|
||||
public string newNickname;
|
||||
public override bool IsReceivedAllField()
|
||||
{
|
||||
if (uuid == "")
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class NicknameChangeResp : Resp
|
||||
{
|
||||
public string nickname;
|
||||
public ulong cash;
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
EquipChange = 200,//장비 변경
|
||||
DeckChange = 201,//덱 유닛 변경
|
||||
NicknameChange = 202,//닉네임 변경
|
||||
}
|
||||
|
||||
public enum Error
|
||||
|
|
@ -23,6 +24,8 @@ public enum Error
|
|||
success = 200,//성공
|
||||
notFound = 404,//프로토콜 없음
|
||||
unknown = 500,//파라미터 오류
|
||||
errordata = 501,//잘못된 데이터
|
||||
crypto = 800,//암복호화 에러
|
||||
nodata = 900,//데이터가 없음
|
||||
nogold = 901,//소모재화가 없음
|
||||
}
|
||||
Loading…
Reference in New Issue