From c1e76fcbb2ba22682ae74443219a41d91fb35be5 Mon Sep 17 00:00:00 2001 From: Inky Date: Sat, 29 Jun 2019 03:47:02 +0300 Subject: [PATCH] Changed: add character exportation handler --HG-- branch : menu_navi --- code/ryzom/client/src/connection.cpp | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/code/ryzom/client/src/connection.cpp b/code/ryzom/client/src/connection.cpp index 59b30cf57..581b7de95 100644 --- a/code/ryzom/client/src/connection.cpp +++ b/code/ryzom/client/src/connection.cpp @@ -3616,3 +3616,54 @@ class CAHImportCharacter : public IActionHandler } }; REGISTER_ACTION_HANDLER( CAHImportCharacter, "import_char" ); + +// *************************************************************************** +class CAHExportCharacter : public IActionHandler +{ + virtual void execute (CCtrlBase * /* pCaller */, const std::string &Params) + { + if (Params.empty()) + return; + + sint32 slot = -1; + if (!fromString(getParam(Params, "slot"), slot)) + return; + + if (slot >= CharacterSummaries.size() || slot < 0) + return; + + // retrieve infos + CCharacterSummary &CS = CharacterSummaries[slot]; + if (CS.Name.empty()) + return; + + // extract name + const std::string name = buildPlayerNameForSaveFile(CS.Name.toString()); + + COFile fd; + bool success = false; + // use temporary file until close() + if (fd.open(toString("save/character_%s.save", name.c_str()), false, false, true)) + { + try + { + fd.serial(CS); + fd.flush(); + // validate + success = true; + } + catch (const EStream &e) + { + nlwarning(e.what()); + } + fd.close(); + } + else + nlwarning("Failed to open file: save/character_%s.save", name.c_str()); + + const uint8 val = (success == true) ? 0 : 1; + // user notification + CLuaManager::getInstance().executeLuaScript(toString("outgame:procCharselNotifaction(%i)", val)); + } +}; +REGISTER_ACTION_HANDLER( CAHExportCharacter, "export_char" );