From 7064839819fce8b77f69f8f8ae2b7810dddb74e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=8C=90=EB=8F=8C?= Date: Sat, 13 Apr 2024 14:04:01 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A1=9C=EC=BB=AC=20redis=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/Program.cs | 1 - Server/Scheduler/SessionScheduler.cs | 17 +++++++++------- Server/Service/Login.cs | 29 ++++++++++++++-------------- Server/System/Redis.cs | 24 +++++++++++++++++------ Server/System/Statics.cs | 4 ++-- 5 files changed, 44 insertions(+), 31 deletions(-) diff --git a/Server/Program.cs b/Server/Program.cs index 87d36ca..e190949 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -1,4 +1,3 @@ -using Server.Scheduler; using Server.System; var builder = WebApplication.CreateBuilder(args); diff --git a/Server/Scheduler/SessionScheduler.cs b/Server/Scheduler/SessionScheduler.cs index c4d692a..e5b989b 100644 --- a/Server/Scheduler/SessionScheduler.cs +++ b/Server/Scheduler/SessionScheduler.cs @@ -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,22 +22,22 @@ 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 users = Statics.redis.GetAllHash("LoginUsers"); - - foreach(var item in users) + logger.Info($"New User : {user.nickname}, session : {loginUUID}"); + 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; + 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; } //세션 업데이트 diff --git a/Server/Service/Login.cs b/Server/Service/Login.cs index f4d8ba1..8c5d2a8 100644 --- a/Server/Service/Login.cs +++ b/Server/Service/Login.cs @@ -47,7 +47,7 @@ namespace Server.Service deckInfoList = Statics.deckInfoSQL.SelectUid(user.id); itemManager = new ItemManager(user); } - if(user == null) + if (user == null) { if (req.mail == "") { @@ -78,7 +78,7 @@ namespace Server.Service #region 신규 덱 추가 DeckInfo deckInfo; deckInfo = new DeckInfo(); - deckInfo.user_id= user.id; + deckInfo.user_id = user.id; deckInfo.deck_type = 1; deckInfo.deck_unit0_id = itemManager.box.deckUnitInfo[0].id; deckInfo.deck_unit1_id = itemManager.box.deckUnitInfo[1].id; @@ -96,11 +96,8 @@ namespace Server.Service } //세션 추가 - addSession(user); + string session = addSession(user); #endregion - - - #region 상점 세팅 //리셋 상점 List resetShopItem = Statics.resetShopItemSQL.SelectUid(user.id); @@ -112,10 +109,10 @@ namespace Server.Service //일일 상품 추가 if (shopItemData == null) shopItemData = Statics.resetShopItemExcel.getResetShopItemData(); - List < ResetShopItemData > shopList = new List(); - foreach(var item in shopItemData) + List shopList = new List(); + foreach (var item in shopItemData) { - if(item.shop_index == 10001) + if (item.shop_index == 10001) { shopList.Add(item); } @@ -127,7 +124,7 @@ namespace Server.Service { int select = rand.Next(0, shopList.Count); int index = addItem.FindIndex(data => data.reset_shop_item_data_id == shopList[select].index); - if (index != -1) + if (index != -1) { addItem[index].count++; } @@ -247,7 +244,7 @@ namespace Server.Service } } } - if(addItem.Count != 0) + if (addItem.Count != 0) { Statics.resetShopItemSQL.Insert(addItem); Statics.resetShopItemSQL.SaveChanges(); @@ -257,22 +254,23 @@ namespace Server.Service List 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; - + public override Req Requst(string json) { req = JsonConvert.DeserializeObject(json); return req; } - private string makeResp(User user, List dynamicData, List deckInfo, ItemManager itemManager, bool newUser, List resetShopItem, List shopItem) + private string makeResp(User user, string session, List dynamicData, List deckInfo, ItemManager itemManager, bool newUser, List resetShopItem, List 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; @@ -296,7 +294,7 @@ namespace Server.Service public string mail; public override bool IsReceivedAllField() { - if(mail == null && uuid == null) + if (mail == null && uuid == null) return false; return true; } @@ -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; diff --git a/Server/System/Redis.cs b/Server/System/Redis.cs index ed7f7c2..876bca1 100644 --- a/Server/System/Redis.cs +++ b/Server/System/Redis.cs @@ -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 { { field, JsonConvert.SerializeObject(value) } }); - else { Dictionary 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 { { field, value } }); } else { @@ -231,9 +231,21 @@ namespace Server.System Dictionary hash = new Dictionary(); if (local) { - Dictionary hashs = new Dictionary(hashType[KeySet(keys)]); - foreach (var entry in hashs) - hash.Add(entry.Key, entry.Value); + Dictionary 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(); + foreach (var entry in hashs) + hash.Add(entry.Key, entry.Value); + hashType.Add(KeySet(keys), hashs); + } + } else { diff --git a/Server/System/Statics.cs b/Server/System/Statics.cs index 29a36a3..06b8bda 100644 --- a/Server/System/Statics.cs +++ b/Server/System/Statics.cs @@ -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