forked from flash/temporary-satori-hole
155 lines
4.5 KiB
C
155 lines
4.5 KiB
C
#include <stdio.h>
|
|
#include <time.h>
|
|
#include "satori.h"
|
|
|
|
int main(void) {
|
|
puts(" _____ __ _");
|
|
puts(" / ___/____ _/ /_____ _____(_)");
|
|
puts(" \\__ \\/ __ `/ __/ __ \\/ ___/ /");
|
|
puts(" ___/ / /_/ / /_/ /_/ / / / /");
|
|
puts("/____/\\__,_/\\__/\\____/_/ /_/");
|
|
puts("");
|
|
puts("Satori Testing Hole");
|
|
|
|
puts("Initialising Libraries...");
|
|
if(curl_global_init(CURL_GLOBAL_ALL)) {
|
|
puts("Failed to initialise cURL.");
|
|
return 0;
|
|
}
|
|
|
|
|
|
int err;
|
|
satori_ctx_ptr satori = satori_ctx_alloc();
|
|
satori->startup = time(NULL);
|
|
|
|
|
|
satori->config = sat_config_alloc_stream();
|
|
err = sat_config_stream_open_file(satori->config, "Satori.cfg");
|
|
|
|
if(err) {
|
|
printf("sat_config_stream_open_file: %d\r\n", err);
|
|
//return;
|
|
} else {
|
|
if(sat_config_read_bool(satori->config, "exampleCfg:unedited", false)) {
|
|
puts("Please review the configuration file before starting again.");
|
|
//return;
|
|
}
|
|
|
|
char *test = sat_config_read_value(satori->config, "test", NULL);
|
|
printf("sat_config_read_value: %s\r\n", test);
|
|
free(test);
|
|
|
|
|
|
sat_config_ptr scoped = sat_config_scope_to(satori->config, "sockchat");
|
|
|
|
test = sat_config_read_value(scoped, "host", NULL);
|
|
printf("sat_config_read_value: %s\r\n", test);
|
|
free(test);
|
|
|
|
sat_config_free(scoped);
|
|
|
|
|
|
sat_config_ptr scoped1 = sat_config_scope_to(satori->config, "flashii");
|
|
sat_config_ptr scoped2 = sat_config_scope_to(scoped1, "broadcasts");
|
|
|
|
sat_config_free(scoped1);
|
|
|
|
bool testb = sat_config_read_bool(scoped2, "enable", false);
|
|
printf("sat_config_read_bool: %s\r\n", testb ? "YES" : "NO");
|
|
|
|
sat_config_free(scoped2);
|
|
}
|
|
|
|
|
|
satori->persist = sat_persist_alloc();
|
|
err = sat_persist_create_file(satori->persist, "Persist.dat");
|
|
|
|
if(err) {
|
|
printf("sat_persist_create_file: %d\r\n", err);
|
|
//return;
|
|
} else {
|
|
if(sat_persist_get_fii_forum_last_post_id(satori->persist) < 1) {
|
|
puts("Importing Flashii last forum post id from legacy configuration...");
|
|
sat_persist_set_fii_forum_last_post_id(
|
|
satori->persist,
|
|
sat_config_read_u64(satori->config, "legacy:flashii:broadcasts:lastForumPostId", 0)
|
|
);
|
|
sat_persist_flush(satori->persist);
|
|
}
|
|
|
|
if(sat_persist_get_fii_user_last_register_id(satori->persist) < 1) {
|
|
puts("Importing Flashii last joined user id from legacy configuration...");
|
|
sat_persist_set_fii_user_last_register_id(
|
|
satori->persist,
|
|
sat_config_read_u64(satori->config, "legacy:flashii:broadcasts:lastJoinUserId", 0)
|
|
);
|
|
sat_persist_flush(satori->persist);
|
|
}
|
|
}
|
|
|
|
|
|
satori->futami = sat_futami_alloc();
|
|
|
|
char *futamiUrl = sat_config_read_value(satori->config, "futami:common", NULL);
|
|
if(futamiUrl == NULL) {
|
|
puts("Missing Futami URL from config, cannot continue startup.");
|
|
//return;
|
|
}
|
|
|
|
err = sat_futami_load_json_url(satori->futami, futamiUrl);
|
|
free(futamiUrl);
|
|
|
|
if(err) {
|
|
printf("sat_futami_load_json_url: %d\r\n", err);
|
|
//return;
|
|
} else {
|
|
printf("Ping Interval: %d seconds, Server count: %ld\r\n", satori->futami->ping, satori->futami->serversCount);
|
|
|
|
for(size_t i = 0; i < satori->futami->serversCount; ++i)
|
|
printf(" - %s\r\n", satori->futami->servers[i]);
|
|
|
|
printf("\r\n");
|
|
}
|
|
|
|
|
|
if(satori->futami->serversCount < 1) {
|
|
puts("There are no available servers.");
|
|
//return;
|
|
}
|
|
|
|
sat_curl_url url = {0};
|
|
sat_curl_url_parse(&url, satori->futami->servers[0], "ws", NULL, NULL, "/", true);
|
|
|
|
sat_sock_ptr sock = sat_sock_alloc();
|
|
err = sat_sock_connect_tcp(sock, url.host, url.port);
|
|
sat_sock_set_blocking(sock, true);
|
|
|
|
sat_websock_ptr websock = sat_websock_alloc();
|
|
sat_websock_init(websock, sock);
|
|
|
|
sat_websock_handshake wshs = {0};
|
|
wshs.websock = websock;
|
|
wshs.host = url.host;
|
|
wshs.path = url.path;
|
|
sat_websock_handshake_gen_key(&wshs);
|
|
|
|
err = sat_websock_handshake_send(&wshs);
|
|
printf("sat_websock_handshake_send: %d\r\n", err);
|
|
|
|
|
|
err = sat_websock_handshake_recv(&wshs);
|
|
printf("sat_websock_handshake_recv: %d\r\n", err);
|
|
|
|
|
|
|
|
sat_sock_close(sock);
|
|
sat_sock_free(sock);
|
|
|
|
satori_ctx_free(satori);
|
|
|
|
puts("Cleaning up Libraries...");
|
|
curl_global_cleanup();
|
|
|
|
return 0;
|
|
}
|