static void init_tox_callbacks(Tox *m) { tox_callback_self_connection_status(m, prompt_onSelfConnectionChange); tox_callback_friend_connection_status(m, on_connectionchange); tox_callback_friend_typing(m, on_typing_change); tox_callback_friend_request(m, on_request); tox_callback_friend_message(m, on_message); tox_callback_friend_name(m, on_nickchange); tox_callback_friend_status(m, on_statuschange); tox_callback_friend_status_message(m, on_statusmessagechange); tox_callback_friend_read_receipt(m, on_read_receipt); tox_callback_conference_invite(m, on_groupinvite); tox_callback_conference_message(m, on_groupmessage); tox_callback_conference_namelist_change(m, on_group_namelistchange); tox_callback_conference_title(m, on_group_titlechange); tox_callback_file_recv(m, on_file_recv); tox_callback_file_chunk_request(m, on_file_chunk_request); tox_callback_file_recv_control(m, on_file_control); tox_callback_file_recv_chunk(m, on_file_recv_chunk); }
int main(void) { uint32_t conference_number; struct Tox_Options to; Tox *t; TOX_ERR_CONFERENCE_NEW conference_err; TOX_ERR_CONFERENCE_TITLE title_err; tox_options_default(&to); t = tox_new(&to, NULL); tox_callback_conference_title(t, &cbtitlechange); if ((conference_number = tox_conference_new(t, &conference_err)) == UINT32_MAX) { tox_kill(t); fprintf(stderr, "error: could not create new conference, error code %d\n", conference_err); return 2; } tox_iterate(t, NULL); c_sleep(tox_iteration_interval(t)); if (!tox_conference_set_title(t, conference_number, (const uint8_t *)newtitle, strlen(newtitle), &title_err)) { tox_kill(t); fprintf(stderr, "error: could not set conference title, error code %d\n", title_err); return 3; } tox_iterate(t, NULL); c_sleep(tox_iteration_interval(t)); tox_iterate(t, NULL); fprintf(stderr, "error: title was not changed in callback. exiting.\n"); tox_kill(t); return 1; }
static int r2tox_connect() { if (tox) { printf ("Status: Online\n"); print_tox_my_address (tox); return -1; } Tox *t = NULL; struct Tox_Options *options = tox_options_new(NULL); FILE *fd = fopen("tox.data", "rb"); if (fd) { eprintf ("Using tox.data\n"); size_t sz = fread (&data, 1, 4096, fd); fclose (fd); tox_options_set_savedata_length (options, sz); tox_options_set_savedata_type (options, TOX_SAVEDATA_TYPE_TOX_SAVE); tox_options_set_savedata_data (options, data, sz); t = tox_new (options, NULL); if (!t) { printf("cannot new\n"); return 1; } } else { t = tox_new (NULL, NULL); if (!t) { eprintf ("cannot new\n"); return 1; } // r2tox_save(); } const char *username = "******"; const char *status = "Available"; tox_self_set_name (t, username, strlen(username), NULL); tox_self_set_status_message (t, status, strlen(status), NULL); tox_callback_friend_name(t, handle_friend_name); tox_callback_friend_request (t, handle_friend_request); tox_callback_friend_message (t, handle_friend_message); tox_callback_friend_lossy_packet (t, handle_friend_lossy_packet); tox_callback_friend_lossless_packet (t, handle_friend_lossless_packet); tox_callback_friend_read_receipt (t, handle_friend_read_receipt); tox_callback_conference_invite(t, handle_conference_invite); tox_callback_conference_message(t, handle_conference_message); tox_callback_conference_title(t, handle_conference_title); // bootstrap size_t i; for (i = 0; i < sizeof(nodes)/sizeof(DHT_node); i ++) { sodium_hex2bin(nodes[i].key_bin, sizeof(nodes[i].key_bin), nodes[i].key_hex, sizeof(nodes[i].key_hex)-1, NULL, NULL, NULL); tox_bootstrap(t, nodes[i].ip, nodes[i].port, nodes[i].key_bin, NULL); } print_tox_my_address (t); tox_callback_self_connection_status (t, self_connection_status_cb); tox = t; // thread here if (!thread) { thread = r_th_new (r2tox_mainloop, NULL, 1); r_th_start (thread, true); } return 0; }
/** * @brief Initializes the core, must be called before anything else */ void Core::start(const QByteArray& savedata) { bool isNewProfile = profile.isNewProfile(); if (isNewProfile) { qDebug() << "Creating a new profile"; makeTox(QByteArray()); makeAv(); setStatusMessage(tr("Toxing on qTox")); setUsername(profile.getName()); } else { qDebug() << "Loading user profile"; if (savedata.isEmpty()) { emit failedToStart(); return; } makeTox(savedata); makeAv(); } qsrand(time(nullptr)); if (!tox) { ready = true; GUI::setEnabled(true); return; } // set GUI with user and statusmsg QString name = getUsername(); if (!name.isEmpty()) { emit usernameSet(name); } QString msg = getStatusMessage(); if (!msg.isEmpty()) { emit statusMessageSet(msg); } ToxId id = getSelfId(); // TODO: probably useless check, comes basically directly from toxcore if (id.isValid()) { emit idSet(id); } loadFriends(); tox_callback_friend_request(tox, onFriendRequest); tox_callback_friend_message(tox, onFriendMessage); tox_callback_friend_name(tox, onFriendNameChange); tox_callback_friend_typing(tox, onFriendTypingChange); tox_callback_friend_status_message(tox, onStatusMessageChanged); tox_callback_friend_status(tox, onUserStatusChanged); tox_callback_friend_connection_status(tox, onConnectionStatusChanged); tox_callback_friend_read_receipt(tox, onReadReceiptCallback); tox_callback_conference_invite(tox, onGroupInvite); tox_callback_conference_message(tox, onGroupMessage); tox_callback_conference_namelist_change(tox, onGroupNamelistChange); tox_callback_conference_title(tox, onGroupTitleChange); tox_callback_file_chunk_request(tox, CoreFile::onFileDataCallback); tox_callback_file_recv(tox, CoreFile::onFileReceiveCallback); tox_callback_file_recv_chunk(tox, CoreFile::onFileRecvChunkCallback); tox_callback_file_recv_control(tox, CoreFile::onFileControlCallback); QByteArray data = profile.loadAvatarData(getSelfPublicKey().toString()); if (data.isEmpty()) { qDebug() << "Self avatar not found, will broadcast empty avatar to friends"; } setAvatar(data); ready = true; if (isNewProfile) { profile.saveToxSave(); } if (isReady()) { GUI::setEnabled(true); } process(); // starts its own timer av->start(); }
/** * @brief Initializes the core, must be called before anything else */ void Core::start() { bool isNewProfile = profile.isNewProfile(); if (isNewProfile) { qDebug() << "Creating a new profile"; makeTox(QByteArray()); setStatusMessage(tr("Toxing on qTox")); setUsername(profile.getName()); } else { qDebug() << "Loading user profile"; QByteArray savedata = profile.loadToxSave(); if (savedata.isEmpty()) { emit failedToStart(); return; } makeTox(savedata); } qsrand(time(nullptr)); if (!tox) { ready = true; GUI::setEnabled(true); return; } // set GUI with user and statusmsg QString name = getUsername(); if (!name.isEmpty()) emit usernameSet(name); QString msg = getStatusMessage(); if (!msg.isEmpty()) emit statusMessageSet(msg); ToxId id = getSelfId(); if (id.isValid()) // TODO: probably useless check, comes basically directly from toxcore emit idSet(id); // TODO: This is a backwards compatibility check, // once most people have been upgraded away from the old HistoryKeeper, remove this if (Nexus::getProfile()->isEncrypted()) checkEncryptedHistory(); loadFriends(); tox_callback_friend_request(tox, onFriendRequest); tox_callback_friend_message(tox, onFriendMessage); tox_callback_friend_name(tox, onFriendNameChange); tox_callback_friend_typing(tox, onFriendTypingChange); tox_callback_friend_status_message(tox, onStatusMessageChanged); tox_callback_friend_status(tox, onUserStatusChanged); tox_callback_friend_connection_status(tox, onConnectionStatusChanged); tox_callback_friend_read_receipt(tox, onReadReceiptCallback); tox_callback_conference_invite(tox, onGroupInvite); tox_callback_conference_message(tox, onGroupMessage); tox_callback_conference_namelist_change(tox, onGroupNamelistChange); tox_callback_conference_title(tox, onGroupTitleChange); tox_callback_file_chunk_request(tox, CoreFile::onFileDataCallback); tox_callback_file_recv(tox, CoreFile::onFileReceiveCallback); tox_callback_file_recv_chunk(tox, CoreFile::onFileRecvChunkCallback); tox_callback_file_recv_control(tox, CoreFile::onFileControlCallback); QPixmap pic = profile.loadAvatar(); if (!pic.isNull() && !pic.size().isEmpty()) { QByteArray data; QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); pic.save(&buffer, "PNG"); buffer.close(); setAvatar(data); } else { qDebug() << "Self avatar not found, will broadcast empty avatar to friends"; setAvatar({}); } ready = true; if (isNewProfile) { profile.saveToxSave(); } if (isReady()) GUI::setEnabled(true); process(); // starts its own timer av->start(); }