Ejemplo n.º 1
0
/*
 *Exit
 */
void exit_client(packet *pkt, int fd) {
   packet ret;
   User *current;

   //Remove user from their current room and the active user's list
   current = get_user(&active_users_list, pkt->username, active_users_mutex);
   if(current != NULL) {
      //Send disconnect message to user room
      ret.options = current->roomID;
      strcpy(ret.realname, SERVER_NAME);
      strcpy(ret.username, SERVER_NAME);
      sprintf(ret.buf, "User %s has disconnected.", pkt->realname);
      ret.timestamp = time(NULL);
      send_message(&ret, -1);

      memset(&ret, 0, sizeof(packet));
      strcpy(ret.realname, SERVER_NAME);
      strcpy(ret.username, SERVER_NAME);
      ret.options = EXIT;
      strcat(ret.buf, "Goodbye!");
      ret.timestamp = time(NULL);
      printf("Sending close message to %d\n", fd);
      send(fd, &ret, sizeof(packet), MSG_NOSIGNAL);
      close(fd);

      Room *room = Rget_roomFID(&room_list, current->roomID, rooms_mutex);
      printf("got room\n");
      removeUser(&(room->user_list), current, room->user_list_mutex); 
      printf("removed user from current room\n");
      removeUser(&active_users_list, current, active_users_mutex);
      printf("removed user from active users\n");
   }
}
Ejemplo n.º 2
0
void XN_CALLBACK_TYPE UserTracker::User_LostUser(xn::UserGenerator& generator, XnUserID nId, void* pCookie)
{
    XnUInt32 epochTime = 0;
	xnOSGetEpochTime(&epochTime);
	printf("%d Lost user %d\n", epochTime, nId);
    removeUser(nId);
}
int main(int argc, char *argv[])
{
        // usage: ./updateGradersDatabase remote_user [add|remove] userid
        if (argc != 4) {
                return -1;
        }

        char *remote_user = argv[1];
        char *operation = argv[2];
        char *userid = argv[3];

        const char* env_remote_user = getenv("REMOTE_USER");
        if (strcmp(remote_user,env_remote_user) != 0){
                // not the right user
                printf("incorrect user\n");
                return -1;
        }

        // sanity check so we don't remove "graders:"
        if (strcmp("graders:",userid) == 0) {
                return -1;
        }

        if (strcmp("add",operation) == 0) {
                return addUser(userid);
        }
        else if (strcmp("remove",operation) == 0) {
                return removeUser(userid);
        }
}
Ejemplo n.º 4
0
void lmcMessaging::checkPendingMsg(void) {
	for(int index = 0; index < pendingList.count(); index++) {
		//	check if message has timed out
		if(pendingList[index].active && pendingList[index].timeStamp.msecsTo(QDateTime::currentDateTime()) > nTimeout) {
			if(pendingList[index].retry < nMaxRetry) {
				//	send the message once more
				pendingList[index].retry++;
				pendingList[index].timeStamp = QDateTime::currentDateTime();
				resendMessage(pendingList[index].type, pendingList[index].msgId, &pendingList[index].userId, &pendingList[index].xmlMessage);
			}
			else {
				XmlMessage statusMsg;
				//	max retries exceeded. mark message as failed.
				switch(pendingList[index].type) {
				case MT_Message:
					emit messageReceived(MT_Failed, &pendingList[index].userId, &pendingList[index].xmlMessage);
					break;
				case MT_Ping:
					statusMsg.addData(XN_STATUS, statusCode[ST_COUNT - 1]);
					emit messageReceived(MT_Status, &pendingList[index].userId, &statusMsg);
					emit messageReceived(MT_Depart, &pendingList[index].userId, NULL);
					removeUser(pendingList[index].userId);
					break;
                default:
                    break;
				}
				pendingList[index].active = false;
				pendingList.removeAt(index);
				index--;	//	since next item will have this index now
			}
		}
	}
}
Ejemplo n.º 5
0
NetworkServer::AutoPacket NetworkServer::receive()
{
	assert(isConnected());

	for (;;) {
		if (_queuedUser) {
			removeUser(_queuedUser);
			_queuedUser = 0;
		}

		Packet* raw = _peer->Receive();
		if (!raw) {
			return AutoPacket();
		}
		AutoDepacketer depacketer(*_peer, raw);

		AutoPacket packet(processPacket(*raw));
		if (packet.get()) {
			User *user = findUser(raw->systemAddress);
			if (!user) {
				packetHeader(std::cout, *raw);
				std::cout << "Packet from unknown user: " << int(packet->kind()) << std::endl;
				continue;
			}
			packet->read(raw, user);
			return packet;
		}
	}
}
Ejemplo n.º 6
0
void User::slotDisconnectUser()
{
    if (_isAuthorized)
        _serverUser->sendUserLeft(_nameUser);
    emit removeUser(this);
    this->deleteLater();
}
Ejemplo n.º 7
0
void DSRC_Signal_Interrupt(void) {
    removeUser(pid, &entry);
    signal(SIGINT, SIG_DFL);
    printf("\n\nPackets received = %llu\n", count);
    printf("Blank Poll = %llu\n", blank);
    printf("remoterx killed by kill signal\n");
    exit(0);
}
Ejemplo n.º 8
0
void UsersFrame::on(UserRemoved, const FavoriteUser& aUser) noexcept
{
	dcassert(!ClientManager::isShutdown());
	if (!ClientManager::isShutdown())
	{
		removeUser(aUser);
	}
}
Ejemplo n.º 9
0
    void removeListener (CameraDevice::Listener* listenerToRemove)
    {
        const ScopedLock sl (listenerLock);
        listeners.removeAllInstancesOf (listenerToRemove);

        if (listeners.size() == 0)
            removeUser();
    }
Ejemplo n.º 10
0
void IRCChannelWidget::updateGui()
{
    // show all messages on the screen
    _msgMtx.lock();
    while (!_msgsToShow.empty()) {
        showMessage(_msgsToShow.front());
        _msgsToShow.pop();
    }
    _msgMtx.unlock();

    // update user list
    _newUsrsMtx.lock();
    for (list<User>::iterator it = _newUsrs.begin(); it != _newUsrs.end(); ++it)
        addUser(*it);
    _newUsrs.clear();
    _newUsrsMtx.unlock();
    _leftUsrsMtx.lock();
    for (list<User>::iterator it = _leftUsrs.begin(); it != _leftUsrs.end(); ++it)
        removeUser(*it);
    _leftUsrs.clear();
    _leftUsrsMtx.unlock();



    QMessageBox msgBox;
    QString fileName;
    int ret;

    // statuswindow takes care of recv  files
    if (_client)
    {
        _fileReqsMtx.lock();
        // for each filerequest, show a dialog
        for (list<IRCClient::FileRecvReq>::iterator i = _fileReqs.begin(); i != _fileReqs.end(); ++i) {

            msgBox.setText("Receiving file from user");
            msgBox.setInformativeText("User " + QString::fromStdString((*i)._userName) + " is trying to send you the file: " + QString::fromStdString((*i)._fileName));
            msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
            msgBox.setDefaultButton(QMessageBox::Yes);
            ret = msgBox.exec();
            if (ret == QMessageBox::Yes)
            {
                fileName = QFileDialog::getSaveFileName(this, "save file");
                if (!fileName.isEmpty())
                {
                    (*i)._path = fileName.toStdString();
                    DCCWidget* dccWidget = new DCCWidget(this);
                    if (!fileName.isEmpty())
                        _client->recvFile(*i)->registerObserver(dccWidget);
                    dccWidget->show();
                }
            }

        }
        _fileReqsMtx.unlock();
    }
}
Ejemplo n.º 11
0
void sig_term(void) {
    //	int ret;
    removeUser(pid, &entry);
    signal(SIGINT, SIG_DFL);
    printf("\n\nPackets received = %llu\n", count);
    printf("Blank Poll = %llu\n", blank);
    printf("remoterx killed by kill signal\n");
    exit(0);
}
Ejemplo n.º 12
0
 void stopRecording()
 {
     if (isRecording)
     {
         removeFileCaptureFilter();
         removeUser();
         isRecording = false;
     }
 }
Ejemplo n.º 13
0
void UserModel::decrementTimeout()
{
    for(auto user: m_UserList) {
        user->decrementTimeout();
        if(!user->isAlive()) {
            removeUser(user->nickname());
        }
    }
}
Ejemplo n.º 14
0
void main()
{
	InitWinSock();
	primarySock = mksocket();
	sockaddr_in service;
	service.sin_family = AF_INET;
	service.sin_addr.s_addr = htonl(INADDR_ANY);
	service.sin_port = htons(SERVER_PORT);

	 if (bind( primarySock, (SOCKADDR*) &service, sizeof(service)) == SOCKET_ERROR) 
	 {
		printf("bind() failed.\n");
		closesocket(primarySock);
		return;
	  }

	 sockaddr_in sender;
	 int senderlen = sizeof(sender);
	 stMessage recvMessage;

	 cout <<"recving..."<<endl;
	 for(;;)
	 {
		 int iret = recvfrom(primarySock,(char*)&recvMessage,sizeof(stMessage),0,(SOCKADDR *)&sender,&senderlen);
		 if(iret < 0)
		 {
			 cout << "recv data error!"<<endl;
		 }else
		 {
			 int type = recvMessage.iMessageType;
			 switch(type)
			 {
			case LOGIN:
				clientLogin(&recvMessage,&sender);
				getUserList(sender);
				break;
			case LOGOUT:
				removeUser(recvMessage.message.loginoutMessage.stUserName);
				break;
			case GETUSERLIST:
				{
					stP2PMessage command;
					command.iMessageType = GETUSERLIST;
					sendto(primarySock,(const char *)&command,sizeof(stP2PMessage),0,(const SOCKADDR *)&sender,senderlen);
					getUserList(sender);
					break;
				}
			case P2PTRAN:
				P2PTran(recvMessage.message.translateMessage.stUserName,primarySock,sender);
				break;
			 }
		 }
	 }

	getchar();
}
Ejemplo n.º 15
0
void handle_PART(char ** params, int socket) {
  char *chanName = params[1];
  char *msg = params[10];
  char msgbuf[512];
  channel *chan;
  char *user;
  char *nick;
  struct ClientData *userstruct;
  
  //printf("msg: %s\n", msg);

  //search for user by socket
  printf("searching for user\n");
  pthread_mutex_lock(&listLock);
  userstruct = (struct ClientData *)list_seek(&clientList, &socket);
  pthread_mutex_unlock(&listLock);
  user = userstruct->user;
  nick = userstruct->nick;
  
  //search for channel by name
  printf("searching for channel\n");
  chan = (channel *) findChannel(chanName);
  
  //if channel doesn't exist
  if(chan == NULL){
    sprintf(msgbuf, ":%s 403 %s %s :No such channel\r\n", host, nick, chanName);
    sendMessage(msgbuf, socket);
    return;
  }

  //if user is not in channel
  printf("checking if user is in channel\n");
  if(isUserInChannel(socket, chan) == -1){
    sprintf(msgbuf, ":%s 442 %s %s :You're not on that channel\r\n", host, nick, chanName);
    sendMessage(msgbuf, socket);
    return;
  }

  //check if they have a parting message
  if(msg[0] == '\0'){
    //msg = nick;
    sprintf(msgbuf, ":%s!%s@hostname PART %s\r\n", nick, user, chanName);
    sendMessage(msgbuf, socket);
    messageAllUsers(msgbuf, chan, socket);
  } else {
    sprintf(msgbuf, ":%s!%s@hostname PART %s :%s\r\n", nick, user, chanName, msg);
    sendMessage(msgbuf, socket);
    messageAllUsers(msgbuf, chan, socket);
  }
  //do the deed
  printf("actually remvoing user\n");
  removeUser(socket, chan);
  
  return;
}
Ejemplo n.º 16
0
void IrcUserModelPrivate::promoteUser(IrcUser* user)
{
    Q_Q(IrcUserModel);
    if (sortMethod == Irc::SortByActivity) {
        const bool notify = false;
        removeUser(user, notify);
        insertUser(0, user, notify);
        if (updateTitles())
            emit q->titlesChanged(titles);
        emit q->usersChanged(userList);
    }
}
Ejemplo n.º 17
0
Gui_Admin::Gui_Admin(QWidget* parent): QWidget(parent), db(new LinkedDB){
    this->setWindowTitle("Welcome to LinQedIn Admin");
    this->resize(QDesktopWidget().availableGeometry(this).size() * 0.5);
    this->setFixedSize(this->size());

    QHBoxLayout* adminLayout = new QHBoxLayout();

    QVBoxLayout* firstCol = new QVBoxLayout();
    usersList = new QListWidget(this);
    for(std::list<SmartUser>::const_iterator it = db->begin(); it != db->end(); ++it) {
        QListWidgetItem* user = new QListWidgetItem(QString::fromStdString((*it)->account()->username().getLogin()));
        usersList->insertItem(usersList->count(),user);
    }
    usersList->setCurrentRow(0);
    usersList->setFixedHeight(this->height()/1.75);
    usersList->setFixedWidth(200);
    filterSearch = new QLineEdit();
    filterSearch->setPlaceholderText("filter users by username");
    filterSearch->setFixedWidth(200);
    connect(filterSearch, SIGNAL(textEdited(QString)), this, SLOT(filterUsers(QString)));
    firstCol->addSpacing(50);
    firstCol->addWidget(filterSearch, 0, Qt::AlignCenter);
    firstCol->addWidget(usersList,0, Qt::AlignCenter);
    firstCol->addSpacing(50);

    QVBoxLayout* secCol = new QVBoxLayout();
    QPushButton* adduserB = new QPushButton("add new user");
    adduserB->setFixedSize(160,30);
    connect(adduserB, SIGNAL(clicked()), this, SLOT(openAddUser()));
    QPushButton* removeuserB = new QPushButton("remove user");
    removeuserB->setFixedSize(160,30);
    connect(removeuserB, SIGNAL(clicked()), this, SLOT(removeUser()));
    QPushButton* changesubuserB = new QPushButton("change Subscription");
    changesubuserB->setFixedSize(160,30);
    connect(changesubuserB, SIGNAL(clicked()), this, SLOT(openChangeSubType()));
    QPushButton* logoutB = new QPushButton("Logout");
    logoutB->setFixedSize(160,30);
    connect(logoutB, SIGNAL(clicked()), this, SLOT(logout()));

    secCol->setSpacing(10);
    secCol->addSpacing(50);
    secCol->addWidget(adduserB,0, Qt::AlignLeft);
    secCol->addWidget(removeuserB,0, Qt::AlignLeft);
    secCol->addWidget(changesubuserB,0, Qt::AlignLeft);
    secCol->addWidget(logoutB, 0, Qt::AlignLeft);
    secCol->addSpacing(50);


    adminLayout->addLayout(firstCol);
    adminLayout->addLayout(secCol);
    setLayout(adminLayout);
}
Ejemplo n.º 18
0
/*接收到线程发出的连接断开信号后,在线程数组中查找该线程并移除*/
void Server::clientDisconnect(int descriptor)
{
    for (int i = 0; i < _threadList.count(); i++)
    {
        if(_threadList.at(i)->getDescriptor() == descriptor)
        {
            _threadList.at(i)->exit();
            _threadList.removeAt(i);
            emit removeUser(descriptor);
            return;
        }
    }
}
Ejemplo n.º 19
0
void PrivateChatChannel::excludePlayer(Player* player, Player* excludePlayer)
{
	if(player != excludePlayer && removeInvited(excludePlayer)){
		removeUser(excludePlayer);

		std::string msg;
		msg = excludePlayer->getName();
		msg += " has been excluded.";
		player->sendTextMessage(MSG_INFO_DESCR, msg.c_str());
		
		excludePlayer->sendClosePrivate(getId());
	}
}
Ejemplo n.º 20
0
void ChatChannel::connectAll()
{
  connect(_conn, SIGNAL(chatUsersRecv(QString,QMap<QString,shared_ptr<ChatUser> >)),
          this, SLOT(updateUsers(QString,QMap<QString,shared_ptr<ChatUser> >)));
  connect(_conn, SIGNAL(chatUserEnter(QString,shared_ptr<ChatUser>)),
          this, SLOT(insertUser(QString,shared_ptr<ChatUser>)));
  connect(_conn, SIGNAL(chatUserLeave(QString,QString)),
          this, SLOT(removeUser(QString,QString)));
  connect(this, SIGNAL(sendPublicReady(QString,QString)),
          _conn, SLOT(chatSendPublic(QString,QString)));
  connect(_conn, SIGNAL(chatPublicMessage(QString,QString,QString)),
          this, SLOT(publicMessageRecv(QString,QString,QString)));
}
Ejemplo n.º 21
0
void PrivateChatChannel::excludePlayer(const Player& player, Player& excludePlayer)
{
	if (!removeInvite(excludePlayer.getGUID())) {
		return;
	}

	removeUser(excludePlayer);

	std::ostringstream ss;
	ss << excludePlayer.getName() << " has been excluded.";
	player.sendTextMessage(MESSAGE_INFO_DESCR, ss.str());

	excludePlayer.sendClosePrivate(id);
}
Ejemplo n.º 22
0
void ChannelPage::kick(const IrcClient::User& sender, const QString& message, const QString& recipient)
{
    print(QString("*** %1 has kicked %2 (%3)")
          .arg(sender.nick)
          .arg(recipient)
          .arg(message)
          , Information
    );
    if (!Window::ircClient->getUs().nick.compare(recipient, Qt::CaseInsensitive)) {
        disable();
    } else {
        removeUser(recipient);
    }
}
Ejemplo n.º 23
0
void ChannelPage::part(const IrcClient::User &user)
{
    print(QString("*** %1 (%2@%3) has left the channel")
          .arg(user.nick)
          .arg(user.username)
          .arg(user.hostname)
          , Information
    );
    if (!Window::ircClient->getUs().nick.compare(user.nick, Qt::CaseInsensitive)) {
        disable();
    } else {
        removeUser(user.nick);
    }
}
Ejemplo n.º 24
0
void IrcUserModelPrivate::renameUser(IrcUser* user)
{
    Q_Q(IrcUserModel);
    if (updateUser(user) && sortMethod != Irc::SortByHand) {
        QList<IrcUser*> users = userList;
        const bool notify = false;
        removeUser(user, notify);
        insertUser(-1, user, notify);
        if (updateTitles())
            emit q->titlesChanged(titles);
        if (users != userList)
            emit q->usersChanged(userList);
    }
}
Ejemplo n.º 25
0
void MyClient::onDisconnect()
{
    qDebug() << "Client disconnected";
    //если авторизован
    if (_isAutched)
    {
        //убирием из интерфейса
        emit removeUserFromGui(_name);
        //сообщаем всем, что клиент вышел
        _serv->doSendToAllUserLeft(_name);
        //убираем из списка
        emit removeUser(this);
    }
    deleteLater();
}
Ejemplo n.º 26
0
void PrivateChatChannel::excludePlayer(const Player& player, Player& excludePlayer)
{
	if (removeInvited(excludePlayer)) {
		removeUser(excludePlayer);

		std::ostringstream ss;
		ss << excludePlayer.getName() << " has been excluded.";
		player.sendTextMessage(MSG_INFO_DESCR, ss.str());

		excludePlayer.sendClosePrivate(getId());

		for (const auto& it : users) {
			it.second->sendChannelEvent(id, excludePlayer.getName(), CHANNELEVENT_EXCLUDE);
		}
	}
}
Ejemplo n.º 27
0
UserSettings::UserSettings(QWidget *parent, Qt::WindowFlags f)
    : QDialog(parent, f)
{
    list_ = new QListWidget(this);

    /*list->setIconSize(QSize(60, 60));
    for (int i = (int)QStyle::SP_TitleBarMinButton; i < (int)QStyle::SP_MediaVolumeMuted; ++i)
    {
        QListWidgetItem *item = new QListWidgetItem(QApplication::style()->standardIcon((QStyle::StandardPixmap)i), QString::number(i), list);
    }*/

    /*QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal, this);
    QPushButton *okButton = buttonBox->addButton(QDialogButtonBox::Ok);
    connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));

    QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
    connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
    */

    addUserButton_ = new QPushButton(this);
    connect(addUserButton_, SIGNAL(clicked()), this, SLOT(addUser()));

    removeUserButton_ = new QPushButton(this);
    connect(removeUserButton_, SIGNAL(clicked()), this, SLOT(removeUser()));

    QHBoxLayout *buttonLayout = new QHBoxLayout(this);
    buttonLayout->addStretch();
    buttonLayout->addWidget(addUserButton_);
    buttonLayout->addWidget(removeUserButton_);
    QWidget *buttonWidget = new QWidget(this);
    buttonWidget->setLayout(buttonLayout);

    QVBoxLayout *mainLayout = new QVBoxLayout(this);
    mainLayout->addWidget(list_);
    mainLayout->addWidget(buttonWidget);
    //mainLayout->addWidget(buttonBox);

    setLayout(mainLayout);

    retranslateUi();

    // request users from database
    QTimer::singleShot(0, this, SLOT(requestUsers()));
}
Ejemplo n.º 28
0
void PrivateChatChannel::excludePlayer(Player* player, Player* excludePlayer)
{
	if(player == excludePlayer || !removeInvited(excludePlayer))
		return;

	std::string msg = excludePlayer->getName();
	msg += " has been excluded.";
	player->sendTextMessage(MSG_INFO_DESCR, msg.c_str());

	removeUser(excludePlayer);
	excludePlayer->sendClosePrivate(getId());

	Player* tmpPlayer = NULL;
	for(UsersMap::iterator cit = m_users.begin(); cit != m_users.end(); ++cit)
	{
		if((tmpPlayer = cit->second->getPlayer()))
			tmpPlayer->sendChannelEvent(m_id, excludePlayer->getName(), CHANNELEVENT_EXCLUDE);
	}
}
Ejemplo n.º 29
0
void AlbumInfoWidget::addUser(const QVariantMap &user)
{
    AlbumTaskWidget *task = m_container->getCurrTask();
    if (!task || user.isEmpty())
    {
        return;
    }

    //qDebug() << __FILE__ << __LINE__ << user;

    UserInfoWidget *widget = NULL;
    QListWidgetItem *item = NULL;
    int num = ui->usersListWidgets1->count();
    int uid = user["id"].toInt();
    QString base = tr(" 手机号码:%1").arg(user["telephone"].toString());
    QString info = tr("%1\t\t姓名:%2\t\t初始密码:%3").arg(base).arg(user["realname"].toString()).arg(user["initpassword"].toString());

    for (int i = 0; i < num; i++)
    {
        if ((item = ui->usersListWidgets1->item(i)) &&
            (widget = static_cast<UserInfoWidget *>(ui->usersListWidgets1->itemWidget(item))))
        {
            QString data = widget->getInfo();
            if (info == data)
            {
                item->setSelected(true);
                return;
            }
            else if (data.startsWith(base))
            {
                removeUser(i);
                break;
            }
        }
    }

    widget = new UserInfoWidget(ui->usersListWidgets1->count(), uid, info, *this);
    item = new QListWidgetItem(ui->usersListWidgets1);
    item->setSizeHint(widget->sizeHint());
    ui->usersListWidgets1->setItemWidget(item, widget);
}
Ejemplo n.º 30
0
OtherUserPage::OtherUserPage( QWidget *parent )
  : QWidget( parent )
{
  QGridLayout *layout = new QGridLayout( this, 2, 2, 11, 6 );

  mView = new OtherUserView( &mManager, this );
  layout->addMultiCellWidget( mView, 0, 0, 0, 1 );

  mAddButton = new QPushButton( i18n( "Add Account..." ), this );
  layout->addWidget( mAddButton, 1, 0 );

  mDeleteButton = new QPushButton( i18n( "Remove Account" ), this );
  mDeleteButton->setEnabled( false );
  layout->addWidget( mDeleteButton, 1, 1 );

  connect( mView, SIGNAL( selectionChanged() ), SLOT( selectionChanged() ) );
  connect( mAddButton, SIGNAL( clicked() ), SLOT( addUser() ) );
  connect( mDeleteButton, SIGNAL( clicked() ), SLOT( removeUser() ) );

  loadAllUsers();
}