public override async void Run(long uid, long configId, int count) { var lobbyComponent = Game.Scene.GetComponent <LobbyComponent>(); if (lobbyComponent == null) { Console.WriteLine($"The command needs to use lobbyComponent"); return; } if (uid <= 0) { Console.WriteLine($"uid:{uid} <= 0 is invalid"); return; } if (!EquipmentDataHelper.TryGetEquipmentConfig(configId, out CharacterConfig characterConfig)) { Console.WriteLine($"configId:{configId} is invalid"); return; } if (count <= 0) { Console.WriteLine($"count:{count} <= 0 is invalid"); return; } var result = await EquipmentDataHelper.DeleteEquipment(uid, new List <EquipmentInfo> { new EquipmentInfo { Id = 0, ConfigId = configId, Count = count } }, EquipmentDataHelper.EquipmentFrom.System, (int)EquipmentDataHelper.SystemUid.Console, true); if (result.error == ErrorCode.ERR_Success) { GateMessageHelper.BroadcastTarget(new L2C_OnEquipmentsDeleted { FromUid = (int)EquipmentDataHelper.SystemUid.Console, EquipmentInfoList = result.equipmentInfos, UserBagInfo = result.userBagInfo, }, uid); Console.WriteLine($"ok"); } else { Console.WriteLine($"error code: {result.error}"); } }
protected override async ETTask <bool> _IsValid() { var command = new BsonDocument { { "find", "User" } }; BsonDocument results = await db.database.RunCommandAsync <BsonDocument>(command); List <BsonDocument> users = BsonSerializer.Deserialize <List <BsonDocument> >(results["cursor"]["firstBatch"].ToJson()); if (users.Count == 0) { return(true); } var configComponent = Game.Scene.GetComponent <ConfigComponent>(); var bagLimitSettings = configComponent.GetAll(typeof(BagLimitSetting)).OfType <BagLimitSetting>().ToList(); bool valid = users.All(e => { if (e.TryGetValue("userBagCapacity", out BsonValue val)) { var doc = val.ToBsonDocument(); if (doc == null) { return(false); } for (int i = 0; i < bagLimitSettings.Count; i++) { var bagLimitSetting = bagLimitSettings[i]; Equipment.EquipmentType equipmentType = (Equipment.EquipmentType)bagLimitSetting.Id; var usedCountString = EquipmentDataHelper.GetUsedCountString(equipmentType); var totalCountString = EquipmentDataHelper.GetTotalCountString(equipmentType); if (doc[usedCountString].AsInt32 <0 || doc[usedCountString].AsInt32> doc[totalCountString].AsInt32) { return(false); } if (doc[totalCountString].AsInt32 > bagLimitSetting.MaxSlotCount) { return(false); } } return(true); } return(false); }); if (!valid) { failedReason = $"DBSchema.User.userBagCapacity with invalid slot count or no the element on document!"; } return(valid); }
private async ETTask RunAsync(Player player, C2L_GetUserAllEquipment message, Action <L2C_GetUserAllEquipment> reply) { L2C_GetUserAllEquipment response = new L2C_GetUserAllEquipment(); try { long uid = player.uid; response.Uid = uid; response.EquipmentInfoList = await EquipmentDataHelper.GetUserAllEquipmentInfo(uid); reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
public async static ETTask <int> AuthenticationByBot(string deviceUniqueIdentifier) { long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); ThirdPartyUser thirdPartyUser = await UserDataHelper.FindOneThirdPartyUser(deviceUniqueIdentifier, UserDataHelper.tagGuest); User user = null; if (thirdPartyUser == null) { user = ComponentFactory.CreateWithId <User>(IdGenerater.GenerateId()); string salt = CryptographyHelper.GenerateRandomId(); string password = CryptographyHelper.GenerateRandomId(16); string hashPassword = CryptographyHelper.MD5Encoding(password, salt); user.salt = salt; user.hashPassword = hashPassword; user.createAt = now; user.name = $"{user.Id}"; user.playerCharSetting = new PlayerCharSetting(); user.playerCharSetting.CharacterId = 1L; user.playerRideTotalInfo = new RideTotalInfo(); user.language = 10; user.identity = (int)User.Identity.TestPlayer; user.userBagCapacity = EquipmentDataHelper.GetDefaultUserBag(); await UserDataHelper.SinUserUp(user); //註冊第三方-Guest thirdPartyUser = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId()); thirdPartyUser.uid = user.Id; thirdPartyUser.party = UserDataHelper.tagGuest; thirdPartyUser.userId = deviceUniqueIdentifier; thirdPartyUser.name = ""; thirdPartyUser.gender = ""; thirdPartyUser.location = ""; thirdPartyUser.email = ""; thirdPartyUser.birthday = ""; thirdPartyUser.createAt = now; await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser); return(ErrorCode.ERR_Success); } else { return(ErrorCode.ERR_DeviceUniqueIdentifierIsExist); } }
protected override async ETTask _Run() { var userBagCapacity = EquipmentDataHelper.GetDefaultUserBag(); var command = new BsonDocument { { "update", "User" }, { "updates", new BsonArray { new BsonDocument { { "q", new BsonDocument { } }, { "u", new BsonDocument { { "$set", new BsonDocument { { "userBagCapacity", userBagCapacity }, } } } }, { "upsert", false }, { "multi", true } } } }, }; var result = await db.database.RunCommandAsync <BsonDocument>(command); Console.WriteLine(result.ToJson()); }
/// <summary> /// 使用AppleID登入 /// </summary> /// <param name="session"></param> /// <param name="info"></param> /// <param name="response"></param> /// <returns></returns> public async static ETTask AuthenticationByAppleId(Session session, AuthenticationInfo info, R2C_Authentication response) { string appleId = CryptographyHelper.AESDecrypt(info.Secret); ThirdPartyInfo appleInfo = new ThirdPartyInfo { id = appleId, }; long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); ThirdPartyUser thirdPartyUser = await UserDataHelper.FindOneThirdPartyUser(appleInfo.id, UserDataHelper.tagAppleId); User user = null; if (thirdPartyUser == null) { // 用AppleId註冊帳號 user = ComponentFactory.CreateWithId <User>(IdGenerater.GenerateId()); string salt = CryptographyHelper.GenerateRandomId(); string password = CryptographyHelper.GenerateRandomId(16); string hashPassword = CryptographyHelper.MD5Encoding(password, salt); user.salt = salt; user.hashPassword = hashPassword; user.email = appleInfo.email; user.name = user.Id.ToString(); user.gender = appleInfo.genderCode; user.location = appleInfo.locationCode; user.birthday = appleInfo.birthdayCode; user.createAt = now; user.playerCharSetting = new PlayerCharSetting(); user.playerCharSetting.CharacterId = 1L; user.playerRideTotalInfo = new RideTotalInfo(); user.language = info.Language; user.identity = (int)User.Identity.Player; user.userBagCapacity = EquipmentDataHelper.GetDefaultUserBag(); await UserDataHelper.SinUserUp(user); // 註冊第三方-AppleId thirdPartyUser = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId()); thirdPartyUser.uid = user.Id; thirdPartyUser.party = UserDataHelper.tagAppleId; thirdPartyUser.userId = appleInfo.id; thirdPartyUser.gender = appleInfo.gender; thirdPartyUser.location = appleInfo.location; thirdPartyUser.email = appleInfo.email; thirdPartyUser.name = appleInfo.name; thirdPartyUser.birthday = appleInfo.birthday; thirdPartyUser.createAt = now; await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser); // 註冊第三方-Guest thirdPartyUser = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId()); thirdPartyUser.uid = user.Id; thirdPartyUser.party = UserDataHelper.tagGuest; thirdPartyUser.userId = info.DeviceId; thirdPartyUser.name = ""; thirdPartyUser.gender = ""; thirdPartyUser.location = ""; thirdPartyUser.email = ""; thirdPartyUser.birthday = ""; thirdPartyUser.createAt = now; await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser); } else { user = await UserDataHelper.FindOneUser(thirdPartyUser.uid); } await SignInByUid(session, user, response, info.FirebaseDeviceToken, true, UserDataHelper.tagAppleId); }
public async static ETTask AuthenticationByFaceBook(Session session, AuthenticationInfo info, R2C_Authentication response) { string fbToken = info.Secret; bool isValidToken = await FacebookHelper.ValidateFacebookToken(fbToken); if (!isValidToken) { response.Error = ErrorCode.ERR_FBSignInFailed; return; } ThirdPartyInfo fbInfo = await FacebookHelper.GetFacebookUserInfo(fbToken); if (fbInfo == null) { response.Error = ErrorCode.ERR_FBSignInFailed; return; } long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); ThirdPartyUser thirdPartyUser = await UserDataHelper.FindOneThirdPartyUser(fbInfo.id, UserDataHelper.tagFB); User user = null; if (thirdPartyUser == null) { // 用FB註冊帳號 user = ComponentFactory.CreateWithId <User>(IdGenerater.GenerateId()); string salt = CryptographyHelper.GenerateRandomId(); string password = CryptographyHelper.GenerateRandomId(16); string hashPassword = CryptographyHelper.MD5Encoding(password, salt); user.salt = salt; user.hashPassword = hashPassword; user.email = fbInfo.email; user.name = fbInfo.name; user.gender = fbInfo.genderCode; user.location = fbInfo.locationCode; user.birthday = fbInfo.birthdayCode; user.createAt = now; user.playerCharSetting = new PlayerCharSetting(); user.playerCharSetting.CharacterId = 1L; user.playerRideTotalInfo = new RideTotalInfo(); user.language = info.Language; user.identity = (int)User.Identity.Player; user.userBagCapacity = EquipmentDataHelper.GetDefaultUserBag(); await UserDataHelper.SinUserUp(user); //註冊第三方-FB thirdPartyUser = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId()); thirdPartyUser.uid = user.Id; thirdPartyUser.party = UserDataHelper.tagFB; thirdPartyUser.userId = fbInfo.id; thirdPartyUser.gender = fbInfo.gender; thirdPartyUser.location = fbInfo.location; thirdPartyUser.email = fbInfo.email; thirdPartyUser.name = fbInfo.name; thirdPartyUser.birthday = fbInfo.birthday; thirdPartyUser.createAt = now; await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser); //註冊第三方-Guest thirdPartyUser = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId()); thirdPartyUser.uid = user.Id; thirdPartyUser.party = UserDataHelper.tagGuest; thirdPartyUser.userId = info.DeviceId; thirdPartyUser.name = ""; thirdPartyUser.gender = ""; thirdPartyUser.location = ""; thirdPartyUser.email = ""; thirdPartyUser.birthday = ""; thirdPartyUser.createAt = now; await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser); } else { user = await UserDataHelper.FindOneUser(thirdPartyUser.uid); } await SignInByUid(session, user, response, info.FirebaseDeviceToken, true, UserDataHelper.tagFB); }
public async static ETTask AuthenticationByGuest(Session session, AuthenticationInfo info, R2C_Authentication response) { string deviceUniqueIdentifier = string.Empty; try { deviceUniqueIdentifier = CryptographyHelper.AESDecrypt(info.Secret); } catch (Exception) { response.Error = ErrorCode.ERR_InvalidDeviceUniqueIdentifier; return; } if (string.IsNullOrEmpty(deviceUniqueIdentifier)) { response.Error = ErrorCode.ERR_DeviceUniqueIdentifierIsNull; return; } long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); ThirdPartyUser thirdPartyUser = await UserDataHelper.FindOneThirdPartyUser(deviceUniqueIdentifier, UserDataHelper.tagGuest); User user = null; if (thirdPartyUser == null) { user = ComponentFactory.CreateWithId <User>(IdGenerater.GenerateId()); string salt = CryptographyHelper.GenerateRandomId(); string password = CryptographyHelper.GenerateRandomId(16); string hashPassword = CryptographyHelper.MD5Encoding(password, salt); user.salt = salt; user.hashPassword = hashPassword; user.createAt = now; user.name = $"{user.Id}"; user.email = ""; user.playerCharSetting = new PlayerCharSetting(); user.playerCharSetting.CharacterId = 1L; user.playerRideTotalInfo = new RideTotalInfo(); user.language = info.Language; user.identity = (int)User.Identity.Player; user.userBagCapacity = EquipmentDataHelper.GetDefaultUserBag(); await UserDataHelper.SinUserUp(user); //註冊第三方-Guest thirdPartyUser = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId()); thirdPartyUser.uid = user.Id; thirdPartyUser.party = UserDataHelper.tagGuest; thirdPartyUser.userId = deviceUniqueIdentifier; thirdPartyUser.name = ""; thirdPartyUser.gender = ""; thirdPartyUser.location = ""; thirdPartyUser.email = ""; thirdPartyUser.birthday = ""; thirdPartyUser.createAt = now; await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser); } else { user = await UserDataHelper.FindOneUser(thirdPartyUser.uid); } await SignInByUid(session, user, response, info.FirebaseDeviceToken, true, UserDataHelper.tagGuest); }