Créditos a Strider
Ai está o código do Ruly the account manager:
Em Game.cpp, na inclusão dos headers, inclua ioaccount.h:
#ifdef YUR_LOGIN_QUEUEif (!p || c->access >= g_config.ACCESS_ENTER || #ifdef YUR_PREMIUM_PROMOTION (p->premmium == true && !g_config.QUEUE_PREMMY) ||#endif //YUR_PREMIUM_PROMOTION loginQueue.login(p->accountNumber, getPlayersOnline(), max_players, placeInQueue)) {#else //YUR_LOGIN_QUEUEif (!p || c->access >= g_config.ACCESS_ENTER || getPlayersOnline() < max_players
Adicione:
void Game::updateTile(const Position& pos){SpectatorVec list;SpectatorVec::iterator i;getSpectators(Range(pos), list);for(i = list.begin(); i != list.end(); ++i)(*i)->onTileUpdated(pos);}#endif //SG_LVLDOOR#ifdef TLM_BEDbool Game::loadBeds(std::string file) { xmlDocPtr doc; doc = xmlParseFile(file.c_str()); if (doc){ xmlNodePtr root, p, tmp; root = xmlDocGetRootElement(doc); if (xmlStrcmp(root->name, (const xmlChar*)"beds")) { xmlFreeDoc(doc); return -1; } tmp = root->children; int x,y,z,id; while(tmp){ if (strcmp((char*) tmp->name, "bed")==0){ x = atoi((const char*) xmlGetProp(tmp, (const xmlChar*) "x")); y = atoi((const char*) xmlGetProp(tmp, (const xmlChar*) "y")); z = atoi((const char*) xmlGetProp(tmp, (const xmlChar*) "z")); id = atoi((const char*) xmlGetProp(tmp, (const xmlChar*) "id")); Position mainPos(x, y, z); Item *mainItem = Item::CreateItem(id); Tile *mainTile = getTile(mainPos.x, mainPos.y, mainPos.z); if (mainTile && mainItem){ Position nextPos(x, y, z); Item *nextItem = Item::CreateItem(id+1); if (id == BED_ID1 || id == BED_ID3 || id == BED_ID7 || id == BED_ID8){ nextPos.y++; } else if(id == BED_ID2 || id == BED_ID4 || id == BED_ID9 || id == BED_ID10){ nextPos.x++; } Tile *nextTile = getTile(nextPos.x, nextPos.y, nextPos.z); if (nextTile && nextItem){ mainTile->addThing(mainItem); mainItem->pos = mainPos; nextTile->addThing(nextItem); nextItem->pos = nextPos; } } } tmp = tmp->next; } xmlFreeDoc(doc); return 0; } return -1;}std::string Game::getBedSleeper(const Position pos){ std::string file="data/world/beds.xml"; xmlDocPtr doc; doc = xmlParseFile(file.c_str()); if (doc){ xmlNodePtr root, tmp; root = xmlDocGetRootElement(doc); if (xmlStrcmp(root->name, (const xmlChar*)"beds")) { xmlFreeDoc(doc); return "Nobody"; } tmp = root->children; while(tmp){ if (strcmp((const char*) tmp->name, "bed")==0){ int x = atoi((const char*) xmlGetProp(tmp, (const xmlChar*) "x")); int y = atoi((const char*) xmlGetProp(tmp, (const xmlChar*) "y")); int z = atoi((const char*) xmlGetProp(tmp, (const xmlChar*) "z")); if (x == pos.x && y == pos.y && z == pos.z){ return (const char*)xmlGetProp(tmp, (const xmlChar *)"name"); } } tmp = tmp->next; } xmlFreeDoc(doc); } return "Nobody";}unsigned int Game::getBedID(const Position pos){ std::string file="data/world/beds.xml"; xmlDocPtr doc; doc = xmlParseFile(file.c_str()); if (doc){ xmlNodePtr root, tmp; root = xmlDocGetRootElement(doc); if (xmlStrcmp(root->name, (const xmlChar*)"beds")) { xmlFreeDoc(doc); return 0; } tmp = root->children; while(tmp){ if (strcmp((const char*) tmp->name, "bed")==0){ int x = atoi((const char*) xmlGetProp(tmp, (const xmlChar*) "x")); int y = atoi((const char*) xmlGetProp(tmp, (const xmlChar*) "y")); int z = atoi((const char*) xmlGetProp(tmp, (const xmlChar*) "z")); if (x == pos.x && y == pos.y && z == pos.z){ return atoi((const char*) xmlGetProp(tmp, (const xmlChar*) "id")); } } tmp = tmp->next; } xmlFreeDoc(doc); } return 0;}bool Game::changeBed(const Position pos, unsigned int oldid, std::string sleepname){ Tile *maintile = getTile(pos.x,pos.y,pos.z); Item *mainitem = dynamic_cast<Item*>(maintile->getThingByStackPos(maintile->getThingCount()-1)); if (mainitem && maintile->isPz()){ Position tilePos(pos.x, pos.y, pos.z); if (oldid == BED_ID1 || oldid == BED_ID3 || oldid == BED_ID7 || oldid == BED_ID8){ tilePos.y++; } else if(oldid == BED_ID2 || oldid == BED_ID4 || oldid == BED_ID9 || oldid == BED_ID10){ tilePos.x++; } Tile *nexttile = getTile(tilePos.x,tilePos.y,tilePos.z); Item *nextitem = dynamic_cast<Item*>(nexttile->getThingByStackPos(maintile->getThingCount()-1)); if (nextitem && nexttile->isPz()){ if (oldid == BED_ID1 || oldid == BED_ID3){ mainitem->setID(oldid+8); } else if(oldid == BED_ID2){ mainitem->setID(BED_ID10); } else if(oldid == BED_ID4){ mainitem->setID(BED_ID9); } else if(oldid == BED_ID7 || oldid == BED_ID8){ mainitem->setID(oldid-8); } else if(oldid == BED_ID9){ mainitem->setID(BED_ID4); } else if(oldid == BED_ID10){ mainitem->setID(BED_ID2); } nextitem->setID(mainitem->getID()+1); SpectatorVec list; SpectatorVec::iterator it; getSpectators(Range(tilePos, true), list); //players for(it = list.begin(); it != list.end(); ++it) { if(dynamic_cast<Player*>(*it)) { (*it)->onTileUpdated(pos); (*it)->onTileUpdated(tilePos); } } //Player *player = dynamic_cast<Player*>(player); //player->onTileUpdated(pos); //player->onTileUpdated(tilePos); std::string file="data/world/beds.xml"; xmlDocPtr doc; doc = xmlParseFile(file.c_str()); if (doc){ xmlNodePtr root, tmp; root = xmlDocGetRootElement(doc); if (xmlStrcmp(root->name, (const xmlChar*)"beds")) { xmlFreeDoc(doc); return false; } Position bedPos[1000];// 1000 = number of beds unsigned int id[1000]; std::string name[1000]; int i = 0; tmp = root->children; while(tmp){ if (strcmp((const char*) tmp->name, "bed")==0){ i++; bedPos[i].x = atoi((const char*) xmlGetProp(tmp, (const xmlChar*) "x" )); bedPos[i].y = atoi((const char*) xmlGetProp(tmp, (const xmlChar*) "y" )); bedPos[i].z = atoi((const char*) xmlGetProp(tmp, (const xmlChar*) "z" )); id[i] = atoi((const char*) xmlGetProp(tmp, (const xmlChar*) "id" )); name[i] = (const char*) xmlGetProp(tmp, (const xmlChar*) "name"); if (bedPos[i] == pos){ id[i] = mainitem->getID(); name[i] = sleepname; } } tmp = tmp->next; } doc = xmlNewDoc((const xmlChar*)"1.0"); doc->children = xmlNewDocNode(doc, NULL, (const xmlChar*)"beds", NULL); root = doc->children; std::stringstream sb; for(int x = 1; x <= i; x++){ tmp = xmlNewNode(NULL,(const xmlChar*)"bed"); sb << bedPos[x].x; xmlSetProp(tmp, (const xmlChar*) "x" , (const xmlChar*)sb.str().c_str()); sb.str(""); sb << bedPos[x].y; xmlSetProp(tmp, (const xmlChar*) "y" , (const xmlChar*)sb.str().c_str()); sb.str(""); sb << bedPos[x].z; xmlSetProp(tmp, (const xmlChar*) "z" , (const xmlChar*)sb.str().c_str()); sb.str(""); sb << id[x]; xmlSetProp(tmp, (const xmlChar*) "id", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << name[x]; xmlSetProp(tmp, (const xmlChar*) "name", (const xmlChar*)sb.str().c_str()); sb.str(""); xmlAddChild(root, tmp); } xmlSaveFile(file.c_str(), doc); xmlFreeDoc(doc); return true; }return false;}}}Position Game::getBedPos(std::string name){ std::string file="data/world/beds.xml"; xmlDocPtr doc; doc = xmlParseFile(file.c_str()); if (doc){ xmlNodePtr root, tmp; root = xmlDocGetRootElement(doc); if (xmlStrcmp(root->name, (const xmlChar*)"beds")) { xmlFreeDoc(doc); return Position(0xFFFF,0xFFFF,0xFF); } tmp = root->children; while(tmp){ if (strcmp((const char*) tmp->name, "bed")==0){ std::string sleepname = (const char*)xmlGetProp(tmp, (const xmlChar *)"name"); if (sleepname == name){ int x = atoi((const char*) xmlGetProp(tmp, (const xmlChar*) "x")); int y = atoi((const char*) xmlGetProp(tmp, (const xmlChar*) "y")); int z = atoi((const char*) xmlGetProp(tmp, (const xmlChar*) "z")); return Position(x,y,z); } } tmp = tmp->next; } xmlFreeDoc(doc); } return Position(0xFFFF,0xFFFF,0xFF);}#endif
Adicione:
#ifdef RULY_ACCMANAGERvoid Game::accCreator(Player* player, std::string &text){ player->onCreatureSay(player, SPEAK_SAY, text); if(player->managerActive == 0){ if(text == "hi" || text == "hello") { player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Hello dude, how are you feeling today?"); player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: If you want to continue, just type \"account\"."); return; } else if(text == "account") { player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Ok, feel free to type the account that you wish!"); player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Fique a vontade para digitar a sua conta."); player->managerActive = 1; return; } else{ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Sorry, i cant understand this, can you type again?"); player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Desculpe, eu não entendo. Pode digitar novamente?"); return; } } if(player->managerActive == 1) { if(player->willSayYesOrNo == 0){ bool okj = false; if(text.length() >= 8 || text.length() <= 4) { player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Your account must have more than 4 digits and less than 8."); return; } for(int i = 0; i < text.length(); i++){ if(isdigit(text[i])) okj = true; else{ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: You must type only numbers."); return; } } if(okj){ std::string filename="data/accounts/"+text+".xml"; //std::transform (filename.begin(),filename.end(), filename.begin(), tolower); std::ifstream ifile; ifile.open(filename.c_str()); // Passing the return value of a function to another function if (ifile){ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Sorry, this account already exist =(. Type another account."); } else{ std::stringstream msg; msg << "Ruly the Acc Manager: So, do you want "<<text<<" as your account?"; player->sendTextMessage(MSG_BLUE_TEXT, msg.str().c_str()); player->willSayYesOrNo = 1; player->newAcc = text; } ifile.close(); return; } } if(player->willSayYesOrNo == 1){ if(text == "yes"){ player->managerActive = 3; player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Ok, please type a password."); player->willSayYesOrNo = 0; return; } else if(text == "no"){ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Ok..."); player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: If you want to continue, just type \"account\"."); player->willSayYesOrNo = 0; player->managerActive = 0; return; } else{ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Sorry, invalid command."); player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: If you want to continue, just type \"account\"."); player->willSayYesOrNo = 0; player->managerActive = 0; return; } } } if(player->managerActive == 2){ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: You alredy created your account. Please log off from this manager and log using your account and password."); player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Você já criou a sua conta. Por favor saia desse gerenciador e entre com a sua conta e a sua senha."); return; } if(player->managerActive == 3){ if(player->passIsOk == 0){ std::stringstream msg; msg << "Ruly the Acc Manager: So, do you want "<<text<<" as your password?"; player->sendTextMessage(MSG_BLUE_TEXT, msg.str().c_str()); player->newPass = text; player->passIsOk = 1; return; } if(player->passIsOk == 1){ if(text == "yes"){ //Create Account std::string filename = "data/accounts/"+player->newAcc+".xml"; std::stringstream sb; xmlDocPtr doc; xmlMutexLock(xmlmutex); xmlNodePtr nn, sn, pn, root; doc = xmlNewDoc((const xmlChar*)"1.0"); doc->children = xmlNewDocNode(doc, NULL, (const xmlChar*)"account", NULL); root = doc->children; //xmlSetProp(root, (const xmlChar*) "pass", (const xmlChar*)"manager01"); sb.str(""); sb << player->newPass;xmlSetProp(root, (const xmlChar*) "pass", (const xmlChar*)sb.str().c_str()); sb.str(""); xmlSetProp(root, (const xmlChar*) "type", (const xmlChar*)"1"); sb.str(""); xmlSetProp(root, (const xmlChar*) "premDays", (const xmlChar*)"0"); sb.str(""); sb.str(""); sb << player->newAcc; sn = xmlNewNode(NULL,(const xmlChar*)"characters"); pn = xmlNewNode(NULL,(const xmlChar*)"character"); //xmlSetProp(pn, (const xmlChar*) "name", (const xmlChar*)"Trs Manager"); xmlSetProp(pn, (const xmlChar*) "name", (const xmlChar*)sb.str().c_str()); xmlAddChild(sn, pn); xmlAddChild(root, sn); if (xmlSaveFile(filename.c_str(), doc)) { #ifdef __DEBUG__ std::cout << ":: Accound Created!\n"; #endif xmlFreeDoc(doc); xmlMutexUnlock(xmlmutex); //return; } else { std::cout << "\tCouldn't save character =(\n"; xmlFreeDoc(doc); xmlMutexUnlock(xmlmutex); player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Ops, we had a problem...Please start all again."); player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Ops, nós temos um problema, não foi possível criar a sua conta. Por favor reinicie todo o processo."); player->managerActive = 1; return; } //Step to create the personal acc manager player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Ok, your account has been created. Relog using your account and password."); player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Você já criou a sua conta. Por favor saia desse gerenciador e entre com a sua conta e a sua senha."); player->passIsOk = 0; player->managerActive = 2; std::cout << " New Account Created: " << player->newAcc << "." << std::endl; doSavePlayer(player); return; } else if(text == "no"){ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Type another password then..."); player->passIsOk = 0; return; } else{ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Sorry I cant understand this..."); player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Type another password then..."); player->passIsOk = 0; return; } } } }bool Game::doSavePlayer(Player* player){ std::string filename2 = "data/players/"+player->newAcc+".xml"; std::stringstream sb; xmlDocPtr doc; xmlMutexLock(xmlmutex); xmlNodePtr nn, sn, pn, root; doc = xmlNewDoc((const xmlChar*)"1.0"); doc->children = xmlNewDocNode(doc, NULL, (const xmlChar*)"player", NULL); root = doc->children; sb << player->newAcc; xmlSetProp(root, (const xmlChar*) "name", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << player->newAcc; xmlSetProp(root, (const xmlChar*) "account", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << "1"; xmlSetProp(root, (const xmlChar*) "sex", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << "2"; xmlSetProp(root, (const xmlChar*) "lookdir", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << "0"; xmlSetProp(root, (const xmlChar*) "exp", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << "0"; xmlSetProp(root, (const xmlChar*) "voc", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << "1"; xmlSetProp(root, (const xmlChar*) "level", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << "0"; xmlSetProp(root, (const xmlChar*) "access", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << "300"; xmlSetProp(root, (const xmlChar*) "cap", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << "0"; xmlSetProp(root, (const xmlChar*) "maglevel", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << "0"; xmlSetProp(root, (const xmlChar*) "vipsize", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << "1"; xmlSetProp(root, (const xmlChar*) "lastlogin", (const xmlChar*)sb.str().c_str()); sb.str(""); pn = xmlNewNode(NULL,(const xmlChar*)"spawn"); sb << "207"; xmlSetProp(pn, (const xmlChar*) "x", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << "26"; xmlSetProp(pn, (const xmlChar*) "y", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << "7"; xmlSetProp(pn, (const xmlChar*) "z", (const xmlChar*)sb.str().c_str()); sb.str(""); xmlAddChild(root, pn); pn = xmlNewNode(NULL,(const xmlChar*)"temple"); sb << "207"; xmlSetProp(pn, (const xmlChar*) "x", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << "26"; xmlSetProp(pn, (const xmlChar*) "y", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << "7"; xmlSetProp(pn, (const xmlChar*) "z", (const xmlChar*)sb.str().c_str()); sb.str(""); xmlAddChild(root, pn); pn = xmlNewNode(NULL,(const xmlChar*)"health"); sb << "100"; xmlSetProp(pn, (const xmlChar*) "now", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << "100"; xmlSetProp(pn, (const xmlChar*) "max", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << "0"; xmlSetProp(pn, (const xmlChar*) "food", (const xmlChar*)sb.str().c_str()); sb.str(""); xmlAddChild(root, pn); pn = xmlNewNode(NULL,(const xmlChar*)"mana"); sb << 100; xmlSetProp(pn, (const xmlChar*) "now", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << 100; xmlSetProp(pn, (const xmlChar*) "max", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << 0; xmlSetProp(pn, (const xmlChar*) "spent", (const xmlChar*)sb.str().c_str()); sb.str(""); xmlAddChild(root, pn); pn = xmlNewNode(NULL,(const xmlChar*)"look"); sb << 73; xmlSetProp(pn, (const xmlChar*) "type", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << 50; xmlSetProp(pn, (const xmlChar*) "head", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << 50; xmlSetProp(pn, (const xmlChar*) "body", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << 50; xmlSetProp(pn, (const xmlChar*) "legs", (const xmlChar*)sb.str().c_str()); sb.str(""); sb << 50; xmlSetProp(pn, (const xmlChar*) "feet", (const xmlChar*)sb.str().c_str()); sb.str(""); xmlAddChild(root, pn); //Save the character if (xmlSaveFile(filename2.c_str(), doc)) { #ifdef __DEBUG__ std::cout << "\tSaved character succefully!\n"; #endif xmlFreeDoc(doc); xmlMutexUnlock(xmlmutex); return true; } else { std::cout << "\tCouldn't save character =(\n"; xmlFreeDoc(doc); xmlMutexUnlock(xmlmutex); return false; }}void Game::accManager(Player* player, std::string &text){ player->onCreatureSay(player, SPEAK_SAY, text); if(player->managerActive == 0){ if(text == "character"){ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Please type your new char name."); player->managerActive = 1; return; } if(text == "password"){ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Sorry, you cant change password."); player->managerActive == 1; return; } } if(player->managerActive == 1){ bool okj = false; if(text.length() > 15 || text.length() < 1) { player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Your name must have more than 1 char, and less than 15."); return; } for(int i = 0; i <= text.length(); i++){ if(!isdigit(text[i])) okj = true; else{ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: You can't type numbers on your name."); return; } }for(int i=0; i <= text.length(); i++){ if((text[i] == 'g' && text[i+1] == 'm') || (text[i] == 'g' && text[i+1] == 'M') || (text[i] == 'G' && text[i+1] == 'm') || (text[i] == 'G' && text[i+1] == 'M') || (text[i] == 't' && text[i+1] == 'r') || (text[i] == 'T' && text[i+1] == 'r') || (text[i] == 't' && text[i+1] == 'R') || (text[i] == 'T' && text[i+1] == 'R') || (text[i] == 'f' && text[i+1] == 'u' && text[i+2] == 'c' && text[i+3] == 'k') || (text[i] == 'F' && text[i+1] == 'U' && text[i+2] == 'C' && text[i+3] == 'K') || (text[i] == 'F' && text[i+1] == 'u' && text[i+2] == 'c' && text[i+3] == 'k') || (text[i] == 's' && text[i+1] == 'h' && text[i+2] == 'i' && text[i+3] == 't') || (text[i] == 'b' && text[i+1] == 'i' && text[i+2] == 't' && text[i+3] == 'c' && text[i+4] == 'h') || (text[i] == 'B' && text[i+1] == 'i' && text[i+2] == 't' && text[i+3] == 'c' && text[i+4] == 'h') || (text[i] == '~') || (text[i] == '.') || (text[i] == ';') || (text[i] == '\\') || (text[i] == '/') || (text[i] == '?') || (text[i] == ',') || (text[i] == '<') || (text[i] == '>') || (text[i] == '(') || (text[i] == ')') || (text[i] == '-') || (text[i] == '_') || (text[i] == '=') || (text[i] == '[') || (text[i] == ']') || (text[i] == '{') || (text[i] == '}') || (text[i] == '|') || (text[i] == '`') || (text[i] == '*') || (text[i] == '&') || (text[i] == '^') || (text[i] == '%') || (text[i] == '$') || (text[i] == '#') || (text[i] == '@') || (text[i] == '!')){ player->sendTextMessage(MSG_RED_TEXT, "Ruly the Acc Manager: Your name violates the name rules.\nPlease retype your name."); return; } } if(text[0] == ' ' || text[0] == ' '){ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Invalid character on your name...Type it again."); return; } std::string filename="data/players/"+text+".xml"; std::ifstream ifile; ifile.open(filename.c_str()); // Passing the return value of a function to another function if (ifile){ player->sendTextMessage(MSG_SMALLINFO, "Ruly the Acc Manager: Sorry, this player already exist, type another name."); return; } if(okj){ std::stringstream inutil; inutil <<"Ruly the Acc Manager: "<<text<<". Interesting name. Male or female?"; player->newCharName = text; player->managerActive = 2; player->sendTextMessage(MSG_BLUE_TEXT, inutil.str().c_str()); return; } } if(player->managerActive == 2){ if(text == "male"){ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: So we got more 1 men(or not) on this server... What vocation do you want to follow?"); player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: You can be a \"knight\", a \"paladin\", a \"druid\" or a \"sorcerer\"."); player->newSex = 1; player->managerActive = 3; return; } else if(text == "female"){ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: OH YEAH!! A new girl?!?! What vocation do you want to follow babe?"); player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: You can be a \"knight\", a \"paladin\", a \"druid\" or a \"sorcerer\"."); player->newSex = 0; player->managerActive = 3; return; } else{ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: I cant understand this gender, do you typed it right???"); return; } } if(player->managerActive == 3){ if(text == "knight"){ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: A powerfull warrior you want to be, are you sure?"); player->newVoc = 4; player->managerActive = 4; return; } else if(text == "paladin"){ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: A mighty archer you want to be, are you sure?"); player->newVoc = 3; player->managerActive = 4; return; } else if(text == "druid"){ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: A warrior of the nature you want to be, are you sure?"); player->newVoc = 2; player->managerActive = 4; return; } else if(text == "sorcerer"){ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: A dangerous magician you want to be, are you sure?"); player->newVoc = 1; player->managerActive = 4; return; } else{ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Pay atention to what you write young adventurer, this vocation is invalid."); return; } } if(player->managerActive == 4) { if(text == "yes") { doSaveNewAccount(player); std::stringstream x; x << "data/players/" << player->newCharName << ".xml"; const char *file = x.str().c_str(); ofstream save(file); save << "<?xml version=\"1.0\"?>\n"; save << "<player name=\"" << player->newCharName << "\" account=\"" << player->accountNumber << "\" "; save << "sex=\"" << player->newSex << "\" "; //save << "lookdir=\"0\" exp=\"4200\" "; save << "lookdir=\"0\" exp=\"" << g_config.MANAGER_P_EXP << "\" "; save << "voc=\"" << player->newVoc << "\" "; if(player->newVoc == 1 || player->newVoc == 2) save << "level=\"" << g_config.MANAGER_P_LVL << "\" access=\"0\" cap=\"" << g_config.MANAGER_CAP_MAGE << "\" "; else if(player->newVoc == 3) save << "level=\"" << g_config.MANAGER_P_LVL << "\" access=\"0\" cap=\"" << g_config.MANAGER_CAP_PALLY << "\" "; else if(player->newVoc == 4) save << "level=\"" << g_config.MANAGER_P_LVL << "\" access=\"0\" cap=\"" << g_config.MANAGER_CAP_KNIGHT << "\" "; if(player->newVoc == 1) save << "maglevel=\"" << g_config.MANAGER_MAGE_ML << "\">\n"; else if(player->newVoc == 2) save << "maglevel=\"" << g_config.MANAGER_MAGE_ML << "\">\n"; else if(player->newVoc == 3) save << "maglevel=\"" << g_config.MANAGER_PALLY_ML << "\">\n"; else if(player->newVoc == 4) save << "maglevel=\"" << g_config.MANAGER_KNIGHT_ML << "\">\n"; save << "<spawn x=\"" << g_config.MANAGER_TEMPLE_X << "\" y=\"" << g_config.MANAGER_TEMPLE_Y << "\" z=\"" << g_config.MANAGER_TEMPLE_Z << "\"/>\n"; save << "<temple x=\"" << g_config.MANAGER_TEMPLE_X << "\" y=\"" << g_config.MANAGER_TEMPLE_Y << "\" z=\"" << g_config.MANAGER_TEMPLE_Z << "\"/>\n"; if(player->newVoc == 1 || player->newVoc == 2) save << "<health now=\"" << g_config.MANAGER_MAGES_HP << "\" max=\"" << g_config.MANAGER_MAGES_HP << "\" food=\"0\"/>\n"; else if(player->newVoc == 3) save << "<health now=\"" << g_config.MANAGER_PALLY_HP << "\" max=\"" << g_config.MANAGER_PALLY_HP << "\" food=\"0\"/>\n"; else if(player->newVoc == 4) save << "<health now=\"" << g_config.MANAGER_KNIGHT_HP << "\" max=\"" << g_config.MANAGER_KNIGHT_HP << "\" food=\"0\"/>\n"; if(player->newVoc == 1 || player->newVoc == 2) save << "<mana now=\"" << g_config.MANAGER_MAGES_MANA << "\" max=\"" << g_config.MANAGER_MAGES_MANA << "\" spent=\"0\"/>\n"; else if(player->newVoc == 3) save << "<mana now=\"" << g_config.MANAGER_PALLY_MANA << "\" max=\"" << g_config.MANAGER_PALLY_MANA << "\" spent=\"0\"/>\n"; else if(player->newVoc == 4) save << "<mana now=\"" << g_config.MANAGER_KNIGHT_MANA << "\" max=\"" << g_config.MANAGER_KNIGHT_MANA << "\" spent=\"0\"/>\n"; if(player->newSex == 0) save << "<look type=\"136\" head=\"97\" body=\"129\" legs=\"129\" feet=\"114\"/>\n"; else save << "<look type=\"128\" head=\"97\" body=\"129\" legs=\"129\" feet=\"81\"/>\n"; save << "<skills>\n"; if(player->newVoc == 1 || player->newVoc == 2) { save << "<skill skillid=\"0\" level=\"" << g_config.MANAGER_MAGES_FIST << "\" tries=\"0\"/>\n"; save << "<skill skillid=\"1\" level=\"" << g_config.MANAGER_MAGES_CLUB << "\" tries=\"0\"/>\n"; save << "<skill skillid=\"2\" level=\"" << g_config.MANAGER_MAGES_SWORD << "\" tries=\"0\"/>\n"; save << "<skill skillid=\"3\" level=\"" << g_config.MANAGER_MAGES_AXE << "\" tries=\"0\"/>\n"; save << "<skill skillid=\"4\" level=\"" << g_config.MANAGER_MAGES_DISTANCE << "\" tries=\"0\"/>\n"; save << "<skill skillid=\"5\" level=\"" << g_config.MANAGER_MAGES_SHIELD << "\" tries=\"0\"/>\n"; save << "<skill skillid=\"6\" level=\"" << g_config.MANAGER_MAGES_FISHING << "\" tries=\"0\"/>\n"; } else if(player->newVoc == 3) { save << "<skill skillid=\"0\" level=\"" << g_config.MANAGER_PALLY_FIST << "\" tries=\"0\"/>\n"; save << "<skill skillid=\"1\" level=\"" << g_config.MANAGER_PALLY_CLUB << "\" tries=\"0\"/>\n"; save << "<skill skillid=\"2\" level=\"" << g_config.MANAGER_PALLY_SWORD << "\" tries=\"0\"/>\n"; save << "<skill skillid=\"3\" level=\"" << g_config.MANAGER_PALLY_AXE << "\" tries=\"0\"/>\n"; save << "<skill skillid=\"4\" level=\"" << g_config.MANAGER_PALLY_DISTANCE << "\" tries=\"0\"/>\n"; save << "<skill skillid=\"5\" level=\"" << g_config.MANAGER_PALLY_SHIELD << "\" tries=\"0\"/>\n"; save << "<skill skillid=\"6\" level=\"" << g_config.MANAGER_PALLY_FISHING << "\" tries=\"0\"/>\n"; } else if(player->newVoc == 4) { save << "<skill skillid=\"0\" level=\"" << g_config.MANAGER_KNIGHT_FIST << "\" tries=\"0\"/>\n"; save << "<skill skillid=\"1\" level=\"" << g_config.MANAGER_KNIGHT_CLUB << "\" tries=\"0\"/>\n"; save << "<skill skillid=\"2\" level=\"" << g_config.MANAGER_KNIGHT_SWORD << "\" tries=\"0\"/>\n"; save << "<skill skillid=\"3\" level=\"" << g_config.MANAGER_KNIGHT_AXE << "\" tries=\"0\"/>\n"; save << "<skill skillid=\"4\" level=\"" << g_config.MANAGER_KNIGHT_DISTANCE << "\" tries=\"0\"/>\n"; save << "<skill skillid=\"5\" level=\"" << g_config.MANAGER_KNIGHT_SHIELD << "\" tries=\"0\"/>\n"; save << "<skill skillid=\"6\" level=\"" << g_config.MANAGER_KNIGHT_FISHING << "\" tries=\"0\"/>\n"; } save << "</skills>\n"; save << "<inventory>\n"; save << "<slot slotid=\"1\"><item id=\"" << g_config.MANAGER_ALL_SLOT1 << "\"/></slot>\n"; if(player->newVoc == 1 || player->newVoc == 2) { save << "<slot slotid=\"3\"><item id=\"3940\"><inside><item id=\"2260\"/><item id=\"2260\"/><item id=\"2260\"/><item id=\"2120\"/><item id=\"2554\"/><item id=\"2152\" count=\"2\"/></inside></item></slot>\n"; save << "<slot slotid=\"5\"><item id=\"" << g_config.MANAGER_ALL_SLOT5 << "\"/></slot>\n"; save << "<slot slotid=\"6\"><item id=\"" << g_config.MANAGER_ALL_SLOT6 << "\"/></slot>\n"; save << "<slot slotid=\"10\"><item id=\"" << g_config.MANAGER_ALL_SLOT10 << "\"/></slot>\n"; } else if(player->newVoc == 3) {
save << "<slot slotid=\"3\"><item id=\"3940\"><inside><item id=\"2543\" count=\"100\"/><item id=\"2120\"/><item id=\"2554\"/><item id=\"2580\"/><item id=\"2152\" count=\"2\"/></inside></item></slot>\n"; save << "<slot slotid=\"5\"><item id=\"" << g_config.MANAGER_ALL_SLOT5 << "\"/></slot>\n"; save << "<slot slotid=\"6\"><item id=\"" << g_config.MANAGER_ALL_SLOT6 << "\"/></slot>\n"; save << "<slot slotid=\"10\"><item id=\"" << g_config.MANAGER_ALL_SLOT10 << "\"/></slot>\n"; } else if(player->newVoc == 4) { save << "<slot slotid=\"3\"><item id=\"3940\"><inside><item id=\"2413\"/><item id=\"2120\"/><item id=\"2554\"/><item id=\"2152\" count=\"2\"/></inside></item></slot>\n"; save << "<slot slotid=\"5\"><item id=\"" << g_config.MANAGER_ALL_SLOT5 << "\"/></slot>\n"; save << "<slot slotid=\"6\"><item id=\"" << g_config.MANAGER_ALL_SLOT6 << "\"/></slot>\n"; save << "<slot slotid=\"10\"><item id=\"" << g_config.MANAGER_ALL_SLOT10 << "\"/></slot>\n"; } save << "<slot slotid=\"4\"><item id=\"" << g_config.MANAGER_ALL_SLOT4 << "\"/></slot>\n"; save << "<slot slotid=\"7\"><item id=\"" << g_config.MANAGER_ALL_SLOT7 << "\"/></slot>\n"; save << "<slot slotid=\"8\"><item id=\"" << g_config.MANAGER_ALL_SLOT8 << "\"/></slot>\n"; save << "</inventory>\n"; save << "<depots><depot depotid=\"1\"><item id=\"2591\"><inside><item id=\"2594\"/></inside></item></depot><depot depotid=\"2\"><item id=\"2591\"><inside><item id=\"2594\"/></inside></item></depot><depot depotid=\"3\"><item id=\"2591\"><inside><item id=\"2594\"/></inside></item></depot><depot depotid=\"4\"><item id=\"2591\"><inside><item id=\"2594\"/></inside></item></depot><depot depotid=\"5\"><item id=\"2591\"><inside><item id=\"2594\"/></inside></item></depot></depots><storage/>\n</player>"; save.close(); player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Operation complete. Please log out and login again."); std::cout << " New Char Created: " << player->newCharName << "." << std::endl; return; } else if(text == "no"){ player->newVoc = 0; player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Ok, choose another vocation then."); player->managerActive = 3; return; } else{ player->sendTextMessage(MSG_BLUE_TEXT, "Ruly the Acc Manager: Cant understand this command, can you type again?"); return; } }}void Game::doPreVoc(Player* player){ if(player->newSex == 1) player->newLookMaster = 128; else player->newLookMaster = 77; if(player->newVoc == 1)//Sorcerer { player->newHealth = 1200; player->newHealthMax = 1200; player->newMana = 2400; player->newManaMax = 2400; player->newMagLvl = 65; } if(player->newVoc == 2)//Druid { player->newHealth = 1200; player->newHealthMax = 1200; player->newMana = 2400; player->newManaMax = 2400; player->newMagLvl = 65; } if(player->newVoc == 3)//Pally { player->newHealth = 1400; player->newHealthMax = 1400; player->newMana = 1400; player->newManaMax = 1400; player->newMagLvl = 20; } if(player->newVoc == 4)//Knight { player->newHealth = 2500; player->newHealthMax = 2500; player->newMana = 1000; player->newManaMax = 1000; player->newMagLvl = 9; }}void Game::doSaveNewAccount(Player* player){ Account account = IOAccount::instance()->loadAccount(player->accountNumber); char accstring[16]; sprintf(accstring, "%i", account.accnumber); std::list<std::string>::iterator it; for (it = account.charList.begin(); it != account.charList.end(); it++) { if((*it) != "" && (*it) != accstring && (*it) != account.password){ player->charOnList[player->passIsOk] = (*it); } player->passIsOk += 1; } doStep2(player);}void Game::doStep2(Player* player)//We had to read before to save... Sad thing huh?{ //Create Account Account account = IOAccount::instance()->loadAccount(player->accountNumber); std::stringstream PKWarning; PKWarning << "data/accounts/"<<player->accountNumber<<".xml"; std::string filename = PKWarning.str().c_str(); std::stringstream sb; xmlDocPtr doc; xmlMutexLock(xmlmutex); xmlNodePtr nn, sn, pn, root; doc = xmlNewDoc((const xmlChar*)"1.0"); doc->children = xmlNewDocNode(doc, NULL, (const xmlChar*)"account", NULL); root = doc->children; sb << account.password;xmlSetProp(root, (const xmlChar*) "pass", (const xmlChar*)sb.str().c_str()); sb.str(""); xmlSetProp(root, (const xmlChar*) "type", (const xmlChar*)"1"); sb.str(""); xmlSetProp(root, (const xmlChar*) "premDays", (const xmlChar*)"0"); sb.str(""); sn = xmlNewNode(NULL,(const xmlChar*)"characters"); std::stringstream sc; pn = xmlNewNode(NULL,(const xmlChar*)"character"); sb << player->accountNumber; xmlSetProp(pn, (const xmlChar*) "name", (const xmlChar*)sb.str().c_str()); sb.str(""); xmlAddChild(sn, pn); for(int a=1; a<=20; ++a){ if(player->charOnList[a] != "" && player->charOnList[a] != account.password){ pn = xmlNewNode(NULL,(const xmlChar*)"character"); sc << player->charOnList[a]; xmlSetProp(pn, (const xmlChar*) "name", (const xmlChar*)sc.str().c_str()); sc.str(""); xmlAddChild(sn, pn); } } std::stringstream sd; pn = xmlNewNode(NULL,(const xmlChar*)"character"); sd << player->newCharName; xmlSetProp(pn, (const xmlChar*) "name", (const xmlChar*)sd.str().c_str()); sd.str(""); xmlAddChild(sn, pn); xmlAddChild(root, sn); if (xmlSaveFile(filename.c_str(), doc)) { #ifdef __DEBUG__ std::cout << ":: Accound Created!\n"; #endif xmlFreeDoc(doc); xmlMutexUnlock(xmlmutex); return; } else { std::cout << "\tCouldn't save character =(\n"; xmlFreeDoc(doc); xmlMutexUnlock(xmlmutex); return; }}#endif
Na declaração das funções adicione:
#ifdef RULY_ACCMANAGER void accCreator(Player* player, std::string &text);void accManager(Player* player, std::string &text);bool doSavePlayer(Player* player);void doPreVoc(Player* player);void doSaveNewAccount(Player* player);void doStep2(Player* player);#endif