public ClientVC(NetworkReader nr) : base(new Vec2i(0,0), 0) { this.data = new VesselTile[VesselChunk.DATA_COUNT]; index.x = nr.ReadInt32(); index.y = nr.ReadInt32(); version = nr.ReadUInt32(); tileCount = nr.ReadInt32(); for (int i = 0; i < tileCount; i++) { //read in vessel tile Vec2i tileI; tileI.x = nr.ReadInt32(); tileI.y = nr.ReadInt32(); FloorType floor0 = (FloorType)nr.ReadByte(); FloorType floor1 = (FloorType)nr.ReadByte(); WallTypeMask wallMask = (WallTypeMask)nr.ReadByte(); bool wallNode = nr.ReadBoolean(); VesselTile tile = new VesselTile(wallMask, wallNode, floor0, floor1, (uint)VesselTile.FLAGS.NONE); SetTile(tileI, tile); } }
public override void Deserialize(NetworkReader reader) { proxyId = reader.ReadInt16(); packet.Compression = (VoiceChatCompression)reader.ReadInt16(); packet.Length = reader.ReadInt32(); packet.Data = reader.ReadBytesAndSize(); }
private CharacterState serverLastState; //SERVER: Store last state #endregion Fields #region Methods /// <summary> /// All Clients: Deserialize the state from network /// </summary> /// <param name="reader"></param> /// <param name="initialState"></param> public override void OnDeserialize(NetworkReader reader, bool initialState) { CharacterState state = new CharacterState(); state.state = reader.ReadInt32(); state.position = reader.ReadVector3(); state.rotation = reader.ReadQuaternion(); //Client: Received a new state for the local player, treat it as an ACK and do reconciliation if (isLocalPlayer) { SendMessage("ServerState", state, SendMessageOptions.DontRequireReceiver); } else { //Other Clients: Received a state, treat it like a new position snapshot from authority if (initialState) { //Others Clients: First state, just snap to new position transform.position = state.position; transform.rotation = state.rotation; } else if (networkInterpolation != null) { //Others Clients: Interpolate between received positions networkInterpolation.ReceiveState(state); } } }
public override void Deserialize(NetworkReader reader) { base.Deserialize(reader); int count = reader.ReadInt32(); Polyline = new List<Vector3>(count); for(int i=0; i < count; i++) Polyline.Add(reader.ReadVector3()); }
public override void Deserialize(NetworkReader reader) { m_id = reader.ReadNetworkId(); m_parentId = reader.ReadNetworkId(); m_childId = reader.ReadInt32(); m_position = reader.ReadVector3(); m_payload = reader.ReadBytesAndSize(); }
public override void Deserialize(NetworkReader reader) { base.Deserialize(reader); byte setType = reader.ReadByte(); switch (setType) { case (byte)0: _actionSet = new SinglePanelActionSet(); break; case (byte)1: _actionSet = new ReplacementPanelActionSet(); break; case (byte)2: _actionSet = new CodePanelActionSet(); break; default: throw new Exception("Unexpected Action Set ID " + setType); } _actionSet.Deserialize(reader); _x = reader.ReadInt32(); _y = reader.ReadInt32(); _prefabIndex = reader.ReadInt32(); }
public override void Deserialize(NetworkReader reader) { base.Deserialize(reader); _instructionBase = reader.ReadString(); _variantReplacements = new string[reader.ReadInt32()]; for (int i = 0; i < _variantReplacements.Length; i++) { _variantReplacements[i] = reader.ReadString(); } }
public override void Deserialize(NetworkReader reader) { //Get the no of inputs received int count = reader.ReadInt32(); //Prepaare list if (inputsList != null) { inputsList.Clear(); //Detatch prev elements } inputsList = new List<Inputs>(); //Detatch prev mem //Build all inputs for (int i = 0; i < count; i++){ //Create Inputs input = new Inputs(); //Deserialize individually input.crouch = reader.ReadBoolean(); input.jump = reader.ReadBoolean(); input.move = reader.ReadBoolean(); input.pitch = reader.ReadSingle(); input.rotate = reader.ReadBoolean(); input.timeStamp = reader.ReadDouble(); input.walk = reader.ReadBoolean(); bool[] wasd = new bool[4]; wasd[0] = reader.ReadBoolean(); wasd[1] = reader.ReadBoolean(); wasd[2] = reader.ReadBoolean(); wasd[3] = reader.ReadBoolean(); input.wasd = wasd; input.yaw = reader.ReadSingle(); //Add to the message list inputsList.Add(input); //Check if is the last input and register stamp if(i == count - 1) { stamp = input.timeStamp; } } }
public override void OnDeserialize(NetworkReader reader, bool initialState) { if (initialState) { int stateNameHash = reader.ReadInt32(); float normalizedTime = reader.ReadSingle(); this.ReadParameters(reader, false); this.m_Animator.Play(stateNameHash, 0, normalizedTime); } }
public override void Deserialize(NetworkReader reader) { PlayerId = (int)reader.ReadPackedUInt32(); IsPermanent = reader.ReadBoolean(); GameResult = (GameResult)reader.ReadInt32(); }
public override void Deserialize(NetworkReader reader) { playerID = reader.ReadString(); characterIndex = reader.ReadInt32(); }
public override void OnDeserialize(NetworkReader reader, bool initialState) { if (initialState) { int playerId = reader.ReadByte(); if (MatchSession.Current.Players.Count > playerId) { byte unitCategoryId = reader.ReadByte(); int unitId = reader.ReadInt32(); PlayerData owner = MatchSession.Current.Players[playerId]; if (unitCategoryId < GameSession.Singleton.Armory.Categories.Length && unitId < GameSession.Singleton.Armory.Categories[unitCategoryId].Count) { FinalHeading = reader.ReadSingle(); Unit unit = GameSession.Singleton.Armory.Categories[unitCategoryId][unitId]; Initialize(unit, owner); UpdateGhostLocations(); } else { if (unitCategoryId < GameSession.Singleton.Armory.Categories.Length) { Logger.LogNetworking(LogLevel.ERROR, $"Got bad unit id = {unitId} from " + $"the server. Total units = {GameSession.Singleton.Armory.Categories[unitCategoryId].Count} " + $"(category = {unitCategoryId})."); } else { Logger.LogNetworking(LogLevel.ERROR, $"Got bad category id = {unitCategoryId} from " + $"the server. Total categories = {GameSession.Singleton.Armory.Categories.Length}"); } } } else { // Got an invalid player id, server is trying to crash us? Logger.LogNetworking(LogLevel.ERROR, $"Network tried to create a ghostplatoon with an invalid player id {playerId}."); } } else { float heading = reader.ReadSingle(); if (heading != FinalHeading) { FinalHeading = heading; UpdateGhostLocations(); } int unitCount = reader.ReadByte(); while (unitCount != _units.Count && unitCount != 0) { if (unitCount > _units.Count) { AddSingleUnit(); } else if (unitCount < _units.Count) { RemoveOneGhostUnit(); } } } }
public override void Deserialize(NetworkReader reader) { name = reader.ReadString(); var isNull = reader.ReadBoolean(); if (isNull){ value = null; return; } var typeName = reader.ReadString(); var t = System.Type.GetType(typeName); if (t == typeof(string)){ value = reader.ReadString(); return; } if (t == typeof(bool)){ value = reader.ReadBoolean(); return; } if (t == typeof(int)){ value = reader.ReadInt32(); return; } if (t == typeof(float)){ value = reader.ReadSingle(); return; } if (t == typeof(Color)){ value = reader.ReadColor(); return; } if (t == typeof(Vector2)){ value = reader.ReadVector2(); return; } if (t == typeof(Vector3)){ value = reader.ReadVector3(); return; } if (t == typeof(Vector4)){ value = reader.ReadVector4(); return; } if (t == typeof(Quaternion)){ value = reader.ReadQuaternion(); return; } if (t == typeof(GameObject)){ value = reader.ReadGameObject(); return; } if (typeof(Component).RTIsAssignableFrom(t)){ var go = reader.ReadGameObject(); if (go != null){ value = go.GetComponent(t); } return; } }
private ServerVC ReadChunkRequest(NetworkReader nr) { Vec2i index; index.x = nr.ReadInt32(); index.y = nr.ReadInt32(); uint version = nr.ReadUInt32(); if (version == uint.MaxValue) { return (ServerVC)chunks.TryGet(index); } else { ServerVC vc = (ServerVC)chunks.TryGet(index); if (version != vc.version) { return vc; } else { return null; } } }
public override void OnDeserialize(NetworkReader reader, bool initialState) { value = reader.ReadInt32(); }
public override void Deserialize(NetworkReader reader) { Result = reader.ReadInt32(); JustDoIt = reader.ReadBoolean(); PlayerID = reader.ReadInt64(); }
private void ReceiveSetTile(NetworkReader reader) { int location = reader.ReadInt32(); byte tile = reader.ReadByte(); if (hosting) { SendAll(SetTileMessage(location, tile)); } if (world.tilemap[location] != tile) { audio.PlayOneShot(placeSound); worldView.SetTile(location, tile); } }
private void ReceiveGiveAvatar(NetworkReader reader) { World.Avatar avatar = ID2Avatar(reader.ReadInt32()); worldView.viewer = avatar; avatar.graphic.texture.SetPixels32(avatarGraphic.GetPixels32()); world.PalettiseTexture(avatar.graphic.texture, true); SendAll(AvatarInChunksMessages(world, worldView.viewer)); }
private void ReceiveDestroyAvatar(NetworkReader reader) { World.Avatar avatar = ID2Avatar(reader.ReadInt32()); RemoveAvatar(avatar); }
string ReadParameterToString(Type t, NetworkReader reader) { if (t.IsArray) { Type elemType = t.GetElementType(); int count = reader.ReadInt32(); StringBuilder sb = new StringBuilder(); sb.Append("["); for (int x = 0; x < count; x++) { if (x != 0) { sb.Append(", "); } sb.Append(ReadParameterToString(elemType, reader)); } sb.Append("]"); return(sb.ToString()); } else { if (t == typeof(int)) { return(reader.ReadInt32().ToString()); } else if (t == typeof(string)) { return(reader.ReadString()); } else if (t == typeof(short)) { return(reader.ReadInt16().ToString()); } else if (t == typeof(byte)) { return(reader.ReadByte().ToString()); } else if (t.IsEnum) { return(Enum.Parse(t, reader.ReadByte().ToString()).ToString()); } else { MethodInfo deserializeMethod = t.GetMethod("NetworkDeserialize", BindingFlags.Static | BindingFlags.Public); if (deserializeMethod != null) { object value = Activator.CreateInstance(t); deserializeMethod.Invoke(null, new object[] { value, reader }); return(value.ToString()); } else { return(string.Format("[{0}]", t.Name)); } } } }
public void TestWritingAndReading() { writer.WriteChar((char)1); writer.WriteByte(2); writer.WriteSByte(3); writer.WriteBoolean(true); writer.WriteInt16(4); writer.WriteUInt16(5); writer.WriteInt32(6); writer.WriteUInt32(7U); writer.WriteInt64(8L); writer.WriteUInt64(9UL); writer.WriteSingle(10.0F); writer.WriteDouble(11.0D); writer.WriteDecimal(12); writer.WriteString(null); writer.WriteString(""); writer.WriteString("13"); // just the byte array, no size info etc. writer.WriteBytes(new byte[] { 14, 15 }, 0, 2); // [SyncVar] struct values can have uninitialized byte arrays, null needs to be supported writer.WriteBytesAndSize(null); // buffer, no-offset, count writer.WriteBytesAndSize(new byte[] { 17, 18 }, 0, 2); // buffer, offset, count writer.WriteBytesAndSize(new byte[] { 19, 20, 21 }, 1, 2); // size, buffer writer.WriteBytesAndSize(new byte[] { 22, 23 }, 0, 2); // read them var reader = new NetworkReader(writer.ToArray()); Assert.That(reader.ReadChar(), Is.EqualTo(1)); Assert.That(reader.ReadByte(), Is.EqualTo(2)); Assert.That(reader.ReadSByte(), Is.EqualTo(3)); Assert.That(reader.ReadBoolean(), Is.True); Assert.That(reader.ReadInt16(), Is.EqualTo(4)); Assert.That(reader.ReadUInt16(), Is.EqualTo(5)); Assert.That(reader.ReadInt32(), Is.EqualTo(6)); Assert.That(reader.ReadUInt32(), Is.EqualTo(7)); Assert.That(reader.ReadInt64(), Is.EqualTo(8)); Assert.That(reader.ReadUInt64(), Is.EqualTo(9)); Assert.That(reader.ReadSingle(), Is.EqualTo(10)); Assert.That(reader.ReadDouble(), Is.EqualTo(11)); Assert.That(reader.ReadDecimal(), Is.EqualTo(12)); // writing null string should write null in Mirage ("" in original HLAPI) Assert.That(reader.ReadString(), Is.Null); Assert.That(reader.ReadString(), Is.EqualTo("")); Assert.That(reader.ReadString(), Is.EqualTo("13")); Assert.That(reader.ReadBytes(2), Is.EqualTo(new byte[] { 14, 15 })); Assert.That(reader.ReadBytesAndSize(), Is.Null); Assert.That(reader.ReadBytesAndSize(), Is.EqualTo(new byte[] { 17, 18 })); Assert.That(reader.ReadBytesAndSize(), Is.EqualTo(new byte[] { 20, 21 })); Assert.That(reader.ReadBytesAndSize(), Is.EqualTo(new byte[] { 22, 23 })); }
protected override Item DeserializeItem(NetworkReader reader) { return(ItemBase.GetItem(reader.ReadInt32())); }
public override void Deserialize(NetworkReader reader) { index = reader.ReadInt32(); time = reader.ReadDouble(); }
public void Deserialize(NetworkReader reader) { IntValue = reader.ReadInt32(); StringValue = reader.ReadString(); DoubleValue = reader.ReadDouble(); }
public override void Deserialize(NetworkReader reader) { mapID = reader.ReadInt32(); position = reader.ReadVector3(); }
private void ReceiveLockTile(NetworkReader reader) { World.Avatar avatar = ID2Avatar(reader.ReadInt32()); byte tile = reader.ReadByte(); if (avatar != null) { Debug.LogFormat("{0} locking {1}", avatar.id, tile); locks[tile] = avatar; if (avatar == worldView.viewer) OpenForEdit(tile); if (hosting) SendAll(LockTileMessage(avatar, tile)); } else if (locks.ContainsKey(tile)) { Debug.LogFormat("unlocking {0}", tile); locks.Remove(tile); if (hosting) SendAll(LockTileMessage(null, tile)); } tilePalette.Refresh(); }
public override void Deserialize(NetworkReader reader) { itemIndex = reader.ReadInt32(); vect = reader.ReadVector3(); rotate = reader.ReadQuaternion(); }
private void ReceiveCreateAvatar(NetworkReader reader) { var avatar = new World.Avatar { id = reader.ReadInt32(), destination = reader.ReadVector2(), source = reader.ReadVector2(), graphic = BlankTexture.FullSprite(BlankTexture.New(32, 32, Color.clear)), }; AddAvatar(avatar); }
public void Deserialize(ref NetworkReader reader, int tick) { this.tick = reader.ReadInt32(); lethal = reader.ReadBoolean(); }
public int ReceiveInt() { return(reader.ReadInt32()); }
public override void Deserialize(NetworkReader reader) { base.Deserialize(reader); var componentID = reader.ReadUInt16(); if (componentID == UNKNOWN_COMPONENT_TYPE_ID) { //client didn't know which to trigger, leave ComponentType null ComponentType = null; } else { //client requested a specific component. ComponentType = componentIDToComponentType[componentID]; } InteractionType = interactionIDToInteractionType[reader.ReadByte()]; if (componentID != UNKNOWN_COMPONENT_TYPE_ID) { // client specified exact component ProcessorObject = reader.ReadUInt32(); } else { // client requested server to check the interaction ProcessorObject = NetId.Invalid; } Intent = (Intent)reader.ReadByte(); if (InteractionType == typeof(PositionalHandApply)) { TargetObject = reader.ReadUInt32(); TargetVector = reader.ReadVector2(); TargetBodyPart = (BodyPartType)reader.ReadUInt32(); } else if (InteractionType == typeof(HandApply)) { TargetObject = reader.ReadUInt32(); TargetBodyPart = (BodyPartType)reader.ReadUInt32(); IsAltUsed = reader.ReadBoolean(); } else if (InteractionType == typeof(AimApply)) { TargetVector = reader.ReadVector2(); MouseButtonState = reader.ReadBoolean() ? MouseButtonState.PRESS : MouseButtonState.HOLD; } else if (InteractionType == typeof(MouseDrop)) { TargetObject = reader.ReadUInt32(); UsedObject = reader.ReadUInt32(); } else if (InteractionType == typeof(InventoryApply)) { UsedObject = reader.ReadUInt32(); Storage = reader.ReadUInt32(); SlotIndex = reader.ReadInt32(); NamedSlot = (NamedSlot)reader.ReadInt32(); IsAltUsed = reader.ReadBoolean(); } else if (InteractionType == typeof(TileApply)) { TargetVector = reader.ReadVector2(); } else if (InteractionType == typeof(TileMouseDrop)) { UsedObject = reader.ReadUInt32(); TargetVector = reader.ReadVector2(); } else if (InteractionType == typeof(ConnectionApply)) { TargetObject = reader.ReadUInt32(); TargetVector = reader.ReadVector2(); connectionPointA = (Connection)reader.ReadByte(); connectionPointB = (Connection)reader.ReadByte(); } else if (InteractionType == typeof(ContextMenuApply)) { TargetObject = reader.ReadUInt32(); RequestedOption = reader.ReadString(); } }
public override void Deserialize(NetworkReader reader) { base.Deserialize(reader); UnitId = reader.ReadInt32(); }
void UpdateNetwork() { NetworkEventType recData; do { int recHostId; int recConnectionId; int channelId; int bufferSize = 1024; byte[] recBuffer = new byte[bufferSize]; int dataSize; byte error; recData = NetworkTransport.Receive(out recHostId, out recConnectionId, out channelId, recBuffer, bufferSize, out dataSize, out error); switch (recData) { case NetworkEventType.Nothing: break; case NetworkEventType.ConnectEvent: Debug.Log("ConnectEvent"); if (connectionId == recConnectionId) { ClientOnConnect(); } else { ServerOnClientConnect(recConnectionId); } break; case NetworkEventType.DataEvent: NetworkReader networkReader = new NetworkReader(recBuffer); byte[] readerMsgSizeData = networkReader.ReadBytes(2); short readerMsgSize = (short)((readerMsgSizeData[1] << 8) + readerMsgSizeData[0]); byte[] readerMsgTypeData = networkReader.ReadBytes(2); short readerMsgType = (short)((readerMsgTypeData[1] << 8) + readerMsgTypeData[0]); string targetObjectName = networkReader.ReadString(); string methodName = networkReader.ReadString(); int paramCount = networkReader.ReadInt32(); switch (readerMsgType) { case (101): BroadcastCAVE2RPC(targetObjectName, methodName, ReaderToObject(networkReader)); break; case (102): BroadcastCAVE2RPC4(targetObjectName, methodName, ReaderToObject(networkReader), ReaderToObject(networkReader)); break; case (201): SendCAVE2RPC(targetObjectName, methodName, ReaderToObject(networkReader)); break; case (202): SendCAVE2RPC4(targetObjectName, methodName, ReaderToObject(networkReader), ReaderToObject(networkReader)); break; case (203): SendCAVE2RPC5(targetObjectName, methodName, ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader)); break; case (204): SendCAVE2RPC6(targetObjectName, methodName, ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader)); break; case (205): SendCAVE2RPC7(targetObjectName, methodName, ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader)); break; case (207): SendCAVE2RPC9(targetObjectName, methodName, ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader)); break; case (216): SendCAVE2RPC18(targetObjectName, methodName, ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader), ReaderToObject(networkReader)); break; } break; case NetworkEventType.DisconnectEvent: Debug.Log("DisconnectEvent"); if (connectionId != recConnectionId) { ServerOnClientDisconnect(recConnectionId); } break; case NetworkEventType.BroadcastEvent: Debug.Log("BroadcastEvent"); break; } } while (recData != NetworkEventType.Nothing); }
public void Deserialize(ref NetworkReader reader, IEntityReferenceSerializer refSerializer, int tick) { fireTick = reader.ReadInt32(); }
public static RequestInteractMessage.NetMessage Deserialize(this NetworkReader reader) { var message = new RequestInteractMessage.NetMessage(); var componentID = reader.ReadUInt16(); if (componentID == RequestInteractMessage.UNKNOWN_COMPONENT_TYPE_ID) { //client didn't know which to trigger, leave ComponentType null message.ComponentType = null; } else { //client requested a specific component. message.ComponentType = RequestInteractMessage.componentIDToComponentType[componentID]; } message.InteractionType = RequestInteractMessage.interactionIDToInteractionType[reader.ReadByte()]; if (componentID != RequestInteractMessage.UNKNOWN_COMPONENT_TYPE_ID) { // client specified exact component message.ProcessorObject = reader.ReadUInt32(); } else { // client requested server to check the interaction message.ProcessorObject = NetId.Invalid; } message.Intent = (Intent)reader.ReadByte(); if (message.InteractionType == typeof(PositionalHandApply)) { message.TargetObject = reader.ReadUInt32(); message.TargetVector = reader.ReadVector2(); message.TargetBodyPart = (BodyPartType)reader.ReadUInt32(); } else if (message.InteractionType == typeof(HandApply)) { message.TargetObject = reader.ReadUInt32(); message.TargetBodyPart = (BodyPartType)reader.ReadUInt32(); message.IsAltUsed = reader.ReadBoolean(); } else if (message.InteractionType == typeof(AimApply)) { message.TargetVector = reader.ReadVector2(); message.MouseButtonState = reader.ReadBoolean() ? MouseButtonState.PRESS : MouseButtonState.HOLD; } else if (message.InteractionType == typeof(MouseDrop)) { message.TargetObject = reader.ReadUInt32(); message.UsedObject = reader.ReadUInt32(); } else if (message.InteractionType == typeof(InventoryApply)) { message.StorageIndexOnGameObject = reader.ReadUInt32(); message.UsedObject = reader.ReadUInt32(); message.Storage = reader.ReadUInt32(); message.SlotIndex = reader.ReadInt32(); message.NamedSlot = (NamedSlot)reader.ReadInt32(); message.IsAltUsed = reader.ReadBoolean(); } else if (message.InteractionType == typeof(TileApply)) { message.TargetVector = reader.ReadVector2(); } else if (message.InteractionType == typeof(TileMouseDrop)) { message.UsedObject = reader.ReadUInt32(); message.TargetVector = reader.ReadVector2(); } else if (message.InteractionType == typeof(ConnectionApply)) { message.TargetObject = reader.ReadUInt32(); message.TargetVector = reader.ReadVector2(); message.connectionPointA = (Connection)reader.ReadByte(); message.connectionPointB = (Connection)reader.ReadByte(); } else if (message.InteractionType == typeof(ContextMenuApply)) { message.TargetObject = reader.ReadUInt32(); message.RequestedOption = reader.ReadString(); } else if (message.InteractionType == typeof(AiActivate)) { message.TargetObject = reader.ReadUInt32(); message.ClickTypes = (AiActivate.ClickTypes)reader.ReadByte(); } return(message); }
// Server sent us a packet about all connected clients or an update for all cube positions void ProcessServerData(byte[] buffer) { NetworkReader nr = new NetworkReader(buffer); PacketTypeEnum packetType = (PacketTypeEnum)nr.ReadByte(); switch (packetType) { case PacketTypeEnum.Position: List <PositionData> posList = new List <PositionData>(); PositionData p; while (nr.Position != buffer.Length) { p = new PositionData(); p.objectId = nr.ReadInt32(); p.pos = nr.ReadVector3(); posList.Add(p); } // Update game objects foreach (var item in clientList) { if (item.obj == null) { continue; } p = posList.FirstOrDefault(x => x.objectId == item.objectId); if (p == null) { Debug.Log("Cannot find game object"); } else { item.obj.transform.position = p.pos; } } break; case PacketTypeEnum.Information: List <InformationData> infoList = new List <InformationData>(); InformationData info; while (nr.Position != buffer.Length) { info = new InformationData(); info.objectId = nr.ReadInt32(); info.name = nr.ReadString(); info.pos = nr.ReadVector3(); info.r = nr.ReadSingle(); info.g = nr.ReadSingle(); info.b = nr.ReadSingle(); infoList.Add(info); } // Remove clients that aren't listed foreach (var item in clientList) { if (item.obj == null) { continue; } info = infoList.FirstOrDefault(x => x.objectId == item.objectId); if (info == null) { Destroy(item.obj); } } clientList.RemoveAll(x => x.obj == null); // Note items are set to null only after Update! foreach (var item in infoList) { ClientData cd = clientList.FirstOrDefault(x => x.objectId == item.objectId); // Is this new client info? if (cd == null) { // Create new object GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube); // No CharacterController here! // Set position obj.transform.position = item.pos; // Set color obj.GetComponent <Renderer>().material.color = new Color(item.r, item.g, item.b); cd = new ClientData(); cd.objectId = item.objectId; cd.name = item.name; cd.obj = obj; clientList.Add(cd); Debug.Log(string.Format("New client info for {0}", cd.name)); } } break; default: Debug.Log("Unknown packet type"); break; } }
public override void Deserialize(NetworkReader reader) { base.Deserialize(reader); ConnectionId = reader.ReadInt32(); }
public override void Deserialize(NetworkReader reader) { errorCode = reader.ReadInt32(); }
public override void Deserialize(ref NetworkReader reader) { intValue = reader.ReadInt32(); boolValue = reader.ReadBoolean(); floatValue = reader.ReadFloat(); }
public override void OnDeserialize(NetworkReader reader) { base.OnDeserialize(reader); this.swingIndex = reader.ReadInt32(); }
public override void Deserialize(NetworkReader reader) { playerID = reader.ReadString(); targetID = reader.ReadString(); spellID = reader.ReadInt32(); }
public override void Deserialize(NetworkReader reader) { name = reader.ReadString(); var isNull = reader.ReadBoolean(); if (isNull) { value = null; return; } var typeName = reader.ReadString(); var t = System.Type.GetType(typeName); if (t == typeof(string)) { value = reader.ReadString(); return; } if (t == typeof(bool)) { value = reader.ReadBoolean(); return; } if (t == typeof(int)) { value = reader.ReadInt32(); return; } if (t == typeof(float)) { value = reader.ReadSingle(); return; } if (t == typeof(Color)) { value = reader.ReadColor(); return; } if (t == typeof(Vector2)) { value = reader.ReadVector2(); return; } if (t == typeof(Vector3)) { value = reader.ReadVector3(); return; } if (t == typeof(Vector4)) { value = reader.ReadVector4(); return; } if (t == typeof(Quaternion)) { value = reader.ReadQuaternion(); return; } if (t == typeof(GameObject)) { value = reader.ReadGameObject(); return; } if (typeof(Component).RTIsAssignableFrom(t)) { var go = reader.ReadGameObject(); if (go != null) { value = go.GetComponent(t); } return; } }
private void ReceiveAvatarChunk(NetworkReader reader, int connectionID) { World.Avatar avatar = ID2Avatar(reader.ReadInt32()); int offset = reader.ReadInt32(); byte[] chunk = UncrunchBytes(reader.ReadBytesAndSize()); // if we're the host, disallow chunks not send by the owner if (hosting && avatar.id != connectionID) return; Color32[] colors = avatar.graphic.texture.GetPixels32(); for (int i = 0; i < chunk.Length; ++i) { byte index = chunk[i]; colors[i + offset] = index == 0 ? Color.clear : world.palette[index]; } avatar.graphic.texture.SetPixels32(colors); avatar.graphic.texture.Apply(); if (hosting) { SendAll(AvatarInChunksMessages(world, avatar)); } }
public override void Read(NetworkReader reader) { World = reader.ReadInt32(); ClassType = reader.ReadInt32(); CharacterIndex = reader.ReadInt32(); }
/// <summary> /// Used to deserialize a message received via networking. /// </summary> /// <param name="reader"></param> public override void Deserialize(NetworkReader reader) { Direction = reader.ReadVector3(); SyncBaseID = reader.ReadInt32(); }
private void Update() { if (Input.GetKeyDown(KeyCode.LeftBracket)) { paletteEditor.gameObject.SetActive(!paletteEditor.gameObject.activeSelf); } bool editing = tileEditor.gameObject.activeSelf; bool chatting = chatOverlay.gameObject.activeSelf; bool mapping = Input.GetKey(KeyCode.Tab) && !chatting; if (editing && !chatting) { tileEditor.CheckInput(); } if (Input.GetKeyDown(KeyCode.Escape)) { if (chatting) { chatOverlay.Hide(); } else if (editing) { tileEditor.OnClickedSave(); } else if (hostID != -1) { OnApplicationQuit(); SceneManager.LoadScene("Main"); return; } else { Application.Quit(); return; } } else if (Input.GetKeyDown(KeyCode.F12)) { string selfies = Application.persistentDataPath + "/selfies"; Directory.CreateDirectory(selfies); Application.CaptureScreenshot(string.Format("{0}/{1}.png", selfies, System.DateTime.Now.Ticks)); } else if (Input.GetKeyDown(KeyCode.F11)) { string maps = Application.persistentDataPath + "/maps"; Directory.CreateDirectory(maps); mapCamera.Render(); var old = RenderTexture.active; RenderTexture.active = mapTexture; mapTextureLocal.ReadPixels(Rect.MinMaxRect(0, 0, 1024, 1024), 0, 0); RenderTexture.active = old; File.WriteAllBytes(string.Format("{0}/{1}.png", maps, System.DateTime.Now.Ticks), mapTextureLocal.EncodeToPNG()); } else if (Input.GetKeyDown(KeyCode.F2)) { scale = 3 - scale; Screen.SetResolution(512 * scale, 512 * scale, false); } if (hostID == -1) return; config.hideTutorial |= !tutorialChat.activeSelf && !tutorialMove.activeSelf && !tutorialTile.activeSelf && !tutorialWall.activeSelf; tutorialObject.SetActive(!config.hideTutorial); mapCamera.gameObject.SetActive(mapping); mapObject.SetActive(mapping); camera.orthographicSize = Mathf.Lerp(128, 32, zoom); if (Input.GetKeyDown(KeyCode.Return)) { if (chatting) { chatOverlay.OnClickedSend(); } else { chatOverlay.Show(); } } if (!chatting && !editing) { if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W)) { Move(Vector2.up); } else if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) { Move(Vector2.left); } else if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) { Move(Vector2.right); } else if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)) { Move(Vector2.down); } } if (Input.GetKeyDown(KeyCode.Space) && stickypalette) { stickypalette = false; } if (!chatting && !editing && Input.GetKey(KeyCode.Space)) { if (!tilePalette.gameObject.activeSelf) { stickypalette = Input.GetKey(KeyCode.LeftControl); tilePalette.Show(); } } else if (!stickypalette) { tilePalette.Hide(); } if (!UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject() && Rect.MinMaxRect(0, 0, Screen.width, Screen.height).Contains(Input.mousePosition) && !editing) { bool picker = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt); bool waller = !picker && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)); tileCursor.gameObject.SetActive(true); pickerCursor.SetActive(picker); tileCursor.sprite = this.world.tiles[tilePalette.SelectedTile]; Vector2 mouse = Input.mousePosition; Vector3 world; RectTransformUtility.ScreenPointToWorldPointInRectangle(worldView.transform as RectTransform, mouse, camera, out world); int x = Mathf.FloorToInt(world.x / 32); int y = Mathf.FloorToInt(world.y / 32); tileCursor.transform.position = new Vector2(x * 32, y * 32); byte tile = tilePalette.SelectedTile; int location = (y + 16) * 32 + (x + 16); if (location >= 0 && location < 1024) { if (waller && Input.GetMouseButtonDown(0)) { tile = this.world.tilemap[location]; bool wall = !this.world.walls.Contains(tile); SendAll(SetWallMessage(tile, wall)); if (this.world.walls.Set(tile, wall)) { tutorialWall.SetActive(false); audio.PlayOneShot(placeSound); } worldView.RefreshWalls(); } else if (!waller && Input.GetMouseButton(0)) { if (!picker && this.world.tilemap[location] != tile) { audio.PlayOneShot(placeSound); worldView.SetTile(location, tile); if (tile != 0) tutorialTile.SetActive(false); SendAll(SetTileMessage(location, tile)); } else if (picker) { tilePalette.SetSelectedTile(this.world.tilemap[location]); } } } } else { tileCursor.gameObject.SetActive(false); } var eventType = NetworkEventType.Nothing; int connectionID; int channelId; int receivedSize; byte error; do { // Get events from the server/client game connection eventType = NetworkTransport.ReceiveFromHost(hostID, out connectionID, out channelId, recvBuffer, recvBuffer.Length, out receivedSize, out error); if ((NetworkError)error != NetworkError.Ok) { group.interactable = true; popups.Show("Network Error: " + (NetworkError)error, delegate { }); } if (eventType == NetworkEventType.ConnectEvent) { connected = true; if (hosting) { OnNewClientConnected(connectionID); } else { OnConnectedToHost(connectionID); } } else if (eventType == NetworkEventType.DisconnectEvent) { if (hosting) { OnClientDisconnected(connectionID); } else { OnDisconnectedFromHost(connectionID); } } else if (eventType == NetworkEventType.DataEvent) { var reader = new NetworkReader(recvBuffer); { Type type = (Type) reader.ReadByte(); if (type == Type.Tilemap) { world.tilemap = reader.ReadBytesAndSize(); worldView.SetWorld(world); } else if (type == Type.Palette) { for (int i = 0; i < 16; ++i) { world.palette[i] = reader.ReadColor32(); SetPalette((byte) i, world.palette[i]); } } else if (type == Type.PaletteEdit) { ReceivePaletteEdit(reader); } else if (type == Type.Walls) { world.walls.Clear(); foreach (var wall in reader.ReadBytesAndSize()) { world.walls.Add(wall); } worldView.RefreshWalls(); } else if (type == Type.Tileset) { int id = reader.ReadInt32(); tiledata[id] = reader.ReadBytesAndSize(); } else if (type == Type.ReplicateAvatar) { ReceiveCreateAvatar(reader); } else if (type == Type.DestroyAvatar) { ReceiveDestroyAvatar(reader); } else if (type == Type.GiveAvatar) { ReceiveGiveAvatar(reader); } else if (type == Type.MoveAvatar) { World.Avatar avatar = ID2Avatar(reader.ReadInt32()); Vector2 dest = reader.ReadVector2(); if (hosting) { if (connectionID == avatar.id && !Blocked(avatar, dest)) { avatar.source = avatar.destination; avatar.destination = dest; avatar.u = 0; SendAll(MoveAvatarMessage(avatar, avatar.destination), except: avatar.id); } else { Send(connectionID, MoveAvatarMessage(avatar, avatar.destination)); } } else { avatar.source = avatar.destination; avatar.destination = dest; avatar.u = 0; } } else if (type == Type.Chat) { World.Avatar avatar = ID2Avatar(reader.ReadInt32()); string message = reader.ReadString(); if (hosting) { if (connectionID == avatar.id) { SendAll(ChatMessage(avatar, message), except: connectionID); Chat(avatar, message); } } else { Chat(avatar, message); } } else if (type == Type.SetTile) { ReceiveSetTile(reader); } else if (type == Type.SetWall) { ReceiveSetWall(reader); } else if (type == Type.TileChunk) { ReceiveTileChunk(reader, connectionID); } else if (type == Type.LockTile) { ReceiveLockTile(reader); } else if (type == Type.AvatarChunk) { ReceiveAvatarChunk(reader, connectionID); } else if (type == Type.TileStroke) { ReceiveTileStroke(reader, connectionID); } } } } while (eventType != NetworkEventType.Nothing); }
public void Deserialize(NetworkReader reader) { this.targetId = reader.ReadNetworkId(); this.buffIndex = reader.ReadBuffIndex(); this.stacks = reader.ReadInt32(); }
public override void Deserialize(NetworkReader reader) { ActionMode = (EditorActionMode) reader.ReadInt32(); }
public void Deserialize(ref SerializeContext context, ref NetworkReader reader) { active = reader.ReadBoolean() ? 1 : 0; terminating = reader.ReadBoolean() ? 1 : 0; terminateStartTick = reader.ReadInt32(); }
public static EnumReadWriteTests.MyCustom ReadMyCustomEnum(this NetworkReader networkReader) { return((EnumReadWriteTests.MyCustom)networkReader.ReadInt32()); }
private void ReceiveTileChunk(NetworkReader reader, int connectionID) { byte tile = reader.ReadByte(); int offset = reader.ReadInt32(); byte[] chunk = UncrunchBytes(reader.ReadBytesAndSize()); int x = tile % 16; int y = tile / 16; bool locked = locks.ContainsKey(tile); // if we're the host, disallow chunks not send by someone with a lock if (hosting && (!locked || locks[tile].id != connectionID)) return; // we're editing this tile, so ignore it if (locked && locks[tile] == worldView.viewer) return; Color[] colors = world.tileset.GetPixels(x * 32, y * 32, 32, 32); for (int i = 0; i < chunk.Length; ++i) { colors[i + offset] = world.palette[chunk[i]]; } world.tileset.SetPixels(x * 32, y * 32, 32, 32, colors); world.tileset.Apply(); if (hosting) { SendAll(TileInChunksMessages(world, tile)); } }