로컬 redis수정

This commit is contained in:
김판돌 2024-04-13 14:04:01 +09:00
parent 2cf512d48b
commit 7064839819
5 changed files with 44 additions and 31 deletions

View File

@ -1,4 +1,3 @@
using Server.Scheduler;
using Server.System;
var builder = WebApplication.CreateBuilder(args);

View File

@ -1,9 +1,10 @@
using Server.SQL;
using NLog;
using Server.SQL;
using Server.System;
using System.Runtime.CompilerServices;
namespace Server.Scheduler
{
public class SessionScheduler : System.Scheduler
{
public override void Process()
@ -21,14 +22,14 @@ namespace Server.Scheduler
}
}
}
private static readonly NLog.ILogger logger = LogManager.GetCurrentClassLogger();
//신규 로그인
public static void addSession(User user)
public static string addSession(User user)
{
//기존 세션 확인
string loginUUID = Guid.NewGuid().ToString();
Dictionary<string, string> users = Statics.redis.GetAllHash("LoginUsers");
logger.Info($"New User : {user.nickname}, session : {loginUUID}");
foreach (var item in users)
{
if(int.Parse(item.Value) == user.id)
@ -36,7 +37,7 @@ namespace Server.Scheduler
Statics.redis.RemoveHash(item.Key);
Statics.redis.SetHash(loginUUID, user.id.ToString(), "LoginUsers");
updateSession(loginUUID);
return;
return loginUUID;
}
}
@ -51,6 +52,8 @@ namespace Server.Scheduler
userInfo.Add("pay_cash", user.pay_cash.ToString());
userInfo.Add("end_login", DateTime.Now.ToString());
Statics.redis.SetHash(userInfo, "UserInfo", user.id.ToString());
return loginUUID;
}
//세션 업데이트

View File

@ -96,11 +96,8 @@ namespace Server.Service
}
//세션 추가
addSession(user);
string session = addSession(user);
#endregion
#region
//리셋 상점
List<ResetShopItem> resetShopItem = Statics.resetShopItemSQL.SelectUid(user.id);
@ -257,7 +254,7 @@ namespace Server.Service
List<ShopItem> shopItem = Statics.shopItemSQL.SelectUid(user.id);
#endregion
return makeResp(user, dynamicDataList, deckInfoList, itemManager, newUser, resetShopItem, shopItem);
return makeResp(user, session, dynamicDataList, deckInfoList, itemManager, newUser, resetShopItem, shopItem);
}
public override Protocol ProtocolValue() => Protocol.Login;
@ -268,11 +265,12 @@ namespace Server.Service
return req;
}
private string makeResp(User user, List<DynamicData> dynamicData, List<DeckInfo> deckInfo, ItemManager itemManager, bool newUser, List<ResetShopItem> resetShopItem, List<ShopItem> shopItem)
private string makeResp(User user, string session, List<DynamicData> dynamicData, List<DeckInfo> deckInfo, ItemManager itemManager, bool newUser, List<ResetShopItem> resetShopItem, List<ShopItem> shopItem)
{
LoginResp resp = new LoginResp();
resp.nickname = user.nickname;
resp.uuid = user.uuid;
resp.session = session;
resp.gold = (ulong)user.gold;
resp.cash = (ulong)(user.free_cash + user.pay_cash);
resp.new_user = newUser;
@ -309,6 +307,7 @@ namespace Server.Service
public class LoginResp : Resp
{
public string uuid;
public string session;
public string nickname;
public ulong gold;
public ulong cash;

View File

@ -28,7 +28,7 @@ namespace Server.System
{
if (password.Equals(string.Empty))
{
Console.WriteLine("true");
Console.WriteLine("false");
redis = ConnectionMultiplexer.Connect($"{host}:{port}");
this.db = redis.GetDatabase(db);
}
@ -204,8 +204,6 @@ namespace Server.System
if (local)
{
if (hashType.ContainsKey(KeySet(keys)))
hashType.Add(KeySet(keys), new Dictionary<string, string> { { field, JsonConvert.SerializeObject(value) } });
else
{
Dictionary<string, string> userHash = hashType[KeySet(keys)];
if (userHash.ContainsKey(field))
@ -213,6 +211,8 @@ namespace Server.System
else
userHash[field] = value;
}
else
hashType.Add(KeySet(keys), new Dictionary<string, string> { { field, value } });
}
else
{
@ -231,11 +231,23 @@ namespace Server.System
Dictionary<string, string> hash = new Dictionary<string, string>();
if (local)
{
Dictionary<string, string> hashs = new Dictionary<string, string>(hashType[KeySet(keys)]);
Dictionary<string, string> hashs;
if (hashType.ContainsKey(KeySet(keys)))
{
hashs = hashType[KeySet(keys)];
foreach (var entry in hashs)
hash.Add(entry.Key, entry.Value);
}
else
{
hashs = new Dictionary<string, string>();
foreach (var entry in hashs)
hash.Add(entry.Key, entry.Value);
hashType.Add(KeySet(keys), hashs);
}
}
else
{
HashEntry[] hashEntries = db.HashGetAll(KeySet(keys));
foreach (var entry in hashEntries)

View File

@ -10,11 +10,11 @@ namespace Server.System
public static readonly string SQL_URL = "Host=192.168.1.2;Port=5432;Username=manager;Password=Zn2zs558W5SdD8K;Database=project_thewar;";
public static readonly string EXCEL_SQL_URL = "Host=192.168.1.2;Port=5432;Username=manager;Password=Zn2zs558W5SdD8K;Database=project_thewar;";
public static readonly string remoteUrl = "https://manager:BQNl01bJJF0wn9R@gitea.pandoli365.com/Team.thewar/thewar_excel.git";
public static readonly Redis redis = new Redis("192.168.1.2", 6379, 1, "xPEz3x08xQ8G1Fa");
public static readonly Redis redis = new Redis("localhost", 6379, 1, "xPEz3x08xQ8G1Fa");
#elif LIVE
public static readonly string SQL_URL = "Host=192.168.1.2;Port=5432;Username=manager;Password=Zn2zs558W5SdD8K;Database=project_thewar;";
public static readonly string EXCEL_SQL_URL = "Host=192.168.1.2;Port=5432;Username=manager;Password=Zn2zs558W5SdD8K;Database=project_thewar;";
public static readonly string remoteUrl = "https://manager:BQNl01bJJF0wn9R@gitea.pandoli365.com/Team.thewar/thewar_excel_live.git";
public static readonly string remoteUrl = "https://manager:BQNl01bJJF0wn9R@gitea.pandoli365.com/Team.thewar/thewar_excel.git";
public static readonly Redis redis = new Redis("192.168.1.2", 6379, 1, "xPEz3x08xQ8G1Fa");
#endif