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

CIRCConnection::CIRCConnection ( const char *  Host,
unsigned short  Port,
CUser Owner,
safe_box_t  Box,
const char *  BindIp,
bool  SSL = false,
int  Family = AF_INET 
)

CIRCConnection

Constructs a new IRC connection object.

Parameters:
Host the server's host name
Port the server's port
Owner the owner of the IRC connection
BindIp bind address (or NULL)
SSL whether to use SSL
Family socket family (either AF_INET or AF_INET6)

Definition at line 39 of file IRCConnection.cpp.

References CFloodControl::AttachInputQueue(), CCore::CreateTimer(), CCore::Fatal(), CUser::GetIdent(), CUser::GetNick(), CUser::GetRealname(), CUser::GetServerPassword(), CUser::GetUsername(), IRCPingTimer, m_Channels, m_CurrentNick, m_DelayJoinTimer, m_EatPong, m_FloodControl, m_ISupport, m_LastResponse, m_NickCatchTimer, m_PingTimer, m_QueueHigh, m_QueueLow, m_QueueMiddle, m_Server, m_ServerFeat, m_ServerVersion, m_Site, m_State, m_Usermodes, CObject< CIRCConnection, CUser >::SetOwner(), CConnection::SetRole(), CConnection::SetSocket(), and CConnection::WriteLine().

                                                                                                                                            : CConnection(Host, Port, BindIp, SSL, Family) {
      const char *Ident;

      SetRole(Role_Client);
      SetOwner(Owner);
      SetBox(Box);

      g_LastReconnect = g_CurrentTime;
      m_LastResponse = g_LastReconnect;

      m_State = State_Connecting;

      m_CurrentNick = NULL;
      m_Server = NULL;
      m_ServerVersion = NULL;
      m_ServerFeat = NULL;
      m_Site = NULL;
      m_Usermodes = NULL;
      m_EatPong = false;

      m_QueueHigh = new CQueue();

      if (m_QueueHigh == NULL) {
            LOGERROR("new operator failed. Could not create queue.");

            g_Bouncer->Fatal();
      }

      m_QueueMiddle = new CQueue();

      if (m_QueueMiddle == NULL) {
            LOGERROR("new operator failed. Could not create queue.");

            g_Bouncer->Fatal();
      }

      m_QueueLow = new CQueue();

      if (m_QueueLow == NULL) {
            LOGERROR("new operator failed. Could not create queue.");

            g_Bouncer->Fatal();
      }

      m_FloodControl = new CFloodControl();

      if (m_FloodControl == NULL) {
            LOGERROR("new operator failed. Could not create flood control object.");

            g_Bouncer->Fatal();
      }

      if (Host != NULL) {
            const char *Password = Owner->GetServerPassword();

            if (Password != NULL) {
                  WriteLine("PASS :%s", Password);
            }

            WriteLine("NICK %s", Owner->GetNick());

            if (Owner->GetIdent() != NULL) {
                  Ident = Owner->GetIdent();
            } else {
                  Ident = Owner->GetUsername();
            }

            WriteLine("USER %s \"\" \"fnords\" :%s", Ident, Owner->GetRealname());
      }

      m_Channels = new CHashtable<CChannel *, false, 16>();

      if (m_Channels == NULL) {
            LOGERROR("new operator failed. Could not create channel list.");

            g_Bouncer->Fatal();
      }

      m_Channels->RegisterValueDestructor(DestroyObject<CChannel>);

      m_ISupport = new CHashtable<char *, false, 32>();
      m_ISupport->RegisterValueDestructor(FreeUString);

      if (m_ISupport == NULL) {
            LOGERROR("new operator failed. Could not create ISupport object.");

            g_Bouncer->Fatal();
      }

      m_ISupport->Add("CHANMODES", ustrdup("bIe,k,l"));
      m_ISupport->Add("CHANTYPES", ustrdup("#&+"));
      m_ISupport->Add("PREFIX", ustrdup("(ov)@+"));
      m_ISupport->Add("NAMESX", ustrdup(""));

      m_FloodControl->AttachInputQueue(m_QueueHigh, 0);
      m_FloodControl->AttachInputQueue(m_QueueMiddle, 1);
      m_FloodControl->AttachInputQueue(m_QueueLow, 2);

      m_PingTimer = g_Bouncer->CreateTimer(180, true, IRCPingTimer, this);
      m_DelayJoinTimer = NULL;
      m_NickCatchTimer = NULL;

      if (Host == NULL && Box != NULL) {
            SOCKET Socket;
            safe_box_t ISupportBox, ChannelsBox;
            const char *Temp;

            Socket = safe_get_integer(Box, "Socket");

            SetSocket(Socket);

            Temp = safe_get_string(Box, "Nick");

            if (Temp != NULL) {
                  m_CurrentNick = ustrdup(Temp);
            }

            Temp = safe_get_string(Box, "Server");

            if (Temp != NULL) {
                  m_Server = ustrdup(Temp);
            }

            Temp = safe_get_string(Box, "ServerVersion");

            if (Temp != NULL) {
                  m_ServerVersion = ustrdup(Temp);
            }

            Temp = safe_get_string(Box, "ServerFeatures");

            if (Temp != NULL) {
                  m_ServerFeat = ustrdup(Temp);
            }

            ISupportBox = safe_get_box(Box, "ISupport");

            if (ISupportBox != NULL) {
                  char Name[128];
                  safe_element_t *Previous = NULL;

                  while (safe_enumerate(ISupportBox, &Previous, Name, sizeof(Name)) != -1) {
                        const char *Value = safe_get_string(ISupportBox, Name);

                        if (Value == NULL) {
                              continue;
                        }

                        m_ISupport->Add(Name, ustrdup(Value));
                  }
            } else {
                  WriteLine("VERSION");
            }

            ChannelsBox = safe_get_box(Box, "Channels");

            if (ChannelsBox != NULL) {
                  char Name[128];
                  safe_element_t *Previous = NULL;

                  Previous = NULL;

                  while (safe_enumerate(ChannelsBox, &Previous, Name, sizeof(Name)) != -1) {
                        CChannel* Channel;
                        safe_box_t ChannelBox;

                        ChannelBox = safe_get_box(ChannelsBox, Name);

                        if (ChannelBox == NULL) {
                              continue;
                        }

                        Channel = new CChannel(Name, this, ChannelBox);

                        if (Channel != NULL) {
                              m_Channels->Add(Name, Channel);
                        }
                  }
            }
      }
}


Generated by  Doxygen 1.6.0   Back to index