// TODO: @student : extend the protocol. // so the receiver can split the package into name and content void ClientChatNetPackageDispatcher::dispatchPacket(unsigned char packetIdentifier, NativePacket* nativePacket ) { NetMessageIDTypes eNetMessageID(static_cast<NetMessageIDTypes>(packetIdentifier)); const bool validMessageId((eNetMessageID > NETMSG_ID_START) && (eNetMessageID < NETMSG_ID_END)); if(validMessageId == false) { return; } switch(eNetMessageID) { case NETMSG_ID_CHATLINE: { const char* message = (const char*)nativePacket->data; // skip the packet identifier message++; if(isEmptyString(message) == true) { getPeer()->log(ELogType_Error, "received an empty chat message"); } else { // TODO: @student : split the packet ... ChatMessage chatMessage("---", message); addChatMessage(chatMessage); } } break; case NETMSG_ID_JSONOBJECT: { // TODO: @student : this might not be enough ... const char* message = (const char*)nativePacket->data; // skip the packet identifier message++; if(isEmptyString(message) == true) { getPeer()->log(ELogType_Error, "received an empty chat message"); } else { SLAString json(message); getPeer()->log(ELogType_Info, "received json %s", json.c_str()); CCDictionary* dictionary = CCJSONConverter::dictionaryFrom(json.c_str()); getPeer()->log(ELogType_Info, dictionary); // DONE: @student : read the relevant dictionary members and pass them to the chat message CCObject *aMessage = dictionary->objectForKey("message"); CCDictionary *messDictionary = dynamic_cast<CCDictionary*>(aMessage); const CCString *aSender = messDictionary->valueForKey("sender"); const CCString *aContent = messDictionary->valueForKey("content"); ChatMessage chatMessage(aSender->getCString(), aContent->getCString()); addChatMessage(chatMessage); } } break; default: break; } }
void Rcon::handleReceive(const boost::system::error_code& error, std::size_t bytes_received) { if (!error) { rcon_socket.recv_buffer[bytes_received] = '\0'; switch(rcon_socket.recv_buffer[7]) { case 0x00: loginResponse(); break; case 0x01: serverResponse(bytes_received); break; case 0x02: chatMessage(bytes_received); break; }; } else { logger->info("Rcon: UDP handleReceive Error: {0}", error.message()); timerKeepAlive(0); { std::lock_guard<std::mutex> lock(rcon_socket.mutex); rcon_socket.socket->close(); } if (auto_reconnect) { timerReconnect(5); } } }
// TODO: @student : extend the protocol. // so the receiver can split the package into name and content void ServerChatNetPackageDispatcher::dispatchPacket(unsigned char packetIdentifier, NativePacket* nativePacket ) { NetMessageIDTypes eNetMessageID(static_cast<NetMessageIDTypes>(packetIdentifier)); const bool validMessageId((eNetMessageID > NETMSG_ID_START) && (eNetMessageID < NETMSG_ID_END)); if(validMessageId == false) { return; } switch(eNetMessageID) { case NETMSG_ID_CHATLINE: { const char* message = (const char*)nativePacket->data; // skip the packet identifier message++; if(isEmptyString(message) == true) { getPeer()->log(ELogType_Error, "received an empty chat message"); } else { // TODO: split the packet ... ChatMessage chatMessage("---", message); addChatMessage(chatMessage); // now broadcast this message to everyone else connected to this peer // except for the sender getPeer()->accessRakNetPeer()->Send((const char*)nativePacket->data, nativePacket->length, HIGH_PRIORITY, RELIABLE_ORDERED, 0, nativePacket->systemAddress, true); } } break; default: break; } }
void Player::sendChatMessage(const json &rawJSON) { // Format chat message with the sender name before broadcasting it to all players ChatMessage chatMessage(rawJSON); chatMessage.rawJSON[Message::DATA_KEY]["text"] = name + ": " + chatMessage.text; game->writePlayers(chatMessage.getJSON()); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); this->chatTimeout = true; this->connected = false; this->currColorId = 2; // czarny this->lastColorButton = ui->blackPushButton; this->graphicsScene = new QGraphicsScene(); ui->graphicsView->setScene(graphicsScene); this->currentPen.setColor(QColor("black")); connect(ui->graphicsView,SIGNAL(drawPoint(QPoint)),this,SLOT(drawPoint(QPoint))); connect(ui->graphicsView,SIGNAL(drawLineTo(QPoint)),this,SLOT(drawLineTo(QPoint))); connect(ui->clearPushButton,SIGNAL(clicked()),this,SLOT(clearView())); connect(ui->redPushButton,SIGNAL(clicked()),this,SLOT(switchColor())); connect(ui->greenPushButton,SIGNAL(clicked()),this,SLOT(switchColor())); connect(ui->blackPushButton,SIGNAL(clicked()),this,SLOT(switchColor())); connect(ui->sendMessagePushButton,SIGNAL(clicked()),this,SLOT(sendMessage())); connect(ui->chatLineEdit,SIGNAL(returnPressed()),this,SLOT(sendMessage())); this->socket = new KalSocket(); this->chatTimer = new QTimer(); connect(socket,SIGNAL(connected()),this,SLOT(connectionSuccess())); connect(socket,SIGNAL(error(QAbstractSocket::SocketError)), this,SLOT(displayError(QAbstractSocket::SocketError))); connect(socket,SIGNAL(pointsReceived(int,int,int,KalSocket::DrawType)), this,SLOT(pointsReceived(int,int,int,KalSocket::DrawType))); connect(socket,SIGNAL(clear()),graphicsScene,SLOT(clear())); connect(socket,SIGNAL(someoneLoggedIn(QString)),this,SLOT(someoneLoggedIn(QString))); connect(socket,SIGNAL(chatMessage(QString,QString)),this,SLOT(addMessage(QString,QString))); connect(socket,SIGNAL(nicknames(QList<QString>)),this,SLOT(getNicknames(QList<QString>))); connect(socket,SIGNAL(logout(QString)),this,SLOT(someoneLoggedOut(QString))); connect(socket,SIGNAL(drawStart(QString)),this,SLOT(drawStart(QString))); connect(socket,SIGNAL(gotSettings(ServerSettings)),this,SLOT(getSettings(ServerSettings))); connect(socket,SIGNAL(errorMessage(QString)),this,SLOT(showMessage(QString))); connect(ui->wantDrawCheckBox,SIGNAL(toggled(bool)),this,SLOT(wantDrawToggled(bool))); // actiony z menu: Polaczenie connect(ui->actionPo_cz,SIGNAL(triggered()),this,SLOT(connectWindowExec())); // laczymy sie connect(ui->actionRoz_cz,SIGNAL(triggered()),this,SLOT(disconnect())); // rozlaczamy sie connect(ui->actionZako_cz,SIGNAL(triggered()),this,SLOT(close())); // koniec programu // timer connect(chatTimer,SIGNAL(timeout()),this,SLOT(timeout())); connect(ui->progressBar,SIGNAL(full()),this,SLOT(drawTimeout())); // inne this->disableActions(false); // Polacz - aktywne, Rozlacz - nieaktywne }
/** * @param msg chat message */ void SessionState::handleChat(const QStringList& tokens) { if(tokens.size()!=3) { qWarning() << "Received invalid chat message"; } else { const User *u = 0; if(users_.contains(tokens[1].toInt())) u = &users_[tokens[1].toInt()]; emit chatMessage(u?u->name():"<unknown>", tokens[2]); } }
FenDevoir::FenDevoir(Client *cl, QWidget *parent) : QDialog(parent), cl(cl) { setupUi(this); connect(cl, SIGNAL(newHomework(Devoir)), this, SLOT(addHomework(Devoir))); connect(cl, SIGNAL(chatMessage(QString,QString)), this, SLOT(addMessage(QString,QString))); zoneMessage->setReadOnly(true); connect(message, SIGNAL(returnPressed()), this, SLOT(on_SendMessage_clicked())); connect(cl, SIGNAL(newListMatieres(QStringList)), this, SLOT(addMatieres(QStringList))); initModel(); }
void ChatInterface::processChatMessages(const NetMessage* message) { switch(message->message_id) { case _net_message_id_chat_mesg_req: chatMessageRequest(message); break; case _net_message_id_chat_mesg: chatMessage(message); break; default: LOGGER.warning("Received unknown chat message (id %d-%d)", message->message_class, message->message_id); } }
/** * @brief Client::echo when data is available for the client tcp socket. That data is read into a buffer array. At the \ of this the echoMessage signal is emitted. This is turn calls the incomingMessage method in the CloudGaming class. */ void Client::echo() { QByteArray buffer = clientSocket->readAll(); qDebug() << buffer; Utility::debug(buffer); QString g = QString::fromLocal8Bit(buffer); if(g.contains("says:")){ emit chatMessage(g); }else if(g.contains("playcatancstats<catan>0")){ emit echoMessage(g); }else if(g.contains("<catan>")){ emit messageForCatan(g); } else{ qDebug() << g; emit echoMessage(g); } }
void DouyuTcpSocket::readDanmuMessage() { QByteArray inBlock = tcpDanmuSoc.readAll(); //接收数据块 QString content; int pos = 0; while((pos = inBlock.indexOf(QString("type"),pos)) != -1) { content = inBlock.mid(pos); QMap<QString,QString> messageMap = STTDeserialization(content); //弹幕类型分析 if(messageMap["type"] == QString("loginres")) {//出现表示服务端消息已经发完,可进入下一个步骤 request_state = "joingroup"; } if(messageMap["type"] == QString("chatmsg")|| messageMap["type"] == QString("dgb")|| messageMap["type"] == QString("bc_buy_deserve")) { emit chatMessage(messageMap); } pos = pos + content.length(); } if(request_state == "joingroup") { QStringList key_list = (QStringList() <<"type" <<"rid" <<"gid" ); QStringList value_list = (QStringList() <<"joingroup" //登录请求 <<danmu_rid //房间号 <<_Douyu_Room_gid //分组 ); QString content = STTSerialization(key_list,value_list); this->messageWrite(content); request_state = "receiveDanmu"; timer->start(_Douyu_DanmuServer_Intervals); } }
/** * @param tokens message tokens */ bool SessionState::handleMessage(const QStringList& tokens) { if(tokens[0] == "SAY") { int userid = tokens.at(1).toInt(); if(hasUser(userid)) emit chatMessage(user(userid).name(), tokens.at(2)); else qWarning() << "Got chat message from unknown user:"******"USER") { updateUser(tokens); } else if(tokens[0] == "PART") { partUser(tokens); } else if(tokens[0] == "SLOCK") { emit syncWait(); } else if(tokens[0] == "SUNLOCK") { emit syncDone(); } else if(tokens[0] == "BOARD") { update(Session(tokens)); } else if(tokens[0] == "RASTER") { releaseRaster(); expectRaster_ = tokens.at(1).toInt(); if(expectRaster_ == 0) emit rasterReceived(100); } else if(tokens[0] == "GIVERASTER") { emit syncRequest(); } else if(tokens[0] == "MORE") { if(isUploading()) sendRasterChunk(); else qWarning() << "Got request for more raster data, but we're not uploading anything!"; } else if(tokens[0] == "ANNOTATE") { protocol::Annotation a(tokens); if(!a.isValid()) qWarning() << "Received an invalid annotation"; else emit annotation(a); } else if(tokens[0] == "RMANNOTATION") { emit rmAnnotation(tokens.at(1).toInt()); } else return false; return true; }
void DouyuTcpSocket::stateChanged(QAbstractSocket::SocketState state) { qDebug()<<state; QString datetime = QDateTime::currentDateTime().toString("MM-dd hh:mm:ss"); QString roomid = danmu_rid; QString cur_state = ""; /* * type = connectstate * time = time * state = state * roomid = roomid * [04-18 09:38:21] 房间号:09900 连接中... */ if(QAbstractSocket::HostLookupState == state) { cur_state = "主机查询中..."; } else if(QAbstractSocket::ConnectingState == state) { cur_state = "连接弹幕服务器中..."; } else if(QAbstractSocket::ConnectedState == state) { cur_state = "弹幕服务器连接成功..."; } else if(QAbstractSocket::ClosingState == state) { cur_state = "弹幕服务器连接关闭..."; } else if(QAbstractSocket::UnconnectedState == state) { cur_state = "未连接服务器..."; } QMap<QString,QString> map; map.insert(QString("type"),QString("connectstate")); map.insert(QString("time"),datetime); map.insert(QString("state"),cur_state); map.insert(QString("roomid"),roomid); emit chatMessage(map); }
void KalSocket::chatMessageReceived(QByteArray nickname, QByteArray message) { emit chatMessage(QString(nickname),QString(message)); }