Jump to content
Sign in to follow this  
Heeeere's johnny!

BIS_fnc_MP not executing given code serverside

Recommended Posts

Hey guyz,

so I'm trying to send an SQL query (string) from a client to the server which then should call an extension to actually execute that on the database. Now, the extension stuff works and database connectivity works just fine. But I'm wondering why the following code does not seem to work at all:

[color=#FF8040][color=#1874CD]_query[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]format[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"SELECT p.name, COUNT(h.ownerUID) FROM players p, houses h WHERE p.playerUID = '%1' AND p.playerUID = h.ownerUID"[/color][color=#8B3E2F][b],[/b][/color] [color=#191970][b]getPlayerUID[/b][/color] [color=#000000]player[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
[color=#8B3E2F][b][[/b][/color]
   [color=#8B3E2F][b][[/b][/color][color=#1874CD]_query[/color][color=#8B3E2F][b],[/b][/color] [color=#000000]player[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b],[/b][/color]
   [color=#8B3E2F][b]{[/b][/color]
       [color=#191970][b]diag_log[/b][/color] [color=#191970][b]format[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"query and player: %1"[/color][color=#8B3E2F][b],[/b][/color] [color=#000000]_this[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
       [color=#8B3E2F][b][[/b][/color]
           [color=#8B3E2F][b]([/b][/color][color=#000000]_this[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]call[/b][/color] JON_fnc_queryDB[color=#8B3E2F][b],[/b][/color]
           [color=#8B3E2F][b]{[/b][/color][color=#191970][b]diag_log[/b][/color] [color=#191970][b]format[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"%1"[/color][color=#8B3E2F][b],[/b][/color] [color=#000000]_this[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color] houseOwnerInfo [color=#8B3E2F][b]=[/b][/color] [color=#000000]_this[/color][color=#8B3E2F][b];[/b][/color][color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b],[/b][/color]
           [color=#191970][b]owner[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#000000]_this[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b],[/b][/color]
           [color=#000000]false[/color]
       [color=#8B3E2F][b]][/b][/color] [color=#191970][b]spawn[/b][/color] BIS_fnc_MP[color=#8B3E2F][b];[/b][/color]
   [color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b],[/b][/color]
   [color=#000000]false[/color][color=#8B3E2F][b],[/b][/color]
   [color=#000000]false[/color]
[color=#8B3E2F][b]][/b][/color] [color=#191970][b]spawn[/b][/color] BIS_fnc_MP[color=#8B3E2F][b];[/b][/color][color=#006400][/color]
[/color]

Kudos to Killzone_Kid for his SQF to BBCode Converter.

To explain what that does (for those who don't see it right away):

The player and query string are sent to the server which then calls a function to execute the query on the DB and return the result (JON_fnc_queryDB). The result is returned to the calling client (represented by the given player) and written into a global variable there.

To check if even anything is going on, I added some diag_logs. But seemingly, nothing happens at all. Nothing is being written to the RPT logs, no script errors occure on either client or server side, I don't know what I'm doing wrong here.

Does anyone see the issue here? I'd be very glad for help.

Kind regards,

Johnny

Share this post


Link to post
Share on other sites

unless i missed something lately, im not sure you can pass a code { block } in place of command/script name. Also needs to be called, not spawned***(edit: wiki claims call execution, but a quick test on my machine showed spawn still worked)

there is mention in the notes on BIS_fnc_MP about passing code as a parameter

or just function-ize:

[[(getPlayerUID player),player],"HJ_fnc_Query",false,false] call BIS_fnc_MP;

HJ_fnc_Query = {
   _query = format ["SELECT p.name, COUNT(h.ownerUID) FROM players p, houses h WHERE p.playerUID = '%1' AND p.playerUID = h.ownerUID", (_this select 0)];
   _return = (_query) call JON_fnc_queryDB;
   [_return, "HJ_fnc_Return", owner (_this select 1), false] call BIS_fnc_MP;
};

HJ_fnc_Return = {
   diag_log format ["%1", _this];
   houseOwnerInfo = _this;
};

thats untested code, more of a break-down theory

Edited by dr_strangepete

Share this post


Link to post
Share on other sites

Why not just use publicvariableserver and addpublicvariableeventhandler?

Share this post


Link to post
Share on other sites
Why not just use publicvariableserver and addpublicvariableeventhandler?

That's how BIS_fnc_MP actually works. ;)

Well, I solved it as dr_strangepete suggested as this seems most reasonable. It's strange though because I'm 99% sure that I've used this very syntax not too long ago to send and execute code serverside. It's even more interesting that no script error is shown, but nothing happens. I think, I'll need to analyze the function some day to understand why that is the case.

Cheers,

Johnny

Share this post


Link to post
Share on other sites

Keep in mind when using spawn that new processes get put into the scheduler, which could increase the time it takes for the server to get the data, this may cause an empty string to be sent back after a request. Also, I think with fnc_MP, a packet is sent to all players, dramatically increasing network traffic. It would be much safer to use publicVariableServer and publicVariableClient and a few specialized public variable event handlers

Share this post


Link to post
Share on other sites

Yes my point exactly, why include BIS_fnc_MP unnecessarily when you can just use the publicvariableserver and addpublicvariableeventhandler.

Share this post


Link to post
Share on other sites
I think with fnc_MP, a packet is sent to all players, dramatically increasing network traffic. It would be much safer to use publicVariableServer and publicVariableClient and a few specialized public variable event handlers

It is not, it is sent directly to the server via publicVariableServer and then the server checks the conditions and then if it is needed it will tell the clients what to execute, If it is a specific client it uses publicVariableClient. It is a fairly robust system.

Also the syntax originally posted is wrong which is why it is not executing but you are better off making it a function as it's not recommended to send code over the network constantly.

Share this post


Link to post
Share on other sites

Also the syntax originally posted is wrong which is why it is not executing but you are better off making it a function as it's not recommended to send code over the network constantly.

Yeah, I already fixed that, but thanks for mentioning it. I won't update the code here though as you might understand. Anyway, I did not consider it a problem to send code if it's (other than this case) just a tiny snippet or if function to send the code is called only occasionally.

Share this post


Link to post
Share on other sites

I confused after now reading through this thread. So does anybody have an example of how to remotely execute code or function using BIS_fnc_MP from client to server, as in Dedicated server. In other words client instructs server to run code. I thought that was not possible with BIS_fnc_MP only client to client or server to client. Those are the results I've gotten in tests several months back anyways. I know it can be done with EH and PVserver as work around for BIS_fnc_MP.

Share this post


Link to post
Share on other sites
I confused after now reading through this thread. So does anybody have an example of how to remotely execute code or function using BIS_fnc_MP from client to server, as in Dedicated server. In other words client instructs server to run code. I thought that was not possible with BIS_fnc_MP only client to client or server to client. Those are the results I've gotten in tests several months back anyways. I know it can be done with EH and PVserver as work around for BIS_fnc_MP.

https://community.bistudio.com/wiki/BIS_fnc_MP

set 'target' to false to execute on the server. if you look at my earlier post, line 1 bis_fnc_mp call has target (_this select 2) false - this first calls the function HJ_fnc_Query on the server only, which inturn calls the client on line 6 (_this select 2 is set to the player) with the sql results.

Or, passing code based on Fireball's note:

[{diag_log 'message received';}, "BIS_fnc_call", false, false, true] call BIS_fnc_MP;
// log message on server only

Edited by dr_strangepete
correction

Share this post


Link to post
Share on other sites
https://community.bistudio.com/wiki/BIS_fnc_MP

[{diag_log 'message received';}, "BIS_fnc_call", false, false, true] call BIS_fnc_MP;
// log message on server only

You linked it yourself, but still your code is just almost correct ;)

[[[], {diag_log 'message received';}], "BIS_fnc_call", false, false, true] call BIS_fnc_MP;

Share this post


Link to post
Share on other sites
You linked it yourself' date=' but still your code is just almost correct ;)[/quote']

It is correct, try it ;)

BIS_fnc_call & spawn do not require an array as parameter, you can send the code block as a parameter itself, if you're not passing anything else (depends on what you need to accomplish)

edit, side note:

Infact, BIS_fnc_call just includes BIS_fnc_spawn, which uses call internally...so the only thing actually determining whether or not a function is called or spawned is the bis_fnc_mp 5th parameter - isCall. I would have figured fnc_spawn would atleast spawn where called. as-such, you can pass code alone as a single non-array parameter for both functions...yay

Edited by dr_strangepete

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  

×