Beispiel #1
0
        public void Update()
        {
            //Hard-coded half-a-second update
            cnt = (++cnt) % 30;
            if (cnt != 0)
            {
                return;
            }

            if (previousMutualConnectionGrids == null)
            {
                previousMutualConnectionGrids = MyAntennaSystem.GetMutuallyConnectedGrids(m_openInventoryInteractedEntityRepresentative);
            }

            if (previousShipInfo == null)
            {
                previousShipInfo = GetAllCubeGridsInfo();
            }

            var currentMutualConnectionGrids = MyAntennaSystem.GetMutuallyConnectedGrids(m_openInventoryInteractedEntityRepresentative);
            var currentShipInfo = GetAllCubeGridsInfo();

            if (!previousMutualConnectionGrids.SetEquals(currentMutualConnectionGrids))
            {
                PopulateMutuallyConnectedCubeGrids(currentMutualConnectionGrids);
            }

            if (!previousShipInfo.SequenceEqual(currentShipInfo))
            {
                PopulateOwnedCubeGrids(currentShipInfo);
            }

            previousMutualConnectionGrids = currentMutualConnectionGrids;
            previousShipInfo = currentShipInfo;
        }
Beispiel #2
0
        //Rule: The representative of block is its cube grid, the representative of a character is himself
        private MyEntity GetInteractedEntityRepresentative(MyEntity controlledEntity)
        {
            if (controlledEntity is MyCubeBlock)
            {
                return(MyAntennaSystem.GetLogicalGroupRepresentative((controlledEntity as MyCubeBlock).CubeGrid));
            }

            //assumption: it is impossible to open the character control panel when in a ship
            return(MySession.LocalCharacter);
        }
        private static void OnFactionMessageRequest(MySyncCharacter sync, ref SendNewFactionMessageMsg msg, MyNetworkClient sender)
        {
            //Ignore messages that have improper lengths
            if (msg.ChatItem.Text.Length == 0 || msg.ChatItem.Text.Length > MyChatConstants.MAX_CHAT_STRING_LENGTH)
            {
                return;
            }

            long currentSenderId = MyEntityIdentifier.ConstructId(MyEntityIdentifier.ID_OBJECT_TYPE.IDENTITY, msg.ChatItem.IdentityIdUniqueNumber);
            var  senderId        = MySession.Static.Players.TryGetIdentity(currentSenderId);

            var chatItem = new MyFactionChatItem();

            chatItem.Init(msg.ChatItem);

            //Find all members that can receive this messages
            m_tempValidIds.Clear();
            for (int i = 0; i < msg.ChatItem.PlayersToSendToUniqueNumber.Count; i++)
            {
                if (!msg.ChatItem.IsAlreadySentTo[i])
                {
                    long receiverIdentityId = MyEntityIdentifier.ConstructId(MyEntityIdentifier.ID_OBJECT_TYPE.IDENTITY, msg.ChatItem.PlayersToSendToUniqueNumber[i]);
                    var  receiverId         = MySession.Static.Players.TryGetIdentity(receiverIdentityId);
                    if (receiverId != null && receiverId.Character != null && MyAntennaSystem.CheckConnection(senderId, receiverId))
                    {
                        m_tempValidIds.Add(receiverIdentityId);
                    }
                }
            }

            //Set their sent flag to true, so that everyone knows they already got it (no need for confirm message)
            foreach (var id in m_tempValidIds)
            {
                chatItem.PlayersToSendTo[id] = true;
            }

            //Save the flags back in the message
            msg.ChatItem = chatItem.GetObjectBuilder();

            //Send success message back to all recepient members
            foreach (var id in m_tempValidIds)
            {
                MyPlayer.PlayerId receiverPlayerId;
                MySession.Static.Players.TryGetPlayerId(id, out receiverPlayerId);
                ulong steamId = receiverPlayerId.SteamId;

                Sync.Layer.SendMessage(ref msg, steamId, MyTransportMessageEnum.Success);
            }

            //Save chat history on server for non-server players
            if (senderId.Character != MySession.LocalCharacter)
            {
                MyChatSystem.AddFactionChatItem(senderId.IdentityId, msg.FactionId1, msg.FactionId2, chatItem);
            }
        }
Beispiel #4
0
        private void PlayerBroadcastersFromGrid(MyCubeGrid grid, List <MyDataBroadcaster> output)
        {
            MyDebug.AssertDebug(output.Count == 0, "Output was not cleared before use!");

            m_tempPlayerBroadcasters.Clear();
            MyAntennaSystem.GetPlayerRelayedBroadcasters(MySession.LocalCharacter, m_openInventoryInteractedEntityRepresentative, m_tempPlayerBroadcasters);
            foreach (var broadcaster in m_tempPlayerBroadcasters)
            {
                if (MyAntennaSystem.GetBroadcasterParentEntityId(broadcaster) == grid.EntityId)
                {
                    output.Add(broadcaster);
                }
            }
        }
Beispiel #5
0
        private HashSet <CubeGridInfo> GetAllCubeGridsInfo()
        {
            HashSet <CubeGridInfo> output     = new HashSet <CubeGridInfo>();
            HashSet <long>         AddedItems = new HashSet <long>();

            //First, you always add yourself
            AddedItems.Add(m_openInventoryInteractedEntityRepresentative.EntityId);
            output.Add(new CubeGridInfo()
            {
                EntityId         = m_openInventoryInteractedEntityRepresentative.EntityId,
                Distance         = 0,
                AppendedDistance = new StringBuilder("0"),
                Name             = m_openInventoryInteractedEntityRepresentative.DisplayName,
                Status           = m_openInventoryInteractedEntityRepresentative == MySession.LocalCharacter ? MyCubeGridConnectionStatus.Me : MyCubeGridConnectionStatus.PhysicallyConnected
            });

            //then you add your owned grids
            foreach (var gridId in MySession.LocalHumanPlayer.Grids)
            {
                MyCubeGrid grid;
                if (!MyEntities.TryGetEntityById <MyCubeGrid>(gridId, out grid))
                {
                    continue;
                }

                if (!PlayerOwnsShip(grid))
                {
                    continue;
                }

                var representative = MyAntennaSystem.GetLogicalGroupRepresentative(grid);
                if (AddedItems.Contains(representative.EntityId))
                {
                    continue;
                }

                AddedItems.Add(representative.EntityId);
                float dist = GetPlayerGridDistance(representative);
                output.Add(new CubeGridInfo()
                {
                    EntityId         = representative.EntityId,
                    Distance         = dist,
                    AppendedDistance = new StringBuilder().AppendDecimal(dist, 0),
                    Name             = representative.DisplayName,
                    Status           = GetShipStatus(representative)
                });
            }

            return(output);
        }
Beispiel #6
0
        private void GridBroadcastersFromPlayer(MyCubeGrid grid, List <MyDataBroadcaster> output)
        {
            MyDebug.AssertDebug(output.Count == 0, "Output was not cleared before use!");

            var gridBroadcasters   = MyRadioBroadcaster.GetGridRelayedBroadcasters(grid);
            var controlledObjectId = m_openInventoryInteractedEntityRepresentative.EntityId;

            foreach (var broadcaster in gridBroadcasters)
            {
                if (MyAntennaSystem.GetBroadcasterParentEntityId(broadcaster) == controlledObjectId)
                {
                    output.Add(broadcaster);
                }
            }
        }
        private bool CheckRangeAndAccess(IMyControllableEntity controlledEntity, MyPlayer player)
        {
            var terminal = controlledEntity as MyTerminalBlock;

            if (terminal == null)
            {
                var character = controlledEntity as MyCharacter;
                if (character != null)
                {
                    return(MyAntennaSystem.CheckConnection(character, CubeGrid, player));
                }
                else
                {
                    return(true);
                }
            }

            MyCubeGrid playerGrid = terminal.SlimBlock.CubeGrid;

            return(MyAntennaSystem.CheckConnection(playerGrid, CubeGrid, player));
        }
        public static bool RetryFactionMessage(long factionId1, long factionId2, MyFactionChatItem chatItem, MyIdentity currentSenderIdentity)
        {
            Debug.Assert(Sync.IsServer, "Faction message retries should only be done on server");

            if (currentSenderIdentity.Character == null)
            {
                return(false);
            }

            m_tempValidIds.Clear();
            foreach (var playerToSendTo in chatItem.PlayersToSendTo)
            {
                if (!playerToSendTo.Value)
                {
                    long receiverIdentityId = playerToSendTo.Key;
                    var  receiverId         = MySession.Static.Players.TryGetIdentity(receiverIdentityId);
                    if (receiverId != null && receiverId.Character != null && MyAntennaSystem.CheckConnection(currentSenderIdentity, receiverId))
                    {
                        m_tempValidIds.Add(receiverIdentityId);
                    }
                }
            }

            if (m_tempValidIds.Count == 0)
            {
                return(false);
            }

            foreach (var id in m_tempValidIds)
            {
                chatItem.PlayersToSendTo[id] = true;
            }

            var msg = new SendNewFactionMessageMsg();

            msg.FactionId1        = factionId1;
            msg.FactionId2        = factionId2;
            msg.CharacterEntityId = currentSenderIdentity.Character.EntityId;
            msg.ChatItem          = chatItem.GetObjectBuilder();

            var confirmMessage = new ConfirmFactionMessageMsg();

            confirmMessage.CharacterEntityId = currentSenderIdentity.Character.EntityId;

            confirmMessage.FactionId1       = msg.FactionId1;
            confirmMessage.FactionId2       = msg.FactionId2;
            confirmMessage.OriginalSenderId = chatItem.IdentityId;
            confirmMessage.Timestamp        = chatItem.Timestamp.Ticks;
            confirmMessage.Text             = msg.ChatItem.Text;

            foreach (var id in m_tempValidIds)
            {
                MyPlayer.PlayerId receiverPlayerId;
                MySession.Static.Players.TryGetPlayerId(id, out receiverPlayerId);
                ulong steamId = receiverPlayerId.SteamId;

                Sync.Layer.SendMessage(ref msg, steamId, MyTransportMessageEnum.Success);
            }
            foreach (var id in m_tempValidIds)
            {
                confirmMessage.ReceiverId = id;

                //Send confimation to members of both factions
                SendConfirmMessageToFaction(confirmMessage.FactionId1, chatItem.PlayersToSendTo, ref confirmMessage);
                if (confirmMessage.FactionId1 != confirmMessage.FactionId2)
                {
                    SendConfirmMessageToFaction(confirmMessage.FactionId2, chatItem.PlayersToSendTo, ref confirmMessage);
                }
            }

            return(true);
        }
        private static void OnPlayerMessageRequest(MySyncCharacter sync, ref SendPlayerMessageMsg msg, MyNetworkClient sender)
        {
            //Ignore messages that have improper lengths
            if (msg.Text.Length == 0 || msg.Text.Length > MyChatConstants.MAX_CHAT_STRING_LENGTH)
            {
                return;
            }

            var receiverId = MySession.Static.Players.TryGetPlayerIdentity(new MyPlayer.PlayerId(msg.ReceiverSteamId));
            var senderId   = MySession.Static.Players.TryGetPlayerIdentity(new MyPlayer.PlayerId(msg.SenderSteamId));

            //TODO(AF) Check if message was already received

            if (receiverId != null && receiverId.Character != null && senderId != null && senderId.Character != null && MyAntennaSystem.CheckConnection(senderId, receiverId))
            {
                Sync.Layer.SendMessage(ref msg, msg.ReceiverSteamId, MyTransportMessageEnum.Success);
                Sync.Layer.SendMessage(ref msg, sender.SteamUserId, MyTransportMessageEnum.Success);

                //Save chat history on server for non-server players
                if (receiverId.Character != MySession.LocalCharacter)
                {
                    MyChatSystem.AddPlayerChatItem(receiverId.IdentityId, senderId.IdentityId, new MyPlayerChatItem(msg.Text, senderId.IdentityId, msg.Timestamp, true));
                }
                if (senderId.Character != MySession.LocalCharacter)
                {
                    MyChatSystem.AddPlayerChatItem(senderId.IdentityId, receiverId.IdentityId, new MyPlayerChatItem(msg.Text, senderId.IdentityId, msg.Timestamp, true));
                }
            }
        }
        public bool CheckPlayerConnection(ulong senderSteamId, ulong receiverSteamId)
        {
            var receiverId = MySession.Static.Players.TryGetPlayerIdentity(new MyPlayer.PlayerId(receiverSteamId));
            var senderId   = MySession.Static.Players.TryGetPlayerIdentity(new MyPlayer.PlayerId(senderSteamId));

            return(receiverId != null && receiverId.Character != null && senderId != null && senderId.Character != null && MyAntennaSystem.CheckConnection(senderId, receiverId));
        }
        private static void OnGlobalMessageRequest(MySyncCharacter sync, ref SendGlobalMessageMsg msg, MyNetworkClient sender)
        {
            //Ignore messages that have improper lengths
            if (msg.Text.Length == 0 || msg.Text.Length > MyChatConstants.MAX_CHAT_STRING_LENGTH)
            {
                return;
            }

            var senderId   = MySession.Static.Players.TryGetPlayerIdentity(new MyPlayer.PlayerId(msg.SenderSteamId));
            var allPlayers = MySession.Static.Players.GetOnlinePlayers();

            foreach (var player in allPlayers)
            {
                var receiverId = player.Identity;
                if (receiverId != null && receiverId.Character != null && senderId != null && senderId.Character != null && MyAntennaSystem.CheckConnection(senderId, receiverId))
                {
                    Sync.Layer.SendMessage(ref msg, player.Id.SteamId, MyTransportMessageEnum.Success);

                    //Save chat history on server for non-server players
                    if (receiverId.Character != MySession.LocalCharacter)
                    {
                        MyChatSystem.AddGlobalChatItem(player.Identity.IdentityId, new MyGlobalChatItem(msg.Text, senderId.IdentityId));
                    }
                }
            }
        }
Beispiel #12
0
 public void Refresh()
 {
     PopulateMutuallyConnectedCubeGrids(MyAntennaSystem.GetMutuallyConnectedGrids(m_openInventoryInteractedEntityRepresentative));
     PopulateOwnedCubeGrids(GetAllCubeGridsInfo());
 }