summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2014-02-15 11:17:10 +0100
committerTreeki <treeki@gmail.com>2014-02-15 11:17:10 +0100
commitf5c91243ce04b5fab96ebe8838e384b0356793e0 (patch)
treea218cbcb468f3b4a5473d657f4892e39147b45ec
parent848c96b0df5282a9089bd4259e3e6ae3620f3ec9 (diff)
downloadbounce4-f5c91243ce04b5fab96ebe8838e384b0356793e0.tar.gz
bounce4-f5c91243ce04b5fab96ebe8838e384b0356793e0.zip
add nick colours, fix a bug with RGB colours in richtext
-rw-r--r--bouncer/richtext.cpp17
-rw-r--r--bouncer/richtext.h6
-rw-r--r--bouncer/window.cpp27
-rw-r--r--python_client.py5
4 files changed, 43 insertions, 12 deletions
diff --git a/bouncer/richtext.cpp b/bouncer/richtext.cpp
index 22c6330..2deebda 100644
--- a/bouncer/richtext.cpp
+++ b/bouncer/richtext.cpp
@@ -174,3 +174,20 @@ const char *RichTextBuilder::c_str() {
return data();
}
+
+
+
+void RichTextBuilder::appendNick(const char *nick) {
+ uint32_t hash = 0;
+ const char *c = nick;
+ while (*c)
+ hash = (hash * 17) + *(c++);
+
+ int r = ((hash & 0xFF0000) >> 16);
+ int g = ((hash & 0xFF00) >> 8);
+ int b = (hash & 0xFF);
+
+ foreground(COL_LEVEL_NICK, r, g, b);
+ append(nick);
+ endForeground(COL_LEVEL_NICK);
+}
diff --git a/bouncer/richtext.h b/bouncer/richtext.h
index 608a1d6..c2f8d01 100644
--- a/bouncer/richtext.h
+++ b/bouncer/richtext.h
@@ -48,6 +48,11 @@ public:
void colour(bool background, int layer, int r, int g, int b) {
writeU8(0x10 + (background ? 4 : 0) + layer);
+
+ r >>= 1;
+ g >>= 1;
+ b >>= 1;
+
writeU8((r==0)?2:(r&254));
writeU8((g==0)?1:g);
writeU8((b==0)?1:b);
@@ -86,6 +91,7 @@ public:
}
void appendIRC(const char *str);
+ void appendNick(const char *nick);
const char *c_str();
};
diff --git a/bouncer/window.cpp b/bouncer/window.cpp
index 04689f5..a8a7bb2 100644
--- a/bouncer/window.cpp
+++ b/bouncer/window.cpp
@@ -171,6 +171,13 @@ void StatusWindow::handleUserInput(const char *str) {
pushMessage("Server password changed.");
else
pushMessage("Server password cleared.");
+
+ } else if (strcmp(str, "/c") == 0) {
+ RichTextBuilder rt;
+ rt.foreground(2, 100, 0, 255);
+ rt.append("boooooop");
+ rt.endForeground(2);
+ pushMessage(rt.c_str());
}
} else {
server->sendLine(str);
@@ -303,7 +310,7 @@ void Channel::outputUserAction(int colour, const UserRef &user, const char *pref
rt.append("You have ");
} else {
rt.bold();
- rt.append(user.nick.c_str());
+ rt.appendNick(user.nick.c_str());
rt.endBold();
rt.append(" (");
@@ -428,14 +435,14 @@ void Channel::handleKick(const UserRef &user, const char *target, const char *me
inChannel = false;
rt.append("You have been kicked by ");
- rt.append(user.nick.c_str());
+ rt.appendNick(user.nick.c_str());
} else {
if (user.isSelf) {
rt.append("You have kicked ");
} else {
rt.bold();
- rt.append(user.nick.c_str());
+ rt.appendNick(user.nick.c_str());
rt.endBold();
rt.append(" has kicked ");
}
@@ -476,13 +483,13 @@ void Channel::handleNick(const UserRef &user, const char *newNick) {
rt.append("You are now known as ");
} else {
rt.bold();
- rt.append(user.nick.c_str());
+ rt.appendNick(user.nick.c_str());
rt.endBold();
rt.append(" is now known as ");
}
rt.bold();
- rt.append(newNick);
+ rt.appendNick(newNick);
rt.endBold();
pushMessage(rt.c_str());
@@ -544,7 +551,7 @@ void Channel::handleMode(const UserRef &user, const char *str) {
rt.append("-- ");
rt.bold();
- rt.append(user.nick.c_str());
+ rt.appendNick(user.nick.c_str());
rt.endBold();
rt.append(addFlag ? " set mode " : " cleared mode ");
@@ -582,7 +589,7 @@ void Channel::handleMode(const UserRef &user, const char *str) {
rt.append("-- ");
rt.bold();
- rt.append(user.nick.c_str());
+ rt.appendNick(user.nick.c_str());
rt.endBold();
rt.append(addFlag ? " set channel mode " : " cleared channel mode ");
@@ -616,7 +623,7 @@ void Channel::outputUserMessage(const char *nick, const char *str, bool isAction
rt.writeS8(prefix);
rt.bold();
- rt.append(nick);
+ rt.appendNick(nick);
rt.endBold();
rt.append(isAction ? " " : "> ");
@@ -635,7 +642,7 @@ void Channel::handleCtcp(const UserRef &user, const char *type, const char *para
rt.append("*** CTCP from ");
rt.bold();
- rt.append(user.nick.c_str());
+ rt.appendNick(user.nick.c_str());
rt.endBold();
rt.append(": ");
@@ -655,7 +662,7 @@ void Channel::handleTopic(const UserRef &user, const char *message) {
if (user.isValid) {
rt.append("*** ");
rt.bold();
- rt.append(user.nick.c_str());
+ rt.appendNick(user.nick.c_str());
rt.endBold();
rt.append(" changed the topic to: ");
} else {
diff --git a/python_client.py b/python_client.py
index d30993c..9cfcd74 100644
--- a/python_client.py
+++ b/python_client.py
@@ -235,8 +235,9 @@ class WindowTab(QtWidgets.QWidget):
col = PRESET_COLOURS[bit1 >> 1]
pos += 1
elif (pos + 3) < l:
- bit2 = ord(msg[pos + 2])
- bit3 = ord(msg[pos + 3])
+ bit1 <<= 1
+ bit2 = ord(msg[pos + 2]) << 1
+ bit3 = ord(msg[pos + 3]) << 1
pos += 3
col = QtGui.QColor(bit1,bit2,bit3)