Beispiel #1
0
        private void ServerSendMiningSoundCue(IDynamicWorldObject objectDrone, ICharacter characterOwner)
        {
            using var observers = Api.Shared.GetTempList <ICharacter>();
            var eventNetworkRadius = (byte)Math.Max(
                15,
                Math.Ceiling(this.ProtoItemMiningTool.SoundPresetWeaponDistance.max));

            Server.World.GetCharactersInRadius(objectDrone.TilePosition,
                                               observers,
                                               radius: eventNetworkRadius,
                                               onlyPlayers: true);
            observers.Remove(characterOwner);

            if (observers.Count == 0)
            {
                return;
            }

            var partyId = PartySystem.ServerGetParty(characterOwner)?.Id ?? 0;

            this.CallClient(observers.AsList(),
                            _ => _.ClientRemote_OnMiningSoundCue(objectDrone,
                                                                 partyId,
                                                                 objectDrone.TilePosition));
        }
Beispiel #2
0
        public string Execute(ICharacter player, string clanTag = null)
        {
            var party = PartySystem.ServerGetParty(player);

            if (party is null)
            {
                return($"Player \"{player.Name}\" has no party");
            }

            PartySystem.ServerSetClanTag(party, clanTag);
            return("Party clan tag set successfully");
        }
        private void ServerCharacterJoinedOrLeftPartyHandler(ICharacter character)
        {
            if (PartySystem.ServerGetParty(character) is null)
            {
                return;
            }

            var context = this.GetActiveContext(character, out _);

            context?.Refresh();

            this.RefreshContextForPartyMembers(character);
        }
Beispiel #4
0
        public static void ServerSetupClaim(
            ILogicObject objectClaim,
            ICharacter character,
            IWorldObject worldObject,
            double durationSeconds)
        {
            var publicState = GetPublicState(objectClaim);

            publicState.PlayerCharacterId = character.Id;
            publicState.PlayerPartyId     = PartySystem.ServerGetParty(character)?.Id ?? 0;
            publicState.ExpirationTime    = Server.Game.FrameTime + durationSeconds;
            publicState.WorldObject       = worldObject;
        }
        private static List <ICharacter> ServerGetOnlineStatusChangeReceivers(
            ICharacter aboutPlayerCharacter)
        {
            var list = Server.Characters
                       .EnumerateAllPlayerCharacters(onlyOnline: true)
                       .ToList();

            for (var index = 0; index < list.Count; index++)
            {
                var character = list[index];
                if (ReferenceEquals(character, aboutPlayerCharacter))
                {
                    list.RemoveAt(index);
                    break;
                }
            }

            var aboutPlayerCharacterParty = PartySystem.ServerGetParty(aboutPlayerCharacter);

            List <ICharacter> onlineStatusChangeReceivers;

            if (ServerIsListHidden)
            {
                // only server operators, moderators, and party members will receive a notification
                onlineStatusChangeReceivers = new List <ICharacter>(list.Count);
                foreach (var character in list)
                {
                    if (ServerIsOperatorOrModerator(character) ||
                        (aboutPlayerCharacterParty is not null &&
                         ReferenceEquals(aboutPlayerCharacterParty,
                                         PartySystem.ServerGetParty(character))))
                    {
                        onlineStatusChangeReceivers.Add(character);
                    }
                }
            }
            else
            {
                // all players will receive a notification about the status change for this player
                onlineStatusChangeReceivers = list;
            }

            return(onlineStatusChangeReceivers);
        }
Beispiel #6
0
        private static void SharedCallOnWeaponShot(
            ICharacter character,
            IProtoItemWeapon protoWeapon)
        {
            if (IsClient)
            {
                // start firing weapon on Client-side
                WeaponSystemClientDisplay.ClientOnWeaponShot(character,
                                                             partyId:
                                                             0, // not relevant here as it's the current player firing the weapon
                                                             protoWeapon: protoWeapon,
                                                             protoCharacter: character.ProtoCharacter,
                                                             fallbackPosition: character.Position.ToVector2Ushort());
            }
            else // if IsServer
            {
                using var observers = Shared.GetTempList <ICharacter>();
                var eventNetworkRadius = (byte)Math.Max(
                    15,
                    Math.Ceiling(protoWeapon.SoundPresetWeaponDistance.max));

                Server.World.GetCharactersInRadius(character.TilePosition,
                                                   observers,
                                                   radius: eventNetworkRadius,
                                                   onlyPlayers: true);
                observers.Remove(character);

                if (observers.Count > 0)
                {
                    var partyId = PartySystem.ServerGetParty(character)?.Id ?? 0;

                    Instance.CallClient(observers.AsList(),
                                        _ => _.ClientRemote_OnWeaponShot(character,
                                                                         partyId,
                                                                         protoWeapon,
                                                                         character.ProtoCharacter,
                                                                         character.Position.ToVector2Ushort()));
                }
            }
        }
Beispiel #7
0
        public string Execute(ICharacter player)
        {
            var party = PartySystem.ServerGetParty(player);

            if (party is null)
            {
                return($"Player \"{player.Name}\" has no party");
            }

            var memberNames = PartySystem.ServerGetPartyMembersReadOnly(party);
            var sb          = new StringBuilder("Player \"")
                              .Append(player.Name)
                              .AppendLine("\" - party info:")
                              .AppendLine("Members list: ");

            foreach (var memberName in memberNames)
            {
                sb.Append(" * ").AppendLine(memberName);
            }

            return(sb.ToString());
        }
Beispiel #8
0
        private void ServerSendOnlineListAndOtherInfo(ICharacter playerCharacter)
        {
            if (!playerCharacter.ServerIsOnline)
            {
                return;
            }

            var isOperatorOrModerator = ServerIsOperatorOrModerator(playerCharacter);
            var isListHidden          = SharedIsListHidden &&
                                        !isOperatorOrModerator;

            var onlinePlayersList = new List <Entry>();

            if (isListHidden)
            {
                // send only the party and faction members
                var faction = FactionSystem.ServerGetFaction(playerCharacter);
                if (faction is not null)
                //&& FactionSystem.SharedGetFactionKind(faction) != FactionKind.Public)
                {
                    var factionClanTag = FactionSystem.SharedGetClanTag(faction);
                    onlinePlayersList.AddRange(
                        Server.Characters
                        .EnumerateAllPlayerCharacters(onlyOnline: true)
                        .ExceptOne(playerCharacter)
                        .Where(c => factionClanTag == FactionSystem.SharedGetClanTag(c))
                        .Select(c => new Entry(c.Name, factionClanTag)));
                }

                var party = PartySystem.ServerGetParty(playerCharacter);
                if (party is not null)
                {
                    var partyMembers = Server.Characters
                                       .EnumerateAllPlayerCharacters(onlyOnline: true)
                                       .ExceptOne(playerCharacter)
                                       .Where(c => party == PartySystem.ServerGetParty(c))
                                       .Select(c => new Entry(c.Name, FactionSystem.SharedGetClanTag(c)));
                    if (onlinePlayersList.Count == 0)
                    {
                        onlinePlayersList.AddRange(partyMembers);
                    }
                    else
                    {
                        foreach (var entry in partyMembers)
                        {
                            onlinePlayersList.AddIfNotContains(entry);
                        }
                    }
                }
            }
            else
            {
                onlinePlayersList = Server.Characters
                                    .EnumerateAllPlayerCharacters(onlyOnline: true)
                                    .ExceptOne(playerCharacter)
                                    .Select(c => new Entry(c.Name,
                                                           FactionSystem.SharedGetClanTag(c)))
                                    .ToList();
            }

            // uncomment to test the online players list with some fake data
            //onlineList.Add(new Entry("Aaa1", "XXX"));
            //onlineList.Add(new Entry("Ссс1", "XXX"));
            //onlineList.Add(new Entry("Bbb1", "XXX"));
            //onlineList.Add(new Entry("Aaa", ""));
            //onlineList.Add(new Entry("Ссс", null));
            //onlineList.Add(new Entry("Bbb", ""));
            //onlineList.Add(new Entry("Aaa2", "YYY"));
            //onlineList.Add(new Entry("Ссс2", "YYY"));
            //onlineList.Add(new Entry("Bbb2", "YYY"));

            this.CallClient(playerCharacter,
                            _ => _.ClientRemote_OnlinePlayersList(onlinePlayersList,
                                                                  isListHidden
                                                                      ? Server.Characters.OnlinePlayersCount
                                                                      : 0));

            // provide info about the total players count only to a server operator or moderator
            var totalPlayersCount = isOperatorOrModerator
                                        ? serverLastTotalPlayersCount
                                        : 0;

            this.CallClient(playerCharacter,
                            _ => _.ClientRemote_TotalPlayerCharactersCountChanged(totalPlayersCount));
        }
Beispiel #9
0
        private static List <ICharacter> ServerGetOnlineStatusChangeReceivers(ICharacter aboutPlayerCharacter)
        {
            var list = Server.Characters
                       .EnumerateAllPlayerCharacters(onlyOnline: true)
                       .ToList();

            for (var index = 0; index < list.Count; index++)
            {
                var character = list[index];
                if (ReferenceEquals(character, aboutPlayerCharacter))
                {
                    list.RemoveAt(index);
                    break;
                }
            }

            var    aboutPlayerCharacterParty          = PartySystem.ServerGetParty(aboutPlayerCharacter);
            string aboutPlayerCharacterFactionClanTag = null;
            {
                var faction = FactionSystem.ServerGetFaction(aboutPlayerCharacter);
                if (faction is not null)
                {
                    /*if (FactionSystem.SharedGetFactionKind(faction) == FactionKind.Public)
                     * {
                     *  // public faction doesn't provide online status of faction members
                     * }
                     * else
                     * {*/
                    aboutPlayerCharacterFactionClanTag = FactionSystem.SharedGetClanTag(faction);
                    //}
                }
            }

            List <ICharacter> onlineStatusChangeReceivers;

            if (SharedIsListHidden)
            {
                // only server operators, moderators, and party members will receive a notification
                onlineStatusChangeReceivers = new List <ICharacter>(list.Count);
                foreach (var character in list)
                {
                    if (ServerIsOperatorOrModerator(character) ||
                        (aboutPlayerCharacterFactionClanTag is not null &&
                         string.Equals(aboutPlayerCharacterFactionClanTag,
                                       FactionSystem.SharedGetClanTag(character))) ||
                        (aboutPlayerCharacterParty is not null &&
                         ReferenceEquals(aboutPlayerCharacterParty,
                                         PartySystem.ServerGetParty(character))))
                    {
                        onlineStatusChangeReceivers.Add(character);
                    }
                }
            }
            else
            {
                // all players will receive a notification about the status change for this player
                onlineStatusChangeReceivers = list;
            }

            return(onlineStatusChangeReceivers);
        }
        private void ServerSendOnlineListAndOtherInfo(ICharacter playerCharacter)
        {
            if (!playerCharacter.ServerIsOnline)
            {
                return;
            }

            var isOperatorOrModerator = ServerIsOperatorOrModerator(playerCharacter);
            var isListHidden          = ServerIsListHidden &&
                                        !isOperatorOrModerator;

            IReadOnlyList <Entry> onlinePlayersList;

            if (isListHidden)
            {
                // send only the party members
                var party = PartySystem.ServerGetParty(playerCharacter);
                if (party is null)
                {
                    onlinePlayersList = Array.Empty <Entry>();
                }
                else
                {
                    onlinePlayersList = Server.Characters
                                        .EnumerateAllPlayerCharacters(onlyOnline: true)
                                        .ExceptOne(playerCharacter)
                                        .Where(c => party == PartySystem.ServerGetParty(c))
                                        .Select(c => new Entry(c.Name,
                                                               ServerGetClanTag(c)))
                                        .ToList();
                }
            }
            else
            {
                onlinePlayersList = Server.Characters
                                    .EnumerateAllPlayerCharacters(onlyOnline: true)
                                    .ExceptOne(playerCharacter)
                                    .Select(c => new Entry(c.Name,
                                                           ServerGetClanTag(c)))
                                    .ToList();
            }

            // uncomment to test the online players list with some fake data
            //onlineList.Add(new Entry("Aaa1", "XXX"));
            //onlineList.Add(new Entry("Ссс1", "XXX"));
            //onlineList.Add(new Entry("Bbb1", "XXX"));
            //onlineList.Add(new Entry("Aaa", ""));
            //onlineList.Add(new Entry("Ссс", null));
            //onlineList.Add(new Entry("Bbb", ""));
            //onlineList.Add(new Entry("Aaa2", "YYY"));
            //onlineList.Add(new Entry("Ссс2", "YYY"));
            //onlineList.Add(new Entry("Bbb2", "YYY"));

            this.CallClient(playerCharacter,
                            _ => _.ClientRemote_OnlinePlayersList(onlinePlayersList,
                                                                  isListHidden,
                                                                  isListHidden
                                                                      ? Server.Characters.OnlinePlayersCount
                                                                      : 0));

            // provide info about the total players count only to a server operator or moderator
            var totalPlayersCount = isOperatorOrModerator
                                        ? serverLastTotalPlayersCount
                                        : 0;

            this.CallClient(playerCharacter,
                            _ => _.ClientRemote_TotalPlayerCharactersCountChanged(totalPlayersCount));
        }