Jump to content
  • 0

Client Side (Player) Logging to Server Log.


axeman

Question

I have seen a couple of threads where debugging is becoming an issue and thought I would share one of the tools I have written.

 

Basically it allows you to add an entry to the server log, normally done with diag_log at the server, from the client (player) side of your mission scripts. Normally, for the client, hint is the only way to do any sensible debugging. I now use this religiously when scripting.

 

All this does is setup a public variable event handler that, when called, runs a small script on the server that logs whatever is sent to it via the public variable.

 

The reason for this requirement, if you have tried doing a diag_log from the client you will have noticed that nothing appears in the server log. This is because of locality. In short, not all things are available to the client that are for the server and vice/versa.

 

If you are serious about scripting locality is one thing you will want to get your head around, it explains why a lot of things that, at first glance, appear like they should work but just don't..

 

To Install:

 

In init.sqf (in your mission folder) add (Or add the relevant code to an existing isServer):

if (isServer) then {
axe_server_log = compile preprocessFileLineNumbers "tools\logtorpt.sqf";
"axeDiagLog" addPublicVariableEventHandler {_id = (_this select 1) spawn axe_server_log};
};

Create a folder called tools in your mission folder and add logtorpt.sqf (this can be packaged in, and referenced from, dayz_server.pbo):

//logtorpt.sqf
private ["_targetObj"];
_targetObj = _this;
diag_log format["AXELOG: %1",_targetObj];

Then when you want to create a log entry from your clientside code use this as an example (the key bits are the last two lines):

_var1 = "wow";
_var2 = "a log entry.";
axeDiagLog = format["I am logging something here: 1st Var=%1 | 2nd Var=%2.",_var1,_var2];//Set the public variable value
publicVariable "axeDiagLog";//Send the public variable 'to the event handler'

Obviously you can make axeDiagLog pretty much anything you want. That example will then appear in your server side log as:

13:49:31 "AXELOG:I am logging something here: 1st Var=wow | 2nd Var=a log entry."

This is creating public variables so may cause network issues if overdone. Always remove for live servers to increase performance.

 

That said I have had this running at hundreds of logs per second on my test server and had no noticeable lag with 2 to 3 players in testing. Is entirely possible this could be optimised using publicVariableServer instead, it works so I haven't 'fixed' it.

 

That's it, server side logging from the client, enjoy.. :)

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Thanks for that. I actually used a smiliar method just for a single purpose and no general log handler (described here, step 4 http://dayzepoch.com/forum/index.php?/topic/3603-release-areal-maintenance-for-player-bases-script/), but I was thinking about that.. but when I am testing my scripts I can just log to my client RPT so I thought why.. :D

 

Anyway about the DevCon tool I mentioned in the other thread, I got it working so far I can see the HUD and type into it, but nothing is happening and not executing my commands sadly (I am logged in as local admin as the wiki says). :/

I just need a way to type in text in game, why is there no input dialog in ArmA??? :(

 

Edit: I would add a client side function to make the log available as 1 command, just so there is no need to use publicVariable all the time and can be later customized in that function:

remote_log = {
	axeDiagLog = _this select 0;
	publicVariable "axeDiagLog";
};

// then call it simply like this
["foo bar"] call remote_log;
// or like this
[format["foo %1", "bar"]] call remote_log;
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Discord

×
×
  • Create New...