세션 처리 업데이트
This commit is contained in:
parent
2a56bc4da7
commit
d2fb9cacd5
|
|
@ -1,4 +1,6 @@
|
|||
using Server.System;
|
||||
using Server.SQL;
|
||||
using Server.System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Server.Scheduler
|
||||
{
|
||||
|
|
@ -12,12 +14,67 @@ namespace Server.Scheduler
|
|||
|
||||
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.RemoveKey("UserSession", users[n]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//신규 로그인
|
||||
public static void addSession(User user)
|
||||
{
|
||||
//기존 세션 확인
|
||||
//TODO 기존 중복세션에 대한 처리도 필요
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
using Newtonsoft.Json;
|
||||
using Server.SQL;
|
||||
using Server.Manager;
|
||||
using Microsoft.AspNetCore.DataProtection.KeyManagement;
|
||||
using System.Collections.Generic;
|
||||
using Server.SQL.Excel;
|
||||
using static Server.Scheduler.SessionScheduler;
|
||||
|
||||
|
|
@ -96,24 +94,12 @@ namespace Server.Service
|
|||
deckInfoList = new List<DeckInfo> { deckInfo };
|
||||
#endregion
|
||||
}
|
||||
|
||||
//세션 추가
|
||||
addSession(user);
|
||||
#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 상점 세팅
|
||||
//리셋 상점
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using Newtonsoft.Json;
|
||||
using Server.Scheduler;
|
||||
using Server.SQL;
|
||||
using static Server.Scheduler.SessionScheduler;
|
||||
|
||||
namespace Server.System
|
||||
{
|
||||
|
|
@ -39,15 +39,7 @@ namespace Server.System
|
|||
{
|
||||
try
|
||||
{
|
||||
Dictionary<string, object> hash = Statics.redis.GetAllHash("UserInfo", 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);
|
||||
user = SessionScheduler.GetUser(uuid);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ namespace Server.System
|
|||
return result;
|
||||
}
|
||||
|
||||
public void SetHash(string field, object value, params string[] keys)
|
||||
public void SetHash(string field, string value, params string[] keys)
|
||||
{
|
||||
if (local)
|
||||
{
|
||||
|
|
@ -209,9 +209,9 @@ namespace Server.System
|
|||
{
|
||||
Dictionary<string, string> userHash = hashType[KeySet(keys)];
|
||||
if (userHash.ContainsKey(field))
|
||||
userHash.Add(field, JsonConvert.SerializeObject(value));
|
||||
userHash.Add(field, value);
|
||||
else
|
||||
userHash[field] = JsonConvert.SerializeObject(value);
|
||||
userHash[field] = value;
|
||||
}
|
||||
}
|
||||
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)
|
||||
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)
|
||||
{
|
||||
Dictionary<string, string> hashs = new Dictionary<string, string>(hashType[KeySet(keys)]);
|
||||
foreach (var entry in hashs)
|
||||
hash.Add(entry.Key, JsonConvert.DeserializeObject(entry.Value));
|
||||
hash.Add(entry.Key, entry.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -244,7 +244,7 @@ namespace Server.System
|
|||
return hash;
|
||||
}
|
||||
|
||||
public object GetHash(string field ,params string[] keys)
|
||||
public string GetHash(string field ,params string[] keys)
|
||||
{
|
||||
if (local)
|
||||
{
|
||||
|
|
@ -255,6 +255,14 @@ namespace Server.System
|
|||
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)
|
||||
{
|
||||
if (local)
|
||||
|
|
|
|||
Loading…
Reference in New Issue