Commit Graph

222 Commits

Author SHA1 Message Date
赵怡然
876805895b
[core] Fix: 缓存可能因为计算机硬碟或程式不稳定造成损毁。 (#2841)
* Fix: 缓存可能因为计算机硬碟或程式不稳定造成损毁。

* Apply suggestions from code review

---------

Co-authored-by: Him188 <Him188@mamoe.net>
2024-03-03 00:01:12 +00:00
StageGuard
5b3e508b75
feature: add ShortVideo message support (#2739)
* initial support for ShortVideo message

* dump api

* [core] upload protocol

* [core] short video upload event

* [core] doc

* [core] protocol

* [core] fix mp4 file check

* [core] extract fileName from `OnlineShortVideo` to `ShortVideo`

* [core] ShortVideo.Builder

* [core] mirai code support for `ShortVideo`

* [core] add doc for OnlineShortVideo and OfflineShortVideo

* [core] fix text

* dump api

* update `Contact.uploadShortVideo`·` doc

* [core] remove mirai code support for ShortVideo

* [core] ensure Mirai service is loaded before load other services

* [core] introduce `CombinedExternalResource` to reference multiple external resources for combined calculation.

* [core] move refine context key defined in `OnlineShortVideoMsgInternal` to `RefineContext`

* [core] remove data class

* [core] broadcast `ShortVideoUploadEvent.Failed` event

* [core] warn when cannot determine fromId

* [core] add `contentToString` and `toString` for `OnlineShortVideoMsgInternal`

* [core] optimize imports

* [core] import

* [core] revert

* [core] doc

* [core] auto close resource

* dump api

* keep consistence of param name

* update doc

* move Builder to OfflineShortVideo

* optimize RefineContext

* RefineContext.merge

* dump api

* fix test

* show more video info

* optimize constructor and builder of offline short video

* optimize thumbnail

* move thumbnail to main constructor arg

* dump api

* avoid null cast exception.

* combine format transition

* cleanup
2023-08-20 18:41:05 +08:00
赵怡然
d1295c4e39
default encodeBase64/decodeBase64 mode to NO_WRAP on Android (#2753) 2023-07-26 13:25:22 +08:00
Karlatemp
061bd28798
[build/testing] Add jupiter-api back to testing 2023-07-25 15:29:05 +08:00
Him188
8ff64d4a7f
Remove native (#2700)
* Remove native target

* Add foojay-resolver-convention

* disable windows
2023-06-16 13:40:46 +01:00
StageGuard
60d360baad
[core] Update login protocol, deprecate DeviceInfo constructor and serializer (#2613)
* [core] update protocol

* [core] fix t106 decryption key

* [core] handle t543

* [core] revert t106

* [core] revert native test pow data

* [core] split build version and apk version name

* [core] pass time to t1 instead of time diff

* [core] remove unused t106 writer & rename param ip to ipv4 of t1 and t106

* [core] implement qimei for t545
TODO: aes and rsa crypto for nativeMain

* [core] fix base64 decode for android in rsa

* [core] fix unix timestamp parsing on native and add more tests

* [api] DeviceInfo move `androidId` to main constructor and adjust test.

* [api] do not request qimei when protocol is neither  ANDROID_PHONE nor ANDROID_PAD

* [api] implement aes crypto for native target

* [api] rsa crypto for multi-platform

* [api] crypto test

* [api] move freePointer util

* [api] openssl api compatibility

* [core] add explicit `androidId` param

* [core] remove unused `tlvCount`

* [core] optimize crypto

* [core] move Qimei to network package

* [core] move appId to protocol

* [core] lazily initialize qimeiLogger

* [core] write byte array to BIO mem

* [core] move qimei to client, add direct serializer for DeviceInfo

* [core] optimize DeviceInfoDelegateSerializer

* [core] real user-agent when requesting qimei

* [core] use `DeviceInfo.version.release`

* [core] remove unused wtlogin packet

* [core] do what constructor serializer should do

* [core] fix endless cache validation caused by not upgrading device info file.

* [core] request qimei before fast-login

* [core] tlv order

* [core] remove wrong tests and print more detail when deserialize failed.

* [core] device info upgrade for native

* [core] request qimei after validating cache

* [core] DeviceInfo compatibility

* [core] DeviceInfo test name

* [core] compatibility serializer

* [core] disable rsa crypto test on android unit test

* [core] move rsa impl to jvmBase

* action

* import

* api dump

* api dump

* revert wrong api dumps

* [core] Deprecate DeviceInfo constructor and serializer, provide `serializeToString` and `deserializeFromString` for replacement

* rerun ci

* optimize

* use serializer directly

* optimize test

* revert

* [core] CacheValidator use `DeviceInfo.serializeToString()` instead of direct serializer

* Remove `println` in `DeviceInfoManager`

* Add legacy deserialize overload for ABI compatibility

* Remove uncompleted docs for DeviceInfo

* Suppress DeviceInfo deprecation warnings for internal usages

---------

Co-authored-by: Him188 <Him188@mamoe.net>
2023-05-21 13:45:46 +01:00
Him188
c57fdd7790
Revert "[core] Add common JvmFile for compatibility"
This reverts commit 64e3d6c0f2.
2023-05-08 13:00:53 +01:00
Him188
64e3d6c0f2
[core] Add common JvmFile for compatibility 2023-05-08 12:21:38 +01:00
Him188
b82e938b2c
[build] Fix checkAndroidApiLevel tasks when building without ADK 2023-05-06 11:20:49 +01:00
Him188
363d1f7ece
Remove module-level opt-ins, add @OptIn explicit in use-sites;
added some opt-in markers on API which should have:

- `appendMiraiCodeTo`

Made API stable (otherwise they require too heavy opt-ins):
- MiraiConsoleImplementation$ConsoleLaunchOptions
- LowLevelApi
2023-05-06 11:04:31 +01:00
Him188
bda5d54bd3 [core/auth] Wrap exception from BotAuthorization as BotAuthorizationException; add tests 2023-05-04 16:36:28 +01:00
Him188
c6a8f4bde5 [core] Remove Latch since it's not needed anymore 2023-05-04 16:36:28 +01:00
Him188
0e625d3368 [core] OnDemandChannel: Ensure scope is closed on exceptional cases:
[core] OnDemandChannel: Ensure channel close and emit shares same behavior

[core] OnDemandChannel: Ensure channel is closed properly when producer throws an exception

[core] OnDemandChannel: Ensure coroutine scope cancelled when producer coroutine throws exception,

also added more tests
2023-05-04 16:36:28 +01:00
Him188
87fbaa4fb2 [core] Revise OnDemandChannel, improve state abstraction:
[core] Start producer coroutine immediately on `expectMore` and yield

Improve docs for OnDemandChannel

Rename factory function `OnDemandReceiveChannel` to  `OnDemandChannel` to better cover its meaning

Create deferred lazily in Producing state

Rename ProducerState to ChannelState

fix atomicfu bug receiveOrNull

Add docs (WIP, to be rebased)

[core] OnDemandChannel: Catch Throwable in `receiveOrNull` to prevent possible failures
2023-05-04 16:36:28 +01:00
Him188
99f592d614 [core] Move Latch and OnDemandValueScope to mirai-core-utils,
and rename OnDemandValueScope to OnDemandSendChannel and OnDemandReceiveChannel
2023-05-04 16:36:28 +01:00
Him188
36d90c57fe [core] Add UtilsLogger in mirai-core-utils module to bridge logging,
also added delegations in mirai-core and mirai-core-api.
2023-05-04 16:36:28 +01:00
Him188
84d03c9a71 [core] Set minimum Android API level to 21 2023-05-02 16:17:48 +01:00
Him188
2ef89d2b3f [build] Do not apply Android-relevant plugins if Android target is not enabled 2023-05-02 16:17:48 +01:00
Him188
178ca6c1b5 [build] Rewrite shadow relocation; fix dependency graph issues with Android, and improve build performance:
- Generate relocated JARs with classifier `relocated`, instead of replacing the output of `:jar` task.

- Create `JvmRelocated` publications to publish relocated artifacts.

- Patch Kotlin Metadata and Maven Pom for the added publication.

- Updated deps test to be more strict
2023-05-02 16:17:48 +01:00
Him188
40d4957837 [core/android] Implement mirai-core tests for Android target with AndroidSDK 2023-05-02 16:17:48 +01:00
Him188
4ed551027a [build] Support both configuring Android targets by Android SDK or JVM
- try to fix sdk dir when android is desired
- Do not printAndroidNotInstalled multiple times
2023-05-02 16:17:48 +01:00
Him188
2cf97a181f [build] Use JUnit5 on Android 2023-05-02 16:17:48 +01:00
Him188
a2d50ec03a [build] Relocate ktor only for jvm, not for Android 2023-05-02 16:17:48 +01:00
Him188
164f621427 [build] Fully support Android target; Update to Gradle 8.0 2023-05-02 16:17:48 +01:00
Him188
7a5cbbcb88
[core] Add kotlinx-coroutines-debug in mirai-core-utils 2023-05-01 22:52:29 +01:00
Him188
0ea5503f3b
[core/testFramework] Add assertNoCoroutineSuspension 2023-05-01 22:52:11 +01:00
Him188
c3a9511783
[core] Remove redundant AtomicFU runtime dependency from mirai-core-utils 2023-05-01 11:09:40 +01:00
Him188
1166f3d77a
[core] Make Services.registerAsOverride public to be used in tests 2023-05-01 11:08:26 +01:00
Him188
d2d2f4844d
[core] Fix minor compiler warnings
- unused variables
- requires opt-in
2023-05-01 11:08:04 +01:00
Him188
3cbc253121
[core] Handle a nullable case in readResource from Java 2023-05-01 11:08:04 +01:00
Him188
959224cad2
[core] Throw ISE when "user.dir" is not available, instead of throwing NPE 2023-05-01 11:08:04 +01:00
微莹·纤绫
434ef0cc39
Tlv writer (#2569)
* [core] TlvMapWriter

* [core] bind tlv writing with writer

* [core] Add checking to avoid wrong nest writing

* [core] Drop Int.invoke

* [core] Merge with dev

* [core] Update style
2023-03-26 23:51:03 +08:00
Him188
427c37e649
[build] Update to Kotlin 1.8.10 2023-03-19 03:18:34 +00:00
StageGuard
78d0b4fd54
QRCode login support & Introduce new authorization factory (#2502)
* [core] process `wtlogin.trans_emp` to support qrcode login

* [core] fix `wtlogin.trans_emp` protocol

* [core] optimize QRCodeLoginProcessor logic

* [core] fix `wtlogin.trans_emp` outgoing packet

* [core] cancel login when logging a bot which is inconsistent from bot factory

* [core] ignore `flag3` check on ANDROID_WATCH & name `flag1` and `flag2`

* [core] provide default `QRCodeLoginListener` for jvm

* [core] don't catch IllegalStateException in QRCodeLoginProcessor

* [core] Use `LoginSolver.createQRCodeLoginListener()` instead of property; Rename configuration name

* [core] Code improvement

* [core] remove qrcode state lock

* [core] ignore `flag3` when command is `wtlogin.trans_emp` in packet codec

* [core] enable qrcode login for macos

* [core] remove debug property in log

* [core] reformat code

* [core] rename `TransEmpResponse` to `Response`

* [core] assert `flag3Exception` not null first

* [core] remove arg client

* [core] update qrcode login notes

* [core] set custom qrcode size

* [core] Draft BotAuthorization

* [core] make SecretsProtection mpp

* [core] BotAuthorization.byXXX

* [core] Move QRCodeLoginListener to `.auth`

* [core] Protect data of BotAccount

* [core] Add SelectorRequireReconnectException

* [core] Implementation of BotAuthorization

* Revert changes of BotConfiguration

* api dump

* [core] remove passwordMd5 in `BotAccount`

* [mock] Add new bot factory function to mock bot factory

* Delete LoginCommandTest

* [core] Improve QRCode render

* [core] Introduce UnsupportedCaptchaMethodException & UnsupportedQRCodeCaptchaException

* api dump

* update docs

* [core] update `DebugRunHelper`

* [core] add simple block for BotAuthorization

* api dump

* Rename `canDoQRLogin` to `supportsQRLogin`, and specify argument names for MiraiProtocolInternal

* Remove `phoneNumber` parameter from BotAccount

* Make `BotAccount.<init>` with String password parameter TestOnly

* Rename `InconsistentBotException` to `InconsistentBotIdException`

* Rename `QRCodeLoginListener.onStatusChanged` to `QRCodeLoginListener.onStateChanged`

* Rename `BotAuthorizationResult` to `BotAuthResult`

* Rename BotAuthComponent, move internal APIs to internal module

* Logic fixup

* doc update

* QRCodeLoginListener.qrCodeStateUpdateInterval & onIntervalLoop

* console login with BotAuthorization

* update testing

* Update mirai-core-api/src/jvmMain/kotlin/utils/LoginSolver.jvm.kt

* Move AuthControl outside SsoProcessor

* Redesign auth

* Add initialTicket to producerCoroutine

* Revert protocol changes of MACOS

* Fix latch death locking

* Fix CoroutineOnDemandValueScope.receiveOrNull exceptional finish

* Fix exception collecting

* Fix DefaultBotAuthorizationFactory loading

* [core] qrcode login for IPAD protocol

* Revert "[core] qrcode login for IPAD protocol"

This reverts commit c1136a8798.

---------

Co-authored-by: Karlatemp <kar@kasukusakura.com>
Co-authored-by: Him188 <Him188@mamoe.net>
2023-03-18 13:52:31 +00:00
ArgonarioD
4f0f733f4d
修复JvmPlugin无法通过自己的classLoader以getResource的方法获取全局依赖的class文件 (#2536)
* [console] Fixed classLoaders of JvmPlugin cannot getResource(classes of global dependencies), fix #2535

* [core/utils/jvm] new fun: addAll(Enumeration)

* [console] modify DynLibClassLoader.tryFastOrStrictResolveResource to tryFastOrStrictResolveResources

* [console] remove allClassesAsResources field

* [console] add var to control whether class files of mirai dependencies could be load as resources

* [console/integration-test] modify loader test

* [console] dump new apis

* [console] rename JvmPluginClasspath.openMiraiDependenciesClassResource and standardize its KDoc

* [console] modify the KDoc of JvmPluginClasspath.shouldResolveConsoleSystemResource

* [console/integration-test] improve resources loading test cases

* [console/integration-test] modify assert to assertTrue
2023-03-12 22:37:47 +08:00
Eritque arcus
3ff2737b3c
Add fallback solution for Services (#2511)
* add fallback solution for Services

* use castUp

* throw exception when prop doesn't match

* cannot use castUp

* improve codes

* improve name of functions

* add both

* add override

* solve conflicts

* [core] Move MiraiCoreServices to common

* [core] Improvement

* update var names

* update func names

---------

Co-authored-by: Karlatemp <kar@kasukusakura.com>
2023-03-11 18:12:56 +08:00
cssxsh
9f36eff070
[core] Support loading service from classloaders other than current (#2428)
* fix: load service, close #2268 #2427

* fix: check empty
2023-02-17 09:57:12 +00:00
sandtechnology
cc7f35519e
Update login protocol (#2433)
* Update login protocol
Still need testing

* Turn off debug option and make t547 null when failed

* Fix wrong convert method and improve tips

* Remove unused part and improve tips

* Fix typo

* Inline resultStatus for performance

* Rename pow to PoW, the name should be "Proof of Work"

* Add shadow and deps-test for kt-bignum

* Try to fix deps-test

* Fix deps-test again
2023-01-18 17:41:21 +08:00
Karlatemp
c77ed79b12
[core] Encode html entities for forward message; fix #2241 2022-12-11 22:26:06 +08:00
Him188
60bbcf6e2c
[core] Revert "Review atomic calls and enable atomicfu compiler. Close #2315", due to atomicfu does not behave correctly when mirai-console depends on mirai-core-utils. Fixes #2329.
This commit reverts part of commit 564a7ce8f8
2022-11-27 20:08:21 +00:00
Him188
3360347ca2 [build] Fix dependency exclusion for builds when IDEA_ACTIVE 2022-11-27 15:25:18 +00:00
Him188
c0ccdbe9d3 [build] Rewrite shadow relocation 2022-11-27 15:25:18 +00:00
Him188
f24ca9628f
[core] Optimize array expansions 2022-11-02 19:29:02 +00:00
微莹·纤绫
4abb3e3703
[core] Introduce Flow<T>.toStream() for simply implement Streamable (#2259)
* [core] Introduce `Flow<T>.toStream()` for simply implement `Streamable`

* Drop `unintercepted` support

* fix ci

* update test
2022-10-31 13:09:58 +00:00
Him188
564a7ce8f8
[core] Review atomic calls and enable atomicfu compiler. Close #2315 2022-10-29 13:04:37 +01:00
Him188
1f8524fb04
Fix all compiler warnings throughout the project 2022-10-21 17:00:37 +01:00
Him188
25e66d19c7
[core] Filter out relocated ktor dependencies in runtime except for mirai-core-utils and mirai-core-all. Fix #2291 2022-10-21 16:09:27 +01:00
Him188
4d80e0e6d3
[core] Improve documentation on processor pipeline system. 2022-10-12 14:38:17 +01:00
Him188
2da0a2d6d3
[core] Fix relevant uses of Closeable 2022-09-23 23:01:39 +08:00
Him188
9122dddfb7
[core] Add net.mamoe.mirai.utils.Closeable for MPP use 2022-09-23 21:38:06 +08:00