Server Client
by Robert Stewart · in Torque Game Engine · 10/25/2004 (10:03 am) · 22 replies
I have a problem, on my server i have a script file, i only want to be called from the server, so there should be no need for it on the client. Here is an example, this is the most updated server script "example\fps\server\scripts"
function CheckPhp(%client, %username, %passcrc)
{
echo "12345";
}
This is the outdated file, on the client side "example\fps\server\scripts"
function CheckPhp(%client, %username, %passcrc)
{
echo "54321";
}
When the client calls Checkphp(); I want the client to use the servers script, not its own. as i see it client should only ever need to use "example\fps\client\scripts" and server "example\fps\server\scripts". thanks for any help.
function CheckPhp(%client, %username, %passcrc)
{
echo "12345";
}
This is the outdated file, on the client side "example\fps\server\scripts"
function CheckPhp(%client, %username, %passcrc)
{
echo "54321";
}
When the client calls Checkphp(); I want the client to use the servers script, not its own. as i see it client should only ever need to use "example\fps\client\scripts" and server "example\fps\server\scripts". thanks for any help.
About the author
#2
10/25/2004 (10:44 am)
Can you explain that, what does "me" and "pass" do? is that the variables? like CheckPhp($client, $this); ? thanks
#3
10/25/2004 (10:47 am)
Sure, the format is commandToServer( commandName, ... ); where ... is the list of variables to pass. the ´ mess are single quotes by the way.
#4
10/25/2004 (10:48 am)
Me would be the object that called the server function , pass would be the first parameter passed into the server command
#5
10/25/2004 (10:51 am)
I know about those single quotes there annoying lol, thanks. this is exactly what i wanted.
#6
10/25/2004 (10:52 am)
Oh and the server recieves the command by tacking serverCmd to the front of the commandName and calling a function of the resulting name. In this case it would look for serverCmdCheckPhp().
#7
function serverCmdCheckPhp(%client, %username, %passcrc)
{
commandToClient(%client, 'ForceDisconnect') ;
}
but that would send %client, if i wanted to send multiple variables, how would i do that?
10/25/2004 (11:22 am)
One more question, for sending to client i guess i use this function serverCmdCheckPhp(%client, %username, %passcrc)
{
commandToClient(%client, 'ForceDisconnect') ;
}
but that would send %client, if i wanted to send multiple variables, how would i do that?
#8
commandToClient(%client, %username, %passcrc, 'Updater') ;
I get a "Remote Command Error"
10/25/2004 (12:14 pm)
Would this work? commandToClient(%client, %username, %passcrc, 'Updater') ;
I get a "Remote Command Error"
#9
10/25/2004 (12:17 pm)
CommandToClient (%client, commandName, [variable list] );
#10
CommandToClient (%client, 'Updater', %username, %passcrc );
i have this as the client side
function clientCmdUpdater(%client, %username, %passcrc)
{
echo (%username);
echo "Working";
}
Thanks
10/25/2004 (12:22 pm)
Is this right? CommandToClient (%client, 'Updater', %username, %passcrc );
i have this as the client side
function clientCmdUpdater(%client, %username, %passcrc)
{
echo (%username);
echo "Working";
}
Thanks
#11
Client,
Server,
10/25/2004 (12:45 pm)
Ok i think i have most of this working, i still get an error "clientCmdUpdater : unkown command" here is my code, Client,
function Update()
{
commandToServer('UpdatePhp') ;
}
function clientCmdUpdater(%client, %username, %passcrc)
{
echo (%username);
echo "Working";
}Server,
function serverCmdUpdatePhp(%client, %username, %passcrc)
{
%username = "stuff";
%passcrc = "stuff";
commandToClient(%client,'Updater', %username) ;
}
#12
10/25/2004 (1:00 pm)
If this function does what I think it does, I suggest you do NOT make this evokeable from the client, but only call it from the server - unless it's activated by a client's keypress anyway.
#13
function clientCmdUpdater(%client, %username, %passcrc)
{
echo (%username);
echo ("Working");
}
Just missing those parentheses for the echo command.
10/25/2004 (1:01 pm)
You have a syntax error that is braking the funciton, should be:function clientCmdUpdater(%client, %username, %passcrc)
{
echo (%username);
echo ("Working");
}
Just missing those parentheses for the echo command.
#14
l
Martin, lol thanks man.
10/25/2004 (1:18 pm)
Josef, how do you do it? i noticed you were on the persistence resource, how exactly do you do it? pass from client to server, securelyl
Martin, lol thanks man.
#15
l
Martin, lol thanks man.
10/25/2004 (1:23 pm)
Josef, how do you do it? i noticed you were on the persistence resource, how exactly do you do it? pass from client to server, securelyl
Martin, lol thanks man.
#16
10/25/2004 (1:24 pm)
Its working now, but Josef if you have a better way of doing this securely, then please post Thanks.
#17
Note that this means that the client is already in the game (hence you should not spawn a player yet, just an observer camera)
In effect this looks a bit like this:
Then, add the following functions:
10/26/2004 (1:22 am)
The best place to start the client authentication is in GameConnection::onClientEnterGame() in game.csNote that this means that the client is already in the game (hence you should not spawn a player yet, just an observer camera)
In effect this looks a bit like this:
function GameConnection::onClientEnterGame(%this)
{
commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);
%this.camera = new Camera() {
dataBlock = Observer;
};
MissionCleanup.add( %this.camera );
%this.camera.scopeToClient(%this);
// Setup game parameters, the onConnect method currently starts
// everyone with a 0 score.
%this.score = 0;
echo("No auth yet, spawning observer...");
%this.camera.setTransform(pickObserverPoint(%this));
%this.camera.setVelocity("0 0 0");
%this.setControlObject(%this.camera);
if (%this.getAddress() $= "local")
{
$authSuccessfull[%this] = true;
echo ("Skipping authentication for hosting player");
$initialSpawnDone[%this] = true;
%this.spawnPlayer();
}
else
{
checkClientLogin(%this, %this.nameBase, %this.passcrc);
//give 30 seconds for response or boot him!
%this.loginLoop = schedule(30000, 0, "clientLoginFailed", %this);
}Then, add the following functions:
//The following settings assumes that the php file
//game_login.php exists at http://www.bla.com/auth/game_login.php
$AuthServer = "myserver.com:80"; //url and port
$AuthServerPath = "/auth/"; //server path
function checkClientLogin(%client, %username, %passcrc)
{
%client.authReturned = false;
%query = "user="@%username@"\t"@
"passcrc="@%passcrc@"\t"@
"action=login";
%server = $AuthServer;
%path = $AuthServerPath;
%script = %path @ "game_login.php";
%upd = new HTTPObject(CharLogin);
%upd.clientid = %client;
%upd.get(%server, %script, %query);
}
#18
In GameConnection::onConnect() inside the same game.cs search for this part:
...and replace it with this block:
Now all you need to make this work on the webserver is the php file from the persistent character resource - either the original one or my version. You might have to tweak the result strings or other things, so please read and understand the code before you just use it ;)
10/26/2004 (1:23 am)
Function CharLogin::onLine( %this, %line )
{
%client = %this.clientid;
//Check if webpage returns the word Verified on the first line (this could be improved)
if(StrStr(%line, "Verified") != -1)
{
// Inform the client we've joined up
messageClient(%client,
'MsgClientJoin', 'Login authenticated successfully.',
%client.name,
%client,
%client.sendGuid,
%client.score,
%client.isAiControlled(),
%client.isAdmin,
%client.isSuperAdmin);
if ($initialSpawnDone[%client] == false)
{
echo ("Auth completed successfully, spawning player");
$initialSpawnDone[%client] = true;
%client.spawnPlayer();
}
$authSuccessfull[%client] = true;
cancel(%client.loginLoop);
return;
}
//otherwise, auth failed!
$authSuccessfull[%client] = false;
error("- ",%line);
clientLoginFailed(%client);
}
function CharLogin::onConnectionDied( %this )
{
%client = %this.clientid;
clientLoginFailed(%client);
}
function CharLogin::onDNSFailed( %this )
{
%client = %this.clientid;
clientLoginFailed(%client);
}
function CharLogin::onConnectFailed( %this )
{
%client = %this.clientid;
clientLoginFailed(%client);
}
function clientLoginFailed(%client)
{
echo ("ERROR: Client disconnected due to authentication error");
%client.delete();
}In GameConnection::onConnect() inside the same game.cs search for this part:
// if hosting this server, set this client to superAdmin
if (%client.getAddress() $= "local") {
%client.isAdmin = true;
%client.isSuperAdmin = true;
}...and replace it with this block:
$authSuccessfull[%client] = false;
$initialSpawnDone[%client] = false;
// if hosting this server, set this client to superAdmin
if (%client.getAddress() $= "local") {
$authSuccessfull[%client] = true;
%client.isAdmin = true;
%client.isSuperAdmin = true;
}Now all you need to make this work on the webserver is the php file from the persistent character resource - either the original one or my version. You might have to tweak the result strings or other things, so please read and understand the code before you just use it ;)
#19
I've tested this code extensively and it should work without any problems. If you're ok with clients spawning as observer while not authenticated, this should be sufficient for you.
Also note that I'm doing a client-side initiated authentication too, but that is only to confirm to the user that his username/password are correct, so he doesn't have to get booted from a server to find out that his data is wrong.
10/26/2004 (1:28 am)
Note: This method differs from what is suggested in the persistent character resource, and I have my reasons for doing that. You get all kinds of problems if you start authenticating while the mission loads. Also note that this code runs SERVER-SIDE, not client-side - hence my "$authSuccessfull[%client]"-arrays. I've tested this code extensively and it should work without any problems. If you're ok with clients spawning as observer while not authenticated, this should be sufficient for you.
Also note that I'm doing a client-side initiated authentication too, but that is only to confirm to the user that his username/password are correct, so he doesn't have to get booted from a server to find out that his data is wrong.
#20
10/26/2004 (6:59 am)
What does this mean? "You get all kinds of problems if you start authenticating while the mission loads" i cant see any problems with that, but anyway Ill review that code, you helped allot with this topic, Thanks.
Torque Owner Owen Ortmayer
ex: