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

CUser::CUser ( const char *  Name,
safe_box_t  Box 
)

CUser

Constructs a new user object.

Parameters:
Name the name of the user

Definition at line 33 of file User.cpp.

References AddClientConnection(), BadLoginTimer, CCore::BuildPath(), CCore::CreateConfigObject(), CCore::Fatal(), CCore::GetAdminUsers(), CVector< Type >::Insert(), IsAdmin(), IsQuitted(), m_BadLoginPulse, m_ClientCertificates, m_ClientStats, m_Config, m_IRC, m_IRCStats, m_Keys, m_LastReconnect, m_Log, m_Name, m_ReconnectTime, CClientConnection::Privmsg(), ScheduleReconnect(), and SetIRCConnection().

                                             {
      char *Out;
      X509 *Cert;
      FILE *ClientCert;
      safe_box_t TrafficClientStatsBox = NULL, TrafficIRCStatsBox = NULL;

      SetBox(Box);

      m_ManagedMemory = 0;
      m_MemoryManager = NULL;

      m_PrimaryClient = NULL;
      m_ClientMultiplexer = new CClientConnectionMultiplexer(this);
      m_IRC = NULL;
      m_Name = ustrdup(Name);

      CHECK_ALLOC_RESULT(m_Name, strdup) {
            g_Bouncer->Fatal();
      } CHECK_ALLOC_RESULT_END;

      asprintf(&Out, "users/%s.conf", Name);

      CHECK_ALLOC_RESULT(Out, asprintf) {
            g_Bouncer->Fatal();
      } CHECK_ALLOC_RESULT_END;

      m_Config = g_Bouncer->CreateConfigObject(Out, this);

      free(Out);

      CHECK_ALLOC_RESULT(m_Config, new) {
            g_Bouncer->Fatal();
      } CHECK_ALLOC_RESULT_END;

      CacheInitialize(m_ConfigCache, m_Config, "user.");

      m_IRC = NULL;

      m_ReconnectTime = 0;
      m_LastReconnect = 0;

      asprintf(&Out, "users/%s.log", Name);

      CHECK_ALLOC_RESULT(Out, asprintf) {
            g_Bouncer->Fatal();
      } CHECK_ALLOC_RESULT_END;

      m_Log = new CLog(g_Bouncer->BuildPath(Out));

      free(Out);

      CHECK_ALLOC_RESULT(m_Log, new) {
            g_Bouncer->Fatal();
      } CHECK_ALLOC_RESULT_END;

      if (GetBox() != NULL) {
            TrafficClientStatsBox = safe_put_box(GetBox(), "TrafficClientStats");
            TrafficIRCStatsBox = safe_put_box(GetBox(), "TrafficIRCStats");
      }

      m_ClientStats = new CTrafficStats(TrafficClientStatsBox);
      m_IRCStats = new CTrafficStats(TrafficIRCStatsBox);

      m_Keys = new CKeyring(m_Config, this);

      m_BadLoginPulse = new CTimer(200, true, BadLoginTimer, this);

#ifdef USESSL
      asprintf(&Out, "users/%s.pem", Name);

      CHECK_ALLOC_RESULT(Out, asprintf) {
            g_Bouncer->Fatal();
      } CHECK_ALLOC_RESULT_END;

      ClientCert = fopen(g_Bouncer->BuildPath(Out), "r");

      free(Out);

      if (ClientCert != NULL) {
            while ((Cert = PEM_read_X509(ClientCert, NULL, NULL, NULL)) != NULL) {
                  m_ClientCertificates.Insert(Cert);
            }

            fclose(ClientCert);
      }

#endif

      if (IsQuitted() != 2) {
            ScheduleReconnect();
      }

      if (IsAdmin()) {
            g_Bouncer->GetAdminUsers()->Insert(this);
      }

      if (Box != NULL) {
            safe_box_t IRCBox = safe_get_box(Box, "IRC");

            if (IRCBox != NULL) {
                  CIRCConnection *IRC;

                  IRC = new CIRCConnection(NULL, 0, this, IRCBox, NULL);

                  if (IRC != NULL) {
                        SetIRCConnection(IRC);
                  }
            }

            safe_box_t ClientsBox = safe_get_box(Box, "Clients");

            if (ClientsBox != NULL) {
                  safe_element_t *PreviousClient = NULL;
                  char ClientName[128];

                  safe_set_ro(ClientsBox, 1);

                  while (safe_enumerate(ClientsBox, &PreviousClient, ClientName, sizeof(ClientName)) != -1) {
                        CClientConnection *Client;

                        safe_box_t ClientBox = safe_get_box(ClientsBox, ClientName);

                        Client = new CClientConnection(INVALID_SOCKET, ClientBox);

                        if (Client != NULL) {
                              AddClientConnection(Client);

                              if (IsAdmin()) {
                                    Client->Privmsg("shroudBNC seems to have died unexpectedly. However the parent process was able to successfully resurrect it.");
                              }
                        }
                  }

                  safe_set_ro(ClientsBox, 0);
            }     
      }
}


Generated by  Doxygen 1.6.0   Back to index