internal override void Handle() { Alliance alliance = Alliances.Get(this.AllianceID); if (alliance != null) { if (!alliance.Members.Contains(alliance.Members.Find(member => member.Identifier == this.Connection.Avatar.Identifier))) { AllianceMember member = new AllianceMember(this.Connection.Avatar, Alliance.Role.Member); alliance.Members.Add(member); this.Connection.Avatar.ClanHighID = alliance.HighID; this.Connection.Avatar.ClanLowID = alliance.LowID; this.Connection.Avatar.Save(); Alliances.Save(alliance); new AvailableServerCommandMessage(this.Connection, new LogicChangeAllianceRoleCommand(this.Connection) { Role = Alliance.Role.Member }).Send(); new AvailableServerCommandMessage(this.Connection, new LogicJoinAllianceCommand(this.Connection)).Send(); new AllianceStreamMessage(this.Connection).Send(); alliance.AddEntry(new StreamEntry(member, member, StreamEntry.StreamEvent.Joined)); this.Connection.Avatar.Save(); } } }
internal override void Handle() { LogicClientAvatar avatar = this.Connection.Avatar; Alliance alliance = avatar.Alliance; if (alliance != null) { AllianceMember member = alliance.Members.Find(m => m.Identifier == avatar.Identifier); avatar.ClanHighID = 0; avatar.ClanLowID = 0; avatar.Save(); if (alliance.Members.Size == 0) { Alliances.Delete(alliance); } else { if (member.Role == (int)Alliance.Role.Leader) { LeaveAllianceMessage.FindNewLeader(alliance, member); } } new AvailableServerCommandMessage(this.Connection, new LogicLeaveAllianceCommand(this.Connection, alliance.Identifier)).Send(); alliance.AddEntry(new StreamEntry(member, member, StreamEntry.StreamEvent.Left)); alliance.Members.Remove(member); Alliances.Save(alliance); } }
internal override void Handle() { Alliance alliance = Alliances.Get(this.Connection.Avatar.Alliance.Identifier); if (alliance != null) { AllianceMember member = alliance.Members.Find(m => m.Identifier == this.MemberID); AllianceMember sender = alliance.Members.Find(m => m.Identifier == this.Connection.Avatar.Identifier); alliance.AddEntry(new StreamEntry(member, sender, ChangeAllianceMemberRoleMessage.IsHigherRoleThan(this.Role, member.Role) ? StreamEntry.StreamEvent.Promoted : StreamEntry.StreamEvent.Demoted)); member.Role = this.Role; if (this.Role == (int)Alliance.Role.Leader) { sender.Role = (int)Alliance.Role.CoLeader; alliance.AddEntry(new StreamEntry(sender, sender, StreamEntry.StreamEvent.Demoted)); } Alliances.Save(alliance); new AvailableServerCommandMessage(this.Connection, new LogicChangeAllianceRoleCommand(this.Connection) { Role = (Alliance.Role) this.Role }).Send(); } }
internal override void Execute() { LogicClientAvatar avatar = Avatars.Get(this.Identifier); if (avatar != null) { Alliance alliance = avatar.Alliance; AllianceMember allianceMember = alliance.Members.Find(member => member.Identifier == this.Identifier); if (allianceMember != null) { alliance.Members.Remove(allianceMember); } Alliances.Save(alliance); } }
internal override void Handle() { if (this.Connection.Avatar.IsInAlliance) { Alliance alliance = Alliances.Get(this.Connection.Avatar.Alliance.Identifier); if (alliance != null) { this.CheckValues(alliance); Alliances.Save(alliance); foreach (LogicClientAvatar avatar in alliance.Members.Select(member => Avatars.Get(member.Identifier)).Where(avatar => avatar.Connection != null)) { new AvailableServerCommandMessage(avatar.Connection, new LogicAllianceSettingsChangedCommand(this.Connection) { Badge = this.BadgeData }).Send(); } } } }
internal override void Handle() { if (!this.Connection.Avatar.IsInAlliance && this.Connection.Avatar.Gold >= 10000) { this.Connection.Avatar.Gold -= 10000; } Alliance alliance = Alliances.Create(); if (alliance != null) { alliance.Name = this.AllianceName; alliance.Description = this.AllianceDescription; alliance.Badge = this.BadgeData.GlobalID; alliance.Type = (Hiring)this.Type; alliance.RequiredTrophies = this.TrophyLimit; alliance.Members.Add(new AllianceMember(this.Connection.Avatar, Alliance.Role.Leader)); Alliances.Save(alliance); this.Connection.Avatar.ClanHighID = alliance.HighID; this.Connection.Avatar.ClanLowID = alliance.LowID; new AvailableServerCommandMessage(this.Connection, new LogicChangeAllianceRoleCommand(this.Connection) { Alliance = alliance, Role = Alliance.Role.Leader }).Send(); new AvailableServerCommandMessage(this.Connection, new LogicJoinAllianceCommand(this.Connection) { Alliance = alliance }).Send(); } this.Connection.Avatar.Save(); }
/// <summary> /// Shuts down the server. /// </summary> internal static void Exit() { var method = MethodBase.GetCurrentMethod(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Shutting down..."); Debugger.Info("Server is shutting down..."); Task task = Task.Run(() => { if (Connections.Count > 0) { Connections.ForEach(connection => { if (connection != null && connection.State >= State.LoggedIn) { new MaintenanceInboundMessage(connection).Send(); new DisconnectedMessage(connection).Send(); } }); Debugger.Info("Warned every player about the maintenance.", method); } }); int timeout = 1000; bool saveAvatars = false; bool saveAlliances = false; if (Avatars.Count > 0) { saveAvatars = true; timeout += 500; } if (Alliances.Count > 0) { saveAlliances = true; timeout += 500; } if (saveAvatars || saveAlliances) { Task pTask = new Task(() => Avatars.Save()); Task cTask = new Task(() => Alliances.Save()); if (saveAvatars) { pTask.Start(); } if (saveAlliances) { cTask.Start(); } if (saveAvatars) { pTask.Wait(); } if (saveAlliances) { cTask.Wait(); } } else { Debugger.Info("Server has nothing to save, shutting down immediately."); } task.Wait(5000); Thread.Sleep(timeout); Environment.Exit(0); }
/// <summary> /// Saves the specified avatar. /// </summary> internal static void Save(this LogicClientAvatar avatar, DBMS database = Settings.Database) { Avatars.Save(avatar, database); Alliances.Save(avatar.Alliance, database); }