Overgram/lib/src/main/java/io/github/lonamiwebs/overgram/Overgram.java

47 lines
1.7 KiB
Java
Raw Normal View History

2018-07-23 19:01:05 +00:00
package io.github.lonamiwebs.overgram;
import io.github.lonamiwebs.overgram.crypto.AuthKey;
2018-07-24 18:26:54 +00:00
import io.github.lonamiwebs.overgram.network.MTProtoSender;
import io.github.lonamiwebs.overgram.network.MTProtoState;
2018-07-23 19:59:28 +00:00
import io.github.lonamiwebs.overgram.network.connection.TcpFull;
2018-07-25 14:04:43 +00:00
import io.github.lonamiwebs.overgram.tl.Functions;
2018-07-23 19:59:28 +00:00
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
2018-07-23 19:59:28 +00:00
import java.io.IOException;
2018-07-25 14:04:43 +00:00
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
2018-07-23 19:59:28 +00:00
2018-07-23 19:01:05 +00:00
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;
}
}
2018-07-25 14:04:43 +00:00
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 {
2018-07-24 18:26:54 +00:00
sender.connect("149.154.167.91", 443);
saveAuthKey(sender.state.authKey, authKey);
final Future result = sender.send(new Functions.Ping());
2018-07-25 14:04:43 +00:00
System.out.println(result.get());
} finally {
2018-07-24 18:26:54 +00:00
sender.disconnect();
}
2018-07-23 19:01:05 +00:00
}
}