public override async void Process(Level level) { try { ClientAvatar avatar = level.GetPlayerAvatar(); Alliance alliance = await ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId()); if (await avatar.GetAllianceRole() == 2 && alliance.GetAllianceMembers().Count > 1) { List<AllianceMemberEntry> members = alliance.GetAllianceMembers(); foreach (AllianceMemberEntry player in members.Where(player => player.GetRole() >= 3)) { player.SetRole(2); if (ResourcesManager.IsPlayerOnline(await ResourcesManager.GetPlayer(player.GetAvatarId()))) { AllianceRoleUpdateCommand c = new AllianceRoleUpdateCommand(); c.SetAlliance(alliance); c.SetRole(2); c.Tick(level); Level l = await ResourcesManager.GetPlayer(player.GetAvatarId()); AvailableServerCommandMessage d = new AvailableServerCommandMessage(l.GetClient()); d.SetCommandId(8); d.SetCommand(c); PacketProcessor.Send(d); } done = true; break; } if (!done) { int count = alliance.GetAllianceMembers().Count; Random rnd = new Random(); int id = rnd.Next(1, count); while (id != level.GetPlayerAvatar().GetId()) id = rnd.Next(1, count); int loop = 0; foreach (AllianceMemberEntry player in members) { loop++; if (loop == id) { player.SetRole(2); if (ResourcesManager.IsPlayerOnline(await ResourcesManager.GetPlayer(player.GetAvatarId()))) { AllianceRoleUpdateCommand e = new AllianceRoleUpdateCommand(); e.SetAlliance(alliance); e.SetRole(2); e.Tick(level); Level l2 = await ResourcesManager.GetPlayer(player.GetAvatarId()); AvailableServerCommandMessage f = new AvailableServerCommandMessage(l2.GetClient()); f.SetCommandId(8); f.SetCommand(e); PacketProcessor.Send(f); } break; } } } } LeavedAllianceCommand a = new LeavedAllianceCommand(); a.SetAlliance(alliance); a.SetReason(1); AvailableServerCommandMessage b = new AvailableServerCommandMessage(Client); b.SetCommandId(2); b.SetCommand(a); PacketProcessor.Send(b); alliance.RemoveMember(avatar.GetId()); avatar.SetAllianceId(0); if (alliance.GetAllianceMembers().Count > 0) { AllianceEventStreamEntry eventStreamEntry = new AllianceEventStreamEntry(); eventStreamEntry.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds); eventStreamEntry.SetSender(avatar); eventStreamEntry.SetEventType(4); eventStreamEntry.SetAvatarId(avatar.GetId()); eventStreamEntry.SetAvatarName(avatar.GetAvatarName()); alliance.AddChatMessage(eventStreamEntry); foreach (Level onlinePlayer in ResourcesManager.GetOnlinePlayers()) if (onlinePlayer.GetPlayerAvatar().GetAllianceId() == alliance.GetAllianceId()) { AllianceStreamEntryMessage p = new AllianceStreamEntryMessage(onlinePlayer.GetClient()); p.SetStreamEntry(eventStreamEntry); PacketProcessor.Send(p); } } else { DatabaseManager.Single().RemoveAlliance(alliance); } PacketProcessor.Send(new LeaveAllianceOkMessage(Client, alliance)); } catch (Exception) { } }
public override void Process(Level level) { var avatar = level.GetPlayerAvatar(); var alliance = ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId()); if (avatar.GetAllianceRole() == 2 && alliance.GetAllianceMembers().Count > 1) { var members = alliance.GetAllianceMembers(); foreach (AllianceMemberEntry player in members.Where(player => player.GetRole() >= 3)) { player.SetRole(2); if (ResourcesManager.IsPlayerOnline(ResourcesManager.GetPlayer(player.GetAvatarId()))) { var c = new AllianceRoleUpdateCommand(); c.SetAlliance(alliance); c.SetRole(2); c.Tick(level); var d = new AvailableServerCommandMessage(ResourcesManager.GetPlayer(player.GetAvatarId()).GetClient()); d.SetCommandId(8); d.SetCommand(c); d.Send(); } done = true; break; } if (!done) { var count = alliance.GetAllianceMembers().Count; var rnd = new Random(); var id = rnd.Next(1, count); while (id != level.GetPlayerAvatar().GetId()) { id = rnd.Next(1, count); } var loop = 0; foreach (AllianceMemberEntry player in members) { loop++; if (loop == id) { player.SetRole(2); if (ResourcesManager.IsPlayerOnline(ResourcesManager.GetPlayer(player.GetAvatarId()))) { var e = new AllianceRoleUpdateCommand(); e.SetAlliance(alliance); e.SetRole(2); e.Tick(level); var f = new AvailableServerCommandMessage(ResourcesManager.GetPlayer(player.GetAvatarId()).GetClient()); f.SetCommandId(8); f.SetCommand(e); f.Send(); } break; } } } } var a = new LeavedAllianceCommand(); a.SetAlliance(alliance); a.SetReason(1); var b = new AvailableServerCommandMessage(Client); b.SetCommandId(2); b.SetCommand(a); b.Send(); alliance.RemoveMember(avatar.GetId()); avatar.SetAllianceId(0); if (alliance.GetAllianceMembers().Count > 0) { var eventStreamEntry = new AllianceEventStreamEntry(); eventStreamEntry.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds); eventStreamEntry.SetSender(avatar); eventStreamEntry.SetEventType(4); eventStreamEntry.SetAvatarId(avatar.GetId()); eventStreamEntry.SetAvatarName(avatar.GetAvatarName()); alliance.AddChatMessage(eventStreamEntry); foreach (Level onlinePlayer in ResourcesManager.GetOnlinePlayers()) { if (onlinePlayer.GetPlayerAvatar().GetAllianceId() == alliance.GetAllianceId()) { AllianceStreamEntryMessage p = new AllianceStreamEntryMessage(onlinePlayer.GetClient()); p.SetStreamEntry(eventStreamEntry); p.Send(); } } } else { DatabaseManager.Single().RemoveAlliance(alliance); } new LeaveAllianceOkMessage(Client, alliance).Send(); }
internal override async void Process() { try { var targetAccount = await ResourcesManager.GetPlayer(m_vAvatarId); if (targetAccount != null) { var targetAvatar = targetAccount.Avatar; var targetAllianceId = targetAvatar.AllianceId; var requesterAvatar = this.Device.Player.Avatar; var requesterAllianceId = requesterAvatar.AllianceId; if (requesterAllianceId > 0 && targetAllianceId == requesterAllianceId) { var alliance = ObjectManager.GetAlliance(requesterAllianceId); var requesterMember = alliance.m_vAllianceMembers[requesterAvatar.UserId]; var targetMember = alliance.m_vAllianceMembers[m_vAvatarId]; if (targetMember.HasLowerRoleThan(requesterMember.Role)) { targetAvatar.AllianceId = 0; alliance.RemoveMember(m_vAvatarId); if (ResourcesManager.IsPlayerOnline(targetAccount)) { var leaveAllianceCommand = new LeavedAllianceCommand(this.Device); leaveAllianceCommand.SetAlliance(alliance); leaveAllianceCommand.SetReason(2); //Kick new AvailableServerCommandMessage(targetAccount.Client, leaveAllianceCommand.Handle()).Send(); var kickOutStreamEntry = new AllianceKickOutStreamEntry(); kickOutStreamEntry.ID = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; kickOutStreamEntry.SetSender(requesterAvatar); kickOutStreamEntry.IsNew = 2; kickOutStreamEntry.SetAllianceId(alliance.m_vAllianceId); kickOutStreamEntry.SetAllianceBadgeData(alliance.m_vAllianceBadgeData); kickOutStreamEntry.SetAllianceName(alliance.m_vAllianceName); kickOutStreamEntry.SetMessage(m_vMessage); var p = new AvatarStreamEntryMessage(targetAccount.Client); p.SetAvatarStreamEntry(kickOutStreamEntry); p.Send(); } var eventStreamEntry = new AllianceEventStreamEntry(); eventStreamEntry.ID = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; eventStreamEntry.SetSender(targetAvatar); eventStreamEntry.m_vAvatarName = this.Device.Player.Avatar.AvatarName; eventStreamEntry.EventType = 1; alliance.AddChatMessage(eventStreamEntry); foreach (AllianceMemberEntry op in alliance.GetAllianceMembers()) { Level alliancemembers = await ResourcesManager.GetPlayer(op.AvatarId); if (alliancemembers.Client != null) { new AllianceStreamEntryMessage(alliancemembers.Client) { StreamEntry = eventStreamEntry }.Send(); } } } } } } catch (Exception) { } }
public override async void Execute(Level level) { try { var targetAccount = await ResourcesManager.GetPlayer(m_vAvatarId); if (targetAccount != null) { var targetAvatar = targetAccount.GetPlayerAvatar(); var targetAllianceId = targetAvatar.GetAllianceId(); var requesterAvatar = level.GetPlayerAvatar(); var requesterAllianceId = requesterAvatar.GetAllianceId(); if (requesterAllianceId > 0 && targetAllianceId == requesterAllianceId) { var alliance = await ObjectManager.GetAlliance(requesterAllianceId); var requesterMember = alliance.GetAllianceMember(requesterAvatar.GetId()); var targetMember = alliance.GetAllianceMember(m_vAvatarId); if (targetMember.HasLowerRoleThan(requesterMember.GetRole())) { targetAvatar.SetAllianceId(0); alliance.RemoveMember(m_vAvatarId); if (ResourcesManager.IsPlayerOnline(targetAccount)) { var leaveAllianceCommand = new LeavedAllianceCommand(); leaveAllianceCommand.SetAlliance(alliance); leaveAllianceCommand.SetReason(2); //Kick var availableServerCommandMessage = new AvailableServerCommandMessage(targetAccount.GetClient()); availableServerCommandMessage.SetCommandId(2); availableServerCommandMessage.SetCommand(leaveAllianceCommand); PacketProcessor.Send(availableServerCommandMessage); var kickOutStreamEntry = new AllianceKickOutStreamEntry(); kickOutStreamEntry.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds); kickOutStreamEntry.SetAvatar(requesterAvatar); kickOutStreamEntry.SetIsNew(0); kickOutStreamEntry.SetAllianceId(alliance.GetAllianceId()); kickOutStreamEntry.SetAllianceBadgeData(alliance.GetAllianceBadgeData()); kickOutStreamEntry.SetAllianceName(alliance.GetAllianceName()); kickOutStreamEntry.SetMessage(m_vMessage); var p = new AvatarStreamEntryMessage(targetAccount.GetClient()); p.SetAvatarStreamEntry(kickOutStreamEntry); PacketProcessor.Send(p); } var eventStreamEntry = new AllianceEventStreamEntry(); eventStreamEntry.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds); eventStreamEntry.SetSender(targetAvatar); eventStreamEntry.SetEventType(1); eventStreamEntry.SetAvatarId(requesterAvatar.GetId()); eventStreamEntry.SetAvatarName(requesterAvatar.GetAvatarName()); alliance.AddChatMessage(eventStreamEntry); 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(eventStreamEntry); PacketProcessor.Send(p); } } } } } } catch (Exception) { } }
internal override async void Process() { try { ClientAvatar avatar = this.Device.Player.Avatar; Alliance alliance = ObjectManager.GetAlliance(avatar.AllianceId); if (await avatar.GetAllianceRole() == 2 && alliance.GetAllianceMembers().Count > 1) { List <AllianceMemberEntry> members = alliance.GetAllianceMembers(); foreach (AllianceMemberEntry player in members.Where(player => player.Role >= 3)) { player.Role = 2; if (ResourcesManager.IsPlayerOnline(await ResourcesManager.GetPlayer(player.AvatarId))) { Level l = await ResourcesManager.GetPlayer(player.AvatarId); AllianceRoleUpdateCommand c = new AllianceRoleUpdateCommand(l.Client); c.SetAlliance(alliance); c.SetRole(2); c.Tick(l); new AvailableServerCommandMessage(l.Client, c.Handle()).Send(); } done = true; break; } if (!done) { int count = alliance.GetAllianceMembers().Count; Random rnd = new Random(); int id = rnd.Next(1, count); while (id != this.Device.Player.Avatar.UserId) { id = rnd.Next(1, count); } int loop = 0; foreach (AllianceMemberEntry player in members) { loop++; if (loop == id) { player.Role = 2; if (ResourcesManager.IsPlayerOnline(await ResourcesManager.GetPlayer(player.AvatarId))) { Level l2 = await ResourcesManager.GetPlayer(player.AvatarId); AllianceRoleUpdateCommand e = new AllianceRoleUpdateCommand(l2.Client); e.SetAlliance(alliance); e.SetRole(2); e.Tick(l2); new AvailableServerCommandMessage(l2.Client, e.Handle()).Send(); } break; } } } } LeavedAllianceCommand a = new LeavedAllianceCommand(this.Device); a.SetAlliance(alliance); a.SetReason(1); new AvailableServerCommandMessage(Device, a.Handle()).Send(); alliance.RemoveMember(avatar.UserId); avatar.AllianceId = 0; if (alliance.GetAllianceMembers().Count > 0) { AllianceEventStreamEntry eventStreamEntry = new AllianceEventStreamEntry(); eventStreamEntry.ID = alliance.m_vChatMessages.Count + 1; eventStreamEntry.SetSender(avatar); eventStreamEntry.EventType = 4; alliance.AddChatMessage(eventStreamEntry); foreach (Level onlinePlayer in ResourcesManager.m_vOnlinePlayers) { if (onlinePlayer.Avatar.AllianceId == alliance.m_vAllianceId) { new AllianceStreamEntryMessage(onlinePlayer.Client) { StreamEntry = eventStreamEntry }.Send(); } } } else { Resources.DatabaseManager.RemoveAlliance(alliance); } new LeaveAllianceOkMessage(Device, alliance).Send(); } catch (Exception) { } }