mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-28 21:25:46 +01:00
Fixes for alias/nicknames in web UI (esp handling player icons),
HeroChat fixes
This commit is contained in:
parent
b108cad2d3
commit
06785be5f3
@ -40,27 +40,34 @@ public class Client {
|
|||||||
public String source;
|
public String source;
|
||||||
public String playerName;
|
public String playerName;
|
||||||
public String message;
|
public String message;
|
||||||
|
public String account;
|
||||||
public ChatMessage(String source, String playerName, String message) {
|
public String channel;
|
||||||
|
public ChatMessage(String source, String channel, String playerName, String message, String playeraccount) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
this.playerName = ChatColor.stripColor(playerName);
|
this.playerName = ChatColor.stripColor(playerName);
|
||||||
this.message = ChatColor.stripColor(message);
|
this.message = ChatColor.stripColor(message);
|
||||||
|
this.account = playeraccount;
|
||||||
|
this.channel = channel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class PlayerJoinMessage extends Stamped {
|
public static class PlayerJoinMessage extends Stamped {
|
||||||
public String type = "playerjoin";
|
public String type = "playerjoin";
|
||||||
public String playerName;
|
public String playerName;
|
||||||
public PlayerJoinMessage(String playerName) {
|
public String account;
|
||||||
|
public PlayerJoinMessage(String playerName, String playeraccount) {
|
||||||
this.playerName = ChatColor.stripColor(playerName);
|
this.playerName = ChatColor.stripColor(playerName);
|
||||||
|
this.account = playeraccount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class PlayerQuitMessage extends Stamped {
|
public static class PlayerQuitMessage extends Stamped {
|
||||||
public String type = "playerquit";
|
public String type = "playerquit";
|
||||||
public String playerName;
|
public String playerName;
|
||||||
public PlayerQuitMessage(String playerName) {
|
public String account;
|
||||||
|
public PlayerQuitMessage(String playerName, String playeraccount) {
|
||||||
this.playerName = ChatColor.stripColor(playerName);
|
this.playerName = ChatColor.stripColor(playerName);
|
||||||
|
this.account = playeraccount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,17 +15,19 @@ public class DynmapPlayerChatListener extends PlayerListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onPlayerChat(PlayerChatEvent event) {
|
public void onPlayerChat(PlayerChatEvent event) {
|
||||||
if(event.isCancelled()) return;
|
if(event.isCancelled()) return;
|
||||||
plugin.mapManager.pushUpdate(new Client.ChatMessage("player", event.getPlayer().getDisplayName(), event.getMessage()));
|
plugin.mapManager.pushUpdate(new Client.ChatMessage("player", "",
|
||||||
|
event.getPlayer().getDisplayName(), event.getMessage(),
|
||||||
|
event.getPlayer().getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
plugin.mapManager.pushUpdate(new Client.PlayerJoinMessage(event.getPlayer().getDisplayName()));
|
plugin.mapManager.pushUpdate(new Client.PlayerJoinMessage(event.getPlayer().getDisplayName(), event.getPlayer().getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
plugin.mapManager.pushUpdate(new Client.PlayerQuitMessage(event.getPlayer().getDisplayName()));
|
plugin.mapManager.pushUpdate(new Client.PlayerQuitMessage(event.getPlayer().getDisplayName(), event.getPlayer().getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -411,7 +411,7 @@ public class DynmapPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void webChat(String name, String message) {
|
public void webChat(String name, String message) {
|
||||||
mapManager.pushUpdate(new Client.ChatMessage("web", name, message));
|
mapManager.pushUpdate(new Client.ChatMessage("web", null, name, message, null));
|
||||||
Log.info("[WEB]" + name + ": " + message);
|
Log.info("[WEB]" + name + ": " + message);
|
||||||
/* Let HeroChat take a look - only broadcast to players if it doesn't handle it */
|
/* Let HeroChat take a look - only broadcast to players if it doesn't handle it */
|
||||||
if(hchand.sendWebMessageToHeroChat(name, message) == false)
|
if(hchand.sendWebMessageToHeroChat(name, message) == false)
|
||||||
|
@ -38,6 +38,7 @@ public class HeroChatHandler {
|
|||||||
private static Class channelchatevent;
|
private static Class channelchatevent;
|
||||||
private static Method getsource;
|
private static Method getsource;
|
||||||
private static Method getmessage;
|
private static Method getmessage;
|
||||||
|
private static Method issentbyplayer;
|
||||||
private static boolean isgood = false;
|
private static boolean isgood = false;
|
||||||
private Event evt;
|
private Event evt;
|
||||||
|
|
||||||
@ -48,6 +49,7 @@ public class HeroChatHandler {
|
|||||||
.forName("com.herocraftonline.dthielke.herochat.event.ChannelChatEvent");
|
.forName("com.herocraftonline.dthielke.herochat.event.ChannelChatEvent");
|
||||||
getsource = channelchatevent.getMethod("getSource", new Class[0]);
|
getsource = channelchatevent.getMethod("getSource", new Class[0]);
|
||||||
getmessage = channelchatevent.getMethod("getMessage", new Class[0]);
|
getmessage = channelchatevent.getMethod("getMessage", new Class[0]);
|
||||||
|
issentbyplayer = channelchatevent.getMethod("isSentByPlayer", new Class[0]);
|
||||||
isgood = true;
|
isgood = true;
|
||||||
} catch (ClassNotFoundException cnfx) {
|
} catch (ClassNotFoundException cnfx) {
|
||||||
} catch (NoSuchMethodException nsmx) {
|
} catch (NoSuchMethodException nsmx) {
|
||||||
@ -78,6 +80,14 @@ public class HeroChatHandler {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSentByPlayer() {
|
||||||
|
try {
|
||||||
|
return (Boolean) issentbyplayer.invoke(evt);
|
||||||
|
} catch (Exception x) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reflection-based access wrapper for ChannelEvent from HeroChat */
|
/* Reflection-based access wrapper for ChannelEvent from HeroChat */
|
||||||
@ -213,9 +223,15 @@ public class HeroChatHandler {
|
|||||||
/* Match on name or nickname of channel */
|
/* Match on name or nickname of channel */
|
||||||
if (hcchannels.contains(c.getName()) ||
|
if (hcchannels.contains(c.getName()) ||
|
||||||
hcchannels.contains(c.getNick())) {
|
hcchannels.contains(c.getNick())) {
|
||||||
plugin.mapManager.pushUpdate(new Client.ChatMessage(
|
if(cce.isSentByPlayer()) { /* Player message? */
|
||||||
"player", "[" + c.getNick() + "] "
|
org.bukkit.entity.Player p = plugin.getServer().getPlayer(cce.getSource());
|
||||||
+ cce.getSource(), cce.getMessage()));
|
if(p != null)
|
||||||
|
plugin.mapManager.pushUpdate(new Client.ChatMessage("player",
|
||||||
|
c.getNick(),
|
||||||
|
p.getDisplayName(),
|
||||||
|
cce.getMessage(),
|
||||||
|
p.getName()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package org.dynmap.web;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
public class HttpRequest {
|
public class HttpRequest {
|
||||||
public String method;
|
public String method;
|
||||||
@ -10,4 +11,5 @@ public class HttpRequest {
|
|||||||
public String version;
|
public String version;
|
||||||
public Map<String, String> fields = new HashMap<String, String>();
|
public Map<String, String> fields = new HashMap<String, String>();
|
||||||
public InputStream body;
|
public InputStream body;
|
||||||
|
public InetSocketAddress rmtaddr;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
import org.dynmap.Log;
|
import org.dynmap.Log;
|
||||||
import org.dynmap.debug.Debug;
|
import org.dynmap.debug.Debug;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
public class HttpServerConnection extends Thread {
|
public class HttpServerConnection extends Thread {
|
||||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||||
@ -120,13 +121,14 @@ public class HttpServerConnection extends Thread {
|
|||||||
if (socket == null)
|
if (socket == null)
|
||||||
return;
|
return;
|
||||||
socket.setSoTimeout(5000);
|
socket.setSoTimeout(5000);
|
||||||
|
InetSocketAddress rmtaddr = (InetSocketAddress)socket.getRemoteSocketAddress(); /* Get remote address */
|
||||||
InputStream in = socket.getInputStream();
|
InputStream in = socket.getInputStream();
|
||||||
BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream(), 40960);
|
BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream(), 40960);
|
||||||
|
|
||||||
printOut = new PrintStream(out, false);
|
printOut = new PrintStream(out, false);
|
||||||
while (true) {
|
while (true) {
|
||||||
HttpRequest request = new HttpRequest();
|
HttpRequest request = new HttpRequest();
|
||||||
|
request.rmtaddr = rmtaddr;
|
||||||
if (!readRequestHeader(in, request)) {
|
if (!readRequestHeader(in, request)) {
|
||||||
socket.close();
|
socket.close();
|
||||||
return;
|
return;
|
||||||
|
@ -40,7 +40,8 @@ public class SendMessageHandler implements HttpHandler {
|
|||||||
|
|
||||||
JSONObject o = (JSONObject)parser.parse(reader);
|
JSONObject o = (JSONObject)parser.parse(reader);
|
||||||
final Message message = new Message();
|
final Message message = new Message();
|
||||||
message.name = String.valueOf(o.get("name"));
|
//message.name = String.valueOf(o.get("name")); //Can't trust client....we don't need to on internal web server
|
||||||
|
message.name = request.rmtaddr.getAddress().getHostAddress();
|
||||||
message.message = String.valueOf(o.get("message"));
|
message.message = String.valueOf(o.get("message"));
|
||||||
|
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
|
@ -12,7 +12,8 @@ componentconstructors['chat'] = function(dynmap, configuration) {
|
|||||||
$(dynmap).bind('worldupdate', function(event, update) {
|
$(dynmap).bind('worldupdate', function(event, update) {
|
||||||
swtch(update.type, {
|
swtch(update.type, {
|
||||||
chat: function() {
|
chat: function() {
|
||||||
$(dynmap).trigger('chat', [{source: update.source, name: update.playerName, text: update.message}]);
|
$(dynmap).trigger('chat', [{source: update.source, name: update.playerName, text: update.message, account: update.account,
|
||||||
|
channel: update.channel}]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -50,20 +50,29 @@ componentconstructors['chatbox'] = function(dynmap, configuration) {
|
|||||||
|
|
||||||
$(dynmap).bind('chat', function(event, message) {
|
$(dynmap).bind('chat', function(event, message) {
|
||||||
var playerName = message.name;
|
var playerName = message.name;
|
||||||
|
var playerAccount = message.account;
|
||||||
var messageRow = $('<div/>')
|
var messageRow = $('<div/>')
|
||||||
.addClass('messagerow');
|
.addClass('messagerow');
|
||||||
|
|
||||||
var playerIconContainer = $('<span/>')
|
var playerIconContainer = $('<span/>')
|
||||||
.addClass('messageicon');
|
.addClass('messageicon');
|
||||||
|
|
||||||
if (message.source === 'player' && configuration.showplayerfaces) {
|
if (message.source === 'player' && configuration.showplayerfaces &&
|
||||||
getMinecraftHead(playerName, 16, function(head) {
|
playerAccount) {
|
||||||
|
getMinecraftHead(playerAccount, 16, function(head) {
|
||||||
messageRow.icon = $(head)
|
messageRow.icon = $(head)
|
||||||
.addClass('playerIcon')
|
.addClass('playerIcon')
|
||||||
.appendTo(playerIconContainer);
|
.appendTo(playerIconContainer);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var playerChannelContainer = '';
|
||||||
|
if (message.channel) {
|
||||||
|
playerChannelContainer = $('<span/>').addClass('messagetext')
|
||||||
|
.text('[' + message.channel + '] ')
|
||||||
|
.appendTo(messageRow);
|
||||||
|
}
|
||||||
|
|
||||||
if (message.source === 'player' && configuration.showworld) {
|
if (message.source === 'player' && configuration.showworld) {
|
||||||
var playerWorldContainer = $('<span/>')
|
var playerWorldContainer = $('<span/>')
|
||||||
.addClass('messagetext')
|
.addClass('messagetext')
|
||||||
@ -79,7 +88,7 @@ componentconstructors['chatbox'] = function(dynmap, configuration) {
|
|||||||
.addClass('messagetext')
|
.addClass('messagetext')
|
||||||
.text(message.text);
|
.text(message.text);
|
||||||
|
|
||||||
messageRow.append(playerIconContainer,playerNameContainer,playerMessageContainer);
|
messageRow.append(playerIconContainer,playerChannelContainer,playerNameContainer,playerMessageContainer);
|
||||||
addrow(messageRow);
|
addrow(messageRow);
|
||||||
});
|
});
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user