Added generated usernames and colors.
This commit is contained in:
parent
2107ebff56
commit
1a1a23383f
|
|
@ -120,8 +120,8 @@ function jumpBySteps(steps) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function recvChatMessage(sender, text) {
|
function recvChatMessage(sender, text, color = "white") {
|
||||||
divlog('<font color="#c0ff80"><b>' + sender + ':</b> '
|
divlog('<font color="' + color + '"><b>' + sender + ':</b> '
|
||||||
+ text + '</font>', false);
|
+ text + '</font>', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1178,7 +1178,7 @@ function on_ws_recv(evt) {
|
||||||
divlog(json['value'], true);
|
divlog(json['value'], true);
|
||||||
break;
|
break;
|
||||||
case 'chat_message':
|
case 'chat_message':
|
||||||
recvChatMessage(json['sender'], json['text']);
|
recvChatMessage(json['sender'], json['text'], json['color']);
|
||||||
break;
|
break;
|
||||||
case 'backoff':
|
case 'backoff':
|
||||||
divlog("Server is currently busy: " + json['reason'], true);
|
divlog("Server is currently busy: " + json['reason'], true);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
from owrx.config import Config
|
from owrx.config import Config
|
||||||
|
from owrx.color import ColorCache
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
|
@ -29,6 +30,9 @@ class ClientRegistry(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.clients = []
|
self.clients = []
|
||||||
self.bans = {}
|
self.bans = {}
|
||||||
|
self.chat = {}
|
||||||
|
self.chatCount = 0
|
||||||
|
self.chatColors = ColorCache()
|
||||||
Config.get().wireProperty("max_clients", self._checkClientCount)
|
Config.get().wireProperty("max_clients", self._checkClientCount)
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
|
@ -51,6 +55,8 @@ class ClientRegistry(object):
|
||||||
|
|
||||||
def removeClient(self, client):
|
def removeClient(self, client):
|
||||||
try:
|
try:
|
||||||
|
if client in self.chat:
|
||||||
|
del self.chat[client]
|
||||||
self.clients.remove(client)
|
self.clients.remove(client)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
@ -62,9 +68,18 @@ class ClientRegistry(object):
|
||||||
client.close()
|
client.close()
|
||||||
|
|
||||||
# Broadcast chat message to all connected clients.
|
# Broadcast chat message to all connected clients.
|
||||||
def broadcastChatMessage(self, sender: str, text: str):
|
def broadcastChatMessage(self, client, text: str):
|
||||||
|
if client in self.chat:
|
||||||
|
name = self.chat[client]["name"]
|
||||||
|
color = self.chat[client]["color"]
|
||||||
|
else:
|
||||||
|
name = "User%04d" % (self.chatCount + 1)
|
||||||
|
color = self.chatColors.getColor(name)
|
||||||
|
self.chat[client] = { "name": name, "color": color }
|
||||||
|
self.chatCount = (self.chatCount + 1) % 9999
|
||||||
|
|
||||||
for c in self.clients:
|
for c in self.clients:
|
||||||
c.write_chat_message(sender, text)
|
c.write_chat_message(name, text, color)
|
||||||
|
|
||||||
# List all active and banned clients.
|
# List all active and banned clients.
|
||||||
def listAll(self):
|
def listAll(self):
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
class ColorCache:
|
||||||
|
def __init__(self):
|
||||||
|
# Use these colors for labels
|
||||||
|
self.colors = [
|
||||||
|
"#FFFFFF", "#999999", "#FF9999", "#FFCC99", "#FFFF99", "#CCFF99",
|
||||||
|
"#99FF99", "#99FFCC", "#99FFFF", "#99CCFF", "#9999FF", "#CC99FF",
|
||||||
|
"#FF99FF", "#FF99CC",
|
||||||
|
]
|
||||||
|
# Labels are cached here
|
||||||
|
self.colorBuf = {}
|
||||||
|
|
||||||
|
# Get a unique color for a given ID, reusing colors as we go
|
||||||
|
def getColor(self, id: str) -> str:
|
||||||
|
if id in self.colorBuf:
|
||||||
|
# Sort entries in order of freshness
|
||||||
|
color = self.colorBuf.pop(id)
|
||||||
|
elif len(self.colorBuf) < len(self.colors):
|
||||||
|
# Assign each initial entry color based on its order
|
||||||
|
color = self.colors[len(self.colorBuf)]
|
||||||
|
else:
|
||||||
|
# If we run out of colors, reuse the oldest entry
|
||||||
|
color = self.colorBuf.pop(next(iter(self.colorBuf)))
|
||||||
|
# Done
|
||||||
|
self.colorBuf[id] = color
|
||||||
|
return color
|
||||||
|
|
||||||
|
def rename(self, old_id: str, new_id: str):
|
||||||
|
if old_id in self.colorBuf and new_id != old_id:
|
||||||
|
self.colorBuf[new_id] = self.colorBuf[old_id]
|
||||||
|
del self.colorBuf[old_id]
|
||||||
|
|
@ -21,7 +21,6 @@ from abc import ABCMeta, abstractmethod
|
||||||
import json
|
import json
|
||||||
import threading
|
import threading
|
||||||
import struct
|
import struct
|
||||||
import re
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
@ -346,8 +345,7 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient):
|
||||||
elif message["type"] == "sendmessage":
|
elif message["type"] == "sendmessage":
|
||||||
if "text" in message:
|
if "text" in message:
|
||||||
ClientRegistry.getSharedInstance().broadcastChatMessage(
|
ClientRegistry.getSharedInstance().broadcastChatMessage(
|
||||||
re.sub("^::ffff:", "", self.conn.getIp()),
|
self, message["text"]
|
||||||
message["text"]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
@ -491,9 +489,14 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient):
|
||||||
def write_backoff_message(self, reason):
|
def write_backoff_message(self, reason):
|
||||||
self.send({"type": "backoff", "reason": reason})
|
self.send({"type": "backoff", "reason": reason})
|
||||||
|
|
||||||
def write_chat_message(self, sender, text):
|
def write_chat_message(self, sender, text, color = "white"):
|
||||||
logger.debug("Sending {0}".format({"type": "chat_message", "sender": sender, "text": text}))
|
logger.debug("Sending {0}".format({"type": "chat_message", "sender": sender, "text": text}))
|
||||||
self.send({"type": "chat_message", "sender": sender, "text": text})
|
self.send({
|
||||||
|
"type": "chat_message",
|
||||||
|
"sender": sender,
|
||||||
|
"text": text,
|
||||||
|
"color": color
|
||||||
|
})
|
||||||
|
|
||||||
def write_modes(self, modes):
|
def write_modes(self, modes):
|
||||||
def to_json(m):
|
def to_json(m):
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from owrx.storage import Storage
|
from owrx.storage import Storage
|
||||||
from owrx.config import Config
|
from owrx.config import Config
|
||||||
|
from owrx.color import ColorCache
|
||||||
from csdr.module import LineBasedModule
|
from csdr.module import LineBasedModule
|
||||||
from pycsdr.types import Format
|
from pycsdr.types import Format
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
@ -13,38 +14,6 @@ import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ColorCache:
|
|
||||||
def __init__(self):
|
|
||||||
# Use these colors for labels
|
|
||||||
self.colors = [
|
|
||||||
"#FFFFFF", "#999999", "#FF9999", "#FFCC99", "#FFFF99", "#CCFF99",
|
|
||||||
"#99FF99", "#99FFCC", "#99FFFF", "#99CCFF", "#9999FF", "#CC99FF",
|
|
||||||
"#FF99FF", "#FF99CC",
|
|
||||||
]
|
|
||||||
# Labels are cached here
|
|
||||||
self.colorBuf = {}
|
|
||||||
|
|
||||||
# Get a unique color for a given ID, reusing colors as we go
|
|
||||||
def getColor(self, id: str) -> str:
|
|
||||||
if id in self.colorBuf:
|
|
||||||
# Sort entries in order of freshness
|
|
||||||
color = self.colorBuf.pop(id)
|
|
||||||
elif len(self.colorBuf) < len(self.colors):
|
|
||||||
# Assign each initial entry color based on its order
|
|
||||||
color = self.colors[len(self.colorBuf)]
|
|
||||||
else:
|
|
||||||
# If we run out of colors, reuse the oldest entry
|
|
||||||
color = self.colorBuf.pop(next(iter(self.colorBuf)))
|
|
||||||
# Done
|
|
||||||
self.colorBuf[id] = color
|
|
||||||
return color
|
|
||||||
|
|
||||||
def rename(self, old_id: str, new_id: str):
|
|
||||||
if old_id in self.colorBuf and new_id != old_id:
|
|
||||||
self.colorBuf[new_id] = self.colorBuf[old_id]
|
|
||||||
del self.colorBuf[old_id]
|
|
||||||
|
|
||||||
|
|
||||||
class TextParser(LineBasedModule):
|
class TextParser(LineBasedModule):
|
||||||
def __init__(self, filePrefix: str = None, service: bool = False):
|
def __init__(self, filePrefix: str = None, service: bool = False):
|
||||||
self.service = service
|
self.service = service
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue