Beispiel #1
0
QString title(const Chat& chat)
{
	if (!chat.display().isEmpty())
		return chat.display();
	else
		return chat.name();
}
TalkableFilter::FilterResult HideContactChatsTalkableFilter::filterChat(const Chat &chat)
{
    if (chat.type() == "Contact" || chat.type() == "Simple")
        return Rejected;
    else
        return Undecided;
}
Beispiel #3
0
/*
The worker thread.
Interacts with each client, providing necessary services
*/
void userInteraction(int id, int sock)
{
	NetAddr src;
	NetMessage msg;
	string answer;
	User user;
	NetReceiver receiver;
	char header;

	//creating receiver object
	receiver = NetReceiver(sock);

	//registering user
	user = registerUser(receiver);
	header = netToHostHeader(msg.getContent());
	if(header == USER_EXISTS_ERR || header == INVALID_REQUEST_ERR)
		answer = hostToNetMsg(header);
	else
		answer = hostToNetMsg(OK);
	if(send(sock, answer) < 0)
		error("send");	

	//main loop
	if(answer == hostToNetMsg(OK))
	{
		while(true)
		{
			//receiving message from client
			msg = receiver.recv();
			if(msg.getErrCode() < 0)
				error("recv");	
			if(msg.getErrCode() == 0)
				break;

			//displaying message
			src = msg.getSrcAddr();
			//cout << "[" << id << "]"
			//	<< "[" << src.getIp() << ":" << src.getPort() << "]"
			//	<< " " << msg.getContent() << endl;

			//handling request
			if(handle(sock, msg.getContent(), user) < 0)
				break;
		}	

		//unregistering user
		chat_mtx.lock();
		chat.delUserFromGroup(user.getName(), ONLINE_GROUP);
		chat.addUserToGroup(user.getName(), OFFLINE_GROUP);
		chat_mtx.unlock();
	}

	cout << "[" << id << "] connection ended." << endl;	

	close(sock);
	//marking itself as free at the end
	free_thread_mtx.lock();
	free_thread[id] = true;
	free_thread_mtx.unlock();
}
Beispiel #4
0
int main(int argc, char *argv[])
{
	QApplication a(argc, argv);
	Chat w;
	w.show();
	return a.exec();
}
Beispiel #5
0
void jezibaba::on_label_clicked()
{
    //qDebug() << "serepes\n";
    Chat *chat = new Chat();
    chat->showFullScreen();
    connect(chat, SIGNAL(closing()), this, SLOT(showFullScreen()));
}
Beispiel #6
0
void MainWindow::ricevi() //Ricevo una risposta dal server in merito all'esistenza o meno dell'utente.
{
   Chat* w;

   qint64 bytes = buffermain->write(sockmain->readAll()); //Per leggere i messaggi dal server.
       buffermain->seek(buffermain->pos() - bytes);
       while (buffermain->canReadLine())
               {
                       QString line = buffermain->readLine();
                       if(line.startsWith("#"))
                       {
                           if(line.compare("#true\n")==0)
                           {
                               w = new Chat();
                               w->nomeUtente(this->ui->lineEdit->text());
                               w->chatRoom(this->ui->txtChatRoom->text());
                               w->show();
                               this->close();
                               sockmain->disconnectFromHost();
                           }
                           else
                           {
                              this->ui->lineEdit->setText("Non esisti");
                           }
                       }
               }
}
bool MessagesChatFull::fetch(InboundPkt *in) {
    LQTG_FETCH_LOG;
    int x = in->fetchInt();
    switch(x) {
    case typeMessagesChatFull: {
        m_fullChat.fetch(in);
        if(in->fetchInt() != (qint32)CoreTypes::typeVector) return false;
        qint32 m_chats_length = in->fetchInt();
        m_chats.clear();
        for (qint32 i = 0; i < m_chats_length; i++) {
            Chat type;
            type.fetch(in);
            m_chats.append(type);
        }
        if(in->fetchInt() != (qint32)CoreTypes::typeVector) return false;
        qint32 m_users_length = in->fetchInt();
        m_users.clear();
        for (qint32 i = 0; i < m_users_length; i++) {
            User type;
            type.fetch(in);
            m_users.append(type);
        }
        m_classType = static_cast<MessagesChatFullType>(x);
        return true;
    }
        break;
    
    default:
        LQTG_FETCH_ASSERT;
        return false;
    }
}
Beispiel #8
0
Jid JabberResourceService::bestChatJid(const Chat &chat) const
{
    if (!chat)
        return Jid{};

    auto chatType = m_chatTypeManager->chatType(chat.type());
    if (!chatType)
        return Jid{};

    if (chatType->name() == "Contact")
    {
        Q_ASSERT(1 == chat.contacts().size());
        return bestContactJid(chat.contacts().toContact());
    }

    if (chatType->name() == "Room")
    {
        auto details = qobject_cast<ChatDetailsRoom *>(chat.details());
        Q_ASSERT(details);

        return Jid::parse(details->room());
    }

    return Jid{};
}
Beispiel #9
0
void TabsManager::load()
{
    if (!isValidStorage())
        return;

    StorableObject::load();

    QDomElement itemsNode = storage()->point();
    if (itemsNode.isNull())
        return;

    QVector<QDomElement> itemElements = storage()->storage()->getNodes(itemsNode, "Tab");
    foreach (const QDomElement &element, itemElements)
    {
        QUuid chatId(element.attribute("chat"));

        if (chatId.isNull())
            continue;

        Chat chat = m_chatManager->byUuid(chatId);
        if (!chat)
            continue;

        if (element.attribute("type") == "detachedChat")
            chat.addProperty("tabs:detached", true, CustomProperties::Storable);
        else if (element.attribute("type") == "tab")
            chat.addProperty("tabs:attached", true, CustomProperties::Storable);

        m_chatWidgetManager->openChat(chat, OpenChatActivation::DoNotActivate);
    }
Beispiel #10
0
ChatChannel::~ChatChannel()
{
	setActive(false);
	Chat *chat = static_cast<Chat*>(Chat::instance());
	if (chat && chat->activeSession() == this)
        chat->setActiveSession(0);
}
void MLogin::dispatchLoginCallbacks(float delta)
{

    //CCDirector::sharedDirector()->getScheduler()->pauseTarget(this);
    Director::getInstance()->getScheduler()->pauseTarget(this);
    //CCScene* pScene = CCScene::create();
    Scene *pScene = Scene::create();
    Chat* pLayer = new Chat();
//    pLayer->setChannel(channel);
//    pLayer->setUser(username);
//    pLayer->setClient(pomelo_client);
//    pLayer->setUserQueue(userQueue);
//    pLayer->setMessageQueue(messageQueue);

    CCLOG("init player");
    if(pLayer && pLayer->init()) {
        //pLayer->autorelease();
        pScene->addChild(pLayer);
        CCLOG("director replaceScene");
        Director::getInstance()->replaceScene(TransitionFade::create(1, pScene));
        //CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(1, pScene));
    } else {
        delete pLayer;
        pLayer = NULL;
    }
}
Beispiel #12
0
	void onChat(const std::string &strMessage)
	{
		if (!isServerPacket())
			return;

		printf("[CHAT] %s\n", strMessage.c_str());


		std::string sHaystack = "\xC2§c* First player who types '\xC2§4";
		if (strMessage.length() > sHaystack.length() && strMessage.substr(0, sHaystack.length()) == sHaystack)
		{
			std::string sChallenge = strMessage.substr(sHaystack.length());
			std::string::size_type iIndex = sChallenge.find("\xC2§c'");
			if (iIndex != std::string::npos)
			{
				sChallenge = sChallenge.substr(0, iIndex);

				printf("CHALLENGE: '%s'\n", sChallenge.c_str());

				PacketWriter w;
	                        Chat pack;
	                        pack.writePacket(&w, sChallenge);
	                        w.send(this);
			}
		}
	}
Beispiel #13
0
/*
The worker thread.
Interacts with each client, providing necessary services
*/
void userInteraction(int id, int sock, NetAddr src)
{
	NetMessage msg;
	string answer = OK;
	//string answer;
	User user;

	//registering user
	/*user = registerUser(sock);
	if(user.getName() == USER_EXISTS_ERR || user.getName() == INVALID_CMD_ERR)
		answer = user.getName();
	else
		answer = OK;
	if(send(sock, answer) < 0)
		error("send");	*/

	//main loop
	if(answer == OK)
	{
		while(true)
		{
			//receiving message from client
			msg = recvFrom(sock);
			if(msg.getErrCode() < 0)
				error("recv");	
			if(msg.getErrCode() == 0)
				break;
			cout << "boss" << endl;

			//displaying message
			cout << "[" << id << "]"
				<< "[" << src.getIp() << ":" << src.getPort() << "]"
				<< " " << msg.getContent() << endl;

			if(sendTo(sock, msg.getSrcAddr(), msg.getContent()) < 0)
				error("sendTo");
			if(sendTo(sock, msg.getSrcAddr(), "ey b0ss") < 0)
				error("sendTo");
			if(sendTo(sock, msg.getSrcAddr(), "edjfh") < 0)
				error("sendTo");
			//handling request
			//handle(sock, msg.getContent(), user);
		}	

		//unregistering user
		chat_mtx.lock();
		chat.delUserFromGroup(user.getName(), ONLINE_GROUP);
		chat.addUserToGroup(user.getName(), OFFLINE_GROUP);
		chat_mtx.unlock();
	}

	cout << "[" << id << "] connection ended." << endl;	

	close(sock);
	//marking itself as free at the end
	free_thread_mtx.lock();
	free_thread[id] = true;
	free_thread_mtx.unlock();
}
Beispiel #14
0
bool RecentChatService::isRecent(Chat chat) const
{
    if (!chat.hasProperty(LAST_MESSAGE_DATE_TIME_PROPERTY))
        return false;

    auto dateTime = chat.property(LAST_MESSAGE_DATE_TIME_PROPERTY, QDateTime{}).toDateTime();
    return isRecent(dateTime);
}
Beispiel #15
0
// properties.at(0): Login
// properties.at(1): Id
// properties.at(2): Ip
// properties.at(3): Promo
// properties.at(4): State
// properties.at(5): Location
// properties.at(6): Comment
void    QNetsoul::showConversation(const QStringList& properties,
                                   const QString& message)
{
  bool ok;
  const int id = properties.at(1).toInt(&ok);
  if (ok == false)
    qFatal("[QNetsoul::showConversation] Invalid id (%d)", id);

  Chat* window = getChat(id);
  const bool userEvent = message.isEmpty();

  if (NULL == window)
    {
      // DEBUG focus
      //qDebug() << "CASE 1";
      window = createWindowChat(id, properties.at(0), properties.at(5));
      window->show();
    }
  if (false == window->isVisible())
    {
      // DEBUG focus
      //qDebug() << "CASE 2";
      //window->outputTextBrowser->clear();
      //window->inputTextEdit->clear();
      if (userEvent)
        {
          window->show();
          window->activateWindow();
          QApplication::setActiveWindow(window);
          window->inputTextEdit->setFocus();
        }
      else window->showMinimized();
    }
  else
    {
      // DEBUG focus
      //qDebug() << "CASE 3";
      if (userEvent)
        {
          window->showNormal();
          window->activateWindow();
          QApplication::setActiveWindow(window);
          window->inputTextEdit->setFocus();
        }
    }
  if (message.isEmpty() == false)
    {
      if (window)
        {
          window->insertMessage(properties.at(0), message, QColor(204, 0, 0));
          window->autoReply(statusComboBox->currentIndex());
          QApplication::alert(window);
        }
      if (this->_trayIcon && this->_options->chatWidget->notifyMsg())
        this->_trayIcon->showMessage(properties.at(0), tr(" is talking to you."));
    }
}
Beispiel #16
0
void MessageWind::DoubleClicked(QTreeWidgetItem *item, int row)
{
    if(item->parent()==NULL)      //顶级节点,不做任何响应
    {
        return;
    }
    for(int i=0;i<childBlinkItems.count();i++)  //删除对应联系人的闪烁
    {
        if(item==childBlinkItems[i]->getitem())
        {
            Blink *temp=childBlinkItems[i];
            childBlinkItems.removeAt(i);
            delete temp;
            i--;          //因为删除后,余下闪烁项目的未知会改变,所以要-1
        }
    }
    Contact contact=texttocontact(item->whatsThis(0)); //提取联系人信息
    Chat *chat;
    if(chatdialogexist(contact,&chat)) //存在联系人的聊天窗口
    {
        chat->activateWindow();        //将窗口激活
    }
    else               //不存在联系人的聊天窗口
    {
        chat=new Chat(contact); //则打开此联系人的新的聊天窗口
        if(chat!=NULL)
        {
            connect(chat,SIGNAL(have_chat_dialog_closed()),this,SLOT(havechatdialogclosed()));
            chats.append(chat);
        }
    }
    for(int i=0;i<unreadsms.count();i++) //若有此联系人的未读信息,则将这些未读信息显示在聊天窗口中,并将这些信息移到收件箱或者垃圾箱
    {
        QString number=chat->getcontact().number;

        if(unreadsms[i].number==number)
        {
            Message temp;
            temp=unreadsms[i];
            unreadsms.removeAt(i);
            i--;
            chat->addnewmessage(numberToName(number),temp);
            if(temp.now==2)  //来自黑名单,放入垃圾箱
            {
                temp.now=temp.from=2;
                allMessages.prepend(temp);
            }
            else
            {
                temp.now=temp.from=1;       //否则放入收件箱
                allMessages.prepend(temp);
            }
        }
    }
    update();   //刷新界面
}
Beispiel #17
0
int main()
{
	//creating first groups
	chat.addGroup(ONLINE_GROUP);
	chat.addGroup(OFFLINE_GROUP);

	serverLoop();

	return 0;
}
  // EventController isn't derived from a QObject, this function
  // is called by Scene2D, not the Qt stack.
  void EventController::keyPressEvent(QKeyEvent* event){
    if(event->key() == Qt::Key_Escape){
      if(d_->getScene()->main_view()->link_creator()->active()){
        d_->getScene()->main_view()->link_creator()->clear();
        return;
      }
      d_->app->quit();
      return;
    }

    key_queue_ += event->text().toStdString();

    if(recording_keys_)
      return;

    // Is the user framed on a node?
    // if d_->chat_controller()->reframing()
    if(d_->chat_controller()->last_selected()){
      key_queue_.clear();
      key_queue_ += event->text().toStdString();

      Tete* framed_node = d_->chat_controller()->last_selected();
      GridsID node_id = framed_node->id();
      GridsID chat_id = framed_node->chat_id();

      recording_keys_ = true;

      GridsID new_node_id = Tete::requestCreate(d_, node_id, chat_id,
                                                "", Vec3D() );
      Link::requestCreate(d_, new_node_id, node_id);

    } // We are not framed on a node and not in a chat
    else {
      // rock my world
      key_queue_.clear();
      key_queue_ += event->text().toStdString();

      GridsID chat_id = d_->chat_controller()->default_chat_id();
      GridsID parent_id;

      Chat* chat = d_->chat_controller()->getChatFromID(chat_id);
      if(chat != NULL){
        if(!chat->tetes().empty()){
          parent_id = chat->tetes().back()->id();
        }
      }

      recording_keys_ = true;

      GridsID new_node_id = Tete::requestCreate(d_, parent_id, chat_id,
                                                "", Vec3D() );
    }

	}
void KaduExtInfo::showChatExtInfo()
{
    kdebugf();
    Chat *chat = getCurrentChat();
#if defined(KADU_0_4_x)
    showExtInfo(userlist.byUinValue(*(chat->uins().begin())).altNick());
#elif defined(KADU_0_5_0)
    UserListElements s = chat->users()->toUserListElements();
    showExtInfo(s[0].altNick());
#endif
    kdebugf2();
}
Beispiel #20
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    Chat d;
    QObject::connect(&d, SIGNAL(accepted()), &app, SLOT(quit()));

    d.show();

    app.exec();

    return 0;
}
bool HistoryChatsModelProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
	// chats?
	Chat *leftChat = left.data(ChatRole).value<Chat *>();
	Chat *rightChat = right.data(ChatRole).value<Chat *>();

	if (leftChat && rightChat)
		return compareNames(leftChat->name(), rightChat->name()) < 0;

	ChatType leftType = left.data(ChatTypeRole).value<ChatType>();
	ChatType rightType = right.data(ChatTypeRole).value<ChatType>();

	return compareNames(leftType.displayName(), rightType.displayName()) < 0;
}
Beispiel #22
0
void IOGuild::frag(Player* player, uint64_t deathId, const DeathList& list)
{
	Database* db = Database::getInstance();
	War_t war;

	std::stringstream s;
	for(DeathList::const_iterator it = list.begin(); it != list.end(); )
	{
		if(it->isLast())
			war = it->getWar();

		Creature* creature = it->getKillerCreature();
		if(it != list.begin())
		{
			++it;
			if(it == list.end())
				s << " and ";
			else
				s << ", ";
		}
		else
			++it;

		s << creature->getName();
	}

	std::string killers = s.str();
	s.str("");

	ChatChannel* channel = NULL;
	if((channel = g_chat.getChannel(player, CHANNEL_GUILD)))
	{
		s << "Guild member " << player->getName() << " was killed by " << killers << ". The new score is " << war.frags[
			war.type == WAR_GUILD] << ":" << war.frags[war.type] << " frags (limit " << war.limit << ").";
		channel->talk("", SPEAK_CHANNEL_RA, s.str());
	}

	s.str("");
	if((channel = g_chat.getChannel(list[0].getKillerCreature()->getPlayer(), CHANNEL_GUILD)))
	{
		s << "Opponent " << player->getName() << " was killed by " << killers << ". The new score is " << war.frags[
			war.type] << ":" << war.frags[war.type == WAR_GUILD] << " frags (limit " << war.limit << ").";
		channel->talk("", SPEAK_CHANNEL_RA, s.str());
	}

	DBQuery query;
	query << "INSERT INTO `guild_kills` (`guild_id`, `war_id`, `death_id`) VALUES (" << war.ids[war.type] << ", " << war.war << ", " << deathId << ");";
	db->query(query.str());
}
Beispiel #23
0
inline void addUserCheck(Chat& chat, const string& name)
{
	if(!chat.addUser(User(name, NetAddr()), users++))
		cout << "user '" << name << "' could not be added to chat" << endl;
	else
		cout << "user '" << name << "' added to chat" << endl;
}
Beispiel #24
0
QList<Message> HistorySqlStorage::messagesBackTo(const Chat &chat, const QDateTime &datetime, int limit)
{
	DatabaseMutex.lock();

	QList<Message> result;

	QSqlQuery query(Database);
	// we want last *limit* messages, so we have to invert sorting here
	// it is reverted back manually below
	QString queryString = "SELECT chat, sender, content, send_time, receive_time, attributes FROM kadu_messages WHERE " + chatWhere(chat) +
			" AND datetime(receive_time) >= datetime(:date) ORDER BY receive_time DESC, rowid DESC LIMIT :limit";
	query.prepare(queryString);

	query.bindValue(":chat", chat.uuid().toString());
	query.bindValue(":date", datetime.toString(Qt::ISODate));
	query.bindValue(":limit", limit);

	executeQuery(query);

	result = messagesFromQuery(query);

	DatabaseMutex.unlock();

	// se comment above
	QList<Message> inverted;
#if (QT_VERSION >= 0x040700)
	inverted.reserve(result.size());
#endif
	for (int i = result.size() - 1; i >= 0; --i)
		inverted.append(result.at(i));
	return inverted;
}
Beispiel #25
0
bool TabsManager::acceptChat(Chat chat) const
{
    if (!chat)
        return false;

    if (chat.property("tabs:tmp-attached", false).toBool())
        return true;
    if (chat.property("tabs:tmp-detached", false).toBool())
        return false;
    if (chat.property("tabs:attached", false).toBool())
        return true;
    if (chat.property("tabs:detached", false).toBool())
        return false;

    return ConfigDefaultTabs;
}
Beispiel #26
0
inline void addGroupCheck(Chat& chat, const string& name)
{
	if(!chat.addGroup(name))
		cout << "group '" << name << "' could not be added to chat" << endl;
	else
		cout << "group '" << name << "' added to chat" << endl;
}
Beispiel #27
0
bool FacebookChatService::sendRawMessage(const Chat &chat, const QByteArray &rawMessage)
{
    auto contact = *chat.contacts().begin();
    m_facebookSession.sendMessage(contact.id().toULongLong(), rawMessage);

    return true;
}
Beispiel #28
0
void Party::disband()
{
	g_chat.deleteChannel(this);

	getLeader()->sendTextMessage(MSG_INFO_DESCR, "Your party has been disbanded.");
	getLeader()->setParty(NULL);
	getLeader()->sendPlayerPartyIcons(getLeader());

	for(uint32_t i = 0; i < inviteList.size(); ++i){
		inviteList[i]->removePartyInvitation(this);
		inviteList[i]->sendPlayerPartyIcons(getLeader());
		inviteList[i]->sendPlayerPartyIcons(inviteList[i]);
		getLeader()->sendPlayerPartyIcons(inviteList[i]);
	}
	inviteList.clear();

	for(uint32_t i = 0; i < memberList.size(); ++i){
		memberList[i]->setParty(NULL);
		memberList[i]->sendPlayerPartyIcons(getLeader());
		memberList[i]->sendPlayerPartyIcons(memberList[i]);
		memberList[i]->sendTextMessage(MSG_INFO_DESCR, "Your party has been disbanded.");
		getLeader()->sendPlayerPartyIcons(memberList[i]);
	}
	memberList.clear();

	setLeader(NULL);
	delete this;
}
Beispiel #29
0
bool ChatChannel::addUser(Player* player)
{
	if(m_users.find(player->getID()) != m_users.end())
		return false;

	ChatChannel* channel = g_chat.getChannel(player, m_id);
	if(!channel)
	{
		#ifdef __DEBUG_CHAT__
		std::clog << "ChatChannel::addUser - failed retrieving channel." << std::endl;
		#endif
		return false;
	}

	if(m_id == CHANNEL_PARTY || m_id == CHANNEL_GUILD || m_id == CHANNEL_PRIVATE)
	{
		Player* tmpPlayer = NULL;
		for(UsersMap::iterator cit = m_users.begin(); cit != m_users.end(); ++cit)
		{
			if((tmpPlayer = cit->second->getPlayer()))
				tmpPlayer->sendChannelEvent(m_id, player->getName(), CHANNELEVENT_JOIN);
		}
	}

	m_users[player->getID()] = player;
	CreatureEventList joinEvents = player->getCreatureEvents(CREATURE_EVENT_CHANNEL_JOIN);
	for(CreatureEventList::iterator it = joinEvents.begin(); it != joinEvents.end(); ++it)
		(*it)->executeChannelJoin(player, m_id, m_users);

	Manager::getInstance()->addUser(player->getID(), m_id);
	return true;
}
Beispiel #30
0
inline void addMessageCheck(Chat& chat, const Message& msg)
{
	if(!chat.addMessage(msg))
		cout << "message could not be added to chat" << endl;
	else
		cout << "message added to chat" << endl;
}