From 81722ff786becb636b5f5d5d92fe51bdaab65589 Mon Sep 17 00:00:00 2001 From: brain Date: Sat, 30 Apr 2005 20:56:20 +0000 Subject: Tried a new way of doing remote versions commented some users and connections code added remote @* notice git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1269 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/connection.h | 30 ++++++++++++++++++++++++++---- include/inspircd.h | 1 + include/users.h | 30 ++++++++++++++++++++++++++---- src/commands.cpp | 8 ++++++-- src/connection.cpp | 5 ----- src/inspircd.cpp | 41 ++++++++++++++++++++++++++++++++++++----- src/users.cpp | 1 - 7 files changed, 95 insertions(+), 21 deletions(-) diff --git a/include/connection.h b/include/connection.h index e8af1b648..300a83d4a 100644 --- a/include/connection.h +++ b/include/connection.h @@ -79,6 +79,8 @@ class ircd_connector : public Extensible */ bool SetHostAddress(char* host, int port); + /** This string holds the ircd's version response + */ std::string version; public: @@ -169,12 +171,36 @@ class ircd_connector : public Extensible */ void CloseConnection(); + /** This method adds text to the ircd connection's buffer + * There is no limitation on how much text of what line width may + * be added to this buffer. It is the sending server's responsibility + * to ensure sent data is kept within reasonable quanities. + */ void AddBuffer(std::string a); + + /** This method returns true if the buffer contains at least one + * carriage return character, e.g. one line can be read from the + * buffer successfully. + */ bool BufferIsComplete(); + + /** This method clears the server's buffer by setting it to an empty string. + */ void ClearBuffer(); + + /** This method retrieves the first string from the tail end of the + * buffer and advances the tail end of the buffer past the returned + * string, in a similar manner to strtok(). + */ std::string GetBuffer(); + /** This method sets the version string of the remote server + */ void SetVersionString(std::string newversion); + + /** This method returns the version string of the remote server. + * If the server has no version string an empty string is returned. + */ std::string GetVersionString(); }; @@ -303,10 +329,6 @@ class connection : public Extensible */ bool AddIncoming(int fd,char* targethost, int sourceport); - /** This function is deprecated and may be removed in a later alpha/beta - */ - long GenKey(); - }; diff --git a/include/inspircd.h b/include/inspircd.h index d5f149456..f0199e9dc 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -162,6 +162,7 @@ bool LoadModule(const char* filename); bool UnloadModule(const char* filename); char* ModuleError(); void NoticeAll(userrec *source, bool local_only, char* text, ...); +void NoticeAllOpers(userrec *source, bool local_only, char* text, ...); // mesh network functions diff --git a/include/users.h b/include/users.h index 0dfbc2223..73e1a1173 100644 --- a/include/users.h +++ b/include/users.h @@ -227,10 +227,32 @@ class userrec : public connection */ bool HasPermission(char* command); - bool userrec::AddBuffer(std::string a); - bool userrec::BufferIsReady(); - void userrec::ClearBuffer(); - std::string userrec::GetBuffer(); + /** This method adds data to the buffer of the user. + * The buffer can grow to any size within limits of the available memory, + * managed by the size of a std::string, however if any individual line in + * the buffer grows over 600 bytes in length (which is 88 chars over the + * RFC-specified limit per line) then the method will return false and the + * text will not be inserted. + */ + bool AddBuffer(std::string a); + + /** This method returns true if the buffer contains at least one carriage return + * character (e.g. one complete line may be read) + */ + bool BufferIsReady(); + + /** This function clears the entire buffer by setting it to an empty string. + */ + void ClearBuffer(); + + /** This method returns the first available string at the tail end of the buffer + * and advances the tail end of the buffer past the string. This means it is + * a one way operation in a similar way to strtok(), and multiple calls return + * multiple lines if they are available. The results of this function if there + * are no lines to be read are unknown, always use BufferIsReady() to check if + * it is ok to read the buffer before calling GetBuffer(). + */ + std::string GetBuffer(); }; diff --git a/src/commands.cpp b/src/commands.cpp index 05e0a951c..d66c21125 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -1876,9 +1876,13 @@ void handle_V(char token,char* params,serverrec* source,serverrec* reply, char* if (user) { // notice all - only issuable by a server - if (!strcmp(dest,"*")) + if (!strcmp(dest,"*")) + { + NoticeAll(user,true,"%s",text); + } + if (!strcmp(dest,"@*")) { - NoticeAll(user,true,"%s",text); + NoticeAllOpers(user,true,"%s",text); } else { diff --git a/src/connection.cpp b/src/connection.cpp index 5cdd83f7f..debd3144f 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -546,8 +546,3 @@ bool connection::RecvPacket(std::deque &messages, char* recvhost) return false; } -long connection::GenKey() -{ - return (random()*time(NULL)); -} - diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 2671de21b..2a15f265c 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -197,10 +197,6 @@ int portCount = 0, UDPportCount = 0, ports[MAXSOCKS]; int defaultRoute = 0; char ModPath[MAXBUF]; -connection C; - -long MyKey = C.GenKey(); - /* prototypes */ int has_channel(userrec *u, chanrec *c); @@ -947,6 +943,41 @@ void WriteOpers(char* text, ...) } } +void NoticeAllOpers(userrec *source, bool local_only, char* text, ...) +{ + if ((!text) || (!source)) + { + log(DEFAULT,"*** BUG *** NoticeAllOpers was given an invalid parameter"); + return; + } + + char textbuffer[MAXBUF]; + va_list argsPtr; + va_start (argsPtr, text); + vsnprintf(textbuffer, MAXBUF, text, argsPtr); + va_end(argsPtr); + + for (std::vector::iterator i = all_opers.begin(); i != all_opers.end(); i++) + { + userrec* a = *i; + if ((a) && (a->fd != FD_MAGIC_NUMBER)) + { + if (strchr(a->modes,'s')) + { + // send server notices to all with +s + WriteServ(a->fd,"NOTICE %s :*** Notice From %s: %s",a->nick,source->nick,textbuffer); + } + } + } + + if (!local_only) + { + char buffer[MAXBUF]; + snprintf(buffer,MAXBUF,"V %s @* :%s",source->nick,textbuffer); + NetSendToAll(buffer); + } +} + // returns TRUE of any users on channel C occupy server 'servername'. bool ChanAnyOnThisServer(chanrec *c,char* servername) @@ -1181,7 +1212,7 @@ void NoticeAll(userrec *source, bool local_only, char* text, ...) { if ((!text) || (!source)) { - log(DEFAULT,"*** BUG *** WriteOpers was given an invalid parameter"); + log(DEFAULT,"*** BUG *** NoticeAll was given an invalid parameter"); return; } diff --git a/src/users.cpp b/src/users.cpp index 0d305a3b7..7348c6db3 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -202,7 +202,6 @@ void userrec::ClearBuffer() std::string userrec::GetBuffer() { - log(DEBUG,"GetBuffer\n%s\n",recvq.c_str()); char* line = (char*)recvq.c_str(); std::string ret = ""; while ((*line != '\n') && (strlen(line))) -- cgit v1.2.3