Example #1
0
int main() {
    startup();
    updateUsers();
    loadSettings();
    while(!vars::accepted) {
        getmaxyx(stdscr, vars::maxY, vars::maxX);
        erase();
        firstNotice();
        if(!vars::running)
            break;
        refresh();
    }
    vars::noticeText.scroll = 0;
    while(vars::running) {//Main loop
        updateColors();
        updateUsers();
        if((vars::userList.at(vars::yourself).stat == 0) || ((!vars::chatting) && (!vars::banning)) || ((vars::about) && (!vars::settingsChangingDescription) && (!vars::settingsChangingNickname)))
            curs_set(0);
        else
            curs_set(1);
        getmaxyx(stdscr, vars::maxY, vars::maxX);
        erase();
        if((vars::maxX < 80) || (vars::maxY < 20)) {
            printw("The console window size is too small.\nPlease resize it to at least 80 * 20 width and height respectively.\nPress [Esc] or [Ctrl]+[C] to quit if resizing is not possible.");
            if(getch() == 27)
                vars::running = false;
        }
        else {
            printMainframe();
            if(vars::about)
                about();
            else {
                if(vars::menu == 0) {
                    notifications();
                    askUser();
                }
                else if(vars::menu == 1)
                    chatFrame();
            }
		}

        if((vars::previousState != 4) && (vars::previousState != vars::userList.at(vars::yourself).stat)) { //Check if your user stat changed
            curs_set(0);
            unsigned char thisState = vars::userList.at(vars::yourself).stat;
            if((vars::previousState > 0) && (thisState == 0)) {
                broadcast(std::vector < std::string >(1, "You have been banned!"), 6);
                vars::input.clear();
                vars::chattingWith.clear();
                vars::yourStr.clear();
                vars::menu = 0;
                vars::chatting = true;
                vars::chatScroll = -1;
                flushinp();
            }
            else if((vars::previousState == 0) && (thisState == 1))
                broadcast(std::vector < std::string >(1, "You have been unbanned!"), 8);
            else if((vars::previousState == 2) && (thisState == 1))
                broadcast(std::vector < std::string >(1, "You have been demoted!"), 6);
            else if((vars::previousState < 2) && (thisState == 2))
                broadcast(std::vector < std::string >(1, "You have been promoted to moderator!"), 8);
            broadcastWait(10);
        }
        else if(vars::broadcast.size() > 0) { //Or just draw a broadcast to the screen if there is one being sent.
            curs_set(0);
            broadcast(vars::broadcast, 6);
            vars::broadcast.clear();
            broadcastWait(10);
        }
        else {
            parseInput();
            refresh();
        }
        vars::previousState = vars::userList.at(vars::yourself).stat;
    }
    endwin();
    return 0;
}
Example #2
0
int chat(int argc,char* argv[],char* usr,char* str) 
{
// ciclo para definir el puerto, nombre, ip del contacto con el que se desea comunicar
    memset(nom, 0, 8);
    memset(ip, 0, 13);
    memset(puerto, 0, 7);
    int bandera = 0;
    int largo = strlen(str);
    int i,y; y=0;
    for(i=0;(i<largo)&&(bandera==0);i++)
    {
        if(str[i]!=';')
        {
            nom[y]= str[i];
            y++;
        }
        else
        {
            if(strcmp(nom,usr)== 0)
            {
                i++;y=0;
                for(;i<largo;i++)
                {
                    if(str[i]!=';')
                    {
                        ip[y] = str[i];
                        y++;
                    }
                    else
                    {
                        i++;y=0;
                        for(;str[i]!=';';i++)
                        {
                            puerto[y] = str[i];
                            y++;
                            
                        }
                        bandera=1;
                        break;
                    }
                }
            }
            else
            {
                memset(nom, 0, 8);
                memset(ip, 0, 13);
                memset(puerto, 0, 7);
                for(;i<largo;i++)
                {
                    if(isalpha(str[i])){
                        i--;y=0;
                        break;
                    }
                }
            }
        }
    }
//creacion del frame principal sobre el que se va a encontrar la ventana para enviar mensajes
    GtkWidget *window;
    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), usr);
    gtk_window_set_default_size(GTK_WINDOW(window), 800, 600);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_container_add(GTK_CONTAINER(window), chatFrame());
    gtk_widget_show_all(window);
    gtk_window_set_resizable(GTK_WINDOW(window),FALSE);
    g_signal_connect (G_OBJECT (window), "destroy",G_CALLBACK(gtk_main_quit), NULL);
    g_signal_connect (G_OBJECT(boton), "clicked",G_CALLBACK(enviado), G_OBJECT(textEntry));
    gtk_main();
    return 0;
}