public void DispatchHandshakingPacket(IPacketSerializable packet) { switch (packet.packetId) { case Handshake.Packet: this.InvokeHandshake(packet as Handshake); break; } }
private void InvokeDispatchIncomingPacket(SessionStatus status, IPacketSerializable packet) { if (onDispatchIncomingPacket != null) { onDispatchIncomingPacket(status, packet); } this.OnDispatchIncomingPacket(status, packet); }
private void DispatchStatusPacket(IPacketSerializable packet) { switch (packet.packetId) { case Pong.Packet: this.InvokePong(packet as Pong); break; case Response.Packet: this.InvokeResponse(packet as Response); break; } }
public async Task SendIncomingPacket(IPacketSerializable packet) { if (packet != null) { using (var stream = new MemoryStream()) { using (var bw = new NetworkWrite(stream)) packet.Serialize(bw); await SendIncomingUncompressedPacket(new UncompressedPacket(packet.packetId, new ArraySegment <byte>(stream.ToArray()))); } } }
public void DispatchLoginPacket(IPacketSerializable packet) { switch (packet.packetId) { case LoginStart.Packet: this.InvokeLoginStart(packet as LoginStart); break; case EncryptionResponse.Packet: this.InvokeEncryptionResponse(packet as EncryptionResponse); break; } }
public void DispatchStatusPacket(IPacketSerializable packet) { switch (packet.packetId) { case Ping.Packet: this.InvokePing(packet as Ping); break; case Request.Packet: this.InvokeRequest(packet as Request); break; } }
private void OnDispatchIncomingPacket(SessionStatus status, IPacketSerializable packet) { switch (status) { case SessionStatus.Status: this.DispatchStatusPacket(packet); break; case SessionStatus.Login: this.DispatchLoginPacket(packet); break; case SessionStatus.Play: this.DispatchPlayPacket(packet); break; } }
public Task DispatchIncomingPacket(UncompressedPacket packet) { switch (status) { case SessionStatus.Status: case SessionStatus.Login: case SessionStatus.Play: { IPacketSerializable pack = null; foreach (var it in list[(int)status]) { if (it.packetId == packet.packetId) { pack = it.Clone() as IPacketSerializable; break; } } if (pack != null) { try { using (var br = new NetworkReader(packet.data)) pack.Deserialize(br); this.InvokeDispatchIncomingPacket(status, pack); } catch (System.NotImplementedException e) { UnityEngine.Debug.LogException(e); } } else { this.InvokeDispatchInvalidPacket(status, packet); } } break; } return(Task.CompletedTask); }
private void DispatchLoginPacket(IPacketSerializable packet) { switch (packet.packetId) { case LoginSuccess.Packet: InvokeLoginSuccess(packet as LoginSuccess); break; case LoginDisconnect.Packet: InvokeLoginDisconnect(packet as LoginDisconnect); break; case SetCompression.Packet: InvokeSetCompression(packet as SetCompression); break; case EncryptionRequest.Packet: InvokeEncryptionRequest(packet as EncryptionRequest); break; } }
private void OnDispatchIncomingPacket(SessionStatus status, IPacketSerializable packet) { UnityEngine.Debug.Log($"Status:{status} Packet:{packet.GetType().Name}"); }
public void DispatchPlayPacket(IPacketSerializable packet) { switch (packet.packetId) { case TeleportConfirm.Packet: this.InvokeTeleportConfirm(packet as TeleportConfirm); break; case PrepareCraftingGrid.Packet: this.InvokePrepareCraftingGrid(packet as PrepareCraftingGrid); break; case TabComplete.Packet: this.InvokeTabComplete(packet as TabComplete); break; case ChatMessage.Packet: this.InvokeChatMessage(packet as ChatMessage); break; case ClientStatus.Packet: this.InvokeClientStatus(packet as ClientStatus); break; case ClientSettings.Packet: this.InvokeClientSettings(packet as ClientSettings); break; case ConfirmTransaction.Packet: this.InvokeConfirmTransaction(packet as ConfirmTransaction); break; case EnchantItem.Packet: this.InvokeEnchantItem(packet as EnchantItem); break; case ClickWindow.Packet: this.InvokeClickWindow(packet as ClickWindow); break; case CloseWindow.Packet: this.InvokeCloseWindow(packet as CloseWindow); break; case PluginMessage.Packet: this.InvokePluginMessage(packet as PluginMessage); break; case UseEntity.Packet: this.InvokeUseEntity(packet as UseEntity); break; case KeepAlive.Packet: this.InvokeKeepAlive(packet as KeepAlive); break; case Player.Packet: this.InvokePlayer(packet as Player); break; case PlayerPosition.Packet: this.InvokePlayerPosition(packet as PlayerPosition); break; case PlayerPositionAndLook.Packet: this.InvokePlayerPositionAndLook(packet as PlayerPositionAndLook); break; case PlayerLook.Packet: this.InvokePlayerLook(packet as PlayerLook); break; case VehicleMove.Packet: this.InvokeVehicleMove(packet as VehicleMove); break; case SteerBoat.Packet: this.InvokeSteerBoat(packet as SteerBoat); break; case PlayerAbilities.Packet: this.InvokePlayerAbilities(packet as PlayerAbilities); break; case PlayerDigging.Packet: this.InvokePlayerDigging(packet as PlayerDigging); break; case EntityAction.Packet: this.InvokeEntityAction(packet as EntityAction); break; case SteerVehicle.Packet: this.InvokeSteerVehicle(packet as SteerVehicle); break; case CraftingBookData.Packet: this.InvokeCraftingBookData(packet as CraftingBookData); break; case ResourcePackStatus.Packet: this.InvokeResourcePackStatus(packet as ResourcePackStatus); break; case AdvancementTab.Packet: this.InvokeAdvancementTab(packet as AdvancementTab); break; case HeldItemChange.Packet: this.InvokeHeldItemChange(packet as HeldItemChange); break; case CreativeInventoryAction.Packet: this.InvokeCreativeInventoryAction(packet as CreativeInventoryAction); break; case UpdateSign.Packet: this.InvokeUpdateSign(packet as UpdateSign); break; case Animation.Packet: this.InvokeAnimation(packet as Animation); break; case Spectate.Packet: this.InvokeSpectate(packet as Spectate); break; case PlayerBlockPlacement.Packet: this.InvokePlayerBlockPlacement(packet as PlayerBlockPlacement); break; case UseItem.Packet: this.InvokeUseItem(packet as UseItem); break; } }
public void Write(IPacketSerializable obj) { TestWriteable(); Write(obj.GetType().FullName); Write(obj.Serialize(this)); }
public static bool Deserialize(Type type, byte[] data, ref int position, out object value) { if (type == typeof(byte)) { value = data[position]; position++; } else if (type.GetInterfaces().Contains(typeof(IPacketSerializable))) { IPacketSerializable serializable = (IPacketSerializable)Activator.CreateInstance(type); serializable.Deserialize(data, ref position); value = serializable; } else if (type.IsEnum) { EnumPackageType packageType = (EnumPackageType)type.GetCustomAttribute(typeof(EnumPackageType), false); if (packageType == null) { Console.WriteLine("Error: Enum \"" + type.FullName + "\" doesn't have EnumPackageType attribute"); value = null; return(false); } object obj; if (!Deserialize(packageType.type, data, ref position, out obj)) { value = null; return(false); } value = DynamicCast(DynamicCast(obj, type.GetEnumUnderlyingType()), type); } else if (type == typeof(bool)) { value = BitConverter.ToBoolean(data, position); position++; } else if (type == typeof(short)) { value = BitConverter.ToInt16(data, position); position += 2; } else if (type == typeof(ushort)) { value = BitConverter.ToUInt16(data, position); position += 2; } else if (type == typeof(int)) { value = BitConverter.ToInt32(data, position); position += 4; } else if (type == typeof(uint)) { value = BitConverter.ToUInt32(data, position); position += 4; } else if (type == typeof(long)) { value = BitConverter.ToInt64(data, position); position += 8; } else if (type == typeof(ulong)) { value = BitConverter.ToUInt64(data, position); position += 8; } else if (type == typeof(float)) { value = BitConverter.ToSingle(data, position); position += 4; } else if (type == typeof(double)) { value = BitConverter.ToDouble(data, position); position += 8; } else { value = null; return(false); } return(true); }
private void DispatchPlayPacket(IPacketSerializable packet) { switch (packet.packetId) { case SpawnObject.Packet: this.InvokeSpawnObject(packet as SpawnObject); break; case SpawnExperienceOrb.Packet: this.InvokeSpawnExperienceOrb(packet as SpawnExperienceOrb); break; case SpawnGlobalEntity.Packet: this.InvokeSpawnGlobalEntity(packet as SpawnGlobalEntity); break; case SpawnMob.Packet: this.InvokeSpawnMob(packet as SpawnMob); break; case SpawnPainting.Packet: this.InvokeSpawnPainting(packet as SpawnPainting); break; case SpawnPlayer.Packet: this.InvokeSpawnPlayer(packet as SpawnPlayer); break; case Animation.Packet: this.InvokeAnimation(packet as Animation); break; case Statistics.Packet: this.InvokeStatistics(packet as Statistics); break; case BlockBreakAnimation.Packet: this.InvokeBlockBreakAnimation(packet as BlockBreakAnimation); break; case UpdateBlockEntity.Packet: this.InvokeUpdateBlockEntity(packet as UpdateBlockEntity); break; case BlockAction.Packet: this.InvokeBlockAction(packet as BlockAction); break; case BlockChange.Packet: this.InvokeBlockChange(packet as BlockChange); break; case BossBar.Packet: this.InvokeBossBar(packet as BossBar); break; case ServerDifficulty.Packet: this.InvokeServerDifficulty(packet as ServerDifficulty); break; case TabComplete.Packet: this.InvokeTabComplete(packet as TabComplete); break; case ChatMessage.Packet: this.InvokeChatMessage(packet as ChatMessage); break; case MultiBlockChange.Packet: this.InvokeMultiBlockChange(packet as MultiBlockChange); break; case ConfirmTransaction.Packet: this.InvokeConfirmTransaction(packet as ConfirmTransaction); break; case CloseWindow.Packet: this.InvokeCloseWindow(packet as CloseWindow); break; case OpenWindow.Packet: this.InvokeOpenWindow(packet as OpenWindow); break; case WindowItems.Packet: this.InvokeWindowItems(packet as WindowItems); break; case WindowProperty.Packet: this.InvokeWindowProperty(packet as WindowProperty); break; case SetSlot.Packet: this.InvokeSetSlot(packet as SetSlot); break; case SetCooldown.Packet: this.InvokeSetCooldown(packet as SetCooldown); break; case PluginMessage.Packet: this.InvokePluginMessage(packet as PluginMessage); break; case NamedSoundEffect.Packet: this.InvokeNamedSoundEffect(packet as NamedSoundEffect); break; case Disconnect.Packet: this.InvokeDisconnect(packet as Disconnect); break; case EntityStatus.Packet: this.InvokeEntityStatus(packet as EntityStatus); break; case Explosion.Packet: this.InvokeExplosion(packet as Explosion); break; case ChunkUnload.Packet: this.InvokeChunkUnload(packet as ChunkUnload); break; case ChangeGameState.Packet: this.InvokeChangeGameState(packet as ChangeGameState); break; case KeepAlive.Packet: this.InvokeKeepAlive(packet as KeepAlive); break; case ChunkData.Packet: this.InvokeChunkData(packet as ChunkData); break; case Effect.Packet: this.InvokeEffect(packet as Effect); break; case Particle.Packet: this.InvokeParticle(packet as Particle); break; case JoinGame.Packet: this.InvokeJoinGame(packet as JoinGame); break; case Map.Packet: this.InvokeMap(packet as Map); break; case Entity.Packet: this.InvokeEntity(packet as Entity); break; case EntityRelativeMove.Packet: this.InvokeEntityRelativeMove(packet as EntityRelativeMove); break; case EntityLookAndRelativeMove.Packet: this.InvokeEntityLookAndRelativeMove(packet as EntityLookAndRelativeMove); break; case EntityLook.Packet: this.InvokeEntityLook(packet as EntityLook); break; case VehicleMove.Packet: this.InvokeVehicleMove(packet as VehicleMove); break; case OpenSignEditor.Packet: this.InvokeOpenSignEditor(packet as OpenSignEditor); break; case PlayerAbilities.Packet: this.InvokePlayerAbilities(packet as PlayerAbilities); break; case CombatEvent.Packet: this.InvokeCombatEvent(packet as CombatEvent); break; case PlayerListItem.Packet: this.InvokePlayerListItem(packet as PlayerListItem); break; case PlayerPositionAndLook.Packet: this.InvokePlayerPositionAndLook(packet as PlayerPositionAndLook); break; case UseBed.Packet: this.InvokeUseBed(packet as UseBed); break; case UnlockRecipes.Packet: this.InvokeUnlockRecipes(packet as UnlockRecipes); break; case DestroyEntities.Packet: this.InvokeDestroyEntities(packet as DestroyEntities); break; case RemoveEntityEffect.Packet: this.InvokeRemoveEntityEffect(packet as RemoveEntityEffect); break; case ResourcePackSend.Packet: this.InvokeResourcePackSend(packet as ResourcePackSend); break; case Respawn.Packet: this.InvokeRespawn(packet as Respawn); break; case EntityHeadLook.Packet: this.InvokeEntityHeadLook(packet as EntityHeadLook); break; case SelectAdvancementTab.Packet: this.InvokeSelectAdvancementTab(packet as SelectAdvancementTab); break; case WorldBorder.Packet: this.InvokeWorldBorder(packet as WorldBorder); break; case Camera.Packet: this.InvokeCamera(packet as Camera); break; case HeldItemChange.Packet: this.InvokeHeldItemChange(packet as HeldItemChange); break; case DisplayScoreboard.Packet: this.InvokeDisplayScoreboard(packet as DisplayScoreboard); break; case EntityMetadata.Packet: this.InvokeEntityMetadata(packet as EntityMetadata); break; case AttachEntity.Packet: this.InvokeAttachEntity(packet as AttachEntity); break; case EntityVelocity.Packet: this.InvokeEntityVelocity(packet as EntityVelocity); break; case EntityEquipment.Packet: this.InvokeEntityEquipment(packet as EntityEquipment); break; case SetExperience.Packet: this.InvokeSetExperience(packet as SetExperience); break; case UpdateHealth.Packet: this.InvokeUpdateHealth(packet as UpdateHealth); break; case ScoreboardObjective.Packet: this.InvokeScoreboardObjective(packet as ScoreboardObjective); break; case SetPassengers.Packet: this.InvokeSetPassengers(packet as SetPassengers); break; case Teams.Packet: this.InvokeTeams(packet as Teams); break; case UpdateScore.Packet: this.InvokeUpdateScore(packet as UpdateScore); break; case SpawnPosition.Packet: this.InvokeSpawnPosition(packet as SpawnPosition); break; case TimeUpdate.Packet: this.InvokeTimeUpdate(packet as TimeUpdate); break; case Title.Packet: this.InvokeTitle(packet as Title); break; case SoundEffect.Packet: this.InvokeSoundEffect(packet as SoundEffect); break; case PlayerListHeaderAndFooter.Packet: this.InvokePlayerListHeaderAndFooter(packet as PlayerListHeaderAndFooter); break; case CollectItem.Packet: this.InvokeCollectItem(packet as CollectItem); break; case EntityTeleport.Packet: this.InvokeEntityTeleport(packet as EntityTeleport); break; case Advancements.Packet: this.InvokeAdvancements(packet as Advancements); break; case EntityProperties.Packet: this.InvokeEntityProperties(packet as EntityProperties); break; case EntityEffect.Packet: this.InvokeEntityEffect(packet as EntityEffect); break; } }