bool GameNetConnection::_handle_message(int sender, SerializeBuffer& serializer) { // Read type from buffer message_t type; serializer.read_int(type); switch (type) { case PACKET_CLIENT2SERV_CONNECTION_AFFIRM: { net_recv_connection_affirm(serializer, sender, pd); break; } case PACKET_SERV2CLIENT_INITIALPLAYERDATA: { net_recv_game_init_data(serializer, sender, init_data, pd); break; } case PACKET_ACTION: { net_recv_player_actions(serializer, sender, pd); break; } case PACKET_CHAT_MESSAGE: { ChatMessage msg; msg.deserialize(serializer); chat.add_message(msg); break; } default: serializer.move_read_position(-(int)sizeof(int)); return false; } return true; }
ChatRecord::ChatRecord(ChatMessage message, QObject *parent) : QObject(parent), time(message.getCreateTime()), uuid(message.getUuid()), userUuid(message.getSenderUuid()), content(message.getContent()), isRead(NotRead) { initSendOrReceive(); }
void ChatForm::receiveSuccess(QHostAddress senderIp, quint16 senderPort, ChatMessage message){ qDebug() << message.getSenderUuid() << receiver->getUuid(); if(message.getSenderUuid() == receiver->getUuid()) { if(message.getContent() == ":/shake") { startShake(); } ChatRecord *record = new ChatRecord(message); mChatRecords.append(record); updateChatRecordView(); } }
void ChatSystem() { while(1) { std::string message; std::getline(cin, message); ChatMessage msg; msg.SetTheMessage(message); TheMassiveMessageMgr->SendMessageTo(::Game::kPlayerServer, msg.ToPacket(kClientChatMessage)); } }
void MessageManager::onPrivateMessage(const ChatMessage& aMessage, UserConnection* aUc) { bool myPM = aMessage.replyTo->getUser() == ClientManager::getInstance()->getMe(); const UserPtr& user = myPM ? aMessage.to->getUser() : aMessage.replyTo->getUser(); size_t wndCnt; { WLock l(cs); wndCnt = chats.size(); auto i = chats.find(user); if (i != chats.end()) { //Debug purposes to see if this really ever happens!! if (aUc && !i->second->ccReady()) LogManager::getInstance()->message("Message received via CCPM but frame not connected state! report to Night", LogManager::LOG_ERROR); i->second->handleMessage(aMessage); //We should have a listener in the frame return; } } Client* c = &aMessage.from->getClient(); if (wndCnt > 200 || !myPM && isIgnoredOrFiltered(aMessage, c, true)) { DisconnectCCPM(user); return; } const auto& identity = aMessage.replyTo->getIdentity(); if ((identity.isBot() && !SETTING(POPUP_BOT_PMS)) || (identity.isHub() && !SETTING(POPUP_HUB_PMS))) { c->Message(STRING(PRIVATE_MESSAGE_FROM) + " " + identity.getNick() + ": " + aMessage.format()); return; } //This will result in creating a new window fire(MessageManagerListener::PrivateMessage(), aMessage); }
void net_send_chatmessage(GameNetConnection& net, ChatMessage & message) { if (!net.connection()) { return; } SerializeBuffer& sb = net.grab_buffer( GameNetConnection::PACKET_CHAT_MESSAGE); message.serialize(sb); net.send_packet(sb); }
void QtChatWindow::dropEvent(QDropEvent *event) { if (fileTransferEnabled_ == Yes && event->mimeData()->hasUrls()) { if (event->mimeData()->urls().size() == 1) { onSendFileRequest(Q2PSTRING(event->mimeData()->urls().at(0).toLocalFile())); } else { std::string messageText(Q2PSTRING(tr("Sending of multiple files at once isn't supported at this time."))); ChatMessage message; message.append(boost::make_shared<ChatTextMessagePart>(messageText)); addSystemMessage(message, DefaultDirection); } } else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) { QByteArray dataBytes = event->mimeData()->data("application/vnd.swift.contact-jid-list"); QDataStream dataStream(&dataBytes, QIODevice::ReadOnly); std::vector<JID> invites; while (!dataStream.atEnd()) { QString jidString; dataStream >> jidString; invites.push_back(Q2PSTRING(jidString)); } onInviteToChat(invites); }
// Add message to ChatBox void MainWindow::addToConversation(ChatMessage msg) { openChatBox(); QString tabName = msg.to(); if(msg.to() == myProfile->login) tabName = msg.from(); bool tabOpen = tabIsOpen(tabName); if(!tabOpen) addNewTab(tabName); // Get sender CBDC widget and add to conversation message ChatBoxDialogContent *w = (ChatBoxDialogContent*) sender(); w->ui->conversationHistory->append(msg.toHtml()); qDebug()<<"client: '" + msg.from() + "' send to '" + msg.to() + "' message: '" + msg.text() + "'"; }
void handleNewMessage(char* inBuffer, int size, char** outBuffer, int *outSize) { //Create a Chat Message ChatMessage *m = new ChatMessage(); //Decode Chat Message m->decode(inBuffer, size); //Search the users list for nickname bool found = false; pthread_mutex_lock(&userListMutex); for(vector<Join*>::iterator it = users.begin(); it != users.end(); ++it) { Join *user = (*it); //Remove nickname if it exists if (strcmp(m->getSender(), user->getNickname()) == 0) { found = true; } } pthread_mutex_unlock(&userListMutex); //If the name exists add the name and message to the messages list if (found) { char* message = new char[strlen(m->getSender()) + 2 + strlen(m->getMessage()) + 1]; //sender + ": " + message + null sprintf(message, "%s: %s", m->getSender(), m->getMessage()); //easier than dealing with strcpy pthread_mutex_lock(&messageListMutex); messageList.push_back(message); pthread_mutex_unlock(&messageListMutex); } //Create appropriate confirm message Confirm *c = new Confirm(); c->setResponse(found); //Encode this message and return (*outSize)=c->encode(outBuffer); delete m; delete c; }
bool Game::handleChatBoxMessage(HANDLE_ARGS) { ChatMessage *message = reinterpret_cast<ChatMessage *>(packet->data); //Lets do commands if(message->msg == '.') { const char *cmd[] = { ".set", ".gold", ".speed", ".health", ".xp", ".ap", ".ad", ".mana", ".model", ".help", ".spawn", ".size", ".junglespawn", ".skillpoints", ".level", ".tp"}; // help command if (strncmp(message->getMessage(), cmd[9], strlen(cmd[9])) == 0) { return true; } // set if(strncmp(message->getMessage(), cmd[0], strlen(cmd[0])) == 0) { uint32 blockNo, fieldNo; float value; sscanf(&message->getMessage()[strlen(cmd[0])+1], "%u %u %f", &blockNo, &fieldNo, &value); blockNo = 1 << (blockNo - 1); uint32 mask = 1 << (fieldNo - 1); peerInfo(peer)->getChampion()->getStats().setStat(blockNo, mask, value); return true; } // gold if(strncmp(message->getMessage(), cmd[1], strlen(cmd[1])) == 0) { float gold = (float)atoi(&message->getMessage()[strlen(cmd[1]) + 1]); peerInfo(peer)->getChampion()->getStats().setGold(gold); return true; } // speed if(strncmp(message->getMessage(), cmd[2], strlen(cmd[2])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[2])+1]); printf("Setting speed to %f\n", data); peerInfo(peer)->getChampion()->getStats().setMovementSpeed(data); return true; } // spawn if(strncmp(message->getMessage(), cmd[10], strlen(cmd[10])) == 0) { static const MinionSpawnPosition positions[] = { SPAWN_BLUE_TOP, SPAWN_BLUE_BOT, SPAWN_BLUE_MID, SPAWN_RED_TOP, SPAWN_RED_BOT, SPAWN_RED_MID, }; for(int i = 0; i < 6; ++i) { Minion* m = new Minion(map, GetNewNetID(), MINION_TYPE_MELEE, positions[i]); map->addObject(m); notifyMinionSpawned(m); } return true; } //health if(strncmp(message->getMessage(), cmd[3], strlen(cmd[3])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[3])+1]); peerInfo(peer)->getChampion()->getStats().setCurrentHealth(data); peerInfo(peer)->getChampion()->getStats().setMaxHealth(data); notifySetHealth(peerInfo(peer)->getChampion()); return true; } // xp if(strncmp(message->getMessage(), cmd[4], strlen(cmd[4])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[5])+1]); printf("Setting experience to %f\n", data); peerInfo(peer)->getChampion()->getStats().setExp(data); return true; } // ap if(strncmp(message->getMessage(), cmd[5], strlen(cmd[5])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[5])+1]); printf("Setting AP to %f\n", data); peerInfo(peer)->getChampion()->getStats().setBonusApFlat(data); return true; } // ad if(strncmp(message->getMessage(), cmd[6], strlen(cmd[6])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[5])+1]); printf("Setting AD to %f\n", data); peerInfo(peer)->getChampion()->getStats().setBonusAdFlat(data); return true; } // Mana if(strncmp(message->getMessage(), cmd[7], strlen(cmd[7])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[7])+1]); printf("Setting Mana to %f\n", data); peerInfo(peer)->getChampion()->getStats().setCurrentMana(data); peerInfo(peer)->getChampion()->getStats().setMaxMana(data); return true; } // Model if(strncmp(message->getMessage(), cmd[8], strlen(cmd[8])) == 0) { std::string sModel = (char *)&message->getMessage()[strlen(cmd[8]) + 1]; peerInfo(peer)->getChampion()->setModel(sModel); return true; } // Size if(strncmp(message->getMessage(), cmd[11], strlen(cmd[11])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[11])+1]); printf("Setting size to %f\n", data); peerInfo(peer)->getChampion()->getStats().setSize(data); return true; } // Mob Spawning-Creating, updated if(strncmp(message->getMessage(), cmd[12], strlen(cmd[12])) == 0) { const char *cmd[] = { "c baron" , "c wolves", "c red", "c blue", "c dragon", "c wraiths", "c golems"}; return true; } // Skillpoints if(strncmp(message->getMessage(), cmd[13], strlen(cmd[13])) == 0) { peerInfo(peer)->getChampion()->setSkillPoints(17); SkillUpResponse skillUpResponse(peerInfo(peer)->getChampion()->getNetId(), 0, 0, 17); sendPacket(peer, skillUpResponse, CHL_GAMEPLAY); return true; } // Level if(strncmp(message->getMessage(), cmd[14], strlen(cmd[14])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[14])+1]); peerInfo(peer)->getChampion()->getStats().setLevel(data); return true; } // tp if(strncmp(message->getMessage(), cmd[15], strlen(cmd[15])) == 0) { float x, y; sscanf(&message->getMessage()[strlen(cmd[15])+1], "%f %f", &x, &y); notifyTeleport(peerInfo(peer)->getChampion(), x, y); return true; } } switch(message->type) { case CMT_ALL: return broadcastPacket(packet->data, packet->dataLength, CHL_COMMUNICATION); case CMT_TEAM: return broadcastPacketTeam(peerInfo(peer)->getTeam(), packet->data, packet->dataLength, CHL_COMMUNICATION); default: //Logging->errorLine("Unknown ChatMessageType\n"); return sendPacket(peer, packet->data, packet->dataLength, CHL_COMMUNICATION); } return false; }
bool Game::handleChatBoxMessage(HANDLE_ARGS) { ChatMessage *message = reinterpret_cast<ChatMessage *>(packet->data); //Lets do commands if(message->msg == '.') { const char *cmd[] = { ".set", ".gold", ".speed", ".health", ".xp", ".ap", ".ad", ".mana", ".model", ".help", ".spawn", ".size", ".junglespawn", ".skillpoints", ".level", ".tp", ".coords", ".ch"}; std::ostringstream debugMsg; // help command if (strncmp(message->getMessage(), cmd[9], strlen(cmd[9])) == 0) { return true; } // set if(strncmp(message->getMessage(), cmd[0], strlen(cmd[0])) == 0) { uint32 blockNo, fieldNo; float value; sscanf(&message->getMessage()[strlen(cmd[0])+1], "%u %u %f", &blockNo, &fieldNo, &value); blockNo = 1 << (blockNo - 1); uint32 mask = 1 << (fieldNo - 1); peerInfo(peer)->getChampion()->getStats().setStat(blockNo, mask, value); return true; } // gold if(strncmp(message->getMessage(), cmd[1], strlen(cmd[1])) == 0) { float gold = (float)atoi(&message->getMessage()[strlen(cmd[1]) + 1]); peerInfo(peer)->getChampion()->getStats().setGold(gold); return true; } // speed if(strncmp(message->getMessage(), cmd[2], strlen(cmd[2])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[2])+1]); printf("Setting speed to %f\n", data); peerInfo(peer)->getChampion()->getStats().setMovementSpeed(data); return true; } //health if(strncmp(message->getMessage(), cmd[3], strlen(cmd[3])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[3])+1]); peerInfo(peer)->getChampion()->getStats().setCurrentHealth(data); peerInfo(peer)->getChampion()->getStats().setMaxHealth(data); notifySetHealth(peerInfo(peer)->getChampion()); return true; } // xp if(strncmp(message->getMessage(), cmd[4], strlen(cmd[4])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[5])+1]); printf("Setting experience to %f\n", data); peerInfo(peer)->getChampion()->getStats().setExp(data); return true; } // ap if(strncmp(message->getMessage(), cmd[5], strlen(cmd[5])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[5])+1]); printf("Setting AP to %f\n", data); peerInfo(peer)->getChampion()->getStats().setBonusApFlat(data); return true; } // ad if(strncmp(message->getMessage(), cmd[6], strlen(cmd[6])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[5])+1]); printf("Setting AD to %f\n", data); peerInfo(peer)->getChampion()->getStats().setBonusAdFlat(data); return true; } // Mana if(strncmp(message->getMessage(), cmd[7], strlen(cmd[7])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[7])+1]); printf("Setting Mana to %f\n", data); peerInfo(peer)->getChampion()->getStats().setCurrentMana(data); peerInfo(peer)->getChampion()->getStats().setMaxMana(data); return true; } // Model if(strncmp(message->getMessage(), cmd[8], strlen(cmd[8])) == 0) { std::string sModel = (char *)&message->getMessage()[strlen(cmd[8]) + 1]; peerInfo(peer)->getChampion()->setModel(sModel); return true; } // Size if(strncmp(message->getMessage(), cmd[11], strlen(cmd[11])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[11])+1]); printf("Setting size to %f\n", data); peerInfo(peer)->getChampion()->getStats().setSize(data); return true; } // Mob Spawning-Creating, updated if(strncmp(message->getMessage(), cmd[12], strlen(cmd[12])) == 0) { const char *cmd[] = { "c baron" , "c wolves", "c red", "c blue", "c dragon", "c wraiths", "c golems"}; return true; } // Skillpoints if(strncmp(message->getMessage(), cmd[13], strlen(cmd[13])) == 0) { peerInfo(peer)->getChampion()->setSkillPoints(17); SkillUpResponse skillUpResponse(peerInfo(peer)->getChampion()->getNetId(), 0, 0, 17); sendPacket(peer, skillUpResponse, CHL_GAMEPLAY); return true; } // Level if(strncmp(message->getMessage(), cmd[14], strlen(cmd[14])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[14])+1]); peerInfo(peer)->getChampion()->getStats().setLevel(data); return true; } // tp if(strncmp(message->getMessage(), cmd[15], strlen(cmd[15])) == 0) { float x, y; sscanf(&message->getMessage()[strlen(cmd[15])+1], "%f %f", &x, &y); notifyTeleport(peerInfo(peer)->getChampion(), x, y); return true; } // coords if(strncmp(message->getMessage(), cmd[16], strlen(cmd[16])) == 0) { printf("At %f;%f\n", peerInfo(peer)->getChampion()->getX(), peerInfo(peer)->getChampion()->getY()); debugMsg << "At Coords - X:" << peerInfo(peer)->getChampion()->getX() << " Y:" << peerInfo(peer)->getChampion()->getY() << " Z:" << peerInfo(peer)->getChampion()->getZ(); notifyDebugMessage(debugMsg.str()); return true; } // Ch(ampion) if(strncmp(message->getMessage(), cmd[17], strlen(cmd[17])) == 0) { std::string champ = (char *)&message->getMessage()[strlen(cmd[17]) + 1]; Champion* c = new Champion(champ, map, peerInfo(peer)->getChampion()->getNetId(), peerInfo(peer)->userId); c->setPosition(peerInfo(peer)->getChampion()->getX(), peerInfo(peer)->getChampion()->getY()); c->setModel(champ); // trigger the "modelUpdate" proc map->removeObject(peerInfo(peer)->getChampion()); delete peerInfo(peer)->getChampion(); map->addObject(c); peerInfo(peer)->setChampion(c); return true; } } switch(message->type) { case CMT_ALL: return broadcastPacket(packet->data, packet->dataLength, CHL_COMMUNICATION); case CMT_TEAM: return broadcastPacketTeam(peerInfo(peer)->getTeam(), packet->data, packet->dataLength, CHL_COMMUNICATION); default: //Logging->errorLine("Unknown ChatMessageType\n"); return sendPacket(peer, packet->data, packet->dataLength, CHL_COMMUNICATION); } return false; }
void FacebookAccount::slotMessageErrorAvailable( const ChatMessage &message ) { FacebookChatSession *mm = static_cast<FacebookChatSession *>(contact(message.to())->manager(Kopete::Contact::CanCreate)); mm->slotMessageError(message.messageId()); }
void ChatClient::on_sendButton_clicked() { if(nickAccepted == true) //only respond if they are connected { ChatMessage *cm; Confirm *c; INet4Address *servaddr; Connection *myConnection; char* buffer; //for encoded messages int bytesToSend; int bytesToReceive; //Get the strings out of the address, port and nickname //boxes and convert to strings; QString qmessage = ui.lineEdit->text(); QString qnick = ui.nicknameLine->text(); QString qip = ui.addresLine->text(); QString qport = ui.portLine->text(); //TODO Create new connection objects servaddr = new INet4Address(qip.toLatin1().data(),qport.toInt()); myConnection = new Connection(servaddr); //TODO Connect to server if (myConnection->createSocket() < 0) { printf("Could not create socket error."); return; } if (myConnection->connectSocket() < 0) { printf("Could not connect socket error."); delete(myConnection); delete(servaddr); return; } //TODO Make a chat message cm = new ChatMessage(); cm->setSender(qnick.toLatin1().data()); // I forgot this! cm->setMessage(qmessage.toLatin1().data()); //TODO Send chat message (as bytes) bytesToSend = cm->encode(&buffer); myConnection->writeSize(bytesToSend); myConnection->writen(buffer,bytesToSend); // This was commented out? stupid mistake delete(buffer); //TODO Read response - take action! bytesToReceive = myConnection->readSize(); buffer = new char[bytesToReceive]; //TODO Read byte count and message myConnection->readn(buffer,bytesToReceive); //TODO Destroy socket myConnection->closeSocket(); //TODO Convert to message (confirm) c = new Confirm(); c->decode(buffer,bytesToReceive); //check if nick removed if (c->getResponse()==true) { ui.lineEdit->setText(tr("")); } delete myConnection; delete servaddr; } }
void ChatService::sendMessage(const ChatMessage &message ) { qDebug() << "sendMessage() Sending message to " << message.to(); startMessageSendRequest(message); qDebug() << "sendMessage() DONE Sending message to " << message.to(); }