Question about client / server cmd.
by Claude-Alain Fournier · in Torque Game Engine · 09/29/2004 (10:32 pm) · 2 replies
I am not 100% sure on how this is working.
Let say I have this structure :
CLIENT SIDE script :
SERVER SIDE script:
As you can see in this code I expect each call here to be done sequentially.
MyClientFoo()
commandToServer('FooServer')
----------- network --------------
serverCmdFooServer(...)
commandToClient('FooClient',...)
----------- network --------------
clientCmdFooClient(...)
doSomething(...)
So am I correct to expect this ? or will if be more like doSomething function is called just after the commandToServer is called even before server side is finished :
MyClientFoo()
commandToServer('FooServer')
doSomething(...)
----------- network --------------
serverCmdFooServer(...)
commandToClient('FooClient',...)
----------- network --------------
clientCmdFooClient(...)
I do believe that the 2nd one is the correct assumption but I like to have some expert opinions.
Thanks,
CAF
Let say I have this structure :
CLIENT SIDE script :
$var1 = 0 ;
$var2 = 0 ;
function MyClientFoo()
{
// ask server to send me some information
commandToServer("FooServer") ;
// here process the information......
doSomething($var1, $var2)
}
function clientCmdFooClient(%var1, %var2)
{
$var1 = %var1 ;
$var2 = %var2 ;
} SERVER SIDE script:
function serverCmdFooServer(%client)
{
%var1 = "some info 1" ;
%var2 = "some info 2" ;
commandToClient("FooClient", %var1, %var2) ;
}As you can see in this code I expect each call here to be done sequentially.
MyClientFoo()
commandToServer('FooServer')
----------- network --------------
serverCmdFooServer(...)
commandToClient('FooClient',...)
----------- network --------------
clientCmdFooClient(...)
doSomething(...)
So am I correct to expect this ? or will if be more like doSomething function is called just after the commandToServer is called even before server side is finished :
MyClientFoo()
commandToServer('FooServer')
doSomething(...)
----------- network --------------
serverCmdFooServer(...)
commandToClient('FooClient',...)
----------- network --------------
clientCmdFooClient(...)
I do believe that the 2nd one is the correct assumption but I like to have some expert opinions.
Thanks,
CAF
Torque Owner Claude-Alain Fournier
2nd assumption is correct.
I had this problem to manage client logout so as to save player position. Here is the bit of code I use now :
CLIENT SIDE : (serverConnection.cs)
function disconnectPlayer() { commandToServer('Logout') ; } function clientCmdForceDisconnect() { schedule(500, 0, disconnect); } function disconnect() { // Delete the connection if it's still there. if (isObject(ServerConnection)) ServerConnection.delete(); disconnectedCleanup(); // Call destroyServer in case we're hosting destroyServer(); }SERVER SIDE :
function serverCmdLogout(%client) { ServerSetSpawnPoint(%client) ; // Save player spawn point for next login ServerLogout(%client, true) ; // Save other login information, log action, history etc.... commandToClient(%client, 'ForceDisconnect') ; }Remark that I scheduled the disconnect, in fact the clientCmd... function has to be terminated before the server disconnect otherwise the application crash, with a network event assert. That's why the schedule is there, it could probably be shorted than 500 msec but so far I am happy with it.
I also changed the escapeFromGame() function in default.bind.cs so as to call disconnectPlayer() and not disconnect().
Seems a bit twisted but that is the only way I found so far.
If that help somebody, I'd be happy.
Regards,
CAF