178 lines
6.9 KiB
C#
178 lines
6.9 KiB
C#
using Server.System;
|
|
using Newtonsoft.Json;
|
|
using Server.SQL;
|
|
|
|
namespace Server.Service
|
|
{
|
|
//프라이빗uuid가아닌 기기 ip를 받아와 확인
|
|
//유저 정보를 확인할때 ip도 같이 확인해서 만약 다르면 차단
|
|
public class Login : AbstractService
|
|
{
|
|
private LoginReq req;
|
|
|
|
public override string Process()
|
|
{
|
|
|
|
User user;
|
|
#region 로그인
|
|
List<DynamicData> dynamicDataList = Statics.dynamicDataSQL.Select();
|
|
List<DeckUnitInfo> deckUnitInfoList = null;
|
|
List<DeckInfo> deckInfoList = null;
|
|
List<Equipment> equipmentList = null;
|
|
if (req.uuid == "")
|
|
{
|
|
//최초 메일 로그인
|
|
//게스트 로그인은 허용하지 않고 무조건 구글로그인 혹은 마스토돈 로그인만 가능하게 처리하기
|
|
user = Statics.userSQL.SelectMail(req.mail);
|
|
|
|
if (user != null)
|
|
{
|
|
deckUnitInfoList = Statics.deckUnitInfoSQL.SelectUid(user.id);
|
|
deckInfoList = Statics.deckInfoSQL.SelectUid(user.id);
|
|
equipmentList = Statics.equipmentrSQL.SelectUid(user.id);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//기존 유저 로그인
|
|
user = Statics.userSQL.SelectUuid(req.uuid);
|
|
|
|
deckUnitInfoList = Statics.deckUnitInfoSQL.SelectUid(user.id);
|
|
deckInfoList = Statics.deckInfoSQL.SelectUid(user.id);
|
|
equipmentList = Statics.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 = Statics.dynamicDataSQL.SelectName("defaultNick").value;
|
|
Statics.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);
|
|
Statics.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);
|
|
Statics.deckInfoSQL.Insert(deckInfoList);
|
|
|
|
equipmentList = new List<Equipment>();
|
|
#endregion
|
|
}
|
|
#endregion
|
|
|
|
//#region 상점 아이템
|
|
//List<ShopItemData> shopItemDatas = Statics.shopItemExcel.getShopItemData();
|
|
//#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.gold = (ulong)user.gold;
|
|
resp.cash = (ulong)(user.free_cash + user.pay_cash);
|
|
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 ulong gold;
|
|
public ulong cash;
|
|
public List<DynamicData> dynamic_data;
|
|
public List<DeckUnitInfo> deck_unit;
|
|
public List<DeckInfo> deck_info;
|
|
public List<Equipment> equipment;
|
|
}
|
|
}
|