/// <summary> /// Used to gather information needed /// </summary> /// <remarks> /// Also for converting client side packet to server side packet /// </remarks> /// <param name="packetID"></param> /// <param name="packetData"></param> /// <param name="isLogin"></param> private void HandleInBoundPacket(int packetID, IEnumerable <byte> packetData, bool isLogin) { Queue <byte> p = new Queue <byte>(packetData); PacketTypesIn pType = packetType.GetIncommingTypeById(packetID); // Login success. Get player UUID if (isLogin && packetID == 0x02) { Guid uuid; if (protocolVersion < Protocol18Handler.MC116Version) { if (Guid.TryParse(dataTypes.ReadNextString(p), out uuid)) { SetClientPlayerUUID(uuid); WriteDebugLog("User UUID: " + uuid.ToString()); } } else { var uuid2 = dataTypes.ReadNextUUID(p); SetClientPlayerUUID(uuid2); WriteDebugLog("User UUID: " + uuid2.ToString()); } return; } if (!isLogin && pType == PacketTypesIn.JoinGame) { // Get client player entity ID SetClientEntityID(dataTypes.ReadNextInt(p)); return; } if (!isLogin && pType == PacketTypesIn.SpawnPlayer) { dataTypes.ReadNextVarInt(p); OnPlayerSpawn(dataTypes.ReadNextUUID(p)); return; } // Get client player location for calculating movement delta later if (pType == PacketTypesIn.PlayerPositionAndLook) { double x = dataTypes.ReadNextDouble(p); double y = dataTypes.ReadNextDouble(p); double z = dataTypes.ReadNextDouble(p); float yaw = dataTypes.ReadNextFloat(p); float pitch = dataTypes.ReadNextFloat(p); byte locMask = dataTypes.ReadNextByte(p); playerLastPitch = pitch; playerLastYaw = yaw; if (protocolVersion >= Protocol18Handler.MC18Version) { playerLastPosition.X = (locMask & 1 << 0) != 0 ? playerLastPosition.X + x : x; playerLastPosition.Y = (locMask & 1 << 1) != 0 ? playerLastPosition.Y + y : y; playerLastPosition.Z = (locMask & 1 << 2) != 0 ? playerLastPosition.Z + z : z; } else { playerLastPosition.X = x; playerLastPosition.Y = y; playerLastPosition.Z = z; } return; } }
/// <summary> /// Get incomming packet ID by packet type /// </summary> /// <param name="packetType">Packet type</param> /// <returns>packet ID</returns> public int GetIncommingIdByType(PacketTypesIn packetType) { return(reverseMappingIn[packetType]); }