Example #1
0
void clientMessageHandle(int client_sock,string message){
	vector<string> choppedString;
	stringChopper(message,choppedString);
	if (choppedString[0].compare("LIN") == 0){
		userLogin(client_sock,choppedString);
	}
	else if (choppedString[0].compare("LOU") == 0){
		userLogout(client_sock,choppedString);
	}
	else if (choppedString[0].compare("REG") == 0){
		userRegister(client_sock,choppedString);
	} 
	else if (choppedString[0].compare("MSG") == 0){
		sendMessage(client_sock,choppedString);
	}
	else if (choppedString[0].compare("CGR") == 0){
		createGroup(client_sock,choppedString);
	} 
	else if (choppedString[0].compare("JGR") == 0){
		joinGroup(client_sock,choppedString);
	}
	else if (choppedString[0].compare("LGR") == 0){
		leaveGroup(client_sock,choppedString);
	}
	else{
		errorReply(client_sock,"000","Protocol error!");
	}
}
Example #2
0
void userMenu(user *userList)
{
    int choose = 0;
    printf("==========================\n");
    printf("------ MENU USUÁRIO ------\n");
    printf("==========================\n");
    printf("[1]CADASTRO\n"); //Coloca novo usuário no fim da lista
    printf("[2]ALTERAR\n");  //Altera um usuário na lista
    printf("[3]CONSULTAR\n"); //Consulta um dado usuário na lista
    printf("[4]LISTAR\n");    //Lista todos os usuários da lista
    printf("[5]EXCLUIR\n");   //Exclui usuário da lista
    printf("[6]VOLTAR\n");
    scanf("%i", &choose);
    fflush(stdin);

    switch(choose)
    {
        case 1:
            userRegister(userList); break;
        case 2:
            userModify(userList); break;
        case 3:
            userSearch(userList); break;
        case 4:
            showList(userList); break;
        case 5:
            userDelete(userList); break;
        case 6:
            break;
        default:
            printf("OPÇÃO INVÁLIDA\n");
    }
}
Example #3
0
int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QMainWindow::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: hskBeginner(); break;
        case 1: hskIntermediate(); break;
        case 2: hskAdvanced(); break;
        case 3: userRegister(); break;
        case 4: about(); break;
        }
        _id -= 5;
    }
    return _id;
}
Example #4
0
/*
 * 结构 :  qint8(四种类型) + 数据
*/
void MyServer::slotReadData(QByteArray data)
{
    QDataStream out(&data,QIODevice::ReadOnly);
    out.setVersion(QDataStream::Qt_5_0);
    qint8 type;
    out>>type;
    data.remove(0,sizeof(qint8));                qDebug()<<"slotReadData = "<<type;
    if (type == queryType::login) {
        userLogin(data);
    }
    else if (type == queryType::registe) {
        userRegister(data);
    }
    else if (type == queryType::recommend) {
        userRecommend(data);
    }
    else if (type == queryType::groupsize) {
        DataFormat_login info = DataFormat::getGroupSize(data);
        QVector<groupInfo> groups = model.friendGroup(info.account);
        sendGroupSize(groups, clients[ hx[info.account] ]);
    }
    else if (type == queryType::friendGroup) {
        DataFormat_login info = DataFormat::getGroupSize(data);
        QVector<groupInfo> groups = model.friendGroup(info.account);
        sendFriendGroup(groups,clients[ hx[info.account] ]);
    }
    else if (type == queryType::addFriend) {
        userAddFriend(data);
    }
    else if (type == queryType::findPerson) {
        userFindPerson(data);
    }
    else if (type == queryType::chat) {
        userChat(data);
    }
    else if (type == queryType::offlineMes) {
        sendOfflineMes(data);
    }
    else if (type == queryType::history) {
        userHistoryChat(data);
    }
}
void GatewayTask::slotRegister(const XMPP::IQ& iq)
{
    QString tag = iq.childElement().tagName();
    QString ns = iq.childElement().namespaceURI();

    if ( tag == "query" && ns == NS_IQ_REGISTER && iq.type() == "get" ) {
        Registration form(d->reg);
        form.setTo(iq.from());
        form.setFrom(iq.to());
        form.setId(iq.id());
        form.setType(IQ::Result);

        d->stream->sendStanza(form);
        return;
    }
    if ( tag == "query" && ns == NS_IQ_REGISTER && iq.type() == "set" ) {
        Registration request(iq);

        if ( request.from().isEmpty() ) {
            Registration err = IQ::createReply(request);
            err.setError( Stanza::Error(Stanza::Error::UnexpectedRequest) );
            d->stream->sendStanza(err);
            return;
        }

        if ( request.hasField(Registration::Remove) ) {
            Registration reply = IQ::createReply(iq);
            reply.clearChild();
            reply.setType(IQ::Result);
            d->stream->sendStanza(reply);

            Presence removeSubscription;
            removeSubscription.setTo( iq.from().bare() );
            removeSubscription.setType(Presence::Unsubscribe);
            d->stream->sendStanza(removeSubscription);

            Presence removeAuth;
            removeAuth.setTo( iq.from().bare() );
            removeAuth.setType(Presence::Unsubscribed);
            d->stream->sendStanza(removeAuth);

            Presence logout;
            logout.setTo( iq.from() );
            logout.setType(Presence::Unavailable);
            d->stream->sendStanza(logout);

            emit userUnregister(iq.from());
            return;
        }

        if ( request.getField(Registration::Username).isEmpty() || request.getField(Registration::Password).isEmpty() ) {
            Registration err(request);
            err.swapFromTo();
            err.setError( Stanza::Error(Stanza::Error::NotAcceptable) );
            d->stream->sendStanza(err);
            return;
        }

        /* registration success */
        IQ reply = IQ::createReply(iq);
        reply.clearChild();
        d->stream->sendStanza(reply);

        /* subscribe for user presence */
        Presence subscribe;
        subscribe.setFrom(iq.to());
        subscribe.setTo( iq.from().bare() );
        subscribe.setType(Presence::Subscribe);
        d->stream->sendStanza(subscribe);

        emit userRegister( request.from(), request.getField(Registration::Username), request.getField(Registration::Password) );

        Presence presence;
        presence.setFrom(iq.to());
        presence.setTo( iq.from().bare() );
        d->stream->sendStanza(presence);

        /* execute log-in case */
        emit userLogIn(iq.from(), Presence::None);
        return;
    }
}
int main()
{
	consoleTitleSet("Hafrans Flex LMS Alpha");
	if (init())
	{
		printf("程序出现错误,正在退出...");
		Sleep(1500);
		return -255;
	}

#ifdef DEBUG
	currentPer = 9;
	currentUsr = "******";
	puts("/********************这是调试模式****************/");
#else
	while (currentUsr == NULL)
	{
		while (currentUsr == NULL)
		{
			char buf[__BUFFSIZE__] = { '\0' };
			loginPageViewer();
			printf("请输入选项: ");
			gets_s(buf, __BUFFSIZE__);
			if (strcmp(buf, "1") == 0)
			{
				userLogin();
			}
			else if (strcmp(buf, "2") == 0)
			{
				userRegister();
				flushUSER(0);
			}
			else if (strcmp(buf, "3") == 0)
			{
				printf("将要退出程序。。\n");
				Sleep(1500);
				puts("正在退出...");
				Sleep(1500);
				flushBOOK(0);
				flushUSER(0);
				return 0;

			}
		}
		mainLayoutViewer();
		consoleWaitinCMD();
	}
#endif
	/*bookDetails(head);
	Sleep(1520);
	userDetails(uhead);
	puts("已到达函数底");
	getchar();*/

#ifdef DEBUG
	/*
		程序设置文档请写在此处。
	*/
	pUSER *p = userSelect("2",1,1);
	currentBody = *p;
	puts("已到达程序底部");
	getchar();
#endif
	/*冲刷数据*/
	flushBOOK(0);
	flushUSER(0);
	//Sleep(1000);
	return 0;

}