public void AddStreamEntry(StreamEntry entry) { if (entry.GetId().IsZero()) { throw new Exception("Alliance.addStreamEntry: id should be set!"); } while (this.StreamEntryList.Size() >= Alliance.MAX_STREAM_ENTRY_COUNT) { this.RemoveStreamEntry(this.StreamEntryList[0]); } this.StreamEntryList.Add(entry.GetId()); this.OnStreamEntryAdded(entry); }
private static void OnAllianceRequestAllianceUnitsMessageReceived(AllianceRequestAllianceUnitsMessage message) { if (AllianceManager.TryGet(message.AccountId, out Alliance alliance) && alliance.Members.TryGetValue(message.MemberId, out AllianceMemberEntry memberEntry)) { for (int i = 0; i < alliance.StreamEntryList.Size(); i++) { StreamEntry streamEntry = StreamManager.GetAllianceStream(alliance.StreamEntryList[i]); if (streamEntry != null && streamEntry.GetStreamEntryType() == StreamEntryType.DONATE && streamEntry.GetSenderAvatarId().Equals(memberEntry.GetAvatarId())) { alliance.RemoveStreamEntry(streamEntry.GetId()); } } DonateStreamEntry donateStreamEntry = new DonateStreamEntry(); AllianceStreamEntryUtil.SetSenderInfo(donateStreamEntry, memberEntry); string donateMessage = message.Message; if (donateMessage.Length > 128) { donateMessage = donateMessage.Substring(0, 128); } donateStreamEntry.SetMessage(donateMessage); donateStreamEntry.SetCasteLevel(message.CastleUpgradeLevel, message.CastleUsedCapacity, message.CastleSpellUsedCapacity, message.CastleTotalCapacity, message.CastleSpellTotalCapacity); StreamManager.Create(alliance.Id, donateStreamEntry); alliance.AddStreamEntry(donateStreamEntry); AllianceManager.Save(alliance); } }
private void OnCancelChallengeMessageReceived(CancelChallengeMessage message) { if (this.m_session.Alliance != null) { Alliance alliance = this.m_session.Alliance; AllianceMemberEntry memberEntry = alliance.Members[this.m_session.AccountId]; for (int i = 0; i < alliance.StreamEntryList.Size(); i++) { StreamEntry streamEntry = StreamManager.GetAllianceStream(alliance.StreamEntryList[i]); if (streamEntry != null && streamEntry.GetStreamEntryType() == StreamEntryType.CHALLENGE && streamEntry.GetSenderAvatarId().Equals(memberEntry.GetAvatarId())) { ChallengeStreamEntry prevChallengeStreamEntry = (ChallengeStreamEntry)streamEntry; if (prevChallengeStreamEntry.IsStarted()) { return; } alliance.RemoveStreamEntry(streamEntry.GetId()); } } } }
private void OnDonateAllianceUnitMessageReceived(DonateAllianceUnitMessage message) { if (this.m_session.Alliance != null) { Alliance alliance = this.m_session.Alliance; LogicCombatItemData unitData = message.GetAllianceUnitData(); if (!unitData.IsDonationDisabled()) { if (message.UseQuickDonate()) { if (!LogicDataTables.GetGlobals().EnableQuickDonate() || this.m_session.LogicClientAvatar.GetDiamonds() < unitData.GetDonateCost()) { return; } } else { if (this.m_session.LogicClientAvatar.GetUnitCount(unitData) <= 0) { return; } } if (alliance.StreamEntryList.IndexOf(message.GetStreamId()) != -1) { StreamEntry streamEntry = StreamManager.GetAllianceStream(message.GetStreamId()); if (streamEntry.GetStreamEntryType() == StreamEntryType.DONATE) { DonateStreamEntry donateStreamEntry = (DonateStreamEntry)streamEntry; if (donateStreamEntry.CanAddDonation(this.m_session.AccountId, message.GetAllianceUnitData(), alliance.Header.GetAllianceLevel())) { donateStreamEntry.AddDonation(this.m_session.AccountId, unitData, this.m_session.LogicClientAvatar.GetUnitUpgradeLevel(unitData)); donateStreamEntry.SetDonationPendingRequestCount(donateStreamEntry.GetDonationPendingRequestCount() + 1); StreamManager.Save(donateStreamEntry); alliance.UpdateStreamEntry(donateStreamEntry); if (message.UseQuickDonate()) { this.m_session.LogicClientAvatar.CommodityCountChangeHelper(0, unitData, -1); } LogicDonateAllianceUnitCommand logicDonateAllianceUnitCommand = new LogicDonateAllianceUnitCommand(); logicDonateAllianceUnitCommand.SetData(unitData, streamEntry.GetId(), message.UseQuickDonate()); ServerMessageManager.SendMessage(new GameAllowServerCommandMessage { AccountId = this.m_session.AccountId, ServerCommand = logicDonateAllianceUnitCommand }, 9); } } } } } }
private static void OnAllianceChallengeRequestMessageReceived(AllianceChallengeRequestMessage message) { if (AllianceManager.TryGet(message.AccountId, out Alliance alliance) && alliance.Members.TryGetValue(message.MemberId, out AllianceMemberEntry memberEntry)) { for (int i = 0; i < alliance.StreamEntryList.Size(); i++) { StreamEntry streamEntry = StreamManager.GetAllianceStream(alliance.StreamEntryList[i]); if (streamEntry != null && streamEntry.GetStreamEntryType() == StreamEntryType.CHALLENGE && streamEntry.GetSenderAvatarId().Equals(memberEntry.GetAvatarId())) { ChallengeStreamEntry prevChallengeStreamEntry = (ChallengeStreamEntry)streamEntry; if (prevChallengeStreamEntry.IsStarted()) { return; } alliance.RemoveStreamEntry(streamEntry.GetId()); } } ChallengeStreamEntry challengeStreamEntry = new ChallengeStreamEntry(); AllianceStreamEntryUtil.SetSenderInfo(challengeStreamEntry, memberEntry); string challengeMessage = message.Message; if (challengeMessage.Length > 128) { challengeMessage = challengeMessage.Substring(0, 128); } challengeStreamEntry.SetMessage(challengeMessage); challengeStreamEntry.SetSnapshotHomeJSON(message.HomeJSON); challengeStreamEntry.SetWarLayout(message.WarLayout); StreamManager.Create(alliance.Id, challengeStreamEntry); alliance.AddStreamEntry(challengeStreamEntry); AllianceManager.Save(alliance); } }
public override async void Execute(Level level) { try { ClientAvatar player = level.GetPlayerAvatar(); TroopRequestStreamEntry cm = new TroopRequestStreamEntry(); Alliance all = await ObjectManager.GetAlliance(player.GetAllianceId()); cm.SetId(all.GetChatMessages().Count + 1); cm.SetSenderId(player.GetId()); cm.SetHomeId(player.GetId()); cm.SetSenderLeagueId(player.GetLeagueId()); cm.SetSenderName(player.GetAvatarName()); cm.SetSenderRole(await player.GetAllianceRole()); cm.SetMessage(Message); cm.SetMaxTroop(player.GetAllianceCastleTotalCapacity()); all.AddChatMessage(cm); StreamEntry s = all.GetChatMessages().Find(c => c.GetSenderId() == level.GetPlayerAvatar().GetId() && c.GetStreamEntryType() == 1); if (s == null) { all.GetChatMessages().RemoveAll(t => t == s); } all.AddChatMessage(cm); foreach (AllianceMemberEntry op in all.GetAllianceMembers()) { Level aplayer = await ResourcesManager.GetPlayer(op.GetAvatarId()); if (aplayer.GetClient() != null) { if (s != null) { PacketProcessor.Send(new AllianceStreamEntryRemovedMessage(aplayer.GetClient(), s.GetId())); } AllianceStreamEntryMessage p = new AllianceStreamEntryMessage(aplayer.GetClient()); p.SetStreamEntry(cm); PacketProcessor.Send(p); } } } catch (Exception) { ResourcesManager.DropClient(level.GetClient().GetSocketHandle()); } }
public static void Save(StreamEntry entry) { StreamDocument document = StreamManager.m_allianceStreams[entry.GetId()]; ServerStream.StreamDatabase.InsertOrUpdate(document.Id, CouchbaseDocument.Save(document)); }
public override async void Process(Level level) { try { Alliance a = await ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId()); StreamEntry s = a.GetChatMessages().Find(c => c.GetSenderId() == level.GetPlayerAvatar().GetId() && c.GetStreamEntryType() == 12); if (s != null) { a.GetChatMessages().RemoveAll(t => t == s); foreach (AllianceMemberEntry op in a.GetAllianceMembers()) { Level player = await ResourcesManager.GetPlayer(op.GetAvatarId()); if (player.GetClient() != null) { PacketProcessor.Send(new AllianceStreamEntryRemovedMessage(Client, s.GetId())); } } } } catch (Exception) { } }
public override async void Execute(Level level) { try { ClientAvatar player = level.GetPlayerAvatar(); long allianceID = player.GetAllianceId(); Alliance alliance = await ObjectManager.GetAlliance(allianceID); ChallangeStreamEntry cm = new ChallangeStreamEntry(); cm.SetMessage(Message); cm.SetSenderId(player.GetId()); cm.SetSenderName(player.GetAvatarName()); cm.SetSenderLevel(player.GetAvatarLevel()); cm.SetSenderRole(await player.GetAllianceRole()); cm.SetId(alliance.GetChatMessages().Count + 1); cm.SetSenderLeagueId(player.GetLeagueId()); StreamEntry s = alliance.GetChatMessages().Find(c => c.GetStreamEntryType() == 12); if (s != null) { alliance.GetChatMessages().RemoveAll(t => t == s); foreach (AllianceMemberEntry op in alliance.GetAllianceMembers()) { Level alliancemembers = await ResourcesManager.GetPlayer(op.GetAvatarId()); if (alliancemembers.GetClient() != null) { PacketProcessor.Send(new AllianceStreamEntryRemovedMessage(alliancemembers.GetClient(), s.GetId())); } } } alliance.AddChatMessage(cm); foreach (AllianceMemberEntry op in alliance.GetAllianceMembers()) { Level alliancemembers = await ResourcesManager.GetPlayer(op.GetAvatarId()); if (alliancemembers.GetClient() != null) { AllianceStreamEntryMessage p = new AllianceStreamEntryMessage(alliancemembers.GetClient()); p.SetStreamEntry(cm); PacketProcessor.Send(p); } } } catch (Exception) { } }