コード例 #1
0
        private static void ConfirmMessage(ref ConfirmFactionMessageMsg message, long localPlayerId)
        {
            MyChatHistory chatHistory;

            if (!MySession.Static.ChatHistory.TryGetValue(localPlayerId, out chatHistory))
            {
                chatHistory = new MyChatHistory(localPlayerId);
            }

            var timestamp = new TimeSpan(message.Timestamp);
            var chatItem  = FindFactionChatItem(localPlayerId, message.FactionId1, message.FactionId2, timestamp, message.Text);

            if (chatItem != null)
            {
                chatItem.PlayersToSendTo[message.ReceiverId] = true;
                if (!MySandboxGame.IsDedicated)
                {
                    MySession.Static.ChatSystem.OnNewFactionMessage(message.FactionId1, message.FactionId2, message.OriginalSenderId, false);
                }
            }
            else
            {
                Debug.Fail("Could not find faction chat history between faction " + message.FactionId1 + " and " + message.FactionId2);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        private static void SendConfirmMessageToFaction(long factionId, Dictionary <long, bool> PlayersToSendTo, ref ConfirmFactionMessageMsg confirmMessage)
        {
            var receiverFaction = MySession.Static.Factions.TryGetFactionById(factionId);

            foreach (var member in receiverFaction.Members)
            {
                MyPlayer.PlayerId playerId;
                bool sendToMember = false;
                if (PlayersToSendTo.TryGetValue(member.Key, out sendToMember))
                {
                    if (MySession.Static.Players.TryGetPlayerId(member.Value.PlayerId, out playerId) && sendToMember)
                    {
                        Sync.Layer.SendMessage(confirmMessage, playerId.SteamId, MyTransportMessageEnum.Success);

                        //Save chat history on server for non-server players
                        if (member.Value.PlayerId != MySession.LocalPlayerId)
                        {
                            ConfirmMessage(ref confirmMessage, member.Value.PlayerId);
                        }
                    }
                }
            }
        }
コード例 #4
0
 private static void OnConfirmFactionMessageSuccess(MySyncCharacter syncObject, ref ConfirmFactionMessageMsg message, MyNetworkClient sender)
 {
     ConfirmMessage(ref message, MySession.LocalPlayerId);
 }
コード例 #5
0
        private static void ConfirmMessage(ref ConfirmFactionMessageMsg message, long localPlayerId)
        {
            MyChatHistory chatHistory;
            if (!MySession.Static.ChatHistory.TryGetValue(localPlayerId, out chatHistory))
            {
                chatHistory = new MyChatHistory(localPlayerId);
            }

            var timestamp = new TimeSpan(message.Timestamp);
            var chatItem = FindFactionChatItem(localPlayerId, message.FactionId1, message.FactionId2, timestamp, message.Text);
            if (chatItem != null)
            {
                chatItem.PlayersToSendTo[message.ReceiverId] = true;
                if (!MySandboxGame.IsDedicated)
                {
                    MySession.Static.ChatSystem.OnNewFactionMessage(message.FactionId1, message.FactionId2, message.OriginalSenderId, false);
                }
            }
            else
            {
                Debug.Fail("Could not find faction chat history between faction " + message.FactionId1 + " and " + message.FactionId2);
            }
        }
コード例 #6
0
 private static void OnConfirmFactionMessageSuccess(MySyncCharacter syncObject, ref ConfirmFactionMessageMsg message, MyNetworkClient sender)
 {
     ConfirmMessage(ref message, MySession.LocalPlayerId);
 }
コード例 #7
0
        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;
        }
コード例 #8
0
        private static void SendConfirmMessageToFaction(long factionId, Dictionary<long, bool> PlayersToSendTo, ref ConfirmFactionMessageMsg confirmMessage)
        {
            var receiverFaction = MySession.Static.Factions.TryGetFactionById(factionId);
            foreach (var member in receiverFaction.Members)
            {
                MyPlayer.PlayerId playerId;
                bool sendToMember = false;
                if (PlayersToSendTo.TryGetValue(member.Key, out sendToMember))
                {
                    if (MySession.Static.Players.TryGetPlayerId(member.Value.PlayerId, out playerId) && sendToMember)
                    {
                        Sync.Layer.SendMessage(ref confirmMessage, playerId.SteamId, MyTransportMessageEnum.Success);

                        //Save chat history on server for non-server players
                        if (member.Value.PlayerId != MySession.LocalPlayerId)
                        {
                            ConfirmMessage(ref confirmMessage, member.Value.PlayerId);
                        }
                    }
                }
            }
        }