Пример #1
0
        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);
            }
        }
Пример #2
0
        private static void OnFactionMessageSuccess(MySyncCharacter sync, ref SendNewFactionMessageMsg msg, MyNetworkClient sender)
        {
            long senderIdentityId = MyEntityIdentifier.ConstructId(MyEntityIdentifier.ID_OBJECT_TYPE.IDENTITY, msg.ChatItem.IdentityIdUniqueNumber);

            var factionChatItem = new MyFactionChatItem();

            factionChatItem.Init(msg.ChatItem);
            if (!(Sync.IsServer && senderIdentityId != MySession.LocalPlayerId))
            {
                MyChatSystem.AddFactionChatItem(MySession.LocalPlayerId, msg.FactionId1, msg.FactionId2, factionChatItem);
            }
            if (senderIdentityId != MySession.LocalPlayerId)
            {
                MySession.Static.Gpss.ScanText(factionChatItem.Text, MyTexts.GetString(MySpaceTexts.TerminalTab_GPS_NewFromFactionComms));
            }
            MySession.Static.ChatSystem.OnNewFactionMessage(msg.FactionId1, msg.FactionId2, senderIdentityId, true);
        }