84 lines
2.4 KiB
C#
84 lines
2.4 KiB
C#
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;
|
|
}
|
|
}
|