Пример #1
0
static void init_tox()
{
  /* Init core */
  initMessenger();

  /* Callbacks */
  m_callback_friendrequest(on_request);
  m_callback_friendmessage(on_message);
  m_callback_namechange(on_nickchange);
  m_callback_statusmessage(on_statuschange);
}
Пример #2
0
static Messenger * init_tox()
{
  /* Init core */
  Messenger *m = initMessenger();

  /* Callbacks */
  m_callback_friendrequest(m, on_request, NULL);
  m_callback_friendmessage(m, on_message, NULL);
  m_callback_namechange(m, on_nickchange, NULL);
  m_callback_statusmessage(m, on_statuschange, NULL);
  m_callback_action(m, on_action, NULL);
#ifdef __linux__
  setname(m, (uint8_t*) "Cool guy", sizeof("Cool guy"));
#elif WIN32
  setname(m, (uint8_t*) "I should install GNU/Linux", sizeof("I should install GNU/Linux"));
#else
  setname(m, (uint8_t*) "Hipster", sizeof("Hipster"));
#endif
  return m;
}
Пример #3
0
static Messenger *init_tox()
{
    /* Init core */
    Messenger *m = initMessenger();

    /* Callbacks */
    m_callback_friendrequest(m, on_request, NULL);
    m_callback_friendmessage(m, on_message, NULL);
    m_callback_namechange(m, on_nickchange, NULL);
    m_callback_statusmessage(m, on_statuschange, NULL);
    m_callback_action(m, on_action, NULL);
#ifdef __linux__
    setname(m, (uint8_t *) "Cool guy", sizeof("Cool guy"));
#elif defined(WIN32)
    setname(m, (uint8_t *) "I should install GNU/Linux", sizeof("I should install GNU/Linux"));
#elif defined(__APPLE__)
    setname(m, (uint8_t *) "Hipster", sizeof("Hipster")); //This used to users of other Unixes are hipsters
#else
    setname(m, (uint8_t *) "Registered Minix user #4", sizeof("Registered Minix user #4"));
#endif
    return m;
}
Пример #4
0
int main(int argc, char *argv[])
{
    int on = 0;
    int c = 0;
    int i = 0;
    char *filename = "data";
    char idstring[200] = {0};

    if (argc < 4) {
        printf("[!] Usage: %s [IP] [port] [public_key] <keyfile>\n", argv[0]);
        exit(0);
    }

    for(i = 0; i < argc; i++) {
      if (argv[i] == NULL){
        break;
      } else if(argv[i][0] == '-') {
            if(argv[i][1] == 'h') {
                print_help();
                exit(0);
            } else if(argv[i][1] == 'f') {
                if(argv[i + 1] != NULL)
                    filename = argv[i + 1];
                else {
                    fputs("[!] you passed '-f' without giving an argument!\n", stderr);
                }
            }
        }
    }

    initMessenger();
    load_key(filename);

    m_callback_friendrequest(print_request);
    m_callback_friendmessage(print_message);
    m_callback_namechange(print_nickchange);
    m_callback_statusmessage(print_statuschange);

    initscr();
    noecho();
    raw();
    getmaxyx(stdscr, y, x);

    new_lines("/h for list of commands");
    get_id(idstring);
    new_lines(idstring);
    strcpy(line, "");

    IP_Port bootstrap_ip_port;
    bootstrap_ip_port.port = htons(atoi(argv[2]));
    int resolved_address = resolve_addr(argv[1]);
    if (resolved_address != 0)
        bootstrap_ip_port.ip.i = resolved_address;
    else
        exit(1);

    unsigned char *binary_string = hex_string_to_bin(argv[3]);
    DHT_bootstrap(bootstrap_ip_port, binary_string);
    free(binary_string);
    nodelay(stdscr, TRUE);
    while(true) {
        if (on == 0 && DHT_isconnected()) {
            new_lines("[i] connected to DHT\n[i] define username with /n");
            on = 1;
        }

        doMessenger();
        c_sleep(1);
        do_refresh();

        c = getch();
        if (c == ERR || c == 27)
            continue;

        getmaxyx(stdscr, y, x);
        if (c == '\n') {
            line_eval(line);
            strcpy(line, "");
        } else if (c == 8 || c == 127) {
            line[strlen(line)-1] = '\0';
        } else if (isalnum(c) || ispunct(c) || c == ' ') {
            strcpy(line, appender(line, (char) c));
        }
    }
    endwin();
    return 0;
}
Пример #5
0
/* Set the callback for status message changes.
 *  function(int friendnumber, uint8_t *newstatus, uint16_t length)
 *  You are not responsible for freeing newstatus.
 */
void tox_callback_statusmessage(void *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *),
                                void *userdata)
{
    Messenger *m = tox;
    m_callback_statusmessage(m, function, userdata);
}
Пример #6
0
/* Set the callback for status message changes.
 *  function(int friendnumber, size_t *newstatus, size_t length)
 *  You are not responsible for freeing newstatus.
 */
void tox_callback_status_message(Tox *tox, void (*function)(Messenger *tox, int, size_t *, size_t, void *),
                                 void *userdata)
{
    Messenger *m = tox;
    m_callback_statusmessage(m, function, userdata);
}