void RoomSelector::joinClicked() { QTreeWidgetItem *twi = roomList->currentItem(); if (!twi) return; joinRoom(twi->data(0, Qt::UserRole).toInt(), true); }
void Bot::handleHandshake() { component.warning("ready to serve requests, joining rooms."); SQLiteStatement *statement = db.prepare("SELECT room_jid, room_botnick FROM rooms"); while(statement->next()) { joinRoom(statement->asString("room_jid"), statement->asString("room_botnick")); } delete statement; }
void HallDialog::join(){ int row = table->currentRow(); if(row == -1) return; QTableWidgetItem *item = table->item(row, 0); if(item == NULL) return; bool ok; int room_id = item->text().toInt(&ok); if(!ok) return; joinRoom(room_id); }
void Utility::HandleCommand::command(const HandleMessage &pCommand, Room *pRoom, Entity::Client *pClient) { switch ( static_cast<Command::Code> (pCommand.getKey("command").toInt()) ) { case Command::EDIT_PASSWORD: updatePassword(pCommand.getKey("newPassword").toString(), pClient); break; case Command::JOIN_ROOM: joinRoom(pCommand.getKey("newRoom").toString(), pRoom, pClient); break; default: Utility::HandleMessage message{}; message.setType(TypeMessage::ERROR_MESSAGE); message.setKey("code", Error::UNKNOW_COMMAND); pClient->sendTextMessage(message.toString()); break; } }
void RoomSelector::processListRoomsEvent(const Event_ListRooms &event) { const int roomListSize = event.room_list_size(); for (int i = 0; i < roomListSize; ++i) { const ServerInfo_Room &room = event.room_list(i); for (int j = 0; j < roomList->topLevelItemCount(); ++j) { QTreeWidgetItem *twi = roomList->topLevelItem(j); if (twi->data(0, Qt::UserRole).toInt() == room.room_id()) { if (room.has_name()) twi->setData(0, Qt::DisplayRole, QString::fromStdString(room.name())); if (room.has_description()) twi->setData(1, Qt::DisplayRole, QString::fromStdString(room.description())); if (room.has_player_count()) twi->setData(2, Qt::DisplayRole, room.player_count()); if (room.has_game_count()) twi->setData(3, Qt::DisplayRole, room.game_count()); return; } } QTreeWidgetItem *twi = new QTreeWidgetItem; twi->setData(0, Qt::UserRole, room.room_id()); if (room.has_name()) twi->setData(0, Qt::DisplayRole, QString::fromStdString(room.name())); if (room.has_description()) twi->setData(1, Qt::DisplayRole, QString::fromStdString(room.description())); twi->setData(2, Qt::DisplayRole, room.player_count()); twi->setData(3, Qt::DisplayRole, room.game_count()); twi->setTextAlignment(2, Qt::AlignRight); twi->setTextAlignment(3, Qt::AlignRight); roomList->addTopLevelItem(twi); if (room.has_auto_join()) if (room.auto_join()) joinRoom(room.room_id(), false); } }
int main(int argc, char * argv[]) { struct sockaddr_in serv_addr, client_addr; int len, sockfd, client_sockfd, fdmax, i, j, x, y, nread; fd_set masterfd, cpmasterfd; for(x = 0; x < CHAT_ROOMS; x++) queue[x] = NULL; FD_ZERO(&masterfd); FD_ZERO(&cpmasterfd); if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror(NULL); exit(2); } bzero(&serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(TIME_PORT); serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)); listen(sockfd, 5); FD_SET(sockfd, &masterfd); fdmax = sockfd; while(1) { cpmasterfd = masterfd; select(fdmax+1, &cpmasterfd, NULL, NULL, NULL); for(i = 0; i <= fdmax; i++) { if(FD_ISSET(i, &cpmasterfd)) { if(i == sockfd) // new Connection { len = sizeof(client_addr); client_sockfd = accept(sockfd, (struct sockaddr *)&client_addr, (socklen_t *)&len); FD_SET(client_sockfd, &masterfd); if(client_sockfd > fdmax) fdmax = client_sockfd; greet(client_sockfd); } else // old Client wants to talk { searchRoomForClient(i, &x, &y); nread = read(i, buf, SIZE); printf("%d, %s.\n", nread, buf); if(nread <= 0 || strcmp(buf, "exit") == 0) { printf("Client disconnected.\n"); if(x != -1 && y != -1) { population[x] -= 1; clientsConnected[x][y] = 0; queueToRoom(x, y); } if(i == fdmax) fdmax--; close(i); FD_CLR(i, &masterfd); } else if(joinRoom(i, x, y) != 0) {} //else if(commands() != 0) {} else { if(x != -1 && y != -1 && y < MAX_CLIENTS) { for(j = 0; j < population[x]; j++) { if(FD_ISSET(clientsConnected[x][j], &masterfd) && clientsConnected[x][j] != sockfd && clientsConnected[x][j] != i) write(clientsConnected[x][j], buf, nread); } printf("client: %s\n", buf); } } } } } } return 0; }
void DialogRoom::on_btnJoin_clicked() { emit joinRoom(ui->txtRoom->text()); this->deleteLater(); }