public async UniTaskVoid HandleRequestAcceptGuildInvitation(RequestHandlerData requestHandler, RequestAcceptGuildInvitationMessage request, RequestProceedResultDelegate <ResponseAcceptGuildInvitationMessage> result) { #if UNITY_STANDALONE && !CLIENT_BUILD await UniTask.Yield(); BasePlayerCharacterEntity playerCharacter; if (!GameInstance.ServerUserHandlers.TryGetPlayerCharacter(requestHandler.ConnectionId, out playerCharacter)) { result.Invoke(AckResponseCode.Error, new ResponseAcceptGuildInvitationMessage() { message = UITextKeys.UI_ERROR_NOT_LOGGED_IN, }); return; } ValidateGuildRequestResult validateResult = GameInstance.ServerGuildHandlers.CanAcceptGuildInvitation(request.guildId, playerCharacter); if (!validateResult.IsSuccess) { result.Invoke(AckResponseCode.Error, new ResponseAcceptGuildInvitationMessage() { message = validateResult.GameMessage, }); return; } playerCharacter.GuildId = request.guildId; validateResult.Guild.AddMember(playerCharacter); GameInstance.ServerGuildHandlers.SetGuild(request.guildId, validateResult.Guild); GameInstance.ServerGuildHandlers.RemoveGuildInvitation(request.guildId, playerCharacter.Id); // Save to database _ = DbServiceClient.UpdateCharacterGuildAsync(new UpdateCharacterGuildReq() { SocialCharacterData = SocialCharacterData.Create(playerCharacter), GuildId = request.guildId, GuildRole = validateResult.Guild.GetMemberRole(playerCharacter.Id) }); // Broadcast via chat server if (ChatNetworkManager.IsClientConnected) { ChatNetworkManager.SendAddSocialMember(null, MMOMessageTypes.UpdateGuildMember, request.guildId, playerCharacter.Id, playerCharacter.CharacterName, playerCharacter.DataId, playerCharacter.Level); } GameInstance.ServerGameMessageHandlers.SendSetGuildData(requestHandler.ConnectionId, validateResult.Guild); GameInstance.ServerGameMessageHandlers.SendAddGuildMembersToOne(requestHandler.ConnectionId, validateResult.Guild); GameInstance.ServerGameMessageHandlers.SendAddGuildMemberToMembers(validateResult.Guild, playerCharacter.Id, playerCharacter.CharacterName, playerCharacter.DataId, playerCharacter.Level); result.Invoke(AckResponseCode.Success, new ResponseAcceptGuildInvitationMessage() { message = UITextKeys.UI_GUILD_INVITATION_ACCEPTED, }); #endif }
public async UniTaskVoid HandleRequestCreateParty(RequestHandlerData requestHandler, RequestCreatePartyMessage request, RequestProceedResultDelegate <ResponseCreatePartyMessage> result) { #if UNITY_STANDALONE && !CLIENT_BUILD await UniTask.Yield(); IPlayerCharacterData playerCharacter; if (!GameInstance.ServerUserHandlers.TryGetPlayerCharacter(requestHandler.ConnectionId, out playerCharacter)) { result.Invoke(AckResponseCode.Error, new ResponseCreatePartyMessage() { message = UITextKeys.UI_ERROR_NOT_LOGGED_IN, }); return; } ValidatePartyRequestResult validateResult = playerCharacter.CanCreateParty(); if (!validateResult.IsSuccess) { result.Invoke(AckResponseCode.Error, new ResponseCreatePartyMessage() { message = validateResult.GameMessage, }); return; } PartyResp createPartyResp = await DbServiceClient.CreatePartyAsync(new CreatePartyReq() { LeaderCharacterId = playerCharacter.Id, ShareExp = request.shareExp, ShareItem = request.shareItem }); PartyData party = DatabaseServiceUtils.FromByteString <PartyData>(createPartyResp.PartyData); GameInstance.ServerPartyHandlers.SetParty(party.id, party); playerCharacter.PartyId = party.id; // Broadcast via chat server if (ChatNetworkManager.IsClientConnected) { ChatNetworkManager.SendCreateParty(null, MMOMessageTypes.UpdateParty, party.id, party.shareExp, party.shareItem, playerCharacter.Id); ChatNetworkManager.SendAddSocialMember(null, MMOMessageTypes.UpdatePartyMember, party.id, playerCharacter.Id, playerCharacter.CharacterName, playerCharacter.DataId, playerCharacter.Level); } GameInstance.ServerGameMessageHandlers.SendSetPartyData(requestHandler.ConnectionId, party); GameInstance.ServerGameMessageHandlers.SendAddPartyMembersToOne(requestHandler.ConnectionId, party); result.Invoke(AckResponseCode.Success, new ResponseCreatePartyMessage()); #endif }
public async UniTaskVoid HandleRequestCreateGuild(RequestHandlerData requestHandler, RequestCreateGuildMessage request, RequestProceedResultDelegate <ResponseCreateGuildMessage> result) { #if UNITY_STANDALONE && !CLIENT_BUILD await UniTask.Yield(); IPlayerCharacterData playerCharacter; if (!GameInstance.ServerUserHandlers.TryGetPlayerCharacter(requestHandler.ConnectionId, out playerCharacter)) { result.Invoke(AckResponseCode.Error, new ResponseCreateGuildMessage() { message = UITextKeys.UI_ERROR_NOT_LOGGED_IN, }); return; } ValidateGuildRequestResult validateResult = playerCharacter.CanCreateGuild(request.guildName); if (!validateResult.IsSuccess) { result.Invoke(AckResponseCode.Error, new ResponseCreateGuildMessage() { message = validateResult.GameMessage, }); return; } FindGuildNameResp findGuildNameResp = await DbServiceClient.FindGuildNameAsync(new FindGuildNameReq() { GuildName = request.guildName, }); if (findGuildNameResp.FoundAmount > 0) { result.Invoke(AckResponseCode.Error, new ResponseCreateGuildMessage() { message = UITextKeys.UI_ERROR_GUILD_NAME_EXISTED, }); return; } GuildResp createGuildResp = await DbServiceClient.CreateGuildAsync(new CreateGuildReq() { LeaderCharacterId = playerCharacter.Id, GuildName = request.guildName, }); GuildData guild = createGuildResp.GuildData; GameInstance.Singleton.SocialSystemSetting.DecreaseCreateGuildResource(playerCharacter); GameInstance.ServerGuildHandlers.SetGuild(guild.id, guild); playerCharacter.GuildId = guild.id; playerCharacter.GuildRole = guild.GetMemberRole(playerCharacter.Id); playerCharacter.SharedGuildExp = 0; if (playerCharacter is BasePlayerCharacterEntity) { // Sync guild name to client (playerCharacter as BasePlayerCharacterEntity).GuildName = request.guildName; } // Broadcast via chat server if (ChatNetworkManager.IsClientConnected) { ChatNetworkManager.SendCreateGuild(null, MMOMessageTypes.UpdateGuild, guild.id, request.guildName, playerCharacter.Id); ChatNetworkManager.SendAddSocialMember(null, MMOMessageTypes.UpdateGuildMember, guild.id, playerCharacter.Id, playerCharacter.CharacterName, playerCharacter.DataId, playerCharacter.Level); } GameInstance.ServerGameMessageHandlers.SendSetGuildData(requestHandler.ConnectionId, guild); GameInstance.ServerGameMessageHandlers.SendAddGuildMembersToOne(requestHandler.ConnectionId, guild); result.Invoke(AckResponseCode.Success, new ResponseCreateGuildMessage()); #endif }