Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Development save variables.

Junior Spellweaver
Joined
May 22, 2015
Messages
103
Reaction score
29
Addition to this guide:
http://forum.ragezone.com/f864/development-save-tent-1019961/

Copy prepared DBServerSaveObject and rename to DBServerSaveVariable.

PHP:
GameValue DBServerSaveVariable(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;
  }
}

Now we need to remove some parts of this code.

Step 1. First time comment 3 lines after
PHP:
const GameArrayType &array = oper1;

Step 2. We define a variable for variables.
Replace
Code:
[COLOR=#0000BB]InventoryItem [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]person [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]dyn_cast[/COLOR][COLOR=#007700]<[/COLOR][COLOR=#0000BB]InventoryItem[/COLOR][COLOR=#007700]>([/COLOR][COLOR=#0000BB]GetObject[/COLOR][COLOR=#007700](array[[/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700]]));
    if (![/COLOR][COLOR=#0000BB]person[/COLOR][COLOR=#007700]) return [/COLOR][COLOR=#0000BB]false[/COLOR][COLOR=#007700];[/COLOR]
per
PHP:
RString value = array[1];

Step 3. Rename column for database. Find "model" and rename to "value".
Replace
(person->GetType()->GetName())
by
(value)
Comment next line (person->JSONSaveTent...)

Step 4. Rename function for this type of request. In line BuildServerRequest find save_obj and rename to save_value.

The result should look something like:

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];
    RString value = array[1];

     //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("value", cc_cast(value), 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_value");
    BuildObjectUID(attrib,uid);
    
    return GetNetworkManager().DBSave(url.Data(),attrib,request);
  } 
  else
  {
    return false;
  }
}

Hint: To load variable from database you must use

PHP:
RString retValue = value.GetString();
return retValue;

Dont say "it doesn't work", all works fine. Using this you can save and load any variables: count of killed zombies, state of some door and even script codes. The last can be compiled on server side using method
call compile {code}

Sorry for my English.
 
Initiate Mage
Joined
Jul 22, 2014
Messages
4
Reaction score
0
Addition to this guide:
http://forum.ragezone.com/f864/development-save-tent-1019961/

Copy prepared DBServerSaveObject and rename to DBServerSaveVariable.

PHP:
GameValue DBServerSaveVariable(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;
  }
}

Now we need to remove some parts of this code.

Step 1. First time comment 3 lines after
PHP:
const GameArrayType &array = oper1;

Step 2. We define a variable for variables.
Replace
Code:
[COLOR=#0000BB]InventoryItem [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]person [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]dyn_cast[/COLOR][COLOR=#007700]<[/COLOR][COLOR=#0000BB]InventoryItem[/COLOR][COLOR=#007700]>([/COLOR][COLOR=#0000BB]GetObject[/COLOR][COLOR=#007700](array[[/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700]]));
    if (![/COLOR][COLOR=#0000BB]person[/COLOR][COLOR=#007700]) return [/COLOR][COLOR=#0000BB]false[/COLOR][COLOR=#007700];[/COLOR]
per
PHP:
RString value = array[1];

Step 3. Rename column for database. Find "model" and rename to "value".
Replace
(person->GetType()->GetName())
by
(value)
Comment next line (person->JSONSaveTent...)

Step 4. Rename function for this type of request. In line BuildServerRequest find save_obj and rename to save_value.

The result should look something like:

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];
    RString value = array[1];

     //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("value", cc_cast(value), 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_value");
    BuildObjectUID(attrib,uid);
    
    return GetNetworkManager().DBSave(url.Data(),attrib,request);
  } 
  else
  {
    return false;
  }
}

Hint: To load variable from database you must use

PHP:
RString retValue = value.GetString();
return retValue;

Dont say "it doesn't work", all works fine. Using this you can save and load any variables: count of killed zombies, state of some door and even script codes. The last can be compiled on server side using method
call compile {code}

Sorry for my English.

just why not to use this "sendUDPMessage" method? :)
e.g: _response = sendUDPMessage [_ip, _port, _request];
 
Junior Spellweaver
Joined
May 22, 2015
Messages
103
Reaction score
29
because sendUDPMessage isn't comfortable to work with multiple tables and saving houses, tents, loot and objects with multipla variables
 
Initiate Mage
Joined
Jan 28, 2017
Messages
2
Reaction score
0
Where do I find the DBServerSaveObject function on my server? I have version 0.47 with addons of 0.60Where do I find the DBServerSaveObject function on my server? I have version 0.47 with addons of 0.60
 
Junior Spellweaver
Joined
May 22, 2015
Messages
103
Reaction score
29
Where do I find the DBServerSaveObject function on my server? I have version 0.47 with addons of 0.60Where do I find the DBServerSaveObject function on my server? I have version 0.47 with addons of 0.60

read carefully or copy ready version
 
Back
Top