세션 처리용 코드 추가
This commit is contained in:
parent
914de7dea9
commit
a3e981310f
|
|
@ -7,25 +7,18 @@ namespace Server.Scheduler
|
||||||
{
|
{
|
||||||
public override void Process()
|
public override void Process()
|
||||||
{
|
{
|
||||||
List<LoginUser> users = Statics.redis.GetList<LoginUser>("LoginUser");
|
List<string> users = Statics.redis.GetList<string>("LoginUser");
|
||||||
|
|
||||||
DateTime now = DateTime.Now;
|
DateTime now = DateTime.Now;
|
||||||
|
|
||||||
for (int n = users.Count - 1; n >= 0; n--)
|
for (int n = users.Count - 1; n >= 0; n--)
|
||||||
{
|
{
|
||||||
if ((now - users[n].moveTime).TotalMinutes >= 10)
|
if ((now - (DateTime)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].UUID);
|
Statics.redis.RemoveKey("UserSession", users[n]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LoginUser
|
|
||||||
{
|
|
||||||
public string UUID;
|
|
||||||
public DateTime moveTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ using Server.Manager;
|
||||||
using Microsoft.AspNetCore.DataProtection.KeyManagement;
|
using Microsoft.AspNetCore.DataProtection.KeyManagement;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Server.SQL.Excel;
|
using Server.SQL.Excel;
|
||||||
|
using static Server.Scheduler.SessionScheduler;
|
||||||
|
|
||||||
namespace Server.Service
|
namespace Server.Service
|
||||||
{
|
{
|
||||||
|
|
@ -95,6 +96,20 @@ namespace Server.Service
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region 세션등록
|
||||||
|
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("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 상점 세팅
|
||||||
//리셋 상점
|
//리셋 상점
|
||||||
List<ResetShopItem> resetShopItem = Statics.resetShopItemSQL.SelectUid(user.id);
|
List<ResetShopItem> resetShopItem = Statics.resetShopItemSQL.SelectUid(user.id);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Server.SQL;
|
||||||
|
using static Server.Scheduler.SessionScheduler;
|
||||||
|
|
||||||
namespace Server.System
|
namespace Server.System
|
||||||
{
|
{
|
||||||
|
|
@ -26,10 +28,32 @@ namespace Server.System
|
||||||
public Protocol cmd;
|
public Protocol cmd;
|
||||||
|
|
||||||
public string uuid;
|
public string uuid;
|
||||||
|
|
||||||
|
public User user;
|
||||||
public virtual bool IsReceivedAllField()
|
public virtual bool IsReceivedAllField()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual bool GetRedis()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Dictionary<string, object> hash = Statics.redis.GetAllHash("UserInfo", uuid);
|
||||||
|
user.id = (int)hash["id"];
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ public enum Error
|
||||||
NotFound = 404,//프로토콜 없음
|
NotFound = 404,//프로토콜 없음
|
||||||
Unknown = 500,//파라미터 오류
|
Unknown = 500,//파라미터 오류
|
||||||
ErrorData = 501,//잘못된 데이터
|
ErrorData = 501,//잘못된 데이터
|
||||||
|
NullSession = 502,//세션 만료
|
||||||
Crypto = 800,//암복호화 에러
|
Crypto = 800,//암복호화 에러
|
||||||
NoData = 900,//데이터가 없음
|
NoData = 900,//데이터가 없음
|
||||||
NoGold = 901,//소모재화가 없음
|
NoGold = 901,//소모재화가 없음
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,8 @@ namespace Server.System {
|
||||||
throw new RuntimeException("", Error.NoData);
|
throw new RuntimeException("", Error.NoData);
|
||||||
else if (!req.IsReceivedAllField())
|
else if (!req.IsReceivedAllField())
|
||||||
throw new RuntimeException("Internal Server Error", Error.Unknown);
|
throw new RuntimeException("Internal Server Error", Error.Unknown);
|
||||||
|
else if (!req.GetRedis())
|
||||||
|
throw new RuntimeException("null session", Error.NullSession);
|
||||||
|
|
||||||
Response = abstractService.Process();
|
Response = abstractService.Process();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue