124 lines
3.7 KiB
C++
124 lines
3.7 KiB
C++
#pragma once
|
|
|
|
namespace google
|
|
{
|
|
namespace protobuf
|
|
{
|
|
class Descriptor;
|
|
class Message;
|
|
}
|
|
}
|
|
|
|
namespace a8
|
|
{
|
|
namespace mysql
|
|
{
|
|
class Connection;
|
|
class Query;
|
|
}
|
|
}
|
|
|
|
namespace f8
|
|
{
|
|
typedef void (*ReadCsvMetaFileCallback)(const std::string&);
|
|
|
|
bool ReadCsvMetaFile(const std::string& filename,
|
|
google::protobuf::Message* prototype,
|
|
std::function<void (google::protobuf::Message*)> push_back_func);
|
|
|
|
template <typename T>
|
|
bool ReadCsvMetaFile(const std::string& filename, std::list<T>& meta_list,
|
|
ReadCsvMetaFileCallback callback_func = nullptr)
|
|
{
|
|
if (callback_func) {
|
|
callback_func(filename);
|
|
}
|
|
T dummy;
|
|
return ReadCsvMetaFile(filename,
|
|
&dummy,
|
|
[&meta_list] (google::protobuf::Message* msg)
|
|
{
|
|
T t;
|
|
t.CopyFrom(*msg);
|
|
meta_list.emplace_back(t);
|
|
});
|
|
}
|
|
|
|
bool ReadJsonMetaFile(const std::string& filename,
|
|
google::protobuf::Message* prototype,
|
|
std::function<void (google::protobuf::Message*)> push_back_func);
|
|
|
|
template <typename T>
|
|
bool ReadJsonMetaFile(const std::string& filename, std::list<T>& meta_list)
|
|
{
|
|
T dummy;
|
|
return ReadJsonMetaFile(filename,
|
|
&dummy,
|
|
[&meta_list] (google::protobuf::Message* msg)
|
|
{
|
|
T t;
|
|
t.CopyFrom(*msg);
|
|
meta_list.emplace_back(t);
|
|
});
|
|
}
|
|
|
|
std::string PbToJson(const google::protobuf::Message* msg);
|
|
|
|
template <typename T1,
|
|
typename T2>
|
|
static void RepeatedFieldToVector(const T1& t1, T2& t2)
|
|
{
|
|
t2.clear();
|
|
for (auto& val : t1) {
|
|
t2.push_back(val);
|
|
}
|
|
}
|
|
|
|
template <typename T1,
|
|
typename T2>
|
|
static void RepeatedFieldToSet(const T1& t1, T2& t2)
|
|
{
|
|
t2.clear();
|
|
for (auto& val : t1) {
|
|
t2.insert(val);
|
|
}
|
|
}
|
|
|
|
template <typename T1,
|
|
typename T2>
|
|
static void VectorToRepeatedField(const T1& t1, T2& t2)
|
|
{
|
|
t2.Clear();
|
|
for (auto& val : t1) {
|
|
*t2.Add() = val;
|
|
}
|
|
}
|
|
|
|
template <typename T1,
|
|
typename T2>
|
|
static void SetToRepeatedField(const T1& t1, T2& t2)
|
|
{
|
|
t2.Clear();
|
|
for (auto& val : t1) {
|
|
*t2.Add() = val;
|
|
}
|
|
}
|
|
|
|
void InitMysqlConnection(a8::mysql::Query* query);
|
|
void CheckMysqlConnection(a8::mysql::Connection* conn, a8::mysql::Query* query,
|
|
std::string dbhost, int port, std::string dbuser, std::string dbpasswd, std::string gamedb);
|
|
|
|
bool CheckRegisterTimeInSessionId(const std::string& accountid, const std::string& sessionid);
|
|
time_t ExtractRegisterTimeFromSessionId(const std::string& sessionid);
|
|
bool IsValidSessionId(const std::string& accountid, const std::string& sessionid);
|
|
bool LoginCheck(const std::string& accountid, const std::string& sessionid);
|
|
int ExtractGameIdFromAccountId(const std::string& accountid);
|
|
int ExtractChannelIdFromAccountId(const std::string& accountid);
|
|
|
|
bool IsOnlineEnv();
|
|
bool IsTestEnv();
|
|
bool IsValidNormalConfig(a8::XObject& conf, std::vector<std::string> fields);
|
|
|
|
std::string PbToJson(google::protobuf::Message* pbmsg);
|
|
}
|