Logo Search packages:      
Sourcecode: sbnc version File versions  Download package

void CUser::Simulate ( const char *  Command,
CClientConnection FakeClient = NULL 
)

Simulate

Executes the specified command in this user's context and redirects the output to the given client (or a dummy client if FakeClient is NULL).

Parameters:
Command the command and its parameters
FakeClient the client which is used for sending replies

Definition at line 552 of file User.cpp.

References AddClientConnection(), CClientConnection::Destroy(), CObject< ObjectType, OwnerType >::GetOwner(), IsRegisteredClientConnection(), CClientConnection::ParseLine(), RemoveClientConnection(), and CObject< ObjectType, OwnerType >::SetOwner().

Referenced by CClientConnection::ProcessBncCommand().

                                                                       {
      bool FakeWasNull, FakeWasRegistered;
      char *CommandDup;
      CUser *OldOwner;

      if (Command == NULL) {
            return;
      }

      if (FakeClient == NULL) {
            FakeWasNull = true;
      } else {
            FakeWasNull = false;
      }

      CommandDup = strdup(Command);

      CHECK_ALLOC_RESULT(CommandDup, strdup) {
            return;
      } CHECK_ALLOC_RESULT_END;

      if (FakeClient == NULL) {
            FakeClient = new CClientConnection(INVALID_SOCKET, NULL);

            CHECK_ALLOC_RESULT(FakeClient, new) {
                  free(CommandDup);

                  return;
            } CHECK_ALLOC_RESULT_END;
      }

      OldOwner = FakeClient->GetOwner();
      FakeClient->SetOwner(this);

      if (!IsRegisteredClientConnection(FakeClient)) {
            AddClientConnection(FakeClient, true);
            FakeWasRegistered = false;
      } else {
            FakeWasRegistered = true;
      }

      FakeClient->ParseLine(CommandDup);

      if (!FakeWasRegistered) {
            RemoveClientConnection(FakeClient, true);
      }

      FakeClient->SetOwner(OldOwner);

      if (FakeWasNull) {
            FakeClient->Destroy();
      }

      free(CommandDup);
}


Generated by  Doxygen 1.6.0   Back to index