public void Handle(SignPetition command) { var aggregate = GetAggregate(command.AggregateId); aggregate.AddSigner(command.Email, command.FirstName, command.LastName); _repository.Save(aggregate); }
void HandleSignPetition(SignPetition packet) { Petition petition = Global.PetitionMgr.GetPetition(packet.PetitionGUID); if (petition == null) { Log.outError(LogFilter.Network, $"Petition {packet.PetitionGUID} is not found for player {GetPlayer().GetGUID()} {GetPlayer().GetName()}"); return; } ObjectGuid ownerGuid = petition.ownerGuid; int signs = petition.signatures.Count; if (ownerGuid == GetPlayer().GetGUID()) { return; } // not let enemies sign guild charter if (!WorldConfig.GetBoolValue(WorldCfg.AllowTwoSideInteractionGuild) && GetPlayer().GetTeam() != Global.CharacterCacheStorage.GetCharacterTeamByGuid(ownerGuid)) { Guild.SendCommandResult(this, GuildCommandType.CreateGuild, GuildCommandError.NotAllied); return; } if (GetPlayer().GetGuildId() != 0) { Guild.SendCommandResult(this, GuildCommandType.InvitePlayer, GuildCommandError.AlreadyInGuild_S, GetPlayer().GetName()); return; } if (GetPlayer().GetGuildIdInvited() != 0) { Guild.SendCommandResult(this, GuildCommandType.InvitePlayer, GuildCommandError.AlreadyInvitedToGuild_S, GetPlayer().GetName()); return; } if (++signs > 10) // client signs maximum { return; } // Client doesn't allow to sign petition two times by one character, but not check sign by another character from same account // not allow sign another player from already sign player account PetitionSignResults signResult = new PetitionSignResults(); signResult.Player = GetPlayer().GetGUID(); signResult.Item = packet.PetitionGUID; bool isSigned = petition.IsPetitionSignedByAccount(GetAccountId()); if (isSigned) { signResult.Error = PetitionSigns.AlreadySigned; // close at signer side SendPacket(signResult); // update for owner if online Player owner = Global.ObjAccessor.FindConnectedPlayer(ownerGuid); if (owner != null) { owner.GetSession().SendPacket(signResult); } return; } // fill petition store petition.AddSignature(packet.PetitionGUID, GetAccountId(), _player.GetGUID(), false); Log.outDebug(LogFilter.Network, "PETITION SIGN: {0} by player: {1} ({2} Account: {3})", packet.PetitionGUID.ToString(), GetPlayer().GetName(), GetPlayer().GetGUID().ToString(), GetAccountId()); signResult.Error = PetitionSigns.Ok; SendPacket(signResult); // update signs count on charter Item item = _player.GetItemByGuid(packet.PetitionGUID); if (item != null) { item.SetPetitionNumSignatures((uint)signs); item.SetState(ItemUpdateState.Changed, _player); } // update for owner if online Player owner1 = Global.ObjAccessor.FindPlayer(ownerGuid); if (owner1) { owner1.SendPacket(signResult); } }
void HandleSignPetition(SignPetition packet) { PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_PETITION_SIGNATURES); stmt.AddValue(0, packet.PetitionGUID.GetCounter()); stmt.AddValue(1, packet.PetitionGUID.GetCounter()); SQLResult result = DB.Characters.Query(stmt); if (result.IsEmpty()) { Log.outError(LogFilter.Network, "Petition {0} is not found for player {1} {2}", packet.PetitionGUID.ToString(), GetPlayer().GetGUID().ToString(), GetPlayer().GetName()); return; } ObjectGuid ownerGuid = ObjectGuid.Create(HighGuid.Player, result.Read <ulong>(0)); ulong signs = result.Read <ulong>(1); if (ownerGuid == GetPlayer().GetGUID()) { return; } // not let enemies sign guild charter if (!WorldConfig.GetBoolValue(WorldCfg.AllowTwoSideInteractionGuild) && GetPlayer().GetTeam() != Global.CharacterCacheStorage.GetCharacterTeamByGuid(ownerGuid)) { Guild.SendCommandResult(this, GuildCommandType.CreateGuild, GuildCommandError.NotAllied); return; } if (GetPlayer().GetGuildId() != 0) { Guild.SendCommandResult(this, GuildCommandType.InvitePlayer, GuildCommandError.AlreadyInGuild_S, GetPlayer().GetName()); return; } if (GetPlayer().GetGuildIdInvited() != 0) { Guild.SendCommandResult(this, GuildCommandType.InvitePlayer, GuildCommandError.AlreadyInvitedToGuild_S, GetPlayer().GetName()); return; } // Client doesn't allow to sign petition two times by one character, but not check sign by another character from same account // not allow sign another player from already sign player account stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_PETITION_SIG_BY_ACCOUNT); stmt.AddValue(0, GetAccountId()); stmt.AddValue(1, packet.PetitionGUID.GetCounter()); result = DB.Characters.Query(stmt); PetitionSignResults signResult = new PetitionSignResults(); signResult.Player = GetPlayer().GetGUID(); signResult.Item = packet.PetitionGUID; if (!result.IsEmpty()) { signResult.Error = PetitionSigns.AlreadySigned; // close at signer side SendPacket(signResult); return; } stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_PETITION_SIGNATURE); stmt.AddValue(0, ownerGuid.GetCounter()); stmt.AddValue(1, packet.PetitionGUID.GetCounter()); stmt.AddValue(2, GetPlayer().GetGUID().GetCounter()); stmt.AddValue(3, GetAccountId()); DB.Characters.Execute(stmt); Log.outDebug(LogFilter.Network, "PETITION SIGN: {0} by player: {1} ({2} Account: {3})", packet.PetitionGUID.ToString(), GetPlayer().GetName(), GetPlayer().GetGUID().ToString(), GetAccountId()); signResult.Error = PetitionSigns.Ok; // close at signer side SendPacket(signResult); Item item = _player.GetItemByGuid(packet.PetitionGUID); if (item != null) { item.SetPetitionNumSignatures((uint)signs); item.SetState(ItemUpdateState.Changed, _player); } // update for owner if online Player owner = Global.ObjAccessor.FindPlayer(ownerGuid); if (owner) { owner.SendPacket(signResult); } }