//Geeft de positie van een element in de array; Enkel noodzakelijk om de database te simuleren int OBanDAO::getPositie(int id) { for(int i = 0; i < bannen.size(); i++) { Ban* temp = bannen.at(i); if(temp->getBanID() == id) return i; } return -1; }
Ban* OBanDAO::getBan(int id) { for(int i =0; i < bannen.size(); i++) { Ban* temp = bannen.at(i); if(temp->getBanID() == id) return temp; } return 0; }
vector<Ban*> OBanDAO::vindBanDoorKlantID(int id) { vector<Ban*> results = vector<Ban*>(); for(int i =0; i < bannen.size(); i++) { Ban* temp = bannen.at(i); if(temp->getBanKlantID() == id){ results.push_back(temp); } } return results; }
bool IOBanSQL::loadBans(const std::string& identifier, Ban& banclass) { Database db; if(!db.connect(m_db.c_str(), m_host.c_str(), m_user.c_str(), m_pass.c_str())){ return false; } DBQuery query; DBResult result; query << "SELECT * FROM bans"; if(!db.storeQuery(query, result)) return true; uint32_t currentTime = std::time(NULL); for(int i=0; i < result.getNumRows(); ++i){ int banType = result.getDataInt("type", i); int time = result.getDataInt("time", i); if(time > currentTime){ switch(banType){ case BAN_IPADDRESS: { int ip = result.getDataInt("ip", i); int mask = result.getDataInt("mask", i); banclass.addIpBan(ip, mask, time); break; } case BAN_PLAYER: { int player = result.getDataInt("player", i); banclass.addPlayerBan(player, time); break; } case BAN_ACCOUNT: { int account = result.getDataInt("account", i); banclass.addAccountBan(account, time); break; } } } } return true; }
Ban* OBanDAO::bewaarBan(Ban* ban) { if(ban->getBanID() == -1) { //Dit is een nieuw adres en simuleert de toekenning van een sequentiële ID door de database Ban* temp = bannen.at(bannen.size()-1); int nieuweID = temp->getBanID()+1; ban->setBanID(nieuweID); } Ban* temp = getBan(ban->getBanID()); if(temp == 0) { bannen.push_back(ban); return ban; } else { //Gebande personen updaten temp->setBanID(ban->getBanID()); temp->setBanVanaf(ban->getBanVanaf()); temp->setBanTot(ban->getBanTot()); temp->setBanKlantID(ban->getBanKlantID()); return temp; } }
bool AdminProtocolConfig::allowIP(uint32_t ip) { if(m_onlyLocalHost) { if(ip != 0x0100007F) //127.0.0.1 { addLogLine(NULL, LOGTYPE_WARNING, 1, std::string("forbidden connection try from ") + convertIPToString(ip)); return false; } else return true; } return !g_bans.isIpDisabled(ip); }
void ServicePort::onAccept(boost::asio::ip::tcp::socket* socket, const boost::system::error_code& error) { if (!error) { if (m_services.empty()) { return; } boost::system::error_code socketError; const boost::asio::ip::tcp::endpoint endpoint = socket->remote_endpoint(socketError); uint32_t remote_ip = 0; if (!socketError) { remote_ip = htonl(endpoint.address().to_v4().to_ulong()); } if (remote_ip != 0 && g_bans.acceptConnection(remote_ip)) { Connection_ptr connection = ConnectionManager::getInstance()->createConnection(socket, m_io_service, shared_from_this()); Service_ptr service = m_services.front(); if (service->is_single_socket()) { connection->acceptConnection(service->make_protocol(connection)); } else { connection->acceptConnection(); } } else if (socket->is_open()) { socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both, socketError); socket->close(socketError); delete socket; } accept(); } else if (error != boost::asio::error::operation_aborted) { if (!m_pendingStart) { close(); m_pendingStart = true; g_scheduler.addEvent(createSchedulerTask(15000, boost::bind(&ServicePort::openAcceptor, boost::weak_ptr<ServicePort>(shared_from_this()), m_serverPort))); } } }
bool IOBanXML::loadBans(const std::string& identifier, Ban& banclass) { xmlDocPtr doc = xmlParseFile(identifier.c_str()); if(doc){ xmlNodePtr root; root = xmlDocGetRootElement(doc); if(xmlStrcmp(root->name,(const xmlChar*)"bans") != 0){ xmlFreeDoc(doc); return false; } xmlNodePtr banNode = root->children; while(banNode){ if(xmlStrcmp(banNode->name,(const xmlChar*)"ban") == 0){ int banType; if(readXMLInteger(banNode, "type", banType) && banType >= BAN_IPADDRESS && banType <= BAN_ACCOUNT){ int time = 0; readXMLInteger(banNode, "time", time); switch(banType){ case BAN_IPADDRESS: { int ip = 0; int mask = 0; if(readXMLInteger(banNode, "ip", ip)){ readXMLInteger(banNode, "mask", ip); banclass.addIpBan(ip, mask, time); } break; } case BAN_PLAYER: { int playerguid = 0; if(readXMLInteger(banNode, "player", playerguid)){ banclass.addPlayerBan(playerguid, time); } break; } case BAN_ACCOUNT: { int account = 0; if(readXMLInteger(banNode, "account", account)){ banclass.addAccountBan(account, time); } break; } } } else{ std::cout << "Warning: [IOBanXML::loadBans] could not load ban" << std::endl; } } banNode = banNode->next; } } return true; }
bool ProtocolLogin::parseFirstPacket(NetworkMessage& msg) { if( #ifndef _CONSOLE !GUI::getInstance()->m_connections || #endif g_game.getGameState() == GAME_STATE_SHUTDOWN) { getConnection()->closeConnection(); return false; } uint32_t clientip = getConnection()->getIP(); /*uint16_t clientos = */msg.GetU16(); uint16_t version = msg.GetU16(); msg.SkipBytes(12); if(version <= 760) { disconnectClient(0x0A, "Only clients with protocol " CLIENT_VERSION_STR " allowed!"); return false; } if(!RSA_decrypt(msg)) { getConnection()->closeConnection(); return false; } uint32_t key[4]; key[0] = msg.GetU32(); key[1] = msg.GetU32(); key[2] = msg.GetU32(); key[3] = msg.GetU32(); enableXTEAEncryption(); setXTEAKey(key); std::string accountName = msg.GetString(); std::string password = msg.GetString(); if(accountName.empty()) { if(g_config.getBoolean(ConfigManager::ACCOUNT_MANAGER)) { accountName = "1"; password = "******"; } else { disconnectClient(0x0A, "Invalid Account Name."); return false; } } if(version < CLIENT_VERSION_MIN || version > CLIENT_VERSION_MAX) { disconnectClient(0x0A, "Only clients with protocol " CLIENT_VERSION_STR " allowed!"); return false; } if(g_game.getGameState() == GAME_STATE_STARTUP) { disconnectClient(0x0A, "Gameworld is starting up. Please wait."); return false; } if(g_game.getGameState() == GAME_STATE_MAINTAIN) { disconnectClient(0x0A, "Gameworld is under maintenance. Please re-connect in a while."); return false; } if(g_bans.isIpDisabled(clientip)) { disconnectClient(0x0A, "Too many connections attempts from this IP. Try again later."); return false; } if(IOBan::getInstance()->isIpBanished(clientip)) { disconnectClient(0x0A, "Your IP is banished!"); return false; } uint32_t serverip = serverIPs[0].first; for(uint32_t i = 0; i < serverIPs.size(); i++) { if((serverIPs[i].first & serverIPs[i].second) == (clientip & serverIPs[i].second)) { serverip = serverIPs[i].first; break; } } Account account = IOLoginData::getInstance()->loadAccount(accountName); if(account.id == 0 || !passwordTest(password, account.password)) { g_bans.addLoginAttempt(clientip, false); disconnectClient(0x0A, "Account name or password is not correct."); return false; } g_bans.addLoginAttempt(clientip, true); OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false); if(output) { TRACK_MESSAGE(output); //Update premium days g_game.updatePremium(account); //Add MOTD output->AddByte(0x14); std::ostringstream ss; ss << g_game.getMotdNum() << "\n" << g_config.getString(ConfigManager::MOTD); output->AddString(ss.str()); //Add char list output->AddByte(0x64); if(g_config.getBoolean(ConfigManager::ACCOUNT_MANAGER) && account.id != 1) { output->AddByte((uint8_t)account.charList.size() + 1); output->AddString("Account Manager"); output->AddString(g_config.getString(ConfigManager::SERVER_NAME)); output->AddU32(serverip); output->AddU16(g_config.getNumber(ConfigManager::GAME_PORT)); } else output->AddByte((uint8_t)account.charList.size()); std::list<std::string>::iterator it, end; for(it = account.charList.begin(), end = account.charList.end(); it != end; ++it) { output->AddString(*it); if(g_config.getBoolean(ConfigManager::ON_OR_OFF_CHARLIST)) { if(g_game.getPlayerByName((*it))) output->AddString("Online"); else output->AddString("Offline"); } else output->AddString(g_config.getString(ConfigManager::SERVER_NAME)); output->AddU32(serverip); output->AddU16(g_config.getNumber(ConfigManager::GAME_PORT)); } //Add premium days if(g_config.getBoolean(ConfigManager::FREE_PREMIUM)) output->AddU16(0xFFFF); //client displays free premium else output->AddU16(account.premiumDays); OutputMessagePool::getInstance()->send(output); } getConnection()->closeConnection(); return true; }
bool ProtocolLogin::parseFirstPacket(NetworkMessage& msg) { if(g_game.getGameState() == GAME_STATE_SHUTDOWN){ getConnection()->closeConnection(); return false; } uint32_t clientip = getConnection()->getIP(); /*uint16_t clientos =*/ msg.GetU16(); uint16_t version = msg.GetU16(); msg.SkipBytes(12); if(version <= 760){ disconnectClient(0x0A, STRING_CLIENT_VERSION); } if(!RSA_decrypt(g_otservRSA, msg)){ getConnection()->closeConnection(); return false; } uint32_t key[4]; key[0] = msg.GetU32(); key[1] = msg.GetU32(); key[2] = msg.GetU32(); key[3] = msg.GetU32(); enableXTEAEncryption(); setXTEAKey(key); uint32_t accnumber = msg.GetU32(); std::string password = msg.GetString(); if(!accnumber){ disconnectClient(0x0A, "You must enter your account number."); return false; } if(version < CLIENT_VERSION_MIN || version > CLIENT_VERSION_MAX){ disconnectClient(0x0A, STRING_CLIENT_VERSION); return false; } if(g_game.getGameState() == GAME_STATE_STARTUP){ disconnectClient(0x0A, "Gameworld is starting up. Please wait."); return false; } if(g_bans.isIpDisabled(clientip)){ disconnectClient(0x0A, "Too many connections attempts from this IP. Try again later."); return false; } if(g_bans.isIpBanished(clientip)){ disconnectClient(0x0A, "Your IP is banished!"); return false; } uint32_t serverip = serverIPs[0].first; for(uint32_t i = 0; i < serverIPs.size(); i++){ if((serverIPs[i].first & serverIPs[i].second) == (clientip & serverIPs[i].second)){ serverip = serverIPs[i].first; break; } } Account account = IOAccount::instance()->loadAccount(accnumber); if(!(accnumber != 0 && account.accnumber == accnumber && passwordTest(password, account.password))){ g_bans.addLoginAttempt(clientip, false); disconnectClient(0x0A, "Please enter a valid account number and password."); return false; } g_bans.addLoginAttempt(clientip, true); OutputMessage* output = OutputMessagePool::getInstance()->getOutputMessage(this, false); //Add MOTD std::stringstream motd; output->AddByte(0x14); motd << g_config.getNumber(ConfigManager::MOTD_NUM) << "\n"; motd << g_config.getString(ConfigManager::MOTD); output->AddString(motd.str()); //Add char list output->AddByte(0x64); output->AddByte((uint8_t)account.charList.size()); std::list<std::string>::iterator it; for(it = account.charList.begin(); it != account.charList.end(); it++){ output->AddString((*it)); output->AddString(g_config.getString(ConfigManager::WORLD_NAME)); output->AddU32(serverip); output->AddU16(g_config.getNumber(ConfigManager::PORT)); } //Add premium days output->AddU16(account.premiumDays);//output->AddU16(0); OutputMessagePool::getInstance()->send(output); getConnection()->closeConnection(); return true; }