No Guaranteed message
by Howard Dortch · in Torque 3D Professional · 11/16/2009 (7:41 pm) · 4 replies
I have a little issue with a multiplayer game and some possible communications issues(client/server messages). I will try to make this simple but if you need more deatail I can supply it.
I need to have a user interact with an object. Only one user at a time can interact with the object. On the server side I do this
function Tank::interact(%this, %obj, %client)
{
if(%obj.inUse)
{
message user "Object in Use"
return;
}
%obj.inUse = true;
%client.player.IObj = %obj; <<<<<< save which object the player interacts with.
commandToClient(%client,'UseObject');
}
On the Client side I open a dialog do what ever then when done issue a message back to server that I am done. Then I pop the dialog.
CommandToServer('Done');
And on the server
function serverCmdDone(%client)
{
%obj = %client.player.IObj;
%obj.inUse = false;
}
This works well with one or two players but after I get three or four players in the Object in Use message starts poping up for some of the objects eventually all of them. It doesn't happen all the time and it doesn't happen at any trapable time it seems random. I have alot going on in this game. It seems the message from the client to the server to release access to the object never gets received by the server so is there ANY way I can guarantee a message from client to server without having to code some god awful handshake routine?
Thanks in advance.
I need to have a user interact with an object. Only one user at a time can interact with the object. On the server side I do this
function Tank::interact(%this, %obj, %client)
{
if(%obj.inUse)
{
message user "Object in Use"
return;
}
%obj.inUse = true;
%client.player.IObj = %obj; <<<<<< save which object the player interacts with.
commandToClient(%client,'UseObject');
}
On the Client side I open a dialog do what ever then when done issue a message back to server that I am done. Then I pop the dialog.
CommandToServer('Done');
And on the server
function serverCmdDone(%client)
{
%obj = %client.player.IObj;
%obj.inUse = false;
}
This works well with one or two players but after I get three or four players in the Object in Use message starts poping up for some of the objects eventually all of them. It doesn't happen all the time and it doesn't happen at any trapable time it seems random. I have alot going on in this game. It seems the message from the client to the server to release access to the object never gets received by the server so is there ANY way I can guarantee a message from client to server without having to code some god awful handshake routine?
Thanks in advance.
#2
Thanks for the reply, If you want to see how the interact works I would post it for you.
11/16/2009 (11:03 pm)
The interact works perfectly, it is the close dialog, release the inUse boolean that fails. After the user has finished with the object meaning on the client side they close the dialog, the message should go to the server and the code will release or set the inUse to false so someone else can use it. I know the interact works because I get the message that the object is inUse otherwise that would never happen.Thanks for the reply, If you want to see how the interact works I would post it for you.
#3
Also, if there's something you're not comfortable with posting publicly feel free to email it to me and I can take a look at it. I know how it is when the boss doesn't like code posted on forums and you need a second set of eyes.
11/16/2009 (11:42 pm)
It might help. That was just my first instinct based on what was there. It could be that the right client isn't being accessed. Have you tried echoing the client and its player to make sure they're right?Also, if there's something you're not comfortable with posting publicly feel free to email it to me and I can take a look at it. I know how it is when the boss doesn't like code posted on forums and you need a second set of eyes.
#4
On the client .....
function useObject(%val)
{
if(%val)
commandToServer('interact'); // calls server interact
}
moveMap.bind(keyboard, "u", useObject);
function serverCmdinteract(%client)
{
... RAYCAST code removed for brevity
%Targ.getDataBlock().interact(%obj,%client);
}
and the code I posted before on the server
function Tank::interact(%this, %obj, %client)
{
if(%obj.inUse)
{
commandToClient(%client,'BottomPrint',"Object is currently being used ",3,1);
return;
}
commandToClient(%client,'TankDlgUse');
}
11/17/2009 (7:57 pm)
Im sure the right client gets called because it's that client that has the dialog open so there is no mistake. There is no magic here and this is not the problem, the client is not passing the close message to the server.On the client .....
function useObject(%val)
{
if(%val)
commandToServer('interact'); // calls server interact
}
moveMap.bind(keyboard, "u", useObject);
function serverCmdinteract(%client)
{
... RAYCAST code removed for brevity
%Targ.getDataBlock().interact(%obj,%client);
}
and the code I posted before on the server
function Tank::interact(%this, %obj, %client)
{
if(%obj.inUse)
{
commandToClient(%client,'BottomPrint',"Object is currently being used ",3,1);
return;
}
commandToClient(%client,'TankDlgUse');
}
Associate Scott Burns
GG Alumni
Just based on what's here interact will probably need to become a serverCmd depending on how it's getting called. Past that I'd need to see the code within interact for sending the user the message that the object is in use as that looks to me where the root of the problem may be.