/// <inheritdoc />
        public void WriteDelta(Stream stream)
        {
            using (PooledBitWriter writer = PooledBitWriter.Get(stream))
            {
                writer.WriteUInt16Packed((ushort)dirtyEvents.Count);
                for (int i = 0; i < dirtyEvents.Count; i++)
                {
                    writer.WriteBits((byte)dirtyEvents[i].eventType, 2);

                    switch (dirtyEvents[i].eventType)
                    {
                    case NetworkedSetEvent <T> .EventType.Add:
                    {
                        writer.WriteObjectPacked(dirtyEvents[i].value);         //BOX
                    }
                    break;

                    case NetworkedSetEvent <T> .EventType.Remove:
                    {
                        writer.WriteObjectPacked(dirtyEvents[i].value);         //BOX
                    }
                    break;

                    case NetworkedSetEvent <T> .EventType.Clear:
                    {
                        //Nothing has to be written
                    }
                    break;
                    }
                }
            }
        }
示例#2
0
        /// <inheritdoc />
        public void WriteDelta(Stream stream)
        {
            using (PooledBitWriter writer = PooledBitWriter.Get(stream))
            {
                writer.WriteUInt16Packed((ushort)dirtyEvents.Count);
                for (int i = 0; i < dirtyEvents.Count; i++)
                {
                    writer.WriteBits((byte)dirtyEvents[i].eventType, 3);
                    switch (dirtyEvents[i].eventType)
                    {
                    //F**k me these signatures are proper aids
                    case NetworkedListEvent <T> .EventType.Add:
                    {
                        writer.WriteObjectPacked(dirtyEvents[i].value);         //BOX
                    }
                    break;

                    case NetworkedListEvent <T> .EventType.Insert:
                    {
                        writer.WriteInt32Packed(dirtyEvents[i].index);
                        writer.WriteObjectPacked(dirtyEvents[i].value);         //BOX
                    }
                    break;

                    case NetworkedListEvent <T> .EventType.Remove:
                    {
                        writer.WriteObjectPacked(dirtyEvents[i].value);         //BOX
                    }
                    break;

                    case NetworkedListEvent <T> .EventType.RemoveAt:
                    {
                        writer.WriteInt32Packed(dirtyEvents[i].index);
                    }
                    break;

                    case NetworkedListEvent <T> .EventType.Value:
                    {
                        writer.WriteInt32Packed(dirtyEvents[i].index);
                        writer.WriteObjectPacked(dirtyEvents[i].value);         //BOX
                    }

                    break;

                    case NetworkedListEvent <T> .EventType.Clear:
                    {
                        //Nothing has to be written
                    }
                    break;
                    }
                }
            }
        }
示例#3
0
 /// <inheritdoc />
 public void WriteField(Stream stream)
 {
     using (PooledBitWriter writer = PooledBitWriter.Get(stream))
     {
         writer.WriteUInt16Packed((ushort)dictionary.Count);
         foreach (KeyValuePair <TKey, TValue> pair in dictionary)
         {
             writer.WriteObjectPacked(pair.Key);
             writer.WriteObjectPacked(pair.Value);
         }
     }
 }
示例#4
0
文件: ShotData.cs 项目: bmjoy/Ballers
    public void WriteDelta(Stream stream) => WriteField(stream); // Based on default NetworkedVar implementation. This class doesnt need this

    /// <inheritdoc />
    public void WriteField(Stream stream)
    {
        using (PooledBitWriter writer = PooledBitWriter.Get(stream))
        {
            writer.WriteObjectPacked(InternalValue); //BOX
        }
    }
示例#5
0
        internal static void HandleClientRPCRequest(ulong clientId, Stream stream, string channelName, SecuritySendFlags security)
        {
            using (PooledBitReader reader = PooledBitReader.Get(stream))
            {
                ulong  networkId   = reader.ReadUInt64Packed();
                ushort behaviourId = reader.ReadUInt16Packed();
                ulong  hash        = reader.ReadUInt64Packed();
                ulong  responseId  = reader.ReadUInt64Packed();

                if (SpawnManager.SpawnedObjects.ContainsKey(networkId))
                {
                    NetworkedBehaviour behaviour = SpawnManager.SpawnedObjects[networkId].GetBehaviourAtOrderIndex(behaviourId);
                    if (behaviour != null)
                    {
                        object result = behaviour.OnRemoteClientRPC(hash, clientId, stream);

                        using (PooledBitStream responseStream = PooledBitStream.Get())
                        {
                            using (PooledBitWriter responseWriter = PooledBitWriter.Get(responseStream))
                            {
                                responseWriter.WriteUInt64Packed(responseId);
                                responseWriter.WriteObjectPacked(result);
                            }

                            InternalMessageSender.Send(clientId, MLAPIConstants.MLAPI_CLIENT_RPC_RESPONSE, channelName, responseStream, security, null);
                        }
                    }
                }
            }
        }
示例#6
0
 /// <inheritdoc />
 public void WriteField(Stream stream)
 {
     using (PooledBitWriter writer = PooledBitWriter.Get(stream))
     {
         writer.WriteUInt16Packed((ushort)list.Count);
         for (int i = 0; i < list.Count; i++)
         {
             writer.WriteObjectPacked(list[i]); //BOX
         }
     }
 }
示例#7
0
        internal static void HandleClientRPCRequest(ulong clientId, Stream stream, string channelName, SecuritySendFlags security, Action <ulong> bufferCallback)
        {
            using (PooledBitReader reader = PooledBitReader.Get(stream))
            {
                ulong  networkId   = reader.ReadUInt64Packed();
                ushort behaviourId = reader.ReadUInt16Packed();
                ulong  hash        = reader.ReadUInt64Packed();
                ulong  responseId  = reader.ReadUInt64Packed();

                if (SpawnManager.SpawnedObjects.ContainsKey(networkId))
                {
                    NetworkedBehaviour behaviour = SpawnManager.SpawnedObjects[networkId].GetBehaviourAtOrderIndex(behaviourId);

                    if (behaviour == null)
                    {
                        if (LogHelper.CurrentLogLevel <= LogLevel.Normal)
                        {
                            LogHelper.LogWarning("ClientRPCRequest message recieved for a non existant behaviour. NetworkId: " + networkId + ", behaviourIndex: " + behaviourId);
                        }
                    }
                    else
                    {
                        object result = behaviour.OnRemoteClientRPC(hash, clientId, stream);

                        using (PooledBitStream responseStream = PooledBitStream.Get())
                        {
                            using (PooledBitWriter responseWriter = PooledBitWriter.Get(responseStream))
                            {
                                responseWriter.WriteUInt64Packed(responseId);
                                responseWriter.WriteObjectPacked(result);
                            }

                            InternalMessageSender.Send(clientId, MLAPIConstants.MLAPI_CLIENT_RPC_RESPONSE, channelName, responseStream, security, null);
                        }
                    }
                }
                else if (NetworkingManager.Singleton.IsServer || !NetworkingManager.Singleton.NetworkConfig.EnableMessageBuffering)
                {
                    if (LogHelper.CurrentLogLevel <= LogLevel.Normal)
                    {
                        LogHelper.LogWarning("ClientRPCRequest message recieved for a non existant object with id: " + networkId + ". This message is lost.");
                    }
                }
                else
                {
                    if (LogHelper.CurrentLogLevel <= LogLevel.Normal)
                    {
                        LogHelper.LogWarning("ClientRPCRequest message recieved for a non existant object with id: " + networkId + ". This message will be buffered and might be recovered.");
                    }
                    bufferCallback(networkId);
                }
            }
        }
        /// <inheritdoc />
        public void WriteField(Stream stream)
        {
            using (PooledBitWriter writer = PooledBitWriter.Get(stream))
            {
                writer.WriteUInt16Packed((ushort)set.Count);

                foreach (T value in set)
                {
                    writer.WriteObjectPacked(value); //BOX
                }
            }
        }
示例#9
0
        internal void WriteValue(Stream stream, bool checkDirty = true)
        {
            using (PooledBitWriter writer = PooledBitWriter.Get(stream))
            {
                if (checkDirty)
                {
                    // Trigger a value update
                    IsDirty();
                }

                writer.WriteObjectPacked(value);
            }
        }
示例#10
0
 internal void SendClientRPCBoxed(uint clientIdToIgnore, ulong hash, string channel, SecuritySendFlags security, params object[] parameters)
 {
     using (PooledBitStream stream = PooledBitStream.Get())
     {
         using (PooledBitWriter writer = PooledBitWriter.Get(stream))
         {
             for (int i = 0; i < parameters.Length; i++)
             {
                 writer.WriteObjectPacked(parameters[i]);
             }
             SendClientRPCPerformance(hash, stream, clientIdToIgnore, channel, security);
         }
     }
 }
示例#11
0
        /// <inheritdoc />
        public void WriteDelta(Stream stream)
        {
            using (PooledBitWriter writer = PooledBitWriter.Get(stream))
            {
                writer.WriteUInt16Packed((ushort)dirtyEvents.Count);
                for (int i = 0; i < dirtyEvents.Count; i++)
                {
                    writer.WriteBits((byte)dirtyEvents[i].eventType, 3);
                    switch (dirtyEvents[i].eventType)
                    {
                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Add:
                    {
                        writer.WriteObjectPacked(dirtyEvents[i].key);
                        writer.WriteObjectPacked(dirtyEvents[i].value);
                    }
                    break;

                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Remove:
                    {
                        writer.WriteObjectPacked(dirtyEvents[i].key);
                    }
                    break;

                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.RemovePair:
                    {
                        writer.WriteObjectPacked(dirtyEvents[i].key);
                        writer.WriteObjectPacked(dirtyEvents[i].value);
                    }
                    break;

                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Clear:
                    {
                        //write nothing
                    }
                    break;

                    case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Value:
                    {
                        writer.WriteObjectPacked(dirtyEvents[i].key);
                        writer.WriteObjectPacked(dirtyEvents[i].value);
                    }
                    break;

                    default:
                        break;
                    }
                }
            }
        }
示例#12
0
        internal static void HandleServerRPCRequest(ulong clientId, Stream stream, string channelName, SecuritySendFlags security)
        {
            using (PooledBitReader reader = PooledBitReader.Get(stream))
            {
                ulong  networkId   = reader.ReadUInt64Packed();
                ushort behaviourId = reader.ReadUInt16Packed();
                ulong  hash        = reader.ReadUInt64Packed();
                ulong  responseId  = reader.ReadUInt64Packed();

                if (SpawnManager.SpawnedObjects.ContainsKey(networkId))
                {
                    NetworkedBehaviour behaviour = SpawnManager.SpawnedObjects[networkId].GetBehaviourAtOrderIndex(behaviourId);

                    if (behaviour == null)
                    {
                        if (LogHelper.CurrentLogLevel <= LogLevel.Normal)
                        {
                            LogHelper.LogWarning("ServerRPCRequest message recieved for a non existant behaviour. NetworkId: " + networkId + ", behaviourIndex: " + behaviourId);
                        }
                    }
                    else
                    {
                        object result = behaviour.OnRemoteServerRPC(hash, clientId, stream);

                        using (PooledBitStream responseStream = PooledBitStream.Get())
                        {
                            using (PooledBitWriter responseWriter = PooledBitWriter.Get(responseStream))
                            {
                                responseWriter.WriteUInt64Packed(responseId);
                                responseWriter.WriteObjectPacked(result);
                            }

                            InternalMessageSender.Send(clientId, MLAPIConstants.MLAPI_SERVER_RPC_RESPONSE, channelName, responseStream, security, SpawnManager.SpawnedObjects[networkId]);
                        }
                    }
                }
                else
                {
                    if (LogHelper.CurrentLogLevel <= LogLevel.Normal)
                    {
                        LogHelper.LogWarning("ServerRPCRequest message recieved for a non existant object with id: " + networkId + ". This message is lost.");
                    }
                }
            }
        }