Fix loglevel, fix settings corruption, fix banned bots.

This commit is contained in:
Andrea Cavalli 2021-01-10 03:14:49 +01:00
parent c286176031
commit ebc30f2718
6 changed files with 73 additions and 14 deletions

View File

View File

@ -52,7 +52,7 @@
<dependency>
<groupId>it.tdlight</groupId>
<artifactId>tdlib-session-container</artifactId>
<version>[1.0.0,)</version>
<version>[4.2.7,)</version>
</dependency>
<dependency>
<groupId>it.tdlight</groupId>

View File

@ -236,16 +236,21 @@ public class PrimaryController {
.doOnTerminate(this::enableClicks)
.subscribe(_v -> {}, error -> {
Platform.runLater(() -> {
var skipAndDeleteUserbotBtn = new ButtonType("Skip and delete userbot");
var skipBtn = new ButtonType("Skip");
var alert = new Alert(AlertType.ERROR,
"Error while adding the userbot " + PhoneNumberUtil
.getInstance()
.format(phoneNumber, PhoneNumberFormat.INTERNATIONAL),
ButtonType.CLOSE
error.getLocalizedMessage(),
skipBtn,
skipAndDeleteUserbotBtn
);
alert.setContentText(error.getLocalizedMessage());
MonoFxUtils.showAndWait(alert).subscribe();
enableClicks();
alert.setHeaderText("Error while adding the userbot " + PhoneNumberUtil
.getInstance()
.format(phoneNumber, PhoneNumberFormat.INTERNATIONAL));
MonoFxUtils.showAndWait(alert).subscribe(result -> {
if (skipAndDeleteUserbotBtn.getText().equals(result.getText())) {
App.getSettingsService().removePhoneNumber(getLongPhoneNumber(phoneNumber));
}
}, System.err::println, this::enableClicks);
});
});
} catch (NumberFormatException | NumberParseException ex) {

View File

@ -72,7 +72,7 @@ public class SettingsServiceImpl implements SettingsService {
settings.addProperty("proxyPort", proxyPort.get());
settings.addProperty("proxySecret", proxySecret.get());
try {
Files.writeString(Paths.get("settings.json"), gson.toJson(settings), StandardCharsets.UTF_8, StandardOpenOption.CREATE);
Files.writeString(Paths.get("settings.json"), gson.toJson(settings), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (IOException e) {
App.getLogService().append(Level.ERROR, e.getLocalizedMessage());
}

View File

@ -8,6 +8,7 @@ import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
import com.hazelcast.cp.internal.datastructures.atomicref.AtomicRef;
import it.tdlight.jni.TdApi;
import it.tdlight.jni.TdApi.AuthorizationStateClosed;
import it.tdlight.jni.TdApi.AuthorizationStateClosing;
@ -23,6 +24,7 @@ import it.tdlight.jni.TdApi.SupergroupFullInfo;
import it.tdlight.jni.TdApi.Update;
import it.tdlight.jni.TdApi.User;
import it.tdlight.jni.TdApi.UserTypeRegular;
import it.tdlight.tdlibsession.FatalErrorType;
import it.tdlight.tdlibsession.td.TdError;
import it.tdlight.tdlibsession.td.easy.AsyncTdEasy;
import it.tdlight.tdlibsession.td.easy.ParameterInfoPasswordHint;
@ -41,6 +43,7 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
@ -92,12 +95,16 @@ public class TransferServiceImpl implements TransferService {
}
String alias = PhoneNumberUtil.getInstance().format(phoneNumber, PhoneNumberFormat.INTERNATIONAL);
final AtomicReference<FatalErrorType> fatalError = new AtomicReference<>(null);
return Mono
.fromCallable(() -> {
return AsyncTdMiddleDirect.getAndDeployInstance(clusterManager, alias, "" + phoneNumberLong);
synchronized (clusterManager) {
return AsyncTdMiddleDirect.getAndDeployInstance(clusterManager, alias, "" + phoneNumberLong)
.block(Duration.ofSeconds(60));
}
})
.subscribeOn(Schedulers.boundedElastic())
.flatMap(v -> v)
.map(middle -> new AsyncTdEasy(middle, alias)).flatMap(client -> {
return client
.execute(new TdApi.SetLogVerbosityLevel(0))
@ -117,6 +124,7 @@ public class TransferServiceImpl implements TransferService {
.setSystemLanguageCode("en")
.setDeviceModel(System.getProperty("os.name"))
.setSystemVersion(System.getProperty("os.version"))
.setFatalErrorHandler((FatalErrorType error) -> Mono.fromRunnable(() -> fatalError.set(error)))
.setParameterRequestHandler((parameter, parameterInfo) -> {
switch (parameter) {
case ASK_FIRST_NAME:
@ -185,7 +193,7 @@ public class TransferServiceImpl implements TransferService {
if (state.getConstructor() == AuthorizationStateReady.CONSTRUCTOR) {
sink.complete();
} else {
sink.error(new Exception(state.getClass().getSimpleName()));
sink.error(new Exception("Userbot closed with state: " + state.getClass().getSimpleName()));
}
})
.then();
@ -216,7 +224,15 @@ public class TransferServiceImpl implements TransferService {
newClients.onNext(new ItemUpdate<>(false, newClient));
}));
})
.map(_v -> AddUserBotResult.newSuccess());
.map(_v -> AddUserBotResult.newSuccess())
.onErrorMap(error -> {
var fatalErrorValue = fatalError.get();
if (fatalErrorValue != null) {
return new TdError(500, fatalErrorValue.toString());
} else {
return error;
}
});
}
private Mono<Void> onClientUpdate(Update update) {

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- log4j2.xml - Example log4j configuration file
Place this file in the same directory as your server.jar, edit
to taste, and add -Dlog4j.configurationFile=log4j2.xml to your
server startup flags.
More log4j example configs can be found at
<http://logging.apache.org/log4j/2.x/manual/appenders.html>.
-->
<Configuration status="WARN" packages="net.minecraft,com.mojang">
<Appenders>
<!-- DEFAULT APPENDERS -->
<!-- console logging - logs to stdout -->
<Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} %highlight{${LOG_LEVEL_PATTERN:-%5p}}{FATAL=red blink, ERROR=red, WARN=yellow bold, INFO=green, DEBUG=green bold, TRACE=blue} %style{%processId}{magenta} [%15.15t] %style{%-20.20c{1}}{cyan} : %m%n%ex"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<!-- DEFAULT LOGGERS -->
<filters>
<MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY"
onMismatch="NEUTRAL" />
</filters>
<AppenderRef ref="ConsoleAppender"/>
<!-- EXAMPLE LOGGERS -->
<!-- <AppenderRef ref="LegacyServerLog"/> -->
</Root>
</Loggers>
</Configuration>