Development save tent.

Newbie Spellweaver
Joined
May 17, 2014
Messages
62
Reaction score
10
Today we will try to make the save function tents in the source code Dayz SA.

We already have a function to save the character in module gameStateExt.cpp:

PHP:
GameValue DBServerSaveCharacter(const GameState *state, GameValuePar oper1)
{
  if (!GetNetworkManager().IsServerOwner())
  {
    state->AccessError("dbServerSaveCharacter");
    return false;
  }

  if (oper1.GetType() == GameObject)
  {
    Object *obj = GetObject(oper1);
    Person *person = dyn_cast<Person>(obj);
    if (!person) return false;

    int dpnid;
    if (GetNetworkManager().IsServer())
    {
      dpnid = person->GetRemotePlayer();
      if (dpnid == AI_PLAYER) return false;
    }
    else
    {
      dpnid = 2; // BOT_CLIENT
      if (person != GWorld->PlayerOn()) return false;
    }

    JSONDocument document;
    document.SetObject();
    JSONAllocator& allocator = document.GetAllocator();

    // keep some members outside to be consistent with Load
    document.AddMember("model", cc_cast(person->GetType()->GetName()), allocator);
    document.AddMember("alive", person->Brain() && person->Brain()->LSIsAlive() ? 1 : 0, allocator);
    person->JSONSave(document, allocator);

    JSONBuffer buffer;
    JSONWriter writer(buffer);
    document.Accept(writer);

    RString request = buffer.GetString();

    RString url/*, attrib*/;
    BuildServerRequest(ESERVLET_CHARACTER,url,"save");
//    BuildPlayerUID(attrib,uid);

    return GetNetworkManager().DBSave(url.Data(), dpnid, request);
  }
  else
  {
    DoAssert(oper1.GetType() == GameArray);
    const GameArrayType &array = oper1;
    if (!CheckSize(state, array, 2)) return false;
    if (!CheckType(state, array[0], GameString)) return false;
    if (!CheckType(state, array[1], GameObject)) return false;

    RString uid = array[0];
    Person *person = dyn_cast<Person>(GetObject(array[1]));
    if (!person) return false;

    JSONDocument document;
    document.SetObject();
    JSONAllocator& allocator = document.GetAllocator();

    // keep some members outside to be consistent with Load
    document.AddMember("model", cc_cast(person->GetType()->GetName()), allocator);
    document.AddMember("alive", person->Brain() && person->Brain()->LSIsAlive() ? 1 : 0, allocator);
    person->JSONSave(document, allocator);

    JSONBuffer buffer;
    JSONWriter writer(buffer);
    document.Accept(writer);

    RString request = buffer.GetString();

    RString url, attrib;
    BuildServerRequest(ESERVLET_CHARACTER,url,"save");
    BuildPlayerUID(attrib,uid);

    return GetNetworkManager().DBSave(url.Data(),attrib,request);
  }
}

Copy and rename.

PHP:
GameValue DBServerSaveObject(const GameState *state, GameValuePar oper1)
As you can see in you can pass a function as an object or an array. I am interested in the array. Near the tent unlike the character's no UID, and it should be organized scripts Dayz when creating a tent. We will call the function by passing it an array with two elements: string IDtent and object tent. Delete unnecessary from a function.

PHP:
GameValue DBServerSaveObject(const GameState *state, GameValuePar oper1)
{
    
  if (!GetNetworkManager().IsServerOwner())
  {
    state->AccessError("dbServerSaveCharacter");
    return false;
  }
    
  if (oper1.GetType() == GameArray)
  {    
    
    DoAssert(oper1.GetType() == GameArray);
    const GameArrayType &array = oper1;
    if (!CheckSize(state, array, 2)) return false;
    if (!CheckType(state, array[0], GameString)) return false;
    if (!CheckType(state, array[1], GameObject)) return false;

    RString uid = array[0];
    Person *person = dyn_cast<Person>(GetObject(array[1]));
    if (!person) return false;

    JSONDocument document;
    document.SetObject();
    JSONAllocator& allocator = document.GetAllocator();

    // keep some members outside to be consistent with Load
    document.AddMember("model", cc_cast(person->GetType()->GetName()), allocator);
    document.AddMember("alive", person->Brain() && person->Brain()->LSIsAlive() ? 1 : 0, allocator);
    person->JSONSave(document, allocator);

    JSONBuffer buffer;
    JSONWriter writer(buffer);
    document.Accept(writer);

    RString request = buffer.GetString();

    RString url, attrib;
    BuildServerRequest(ESERVLET_CHARACTER,url,"save");
    BuildPlayerUID(attrib,uid);

    return GetNetworkManager().DBSave(url.Data(),attrib,request);
  }
}

The next step. We need to change the type of the object being saved. It is defined by the line:
PHP:
  Person *person = dyn_cast<Person>(GetObject(array[1]));

Little digging in the source code, we will find the type of object that we need. Write down it. I'm not even going to change the variable names. (a bit lazy)

PHP:
InventoryItem *person = dyn_cast<InventoryItem>(GetObject(array[1]));

Now everything will be stored objects of type InventoryItem. We go further. It retains the status of an "alive", for the tent don't need it. For comment.

PHP:
 //document.AddMember("alive", person->Brain() && person->Brain()->LSIsAlive() ? 1 : 0, allocator);

We were lucky and the class "InventoryItem" also has the function "JSONSave". And here we almost don't want anything to change, but I still its copy and changed (write below).

PHP:
   person->JSONSaveTent(document, allocator);

To distinguish requests the preservation of the character from the query save the tents are changing so:
PHP:
    BuildServerRequest(ESERVLET_CHARACTER,url,"save_obj");

And correct this feature on their:

PHP:
    BuildObjectUID(attrib,uid);

Ultimately, should we would get something like this:
PHP:
GameValue DBServerSaveObject(const GameState *state, GameValuePar oper1)
{
    
  if (!GetNetworkManager().IsServerOwner())
  {
    state->AccessError("dbServerSaveCharacter");
    return false;
  }
    
  if (oper1.GetType() == GameArray)
  {    
    
    DoAssert(oper1.GetType() == GameArray);
    const GameArrayType &array = oper1;
    if (!CheckSize(state, array, 2)) return false;
    if (!CheckType(state, array[0], GameString)) return false;
    if (!CheckType(state, array[1], GameObject)) return false;
    
    RString uid = array[0];

    InventoryItem *person = dyn_cast<InventoryItem>(GetObject(array[1]));
    if (!person) return false;
    
    JSONDocument document;
    document.SetObject();
    JSONAllocator& allocator = document.GetAllocator();
    
    // keep some members outside to be consistent with Load
    document.AddMember("model", cc_cast(person->GetType()->GetName()), allocator);
    //document.AddMember("alive", person->Brain() && person->Brain()->LSIsAlive() ? 1 : 0, allocator);
    person->JSONSaveTent(document, allocator);
    
    JSONBuffer buffer;
    JSONWriter writer(buffer);
    document.Accept(writer);
    
    RString request = buffer.GetString();

    RString url, attrib;
    BuildServerRequest(ESERVLET_CHARACTER,url,"save_obj");
    BuildObjectUID(attrib,uid);
    
    return GetNetworkManager().DBSave(url.Data(),attrib,request);
  } 
  else
  {
    return false;
  }
}

Sorry for my English, used the online translators.
Для русскоязычных людей могу это же изложить на русском, для большей понятности.

p.s.I will not answer questions: how to compile or give an EXE server. Sorry.
 
We are beginning to publish their modifications of the server exe.


You can learn more at:
 
That's not all. I just gave an example to understand this people. There's still a need to write a 5-6 functions, but it will work. On this basis, there are already several servers with saves tents
 
That's not all. I just gave an example to understand this people. There's still a need to write a 5-6 functions, but it will work. On this basis, there are already several servers with saves tents
Well then,I'd better wait if someone could release a full tutorial of tent saving or a tent saving exe:) By the way,is that 0.47 takes up more memory of the server?Because my server crash more often than 0.46 version.
 
Yes, some of us are not very good in dev so could someone share an already modified package ?

Just a question : does it means that external saving system (like with wamp or node.js) is not necessary anymore ?
 
Friend gameStateExt.cpp where I can get this file, I buscandoloe days and do not get to make that modification, another question that exe lasts 30 days would be paid as payment for one month not last ??
 
Help help help I have an error At compilation the ERROR goes In person-> JSONSaveTent (document, allocator); And BuildObjectUID (attrib, uid);

Помогите пожалуйста у меня при компиляции выскакивает ошибка связана с JSONSaveTent (document, allocator); и BuildObjectUID (attrib, uid);



2>gameStateExt.cpp(17254): error C2039: 'JSONSaveTent' : is not a member of 'InventoryItem'
2> d:\v1.4.4\lib\Inventory/inventory.hpp(239) : see declaration of 'InventoryItem'
2>gameStateExt.cpp(17264): error C3861: 'BuildObjectUID': identifier not found
 
Где можно скачать сурс код?

Where can I download source code?
 
False - if the parameters of the function if not an array or object does not exist.
Otherwise, "string" - the result of a query
 
And easy enough to check :)
_ok = DBServerSaveObject(_state,_parameters);
if (typeName _ok == "STRING") then { ...
 
Last edited:
Back