summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-03-02 11:31:37 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-03-02 11:31:37 +0000
commit21a1aec26cfa93e468912080c60d92c4d43b0f0c (patch)
treec711281b2556277655260dd24995edac91b21b27
parent18c757067c0a9e5c1aa81496dca8428a0bf3635f (diff)
De-uglified chanrec::SetCustomMode -- no strlcat, no std::string, just some very clever pointer voodoo
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3415 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--src/channels.cpp62
-rwxr-xr-xsrc/svn-rev.sh2
2 files changed, 49 insertions, 15 deletions
diff --git a/src/channels.cpp b/src/channels.cpp
index 92ad3b78c..3901530a6 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -81,24 +81,59 @@ void chanrec::SetCustomMode(char mode,bool mode_on)
{
if (mode_on)
{
- static char m[3];
- m[0] = mode;
- m[1] = '\0';
- if (!strchr(this->custom_modes,mode))
+ char* mptr = this->custom_modes;
+ int ssize = 0;
+
+ /* Attempt to find the end of the mode string */
+ while (*mptr++)
{
- strlcat(custom_modes,m,MAXMODES);
+ /* While iterating the mode string, we found that they already have
+ * this mode in their list. Abort right now. */
+ if (*mptr == mode)
+ return;
+ /* Increment the string size, saves us doing strlen */
+ ssize++;
}
- log(DEBUG,"Custom mode %c set",mode);
- }
- else {
- std::string a = this->custom_modes;
- int pos = a.find(mode);
- a.erase(pos,1);
- strlcpy(this->custom_modes,a.c_str(),MAXMODES);
+ log(DEBUG,"ssize=%d",ssize);
+
+ /* Is there room left in the buffer? If there is append the mode */
+ if (ssize < MAXMODES-1)
+ {
+ *--mptr = mode;
+ *++mptr = 0;
+ }
+
+ log(DEBUG,"Custom mode %c set, modes='%s'",mode,this->custom_modes);
+ }
+ else
+ {
+ char* mptr = this->custom_modes;
+ bool shift_down = false;
+ /* Iterate through the string */
+ while (*mptr)
+ {
+ /* When we find the mode we intend to remove, set the
+ * flag to tell the loop to start moving chars down
+ * one place
+ */
+ if (*mptr == mode)
+ shift_down = true;
+ /* If we're moving chars down one place, take the current
+ * char, and move it down one slot, so:
+ * ABC\0 becomes BBC\0 then next iteration, BBC\0 becomes
+ * BC\0.
+ */
+ if (shift_down)
+ *mptr = *(mptr+1);
+ *mptr++;
+ }
log(DEBUG,"Custom mode %c removed: modelist='%s'",mode,this->custom_modes);
- this->SetCustomModeParam(mode,"",false);
+
+ /* Only call this if we found the mode */
+ if (shift_down)
+ this->SetCustomModeParam(mode,"",false);
}
}
@@ -130,7 +165,6 @@ void chanrec::SetCustomModeParam(char mode,char* parameter,bool mode_on)
}
}
}
- log(DEBUG,"*** BUG *** Attempt to remove non-existent mode parameter!");
}
}
diff --git a/src/svn-rev.sh b/src/svn-rev.sh
index 5c5377de5..c773323d3 100755
--- a/src/svn-rev.sh
+++ b/src/svn-rev.sh
@@ -1 +1 @@
-echo 3411
+echo 3414