TGB/Networking/GameConnection

From TDN

This page is a Work In Progress by Seth Willits, dated May 13, 2008.

TGB Networking >> GameConnection Class

GameConnection Class

The GameConnection class represents the connection from client to server and server to client. When a client connects to a server, the server assigns the client player's name to the client's name field. On the client side, in the connectToServer method, the connection the server is created:

function connectToServer(%ip)
{
   ...

   %conn = new GameConnection(ServerConnection);
   %conn.setConnectArgs($pref::Player::name);
   %conn.connect(%ip);
   
   ...
}

As you can see, the connection from the client to the server is also named "ServerConnection", so at any time, you can access this connection as ServerConnection in script. For example, in the callback of a remote procedure call from the client to the server you can check the client parameter against the ServerConnection object to know if the RPC call came from the server's local client.

function serverCmdDoSomething(%client, %somethingToDo)
{
   // Message was received from the local client
   if (%client == ServerConnection) {
      ...
   
   // Message was received from a remote client
   } else {
      ...
   }
}


Methods:

  • setConnectionArgs
  • setJoinPassword
  • delete(reason) -- disconnect a client for the given reason.