public string Execute(bool isEnabled, [CurrentCharacterIfNull] ICharacter character) { if (isEnabled) { NewbieProtectionSystem.ServerRegisterNewbie(character); } else { NewbieProtectionSystem.ServerDisableNewbieProtection(character); } return(character + " is now " + (NewbieProtectionSystem.SharedIsNewbie(character) ? "under newbie protection." : "without newbie protection.")); }
private static void ServerAddMember( ICharacter character, ILogicObject faction, FactionMemberRole role) { Api.Assert(!character.IsNpc, "NPC cannot join a faction"); if (!SharedIsValidRole(role)) { throw new Exception("Invalid role: " + role); } var currentFaction = ServerGetFaction(character); if (currentFaction == faction) { // already in faction return; } if (currentFaction is not null) { throw new Exception($"Player already has a faction: {character} in {faction}"); } // faction members cannot have a newbie protection NewbieProtectionSystem.ServerDisableNewbieProtection(character); var members = ServerGetFactionMembersEditable(faction); var factionPublicState = Faction.GetPublicState(faction); var maxMembers = FactionConstants.SharedGetFactionMembersMax(factionPublicState.Kind); if (members.Count >= maxMembers) { throw new Exception("Faction size exceeded - max " + maxMembers); } if (role == FactionMemberRole.Leader) { foreach (var otherMember in members) { if (otherMember.Role == FactionMemberRole.Leader) { throw new Exception("Faction can have only a single leader"); } } } members.Add(new FactionMemberEntry(character.Name, role)); ServerCharacterFactionDictionary[character] = faction; PlayerCharacter.GetPublicState(character).ClanTag = factionPublicState.ClanTag; factionPublicState.PlayersNumberCurrent++; Logger.Important($"Player joined faction: {character} in {faction} - role: {role}", character); ServerInvitations.RemoveAllInvitationsFor(character); Api.SafeInvoke( () => ServerCharacterJoinedOrLeftFaction?.Invoke(character, faction, isJoined: true)); // add this with some delay to prevent from the bug when the player name listed twice due to the late delta-replication ServerTimersSystem.AddAction(delaySeconds: 0.1, () => ServerSendCurrentFaction(character)); }