Datablock & server -> client update
by Frank Bignone · in Torque Game Engine · 04/09/2002 (2:55 pm) · 7 replies
Hello,
I have some datablocks that defines weapon HUD (to be used by a global weapon management system), like that :
I want that these declaration is managed by the server in order to :
- prevent cheating
- allow updates for each client if a server defines new weapon HUD
The problem I have is that if these datablocks are not defined on a client, it will not be possible to use them as the client does not know them (dunno !). You will then tell me it's normal !
So my question : is there a way to define 'new' datablock on the server and have all clients updated with these datablocks definition even if not defined on a client script ?
(It may be related to one thread about object download, but I 'm not quite sure)
I have some datablocks that defines weapon HUD (to be used by a global weapon management system), like that :
datablock WeaponIconData(DefaultMissileHud)
{
type = 1;
staticBitmap = "~/client/data/hud/weapon/missile_static.png";
lockBitmap = "~/client/data/hud/weapon/missile_locked.png";
staticColor = "1.0 1.0 1.0 1.0";
lockedColor = "1.0 0.0 0.0 1.0";
linVel = 200;
angVel = 100;
fov = 0;
timeout = 0;
follow = false;
foe = true;
num = 1;
};I want that these declaration is managed by the server in order to :
- prevent cheating
- allow updates for each client if a server defines new weapon HUD
The problem I have is that if these datablocks are not defined on a client, it will not be possible to use them as the client does not know them (dunno !). You will then tell me it's normal !
So my question : is there a way to define 'new' datablock on the server and have all clients updated with these datablocks definition even if not defined on a client script ?
(It may be related to one thread about object download, but I 'm not quite sure)
About the author
Real programmers don't waste time recompiling; they patch the binary files... ... Real programmers don't waste time patching binary files; they patch memory.
#2
The client must of course know about the classes that are used to make the datablocks. In the case of your example, the client would have to have the necessary engine code to be able to make objects of type WeaponIconData. But the client scripting does not create the datablock named DefaultMissileHud; the server scripting creates that and then it is sent to the client.
Sooo... I'm not sure what your worry is, Frank. Could you take another stab at describing it?
04/09/2002 (6:26 pm)
Datablocks are defined by the server-side scripting, and then transmitted to the client as part of the client's mission-load sequence.The client must of course know about the classes that are used to make the datablocks. In the case of your example, the client would have to have the necessary engine code to be able to make objects of type WeaponIconData. But the client scripting does not create the datablock named DefaultMissileHud; the server scripting creates that and then it is sent to the client.
Sooo... I'm not sure what your worry is, Frank. Could you take another stab at describing it?
#3
coder adds a datablock to the server side,
wants to use it client side. dug in a bit, but
got swamped with other priorities.
Matt will be covering Datablocks in the TGE Scripting Documentation, he mentioned that he might have something for the comminity this weeken.
-Ron
04/09/2002 (6:47 pm)
same type of question in IRC this eveningcoder adds a datablock to the server side,
wants to use it client side. dug in a bit, but
got swamped with other priorities.
Matt will be covering Datablocks in the TGE Scripting Documentation, he mentioned that he might have something for the comminity this weeken.
-Ron
#4
in hud.cs, I have the datablock declaration.
in game.cs, I execute the hud.cs script (so it will be executed only for the server)
Both client & server have the same exec (so the client know the core C++ class corresponding to the datablock).
On the server side, the player knows the MissileHud, but on the client side when I tried to access the MissileHud things I have a message which says MissileHud unknow datablock. Here is the C++ code which is executed from client script to add the MissileHud :
It seems then that the findObject cannot retrieve the MissileHud datablock.
My questions :
1) is it normal ?
2) if yes, how can I dynamically tell the client that a 'new' datablock exists and he may use it.
Hope it's clear ;)
04/10/2002 (1:38 am)
To be more precise, here is what I did :in hud.cs, I have the datablock declaration.
in game.cs, I execute the hud.cs script (so it will be executed only for the server)
Both client & server have the same exec (so the client know the core C++ class corresponding to the datablock).
On the server side, the player knows the MissileHud, but on the client side when I tried to access the MissileHud things I have a message which says MissileHud unknow datablock. Here is the C++ code which is executed from client script to add the MissileHud :
In C++:
static void cSetWeaponIcon(SimObject *obj, S32, const char **argv)
{
GuiWeaponHud *ctrl = static_cast<GuiWeaponHud*>(obj);
WeaponIconData *icon;
if( Sim::findObject(argv[2], icon) )
ctrl->setWeaponIcon(icon, dAtoi( argv[3]) );
else
Con::warnf("setWeaponIcon: %s datablock does not exist (or is not a WeaponIconData)",argv[2]);
}
On the client script side:
WeaponHud.setWeaponIcon(MissileHud,1);It seems then that the findObject cannot retrieve the MissileHud datablock.
My questions :
1) is it normal ?
2) if yes, how can I dynamically tell the client that a 'new' datablock exists and he may use it.
Hope it's clear ;)
#5
For example:
I am working on an explosion editor, When it is opened the first time it executes a .cs with all default explosion datablocks the editor uses. These Datablocks are unusable/dont work corectly because all the datablocks were transmitted at mission start, until they are transmitted to the client using the function Transmitdatablocks().
see gameConnection.cc for more information on how it works.
Seems to me this is what you want to do but I'm not sure.
Edit: I use this little function in my script debugging sometimes to output what datablocks are loaded to the console.
function FindDatablocks(%this)
{
for(%i = 0; %i < DataBlockGroup.getCount(); %i++)
{
echo(%i @ ": " @ DataBlockGroup.getObject(%i).getname());
}
}
Just trying to give some Ideas. Hope its relative to what you are trying to do.
04/10/2002 (5:14 am)
the transmitdatablock function I mentioned above Will transmit datablock changes to the client after the game is already started.For example:
I am working on an explosion editor, When it is opened the first time it executes a .cs with all default explosion datablocks the editor uses. These Datablocks are unusable/dont work corectly because all the datablocks were transmitted at mission start, until they are transmitted to the client using the function Transmitdatablocks().
see gameConnection.cc for more information on how it works.
Seems to me this is what you want to do but I'm not sure.
Edit: I use this little function in my script debugging sometimes to output what datablocks are loaded to the console.
function FindDatablocks(%this)
{
for(%i = 0; %i < DataBlockGroup.getCount(); %i++)
{
echo(%i @ ": " @ DataBlockGroup.getObject(%i).getname());
}
}
Just trying to give some Ideas. Hope its relative to what you are trying to do.
#6
However if you need to send over datablocks later (as in Bruce's case where he is editing them), that's doable too. transmitDatablocks would indeed be the thing to use, but I'm a little concerned about its sequence number argument and the way that interacts with the current scripting in the TGE SDK. I've only just now glanced at the code for this, but here's what it looks like:
- If you send a sequence number of zero, which is an invalid mission sequence number in the current scripting, then up to 16 new/modified datablocks will be sent, but after that the code will check and see that the sequence number is incorrect and stop sending datablocks. Also, onDataBlocksDone will be executed if there are no new/modified datablocks to send, but otherwise it will not be executed.
- If on the other hand you send $missionSequence as the sequence number, all of the new/modified datablocks should get sent over, regardless of how many there are. This will cause onDataBlocksDone to be invoked when it is done; onDataBlocksDone should check the loading phase number and bail out. So this is probably the correct way to go. However, I haven't tried it out.
04/10/2002 (10:01 am)
I don't want to beat this point into the ground, but just so that no one is left confused: The standard approach with datablocks is to define all necessary datablocks on the server during mission load, before calling loadMission for any of the clients. Then the datablocks will be sent to the clients automatically. So if there's no reason why you should need to create that HUD datablock in the middle of the game, you should create it along with the other datablocks before the client loadMission stuff in loadMissionStage2, and everything should be fine.However if you need to send over datablocks later (as in Bruce's case where he is editing them), that's doable too. transmitDatablocks would indeed be the thing to use, but I'm a little concerned about its sequence number argument and the way that interacts with the current scripting in the TGE SDK. I've only just now glanced at the code for this, but here's what it looks like:
- If you send a sequence number of zero, which is an invalid mission sequence number in the current scripting, then up to 16 new/modified datablocks will be sent, but after that the code will check and see that the sequence number is incorrect and stop sending datablocks. Also, onDataBlocksDone will be executed if there are no new/modified datablocks to send, but otherwise it will not be executed.
- If on the other hand you send $missionSequence as the sequence number, all of the new/modified datablocks should get sent over, regardless of how many there are. This will cause onDataBlocksDone to be invoked when it is done; onDataBlocksDone should check the loading phase number and bail out. So this is probably the correct way to go. However, I haven't tried it out.
#7
04/10/2002 (10:35 am)
That will work, a few MOD'ers had used the function for T2.
Torque 3D Owner Bruce Wallace
localClientConnection.transmitDataBlocks(0);
Dunno If that will help you.