This commit is contained in:
Putoo
2026-05-30 17:32:27 +08:00
parent bd1535aee9
commit f8d4a28d53
79 changed files with 1369 additions and 134 deletions

View File

@@ -9,4 +9,8 @@ public static class GameConfig
public const int SendChatGoodsService = 10002;//金海螺
public const int UpLevAddWeight = 10;//升级增加负重
public const int GameBaseVigour = 50;//初始活力
public const int GameRelationEnemyNeedGold = 50;//添加仇人所需金元
public const int GameUpdateNickNeedGoods = 10001;//更新昵称所需道具
public const int GameUpdateSexNeedGoods = 10001;//更新性别所需道具
public const int GameUserFriendMaxCount = 50;//好友最大上限人数
}

View File

@@ -6,4 +6,12 @@ public static class UserEnum
{
Person
}
public enum ConfigCode
{
FriendRole,
ChatRole,
AutoBag,
AutoDrug,
}
}

View File

@@ -15,7 +15,13 @@ public class MessageHandle
if (state == 1)
{
if (await relationService.AddFriend(events.userId, events.pars))
var friendCount = await relationService.GetUserFriendCount(events.pars);
if (friendCount >= GameConfig.GameUserFriendMaxCount)
{
return new MessageHandleResult() { success = false, msg = "Ta的好友人数已达上限!" };
}
if (await relationService.AddFriend(events.pars,events.userId ))
{
var chatService = App.GetService<IGameChatService>();
var userService = App.GetService<IUnitUserService>();
@@ -39,7 +45,7 @@ public class MessageHandle
return new MessageHandleResult() { success = true, msg = "已拒绝该好友申请!" };
}
}
else if (events.code == nameof(MessageEnum.EventCode.Friend))
else if (events.code == nameof(MessageEnum.EventCode.Trade))
{
return new MessageHandleResult() { success = true, msg = "消息通知已处理!" };
}

View File

@@ -10,5 +10,6 @@ public interface IGameChatService
Task<bool> SendChat(string userId, int areaId, string code, string sign, string par = "");
Task<bool> SendChat(string userId, string code, string sign, string par = "");
Task<bool> DeleteChat(string chatId);
Task<game_chat> GetChatInfo(string chatId);
Task<bool> DeleteChat(string chatId, string opUser);
}

View File

@@ -13,4 +13,12 @@ public interface IAreaService
/// <param name="areaId"></param>
/// <returns></returns>
Task<game_area> GetAreaInfo(int areaId);
#region
Task<game_ack> GetAckInfo(string code);
Task<bool> UseAck(string code, string userId);
#endregion
}

View File

@@ -0,0 +1,6 @@
namespace Application.Domain;
public interface IGameMaxNameService
{
}

View File

@@ -11,4 +11,13 @@ public interface IUnitUserRelationService
Task<bool> DeleteFriend(string userId, string toId);
#endregion
#region
Task<List<RelationView>> GetUserEnemyData(string userId);
Task<bool> CheckUserEnemy(string userId, string eId);
Task<bool> AddUserEnemy(string userId, string eId);
Task<bool> DeleteUserEnemy(string userId, string eId);
#endregion
}

View File

@@ -8,8 +8,10 @@ public interface IUnitUserService
Task<unit_user> GetUserInfoByUserId(string userId);
Task<unit_user> GetUserInfoByUserNo(string userNo);
Task<unit_user> GetUserInfoByToken(string token);
Task<bool> CheckUserNickIsAt(string nick);
Task<bool> UpdateUserNick(string userId, string nick);
Task<bool> UpdateUserSex(string userId, string sex);
Task<bool> UpdateUserSign(string userId, string sign);
#endregion
#region
@@ -31,5 +33,16 @@ public interface IUnitUserService
Task<int> GetOnlineCount();
#endregion
#region
Task<unit_user_config> GetUserConfigInfo(string userId);
Task<int> GetUserConfigInfo(string userId, string code);
Task<bool> UpdateUserConfigInfo(string userId, string code, int state);
#endregion
}

View File

@@ -123,6 +123,7 @@ public class GameChatService : IGameChatService, ITransient
chat.addTime = DateTime.Now;
chat.sort = TimeExtend.GetTimeStampSeconds;
chat.delTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays(3));
chat.opUser = "";
switch (code)
{
case "Region":
@@ -146,7 +147,7 @@ public class GameChatService : IGameChatService, ITransient
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_chat>();
return await db.Insertable(chat).ExecuteCommandAsync() > 0;
}
public async Task<bool> SendChat(string userId, string code, string sign, string par = "")
{
var userService = App.GetService<IUnitUserService>();
@@ -156,15 +157,24 @@ public class GameChatService : IGameChatService, ITransient
return await SendChat(userId, (int)userInfo.areaId, code, sign, par);
}
public async Task<game_chat> GetChatInfo(string chatId)
{
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_chat>();
return await db.Queryable<game_chat>().Where(it => it.chatId == chatId).SingleAsync();
}
/// <summary>
/// 删除聊天
/// </summary>
/// <param name="chatId"></param>
/// <param name="opUser"></param>
/// <returns></returns>
public async Task<bool> DeleteChat(string chatId)
public async Task<bool> DeleteChat(string chatId, string opUser)
{
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_chat>();
return await db.Updateable<game_chat>().SetColumns(it => it.state == 0).Where(it => it.chatId == chatId)
return await db.Updateable<game_chat>().SetColumns(it => it.state == 0)
.SetColumns(it => it.opUser == opUser)
.Where(it => it.chatId == chatId)
.ExecuteCommandAsync() > 0;
}
}

View File

@@ -57,4 +57,25 @@ public class AreaService : IAreaService, ITransient
await _redisClient.DelAsync(key);
}
}
#region
public async Task<game_ack> GetAckInfo(string code)
{
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_ack>();
return await db.Queryable<game_ack>().Where(it => it.ackCode == code).SingleAsync();
}
public async Task<bool> UseAck(string code, string userId)
{
DateTime time = DateTime.Now;
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_ack>();
return await db.Updateable<game_ack>().SetColumns(it => it.status == 1)
.SetColumns(it => it.useTime == time)
.SetColumns(it => it.useUser == userId)
.Where(it => it.ackCode == code)
.ExecuteCommandAsync() > 0;
}
#endregion
}

View File

@@ -0,0 +1,6 @@
namespace Application.Domain;
public class GameMaxNameService(ISqlSugarClient DbClient, IRedisCache redis) : IGameMaxNameService, ITransient
{
}

View File

@@ -5,27 +5,27 @@ public class UnitUserAccService(ISqlSugarClient DbClient, IRedisCache redis) : I
public async Task<long> GetUserAccInfo(string userId, string accType)
{
long result = 0;
if (accType == AccEnum.AccType.copper.ToString())
if (accType == nameof(AccEnum.AccType.copper))
{
var info = await GetUserCopperInfo(userId);
result = (long)info.copper;
}
else if (accType == AccEnum.AccType.cowry.ToString())
else if (accType == nameof(AccEnum.AccType.cowry))
{
var info = await GetUserAccInfo(userId);
result = (long)info.cowry;
}
else if (accType == AccEnum.AccType.gold.ToString())
else if (accType == nameof(AccEnum.AccType.gold))
{
var info = await GetUserAccInfo(userId);
result = (long)info.gold;
}
else if (accType == AccEnum.AccType.teach.ToString())
else if (accType == nameof(AccEnum.AccType.teach))
{
var info = await GetUserAccInfo(userId);
result = (long)info.teach;
}
else if (accType == AccEnum.AccType.renown.ToString())
else if (accType == nameof(AccEnum.AccType.renown))
{
var info = await GetUserAccInfo(userId);
result = (long)info.renown;
@@ -53,10 +53,10 @@ public class UnitUserAccService(ISqlSugarClient DbClient, IRedisCache redis) : I
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_acc>();
await DbClient.AsTenant().BeginTranAsync();
isOk = await db.Updateable<unit_user_acc>()
.SetColumnsIF(accType.Equals(AccEnum.AccType.cowry.ToString()), it => it.cowry == it.cowry + opCount)
.SetColumnsIF(accType.Equals(AccEnum.AccType.gold.ToString()), it => it.gold == it.gold + opCount)
.SetColumnsIF(accType.Equals(AccEnum.AccType.teach.ToString()), it => it.teach == it.teach + opCount)
.SetColumnsIF(accType.Equals(AccEnum.AccType.renown.ToString()), it => it.renown == it.renown + opCount)
.SetColumnsIF(accType.Equals(nameof(AccEnum.AccType.cowry)), it => it.cowry == it.cowry + opCount)
.SetColumnsIF(accType.Equals(nameof(AccEnum.AccType.gold)), it => it.gold == it.gold + opCount)
.SetColumnsIF(accType.Equals(nameof(AccEnum.AccType.teach)), it => it.teach == it.teach + opCount)
.SetColumnsIF(accType.Equals(nameof(AccEnum.AccType.renown)), it => it.renown == it.renown + opCount)
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
//生成日志
if (isOk)

View File

@@ -59,7 +59,64 @@ public class UnitUserRelationService(ISqlSugarClient DbClient, IRedisCache redis
{
string frId = StringAssist.GetSortKey(userId, toId);
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_friend>();
return await db.Deleteable<unit_user_friend>().Where(it => it.frId == frId).ExecuteCommandAsync()>0;
return await db.Deleteable<unit_user_friend>().Where(it => it.frId == frId).ExecuteCommandAsync() > 0;
}
#endregion
#region
public async Task<List<RelationView>> GetUserEnemyData(string userId)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_enemy>();
var data = await db.Queryable<unit_user_enemy>().Where(it => it.userId == userId)
.OrderByDescending(it => it.addTime)
.ToListAsync();
List<RelationView> result = new List<RelationView>();
foreach (var item in data)
{
RelationView temp = new RelationView();
temp.user = await UserModelTool.GetUserView(item.eId);
temp.near = 0;
var mapService = App.GetService<IGameMapService>();
var onMap = await mapService.GetUserOnMapInfo(item.eId);
temp.mapName = onMap.mapName;
temp.cityName = onMap.cityName;
temp.sort = TimeExtend.GetTimeStampBySeconds((DateTime)item.addTime);
temp.isOnline = onMap.isOnline;
result.Add(temp);
}
return result;
}
public async Task<bool> CheckUserEnemy(string userId, string eId)
{
string euId = $"{userId}_{eId}";
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_enemy>();
return await db.Queryable<unit_user_enemy>().Where(it => it.euId == euId).AnyAsync();
}
public async Task<bool> AddUserEnemy(string userId, string eId)
{
string euId = $"{userId}_{eId}";
unit_user_enemy enemy = new unit_user_enemy()
{
euId = euId,
userId = userId,
eId = eId,
addTime = DateTime.Now
};
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_enemy>();
return await db.Insertable(enemy).ExecuteCommandAsync() > 0;
}
public async Task<bool> DeleteUserEnemy(string userId, string eId)
{
string euId = $"{userId}_{eId}";
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_enemy>();
return await db.Deleteable<unit_user_enemy>().Where(it => it.euId == euId).ExecuteCommandAsync() > 0;
}
#endregion

View File

@@ -2,36 +2,28 @@
namespace Application.Domain;
public class UnitUserService : IUnitUserService, ITransient
public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUnitUserService, ITransient
{
private readonly ISqlSugarClient _dbClient;
private readonly IRedisCache _redisClient;
public UnitUserService(ISqlSugarClient dbClient, IRedisCache redisClient)
{
_dbClient = dbClient;
_redisClient = redisClient;
}
#region
public async Task<List<unit_user>> GetUserDataByAccId(string accId)
{
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
return await db.Queryable<unit_user>().Where(it => it.accId == accId).ToListAsync();
}
public async Task<unit_user> GetUserInfoByUserId(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserId");
var data = await _redisClient.GetHashAsync<unit_user>(key, userId);
var data = await redis.GetHashAsync<unit_user>(key, userId);
if (data == null)
{
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
data = await db.Queryable<unit_user>().Where(it => it.userId == userId).SingleAsync();
if (data != null)
{
await _redisClient.AddHashAsync(key, userId, data);
await redis.AddHashAsync(key, userId, data);
}
}
@@ -41,14 +33,14 @@ public class UnitUserService : IUnitUserService, ITransient
public async Task<unit_user> GetUserInfoByUserNo(string userNo)
{
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserNo");
var data = await _redisClient.GetHashAsync<unit_user>(key, userNo);
var data = await redis.GetHashAsync<unit_user>(key, userNo);
if (data == null)
{
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
data = await db.Queryable<unit_user>().Where(it => it.userNo == userNo).SingleAsync();
if (data != null)
{
await _redisClient.AddHashAsync(key, userNo, data);
await redis.AddHashAsync(key, userNo, data);
}
}
@@ -58,14 +50,14 @@ public class UnitUserService : IUnitUserService, ITransient
public async Task<unit_user> GetUserInfoByToken(string token)
{
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "token");
var data = await _redisClient.GetHashAsync<unit_user>(key, token);
var data = await redis.GetHashAsync<unit_user>(key, token);
if (data == null)
{
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
data = await db.Queryable<unit_user>().Where(it => it.token == token).SingleAsync();
if (data != null)
{
await _redisClient.AddHashAsync(key, token, data);
await redis.AddHashAsync(key, token, data);
}
}
@@ -86,9 +78,52 @@ public class UnitUserService : IUnitUserService, ITransient
break;
}
await _redisClient.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserId"), result.userId);
await _redisClient.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserNo"), result.userNo);
await _redisClient.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo", "Sid"), result.token);
await redis.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserId"), result.userId);
await redis.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserNo"), result.userNo);
await redis.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo", "Sid"), result.token);
}
public async Task<bool> CheckUserNickIsAt(string nick)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
return await db.Queryable<unit_user>().Where(it => it.nick.Contains(nick)).AnyAsync();
}
public async Task<bool> UpdateUserNick(string userId, string nick)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
bool result = await db.Updateable<unit_user>().SetColumns(it => it.nick == nick)
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
if (result)
{
await ClearUserInfo(0, userId);
}
return result;
}
public async Task<bool> UpdateUserSex(string userId, string sex)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
bool result = await db.Updateable<unit_user>().SetColumns(it => it.sex == sex)
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
if (result)
{
await ClearUserInfo(0, userId);
}
return result;
}
public async Task<bool> UpdateUserSign(string userId, string sign)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
bool result = await db.Updateable<unit_user>().SetColumns(it => it.sign == sign)
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
if (result)
{
await ClearUserInfo(0, userId);
}
return result;
}
#endregion
@@ -100,8 +135,8 @@ public class UnitUserService : IUnitUserService, ITransient
unit_user result = new unit_user();
try
{
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
await _dbClient.AsTenant().BeginTranAsync();
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
await DbClient.AsTenant().BeginTranAsync();
string userId = StringAssist.NewGuid;
result.userId = userId;
result.areaId = areaId;
@@ -123,12 +158,12 @@ public class UnitUserService : IUnitUserService, ITransient
result = null;
}
await _dbClient.AsTenant().CommitTranAsync();
await DbClient.AsTenant().CommitTranAsync();
}
catch
{
result = null;
await _dbClient.AsTenant().RollbackTranAsync();
await DbClient.AsTenant().RollbackTranAsync();
}
return result;
@@ -136,7 +171,7 @@ public class UnitUserService : IUnitUserService, ITransient
public async Task<bool> RegisterUserInfo(string userId, string nick, string sex)
{
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
bool result = await db.Updateable<unit_user>().SetColumns(it => it.nick == nick)
.SetColumns(it => it.sex == sex)
.SetColumns(it => it.regOk == 1)
@@ -163,6 +198,15 @@ public class UnitUserService : IUnitUserService, ITransient
unit_user_attr userAttr = GameTool.GetAttrData(1);
userAttr.userId = userId;
db.Insertable(userAttr).AddQueue();
//注册配置
unit_user_config config = new unit_user_config();
config.userId = userId;
config.friendRole = 1;
config.chatRole = 0;
config.autoBag = -1;
config.autoDrug = -1;
db.Insertable(config).AddQueue();
//注册个人血量
unit_user_blood blood = new unit_user_blood();
@@ -248,10 +292,78 @@ public class UnitUserService : IUnitUserService, ITransient
public async Task<int> GetOnlineCount()
{
long time = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddMinutes(0-GameConfig.OnLineTime));
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
long time = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddMinutes(0 - GameConfig.OnLineTime));
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
return await db.Queryable<unit_user_online>().Where(it => it.upTime > time).CountAsync();
}
#endregion
#region
public async Task<unit_user_config> GetUserConfigInfo(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "Config");
var data = await redis.GetHashAsync<unit_user_config>(key, userId);
if (data == null)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_config>();
data = await db.Queryable<unit_user_config>().Where(it => it.userId == userId).SingleAsync();
if (data != null)
{
await redis.AddHashAsync(key, userId, data);
}
}
return data;
}
public async Task<int> GetUserConfigInfo(string userId, string code)
{
int result = 0;
var config = await GetUserConfigInfo(userId);
switch (code)
{
case "FriendRole":
result = (int)config.friendRole;
break;
case "ChatRole":
result = (int)config.chatRole;
break;
case "AutoBag":
result = (int)config.autoBag;
break;
case "AutoDrug":
result = (int)config.autoDrug;
break;
}
return result;
}
private async Task ClearUserConfig(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "Config");
await redis.DelHashAsync(key, userId);
}
public async Task<bool> UpdateUserConfigInfo(string userId, string code, int state)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_config>();
bool result = await db.Updateable<unit_user_config>()
.SetColumnsIF(code == "FriendRole", it => it.friendRole == state)
.SetColumnsIF(code == "ChatRole", it => it.chatRole == state)
.SetColumnsIF(code == "AutoBag", it => it.autoBag == state)
.SetColumnsIF(code == "AutoDrug", it => it.autoDrug == state)
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
if (result)
{
await ClearUserConfig(userId);
}
return result;
}
#endregion
}

View File

@@ -19,6 +19,7 @@ public class UserModelTool
result.headImg = "";
result.area = 0;
result.icon = "";
result.sign = "会陪你在航海的世界里浪迹天涯~";
result.lev = 999;
}
else
@@ -31,6 +32,7 @@ public class UserModelTool
result.userNo = userInfo.userNo;
result.nick = userInfo.nick;
result.sex = userInfo.sex;
result.sign = userInfo.sign;
result.headImg = userInfo.headImg;
result.area = (int)userInfo.areaId;
result.icon = "";
@@ -38,6 +40,7 @@ public class UserModelTool
{
result.icon = "";
}
result.lev = await attrService.GetUserLev(userId);
}
}