void Commands::getInfo(Player* player, const std::string& cmd, const std::string& param) { Player* paramPlayer = g_game.getPlayerByName(param); if (!paramPlayer) { player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "Player not found."); return; } if (player->getAccountType() < paramPlayer->getAccountType()) { player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, "You can not get info about this player."); return; } uint32_t playerIp = paramPlayer->getIP(); std::ostringstream info; info << "Name: " << paramPlayer->name << std::endl << "Access: " << paramPlayer->group->access << std::endl << "Level: " << paramPlayer->level << std::endl << "Magic Level: " << paramPlayer->magLevel << std::endl << "Speed: " << paramPlayer->getSpeed() << std::endl << "Position: " << paramPlayer->getPosition() << std::endl << "IP: " << convertIPToString(playerIp) << std::endl; player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, info.str()); if (playerIp != 0) { PlayerVector vec; for (const auto& it : g_game.getPlayers()) { if (it.second->getIP() != playerIp || it.second == paramPlayer) { continue; } vec.push_back(it.second); } if (!vec.empty()) { std::ostringstream ss; Player* tmpPlayer = vec[0]; ss << "Other players on same IP: " << tmpPlayer->getName() << " [" << tmpPlayer->getLevel() << "]"; for (PlayerVector::size_type i = 1, size = vec.size(); i < size; ++i) { tmpPlayer = vec[i]; ss << ", " << tmpPlayer->getName() << " [" << tmpPlayer->getLevel() << "]"; } ss << "."; player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, ss.str()); } } }
static PlayerVector loadPlayers(const std::string & path){ PlayerVector players; overlayFiles(path); std::vector<Filesystem::AbsolutePath> files = Storage::instance().getFiles(Storage::instance().find(Filesystem::RelativePath(path + "/")), "*" ); std::sort(files.begin(), files.end()); for ( std::vector<Filesystem::AbsolutePath>::iterator it = files.begin(); it != files.end(); it++ ){ try{ // std::string ourPath = (*it).path(); Filesystem::AbsolutePath ourPath = it->join(Filesystem::RelativePath(it->getLastComponent() + ".txt")); // Global::debug(2, PAINTOWN_DEBUG_CONTEXT) << "Found file " << ourPath << std::endl; // std::string file = ourPath + "/" + ourPath.substr(ourPath.find_last_of('/') + 1) + ".txt"; players.push_back(getPlayer(ourPath)); } catch (const LoadException & le){ Global::debug(0, PAINTOWN_DEBUG_CONTEXT) << "Could not load because " << le.getTrace() << std::endl; } } return players; }
void House::removePlayers(bool ignoreInvites) { PlayerVector kickList; for(HouseTileList::iterator it = houseTiles.begin(); it != houseTiles.end(); ++it) { CreatureVector* creatures = (*it)->getCreatures(); if(!creatures) continue; Player* player = nullptr; for(CreatureVector::iterator cit = creatures->begin(); cit != creatures->end(); ++cit) { if((player = (*cit)->getPlayer()) && !player->isRemoved() && (ignoreInvites || !isInvited(player))) kickList.push_back(player); } } if(kickList.empty()) return; for(PlayerVector::iterator it = kickList.begin(); it != kickList.end(); ++it) removePlayer((*it), false); }
void House::setHouseOwner(uint32_t guid, bool updateDatabase/* = true*/, Player* player/* = NULL*/) { if (updateDatabase) { Database* db = Database::getInstance(); std::ostringstream query; query << "UPDATE `houses` SET `owner` = " << guid << " WHERE `id` = " << houseid; db->executeQuery(query.str()); } if (isLoaded && houseOwner == guid) { return; } isLoaded = true; if (houseOwner) { //send items to depot if (player) { transferToDepot(player); } else { transferToDepot(); } PlayerVector toKick; for (HouseTileList::iterator it = houseTiles.begin(); it != houseTiles.end(); ++it) { if (const CreatureVector* creatures = (*it)->getCreatures()) { for (CreatureVector::const_iterator cit = creatures->begin(), cend = creatures->end(); cit != cend; ++cit) { Player* player = (*cit)->getPlayer(); if (player) { toKick.push_back(player); } } } } while (!toKick.empty()) { Player* c = toKick.back(); toKick.pop_back(); kickPlayer(NULL, c->getName()); } // we need to remove players from beds HouseBedItemList::iterator bit; for (bit = bedsList.begin(); bit != bedsList.end(); ++bit) { if ((*bit)->getSleeper() != 0) { (*bit)->wakeUp(NULL); } } //clean access lists houseOwner = 0; setAccessList(SUBOWNER_LIST, ""); setAccessList(GUEST_LIST, ""); for (HouseDoorList::iterator it = doorList.begin(); it != doorList.end(); ++it) { (*it)->setAccessList(""); } //reset paid date paidUntil = 0; rentWarnings = 0; } std::string name; if (guid != 0 && IOLoginData::getInstance()->getNameByGuid(guid, name)) { houseOwner = guid; houseOwnerName = name; } updateDoorDescription(); }
void ProtocolLogin::onRecvFirstMessage(NetworkMessage& msg) { if( #if defined(WINDOWS) && !defined(_CONSOLE) !GUI::getInstance()->m_connections || #endif g_game.getGameState() == GAMESTATE_SHUTDOWN) { getConnection()->close(); return; } uint32_t clientIp = getConnection()->getIP(); msg.get<uint16_t>(); uint16_t version = msg.get<uint16_t>(); msg.skip(12); #ifdef _MULTIPLATFORM77 if(!RSA_decrypt(msg)) { getConnection()->close(); return; } uint32_t key[4] = {msg.get<uint32_t>(), msg.get<uint32_t>(), msg.get<uint32_t>(), msg.get<uint32_t>()}; enableXTEAEncryption(); setXTEAKey(key); #endif uint32_t name = msg.get<uint32_t>(); std::string password = msg.getString(); if(!name) { name = 10; } if(!g_config.getBool(ConfigManager::MANUAL_ADVANCED_CONFIG)) { if(version < CLIENT_VERSION_MIN || version > CLIENT_VERSION_MAX) { disconnectClient(0x0A, CLIENT_VERSION_STRING); return; } else if(version < g_config.getNumber(ConfigManager::VERSION_MIN) || version > g_config.getNumber(ConfigManager::VERSION_MAX)) { disconnectClient(0x0A, g_config.getString(ConfigManager::VERSION_MSG).c_str()); return; } } #ifdef CLIENT_VERSION_DATA if(sprSignature != CLIENT_VERSION_SPR) { disconnectClient(0x0A, CLIENT_VERSION_DATA); return; } if(datSignature != CLIENT_VERSION_DAT) { disconnectClient(0x0A, CLIENT_VERSION_DATA); return; } if(picSignature != CLIENT_VERSION_PIC) { disconnectClient(0x0A, CLIENT_VERSION_DATA); return; } #endif if(g_game.getGameState() < GAMESTATE_NORMAL) { disconnectClient(0x0A, "Server is just starting up, please wait."); return; } if(g_game.getGameState() == GAMESTATE_MAINTAIN) { disconnectClient(0x0A, "Server is under maintenance, please re-connect in a while."); return; } if(ConnectionManager::getInstance()->isDisabled(clientIp, protocolId)) { disconnectClient(0x0A, "Too many connections attempts from your IP address, please try again later."); return; } if(IOBan::getInstance()->isIpBanished(clientIp)) { disconnectClient(0x0A, "Your IP is banished!"); return; } uint32_t id = 1; if(!IOLoginData::getInstance()->getAccountId(name, id)) { ConnectionManager::getInstance()->addAttempt(clientIp, protocolId, false); disconnectClient(0x0A, "Invalid account id."); return; } Account account = IOLoginData::getInstance()->loadAccount(id); if (name != 10 && !encryptTest(account.salt + password, account.password)) { ConnectionManager::getInstance()->addAttempt(clientIp, protocolId, false); disconnectClient(0x0A, "Invalid password."); return; } Ban ban; ban.value = account.number; ban.type = BAN_ACCOUNT; if(IOBan::getInstance()->getData(ban) && !IOLoginData::getInstance()->hasFlag(account.number, PlayerFlag_CannotBeBanned)) { bool deletion = ban.expires < 0; std::string name_ = "Automatic "; if(!ban.adminId) name_ += (deletion ? "deletion" : "banishment"); else IOLoginData::getInstance()->getNameByGuid(ban.adminId, name_, true); std::stringstream ss; ss << "Your account has been " << (deletion ? "deleted" : "banished") << " at:\n" << formatDateEx(ban.added, "%d %b %Y").c_str() << " by: " << name_.c_str() << "\nReason:\n" << getReason(ban.reason).c_str() << ".\nComment:\n" << ban.comment.c_str() << ".\nYour " << (deletion ? "account won't be undeleted" : "banishment will be lifted at:\n") << (deletion ? "" : formatDateEx(ban.expires).c_str()); disconnectClient(0x0A, ss.str().c_str()); return; } // remove premium days #ifndef __LOGIN_SERVER__ IOLoginData::getInstance()->removePremium(account); if(account.name != "10" && !g_config.getBool(ConfigManager::ACCOUNT_MANAGER) && !account.charList.size()) { disconnectClient(0x0A, std::string("This account does not contain any character yet.\nCreate a new character on the " + g_config.getString(ConfigManager::SERVER_NAME) + " website at " + g_config.getString(ConfigManager::URL) + ".").c_str()); return; } #else Characters charList; for(Characters::iterator it = account.charList.begin(); it != account.charList.end(); ++it) { if(version >= it->second.server->getVersionMin() && version <= it->second.server->getVersionMax()) charList[it->first] = it->second; } IOLoginData::getInstance()->removePremium(account); if(account.name != "10" && !g_config.getBool(ConfigManager::ACCOUNT_MANAGER) && !charList.size()) { disconnectClient(0x0A, std::string("This account does not contain any character on this client yet.\nCreate a new character on the " + g_config.getString(ConfigManager::SERVER_NAME) + " website at " + g_config.getString(ConfigManager::URL) + ".").c_str()); return; } #endif ConnectionManager::getInstance()->addAttempt(clientIp, protocolId, true); if(OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false)) { TRACK_MESSAGE(output); output->put<char>(0x14); uint32_t serverIp = serverIps.front().first; for(std::list<std::pair<uint32_t, uint32_t> >::iterator it = serverIps.begin(); it != serverIps.end(); ++it) { if((it->first & it->second) != (clientIp & it->second)) continue; serverIp = it->first; break; } char motd[1300]; sprintf(motd, "%d\n%s", g_game.getMotdId(), g_config.getString(ConfigManager::MOTD).c_str()); output->putString(motd); //Add char list output->put<char>(0x64); if(account.name == "10" && account.name != "0") { PlayerVector players; for(AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it) { if(!it->second->isRemoved() && it->second->client->isBroadcasting()) players.push_back(it->second); } std::sort(players.begin(), players.end(), Player::sort); output->put<char>(players.size()); for(PlayerVector::iterator it = players.begin(); it != players.end(); ++it) { std::stringstream s; s << (*it)->getLevel(); if(!(*it)->client->check(password)) s << "*"; output->putString((*it)->getName()); output->putString(s.str()); output->put<uint32_t>(serverIp); output->put<uint16_t>(g_config.getNumber(ConfigManager::GAME_PORT)); } } else { if(g_config.getBool(ConfigManager::ACCOUNT_MANAGER) && account.number != 1) { output->put<char>(account.charList.size() + 1); output->putString("Account Manager"); output->putString(g_config.getString(ConfigManager::SERVER_NAME)); output->put<uint32_t>(serverIp); output->put<uint16_t>(g_config.getNumber(ConfigManager::GAME_PORT)); } else output->put<char>((uint8_t)account.charList.size()); #ifndef __LOGIN_SERVER__ for(Characters::iterator it = account.charList.begin(); it != account.charList.end(); ++it) { output->putString((*it)); if(g_config.getBool(ConfigManager::ON_OR_OFF_CHARLIST) && !g_config.getBool(ConfigManager::CHARLIST_INFO)) { if(g_game.getPlayerByName((*it))) output->putString("Online"); else output->putString("Offline"); } else if(g_config.getBool(ConfigManager::CHARLIST_INFO)) { std::stringstream str; Player *player = g_game.getPlayerByName((*it)); bool v = false; if(g_config.getBool(ConfigManager::ON_OR_OFF_CHARLIST)) { if(player) str << "On"; else str << "Off"; str << "/"; } if(!player) { v = true; player = g_game.getPlayerByNameEx((*it)); } str << player->getLevel(); str << "/"; str << player->getVocation()->getName(); output->putString(str.str()); if(v) delete player; } else output->putString(g_config.getString(ConfigManager::SERVER_NAME)); output->put<uint32_t>(serverIp); output->put<uint16_t>(g_config.getNumber(ConfigManager::GAME_PORT)); } #else for(Characters::iterator it = charList.begin(); it != charList.end(); ++it) { output->putString(it->second.name); if(!g_config.getBool(ConfigManager::ON_OR_OFF_CHARLIST) || it->second.status < 0) output->putString(it->second.server->getName()); else if(it->second.status) output->putString("Online"); else output->putString("Offline"); output->put<uint32_t>(it->second.server->getAddress()); IntegerVec games = it->second.server->getPorts(); output->put<uint16_t>(games[random_range(0, games.size() - 1)]); } #endif } //Add premium days if(g_config.getBool(ConfigManager::FREE_PREMIUM)) output->put<uint16_t>(GRATIS_PREMIUM); else output->put<uint16_t>(account.premiumDays); OutputMessagePool::getInstance()->send(output); } getConnection()->close(); }