Help with @Hive key codes?

Xyberviri

Valued Member!
Does anyone have any experience with the key codes dayz/hive uses to publish to the db?


Code:
_key = format["CHILD:301:%1:%2:%3:%4:%5:%6:%7:%8:",_x, _class, 0 , 0, _worldspace, [], _array, 0];
    diag_log ("HIVE: WRITE: "+ str(_key));
    _key call server_hiveWrite;

Code:
//Send request
_key = format["CHILD:308:%1:%2:%3:%4:%5:%6:%7:%8:%9:",dayZ_instance, _class, 0 , _charID, _worldspace, [], [], 0,_uid];
diag_log ("HIVE: WRITE: "+ str(_key));
_key call server_hiveWrite;

Does anyone know where in the hive source these codes are for the sql statements?

Does anyone happen to know if the hive ever does update inserts?

ultimately my goal is to convert the wasteland vehicle spawning system into the system that is used for "new" vehicles on my server. we also are going to be using the mission generation system to generate the military grade vehicles on our server .
 
alright looks like im on track im sure there is a way to convert this entire thing into 1 statement but im too tired to bother at this time.

Code:
SELECT `world_vehicle`.`id`, `world_vehicle`.`vehicle_id`, `vehicle`.`id`
FROM world_vehicle, vehicle
WHERE ((`vehicle`.`id` =`world_vehicle`.`vehicle_id`) AND (`vehicle`.`class_name` ='Mi17_UN_CDF_EP1'))
       
INSERT INTO `instance_vehicle` (`id`, `world_vehicle_id`, `instance_id`, `worldspace`, `inventory`, `parts`, `fuel`, `damage`, `last_updated`, `created`)
VALUES (NULL, '20007', '1393', '[226,[6375.69,8146.38,0.004]]', ' [[[],[]],[[],[]],[[],[]]]', '[]', '0', '0', CURRENT_TIMESTAMP, '0000-00-00 00:00:00');

when i get home ill convert this to a stored procedure.
 
Looks fine, Leave out ID, on the Insert, as that will be generated automatically by mySQL (assuming Bliss database). Inserting null, in my experience, just fails to do anything.

There is a space before your your inventory value (typo).

last_updated should also be automatically filled out. by mySQL (assuming Bliss database), so might as well use CURRENT_TIMESTAMP on the 'created' field. Have had issues inserting zero value date/times, when trying to read them back out..
 
This is the dirty spawn code, it needs to be gone over and cleaned up for dayz:
Code:
waitUntil{allowConnection};
    _type = "UH1H_DZ";
    _dir = (random 360);
    _pos =[13485,4421,0];
    //http://forums.bistudio.com/showthread.php?103108-BIS_fnc_findSafePos
    _newPos = [_pos, 10, 200, 10, 0, 500, 0] call BIS_fnc_findSafePos;
    diag_log format["Attempting to spawn new vehicle: %1 at location %2",_type,str(_newPos)];
  // _newVehicle = ["UH1H_DZ",_newPosr] call object_spawnGoodVehicle;  //object_spawnDamVehicle;
 
    _veh = _type createVehicle _newPos; // [,, [], 0, "CAN_COLLIDE"];
    _veh setDir _dir;
    _veh setPos getPos _veh;
 
    //_veh setVariable ["ObjectID",1,true];
   
    _veh setVariable ["ObjectID", _veh call dayz_objectUID, true];
 
    _hitpoints = _veh call vehicle_getHitpoints;
    _dam = 0.05;
    _veh setFuel 1;
    _veh call fnc_vehicleEventHandler;
    {
        _hit = [_veh,_x] call object_getHit;
        _selection = getText (configFile >> "CfgVehicles" >> (typeOf _veh) >> "HitPoints" >> _x >> "name");
        if (_hit > 0) then {_array set [count _array,[_selection,_hit]]};
    } forEach _hitpoints;
       
      dayz_serverObjectMonitor set [count dayz_serverObjectMonitor,_veh];
      [_veh,_type] spawn server_updateObject;

when you building bliss with the --with-buildings option you get this code in your server_monitor.sqf

Code:
//Send the key
_key = format["CHILD:999:select b.class_name, ib.worldspace from instance_building ib join building b on ib.building_id = b.id where ib.instance_id = ?:[%1]:", dayZ_instance];
_data = "HiveEXT" callExtension _key;
diag_log("SERVER: Fetching buildings...");
//Process result
_result = call compile format ["%1", _data];
_status = _result select 0;
_bldList = [];
_bldCount = 0;
if (_status == "CustomStreamStart") then {
    _val = _result select 1;
    for "_i" from 1 to _val do {
        _data = "HiveEXT" callExtension _key;
        _result = call compile format ["%1",_data];
        _pos = call compile (_result select 1);
        _dir = _pos select 0;
        _pos = _pos select 1;
        _building = createVehicle [_result select 0, _pos, [], 0, "CAN_COLLIDE"];
        _building setDir _dir;
        _bldCount = _bldCount + 1;
    };
    diag_log ("SERVER: Spawned " + str(_bldCount) + " buildings!");
};

Right there is a db fetch so im guessing i can do a insert statment on it aswell, at least i hope, i might need to go the stored procedure route like leo posted in the "allow admins to spawn vehicles" thread in the scripts section of this site.(well he only posted to do it not the proccedure itself)

the ID in the vehicle table is going to be generated here: "_veh setVariable ["ObjectID", _veh call dayz_objectUID, true];" I could go with a row insert but im not 100% if that would work properly, plus i dont know how much sql i can push though the hiveext.

really i would like to do a insert with a select statement, however i haven't mysqld in a couple of weeks.

Here was some other code i was looking at that was a single row pull from mysql

Code:
//Set the Time
_key = "CHILD:307:";
_result = [_key] call server_hiveReadWrite;
_outcome = _result select 0;
if (_outcome == "PASS") then {
    _date = _result select 1; 
    if (isDedicated) then {
        setDate _date;
        dayzSetDate = _date;
        publicVariable "dayzSetDate";
    };
    diag_log("HIVE: Local Time set to " + str(_date));
};
 
On the Insert, you must also ensure that world_vehicle ID actually exists as an ID in the world_vehicle table (schema) and instance_id is a world ID from the instance table (usually 1).

Also drop the single quotes from the field names and any number values:

Code:
INSERT INTO instance_vehicle (world_vehicle_id, instance_id, worldspace, inventory, parts, fuel, damage, created)
VALUES (36, 1, '[226,[6375.69,8146.38,0.004]]', '[[[],[]],[[],[]],[[],[]]]', '[]', 0, 0, CURRENT_TIMESTAMP);

Hope it helps, have tested that last one on my latest Bliss database, it inserted :)

Edited: Am a bit confused now as I would have thought there would need to be an escape on the commas in the values..? But that INSERT works..

Edit Again: Doh, is inside the single quotes, am losing the plot..
 
Nice im working on this from work on a wamp install on my pc so im just psudo coding for when i get home. The instance is a varible in the init.sqf file, the first query is to get any world vehicle id by vehicle class, i changed that row in my test server to the same and all the vehicles became the same..
 
Been trying to spawn from DB and write using the:
Code:
"HiveEXT" callExtension _key;
.

Nothing doing, so I went back to the Bliss server files and server_publishobject.sqf looks interesting.

Was about to un-comment the diag_log lines in there and pitch a tent and fill to see what got logged.

Somehow broke my local install, can't get anything but:

Code:
21:57:13 Warning Message: Script z\addons\dayz_server\init\server_functions.sqf not found
21:57:13 Warning Message: Script z\addons\dayz_server\system\server_monitor.sqf not found
 
lets see i belive this is what i will need in the mysql for that query:

Code:
CREATE DEFINER=`dayz`@`localhost` PROCEDURE `proc_getVehicleWorldID`(IN `p_className` VARCHAR(100))
begin
  set @classname = p_className; --
  prepare stmt from '
  select
    world_vehicle.id
  from
    world_vehicle,
    vehicle
  where
    vehicle.id = world_vehicle.vehicle_id
  and
    vehicle.class_name = ?
  limit 1'; --
  execute stmt using @classname; --
  deallocate prepare stmt; --
end

This is what myphpadmin gives me:
Code:
SET @p0 = 'AH6X_DZ';
 
CALL `proc_getVehicleWorldID` (
@p0
);
 
 
id
301

which is funny because at first i was like uh no thats wrong, but then what ended up happening is checking the world_vehicle table i found i had 2 littlebird spawns and that was the lower number spawn.

hot on the trail of this bitch

Edit:

Code:
CREATE DEFINER=`dayz`@`localhost` PROCEDURE `proc_getVehicleWorldID`(IN `p_className` VARCHAR(100), IN `p_worldID` SMALLINT(5) UNSIGNED)
begin
  set @classname = p_className; --
  set @worldid = p_worldID; --
  prepare stmt from '
  select
    world_vehicle.id
  from
    world_vehicle,
    vehicle
  where
    vehicle.id = world_vehicle.vehicle_id
  and
    vehicle.class_name = ?
  and
    world_vehicle.world_id = ?
  limit 1'; --
  execute stmt using @classname, @worldid; --
  deallocate prepare stmt; --
end

Code:
SET @p0 = 'AH6X_DZ';
 
SET @p1 = '1';
 
CALL `proc_getVehicleWorldID` (
@p0 , @p1
);
i changed the code to include a world id because i realized that my tables included non cherno worlds too in the default bliss install on my machine and that might be the case for some one else if this starts working..


If i can find a Sql Guru Hopefully i can get a sql string that will do a insert with class name, instance id and vehicle id and then look up the world_vehicle table and do a insert with that information. dam time to brush the dust off my mysql books.
 
And so this is where im too tired to bother any more for tonight:

Code:
//Send the key
_key = format["CHILD:999:select world_vehicle.id from world_vehicle, vehicle where vehicle.id = world_vehicle.vehicle_id and vehicle.class_name = '?' and world_vehicle.world_id = '?' :['%1','%2']:", _saveClass,1];
 
diag_log ("Key sent to server: " + str(_key));
_data = "HiveEXT" callExtension _key;
diag_log("SERVER: Attempting to find world Vehicle id.");
 
 
    //Process result
    _result = call compile format ["%1", _data];
    _status = _result select 0;
 
 
    if (_status == "CustomStreamStart") then {
    diag_log("SUCCESS: ATTEMPTING TO RETRIVE ID.");
};

Its returning something but i dont know what, for all i know its returning nothing, i need to working on the parsing he input because thats screwing up the query..
 
Back
Top