Game Development Community

Need some help for Client server issue

by M Sazzad Karim · in Torque Game Engine · 08/20/2006 (1:14 pm) · 1 replies

Hi,

I need some help from Any Torque Gurus, regarding some client server issues in my code.

1. I noticed that, in th ejoinServerGui.gui, in Join() function, there are some code for
setting up the name of the client player and also password.

function JoinServerGui::join(%this)
{
... Some code ...

if (setServerInfo(%index)) {
%conn = new GameConnection(ServerConnection);
%conn.setConnectArgs($pref::Player::Name);
%conn.setJoinPassword($Client::Password);
%conn.connect($ServerInfo::Address);
}

}


I need to get the $pref::Player::Name and verify the $Client::Password in ther server side, when the
client try to connect and assign specific role to that client.

Can any Torque gurus help me in this regards?

#1
10/18/2006 (8:11 pm)
From what I can tell the engine code verifies this for you already.

Checkout \engine\game\gameConnection.cc
GameConnection::readConnectRequest

stream->readString(joinPassword);
...

   const char *serverPassword = Con::getVariable("Pref::Server::Password");
   if(serverPassword[0])
   {
      if(dStrcmp(joinPassword, serverPassword))
      {
         *errorString = "CHR_PASSWORD";
         return false;
      }
   }


So, on the server side in script you need to set the password with
Pref::Server::Password



On the script side on the server, the name of the player and all the args you pass in to the call
%conn.setConnectArgs($pref::Player::Name);
are received here:

\example\common\server\clientConnection.cs
//-----------------------------------------------------------------------------
// This script function is called before a client connection
// is accepted.  Returning "" will accept the connection,
// anything else will be sent back as an error to the client.
// All the connect args are passed also to onConnectRequest
//
function GameConnection::onConnectRequest( %client, %netAddress, %name )
{
   echo("Connect request from: " @ %netAddress);
   if($Server::PlayerCount >= $pref::Server::MaxPlayers)
      return "CR_SERVERFULL";
   return "";
}

The extra args you pass in you would need to add after the %name var.