5 #include "stg/servconf.h"
6 #include "stg/servconf_types.h"
7 #include "stg/corp_conf.h"
8 #include "stg/common.h"
15 std::string Indent(size_t level, bool dash = false)
19 return dash ? std::string(level * 4 - 2, ' ') + "- " : std::string(level * 4, ' ');
22 void PrintCorp(const STG::GET_CORP::INFO & info, size_t level = 0)
24 std::cout << Indent(level, true) << "name: " << info.name << "\n"
25 << Indent(level) << "cash: " << info.cash << "\n";
28 void SimpleCallback(bool result,
29 const std::string & reason,
34 std::cerr << "Operation failed. Reason: '" << reason << "'." << std::endl;
37 std::cout << "Success.\n";
40 void GetCorpsCallback(bool result,
41 const std::string & reason,
42 const std::vector<STG::GET_CORP::INFO> & info,
47 std::cerr << "Failed to get corp list. Reason: '" << reason << "'." << std::endl;
50 std::cout << "Corps:\n";
51 for (size_t i = 0; i < info.size(); ++i)
52 PrintCorp(info[i], 1);
55 void GetCorpCallback(bool result,
56 const std::string & reason,
57 const STG::GET_CORP::INFO & info,
62 std::cerr << "Failed to get corp. Reason: '" << reason << "'." << std::endl;
68 } // namespace anonymous
70 bool SGCONF::GetCorpsFunction(const SGCONF::CONFIG & config,
71 const std::string & /*arg*/,
72 const std::map<std::string, std::string> & /*options*/)
74 STG::SERVCONF proto(config.server.data(),
76 config.userName.data(),
77 config.userPass.data());
78 return proto.GetCorporations(GetCorpsCallback, NULL) == STG::st_ok;
81 bool SGCONF::GetCorpFunction(const SGCONF::CONFIG & config,
82 const std::string & arg,
83 const std::map<std::string, std::string> & /*options*/)
85 STG::SERVCONF proto(config.server.data(),
87 config.userName.data(),
88 config.userPass.data());
89 return proto.GetCorp(arg, GetCorpCallback, NULL) == STG::st_ok;
92 bool SGCONF::DelCorpFunction(const SGCONF::CONFIG & config,
93 const std::string & arg,
94 const std::map<std::string, std::string> & /*options*/)
96 STG::SERVCONF proto(config.server.data(),
98 config.userName.data(),
99 config.userPass.data());
100 return proto.DelCorp(arg, SimpleCallback, NULL) == STG::st_ok;
103 bool SGCONF::AddCorpFunction(const SGCONF::CONFIG & config,
104 const std::string & arg,
105 const std::map<std::string, std::string> & /*options*/)
108 std::cerr << "Unimplemented.\n";
112 bool SGCONF::ChgCorpFunction(const SGCONF::CONFIG & config,
113 const std::string & arg,
114 const std::map<std::string, std::string> & options)
117 std::cerr << "Unimplemented.\n";