47 lines
1.7 KiB
Java
47 lines
1.7 KiB
Java
package io.github.lonamiwebs.overgram;
|
|
|
|
import io.github.lonamiwebs.overgram.crypto.AuthKey;
|
|
import io.github.lonamiwebs.overgram.network.MTProtoSender;
|
|
import io.github.lonamiwebs.overgram.network.MTProtoState;
|
|
import io.github.lonamiwebs.overgram.network.connection.TcpFull;
|
|
import io.github.lonamiwebs.overgram.tl.Functions;
|
|
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.util.concurrent.ExecutionException;
|
|
import java.util.concurrent.Future;
|
|
|
|
public class Overgram {
|
|
private static void saveAuthKey(final AuthKey authKey, final File file) {
|
|
try (final FileOutputStream out = new FileOutputStream(file)) {
|
|
out.write(authKey.key);
|
|
} catch (IOException ignored) {
|
|
}
|
|
}
|
|
|
|
private static AuthKey loadAuthKey(final File file) {
|
|
try (final FileInputStream in = new FileInputStream(file)) {
|
|
final byte[] key = new byte[256];
|
|
assert in.read(key) == key.length;
|
|
return new AuthKey(key);
|
|
} catch (IOException ignored) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static void main(final String... args) throws IOException, InterruptedException, ExecutionException {
|
|
final File authKey = new File("auth.key");
|
|
final MTProtoSender sender = new MTProtoSender(new MTProtoState(loadAuthKey(authKey)), new TcpFull());
|
|
try {
|
|
sender.connect("149.154.167.91", 443);
|
|
saveAuthKey(sender.state.authKey, authKey);
|
|
final Future result = sender.send(new Functions.Ping());
|
|
System.out.println(result.get());
|
|
} finally {
|
|
sender.disconnect();
|
|
}
|
|
}
|
|
}
|