Пример #1
0
 private static void OnRequestAccepted(HighlightMsg msg)
 {
     if (msg.IsExclusive)
     {
         m_static.NotifyExclusiveHighlightAccepted(msg.Data, msg.ExclusiveKey);
     }
     else
     {
         m_static.NotifyHighlightAccepted(msg.Data);
     }
 }
Пример #2
0
 private static void OnRequestRejected(HighlightMsg msg)
 {
     if (msg.IsExclusive)
     {
         m_static.NotifyExclusiveHighlightRejected(msg.Data, msg.ExclusiveKey);
     }
     else
     {
         if (m_static.HighlightRejected != null)
         {
             m_static.HighlightRejected(msg.Data);
         }
     }
 }
Пример #3
0
        private static void OnHighlightOnClient(HighlightMsg msg)
        {
            // Check the exclusive locks
            if (m_static.m_exclusiveKeysToIds.ContainsValue(msg.Data.EntityId))
            {
                long id;
                if (!m_static.m_exclusiveKeysToIds.TryGetValue(msg.ExclusiveKey, out id) || id != msg.Data.EntityId)
                {
                    // The exclusive key is not valid or is used for different entityId
                    if (m_static.HighlightRejected != null)
                    {
                        m_static.HighlightRejected(msg.Data);
                    }

                    MyMultiplayer.RaiseStaticEvent(s => OnRequestRejected, msg, MyEventContext.Current.Sender);
                    return;
                }
            }

            m_static.MakeLocalHighlightChange(msg.Data);
            // Handle the exclusive key
            if (msg.IsExclusive)
            {
                var enableHighlight = msg.Data.Thickness > -1;
                // Default value we need to generate one.
                if (msg.ExclusiveKey == -1)
                {
                    msg.ExclusiveKey = m_exclusiveKeyCounter++;

                    if (enableHighlight && !m_static.m_exclusiveKeysToIds.ContainsKey(msg.ExclusiveKey))
                    {
                        // Adding highlight/Updating
                        m_static.m_exclusiveKeysToIds.Add(msg.ExclusiveKey, msg.Data.EntityId);
                    }
                }

                if (!enableHighlight)
                {
                    // Removing Highlight
                    m_static.m_exclusiveKeysToIds.Remove(msg.ExclusiveKey);
                }
            }

            MyMultiplayer.RaiseStaticEvent(s => OnRequestAccepted, msg, MyEventContext.Current.Sender);
        }
Пример #4
0
 private static void OnRequestAccepted(HighlightMsg msg)
 {
     if (msg.IsExclusive)
     {
         m_static.NotifyExclusiveHighlightAccepted(msg.Data, msg.ExclusiveKey);
     }
     else
     {
         m_static.NotifyHighlightAccepted(msg.Data);
     }
 }
Пример #5
0
 private static void OnRequestRejected(HighlightMsg msg)
 {
     if (msg.IsExclusive)
     {
         m_static.NotifyExclusiveHighlightRejected(msg.Data, msg.ExclusiveKey);
     }
     else
     {
         if(m_static.HighlightRejected != null)
             m_static.HighlightRejected(msg.Data);
     }
 }
Пример #6
0
        private static void OnHighlightOnClient(HighlightMsg msg)
        {
            // Check the exclusive locks
            if(m_static.m_exclusiveKeysToIds.ContainsValue(msg.Data.EntityId))
            {
                long id;
                if(!m_static.m_exclusiveKeysToIds.TryGetValue(msg.ExclusiveKey, out id) || id != msg.Data.EntityId)
                {
                    // The exclusive key is not valid or is used for different entityId
                    if(m_static.HighlightRejected != null)
                        m_static.HighlightRejected(msg.Data);

                    MyMultiplayer.RaiseStaticEvent(s => OnRequestRejected, msg, MyEventContext.Current.Sender);
                    return;
                }
            }

            m_static.MakeLocalHighlightChange(msg.Data);
            // Handle the exclusive key
            if (msg.IsExclusive)
            {
                var enableHighlight = msg.Data.Thickness > -1;
                // Default value we need to generate one.
                if (msg.ExclusiveKey == -1)
                {
                    msg.ExclusiveKey = m_exclusiveKeyCounter++;

                    if (enableHighlight && !m_static.m_exclusiveKeysToIds.ContainsKey(msg.ExclusiveKey))
                    {
                        // Adding highlight/Updating
                        m_static.m_exclusiveKeysToIds.Add(msg.ExclusiveKey, msg.Data.EntityId);
                    }
                }

                if (!enableHighlight)
                {
                    // Removing Highlight
                    m_static.m_exclusiveKeysToIds.Remove(msg.ExclusiveKey);
                }
            }

            MyMultiplayer.RaiseStaticEvent(s => OnRequestAccepted, msg, MyEventContext.Current.Sender);
        }
Пример #7
0
        // Determines if the highlight is local or global request.
        // Sends message to eighter render proxy or server.
        private void ProcessRequest(MyHighlightData data, int exclusiveKey, bool isExclusive)
        {
            // It is a local highlight
            if(data.PlayerId == -1)
            {
                data.PlayerId = MySession.Static.LocalPlayerId;
            }

            if ((MyMultiplayer.Static == null || MyMultiplayer.Static.IsServer) && data.PlayerId != MySession.Static.LocalPlayerId)
            {
                // Stop right here if id does not exist.
                MyPlayer.PlayerId _playerId;
                if (!MySession.Static.Players.TryGetPlayerId(data.PlayerId, out _playerId)) return;

                var msg =  new HighlightMsg()
                {
                    Data = data, ExclusiveKey = exclusiveKey, IsExclusive = isExclusive
                };
                // Server knows nothing, needs to ask clients for exclusive key. OnRejected or OnAccepted will give him answer.
                MyMultiplayer.RaiseStaticEvent(s => OnHighlightOnClient, msg, new EndpointId(_playerId.SteamId));
            }
            else
            {
                var enableHighlight = data.Thickness > -1;
                // Discard invalid requests
                long storedEntityId;
                if(m_exclusiveKeysToIds.ContainsValue(data.EntityId))
                { 
                    if(!m_exclusiveKeysToIds.TryGetValue(exclusiveKey, out storedEntityId) || storedEntityId != data.EntityId)
                    {
                        if(HighlightRejected != null)
                            HighlightRejected(data);

                        return;
                    }
                }

                // Give the exclusive request new local Key
                if (isExclusive)
                {
                    if (exclusiveKey == -1)
                    {
                        // Get new key from the counter
                        exclusiveKey = m_exclusiveKeyCounter++;
                    }
                    
                    if(enableHighlight)
                    { 
                        if(!m_exclusiveKeysToIds.ContainsKey(exclusiveKey))
                            m_exclusiveKeysToIds.Add(exclusiveKey, data.EntityId);
                    }
                    else
                    {
                        m_exclusiveKeysToIds.Remove(exclusiveKey);
                    }
                    
                    MakeLocalHighlightChange(data);

                    if(ExclusiveHighlightAccepted != null)
                        ExclusiveHighlightAccepted(data, exclusiveKey);
                }
                else
                {
                    MakeLocalHighlightChange(data);

                    if (HighlightAccepted != null)
                        HighlightAccepted(data);   
                }
            }
        }
Пример #8
0
        // Determines if the highlight is local or global request.
        // Sends message to eighter render proxy or server.
        private void ProcessRequest(MyHighlightData data, int exclusiveKey, bool isExclusive)
        {
            // It is a local highlight
            if (data.PlayerId == -1)
            {
                data.PlayerId = MySession.Static.LocalPlayerId;
            }

            if ((MyMultiplayer.Static == null || MyMultiplayer.Static.IsServer) && data.PlayerId != MySession.Static.LocalPlayerId)
            {
                // Stop right here if id does not exist.
                MyPlayer.PlayerId _playerId;
                if (!MySession.Static.Players.TryGetPlayerId(data.PlayerId, out _playerId))
                {
                    return;
                }

                var msg = new HighlightMsg()
                {
                    Data = data, ExclusiveKey = exclusiveKey, IsExclusive = isExclusive
                };
                // Server knows nothing, needs to ask clients for exclusive key. OnRejected or OnAccepted will give him answer.
                MyMultiplayer.RaiseStaticEvent(s => OnHighlightOnClient, msg, new EndpointId(_playerId.SteamId));
            }
            else
            {
                var enableHighlight = data.Thickness > -1;
                // Discard invalid requests
                long storedEntityId;
                if (m_exclusiveKeysToIds.ContainsValue(data.EntityId))
                {
                    if (!m_exclusiveKeysToIds.TryGetValue(exclusiveKey, out storedEntityId) || storedEntityId != data.EntityId)
                    {
                        if (HighlightRejected != null)
                        {
                            HighlightRejected(data);
                        }

                        return;
                    }
                }

                // Give the exclusive request new local Key
                if (isExclusive)
                {
                    if (exclusiveKey == -1)
                    {
                        // Get new key from the counter
                        exclusiveKey = m_exclusiveKeyCounter++;
                    }

                    if (enableHighlight)
                    {
                        if (!m_exclusiveKeysToIds.ContainsKey(exclusiveKey))
                        {
                            m_exclusiveKeysToIds.Add(exclusiveKey, data.EntityId);
                        }
                    }
                    else
                    {
                        m_exclusiveKeysToIds.Remove(exclusiveKey);
                    }

                    MakeLocalHighlightChange(data);

                    if (ExclusiveHighlightAccepted != null)
                    {
                        ExclusiveHighlightAccepted(data, exclusiveKey);
                    }
                }
                else
                {
                    MakeLocalHighlightChange(data);

                    if (HighlightAccepted != null)
                    {
                        HighlightAccepted(data);
                    }
                }
            }
        }