Merge branch 'main' of https://gitea.pandoli365.com/Team.thewar/thewar_server
This commit is contained in:
commit
2cf512d48b
|
|
@ -1,4 +1,6 @@
|
||||||
using Server.System;
|
using Server.SQL;
|
||||||
|
using Server.System;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace Server.Scheduler
|
namespace Server.Scheduler
|
||||||
{
|
{
|
||||||
|
|
@ -12,12 +14,66 @@ namespace Server.Scheduler
|
||||||
|
|
||||||
for (int n = users.Count - 1; n >= 0; n--)
|
for (int n = users.Count - 1; n >= 0; n--)
|
||||||
{
|
{
|
||||||
if ((now - (DateTime)Statics.redis.GetHash("end_login", "UserInfo", users[n])).TotalMinutes >= 10)
|
if ((now - DateTime.Parse(Statics.redis.GetHash("end_login", "UserInfo", users[n]))).TotalMinutes >= 10)
|
||||||
{
|
{
|
||||||
Statics.redis.RemoveList(n, users[n], "LoginUser");
|
Statics.redis.RemoveList(n, users[n], "LoginUser");
|
||||||
Statics.redis.RemoveKey("UserSession", users[n]);
|
Statics.redis.RemoveKey("UserSession", users[n]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//신규 로그인
|
||||||
|
public static void addSession(User user)
|
||||||
|
{
|
||||||
|
//기존 세션 확인
|
||||||
|
string loginUUID = Guid.NewGuid().ToString();
|
||||||
|
Dictionary<string, string> users = Statics.redis.GetAllHash("LoginUsers");
|
||||||
|
|
||||||
|
foreach(var item in users)
|
||||||
|
{
|
||||||
|
if(int.Parse(item.Value) == user.id)
|
||||||
|
{
|
||||||
|
Statics.redis.RemoveHash(item.Key);
|
||||||
|
Statics.redis.SetHash(loginUUID, user.id.ToString(), "LoginUsers");
|
||||||
|
updateSession(loginUUID);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Statics.redis.SetHash(loginUUID, user.id.ToString(), "LoginUsers");
|
||||||
|
Dictionary<string, string> userInfo = new Dictionary<string, string>();
|
||||||
|
userInfo.Add("id", user.id.ToString());
|
||||||
|
userInfo.Add("uuid", user.uuid);
|
||||||
|
userInfo.Add("mail", user.mail);
|
||||||
|
userInfo.Add("nickname ", user.nickname);
|
||||||
|
userInfo.Add("gold ", user.gold.ToString());
|
||||||
|
userInfo.Add("free_cash", user.free_cash.ToString());
|
||||||
|
userInfo.Add("pay_cash", user.pay_cash.ToString());
|
||||||
|
userInfo.Add("end_login", DateTime.Now.ToString());
|
||||||
|
Statics.redis.SetHash(userInfo, "UserInfo", user.id.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
//세션 업데이트
|
||||||
|
public static void updateSession(string UUID)
|
||||||
|
{
|
||||||
|
int id = int.Parse(Statics.redis.GetHash(UUID, "LoginUsers"));
|
||||||
|
Statics.redis.SetHash("end_login", DateTime.Now.ToString(), "UserInfo", id.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static User GetUser(string UUID)
|
||||||
|
{
|
||||||
|
User user = new User();
|
||||||
|
int id = int.Parse(Statics.redis.GetHash(UUID, "LoginUsers"));
|
||||||
|
Dictionary<string, string> userHash= Statics.redis.GetAllHash("UserInfo", id.ToString());
|
||||||
|
user.id = int.Parse(userHash["id"]);
|
||||||
|
user.uuid = userHash["uuid"];
|
||||||
|
user.mail = userHash["mail"];
|
||||||
|
user.nickname = userHash["nickname"];
|
||||||
|
user.gold = int.Parse(userHash["gold"]);
|
||||||
|
user.free_cash = int.Parse(userHash["free_cash"]);
|
||||||
|
user.pay_cash = int.Parse(userHash["pay_cash"]);
|
||||||
|
Statics.redis.SetHash("end_login", DateTime.Now.ToString(), "UserInfo", id.ToString());
|
||||||
|
return user;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,11 @@ namespace Server.Service
|
||||||
{
|
{
|
||||||
Statics.userSQL.Update(req.user);
|
Statics.userSQL.Update(req.user);
|
||||||
|
|
||||||
Dictionary<string, object> saveUser = new Dictionary<string, object>();
|
Dictionary<string, string> saveUser = new Dictionary<string, string>();
|
||||||
saveUser.Add("nickname", req.user.nickname);
|
saveUser.Add("nickname", req.user.nickname);
|
||||||
saveUser.Add("gold", req.user.gold);
|
saveUser.Add("gold", req.user.gold.ToString());
|
||||||
saveUser.Add("free_cash", req.user.free_cash);
|
saveUser.Add("free_cash", req.user.free_cash.ToString());
|
||||||
saveUser.Add("pay_cash", req.user.pay_cash);
|
saveUser.Add("pay_cash", req.user.pay_cash.ToString());
|
||||||
Statics.redis.SetHash(saveUser, "UserInfo", req.uuid);
|
Statics.redis.SetHash(saveUser, "UserInfo", req.uuid);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Server.SQL;
|
using Server.SQL;
|
||||||
using Server.Manager;
|
using Server.Manager;
|
||||||
using Microsoft.AspNetCore.DataProtection.KeyManagement;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Server.SQL.Excel;
|
using Server.SQL.Excel;
|
||||||
using static Server.Scheduler.SessionScheduler;
|
using static Server.Scheduler.SessionScheduler;
|
||||||
|
|
||||||
|
|
@ -96,24 +94,12 @@ namespace Server.Service
|
||||||
deckInfoList = new List<DeckInfo> { deckInfo };
|
deckInfoList = new List<DeckInfo> { deckInfo };
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//세션 추가
|
||||||
|
addSession(user);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 세션등록
|
|
||||||
//TODO 기존 중복세션에 대한 처리도 필요
|
|
||||||
//TODO 모든 세션 처리를 세션 스케줄러에서 처리가 가능하도록 수정할것
|
|
||||||
string loginUUID = Guid.NewGuid().ToString();
|
|
||||||
Statics.redis.SetList(loginUUID, "LoginUsers");
|
|
||||||
Dictionary<string, object> userInfo = new Dictionary<string, object>();
|
|
||||||
userInfo.Add("id", user.id);
|
|
||||||
userInfo.Add("uuid", user.uuid);
|
|
||||||
userInfo.Add("mail", user.mail);
|
|
||||||
userInfo.Add("nickname ", user.nickname);
|
|
||||||
userInfo.Add("gold ", user.gold);
|
|
||||||
userInfo.Add("free_cash", user.free_cash);
|
|
||||||
userInfo.Add("pay_cash", user.pay_cash);
|
|
||||||
userInfo.Add("end_login", DateTime.Now);
|
|
||||||
Statics.redis.SetHash(userInfo, "UserInfo", loginUUID);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 상점 세팅
|
#region 상점 세팅
|
||||||
//리셋 상점
|
//리셋 상점
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,11 @@ namespace Server.Service
|
||||||
{
|
{
|
||||||
Statics.userSQL.Update(req.user);
|
Statics.userSQL.Update(req.user);
|
||||||
|
|
||||||
Dictionary<string, object> saveUser = new Dictionary<string, object>();
|
Dictionary<string, string> saveUser = new Dictionary<string, string>();
|
||||||
saveUser.Add("nickname", req.user.nickname);
|
saveUser.Add("nickname", req.user.nickname);
|
||||||
saveUser.Add("gold", req.user.gold);
|
saveUser.Add("gold", req.user.gold.ToString());
|
||||||
saveUser.Add("free_cash", req.user.free_cash);
|
saveUser.Add("free_cash", req.user.free_cash.ToString());
|
||||||
saveUser.Add("pay_cash", req.user.pay_cash);
|
saveUser.Add("pay_cash", req.user.pay_cash.ToString());
|
||||||
Statics.redis.SetHash(saveUser, "UserInfo", req.uuid);
|
Statics.redis.SetHash(saveUser, "UserInfo", req.uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -30,8 +30,8 @@ namespace Server.Service
|
||||||
|
|
||||||
//만약 시스템 설정과 같은 닉네임이 온다면 중복 처리
|
//만약 시스템 설정과 같은 닉네임이 온다면 중복 처리
|
||||||
if (newNickname == defaultNick)
|
if (newNickname == defaultNick)
|
||||||
{
|
{
|
||||||
throw new RuntimeException("Duplicate nickname", Error.ErrorData);
|
throw new RuntimeException("Duplicate nickname", Error.ErrorData);
|
||||||
}
|
}
|
||||||
|
|
||||||
//닉네임 체크
|
//닉네임 체크
|
||||||
|
|
@ -94,4 +94,4 @@ namespace Server.Service
|
||||||
public string nickname;
|
public string nickname;
|
||||||
public uint cash;
|
public uint cash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using Server.System;
|
using Server.System;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Server.SQL;
|
||||||
|
|
||||||
namespace Server.Service
|
namespace Server.Service
|
||||||
{
|
{
|
||||||
|
|
@ -8,6 +9,7 @@ namespace Server.Service
|
||||||
private UseItemReq req;
|
private UseItemReq req;
|
||||||
public override string Process()
|
public override string Process()
|
||||||
{
|
{
|
||||||
|
User user = req.user;
|
||||||
return makeResp();
|
return makeResp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Server.Scheduler;
|
||||||
using Server.SQL;
|
using Server.SQL;
|
||||||
using static Server.Scheduler.SessionScheduler;
|
|
||||||
|
|
||||||
namespace Server.System
|
namespace Server.System
|
||||||
{
|
{
|
||||||
|
|
@ -39,15 +39,7 @@ namespace Server.System
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Dictionary<string, object> hash = Statics.redis.GetAllHash("UserInfo", uuid);
|
user = SessionScheduler.GetUser(uuid);
|
||||||
user.id = (int)hash["id"];
|
|
||||||
user.uuid = (string)hash["uuid"];
|
|
||||||
user.mail = (string)hash["mail"];
|
|
||||||
user.nickname = (string)hash["nickname"];
|
|
||||||
user.gold = (int)hash["gold"];
|
|
||||||
user.free_cash = (int)hash["free_cash"];
|
|
||||||
user.pay_cash = (int)hash["pay_cash"];
|
|
||||||
Statics.redis.SetHash("end_login", DateTime.Now, "UserInfo", uuid);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
|
||||||
|
|
@ -7,17 +7,20 @@
|
||||||
//100~199 로그인이나 시스템과 연관된 프로토콜
|
//100~199 로그인이나 시스템과 연관된 프로토콜
|
||||||
Downlode = 100,//기획 데이터 다운로드
|
Downlode = 100,//기획 데이터 다운로드
|
||||||
Login = 101,//로그인 유저정보 요청
|
Login = 101,//로그인 유저정보 요청
|
||||||
|
Synchronization = 102,//우편함 정보, 실시간 업데이트 등 일정시간마다 불러와야 하는 프로토콜 (TODO)
|
||||||
|
|
||||||
//200~299 유저 장비 관련 혹은 유닛관련 시스템 관리 프로토콜
|
//200~299 유저 장비 관련 혹은 유닛관련 시스템 관리 프로토콜
|
||||||
EquipChange = 200,//장비 변경
|
EquipChange = 200,//장비 변경
|
||||||
DeckChange = 201,//덱 유닛 변경
|
DeckChange = 201,//덱 유닛 변경
|
||||||
NicknameChange = 202,//닉네임 변경
|
NicknameChange = 202,//닉네임 변경
|
||||||
|
OpenMail = 210,//메일 오픈(TODO)
|
||||||
|
GetMail = 211,//메일 첨부 아이탬 획득(TODO)
|
||||||
|
|
||||||
//300~399 상점 관련 프로토콜
|
//300~399 상점 관련 프로토콜
|
||||||
BuyShopItem = 300,//상점 아이템 구매
|
BuyShopItem = 300,//상점 아이템 구매
|
||||||
BuyShopGacha = 301,//가챠 아이탬 사용(보류)
|
BuyShopGacha = 301,//가챠 아이탬 사용(보류)
|
||||||
UseItem = 302,//소모품 사용(보류)
|
UseItem = 302,//소모품 사용(TODO)
|
||||||
BuyItem = 303,//아이탬 판매(보류)
|
BuyItem = 303,//아이탬 판매(TODO)
|
||||||
|
|
||||||
//400~499 스토리 관련 프로토콜
|
//400~499 스토리 관련 프로토콜
|
||||||
UpdateStory = 400,//유저의 스토리 진행 상황 저장(작업 중)
|
UpdateStory = 400,//유저의 스토리 진행 상황 저장(작업 중)
|
||||||
|
|
|
||||||
|
|
@ -199,7 +199,7 @@ namespace Server.System
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetHash(string field, object value, params string[] keys)
|
public void SetHash(string field, string value, params string[] keys)
|
||||||
{
|
{
|
||||||
if (local)
|
if (local)
|
||||||
{
|
{
|
||||||
|
|
@ -209,9 +209,9 @@ namespace Server.System
|
||||||
{
|
{
|
||||||
Dictionary<string, string> userHash = hashType[KeySet(keys)];
|
Dictionary<string, string> userHash = hashType[KeySet(keys)];
|
||||||
if (userHash.ContainsKey(field))
|
if (userHash.ContainsKey(field))
|
||||||
userHash.Add(field, JsonConvert.SerializeObject(value));
|
userHash.Add(field, value);
|
||||||
else
|
else
|
||||||
userHash[field] = JsonConvert.SerializeObject(value);
|
userHash[field] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -220,20 +220,20 @@ namespace Server.System
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetHash(Dictionary<string, object> hash, params string[] keys)
|
public void SetHash(Dictionary<string, string> hash, params string[] keys)
|
||||||
{
|
{
|
||||||
foreach (var item in hash)
|
foreach (var item in hash)
|
||||||
SetHash(item.Key, item.Value, keys);
|
SetHash(item.Key, item.Value, keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<string, object> GetAllHash(params string[] keys)
|
public Dictionary<string, string> GetAllHash(params string[] keys)
|
||||||
{
|
{
|
||||||
Dictionary<string, object> hash = new Dictionary<string, object>();
|
Dictionary<string, string> hash = new Dictionary<string, string>();
|
||||||
if (local)
|
if (local)
|
||||||
{
|
{
|
||||||
Dictionary<string, string> hashs = new Dictionary<string, string>(hashType[KeySet(keys)]);
|
Dictionary<string, string> hashs = new Dictionary<string, string>(hashType[KeySet(keys)]);
|
||||||
foreach (var entry in hashs)
|
foreach (var entry in hashs)
|
||||||
hash.Add(entry.Key, JsonConvert.DeserializeObject(entry.Value));
|
hash.Add(entry.Key, entry.Value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -244,7 +244,7 @@ namespace Server.System
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
public object GetHash(string field ,params string[] keys)
|
public string GetHash(string field ,params string[] keys)
|
||||||
{
|
{
|
||||||
if (local)
|
if (local)
|
||||||
{
|
{
|
||||||
|
|
@ -255,6 +255,14 @@ namespace Server.System
|
||||||
return db.HashGet(KeySet(keys), field);
|
return db.HashGet(KeySet(keys), field);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RemoveHash(string field, params string[] keys)
|
||||||
|
{
|
||||||
|
if (local)
|
||||||
|
hashType[KeySet(keys)].Remove(field);
|
||||||
|
else
|
||||||
|
db.HashDelete(KeySet(keys), field);
|
||||||
|
}
|
||||||
|
|
||||||
public void RemoveKey(params string[] keys)
|
public void RemoveKey(params string[] keys)
|
||||||
{
|
{
|
||||||
if (local)
|
if (local)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue