171 lines
6.5 KiB
C#
171 lines
6.5 KiB
C#
using Server.System;
|
|
using Newtonsoft.Json;
|
|
using Server.SQL;
|
|
|
|
namespace Server.Service
|
|
{
|
|
public class Login : AbstractService
|
|
{
|
|
private LoginReq req;
|
|
public override string Process()
|
|
{
|
|
UserSQL userSql = new UserSQL();
|
|
DynamicDataSQL dynamicDataSQL = new DynamicDataSQL();
|
|
DeckUnitInfoSQL deckUnitInfoSQL = new DeckUnitInfoSQL();
|
|
DeckInfoSQL deckInfoSQL = new DeckInfoSQL();
|
|
EquipmentrSQL equipmentrSQL = new EquipmentrSQL();
|
|
User user;
|
|
List<DynamicData> dynamicDataList = dynamicDataSQL.Select();
|
|
List<DeckUnitInfo> deckUnitInfoList = null;
|
|
List<DeckInfo> deckInfoList = null;
|
|
List<Equipment> equipmentList = null;
|
|
|
|
if (req.uuid == "")
|
|
{
|
|
//최초 메일 로그인
|
|
//게스트 로그인은 허용하지 않고 무조건 구글로그인 혹은 마스토돈 로그인만 가능하게 처리하기
|
|
user = userSql.SelectMail(req.mail);
|
|
|
|
if (user != null)
|
|
{
|
|
deckUnitInfoList = deckUnitInfoSQL.Select();
|
|
deckInfoList = deckInfoSQL.Select();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//기존 유저 로그인
|
|
user = userSql.SelectUuid(req.uuid);
|
|
|
|
deckUnitInfoList = deckUnitInfoSQL.SelectUid(user.id);
|
|
//추후 이것을 1개만 보낼것.
|
|
deckInfoList = deckInfoSQL.SelectUid(user.id);
|
|
equipmentList = equipmentrSQL.SelectUid(user.id);
|
|
}
|
|
if(user == null)
|
|
{
|
|
if (req.mail == "")
|
|
{
|
|
throw new RuntimeException("Not User", Error.nodata);
|
|
}
|
|
#region 신규유저 생성
|
|
user = new User();
|
|
user.mail = req.mail;
|
|
user.uuid = Guid.NewGuid().ToString();
|
|
user.nickname = "NoName";
|
|
userSql.Insert(user); //저장하고 유닛의 id를 얻어오기 위함.
|
|
#endregion
|
|
#region 초기 유닛 지급
|
|
deckUnitInfoList = new List<DeckUnitInfo>();
|
|
DeckUnitInfo deckUnitInfo;
|
|
deckUnitInfo = new DeckUnitInfo();
|
|
deckUnitInfo.user_id = user.id;
|
|
deckUnitInfo.unit_id = 100001;
|
|
deckUnitInfoList.Add(deckUnitInfo);
|
|
deckUnitInfo = new DeckUnitInfo();
|
|
deckUnitInfo.user_id = user.id;
|
|
deckUnitInfo.unit_id = 100002;
|
|
deckUnitInfoList.Add(deckUnitInfo);
|
|
deckUnitInfo = new DeckUnitInfo();
|
|
deckUnitInfo.user_id = user.id;
|
|
deckUnitInfo.unit_id = 100003;
|
|
deckUnitInfoList.Add(deckUnitInfo);
|
|
deckUnitInfo = new DeckUnitInfo();
|
|
deckUnitInfo.user_id = user.id;
|
|
deckUnitInfo.unit_id = 100004;
|
|
deckUnitInfoList.Add(deckUnitInfo);
|
|
deckUnitInfo = new DeckUnitInfo();
|
|
deckUnitInfo.user_id = user.id;
|
|
deckUnitInfo.unit_id = 100005;
|
|
deckUnitInfoList.Add(deckUnitInfo);
|
|
deckUnitInfo = new DeckUnitInfo();
|
|
deckUnitInfo.user_id = user.id;
|
|
deckUnitInfo.unit_id = 100006;
|
|
deckUnitInfoList.Add(deckUnitInfo);
|
|
deckUnitInfo = new DeckUnitInfo();
|
|
deckUnitInfo.user_id = user.id;
|
|
deckUnitInfo.unit_id = 100007;
|
|
deckUnitInfoList.Add(deckUnitInfo);
|
|
deckUnitInfo = new DeckUnitInfo();
|
|
deckUnitInfo.user_id = user.id;
|
|
deckUnitInfo.unit_id = 100008;
|
|
deckUnitInfoList.Add(deckUnitInfo);
|
|
deckUnitInfo = new DeckUnitInfo();
|
|
deckUnitInfo.user_id = user.id;
|
|
deckUnitInfo.unit_id = 100009;
|
|
deckUnitInfoList.Add(deckUnitInfo);
|
|
deckUnitInfoSQL.Insert(deckUnitInfoList);
|
|
#endregion
|
|
#region 신규 덱 추가
|
|
deckInfoList = new List<DeckInfo>();
|
|
DeckInfo deckInfo;
|
|
deckInfo = new DeckInfo();
|
|
deckInfo.user_id= user.id;
|
|
deckInfo.deck_type = 1;
|
|
deckInfo.deck_unit0_id = deckUnitInfoList[0].id;
|
|
deckInfo.deck_unit1_id = deckUnitInfoList[1].id;
|
|
deckInfo.deck_unit2_id = deckUnitInfoList[2].id;
|
|
deckInfo.deck_unit3_id = deckUnitInfoList[3].id;
|
|
deckInfo.deck_unit4_id = deckUnitInfoList[4].id;
|
|
deckInfo.deck_unit5_id = deckUnitInfoList[5].id;
|
|
deckInfo.deck_unit6_id = deckUnitInfoList[6].id;
|
|
deckInfo.deck_unit7_id = deckUnitInfoList[7].id;
|
|
deckInfo.deck_unit8_id = deckUnitInfoList[8].id;
|
|
deckInfoList.Add(deckInfo);
|
|
deckInfoSQL.Insert(deckInfoList);
|
|
#endregion
|
|
}
|
|
|
|
|
|
|
|
return makeResp(user, dynamicDataList, deckUnitInfoList, deckInfoList, equipmentList);
|
|
}
|
|
|
|
public override Protocol ProtocolValue() => Protocol.Login;
|
|
|
|
public override Req Requst(string json)
|
|
{
|
|
req = JsonConvert.DeserializeObject<LoginReq>(json);
|
|
return req;
|
|
}
|
|
|
|
private string makeResp(User user, List<DynamicData> dynamic_data, List<DeckUnitInfo> deck_unit, List<DeckInfo> deck_info, List<Equipment> equipment)
|
|
{
|
|
LoginResp resp = new LoginResp();
|
|
resp.nickname = user.nickname;
|
|
resp.uuid = user.uuid;
|
|
resp.dynamic_data = dynamic_data;
|
|
resp.deck_unit = deck_unit;
|
|
resp.deck_info = deck_info;
|
|
resp.equipment = equipment;
|
|
resp.status = 200;
|
|
return resp.ToJson();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public class LoginReq : Req
|
|
{
|
|
public string mail;
|
|
public string uuid;
|
|
public override bool IsReceivedAllField()
|
|
{
|
|
if(mail == null && uuid == null)
|
|
return false;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public class LoginResp : Resp
|
|
{
|
|
public string uuid;
|
|
public string nickname;
|
|
public long id;
|
|
public List<DynamicData> dynamic_data;
|
|
public List<DeckUnitInfo> deck_unit;
|
|
public List<DeckInfo> deck_info;
|
|
public List<Equipment> equipment;
|
|
}
|
|
}
|