public override void Execute(Level level) { ChallangeCommand challangeCommand = this; try { ClientAvatar player = level.GetPlayerAvatar(); Alliance alliance = ObjectManager.GetAlliance(player.GetAllianceId()); ChallengeStreamEntry cm = new ChallengeStreamEntry(); cm.SetMessage(challangeCommand.Message); cm.SetSenderId(player.GetId()); cm.SetSenderName(player.GetAvatarName()); cm.SetSenderLevel(player.GetAvatarLevel()); ChallengeStreamEntry challengeStreamEntry = cm; int allianceRole = player.GetAllianceRole(); challengeStreamEntry.SetSenderRole(allianceRole); challengeStreamEntry = (ChallengeStreamEntry)null; cm.SetId(alliance.GetChatMessages().Count + 1); cm.SetSenderLeagueId(player.GetLeagueId()); alliance.AddChatMessage((UCS.Logic.StreamEntry.StreamEntry)cm); UCS.Logic.StreamEntry.StreamEntry s = alliance.GetChatMessages().Find((Predicate <UCS.Logic.StreamEntry.StreamEntry>)(c => c.GetStreamEntryType() == 12)); List <AllianceMemberEntry> .Enumerator enumerator; if (s != null) { alliance.GetChatMessages().RemoveAll((Predicate <UCS.Logic.StreamEntry.StreamEntry>)(t => t == s)); foreach (AllianceMemberEntry allianceMember in alliance.GetAllianceMembers()) { Level player1 = ResourcesManager.GetPlayer(allianceMember.GetAvatarId(), false); if (player1.GetClient() != null) { new AllianceStreamEntryRemovedMessage(player1.GetClient(), s.GetId()).Send(); } } enumerator = new List <AllianceMemberEntry> .Enumerator(); } foreach (AllianceMemberEntry allianceMember in alliance.GetAllianceMembers()) { Level player1 = ResourcesManager.GetPlayer(allianceMember.GetAvatarId(), false); if (player1.GetClient() != null) { AllianceStreamEntryMessage Message = new AllianceStreamEntryMessage(player1.GetClient()); ChallengeStreamEntry challengeStreamEntry1 = cm; Message.SetStreamEntry((UCS.Logic.StreamEntry.StreamEntry)challengeStreamEntry1); Message.Send(); } } enumerator = new List <AllianceMemberEntry> .Enumerator(); player = (ClientAvatar)null; alliance = (Alliance)null; cm = (ChallengeStreamEntry)null; } catch (Exception ex) { } }
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) { } }
public override async void Process(Level level) { try { ClientAvatar player = level.GetPlayerAvatar(); Alliance all = await ObjectManager.GetAlliance(ID); InvitationStreamEntry cm = new InvitationStreamEntry(); 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.SetState(1); all.AddChatMessage(cm); foreach (AllianceMemberEntry op in all.GetAllianceMembers()) { Level playera = await ResourcesManager.GetPlayer(op.GetAvatarId()); if (playera.GetClient() != null) { AllianceStreamEntryMessage p = new AllianceStreamEntryMessage(playera.GetClient()); p.SetStreamEntry(cm); PacketProcessor.Send(p); } } } catch (Exception) { } }
public override void Process(Level level) { ClientAvatar player = level.GetPlayerAvatar(); Alliance all = ObjectManager.GetAlliance(ID); InvitationStreamEntry cm = new InvitationStreamEntry(); cm.SetId(all.GetChatMessages().Count + 1); cm.SetSenderId(player.GetId()); cm.SetHomeId(player.GetId()); cm.SetSenderLeagueId(player.GetLeagueId()); cm.SetSenderName(player.GetAvatarName()); cm.SetSenderRole(player.GetAllianceRole()); cm.SetMessage(Message); cm.SetState(1); all.AddChatMessage(cm); // New function for send a message foreach (AllianceMemberEntry op in all.GetAllianceMembers()) { Level playera = ResourcesManager.GetPlayer(op.GetAvatarId()); if (playera.GetClient() != null) { var p = new AllianceStreamEntryMessage(playera.GetClient()); p.SetStreamEntry(cm); p.Send(); } } }
public override void Encode() { List <byte> pack = new List <byte>(); var chatMessages = m_vAlliance.GetChatMessages().ToList(); pack.AddInt32(0); //Unknown pack.AddInt32(chatMessages.Count); int count = 0; foreach (StreamEntry chatMessage in chatMessages) { if (chatMessage != null) { if (chatMessage.Encode() != null) { pack.AddRange(chatMessage.Encode()); count++; if (count >= 150) { break; } } } } Encrypt(pack.ToArray()); }
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 override async void Process(Level level) { try { if (level.GetPlayerAvatar().State == ClientAvatar.UserState.CHA) { ResourcesManager.DisconnectClient(Client); } else { level.GetPlayerAvatar().State = ClientAvatar.UserState.CHA; Alliance a = await ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId()); Level defender = await ResourcesManager.GetPlayer(a.GetChatMessages().Find(c => c.GetId() == ID).GetSenderId()); if (defender != null) { defender.Tick(); PacketProcessor.Send(new ChallangeAttackDataMessage(Client, defender)); } else { new OwnHomeDataMessage(Client, level); } Alliance alliance = await ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId()); 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 playera = await ResourcesManager.GetPlayer(op.GetAvatarId()); if (playera.GetClient() != null) { AllianceStreamEntryMessage p = new AllianceStreamEntryMessage(playera.GetClient()); p.SetStreamEntry(s); PacketProcessor.Send(p); } } } } } catch (Exception) { } }
public override void Encode() { var pack = new List <byte>(); var chatMessages = m_vAlliance.GetChatMessages().ToList(); pack.AddInt32(chatMessages.Count); foreach (var chatMessage in chatMessages) { pack.AddRange(chatMessage.Encode()); } Encrypt(pack.ToArray()); }
public override void Process(Level level) { Alliance a = ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId()); var stream = a.GetChatMessages().Find(c => c.GetId() == MessageID); var sender = ResourcesManager.GetPlayer(stream.GetSenderId()); int upcomingspace = stream.m_vDonatedTroop + Troop.GetHousingSpace(); if (upcomingspace <= stream.m_vMaxTroop) { //System.Console.WriteLine("Troop Donated :" + Troop.GetName()); } }
public override void Encode() { List <Byte> pack = new List <Byte>(); List <StreamEntry> chatMessages = m_vAlliance.GetChatMessages().ToList();//avoid concurrent access issues pack.AddInt32(chatMessages.Count); foreach (var chatMessage in chatMessages) { pack.AddRange(chatMessage.Encode()); } SetData(pack.ToArray()); }
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 void Encode() { System.Collections.Generic.List <UCS.Logic.StreamEntry.StreamEntry> list = this.m_vAlliance.GetChatMessages().ToList <UCS.Logic.StreamEntry.StreamEntry>(); var pack = new List <byte>(); var chatMessages = m_vAlliance.GetChatMessages().ToList(); pack.AddInt32(0); pack.AddInt32(list.Count); int num = 0; foreach (UCS.Logic.StreamEntry.StreamEntry streamEntry in list) { pack.AddRange((IEnumerable <byte>)streamEntry.Encode()); ++num; if (num >= 150) { break; } } Encrypt(pack.ToArray()); }
public override void Encode() { var pack = new List <byte>(); var chatMessages = m_vAlliance.GetChatMessages().ToList(); //avoid concurrent access issues pack.AddInt32(chatMessages.Count); foreach (var chatMessage in chatMessages) { if (Client.GetLevel().isPermittedUser()) { var name = chatMessage.GetSenderName(); chatMessage.SetSenderName(name + " #" + chatMessage.GetSenderId()); pack.AddRange(chatMessage.Encode()); chatMessage.SetSenderName(name); } else { pack.AddRange(chatMessage.Encode()); } } SetData(pack.ToArray()); }
public override async void Process(Level level) { try { Alliance a = await ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId()); StreamEntry message = a.GetChatMessages().Find(c => c.GetId() == MessageID); Level requester = await ResourcesManager.GetPlayer(message.GetSenderId()); if (Choice == 1) { if (!a.IsAllianceFull()) { requester.GetPlayerAvatar().SetAllianceId(a.GetAllianceId()); AllianceMemberEntry member = new AllianceMemberEntry(requester.GetPlayerAvatar().GetId()); member.SetRole(1); a.AddAllianceMember(member); StreamEntry e = a.GetChatMessages().Find(c => c.GetId() == MessageID); e.SetJudgeName(level.GetPlayerAvatar().GetAvatarName()); e.SetState(2); AllianceEventStreamEntry eventStreamEntry = new AllianceEventStreamEntry(); eventStreamEntry.SetId(a.GetChatMessages().Count + 1); eventStreamEntry.SetSender(requester.GetPlayerAvatar()); eventStreamEntry.SetAvatarName(level.GetPlayerAvatar().GetAvatarName()); eventStreamEntry.SetAvatarId(level.GetPlayerAvatar().GetId()); eventStreamEntry.SetEventType(2); a.AddChatMessage(eventStreamEntry); foreach (AllianceMemberEntry op in a.GetAllianceMembers()) { Level player = await ResourcesManager.GetPlayer(op.GetAvatarId()); if (player.GetClient() != null) { AllianceStreamEntryMessage c = new AllianceStreamEntryMessage(player.GetClient()); AllianceStreamEntryMessage p = new AllianceStreamEntryMessage(player.GetClient()); p.SetStreamEntry(eventStreamEntry); c.SetStreamEntry(e); PacketProcessor.Send(p); PacketProcessor.Send(c); } } if (ResourcesManager.IsPlayerOnline(requester)) { JoinedAllianceCommand joinAllianceCommand = new JoinedAllianceCommand(); joinAllianceCommand.SetAlliance(a); AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage(requester.GetClient()); availableServerCommandMessage.SetCommandId(1); availableServerCommandMessage.SetCommand(joinAllianceCommand); AllianceRoleUpdateCommand d = new AllianceRoleUpdateCommand(); d.SetAlliance(a); d.SetRole(4); d.Tick(level); AvailableServerCommandMessage c = new AvailableServerCommandMessage(Client); c.SetCommandId(8); c.SetCommand(d); PacketProcessor.Send(new AnswerJoinRequestAllianceMessage(Client)); PacketProcessor.Send(availableServerCommandMessage); PacketProcessor.Send(c); PacketProcessor.Send(new AllianceStreamMessage(requester.GetClient(), a)); } } } else { StreamEntry e = a.GetChatMessages().Find(c => c.GetId() == MessageID); e.SetJudgeName(level.GetPlayerAvatar().GetAvatarName()); e.SetState(3); foreach (AllianceMemberEntry op in a.GetAllianceMembers()) { Level player = await ResourcesManager.GetPlayer(op.GetAvatarId()); if (player.GetClient() != null) { AllianceStreamEntryMessage c = new AllianceStreamEntryMessage(player.GetClient()); c.SetStreamEntry(e); PacketProcessor.Send(c); } } } } catch (Exception) { } }
public override async void Process(Level level) { try { Level target = await ResourcesManager.GetPlayer(m_vId); ClientAvatar player = level.GetPlayerAvatar(); Alliance alliance = await ObjectManager.GetAlliance(player.GetAllianceId()); if (await player.GetAllianceRole() == 2 || await player.GetAllianceRole() == 4) { if (player.GetAllianceId() == target.GetPlayerAvatar().GetAllianceId()) { int oldrole = await target.GetPlayerAvatar().GetAllianceRole(); target.GetPlayerAvatar().SetAllianceRole(m_vRole); if (m_vRole == 2) { player.SetAllianceRole(4); AllianceEventStreamEntry demote = new AllianceEventStreamEntry(); demote.SetId(alliance.GetChatMessages().Count + 1); demote.SetSender(player); demote.SetEventType(6); demote.SetAvatarId(player.GetId()); demote.SetAvatarName(player.GetAvatarName()); alliance.AddChatMessage(demote); AllianceEventStreamEntry promote = new AllianceEventStreamEntry(); promote.SetId(alliance.GetChatMessages().Count + 1); promote.SetSender(target.GetPlayerAvatar()); promote.SetEventType(5); promote.SetAvatarId(player.GetId()); promote.SetAvatarName(player.GetAvatarName()); alliance.AddChatMessage(promote); PromoteAllianceMemberOkMessage rup = new PromoteAllianceMemberOkMessage(Client); PromoteAllianceMemberOkMessage rub = new PromoteAllianceMemberOkMessage(target.GetClient()); AllianceRoleUpdateCommand p = new AllianceRoleUpdateCommand(); AvailableServerCommandMessage pa = new AvailableServerCommandMessage(Client); AllianceRoleUpdateCommand t = new AllianceRoleUpdateCommand(); AvailableServerCommandMessage ta = new AvailableServerCommandMessage(target.GetClient()); rup.SetID(level.GetPlayerAvatar().GetId()); rup.SetRole(4); rub.SetID(target.GetPlayerAvatar().GetId()); rub.SetRole(2); t.SetAlliance(alliance); p.SetAlliance(alliance); t.SetRole(2); p.SetRole(4); t.Tick(target); p.Tick(level); ta.SetCommandId(8); pa.SetCommandId(8); ta.SetCommand(t); pa.SetCommand(p); if (ResourcesManager.IsPlayerOnline(target)) { PacketProcessor.Send(ta); PacketProcessor.Send(rub); } PacketProcessor.Send(rup); PacketProcessor.Send(pa); foreach (AllianceMemberEntry op in alliance.GetAllianceMembers()) { Level aplayer = await ResourcesManager.GetPlayer(op.GetAvatarId()); if (aplayer.GetClient() != null) { AllianceStreamEntryMessage a = new AllianceStreamEntryMessage(aplayer.GetClient()); AllianceStreamEntryMessage b = new AllianceStreamEntryMessage(aplayer.GetClient()); a.SetStreamEntry(demote); b.SetStreamEntry(promote); PacketProcessor.Send(a); PacketProcessor.Send(b); } } } else { AllianceRoleUpdateCommand t = new AllianceRoleUpdateCommand(); AvailableServerCommandMessage ta = new AvailableServerCommandMessage(target.GetClient()); PromoteAllianceMemberOkMessage ru = new PromoteAllianceMemberOkMessage(target.GetClient()); AllianceEventStreamEntry stream = new AllianceEventStreamEntry(); stream.SetId(alliance.GetChatMessages().Count + 1); stream.SetSender(target.GetPlayerAvatar()); stream.SetAvatarId(player.GetId()); stream.SetAvatarName(player.GetAvatarName()); if (m_vRole > oldrole) { stream.SetEventType(5); } else { stream.SetEventType(6); } t.SetAlliance(alliance); t.SetRole(m_vRole); t.Tick(target); ta.SetCommandId(8); ta.SetCommand(t); ru.SetID(target.GetPlayerAvatar().GetId()); ru.SetRole(m_vRole); alliance.AddChatMessage(stream); if (ResourcesManager.IsPlayerOnline(target)) { PacketProcessor.Send(ta); PacketProcessor.Send(ru); } foreach (AllianceMemberEntry op in alliance.GetAllianceMembers()) { Level aplayer = await ResourcesManager.GetPlayer(op.GetAvatarId()); if (aplayer.GetClient() != null) { AllianceStreamEntryMessage b = new AllianceStreamEntryMessage(aplayer.GetClient()); b.SetStreamEntry(stream); PacketProcessor.Send(b); } } } } } } catch (Exception) { } }
public override async void Process(Level level) { try { Alliance a = await ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId()); StreamEntry stream = a.GetChatMessages().Find(c => c.GetId() == MessageID); Level _Sender = await ResourcesManager.GetPlayer(stream.GetSenderId()); int upcomingspace = stream.m_vDonatedTroop + Troop.GetHousingSpace(); if (upcomingspace <= stream.m_vMaxTroop) { DonateAllianceUnitCommand _Donate = new DonateAllianceUnitCommand(); _Donate.SetMessageID(MessageID); _Donate.Tick(level); _Donate.SetUnit(Troop); DonatedAllianceUnitCommand _Donated = new DonatedAllianceUnitCommand(); _Donated.Tick(_Sender); _Donated.SetDonator(level.GetPlayerAvatar().GetAvatarName()); _Donated.SetUnitID(Troop.GetGlobalID()); _Donated.SetUnitLevel(level.GetPlayerAvatar().GetUnitUpgradeLevel(Troop)); AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage(level.GetClient()); availableServerCommandMessage.SetCommandId(4); availableServerCommandMessage.SetCommand(_Donate); AvailableServerCommandMessage ravailableServerCommandMessage = new AvailableServerCommandMessage(_Sender.GetClient()); ravailableServerCommandMessage.SetCommandId(5); ravailableServerCommandMessage.SetCommand(_Donated); StreamEntry _Stream = a.GetChatMessages().Find(c => c.GetId() == MessageID); Level _PreviousPlayer = await ResourcesManager.GetPlayer(_Stream.GetSenderId()); ClientAvatar _PreviousPlayerAvatar = _PreviousPlayer.GetPlayerAvatar(); _Stream.AddDonatedTroop(level.GetPlayerAvatar().GetId(), Troop.GetGlobalID(), 1, level.GetPlayerAvatar().GetUnitUpgradeLevel(Troop)); int _Capicity = Troop.GetHousingSpace(); _Stream.AddUsedCapicity(_Capicity); _PreviousPlayerAvatar.SetAllianceCastleUsedCapacity(_PreviousPlayerAvatar.GetAllianceCastleUsedCapacity() + _Capicity); _PreviousPlayerAvatar.AddAllianceTroop(level.GetPlayerAvatar().GetId(), Troop.GetGlobalID(), 1, level.GetPlayerAvatar().GetUnitUpgradeLevel(Troop)); //PacketProcessor.Send(availableServerCommandMessage); if (ResourcesManager.IsPlayerOnline(_Sender)) { PacketProcessor.Send(ravailableServerCommandMessage); } foreach (AllianceMemberEntry op in a.GetAllianceMembers()) { Level player = await ResourcesManager.GetPlayer(op.GetAvatarId()); if (player.GetClient() != null) { AllianceStreamEntryMessage c = new AllianceStreamEntryMessage(player.GetClient()); c.SetStreamEntry(_Stream); PacketProcessor.Send(c); } } } } catch (Exception) { } }