Example #1
0
void serve_mouse_event(int x, int y) {
    if (click_room(x, y)) {
        // roomnames.target = get_clicked_roomname(x);
        // update_roomname_win();
        get_online();
        // query_history();
        // query_members();
        // update_chatroom();
    } else if (click_filepath(x, y)) {
        focus_on_target(filepath);
    } else if (click_upload(x, y)) {
        upload_file();
        reset_input();
    } else if (click_inputbox(x, y)) {
        focus_on_target(inputbox);
    } else if (user->download->exist_file) {
        if (click_download(x, y)) {
            wclear(room.console);
            waddstr(room.console, "downloading file...");
            wrefresh(room.console);
            user->download->exist_file = 0;

            init_download();
        } else if (click_cancel(x, y)) {
            wclear(room.console);
            wrefresh(room.console);
            user->download->exist_file = 0;
        }
    }
}
Example #2
0
int getnewutmpent(struct user_info *up)
{
	int utmpfd, ucachefd;
	struct user_info *uentp;
	int i;

	resolve_utmp();
	if (resolve_ucache() == -1)
		return -1;

	utmpfd=utmp_lock();
	if (utmpfd == -1) {
		return -1;
	}

	if (utmpshm->max_login_num < get_online())
		utmpshm->max_login_num = get_online();
	for (i = 0; i < USHM_SIZE; i++) {
		uentp = &(utmpshm->uinfo[i]);
		if (!uentp->active || !uentp->pid)
			break;
	}
	if (i >= USHM_SIZE) {
		utmp_unlock(utmpfd);
		return -2;
	}
	utmpshm->uinfo[i] = *up;
	utmpshm->total_num++;

	utmp_unlock(utmpfd);

	ucachefd=ucache_lock();
	uidshm->status[up->uid-1]++;
	ucache_unlock(ucachefd);

	return i + 1;
}
Example #3
0
int main(int argc, char *argv[]) {

    if (argc != 2) {
        fprintf(stderr, "usage: %s [ip]\n", argv[0]);
        exit(1);
    }

    init_user();
    init_connection(argv[1]);
    signup_signin();

    init_curses();
    init_windows_attr();
    init_windows();
     
    // catch response from server
    pthread_t response_thd;
    if(pthread_create(&response_thd, NULL, response_handler, (void *)0))
        ERR_EXIT("Create response thread failed");

    get_online();

    while (1) {
        int c = wgetch(target->win);
        switch(c) {
            case '\t':
                target->text[target->len] = '\0';
                strcat(target->text, "    ");
                target->len += 4;
                target->y += 4;
                break;
            case KEY_BACKSPACE:
                if (target->y != 0) {
                    target->len--;
                    if (target->offset == 0)
                        mvwaddch(target->win, target->x,--target->y,' ');
                    else {
                        int i;
                        for (i = target->len + target->offset; i < target->len; i++) {
                            target->text[i] = target->text[i + 1];
                            mvwaddch(target->win, target->x, i, target->text[i]);
                        }
                        mvwaddch(target->win, target->x, i,' ');
                        target->y--;
                    }
                    wrefresh(target->win);
                }
                break;
            case 27: //esc
                close_client();
            case KEY_MOUSE:
                // waddstr(target->win, "clicked");
                if(getmouse(&event) == OK)
                    serve_mouse_event(event.y, event.x);
                break;
            case 13: //enter
                target->text[target->len] = '\0';
                if (strcmp(target->type, COMMENT) == 0) {
                    send_cmt();
                } else {
                    upload_file();
                }
                reset_input();
                break;
            case KEY_DOWN:
                break;
            case KEY_UP:
                break;
            case KEY_LEFT:
                if (target->len != 0) {
                    target->y--;
                    target->offset--;
                }
                break;
            case KEY_RIGHT:
                if (target->offset != 0) {
                    target->y++;
                    target->offset++;
                }
                break;
            default:
                mvwaddch(target->win, target->x, target->y, c);
                if (target->offset == 0) {
                    target->text[target->len++] = c;
                } else {
                    int i;
                    for (i = target->len; i > target->len + target->offset; i--)
                        target->text[i] = target->text[i - 1];
                    target->text[i] = c;
                    target->len++;
                    while (i++ < target->len - 1)
                        mvwaddch(target->win, target->x, i, target->text[i]);
                }
                wrefresh(target->win);
                // wprintw(target->win, "%d", c);
                target->y++;
                break;
        }
        wmove(target->win, target->x, target->y);
        wrefresh(target->win);
    }
    close_client();
}