Json_STL完善
This commit is contained in:
parent
44ea52a10a
commit
4b711b004b
|
|
@ -346,4 +346,28 @@ const wchar_t* DNFTOOL::GetWC(const char* c)
|
|||
mbstowcs(wc, c, cSize);
|
||||
|
||||
return wc;
|
||||
}
|
||||
}
|
||||
|
||||
void DNFTOOL::Split(const std::string& src, std::vector<std::string>& dest, const std::string& separator)
|
||||
{
|
||||
std::string str = src;
|
||||
std::string substring;
|
||||
std::string::size_type start = 0, index;
|
||||
dest.clear();
|
||||
index = str.find_first_of(separator, start);
|
||||
do
|
||||
{
|
||||
if (index != std::string::npos)
|
||||
{
|
||||
substring = str.substr(start, index - start);
|
||||
dest.push_back(substring);
|
||||
start = index + separator.size();
|
||||
index = str.find(separator, start);
|
||||
if (start == std::string::npos) break;
|
||||
}
|
||||
} while (index != std::string::npos);
|
||||
|
||||
//the last part
|
||||
substring = str.substr(start);
|
||||
dest.push_back(substring);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,6 +90,8 @@ public:
|
|||
//string 转 wchar_t*
|
||||
static const wchar_t* GetWC(const char* c);
|
||||
|
||||
static void Split(const std::string& src, std::vector<std::string>& dest, const std::string& separator = "->");
|
||||
|
||||
|
||||
//窗口公告 0x10d
|
||||
static void WindowsNotice(char* str, int type = 0x10d, int b = 0x0);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
//#include "squirrel.h"
|
||||
#include "hook.h"
|
||||
|
|
|
|||
|
|
@ -1055,52 +1055,127 @@ int squirrel::Set_DragonModel(uint32_t v)
|
|||
|
||||
#if defined JSON_STL
|
||||
//构造Json类型容器
|
||||
static std::map<wchar_t*, std::string>Json_STL;
|
||||
static std::map<std::string, std::string>Json_STL;
|
||||
//Json容器
|
||||
int squirrel::Jsoner_STL(uint32_t v)
|
||||
{
|
||||
wchar_t* Name;
|
||||
wchar_t* WName;
|
||||
int Type;
|
||||
int ParameterNum = SQGetTop(v);
|
||||
if (ParameterNum == 3)
|
||||
{
|
||||
//获取容器名字
|
||||
SQGetString(v, 2, &Name);
|
||||
//获取模式
|
||||
SQGetInt(v, 3, &Type);
|
||||
SQGetString(v, 2, &WName);
|
||||
char* CName = DNFTOOL::wchar_tTochar(WName);
|
||||
std::string Name = CName;
|
||||
//获取值的类型
|
||||
int ValueType = SQ_GetType(v, 3);
|
||||
|
||||
switch (Type)
|
||||
switch (ValueType)
|
||||
{
|
||||
case 0://构造
|
||||
case OT_INTEGER://int类型
|
||||
{
|
||||
if (Json_STL.count(Name) != 0)//如果这个hash不存在 就创建
|
||||
//获取模式
|
||||
SQGetInt(v, 3, &Type);
|
||||
|
||||
switch (Type)
|
||||
{
|
||||
//构造对应 hash 的 Json容器
|
||||
std::string str = "";
|
||||
Json_STL[Name] = str;
|
||||
case 0://构造
|
||||
{
|
||||
if (Json_STL.count(Name) != 0)//如果这个hash不存在 就创建
|
||||
{
|
||||
//构造对应 hash 的 Json容器
|
||||
std::string str = "";
|
||||
Json_STL[Name] = str;
|
||||
}
|
||||
else
|
||||
{
|
||||
SQPushBool(v, false);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
case 1://读取整体
|
||||
{
|
||||
SQPushBool(v, false);
|
||||
wchar_t* buffer = DNFTOOL::charTowchar_t((char*)Json_STL[Name].c_str());
|
||||
SQPushString(v, buffer, wcslen(buffer));//传给nut
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
case 2://销毁
|
||||
Json_STL.erase(Name);//销毁容器
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1://读取
|
||||
break;
|
||||
case OT_STRING:
|
||||
{
|
||||
wchar_t* buffer = DNFTOOL::charTowchar_t((char*)Json_STL[Name].c_str());
|
||||
SQPushString(v, buffer, wcslen(buffer));//传给nut
|
||||
char* str = (char*)R"({"op":2,"err":0,"result":[{"maxhurt":0,"rank":0,"numberEntries":0,"job":1,"cid":"z0"},{"maxhurt":1,"rank":1,"numberEntries":1,"job":2,"cid":"z1"},{"maxhurt":2,"rank":2,"numberEntries":2,"job":3,"cid":"z2"},{"maxhurt":3,"rank":3,"numberEntries":3,"job":4,"cid":"z3"},{"maxhurt":4,"rank":4,"numberEntries":4,"job":5,"cid":"z4"},{"maxhurt":5,"rank":5,"numberEntries":5,"job":6,"cid":"z5"},{"maxhurt":6,"rank":6,"numberEntries":6,"job":7,"cid":"z6"},{"maxhurt":7,"rank":7,"numberEntries":7,"job":8,"cid":"z7"},{"maxhurt":8,"rank":8,"numberEntries":8,"job":9,"cid":"z8"},{"maxhurt":9,"rank":9,"numberEntries":9,"job":10,"cid":"z9"}],"uid":1,"cid":1})";
|
||||
Json_STL["severbackpack"] = str;
|
||||
std::cout << Json_STL["severbackpack"].c_str() << std::endl;
|
||||
wchar_t* GKey;
|
||||
//获取访问需求
|
||||
SQGetString(v, 3, &GKey);
|
||||
char* key = DNFTOOL::wchar_tTochar(GKey);
|
||||
rapidjson::Document Dom;
|
||||
Dom.Parse(Json_STL["severbackpack"].c_str());//加载 字符串
|
||||
|
||||
std::vector<std::string> Data;
|
||||
DNFTOOL::Split(key, Data);
|
||||
rapidjson::Value Vbuffer;
|
||||
|
||||
for (int i = 0; i < Data.size(); i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
Vbuffer = Dom[Data[i].c_str()];
|
||||
}
|
||||
else if (strlen(Data[i].c_str()) == 1)
|
||||
{
|
||||
char c = Data[i].c_str()[0];
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
Vbuffer = Vbuffer[atoi(Data[i].c_str())];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Vbuffer = Vbuffer[Data[i].c_str()];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (Vbuffer.IsString())
|
||||
{
|
||||
wchar_t* buffer = DNFTOOL::charTowchar_t((char*)Vbuffer.GetString());
|
||||
SQPushString(v, buffer, wcslen(buffer));
|
||||
}
|
||||
if (Vbuffer.IsBool())
|
||||
{
|
||||
SQPushBool(v, Vbuffer.GetBool());
|
||||
}
|
||||
if (Vbuffer.IsInt())
|
||||
{
|
||||
SQPushInt(v, Vbuffer.GetInt());
|
||||
}
|
||||
if (Vbuffer.IsFloat())
|
||||
{
|
||||
SQPushFloat(v, Vbuffer.GetFloat());
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SQPushBool(v, true);
|
||||
}
|
||||
else if (ParameterNum == 4)
|
||||
{
|
||||
//获取容器名字
|
||||
SQGetString(v, 2, &Name);
|
||||
SQGetString(v, 2, &WName);
|
||||
char* CName = DNFTOOL::wchar_tTochar(WName);
|
||||
std::string Name = CName;
|
||||
//获取Key 的名字
|
||||
wchar_t* keybuffer;
|
||||
SQGetString(v, 3, &keybuffer);
|
||||
|
|
@ -1151,16 +1226,20 @@ int squirrel::Jsoner_STL(uint32_t v)
|
|||
default:
|
||||
break;
|
||||
}
|
||||
if (Dom[key].IsNull())
|
||||
|
||||
if (Dom[key].IsNull())//如果键值为空就新增
|
||||
{
|
||||
Dom.AddMember(rapidjson::StringRef(key), BB, Dom.GetAllocator());
|
||||
}
|
||||
else//否则就修改
|
||||
{
|
||||
Dom[key] = BB;
|
||||
}
|
||||
|
||||
rapidjson::StringBuffer jsonBuffer;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(jsonBuffer);
|
||||
Dom.Accept(writer);
|
||||
Json_STL[Name] = jsonBuffer.GetString();
|
||||
//delete[] key;
|
||||
SQPushBool(v, true);
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in New Issue