mirror of https://github.com/zlatinb/muwire
provision for profiles being sent from chat server to clients
parent
feab16e461
commit
203c01e247
|
@ -1,6 +1,6 @@
|
|||
package com.muwire.core.chat;
|
||||
|
||||
enum ChatAction {
|
||||
public enum ChatAction {
|
||||
JOIN(true, false, true, false),
|
||||
LEAVE(false, false, true, false),
|
||||
SAY(false, false, true, false),
|
||||
|
@ -8,6 +8,7 @@ enum ChatAction {
|
|||
HELP(true, true, true, false),
|
||||
INFO(true, true, true, false),
|
||||
JOINED(true, true, false, false),
|
||||
PROFILE(true, false, false, false),
|
||||
TRUST(true, false, true, true),
|
||||
DISTRUST(true, false, true, true);
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ class ChatClient implements Closeable {
|
|||
throw new Exception("Version header missing")
|
||||
|
||||
int version = Integer.parseInt(headers['Version'])
|
||||
if (version != Constants.CHAT_VERSION)
|
||||
if (version > Constants.CHAT_VERSION)
|
||||
throw new Exception("Unknown chat version $version")
|
||||
|
||||
String defaultRoom = null
|
||||
|
@ -102,7 +102,8 @@ class ChatClient implements Closeable {
|
|||
synchronized(this) {
|
||||
if (!connectInProgress)
|
||||
return
|
||||
connection = new ChatConnection(eventBus, endpoint, host, false, trustService, settings)
|
||||
connection = new ChatConnection(eventBus, endpoint, host, false,
|
||||
trustService, settings, Constants.CHAT_VERSION)
|
||||
connection.start()
|
||||
}
|
||||
eventBus.publish(new ChatConnectionEvent(status : ChatConnectionAttemptStatus.SUCCESSFUL, persona : host,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.muwire.core.chat
|
||||
|
||||
class ChatCommand {
|
||||
private final ChatAction action
|
||||
private final String payload
|
||||
final ChatAction action
|
||||
final String payload
|
||||
final String source
|
||||
ChatCommand(String source) {
|
||||
if (source.charAt(0) != '/')
|
||||
|
|
|
@ -34,6 +34,7 @@ class ChatConnection implements ChatLink {
|
|||
private final boolean incoming
|
||||
private final TrustService trustService
|
||||
private final MuWireSettings settings
|
||||
private final int version
|
||||
|
||||
private final AtomicBoolean running = new AtomicBoolean()
|
||||
private final BlockingQueue messages = new LinkedBlockingQueue()
|
||||
|
@ -49,13 +50,14 @@ class ChatConnection implements ChatLink {
|
|||
private volatile long lastPingSentTime
|
||||
|
||||
ChatConnection(EventBus eventBus, Endpoint endpoint, Persona persona, boolean incoming,
|
||||
TrustService trustService, MuWireSettings settings) {
|
||||
TrustService trustService, MuWireSettings settings, int version) {
|
||||
this.eventBus = eventBus
|
||||
this.endpoint = endpoint
|
||||
this.persona = persona
|
||||
this.incoming = incoming
|
||||
this.trustService = trustService
|
||||
this.settings = settings
|
||||
this.version = version
|
||||
|
||||
this.dis = new DataInputStream(endpoint.getInputStream())
|
||||
this.dos = new DataOutputStream(endpoint.getOutputStream())
|
||||
|
@ -130,7 +132,9 @@ class ChatConnection implements ChatLink {
|
|||
}
|
||||
|
||||
private void read() {
|
||||
int length = dis.readUnsignedShort()
|
||||
int length = version == 1 ? dis.readUnsignedShort() : dis.readInt()
|
||||
if (length > (0x1 << 19))
|
||||
throw new Exception("chat message too big $length")
|
||||
byte [] payload = new byte[length]
|
||||
dis.readFully(payload)
|
||||
def json = slurper.parse(payload)
|
||||
|
@ -148,7 +152,10 @@ class ChatConnection implements ChatLink {
|
|||
private void write(Object message) {
|
||||
byte [] payload = JsonOutput.toJson(message).bytes
|
||||
dos.with {
|
||||
writeShort(payload.length)
|
||||
if (version == 1)
|
||||
writeShort(payload.length)
|
||||
else
|
||||
writeInt(payload.length)
|
||||
write(payload)
|
||||
flush()
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ class ChatServer {
|
|||
throw new Exception("Version header missing")
|
||||
|
||||
int version = Integer.parseInt(headers['Version'])
|
||||
if (version != Constants.CHAT_VERSION)
|
||||
if (version > Constants.CHAT_VERSION)
|
||||
throw new Exception("Unknown chat version $version")
|
||||
|
||||
if (!headers.containsKey('Persona'))
|
||||
|
@ -121,14 +121,15 @@ class ChatServer {
|
|||
|
||||
os.with {
|
||||
write("200 OK\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
write("Version:${Constants.CHAT_VERSION}\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
write("Version:${version}\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
if (settings.defaultChatRoom.size() > 0)
|
||||
write("DefaultRoom:${settings.defaultChatRoom}\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
write("\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||
flush()
|
||||
}
|
||||
|
||||
ChatConnection connection = new ChatConnection(eventBus, endpoint, client, true, trustService, settings)
|
||||
ChatConnection connection = new ChatConnection(eventBus, endpoint, client, true,
|
||||
trustService, settings, version)
|
||||
connections.put(endpoint.destination, connection)
|
||||
joinRoom(client, CONSOLE)
|
||||
shortNames.put(client.getHumanReadableName(), client)
|
||||
|
|
|
@ -7,7 +7,7 @@ public class Constants {
|
|||
public static final String INVALID_NICKNAME_CHARS = "'\"();<>=@$%";
|
||||
public static final int MAX_NICKNAME_LENGTH = 30;
|
||||
public static final byte FILE_CERT_VERSION = (byte)2;
|
||||
public static final int CHAT_VERSION = 1;
|
||||
public static final int CHAT_VERSION = 2;
|
||||
|
||||
public static final byte COLLECTION_VERSION = (byte)1;
|
||||
public static final byte COLLECTION_ENTRY_VERSION = (byte)1;
|
||||
|
|
|
@ -185,7 +185,6 @@ class ChatRoomController {
|
|||
} catch (Exception bad) {
|
||||
return
|
||||
}
|
||||
log.info("$model.room processing $command.action")
|
||||
switch(command.action) {
|
||||
case ChatAction.SAY : processSay(e, command.payload);break
|
||||
case ChatAction.JOIN : processJoin(e.timestamp, e.sender); break
|
||||
|
|
Loading…
Reference in New Issue