Codechange: [Network] Let admin-game script use std::string
This commit is contained in:
@@ -139,7 +139,7 @@
|
||||
return 1;
|
||||
}
|
||||
|
||||
NetworkAdminGameScript(json.c_str());
|
||||
NetworkAdminGameScript(json);
|
||||
|
||||
sq_pushinteger(vm, 1);
|
||||
return 1;
|
||||
|
@@ -118,23 +118,18 @@ bool ScriptEventCompanyAskMerger::AcceptMerger()
|
||||
return ScriptObject::DoCommand(0, this->owner, 0, CMD_BUY_COMPANY);
|
||||
}
|
||||
|
||||
ScriptEventAdminPort::ScriptEventAdminPort(const char *json) :
|
||||
ScriptEventAdminPort::ScriptEventAdminPort(const std::string &json) :
|
||||
ScriptEvent(ET_ADMIN_PORT),
|
||||
json(stredup(json))
|
||||
json(json)
|
||||
{
|
||||
}
|
||||
|
||||
ScriptEventAdminPort::~ScriptEventAdminPort()
|
||||
{
|
||||
free(this->json);
|
||||
}
|
||||
|
||||
#define SKIP_EMPTY(p) while (*(p) == ' ' || *(p) == '\n' || *(p) == '\r') (p)++;
|
||||
#define RETURN_ERROR(stack) { ScriptLog::Error("Received invalid JSON data from AdminPort."); if (stack != 0) sq_pop(vm, stack); return nullptr; }
|
||||
|
||||
SQInteger ScriptEventAdminPort::GetObject(HSQUIRRELVM vm)
|
||||
{
|
||||
const char *p = this->json;
|
||||
const char *p = this->json.c_str();
|
||||
|
||||
if (this->ReadTable(vm, p) == nullptr) {
|
||||
sq_pushnull(vm);
|
||||
@@ -168,7 +163,8 @@ const char *ScriptEventAdminPort::ReadString(HSQUIRRELVM vm, const char *p)
|
||||
p++;
|
||||
}
|
||||
|
||||
sq_pushstring(vm, value, p - value);
|
||||
size_t len = p - value;
|
||||
sq_pushstring(vm, value, len);
|
||||
p++; // Step past the end-of-string marker (")
|
||||
|
||||
return p;
|
||||
|
@@ -837,8 +837,7 @@ public:
|
||||
/**
|
||||
* @param json The JSON string which got sent.
|
||||
*/
|
||||
ScriptEventAdminPort(const char *json);
|
||||
~ScriptEventAdminPort();
|
||||
ScriptEventAdminPort(const std::string &json);
|
||||
|
||||
/**
|
||||
* Convert an ScriptEvent to the real instance.
|
||||
@@ -853,7 +852,7 @@ public:
|
||||
SQInteger GetObject(HSQUIRRELVM vm);
|
||||
|
||||
private:
|
||||
char *json; ///< The JSON string.
|
||||
std::string json; ///< The JSON string.
|
||||
|
||||
/**
|
||||
* Read a table from a JSON string.
|
||||
|
Reference in New Issue
Block a user