Moin,
ich hätte da mal eine kleines Thema zum frühen Morgen. Wir haben auf unserem Server ab und an das Problem, dass Häuser doppelt verkauft werden und dies ist natürlich für alle Beteiligten nicht so schön. Vorallem da nicht sicher ist welches Inventar gerade geladen wird. Daher habe ich mir mal die Funktionen angeschaut und bin darauf gestossen, dass es leider keinerlei Sicherheits Mechanismen in den Scripten gibt. Heisst wenn aus irgendeinem Gund der Haus kaufen Button aktiv ist, kann ich ohne weiteres das Haus für mich beanspruchen.
Da ich noch nicht so lange scripte, wollte ich Euch fragen ob ihr Euch die 2 Scripte mal anschaut und mir gegebenfalls einen Hinweis gebt. Ich bin mir nämlich nicht ganz sicher ob das mit dem Rückgabewert so richtig ist.
#include <macro.h>
/*
Author: Bryan "Tonic" Boardwine
modified by moeck
Description:
Buys the house?
*/
private["_house","_uid","_action","_houseCfg",_"owned"];
_house = [_this,0,ObjNull,[ObjNull]] call BIS_fnc_param;
_uid = getPlayerUID player;
if(isNull _house) exitWith {};
if(!(_house isKindOf "House_F")) exitWith {};
if((_house getVariable["house_owned",false])) exitWith {hint "This house is already owned even though you shouldn't be seeing this hint..."};
if(!isNil {(_house getVariable "house_sold")}) exitWith {hint localize "STR_House_Sell_Process"};
if(!license_civ_home) exitWith {hint localize "STR_House_License"};
if(count life_houses >= (__GETC__(life_houseLimit))) exitWith {hint format[localize "STR_House_Max_House",__GETC__(life_houseLimit)]};
closeDialog 0;
_houseCfg = [(typeOf _house)] call life_fnc_houseConfig;
if(count _houseCfg == 0) exitWith {};
_action = [
format[localize "STR_House_BuyMSG",
[(_houseCfg select 0)] call life_fnc_numberText,
(_houseCfg select 1)],localize "STR_House_Purchase",localize "STR_Global_Buy",localize "STR_Global_Cancel"
] call BIS_fnc_guiMessage;
if(life_atm5cash < (_houseCfg select 0)) exitWith {hint localize "STR_House_NotEnough"};
if(_action) then {
[[_uid,_house],"TON_fnc_addHouse",false,false] spawn life_fnc_MP;
_owned = (_house getVariable "owned");
if (_owned != 1) then {
_house setVariable["house_owner",[_uid,profileName],true];
_house setVariable["locked",true,true];
_house setVariable["Trunk",[[],0],true];
_house setVariable["containers",[],true];
_house setVariable["uid",round(random 99999),true];
life_atm5cash = life_atm5cash - (_houseCfg select 0);
life_2vehicles pushBack _house;
life_houses pushBack [str(getPosATL _house),[]];
hint "Dein Haus wird im Grundbuch eingetragen... Bitte warten..."; //Anti CB Log
_marker = createMarkerLocal [format["house_%1",(_house getVariable "uid")],getPosATL _house];
_houseName = getText(configFile >> "CfgVehicles" >> (typeOf _house) >> "displayName");
_marker setMarkerTextLocal _houseName;
_marker setMarkerColorLocal "ColorBlue";
_marker setMarkerTypeLocal "loc_Lighthouse";
_numOfDoors = getNumber(configFile >> "CfgVehicles" >> (typeOf _house) >> "numberOfDoors");
for "_i" from 1 to _numOfDoors do {
_house setVariable[format["bis_disabled_Door_%1",_i],1,true];
[] call SOCK_fnc_syncData; //Anti CB Log
sleep 5; //Anti CB Log
hint "Dein Haus ist nun angemeldet..."; //Anti CB Log
};
} else {
hint "Sorry aber das Haus gehört bereits jemand anderem!"
};
};
Alles anzeigen
und hier die 2. Datei (Funktion)
/*
Author: Bryan "Tonic" Boardwine
modified by moeck
Description:
Blah
*/
private["_house","_uid","_housePos","_query","_owned"];
_uid = [_this,0,"",[""]] call BIS_fnc_param;
_house = [_this,1,ObjNull,[ObjNull]] call BIS_fnc_param;
if(isNull _house OR _uid == "") exitWith {};
_housePos = getPosATL _house;
waitUntil{!DB_Async_Active};
_query = format["SELECT * FROM houses WHERE pos='%1'",_housePos];
_queryResult = [_query,1] call DB_fnc_asyncCall;
_owned = _queryResult select 5;
if (_owned == 1) then {
_house setVariable["house_id",(_queryResult select 0),true];
_house setVariable["pid",(_queryResult select 1),true];
_house setVariable["pos",(_queryResult select 2),true];
_house setVariable["owned",(_queryResult select 5),true];
[[_house],"life_fnc_buyHouse",false,false] spawn life_fnc_MP;
exit;
} else {
_query = format["INSERT INTO houses (pid, pos, inventory, containers, owned) VALUES('%1', '%2', '""[[],0]""', '""[]""', '1')",_uid,_housePos];
diag_log format["Query: %1",_query];
waitUntil{!DB_Async_Active};
[_query,1] call DB_fnc_asyncCall;
};
sleep 0.3;
waitUntil{!DB_Async_Active};
_query = format["SELECT id FROM houses WHERE pos='%1' AND pid='%2' AND owned='1'",_housePos,_uid];
_queryResult = [_query,2] call DB_fnc_asyncCall;
//systemChat format["House ID assigned: %1",_queryResult select 0];
_house setVariable["house_id",(_queryResult select 0),true];
Alles anzeigen
Schon mal vielen Dank im Voraus.
Gruß,
moeck