Author Topic: Problem with OnClientLeaveGame  (Read 1603 times)

I've got the following plan:

User joins: - List of Users gets send to my webserver.
User leaves: - List of Users gets send to my webserver.

The script is like this right now:

Code: [Select]
function sendVarsToWeb(%vars)
{
  new HTTPObject(varSender);
  varSender.post("adresstoserver:port","pathtophpfile",%vars,"");
}

function sendUserListToWeb() {
  %allnames = "";
  for(%i = 0; %i < ClientGroup.getcount(); %i++){
    %obj = ClientGroup.getobject(%i);
    %name = %obj.name;
    %allnames = %allnames @ "|" @ %name;
  }
  sendVarsToWeb("users=" @ %allnames);
}

package sendServerStatsOnLeave {
  function GameConnection::OnClientLeaveGame(%this)
  {
    sendUserListToWeb();
    Parent::OnClientLeaveGame(%this);
  }
};
ActivatePackage(sendServerStatsOnLeave);

package sendServerStatsOnJoin {
  function GameConnection::OnClientEnterGame(%this)
  {
    sendUserListToWeb();
    Parent::OnClientEnterGame(%this);
  }
};
ActivatePackage(sendServerStatsOnJoin);

I join with my Client (username: Zerosan).
When I've fully joined the server send "users=|Zerosan" to the server, that is fully okay.

Then I disconnect again.
The server sends "users=|Zerosan" again.... that's not okay. It should be empty now!.

What should I do to fix that?

*edit*

Okay, I've fixed it now.
I'm excluding the one who called the OnClientLeaveGame function.

Code: [Select]
function sendVarsToWeb(%vars)
{
  new HTTPObject(varSender);
  varSender.post("adresstoserver:port","/pathtophpfile",%vars,"");
}

function sendUserListToWeb(%client,%mode) {
  if(%mode == 1) {
    %exclude = %client.bl_id;
  }
  for(%i = 0; %i < ClientGroup.getcount(); %i++){
    %obj = ClientGroup.getobject(%i);
    %name = %obj.name;
    %bl_id = %obj.bl_id;
    if(%bl_id == %exclude) { }else{
      %allnames = %allnames @ "|" @ %bl_id @ ":" @ %name;
    }
  }
  sendVarsToWeb("users=" @ %allnames);
}

package sendServerStatsOnLeave {
  function GameConnection::OnClientLeaveGame(%this)
  {
    %client = %this;
    sendUserListToWeb(%client,1);
    Parent::OnClientLeaveGame(%this);
  }
};
ActivatePackage(sendServerStatsOnLeave);

package sendServerStatsOnJoin {
  function GameConnection::OnClientEnterGame(%this)
  {
    %client = %this;
    sendUserListToWeb(%client,0);
    Parent::OnClientEnterGame(%this);
  }
};
ActivatePackage(sendServerStatsOnJoin);
« Last Edit: June 03, 2007, 02:58:35 PM by Zerosan »