diff --git a/chatclient.go b/chatclient.go
index d2b8145..5c0c0c0 100644
--- a/chatclient.go
+++ b/chatclient.go
@@ -191,6 +191,11 @@ func (cl *Client) setName(s string) error {
return nil
}
+func (cl *Client) setColor(s string) error {
+ cl.color = s
+ return cl.SendChatData(common.NewChatHiddenMessage(common.CdColor, cl.color))
+}
+
func (cl *Client) replaceColorizedName(chatData common.ChatData) common.ChatData {
data := chatData.Data.(common.DataMessage)
data.Message = cl.regexName.ReplaceAllString(data.Message, `$1`)
diff --git a/chatcommands.go b/chatcommands.go
index 48f41e6..6678cec 100644
--- a/chatcommands.go
+++ b/chatcommands.go
@@ -127,7 +127,7 @@ var commands = &CommandControl{
}
if len(args) == 0 {
- cl.color = common.RandomColor()
+ cl.setColor(common.RandomColor())
return "Random color chosen: " + cl.color
}
@@ -136,7 +136,11 @@ var commands = &CommandControl{
return "To choose a specific color use the format /color #c029ce. Hex values expected."
}
- cl.color = args[0]
+ err := cl.setColor(args[0])
+ if err != nil {
+ common.LogErrorf("[color] could not send color update to client: %v\n", err)
+ }
+
common.LogInfof("[color] %s new color: %s\n", cl.name, cl.color)
return "Color changed successfully."
},
diff --git a/common/colors.go b/common/colors.go
index 57fb7b1..f2c18e1 100644
--- a/common/colors.go
+++ b/common/colors.go
@@ -47,8 +47,7 @@ var (
)
// IsValidColor takes a string s and compares it against a list of css color names.
-// It also accepts hex codes in the form of #000 (RGB), to #00000000 (RRGGBBAA), with A
-// being the alpha value
+// It also accepts hex codes in the form of #RGB and #RRGGBB
func IsValidColor(s string) bool {
s = strings.ToLower(s)
for _, c := range colors {
diff --git a/common/constants.go b/common/constants.go
index e52d4d7..305ee9d 100644
--- a/common/constants.go
+++ b/common/constants.go
@@ -8,6 +8,7 @@ const (
CdUsers // get a list of users
CdPing // ping the server to keep the connection alive
CdAuth // get the auth levels of the user
+ CdColor // get the users color
)
type DataType int
diff --git a/static/js/chat.js b/static/js/chat.js
index 9910cd0..f49fd53 100644
--- a/static/js/chat.js
+++ b/static/js/chat.js
@@ -1,5 +1,21 @@
///