Game Development Community

Urgent question

by Ivan · in Torque Game Engine · 06/22/2006 (3:18 pm) · 2 replies

Hi all,

I have an urgent question, which should be easy to answer for any experienced tnl user but is not very clear to me. I have the following RPC code, which is called by a client and is executed on the server side.

TNL_IMPLEMENT_RPC(GameConnection, rpcMessageClientToServer, (TNL::ByteBufferPtr data), (data), NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirClientToServer, 0)
{
printf("Message arrived: \n");
ClientPacket* cPacket = (ClientPacket*) data->getBuffer();
//here server should get the info somehow, not sure how
}

Several clients connect to the server and each of them send information(cPacket) to the server, which has to be collected and later broadcast back to each of the connected clients. However, after the execution of the RPC code, the data(cPacket) goes out of scope. How can I copy it to some buffer on the server before this?

Thanks a lot. Any feedback will be greatly appreciated.

About the author

Recent Threads


#1
06/22/2006 (6:01 pm)
This data (through the RPC) is being sent from client to server. That means the server end of the connection is receiving it. Therefore, within your RPC, you can call this->getNetInterface(). This NetInterface will be the server's net interface. You can store your data within this interface as long as you wish.

To send the data back to your clients, you will need another RPC method (RPCDirServerToClient) which your server will call, passing in the data as a parameter.

Or if you wish to dispatch the data immediately, you can call the toClient RPC from within the above RPC. i.e:

TNL_IMPLEMENT_RPC(GameConnection, rpcMessageClientToServer, (TNL::ByteBufferPtr data), (data), NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirClientToServer, 0)
{
printf("Message arrived: \n");
ClientPacket* cPacket = (ClientPacket*) data->getBuffer();

// loop through each connection (this->getNetInterface()->getConnectionList() I believe is the call)
    rpcMessageServerToClient(/* pass in data here */);
}

Hope that helps.
#2
06/23/2006 (4:39 am)
Thanks a lot for your answer, it worked well!!