Fix loglevel, fix settings corruption, fix banned bots.
This commit is contained in:
parent
c286176031
commit
ebc30f2718
2
pom.xml
2
pom.xml
@ -52,7 +52,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>it.tdlight</groupId>
|
<groupId>it.tdlight</groupId>
|
||||||
<artifactId>tdlib-session-container</artifactId>
|
<artifactId>tdlib-session-container</artifactId>
|
||||||
<version>[1.0.0,)</version>
|
<version>[4.2.7,)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>it.tdlight</groupId>
|
<groupId>it.tdlight</groupId>
|
||||||
|
@ -236,16 +236,21 @@ public class PrimaryController {
|
|||||||
.doOnTerminate(this::enableClicks)
|
.doOnTerminate(this::enableClicks)
|
||||||
.subscribe(_v -> {}, error -> {
|
.subscribe(_v -> {}, error -> {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
|
var skipAndDeleteUserbotBtn = new ButtonType("Skip and delete userbot");
|
||||||
|
var skipBtn = new ButtonType("Skip");
|
||||||
var alert = new Alert(AlertType.ERROR,
|
var alert = new Alert(AlertType.ERROR,
|
||||||
"Error while adding the userbot " + PhoneNumberUtil
|
error.getLocalizedMessage(),
|
||||||
.getInstance()
|
skipBtn,
|
||||||
.format(phoneNumber, PhoneNumberFormat.INTERNATIONAL),
|
skipAndDeleteUserbotBtn
|
||||||
ButtonType.CLOSE
|
|
||||||
);
|
);
|
||||||
alert.setContentText(error.getLocalizedMessage());
|
alert.setHeaderText("Error while adding the userbot " + PhoneNumberUtil
|
||||||
MonoFxUtils.showAndWait(alert).subscribe();
|
.getInstance()
|
||||||
|
.format(phoneNumber, PhoneNumberFormat.INTERNATIONAL));
|
||||||
enableClicks();
|
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) {
|
} catch (NumberFormatException | NumberParseException ex) {
|
||||||
|
@ -72,7 +72,7 @@ public class SettingsServiceImpl implements SettingsService {
|
|||||||
settings.addProperty("proxyPort", proxyPort.get());
|
settings.addProperty("proxyPort", proxyPort.get());
|
||||||
settings.addProperty("proxySecret", proxySecret.get());
|
settings.addProperty("proxySecret", proxySecret.get());
|
||||||
try {
|
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) {
|
} catch (IOException e) {
|
||||||
App.getLogService().append(Level.ERROR, e.getLocalizedMessage());
|
App.getLogService().append(Level.ERROR, e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import com.google.i18n.phonenumbers.NumberParseException;
|
|||||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||||
import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
|
import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
|
||||||
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
|
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;
|
||||||
import it.tdlight.jni.TdApi.AuthorizationStateClosed;
|
import it.tdlight.jni.TdApi.AuthorizationStateClosed;
|
||||||
import it.tdlight.jni.TdApi.AuthorizationStateClosing;
|
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.Update;
|
||||||
import it.tdlight.jni.TdApi.User;
|
import it.tdlight.jni.TdApi.User;
|
||||||
import it.tdlight.jni.TdApi.UserTypeRegular;
|
import it.tdlight.jni.TdApi.UserTypeRegular;
|
||||||
|
import it.tdlight.tdlibsession.FatalErrorType;
|
||||||
import it.tdlight.tdlibsession.td.TdError;
|
import it.tdlight.tdlibsession.td.TdError;
|
||||||
import it.tdlight.tdlibsession.td.easy.AsyncTdEasy;
|
import it.tdlight.tdlibsession.td.easy.AsyncTdEasy;
|
||||||
import it.tdlight.tdlibsession.td.easy.ParameterInfoPasswordHint;
|
import it.tdlight.tdlibsession.td.easy.ParameterInfoPasswordHint;
|
||||||
@ -41,6 +43,7 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
@ -92,12 +95,16 @@ public class TransferServiceImpl implements TransferService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String alias = PhoneNumberUtil.getInstance().format(phoneNumber, PhoneNumberFormat.INTERNATIONAL);
|
String alias = PhoneNumberUtil.getInstance().format(phoneNumber, PhoneNumberFormat.INTERNATIONAL);
|
||||||
|
final AtomicReference<FatalErrorType> fatalError = new AtomicReference<>(null);
|
||||||
|
|
||||||
return Mono
|
return Mono
|
||||||
.fromCallable(() -> {
|
.fromCallable(() -> {
|
||||||
return AsyncTdMiddleDirect.getAndDeployInstance(clusterManager, alias, "" + phoneNumberLong);
|
synchronized (clusterManager) {
|
||||||
|
return AsyncTdMiddleDirect.getAndDeployInstance(clusterManager, alias, "" + phoneNumberLong)
|
||||||
|
.block(Duration.ofSeconds(60));
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.subscribeOn(Schedulers.boundedElastic())
|
.subscribeOn(Schedulers.boundedElastic())
|
||||||
.flatMap(v -> v)
|
|
||||||
.map(middle -> new AsyncTdEasy(middle, alias)).flatMap(client -> {
|
.map(middle -> new AsyncTdEasy(middle, alias)).flatMap(client -> {
|
||||||
return client
|
return client
|
||||||
.execute(new TdApi.SetLogVerbosityLevel(0))
|
.execute(new TdApi.SetLogVerbosityLevel(0))
|
||||||
@ -117,6 +124,7 @@ public class TransferServiceImpl implements TransferService {
|
|||||||
.setSystemLanguageCode("en")
|
.setSystemLanguageCode("en")
|
||||||
.setDeviceModel(System.getProperty("os.name"))
|
.setDeviceModel(System.getProperty("os.name"))
|
||||||
.setSystemVersion(System.getProperty("os.version"))
|
.setSystemVersion(System.getProperty("os.version"))
|
||||||
|
.setFatalErrorHandler((FatalErrorType error) -> Mono.fromRunnable(() -> fatalError.set(error)))
|
||||||
.setParameterRequestHandler((parameter, parameterInfo) -> {
|
.setParameterRequestHandler((parameter, parameterInfo) -> {
|
||||||
switch (parameter) {
|
switch (parameter) {
|
||||||
case ASK_FIRST_NAME:
|
case ASK_FIRST_NAME:
|
||||||
@ -185,7 +193,7 @@ public class TransferServiceImpl implements TransferService {
|
|||||||
if (state.getConstructor() == AuthorizationStateReady.CONSTRUCTOR) {
|
if (state.getConstructor() == AuthorizationStateReady.CONSTRUCTOR) {
|
||||||
sink.complete();
|
sink.complete();
|
||||||
} else {
|
} else {
|
||||||
sink.error(new Exception(state.getClass().getSimpleName()));
|
sink.error(new Exception("Userbot closed with state: " + state.getClass().getSimpleName()));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then();
|
.then();
|
||||||
@ -216,7 +224,15 @@ public class TransferServiceImpl implements TransferService {
|
|||||||
newClients.onNext(new ItemUpdate<>(false, newClient));
|
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) {
|
private Mono<Void> onClientUpdate(Update update) {
|
||||||
|
38
src/main/resources/log4j2.xml
Normal file
38
src/main/resources/log4j2.xml
Normal 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>
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user