bool LfgGroup::RemoveOfflinePlayers() // Return true if group is empty after check { sLfgMgr.LfgLog("Remove Offline %u, premade %u", GetId(), premadePlayers.empty() ? 0 : 1); if (m_memberSlots.empty()) { sLfgMgr.LfgLog("Group %u add to delete", GetId()); sLfgMgr.AddGroupToDelete(this); return true; } PlayerList toRemove; for(member_citerator citr = m_memberSlots.begin(); citr != m_memberSlots.end(); ++citr) { sLfgMgr.LfgLog("guid %u", citr->guid); Player *plr = sObjectMgr.GetPlayer(citr->guid); if (!plr || (!plr->GetSession() && !plr->IsBeingTeleported()) || (plr->GetGroup() && plr->GetGroup() != this && plr->GetGroup()->isLfgGroup() && ((LfgGroup*)plr->GetGroup())->IsInDungeon())) { sLfgMgr.LfgLog("Add to remove"); toRemove.insert(citr->guid); } } for(PlayerList::iterator itr = toRemove.begin(); itr != toRemove.end(); ++itr) { sLfgMgr.LfgLog("Check for premade %u", *itr); PlayerList::iterator premade = premadePlayers.find(*itr); if(premade != premadePlayers.end()) { sLfgMgr.LfgLog("premade yes"); for(PlayerList::iterator prm = premadePlayers.begin(); prm != premadePlayers.end(); ++prm) { Player *plr = sObjectMgr.GetPlayer(*prm); if(!plr || !plr->GetSession()) continue; Group* group = plr->GetGroup(); if(group) { sLfgMgr.RemoveFromQueue(plr, false); return true; } } for(PlayerList::iterator prm = premadePlayers.begin(); prm != premadePlayers.end(); ++prm) RemoveMember(*prm, 0); } } for(PlayerList::iterator itr = toRemove.begin(); itr != toRemove.end(); ++itr) { sLfgMgr.LfgLog("Remove %u", *itr); RemoveMember(*itr, 0); } toRemove.clear(); //flush empty group if (GetMembersCount() == 0) { sLfgMgr.LfgLog("Group %u add to delete 2", GetId()); sLfgMgr.AddGroupToDelete(this); return true; } return false; }
void MyAvatarLabel::paintEvent(QPaintEvent*) { QPainter painter(this); if(transparent) painter.setOpacity(0.4); else painter.setOpacity(1.0); //hide avatar if player is on ignore list boost::shared_ptr<Game> currentGame = myW->myStartWindow->getSession()->getCurrentGame(); PlayerListConstIterator it_c; int seatPlace; PlayerList seatsList = currentGame->getSeatsList(); for (seatPlace=0,it_c=seatsList->begin(); it_c!=seatsList->end(); ++it_c, seatPlace++) { if(seatPlace == myId) { if(!playerIsOnIgnoreList(QString::fromUtf8((*it_c)->getMyName().c_str()))) { painter.drawPixmap(0,0,myPixmap); return; } else if(myW->getMyConfig()->readConfigInt("DontHideAvatarsOfIgnored")) { painter.drawPixmap(0,0,myPixmap); return; } } } }
void Mud::removeInactivePlayers() { PlayerList toRemove = PlayerList(); for (auto iterator : mudPlayers) { // Proceed only if the player is not connected and is closing. if (!iterator->checkConnection() || iterator->closing) { // Add the player to the list of players that have to be removed. toRemove.insert(iterator); } } for (auto iterator = toRemove.begin(); iterator != toRemove.end(); ++iterator) { // Get the player at the given position. Player * player = *iterator; // Log the action of removing. Logger::log(LogLevel::Global, "Removing inactive player : " + player->getName()); // Only if the player has successfully logged in, save its state on DB. if (player->logged_in) { SQLiteDbms::instance().beginTransaction(); player->updateOnDB(); SQLiteDbms::instance().endTransaction(); } // Remove the player from the list of players. remPlayer(player); // Delete the player. delete (player); } }
void QBSoundWin::stopAll() { //printf("stopAll\n"); QBSoundLocker locker(&mMutex); #ifdef __USE_OGG_VORBIS__ { PlayerList::iterator it = streamTrack.begin(); while(it != streamTrack.end()) { delete (*it).second; ++it; } streamTrack.clear(); } { EffectList::iterator it = sharedList().begin(); while(it != sharedList().end()) { delete (*it).second; ++it; } sharedList().clear(); } #endif return QBSound::stopAll(); }
int set_descriptors() { FD_ZERO(&in_set); FD_ZERO(&out_set); int max_socket = ircSocket; // We want IO from irc FD_SET(ircSocket, &in_set); if (!ircOutBuf.empty()) { FD_SET(ircSocket, &out_set); } // And IO from players for (PlayerListIterator i = playerList.begin(); i != playerList.end(); ++i) { if ((*i)->socket != NO_SOCKET) { max_socket = max ((*i)->socket, max_socket); FD_SET((*i)->socket, &in_set); if (!(*i)->out_buf.empty()) { FD_SET((*i)->socket, &out_set); } } } return max_socket; }
//====================================================================================================================== // // Broadcasts a message to players in group and in range of the given object, used by tutorial and other instances // void MessageLib::_sendToInstancedPlayersUnreliable(Message* message,uint16 priority, const PlayerObject* const playerObject) const { if (!_checkPlayer(playerObject)) { mMessageFactory->DestroyMessage(message); return; } PlayerList const inRangeMembers = playerObject->getInRangeGroupMembers(true); PlayerList::const_iterator playerIt = inRangeMembers.begin(); while (playerIt != inRangeMembers.end()) { if (_checkPlayer(*playerIt)) { // Clone the message. mMessageFactory->StartMessage(); mMessageFactory->addData(message->getData(),message->getSize()); ((*playerIt)->getClient())->SendChannelAUnreliable(mMessageFactory->EndMessage(),(*playerIt)->getAccountId(),CR_Client,static_cast<uint8>(priority)); } ++playerIt; } mMessageFactory->DestroyMessage(message); }
void MyAvatarLabel::reportBadAvatar() { boost::shared_ptr<Game> currentGame = myW->getSession()->getCurrentGame(); int j=0; PlayerListConstIterator it_c; PlayerList seatList = currentGame->getSeatsList(); for (it_c=seatList->begin(); it_c!=seatList->end(); ++it_c) { if(myId == j) { QString avatar = QString::fromUtf8((*it_c)->getMyAvatar().c_str()); if(!avatar.isEmpty()) { QString nick = QString::fromUtf8((*it_c)->getMyName().c_str()); int ret = MyMessageBox::question(this, tr("PokerTH - Question"), tr("Are you sure you want to report the avatar of \"%1\" as inappropriate?").arg(nick), QMessageBox::Yes | QMessageBox::No); if(ret == QMessageBox::Yes) { QFileInfo fi(avatar); myW->getSession()->reportBadAvatar((*it_c)->getMyUniqueID(), fi.baseName().toStdString()); } } break; } j++; } }
void MyAvatarLabel::refreshTooltips() { boost::shared_ptr<Game> currentGame = myW->myStartWindow->getSession()->getCurrentGame(); PlayerListConstIterator it_c; int seatPlace; PlayerList seatsList = currentGame->getSeatsList(); for (seatPlace=0,it_c=seatsList->begin(); it_c!=seatsList->end(); ++it_c, seatPlace++) { if((*it_c)->getMyStayOnTableStatus() == TRUE || (*it_c)->getMyActiveStatus()) { bool computerPlayer = false; if((*it_c)->getMyType() == PLAYER_TYPE_COMPUTER) { computerPlayer = true; } if(!computerPlayer && getPlayerTip(QString::fromUtf8((*it_c)->getMyName().c_str()))!="" && seatPlace!=0) { myW->playerTipLabelArray[(*it_c)->getMyID()]->setText(QString("<a style='text-decoration: none; color: #"+myW->getMyGameTableStyle()->getPlayerInfoHintTextColor()+"; font-size: 14px; font-weight: bold; font-family:serif;' href=\'")+QString::fromUtf8((*it_c)->getMyName().c_str())+"\'>i</a>"); myW->playerTipLabelArray[(*it_c)->getMyID()]->setToolTip( getPlayerTip(QString::fromUtf8((*it_c)->getMyName().c_str())) ); myW->playerAvatarLabelArray[(*it_c)->getMyID()]->setToolTip( getPlayerTip(QString::fromUtf8((*it_c)->getMyName().c_str())) ); } else { myW->playerTipLabelArray[(*it_c)->getMyID()]->setText(""); myW->playerTipLabelArray[(*it_c)->getMyID()]->setToolTip(""); myW->playerAvatarLabelArray[(*it_c)->getMyID()]->setToolTip(""); } } else { myW->playerTipLabelArray[(*it_c)->getMyID()]->setText(""); myW->playerTipLabelArray[(*it_c)->getMyID()]->setToolTip(""); myW->playerAvatarLabelArray[(*it_c)->getMyID()]->setToolTip(""); } } refreshStars(); }
void GroupManager::_processIsmGroupLootMasterResponse(Message* message) { gLogger->logMsg("_processIsmGroupLootMasterResponse"); PlayerObject* playerObject = gWorldManager->getPlayerByAccId(message->getUint32()); // the player whos group_id has changed if(playerObject == NULL) { gLogger->logMsg("GroupManager::_processIsmGroupLootMasterResponse PlayerAccId not found"); return; } //send the SUI gLogger->logMsg("ok\n"); PlayerList inRangeMembers = playerObject->getInRangeGroupMembers(true); PlayerList::iterator it = inRangeMembers.begin(); BStringVector namesArray; while(it != inRangeMembers.end()) { namesArray.push_back((*it)->getFirstName().getAnsi()); ++it; } gUIManager->createNewPlayerSelectListBox(playerObject,"handleSetLootMaster","@group:master_looter_sui_title","@group:set_loot_type_text",namesArray,inRangeMembers,playerObject); }
void players_process_lines() { for (PlayerListIterator i = playerList.begin(); i != playerList.end(); ++i) { if ((*i)->socket != NO_SOCKET) { player_process_lines((*i)); } } }
void QBSoundWin::stopEffect(unsigned int nSoundId) { QBSoundLocker locker(&mMutex,"stopEffect"); PlayerList::iterator p = streamTrack.find(nSoundId); if (p != streamTrack.end()) { findPlayer(nSoundId)->stop(); } }
bool QBSoundWin::streamIsPlaying(int track) { QBSoundLocker locker(&mMutex,"streamStop"); PlayerList::iterator p = streamTrack.find(track); if (p == streamTrack.end()) { return false; } return findPlayer(track)->isPlaying(); }
bool LfgGroup::SelectRandomDungeon() { m_originalInfo = m_dungeonInfo; m_lfgFlags |= LFG_GRP_RANDOM; LfgLocksMap *groupLocks = GetLocksList(); std::vector<LFGDungeonEntry const*> options; LFGDungeonEntry const *currentRow = NULL; //Possible dungeons LfgDungeonList* list = sLfgMgr.GetRandomOptions(m_dungeonInfo->ID); for(LfgDungeonList::iterator itr = list->begin(); itr != list->end(); ++itr) options.push_back(*itr); //And now get only without locks for(LfgLocksMap::iterator itr = groupLocks->begin(); itr != groupLocks->end(); ++itr) { for(LfgLocksList::iterator itr2 = itr->second->begin(); itr2 != itr->second->end(); ++itr2) { for(std::vector<LFGDungeonEntry const*>::iterator itrDung = options.begin(); itrDung != options.end(); ++itrDung) { if ((*itrDung)->ID != (*itr2)->dungeonInfo->ID) continue; DungeonInfo* dungeonInfo = sLfgMgr.GetDungeonInfo((*itr2)->dungeonInfo->ID); if (dungeonInfo->locked || (*itr2)->lockType != LFG_LOCKSTATUS_RAID_LOCKED) { options.erase(itrDung); break; } } } } //This should not happen if (options.empty()) { PlayerList toRemove; for(member_witerator itr = m_memberSlots.begin(); itr != m_memberSlots.end(); ++itr) { Player *plr = sObjectMgr.GetPlayer(itr->guid); if (!plr) continue; sLfgMgr.SendLfgUpdatePlayer(plr, LFG_UPDATETYPE_GROUP_DISBAND); sLog.outError("LfgMgr: Cannot find any random dungeons for player %s", plr->GetName()); plr->GetSession()->SendNotification("Cannot find any random dungeons for this group, you have to find new group. We are sorry"); toRemove.insert(plr->GetGUID()); } for(PlayerList::iterator itr = toRemove.begin(); itr != toRemove.end(); ++itr) RemoveMember(*itr, 0); toRemove.clear(); sLfgMgr.AddGroupToDelete(this); return false; } //Select dungeon, there should be also bind check uint32 tmp = time(NULL)%options.size(); m_dungeonInfo = options[tmp]; return true; }
IrcPlayer *get_player_from_nick(string nick) { for (PlayerListIterator i = playerList.begin(); i != playerList.end(); ++i) { if ((*i)->socket != NO_SOCKET) { if (boost::iequals((*i)->nick, nick)) { return (*i); } } } return NULL; }
static QBStreamSound* findPlayer(int track) { QBStreamSound* player=NULL; PlayerList::iterator p = streamTrack.find(track); if (p != streamTrack.end()) { player = p->second; } else { player = new QBStreamSound(); streamTrack.insert(make_pair(track,player)); } return player; }
void MyAvatarLabel::startEditTip() { boost::shared_ptr<Game> currentGame = myW->getSession()->getCurrentGame(); int j=0; PlayerListConstIterator it_c; PlayerList seatList = currentGame->getSeatsList(); for (it_c=seatList->begin(); it_c!=seatList->end(); ++it_c) { if(myId == j) { QString nick = QString::fromUtf8((*it_c)->getMyName().c_str()); startChangePlayerTip(nick); break; } j++; } }
void remove_disconnected_players() { PlayerListIterator i = playerList.begin (); while (i != playerList.end ()) { IrcPlayer *player = (*i); PlayerListIterator prev = i; i++; if (player->socket == NO_SOCKET) { say_to(player->nick, "You are now disconnected from uMUD"); playerList.erase(prev); delete player; player = 0; } } /* end of looping through players */ }
void close_comms() { // Disconnect players for (PlayerListIterator i = playerList.begin(); i != playerList.end(); ++i) { if ((*i)->socket != NO_SOCKET) { close((*i)->socket); delete (*i); } } playerList.clear(); // Disconnect irc if (ircSocket != NO_SOCKET) { close(ircSocket); } }
static DWORD WINAPI LoaderThreadProc(LPVOID vdParam) { QBSoundWin* snd = (QBSoundWin*)vdParam; bool r=false; while (!r) { { QBSoundLocker locker(&snd->mMutex); PlayerList::iterator it = streamTrack.begin(); while(it != streamTrack.end()) { (*it).second->streamLoad(); ++it; } r = snd->mThreadEnd; } Sleep(10); } }
int Map::handleDeadPlayers () { int deadPlayers = 0; PlayerList list = _players; for (PlayerListIter i = list.begin(); i != list.end(); ++i) { Player* p = *i; if (!p->isDead()) { continue; } const ClientId clientId = p->getClientId(); info(LOG_MAP, "player " + p->getName() + " is dead"); p->onDeath(); disconnect(clientId); ++deadPlayers; } return deadPlayers; }
void instance_ahnkahet::HandleInsanitySwitch(Player* pPhasedPlayer) { // Get the phase aura id std::list<Aura*> lAuraList = pPhasedPlayer->GetAurasByType(SPELL_AURA_PHASE); if (lAuraList.empty()) return; uint32 uiPhaseAura = (*lAuraList.begin())->GetId(); PlayerList lSamePhasePlayers; std::vector<Player*> vOtherPhasePlayers; // Sort the insanity players, into those which have same phase and others for (GuidList::const_iterator itr = m_lInsanityPlayersGuidList.begin(); itr != m_lInsanityPlayersGuidList.end(); ++itr) { if (Player* pTemp = instance->GetPlayer(*itr)) { if (pTemp->HasAura(uiPhaseAura)) lSamePhasePlayers.push_back(pTemp); // Check only for alive players else if (pTemp->isAlive()) vOtherPhasePlayers.push_back(pTemp); } } // This shouldn't happen if (vOtherPhasePlayers.empty()) return; // Get the phase aura of the new selected player Player* pNewPlayer = vOtherPhasePlayers[urand(0, vOtherPhasePlayers.size() - 1)]; // Get the phase aura id std::list<Aura*> lNewAuraList = pNewPlayer->GetAurasByType(SPELL_AURA_PHASE); if (lNewAuraList.empty()) return; uint32 uiNewPhaseAura = (*lNewAuraList.begin())->GetId(); // Move the same phase players to the new phase for (PlayerList::const_iterator itr = lSamePhasePlayers.begin(); itr != lSamePhasePlayers.end(); ++itr) (*itr)->CastSpell((*itr), uiNewPhaseAura, TRIGGERED_OLD_TRIGGERED); }
static void *LoaderThreadProc(void *arg) { QBSoundMac* snd = (QBSoundMac*)arg; bool r=false; while (!r) { { QBSoundLocker locker(&snd->mMutex,"threadProc"); PlayerList::iterator it = streamTrack.begin(); while(it != streamTrack.end()) { (*it).second->streamLoad(); ++it; } r = snd->mThreadEnd; } usleep(1000); } return NULL; }
int QBSoundWin::fill_sound_buffer(void* buffer,int size) { QBSoundLocker locker(&mMutex); int r = QBSound::fill_sound_buffer(buffer,size); #ifdef __USE_OGG_VORBIS__ PlayerList::iterator it = streamTrack.begin(); while(it != streamTrack.end()) { if ((*it).second->streamdone && (*it).first > 0) { delete (*it).second; streamTrack.erase(it++); } else { (*it).second->fill_sound_buffer(buffer,size,mMasterVolume); ++it; } } #endif return r; }
void MyAvatarLabel::refreshStars() { QString fontSize("12"); QString fontFamily(myW->getMyGameTableStyle()->getFont1String()); #ifdef _WIN32 fontSize = "10"; if(QSysInfo::windowsVersion() == QSysInfo::WV_XP) { fontFamily = "font-family: \"DejaVu Sans\";"; fontSize = "12"; } #else #ifdef __APPLE__ fontSize = "7"; #else fontSize = "12"; #endif #endif boost::shared_ptr<Game> curGame = myW->myStartWindow->getSession()->getCurrentGame(); PlayerListConstIterator it_c; int seatPlace; PlayerList seatsList = curGame->getSeatsList(); for (seatPlace=0,it_c=seatsList->begin(); it_c!=seatsList->end(); ++it_c, seatPlace++) { for(int i=1; i<=5; i++)myW->playerStarsArray[i][seatPlace]->setText(""); if(myW->myStartWindow->getSession()->getGameType() == Session::GAME_TYPE_INTERNET && !myW->getSession()->getClientPlayerInfo((*it_c)->getMyUniqueID()).isGuest && (*it_c)->getMyType() != PLAYER_TYPE_COMPUTER) { if((*it_c)->getMyStayOnTableStatus() == TRUE && (*it_c)->getMyName()!="" && seatPlace!=0) { int playerStars=getPlayerRating(QString::fromUtf8((*it_c)->getMyName().c_str())); for(int i=1; i<=5; i++) { myW->playerStarsArray[i][seatPlace]->setText("<a style='color: #"+myW->getMyGameTableStyle()->getRatingStarsColor()+"; "+fontFamily+" font-size: "+fontSize+"px; text-decoration: none;' href='"+QString::fromUtf8((*it_c)->getMyName().c_str())+"\""+QString::number(i)+"'>☆</a>"); } for(int i=1; i<=playerStars; i++) { myW->playerStarsArray[i][seatPlace]->setText("<a style='color: #"+myW->getMyGameTableStyle()->getRatingStarsColor()+"; "+fontFamily+" font-size: "+fontSize+"px; text-decoration: none;' href='"+QString::fromUtf8((*it_c)->getMyName().c_str())+"\""+QString::number(i)+"'>★</a>"); } } } } }
void fill_buffers() { if (FD_ISSET(ircSocket, &in_set)) { // Handle the irc happenings read_into_buffer(ircSocket, ircInBuf); } if (FD_ISSET(ircSocket, &out_set)) { // Send that irc shit out! write_from_buffer(ircSocket, ircOutBuf); } // Loop through the players, checking the status, handling the buffers for (PlayerListIterator i = playerList.begin(); i != playerList.end(); ++i) { if ((*i)->socket != NO_SOCKET) { if (FD_ISSET((*i)->socket, &in_set)) { read_into_buffer((*i)->socket, (*i)->in_buf); } if (FD_ISSET((*i)->socket, &out_set)) { write_from_buffer((*i)->socket, (*i)->out_buf); } } } }
void MyAvatarLabel::putPlayerOnIgnoreList() { QStringList list; PlayerListConstIterator it_c; PlayerList seatList = myW->getSession()->getCurrentGame()->getSeatsList(); for (it_c=seatList->begin(); it_c!=seatList->end(); ++it_c) { list << QString::fromUtf8((*it_c)->getMyName().c_str()); } if(!playerIsOnIgnoreList(list.at(myId))) { myMessageDialogImpl dialog(myW->getMyConfig(), this); if(dialog.exec(INGNORE_PLAYER_QUESTION, tr("You will no longer receive chat messages or game invitations from this user.<br>Do you really want to put player <b>%1</b> on ignore list?").arg(list.at(myId)), tr("PokerTH - Question"), QPixmap(":/gfx/im-ban-user_64.png"), QDialogButtonBox::Yes|QDialogButtonBox::No, false ) == QDialog::Accepted) { std::list<std::string> playerIgnoreList = myW->getMyConfig()->readConfigStringList("PlayerIgnoreList"); playerIgnoreList.push_back(list.at(myId).toUtf8().constData()); myW->getMyConfig()->writeConfigStringList("PlayerIgnoreList", playerIgnoreList); myW->getMyConfig()->writeBuffer(); myW->getMyChat()->refreshIgnoreList(); } } }
void QBSoundMac::stopAll() { QBSoundLocker locker(&mMutex,"stopAll"); #ifdef __USE_OGG_VORBIS__ { PlayerList::iterator it = streamTrack.begin(); while(it != streamTrack.end()) { delete (*it).second; ++it; } streamTrack.clear(); } { EffectList::iterator it = effectTrack.begin(); while(it != effectTrack.end()) { delete (*it).second; ++it; } effectTrack.clear(); } #endif return QBSound::stopAll(); }
void MyNameLabel::setText ( const QString &t, bool trans, bool guest, bool computerplayer) { QString text; QColor transColor; transColor.setNamedColor("#"+myW->getMyGameTableStyle()->getPlayerNickTextColor()); QString red = QString::number(transColor.red()); QString green = QString::number(transColor.green()); QString blue = QString::number(transColor.blue()); if(trans) { this->setStyleSheet("QLabel { "+ myW->getMyGameTableStyle()->getFont2String() +" font-size: "+myW->getMyGameTableStyle()->getPlayerNameLabelFontSize()+"px; font-weight: bold; color: rgba("+red+", "+green+", "+blue+", 80); }"); } else { this->setStyleSheet("QLabel { "+ myW->getMyGameTableStyle()->getFont2String() +" font-size: "+myW->getMyGameTableStyle()->getPlayerNameLabelFontSize()+"px; font-weight: bold; color: #"+myW->getMyGameTableStyle()->getPlayerNickTextColor()+"; }"); } if(myW->getSession()) { if(myW->getSession()->getGameType() == Session::GAME_TYPE_INTERNET && !guest && !computerplayer ) { // for internet game show players name with links to their profile included this->setTextFormat(Qt::RichText); QString linkString; GameInfo info(myW->getSession()->getClientGameInfo(myW->getSession()->getClientCurrentGameId())); if(info.data.gameType == GAME_TYPE_RANKING) { QString nickList; //build nick string list if(myW->getSession()->getCurrentGame()) { boost::shared_ptr<Game> currentGame = myW->getSession()->getCurrentGame(); PlayerListConstIterator it_c; PlayerList seatsList = currentGame->getSeatsList(); int playerCounter = 0; for (it_c=seatsList->begin(); it_c!=seatsList->end(); ++it_c) { if((*it_c)->getMyActiveStatus()) { ++playerCounter; nickList += QString("&nick%1=").arg(playerCounter); nickList += QUrl::toPercentEncoding(QString::fromUtf8((*it_c)->getMyName().c_str())); } } } linkString = QString("http://pokerth.net/redirect_user_profile.php?tableview=1"+nickList+"&table="+QUrl::toPercentEncoding(QString::fromUtf8(info.name.c_str()))); } else { linkString = QString("http://pokerth.net/redirect_user_profile.php?nick="+QUrl::toPercentEncoding(t)); } if(trans) { text = "<a style='color: rgba("+red+", "+green+", "+blue+", 80);' href='"+linkString+"'>"+t+"</a>"; } else { text = "<a style='color: #"+myW->getMyGameTableStyle()->getPlayerNickTextColor()+";' href='"+linkString+"'>"+t+"</a>"; } } else { this->setTextFormat(Qt::PlainText); text = t; } } else { text = t; } QLabel::setText(text); }
std::string CardsValue::determineHandName(int myCardsValueInt, PlayerList activePlayerList) { std::list<int> shownCardsValueInt; std::list<int> sameHandCardsValueInt; bool different = false; bool equal = false; // boost::shared_ptr<Game> currentGame = myW->getSession()->getCurrentGame(); PlayerListConstIterator it_c; // PlayerList activePlayerList = currentGame->getActivePlayerList(); // collect cardsValueInt of all players who will show their cards for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); ++it_c) { if( (*it_c)->getMyAction() != PLAYER_ACTION_FOLD) { shownCardsValueInt.push_back( (*it_c)->getMyCardsValueInt()); } } // erase own cardsValueInt std::list<int>::iterator it; for(it = shownCardsValueInt.begin(); it != shownCardsValueInt.end(); ++it) { if((*it) == myCardsValueInt) { shownCardsValueInt.erase(it); break; } } std::list<std::string> cardString = translateCardsValueCode(myCardsValueInt); std::list<std::string>::const_iterator cardStringIt_c = cardString.begin(); std::string handName; switch(myCardsValueInt/100000000) { // Royal Flush case 9: { handName = *cardStringIt_c; } break; // Straight Flush case 8: { handName = *cardStringIt_c; ++cardStringIt_c; handName += *cardStringIt_c; } break; // Four of a kind case 7: { handName = *cardStringIt_c; ++cardStringIt_c; handName += *cardStringIt_c; // same hand detection for(it = shownCardsValueInt.begin(); it != shownCardsValueInt.end(); ++it) { if(((*it)/1000000) == (myCardsValueInt/1000000)) { sameHandCardsValueInt.push_back(*it); } } // 1.same hands existing if(!(sameHandCardsValueInt.empty())) { // first kicker? for(it = sameHandCardsValueInt.begin(); it != sameHandCardsValueInt.end(); ) { if(((*it)/10000) == (myCardsValueInt/10000)) { equal = true; ++it; } else { different = true; it = sameHandCardsValueInt.erase(it); } } if(different) { ++cardStringIt_c; handName += ", fifth card " + *cardStringIt_c; } } } break; // Full House case 6: { handName = *cardStringIt_c; ++cardStringIt_c; handName += *cardStringIt_c; ++cardStringIt_c; handName += *cardStringIt_c; } break; // Flush case 5: { handName = *cardStringIt_c; ++cardStringIt_c; handName += *cardStringIt_c; // same hand detection for(it = shownCardsValueInt.begin(); it != shownCardsValueInt.end(); ++it) { if(((*it)/1000000) == (myCardsValueInt/1000000)) { sameHandCardsValueInt.push_back(*it); } } // 1.same hands existing if(!(sameHandCardsValueInt.empty())) { // first kicker? for(it = sameHandCardsValueInt.begin(); it != sameHandCardsValueInt.end(); ) { if(((*it)/10000) == (myCardsValueInt/10000)) { equal = true; ++it; } else { different = true; it = sameHandCardsValueInt.erase(it); } } ++cardStringIt_c; if(different) { handName += ", second card " + *cardStringIt_c; } // 2.there are still same hands if(equal) { different = false; equal = false; // second kicker? for(it = sameHandCardsValueInt.begin(); it != sameHandCardsValueInt.end(); ) { if(((*it)/100) == (myCardsValueInt/100)) { equal = true; ++it; } else { different = true; it = sameHandCardsValueInt.erase(it); } } ++cardStringIt_c; if(different) { handName += ", third card " + *cardStringIt_c; } // 3.there are still same hands if(equal) { different = false; equal = false; // third kicker? for(it = sameHandCardsValueInt.begin(); it != sameHandCardsValueInt.end(); ) { if(((*it)/10) == (myCardsValueInt/10)) { equal = true; ++it; } else { different = true; it = sameHandCardsValueInt.erase(it); } } ++cardStringIt_c; if(different) { handName += ", fourth card " + *cardStringIt_c; } // 4.there are still same hands if(equal) { different = false; equal = false; // third kicker? for(it = sameHandCardsValueInt.begin(); it != sameHandCardsValueInt.end(); ) { if((*it) == myCardsValueInt) { equal = true; ++it; } else { different = true; it = sameHandCardsValueInt.erase(it); } } if(different) { ++cardStringIt_c; handName += ", fifth card " + *cardStringIt_c; } } } } } } break; // Straight case 4: { handName = *cardStringIt_c; ++cardStringIt_c; handName += *cardStringIt_c; } break; // Three of a kind case 3: { handName = *cardStringIt_c; ++cardStringIt_c; handName += *cardStringIt_c; // same hand detection for(it = shownCardsValueInt.begin(); it != shownCardsValueInt.end(); ++it) { if(((*it)/1000000) == (myCardsValueInt/1000000)) { sameHandCardsValueInt.push_back(*it); } } // 1.same hands existing if(!(sameHandCardsValueInt.empty())) { // first kicker? for(it = sameHandCardsValueInt.begin(); it != sameHandCardsValueInt.end(); ) { if(((*it)/10000) == (myCardsValueInt/10000)) { equal = true; ++it; } else { different = true; it = sameHandCardsValueInt.erase(it); } } ++cardStringIt_c; if(different) { handName += ", fourth card " + *cardStringIt_c; } // 2.there are still same hands if(equal) { different = false; equal = false; // second kicker? for(it = sameHandCardsValueInt.begin(); it != sameHandCardsValueInt.end(); ) { if(((*it)/100) == (myCardsValueInt/100)) { equal = true; ++it; } else { different = true; it = sameHandCardsValueInt.erase(it); } } if(different) { ++cardStringIt_c; handName += ", fifth card " + *cardStringIt_c; } } } } break; // Two Pair case 2: { handName = *cardStringIt_c; ++cardStringIt_c; handName += *cardStringIt_c; ++cardStringIt_c; handName += *cardStringIt_c; // same hand detection for(it = shownCardsValueInt.begin(); it != shownCardsValueInt.end(); ++it) { if(((*it)/10000) == (myCardsValueInt/10000)) { sameHandCardsValueInt.push_back(*it); } } // 1.same hands existing if(!(sameHandCardsValueInt.empty())) { // first kicker? for(it = sameHandCardsValueInt.begin(); it != sameHandCardsValueInt.end(); ) { if(((*it)/100) == (myCardsValueInt/100)) { equal = true; ++it; } else { different = true; it = sameHandCardsValueInt.erase(it); } } if(different) { ++cardStringIt_c; handName += ", fifth card " + *cardStringIt_c; } } } break; // Pair case 1: { handName = *cardStringIt_c; ++cardStringIt_c; handName += *cardStringIt_c; // same hand detection for(it = shownCardsValueInt.begin(); it != shownCardsValueInt.end(); ++it) { if(((*it)/1000000) == (myCardsValueInt/1000000)) { sameHandCardsValueInt.push_back(*it); } } // 1.same hands existing if(!(sameHandCardsValueInt.empty())) { // first kicker? for(it = sameHandCardsValueInt.begin(); it != sameHandCardsValueInt.end(); ) { if(((*it)/10000) == (myCardsValueInt/10000)) { equal = true; ++it; } else { different = true; it = sameHandCardsValueInt.erase(it); } } ++cardStringIt_c; if(different) { handName += ", third card " + *cardStringIt_c; } // 2.there are still same hands if(equal) { different = false; equal = false; // second kicker? for(it = sameHandCardsValueInt.begin(); it != sameHandCardsValueInt.end(); ) { if(((*it)/100) == (myCardsValueInt/100)) { equal = true; ++it; } else { different = true; it = sameHandCardsValueInt.erase(it); } } ++cardStringIt_c; if(different) { handName += ", fourth card " + *cardStringIt_c; } // 3.there are still same hands if(equal) { different = false; equal = false; // third kicker? for(it = sameHandCardsValueInt.begin(); it != sameHandCardsValueInt.end(); ) { if((*it) == myCardsValueInt) { equal = true; ++it; } else { different = true; it = sameHandCardsValueInt.erase(it); } } if(different) { ++cardStringIt_c; handName += ", fifth card " + *cardStringIt_c; } } } } } break; // highestCard case 0: { handName = *cardStringIt_c; ++cardStringIt_c; handName += *cardStringIt_c; // same hand detection for(it = shownCardsValueInt.begin(); it != shownCardsValueInt.end(); ++it) { if(((*it)/1000000) == (myCardsValueInt/1000000)) { sameHandCardsValueInt.push_back(*it); } } // 1.same hands existing if(!(sameHandCardsValueInt.empty())) { // first kicker? for(it = sameHandCardsValueInt.begin(); it != sameHandCardsValueInt.end(); ) { if(((*it)/10000) == (myCardsValueInt/10000)) { equal = true; ++it; } else { different = true; it = sameHandCardsValueInt.erase(it); } } ++cardStringIt_c; if(different) { handName += ", second card " + *cardStringIt_c; } // 2.there are still same hands if(equal) { different = false; equal = false; // second kicker? for(it = sameHandCardsValueInt.begin(); it != sameHandCardsValueInt.end(); ) { if(((*it)/100) == (myCardsValueInt/100)) { equal = true; ++it; } else { different = true; it = sameHandCardsValueInt.erase(it); } } ++cardStringIt_c; if(different) { handName += ", third card " + *cardStringIt_c; } // 3.there are still same hands if(equal) { different = false; equal = false; // third kicker? for(it = sameHandCardsValueInt.begin(); it != sameHandCardsValueInt.end(); ) { if(((*it)/10) == (myCardsValueInt/10)) { equal = true; ++it; } else { different = true; it = sameHandCardsValueInt.erase(it); } } ++cardStringIt_c; if(different) { handName += ", fourth card " + *cardStringIt_c; } // 4.there are still same hands if(equal) { different = false; // third kicker? for(it = sameHandCardsValueInt.begin(); it != sameHandCardsValueInt.end(); ) { if((*it) == myCardsValueInt) { ++it; } else { different = true; it = sameHandCardsValueInt.erase(it); } } if(different) { ++cardStringIt_c; handName += ", fifth card " + *cardStringIt_c; } } } } } } break; default: {} } return handName; }
int main ( int argc, char * const argv[] ) { Crypto *crypto = new Crypto(); bool loggedIn = false; time_t last_ping = time( NULL ); Socket a_socket( crypto ); Socket g_socket( crypto ); GameMap *gameMap = new GameMap( &g_socket ); Dialogue *dialogue = new Dialogue(); MapFile *mapFile = new MapFile(); User *user = new User( &g_socket, gameMap, dialogue, mapFile ); AccountInfo acct_info; std::vector< PET_PACKET > PetList; char path[255]; strcpy( path, GAMEFILESPATH ); strcat( path, "ini/map.ini" ); mapFile->process( path ); initTime(); srand( time( NULL ) ); if ( argc != 2 ) acct_info = account_info( "Whitey" ); else acct_info = account_info( argv[1] ); if ( !strcmp( acct_info.username, "NOTFOUND" ) || !strcmp( acct_info.username, "" ) || !strcmp( acct_info.password, "" ) || !strcmp( acct_info.serverip, "" ) || !strcmp( acct_info.servername, "" ) ) { std::cout << "Error: .account_info.conf must include a username and password, " << "and optionally a server and protection code." << std::endl; } if ( !a_socket.connect( acct_info.serverip, ACCOUNTPORT ) ) return 0; g_socket = login( a_socket, crypto, acct_info ); while ( true ) { g_socket.select(); if ( g_socket.is_readable() ) { CPacket packet; packet = g_socket.read_packet(); if ( packet.header.size == 0 && packet.header.id == 0 ) { std::cout << "Error while reading packet... time: " << timeGetTime() << std::endl; return 0; } if ( difftime( last_ping, time( NULL ) ) > 300 ) return 0; switch ( packet.header.id ) { case 1002: { memset( ( void * )( packet.data + 0x04 ), 0, packet.header.size - sizeof( CPacketHeader ) ); packet.data[8] = 0xC5; g_socket.send_packet( packet ); } break; case 1004: { MessagePacket *msg = new MessagePacket( packet ); if ( msg->m_channel == CH_SYSTEM ) printf( "[%s]%s\n", msg->m_channelName, msg->m_message ); else if ( msg->m_channel == CH_VENDOR ) printf( "[%s](%s): %s\n", msg->m_channelName, msg->m_sender, msg->m_message ); else printf( "[%s]%s %s speaks to %s: %s\n", msg->m_channelName, msg->m_sender, msg->m_emotion, msg->m_target, msg->m_message ); if ( strcmp( msg->m_sender, OWNER ) && msg->m_channel == CH_PRIVATE ) { MessagePacket *fffffu = new MessagePacket( user->m_name, msg->m_sender, "F**k you, stop PMing me.", CH_PRIVATE ); g_socket.send_packet( fffffu->pack() ); delete fffffu; } if ( !strcmp( msg->m_sender, OWNER ) && msg->m_channel == CH_PRIVATE ) { if ( !strcmp( msg->m_message, "@givemoney" ) ) { PlayerList playerlist = gameMap->list_players(); PlayerList::iterator it; for ( it = playerlist.begin(); it != playerlist.end(); it++ ) user->give_money( it->first, 1 ); } } delete msg; } break; case 1005: { WalkPacket *walk = new WalkPacket( packet ); Player *player = gameMap->find_player( walk->m_playerID ); if ( player->m_id == -1 ) { delete player; break; } player->m_x = walk->m_destX; player->m_y = walk->m_destY; //printf( "%s has moved to [%d, %d]\n", PlayerList[id].m_name, x, y ); delete walk; } break; case 1006: { ActionPacket *action = new ActionPacket( packet ); Player *player = gameMap->find_player( action->m_playerID ); if ( player->m_id == -1 ) { delete player; break; } break; switch ( action->m_actionID ) { case 4: printf( "* %s faints.\n", player->m_name ); break; case 6: printf( "* %s waves.\n", player->m_name ); break; case 7: printf( "* %s kneels.\n", player->m_name ); break; case 8: printf( "* %s is crying.\n", player->m_name ); break; case 9: printf( "* %s is angry.\n", player->m_name ); break; case 10: printf( "* %s sits.\n", player->m_name ); break; case 12: printf( "* %s is happy.\n", player->m_name ); break; case 13: printf( "* %s bows.\n", player->m_name ); break; case 15: printf( "* %s throws.\n", player->m_name ); break; default: printf( "* Unknown action preformed by %s [%d]\n", player->m_name, action->m_actionID ); break; } delete action; } break; case 1007: { JumpPacket *jump = new JumpPacket( packet ); Player *player = gameMap->find_player( jump->m_playerID ); if ( player->m_id == -1 ) { delete player; break; } if ( jump->m_mode == 2 ) { player->m_x = jump->m_x; player->m_y = jump->m_y; //printf( "%s has moved to [%d, %d]\n", PlayerList[id].m_name, x, y ); } else if ( jump->m_direction == 8 ) { //printf( "%s has left the map.\n", PlayerList[id].m_name ); printf( "%s has left the map.\n", player->m_name ); char msg[55]; strcpy( msg, "Cya later, " ); strcat( msg, player->m_name ); MessagePacket *bai = new MessagePacket( user->m_name, player->m_name, msg, CH_PRIVATE ); g_socket.send_packet( bai->pack() ); delete bai; gameMap->del_player( jump->m_playerID ); } delete jump; } break; case 1008: { CharInfoPacket *info = new CharInfoPacket( packet ); user->process( info ); user->m_accountID = account_id; delete info; } break; case 1020: { int response = timeGetTime() ^ ( ( user->m_characterID * user->m_characterID ) + 0x2537 ); memcpy( ( void * )( packet.data + 0x04 ), ( void * )&response, sizeof( response ) ); g_socket.send_packet( packet ); } break; case 1031: { MapInfoPacket *info = new MapInfoPacket( packet ); gameMap->process( info ); dialogue->m_open = false; user->m_x = info->m_x; user->m_y = info->m_y; printf( "Entered: %s\n", gameMap->m_name ); if ( !loggedIn ) { user->jump( 0, 0, 19, 0 ); if ( strcmp( acct_info.pcode, "" ) ) { char unlock[255]; strcpy( unlock, "/unlock " ); strcat( unlock, acct_info.pcode ); MessagePacket *umsg = new MessagePacket( user->m_name, user->m_name, unlock, CH_PRIVATE ); g_socket.send_packet( umsg->pack() ); delete umsg; } MessagePacket *pokeman = new MessagePacket( user->m_name, "All", "A wild BlakeKing appears!", CH_NORMAL ); g_socket.send_packet( pokeman->pack() ); delete pokeman; } delete info; } break; case 1032: { Player *player = new Player( packet ); gameMap->add_player( player ); //printf( "%s has entered the map (%d, %d)\n", player.m_name, player.m_x, player.m_y ); if ( loggedIn ) { char msg[55]; strcpy( msg, "Welcome to Water City, " ); strcat( msg, player->m_name ); MessagePacket *hai = new MessagePacket( user->m_name, player->m_name, msg, CH_PRIVATE ); g_socket.send_packet( hai->pack() ); delete hai; } delete player; } break; case 1033: { /*int pet_id = *( int * )packet.data; std::vector< PET_PACKET >::iterator it; for ( it = PetList.begin(); it != PetList.end(); it++ ) if ( it->id == pet_id ) printf( "Marching Pet: %s\n\n", it->name );*/ } break; case 1034: { PET_PACKET pp; memcpy( ( void * )&pp, ( void * )packet.data, ( packet.header.size - sizeof( CPacketHeader ) ) ); PetList.push_back( pp ); } break; case 1038: { last_ping = time( 0 ); if ( !loggedIn ) loggedIn = true; } break; case 1043: { // Has more data that needs to be reversed /* Don't want to write a class for this quite yet, because * I want to see if this packet is used when a player changes * their actual body in the reborn room, or if it's just * for disguising as a pet. */ int id = *( int * )packet.data; Player *player = gameMap->find_player( id ); if ( player->m_id == -1 ) { delete player; break; } //printf( "* %s has disguised as a pet.\n", player->m_name ); } break; case 1050: /* Why don't i have anything for this packet? It's the first * Received packet from the game server... */ break; case 2030: { NpcInfoPacket *info = new NpcInfoPacket( packet ); Npc *npc = new Npc( info ); gameMap->add_npc( npc ); //printf( "* Added NPC: %s (id=%d)(type=%d)\n", npc->m_name, npc->m_id, npc->m_type ); delete info; delete npc; } break; case 2031: { NpcUpdatePacket *update = new NpcUpdatePacket( packet ); if ( update->m_action == 3 ) gameMap->del_npc( update->m_npcID ); delete update; } break; case 2033: { NpcDialoguePacket *dialog = new NpcDialoguePacket( packet ); dialogue->process( dialog ); delete dialog; } break; default: /*printf( "ID: %d Length: %d Data:\n", packet.header.id, packet.header.size ); hexdump( ( void * )packet.data, ( packet.header.size - sizeof( CPacketHeader ) ) ); printf( "\n");*/ break; } } } return 1; }