public void Read(Stream stream) { using (var reader = PooledBitReader.Get(stream)) { playerId = reader.ReadInt32Packed(); motion = reader.ReadVector2Packed(); } }
public override void NetworkStart(Stream stream) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { string name = reader.ReadString().ToString(); gameObject.name = name; } }
internal static void HandleTimeSync(ulong clientId, Stream stream, float receiveTime) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { float netTime = reader.ReadSinglePacked(); NetworkingManager.Singleton.UpdateNetworkTime(clientId, netTime, receiveTime); } }
internal static void HandleDestroyPoolObject(uint clientId, Stream stream, int channelId) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { uint netId = reader.ReadUInt32Packed(); SpawnManager.SpawnedObjects[netId].gameObject.SetActive(false); } }
private void ApplyRotation(ulong clientID, Stream stream) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { float rotation = reader.ReadSinglePacked(); transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, transform.localEulerAngles.y, rotation); } }
internal static void HandleClientDisconnect(uint clientId, Stream stream, int channelId) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { uint disconnectedClientId = reader.ReadUInt32Packed(); netManager.OnClientDisconnectFromServer(disconnectedClientId); } }
private void HandleNetworkLog(ulong sendingClientID, Stream stream, float receiveTime) { //DO NOT* CALL Debug.Log or other log functions in this function. *See onReceivedNetworkLog summary comments. using (PooledBitReader reader = PooledBitReader.Get(stream)) { m_OnReceivedNetworkLog?.Invoke(sendingClientID, reader.ReadString().ToString(), reader.ReadBool() ? reader.ReadString().ToString() : string.Empty, (LogType)reader.ReadByte()); } }
internal static void HandleDestroyObject(ulong clientId, Stream stream) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { ulong networkId = reader.ReadUInt64Packed(); SpawnManager.OnDestroyObject(networkId, true); } }
internal static void HandleDestroyObject(uint clientId, Stream stream, int channelId) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { uint netId = reader.ReadUInt32Packed(); SpawnManager.OnDestroyObject(netId, true); } }
private void HandleTimeSync(ulong sendingClientID, Stream stream, float receiveTime) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { float netTime = reader.ReadSinglePacked(); UpdateNetworkTime(sendingClientID, netTime, receiveTime); } }
public void ReadSyncTeamSlots(PooledBitReader reader, int count) { for (int i = 0; i < count; i++) { int slot = reader.ReadInt32Packed(); ulong netID = reader.ReadUInt64Packed(); teamSlots[slot] = GameManager.GetPlayerByNetworkID(netID); } }
/// <inheritdoc /> public void ReadDelta(Stream stream) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { ushort deltaCount = reader.ReadUInt16Packed(); for (int i = 0; i < deltaCount; i++) { NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType eventType = (NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType)reader.ReadBits(3); switch (eventType) { case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Add: { TKey key = (TKey)reader.ReadObjectPacked(typeof(TKey)); TValue value = (TValue)reader.ReadObjectPacked(typeof(TValue)); dictionary.Add(key, value); } break; case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Remove: { TKey key = (TKey)reader.ReadObjectPacked(typeof(TKey)); dictionary.Remove(key); } break; case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.RemovePair: { TKey key = (TKey)reader.ReadObjectPacked(typeof(TKey)); TValue value = (TValue)reader.ReadObjectPacked(typeof(TValue)); dictionary.Remove(new KeyValuePair <TKey, TValue>(key, value)); } break; case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Clear: { //read nothing dictionary.Clear(); } break; case NetworkedDictionaryEvent <TKey, TValue> .NetworkedListEventType.Value: { TKey key = (TKey)reader.ReadObjectPacked(typeof(TKey)); TValue value = (TValue)reader.ReadObjectPacked(typeof(TValue)); if (dictionary.ContainsKey(key)) { dictionary[key] = value; } } break; default: break; } } } }
internal void ReadValue(Stream stream) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { value = reader.ReadObjectPacked(field.FieldType); field.SetValue(fieldInstance, value); } }
public bool PullFilesFromPacket(PooledBitReader reader) { bool packetEndHit = false; while (!packetEndHit) { int id = reader.ReadInt32(); byte[] data = reader.ReadByteArray(null); packetEndHit = reader.ReadBit(); float progress = (float)fileBytesReceived / (float)DownloadSize; //Debug.LogError("file packet received: " + id + " " + data.Length + " packet finished: " + packetEndHit.ToString()); fileBytesReceived += data.Length; //Debug.LogWarning("internal prog: " + progress + " - " + fileBytesReceived + "/" + DownloadSize); if (OnProgressUpdated != null) { OnProgressUpdated(progress, "Receiving file: " + Headers[id].path); } numFilesReceived++; //Debug.Log(fileBytesReceived + " / " + DownloadSize); bool allFilesProcessed = fileBytesReceived >= DownloadSize; if (id != previousFileID) { if (receptionFileStream != null) { receptionFileStreamWriter.Dispose(); receptionFileStream.Dispose(); } string filePath = Paths.GetDownloadPath(Headers[id]); receptionFileStream = File.Open(filePath, FileMode.Append); receptionFileStreamWriter = new BinaryWriter(receptionFileStream); } receptionFileStreamWriter.Write(data); if (allFilesProcessed) { receptionFileStreamWriter.Dispose(); receptionFileStream.Dispose(); return(true); } previousFileID = id; } return(false); }
public void ClientSyncTeamSlots(Stream stream) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { int teamid = reader.ReadInt32Packed(); int count = reader.ReadInt32Packed(); teams[teamid].ReadSyncTeamSlots(reader, count); } }
public void Read(Stream stream) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { LocationIndex = reader.ReadByte(); Question = reader.ReadString().ToString(); reader.ReadIntArrayPacked(Answers, ANSWER_COUNT); } }
public void ReadPlayerFromServer(Stream stream) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { isInsideThree = reader.ReadBool(); isInbounds = reader.ReadBool(); HasBall = reader.ReadBool(); } }
public CustomMessages() { CustomMessagingManager.RegisterNamedMessageHandler(MessageName, (sender, payload) => { Debug.Log("MESSAGE HANDLER"); using (var reader = PooledBitReader.Get(payload)) { ChatReceived?.Invoke(this, reader.ReadString().ToString()); } }); }
public static AnimationPacket FromStream(Stream stream) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { bool groundstate = reader.ReadBool(); bool hangstate = reader.ReadBool(); return(new AnimationPacket(groundstate, hangstate)); } }
//In the lobby i want to send a name, outside of that i just want to send an id and find it. It would make a lot of code much nicer. //Maybe register/deregister a custom serializer? public void Read(Stream stream) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { //TODO: ID could very often be inferred by who sent it? ID = reader.ReadUInt64(); Name = reader.ReadString().ToString(); } }
internal static void HandleSwitchScene(uint clientId, Stream stream, int channelId) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { uint sceneIndex = reader.ReadUInt32Packed(); Guid switchSceneGuid = new Guid(reader.ReadByteArray()); NetworkSceneManager.OnSceneSwitch(sceneIndex, switchSceneGuid); } }
internal static void HandleNamedMessage(ulong clientId, Stream stream) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { ulong hash = reader.ReadUInt64Packed(); CustomMessagingManager.InvokeNamedMessage(hash, clientId, stream); } }
internal static void HandleAddObject(ulong clientId, Stream stream) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { bool isPlayerObject = reader.ReadBool(); ulong networkId = reader.ReadUInt64Packed(); ulong ownerId = reader.ReadUInt64Packed(); bool hasParent = reader.ReadBool(); ulong?parentNetworkId = null; if (hasParent) { parentNetworkId = reader.ReadUInt64Packed(); } ulong prefabHash; ulong instanceId; bool softSync; if (NetworkingManager.Singleton.NetworkConfig.UsePrefabSync) { softSync = false; instanceId = 0; prefabHash = reader.ReadUInt64Packed(); } else { softSync = reader.ReadBool(); if (softSync) { instanceId = reader.ReadUInt64Packed(); prefabHash = 0; } else { prefabHash = reader.ReadUInt64Packed(); instanceId = 0; } } Vector3? pos = null; Quaternion?rot = null; if (reader.ReadBool()) { pos = new Vector3(reader.ReadSinglePacked(), reader.ReadSinglePacked(), reader.ReadSinglePacked()); rot = Quaternion.Euler(reader.ReadSinglePacked(), reader.ReadSinglePacked(), reader.ReadSinglePacked()); } bool hasPayload = reader.ReadBool(); int payLoadLength = hasPayload ? reader.ReadInt32Packed() : 0; NetworkedObject netObject = SpawnManager.CreateLocalNetworkedObject(softSync, instanceId, prefabHash, parentNetworkId, pos, rot); SpawnManager.SpawnNetworkedObjectLocally(netObject, networkId, softSync, isPlayerObject, ownerId, stream, hasPayload, payLoadLength, true, false); } }
internal static void HandleTimeSync(ulong clientId, Stream stream) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { float netTime = reader.ReadSinglePacked(); ulong msDelay = NetworkingManager.Singleton.NetworkConfig.NetworkTransport.GetCurrentRtt(clientId); NetworkingManager.Singleton.NetworkTime = netTime + (msDelay / 1000f); } }
public void Read(Stream stream) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { GameMode = (BallersGamemode)reader.ReadByte(); TeamSize = reader.ReadByte(); QuarterLength = reader.ReadByte(); QuartersCount = reader.ReadByte(); } }
public void Read(Stream stream) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { ImposterCount = reader.ReadByte(); MovementSpeed = reader.ReadSinglePacked(); VoteDuration = reader.ReadSinglePacked(); TaskCount = reader.ReadUInt16Packed(); } }
internal void SetNetworkedVarData(Stream stream) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { foreach (var NetworkedVarsList in dummyNetworkedVars.Values) { NetworkedBehaviour.SetNetworkedVarData(NetworkedVarsList, reader, stream); } } }
private void WinRPC(ulong clientId, Stream stream) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { left = reader.ReadInt32(); right = reader.ReadInt32(); leftText.text = left.ToString(); rightText.text = right.ToString(); } }
private void ApplyTransform(ulong clientId, Stream stream) { if (!enabled) { return; } using (PooledBitReader reader = PooledBitReader.Get(stream)) { Vector3 position = Vector3.zero; Quaternion rotation = Quaternion.identity; if (SyncPosition) { position = reader.ReadVector3Packed(); } if (SyncRotation) { if (FullRotation) { Quaternion.Euler(reader.ReadVector3Packed()); } else { Quaternion.Euler(0, reader.ReadSinglePacked(), 0); } } if (InterpolatePosition && !IsServer) { lastReceiveTime = Time.unscaledTime; if (SyncPosition) { lerpStartPos = transform.position; lerpEndPos = position; } if (SyncRotation) { lerpStartRot = transform.rotation; lerpEndRot = rotation; } lerpT = 0; } else { if (SyncPosition) { transform.position = position; } if (SyncRotation) { transform.rotation = rotation; } } } }
internal void SetNetworkedVarData(Stream stream) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { for (int i = 0; i < childNetworkedBehaviours.Count; i++) { childNetworkedBehaviours[i].NetworkedVarInit(); NetworkedBehaviour.SetNetworkedVarData(childNetworkedBehaviours[i].networkedVarFields, reader, stream); } } }