Jump to content
Sign in to follow this  
firefly2442

Arma2MySQL

Recommended Posts

Yes i was thinking of doing something like that.

I'll try this later on and see if i can get it working properly.

Thanks

Share this post


Link to post
Share on other sites

I was wondering if you'd be able to help me with this.

I have a few things set up to save to the DB but it always returns null.

Here are the scripts.

Withdraw money

[[["Wallet",_Wallet],["Account",_Account]],_Player] call DBSaveArray;

DBSaveArray

DBSaveArray =
{
_Var = _this select 0;//Returns [["Wallet",_Wallet],["Account",_Account]]
_Player = _this select 1;//Returns the player i am trying to update in the DB
_PlayerID = getPlayerUID (_this select 1);

disableSerialization;
_Player setVariable ["CanSave",false,true];
   _display = uiNamespace getVariable "VRG_HUD_VAR";
   _ctrlStats = _display displayCtrl 52458;
   _ctrlStats ctrlSetText "Status: Saving";
{
    _VarNameDB = _x select 0;
	_VarSet = _x select 1;
	[[["DBSave",_VarNameDB,_VarSet,_PlayerID],"ServerStats\VariableSave.sqf"],"BIS_fnc_execVM",false,false] spawn BIS_fnc_MP;
}forEach _Var;
sleep 1;
_Player setVariable ["CanSave",true,true];
   _ctrlStats ctrlSetText "Status: Safe";
};

VariableSave.sqf

#include "\x\cba\addons\main\script_macros.hpp"
disableSerialization;
serverRunningQuery = false;

VRG_fnc_formatArray = compile preprocessFileLineNumbers "ServerStats\ToString.sqf";

_case = _this select 0;//Returns "DBSave"

if (_case == "DBSave") then
{
   _VarNameDB = _this select 1;//Returns "Wallet" or "Account" depending on what it's saving
_VarSet = _this select 2;//Returns 0 or 500 depending on what it's saving
_PlayerID = _this select 3;//Returns the players UID (76561198085735088)

   _query = format["UPDATE playerstats SET %1 = '%2' WHERE uid = '%3'", _VarNameDB, _VarSet, _PlayerID];

while{!isNil("serverRunningQuery") && serverRunningQuery} do {};
serverRunningQuery = true;
_return = nil;
while {isNil("_return")} do {
   	_return = "Arma2Net.Unmanaged" callExtension format ["Arma2NETMySQLCommandAsync ['altislife', '%1']", _query];
	hintSilent format["_return = %1", _return];
	if (_return == "") then {
		_return = nil;
	};
		sleep 0.5;
};
serverRunningQuery = false;
};

ArmA2Net log

11/27/2013 18:40:20 function: Arma2NETMySQLCommandAsync ['altislife', 'UPDATE playerstats SET Wallet = '0' WHERE uid = '76561198085735088'']
11/27/2013 18:40:20 maxResultSize: 10239
11/27/2013 18:40:20 Result size: 0
11/27/2013 18:40:20 Result: <null>
11/27/2013 18:40:21 function: Arma2NETMySQLCommandAsync ['altislife', 'UPDATE playerstats SET Account = '500' WHERE uid = '76561198085735088'']
11/27/2013 18:40:21 maxResultSize: 10239
11/27/2013 18:40:21 Result size: 0
11/27/2013 18:40:21 Result: <null>

Databases.txt

# This is a comment
# Any line starting with a "#" is considered a comment
# Make sure each of your database connections doesn't have a "#" in front!
# Put each database connection you want on a separate line
# The databasename MUST be unique!
# For an example, see the following
#databasetype,databasename,ipaddress,port,username,password
#
#mysql,arma,IpAdress,Port,armausername,secret
#sqlite,weaponslite

#SQL Server
#mysql,altislife,119.252.190.185,5000,ArmA3,password

#Local SQL
mysql,altislife,127.0.0.1,2306,root,password

#sqlite,weapons

DB Setup

www.dropbox.com/s/1znrdt99das66hk/Capture.JPG

Hopefully that's enough info haha

Thanks :)

Share this post


Link to post
Share on other sites

@nick103: It looks like the issue is in your DBSaveArray. The way the async version of this works is you can only be interacting with the database one at a time and you have to wait until you get that return result back. Your save code is running both commands in quick succession without waiting for the return value. If you need to run multiple updates like this, look at the example mission here:

https://github.com/firefly2442/Arma2NetMySQLPlugin-Arma3-ExampleMission/blob/master/as_loadouts/selectLoadout.sqf

It uses a "publicVariableClient" and a "while" loop as a mutex to check on the client side where until this is set, it will wait until continuing. At this point, then I know that the server has finished with the query and I can continue. You will need something similar I think.

Also, as an aside, I would not recommend using the root MySQL user. I guess it's OK for local testing but if you deploy this somewhere, you will probably want to change this. Just a small tip.

Good luck. :)

Share this post


Link to post
Share on other sites
@nick103: It looks like the issue is in your DBSaveArray. The way the async version of this works is you can only be interacting with the database one at a time and you have to wait until you get that return result back. Your save code is running both commands in quick succession without waiting for the return value. If you need to run multiple updates like this, look at the example mission here:

https://github.com/firefly2442/Arma2NetMySQLPlugin-Arma3-ExampleMission/blob/master/as_loadouts/selectLoadout.sqf

It uses a "publicVariableClient" and a "while" loop as a mutex to check on the client side where until this is set, it will wait until continuing. At this point, then I know that the server has finished with the query and I can continue. You will need something similar I think.

Ok thanks, I'll try this method when i get access to my Laptop.

Also, as an aside, I would not recommend using the root MySQL user. I guess it's OK for local testing but if you deploy this somewhere, you will probably want to change this. Just a small tip.

Yeah it's only for local testing. When it gets ran on the actual server, it is connected to a remote DB.

Share this post


Link to post
Share on other sites

Nope, still no success.

I can confirm that it is only sending one thing at a time 'cause of the log file.

Here are the upgraded scripts.

DBSaveArray

DBSaveArray =
{
_Var = _this select 0;
_Player = _this select 1;

disableSerialization;
_Player setVariable ["CanSave",false,true];
   _display = uiNamespace getVariable "VRG_HUD_VAR";
   _ctrlStats = _display displayCtrl 52458;
   _ctrlStats ctrlSetText "Status: Saving";
{
    _VarNameDB = _x select 0;
	_VarSet = _x select 1;
	[[["DBSave",_VarNameDB,_VarSet,_Player],"ServerStats\VariableSave.sqf"],"BIS_fnc_execVM",false,false] spawn BIS_fnc_MP;
	while {isNil "ReturnedDatabase"} do {};
	_return = ReturnedDatabase;
	ReturnedDatabase = nil;
	hint format["%1\n\n%2 = %3", _return, _VarNameDB, _VarSet];
}forEach _Var;
sleep 1;
_Player setVariable ["CanSave",true,true];
   _ctrlStats ctrlSetText "Status: Safe";
};

VariableSave.sqf

#include "\x\cba\addons\main\script_macros.hpp"
disableSerialization;
serverRunningQuery = false;

VRG_fnc_formatArray = compile preprocessFileLineNumbers "ServerStats\ToString.sqf";

_case = _this select 0;

if (_case == "DBSave") then
{
   _VarNameDB = _this select 1;
_VarSet = _this select 2;
_Player = _this select 3;
_owner = owner _Player;
_PlayerID = getPlayerUID _player;

   _query = format["UPDATE playerstats SET %1 = '%2' WHERE uid = '%3'", _VarNameDB, _VarSet, _PlayerID];

while{!isNil("serverRunningQuery") && serverRunningQuery} do {};
serverRunningQuery = true;
_return = nil;
while {isNil("_return")} do {
   	_return = "Arma2Net.Unmanaged" callExtension format ["Arma2NETMySQLCommandAsync ['altislife', '%1']", _query];
	hint format["_return = %1", _return];
	if (_return == "") then {
		_return = nil;
	};
		sleep 0.5;
};
serverRunningQuery = false;

ReturnedDatabase = _return;
_owner publicVariableClient "ReturnedDatabase";
};

Error from log file (Same thing over and over again)

11/28/2013 14:43:25 function: Arma2NETMySQLCommandAsync ['altislife', 'UPDATE playerstats SET Wallet = '0' WHERE uid = '76561198085735088'']
11/28/2013 14:43:25 maxResultSize: 10239
11/28/2013 14:43:25 Result size: 0
11/28/2013 14:43:25 Result: <null>

Share this post


Link to post
Share on other sites
Yes, it loops until I exit the mission.

I don't see anything wrong from looking it over. If you run the SQL UPDATE command on Arma2NETExplorer a few times, does it eventually return empty []? If so, I don't think it's anything wrong with the plugin. Have you checked the other log files to make sure everything is OK and it's not encountering an error and returning nil for some reason? Make sure to add an isServer check as well...

Share this post


Link to post
Share on other sites

I have followed the trouble shooting steps for tonics altis life mission even tryed every forum based fix and my compile of the dll, the game will load the mission then completely crashes 'arma3.exe' also arma stopped responding.

What to do??

Share this post


Link to post
Share on other sites
I have followed the trouble shooting steps for tonics altis life mission even tryed every forum based fix and my compile of the dll, the game will load the mission then completely crashes 'arma3.exe' also arma stopped responding.

What to do??

Please post log files for Arma2NET and Arma2NETMySQL. The location of these files can be found in the readme.

Share this post


Link to post
Share on other sites
Do you have the MySQL and SQLite dependencies listed in the readme installed?

Yes. I have both of them installed.

Share this post


Link to post
Share on other sites
Yes. I have both of them installed.

Can you try deleting the log files, re-run it, and then post the log files again. I want to make sure I'm not looking at old results.

Share this post


Link to post
Share on other sites
Can you try deleting the log files, re-run it, and then post the log files again. I want to make sure I'm not looking at old results.

11/30/2013 20:29:34 Arma2Net.Unmanaged loaded successfully

11/30/2013 20:29:35 Fatal unhandled exception of type System.IO.FileNotFoundException

11/30/2013 20:29:35 System.IO.FileNotFoundException: Could not load file or assembly 'Arma2Net.Managed, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8762987cc8e6095e' or one of its dependencies. The system cannot find the file specified.

File name: 'Arma2Net.Managed, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8762987cc8e6095e'

at Arma2Net.Unmanaged.InvokeFunctionImpl(SByte* output, Int32 outputSize, SByte* function)

at Arma2Net.Unmanaged.InvokeFunction(SByte* output, Int32 outputSize, SByte* function)

WRN: Assembly binding logging is turned OFF.

To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.

Note: There is some performance penalty associated with assembly bind failure logging.

To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Share this post


Link to post
Share on other sites
I don't see anything wrong from looking it over. If you run the SQL UPDATE command on Arma2NETExplorer a few times, does it eventually return empty []? If so, I don't think it's anything wrong with the plugin. Have you checked the other log files to make sure everything is OK and it's not encountering an error and returning nil for some reason? Make sure to add an isServer check as well...

Ok, i'll have a quick look aver it later on.

I don't think anything is returning nil 'cause i use hint format["%1", _variable]; to tell me what is being returned ingame.

Share this post


Link to post
Share on other sites
11/30/2013 20:29:34 Arma2Net.Unmanaged loaded successfully

11/30/2013 20:29:35 Fatal unhandled exception of type System.IO.FileNotFoundException

11/30/2013 20:29:35 System.IO.FileNotFoundException: Could not load file or assembly 'Arma2Net.Managed, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8762987cc8e6095e' or one of its dependencies. The system cannot find the file specified.

File name: 'Arma2Net.Managed, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8762987cc8e6095e'

at Arma2Net.Unmanaged.InvokeFunctionImpl(SByte* output, Int32 outputSize, SByte* function)

at Arma2Net.Unmanaged.InvokeFunction(SByte* output, Int32 outputSize, SByte* function)

WRN: Assembly binding logging is turned OFF.

To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.

Note: There is some performance penalty associated with assembly bind failure logging.

To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Do you have the .NET client profile installed? There is a link in the readme for this.

Also, can you check to ensure that the DLL is not blocked? As it states in the readme:

Windows 7 (and other Windows versions?) can sometimes block DLLs from running. If you right click the .dll and click on properties at the bottom of the list there is a security tab. For the precompiled DLL, it knows the DLL came from another computer and thus doesn't trust it. You'll need to enable the DLL to run.

Share this post


Link to post
Share on other sites
Do you have the .NET client profile installed? There is a link in the readme for this.

Also, can you check to ensure that the DLL is not blocked? As it states in the readme:

Okey... Everything is "working" correctly, but the game refuses to communicate (altis life). Maby it is something the provider has done? We have tried everything possible on that box. Multiple settings in sql, rebuilt it, turning everything off... EVERYTHING

Edited by Titan

Share this post


Link to post
Share on other sites
Okey... Everything is "working" correctly, but the game refuses to communicate (altis life). Maby it is something the provider has done? We have tried everything possible on that box. Multiple settings in sql, rebuilt it, turning everything off... EVERYTHING

I'm not sure what you mean by refuses to communicate. Is there an error in the RPT file? Do you think it's an error in the SQF/mission?

Share this post


Link to post
Share on other sites
I'm not sure what you mean by refuses to communicate. Is there an error in the RPT file? Do you think it's an error in the SQF/mission?

rpt has nothing of the crash. Nothing is wrong in the sqf mission as no one else is reporting errors and the exact same process was carried on on multiple boxes.

Share this post


Link to post
Share on other sites
rpt has nothing of the crash. Nothing is wrong in the sqf mission as no one else is reporting errors and the exact same process was carried on on multiple boxes.

Does testing with Arma2NETExplorer work?

Share this post


Link to post
Share on other sites
Does testing with Arma2NETExplorer work?

Yes, it works fine.

Share this post


Link to post
Share on other sites
Yes, it works fine.

Do you have a non-standard install location for Arma3? Can you try copying the unmanaged and managed DLL files from Arma2NET to the root Arma3 folder. Perhaps that will help?

Share this post


Link to post
Share on other sites
Do you have a non-standard install location for Arma3? Can you try copying the unmanaged and managed DLL files from Arma2NET to the root Arma3 folder. Perhaps that will help?

hm... It is in the root folder :L

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×