From bfc67b766ccd27c8692bec29592d96bd7d224bb7 Mon Sep 17 00:00:00 2001 From: Waverunner Date: Wed, 29 Jul 2015 10:49:23 -0400 Subject: [PATCH] Added ability to kick, ban, and unban players from chat rooms --- src/network/PacketType.java | 3 + .../swg/zone/chat/ChatBanAvatarFromRoom.java | 78 ++++++++++ .../swg/zone/chat/ChatKickAvatarFromRoom.java | 71 +++++++++ .../zone/chat/ChatOnBanAvatarFromRoom.java | 78 ++++++++++ .../zone/chat/ChatOnKickAvatarFromRoom.java | 74 ++++++++++ .../zone/chat/ChatOnUnbanAvatarFromRoom.java | 78 ++++++++++ .../zone/chat/ChatUnbanAvatarFromRoom.java | 76 ++++++++++ src/resources/chat/ChatRoom.java | 8 ++ src/services/chat/ChatRoomService.java | 135 ++++++++++++++++-- 9 files changed, 593 insertions(+), 8 deletions(-) create mode 100644 src/network/packets/swg/zone/chat/ChatBanAvatarFromRoom.java create mode 100644 src/network/packets/swg/zone/chat/ChatKickAvatarFromRoom.java create mode 100644 src/network/packets/swg/zone/chat/ChatOnBanAvatarFromRoom.java create mode 100644 src/network/packets/swg/zone/chat/ChatOnKickAvatarFromRoom.java create mode 100644 src/network/packets/swg/zone/chat/ChatOnUnbanAvatarFromRoom.java create mode 100644 src/network/packets/swg/zone/chat/ChatUnbanAvatarFromRoom.java diff --git a/src/network/PacketType.java b/src/network/PacketType.java index c4ef502a6..1fef585c6 100644 --- a/src/network/PacketType.java +++ b/src/network/PacketType.java @@ -135,6 +135,9 @@ public enum PacketType { CHAT_SYSTEM_MESSAGE (ChatSystemMessage.CRC, ChatSystemMessage.class), CHAT_INVITE_AVATAR_TO_ROOM (ChatInviteAvatarToRoom.CRC, ChatInviteAvatarToRoom.class), CHAT_UNINVITE_FROM_ROOM (ChatUninviteFromRoom.CRC, ChatUninviteFromRoom.class), + CHAT_KICK_AVATAR_FROM_ROOM (ChatKickAvatarFromRoom.CRC, ChatKickAvatarFromRoom.class), + CHAT_BAN_AVATAR_FROM_ROOM (ChatBanAvatarFromRoom.CRC, ChatBanAvatarFromRoom.class), + CHAT_UNBAN_AVATAR_FROM_ROOM (ChatUnbanAvatarFromRoom.CRC, ChatUnbanAvatarFromRoom.class), CON_GENERIC_MESSAGE (ConGenericMessage.CRC, ConGenericMessage.class), VOICE_CHAT_STATUS (VoiceChatStatus.CRC, VoiceChatStatus.class), diff --git a/src/network/packets/swg/zone/chat/ChatBanAvatarFromRoom.java b/src/network/packets/swg/zone/chat/ChatBanAvatarFromRoom.java new file mode 100644 index 000000000..c307d67f8 --- /dev/null +++ b/src/network/packets/swg/zone/chat/ChatBanAvatarFromRoom.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2015 /// Project SWG /// www.projectswg.com + * + * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on + * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. + * Our goal is to create an emulator which will provide a server for players to + * continue playing a game similar to the one they used to play. We are basing + * it on the final publish of the game prior to end-game events. + * + * This file is part of Holocore. + * + * -------------------------------------------------------------------------------- + * + * Holocore is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Holocore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Holocore. If not, see + ******************************************************************************/ + +package network.packets.swg.zone.chat; + +import network.packets.swg.SWGPacket; +import resources.chat.ChatAvatar; + +import java.nio.ByteBuffer; + +/** + * @author Waverunner + */ +public class ChatBanAvatarFromRoom extends SWGPacket { + public static final int CRC = getCrc("ChatBanAvatarFromRoom"); + + private ChatAvatar avatar; + private String room; + private int sequence; + + public ChatBanAvatarFromRoom() {} + + @Override + public void decode(ByteBuffer data) { + if (!super.decode(data, CRC)) + return; + avatar = getEncodable(data, ChatAvatar.class); + room = getAscii(data); + sequence = getInt(data); + } + + @Override + public ByteBuffer encode() { + ByteBuffer bb = ByteBuffer.allocate(12 + avatar.encode().length + room.length()); + addShort(bb, 4); + addInt(bb, CRC); + addEncodable(bb, avatar); + addAscii(bb, room); + addInt(bb, sequence); + return bb; + } + + public ChatAvatar getAvatar() { + return avatar; + } + + public String getRoom() { + return room; + } + + public int getSequence() { + return sequence; + } +} diff --git a/src/network/packets/swg/zone/chat/ChatKickAvatarFromRoom.java b/src/network/packets/swg/zone/chat/ChatKickAvatarFromRoom.java new file mode 100644 index 000000000..cfcf67df5 --- /dev/null +++ b/src/network/packets/swg/zone/chat/ChatKickAvatarFromRoom.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2015 /// Project SWG /// www.projectswg.com + * + * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on + * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. + * Our goal is to create an emulator which will provide a server for players to + * continue playing a game similar to the one they used to play. We are basing + * it on the final publish of the game prior to end-game events. + * + * This file is part of Holocore. + * + * -------------------------------------------------------------------------------- + * + * Holocore is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Holocore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Holocore. If not, see + ******************************************************************************/ + +package network.packets.swg.zone.chat; + +import network.packets.swg.SWGPacket; +import resources.chat.ChatAvatar; + +import java.nio.ByteBuffer; + +/** + * @author Waverunner + */ +public class ChatKickAvatarFromRoom extends SWGPacket { + public static final int CRC = getCrc("ChatKickAvatarFromRoom"); + + private ChatAvatar avatar; + private String room; + + public ChatKickAvatarFromRoom() {} + + @Override + public void decode(ByteBuffer data) { + if (!super.decode(data, CRC)) + return; + avatar = getEncodable(data, ChatAvatar.class); + room = getAscii(data); + } + + @Override + public ByteBuffer encode() { + ByteBuffer bb = ByteBuffer.allocate(8 + avatar.encode().length); + addShort(bb, 3); + addInt(bb, CRC); + addEncodable(bb, avatar); + addAscii(bb, room); + return bb; + } + + public ChatAvatar getAvatar() { + return avatar; + } + + public String getRoom() { + return room; + } +} diff --git a/src/network/packets/swg/zone/chat/ChatOnBanAvatarFromRoom.java b/src/network/packets/swg/zone/chat/ChatOnBanAvatarFromRoom.java new file mode 100644 index 000000000..18a37ba73 --- /dev/null +++ b/src/network/packets/swg/zone/chat/ChatOnBanAvatarFromRoom.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2015 /// Project SWG /// www.projectswg.com + * + * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on + * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. + * Our goal is to create an emulator which will provide a server for players to + * continue playing a game similar to the one they used to play. We are basing + * it on the final publish of the game prior to end-game events. + * + * This file is part of Holocore. + * + * -------------------------------------------------------------------------------- + * + * Holocore is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Holocore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Holocore. If not, see + ******************************************************************************/ + +package network.packets.swg.zone.chat; + +import network.packets.swg.SWGPacket; +import resources.chat.ChatAvatar; + +import java.nio.ByteBuffer; + +/** + * @author Waverunner + */ +public class ChatOnBanAvatarFromRoom extends SWGPacket { + public static final int CRC = getCrc("ChatOnBanAvatarFromRoom"); + + private String room; + private ChatAvatar moderator; + private ChatAvatar target; + private int result; + private int sequence; + + public ChatOnBanAvatarFromRoom(String room, ChatAvatar moderator, ChatAvatar target, int result, int sequence) { + this.room = room; + this.moderator = moderator; + this.target = target; + this.result = result; + this.sequence = sequence; + } + + @Override + public void decode(ByteBuffer data) { + if (!super.decode(data, CRC)) + return; + room = getAscii(data); + moderator = getEncodable(data, ChatAvatar.class); + target = getEncodable(data, ChatAvatar.class); + result = getInt(data); + sequence = getInt(data); + } + + @Override + public ByteBuffer encode() { + ByteBuffer bb = ByteBuffer.allocate(16 + moderator.encode().length + target.encode().length + room.length()); + addShort(bb, 6); + addInt(bb, CRC); + addAscii(bb, room); + addEncodable(bb, moderator); + addEncodable(bb, target); + addInt(bb, result); + addInt(bb, sequence); + return bb; + } +} diff --git a/src/network/packets/swg/zone/chat/ChatOnKickAvatarFromRoom.java b/src/network/packets/swg/zone/chat/ChatOnKickAvatarFromRoom.java new file mode 100644 index 000000000..92dfd4045 --- /dev/null +++ b/src/network/packets/swg/zone/chat/ChatOnKickAvatarFromRoom.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2015 /// Project SWG /// www.projectswg.com + * + * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on + * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. + * Our goal is to create an emulator which will provide a server for players to + * continue playing a game similar to the one they used to play. We are basing + * it on the final publish of the game prior to end-game events. + * + * This file is part of Holocore. + * + * -------------------------------------------------------------------------------- + * + * Holocore is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Holocore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Holocore. If not, see + ******************************************************************************/ + +package network.packets.swg.zone.chat; + +import network.packets.swg.SWGPacket; +import resources.chat.ChatAvatar; + +import java.nio.ByteBuffer; + +/** + * @author Waverunner + */ +public class ChatOnKickAvatarFromRoom extends SWGPacket { + public static final int CRC = getCrc("ChatOnKickAvatarFromRoom"); + + private ChatAvatar target; + private ChatAvatar moderator; + private int result; + private String room; + + public ChatOnKickAvatarFromRoom(ChatAvatar target, ChatAvatar moderator, int result, String room) { + this.target = target; + this.moderator = moderator; + this.result = result; + this.room = room; + } + + @Override + public void decode(ByteBuffer data) { + if (!super.decode(data, CRC)) + return; + target = getEncodable(data, ChatAvatar.class); + moderator = getEncodable(data, ChatAvatar.class); + result = getInt(data); + room = getAscii(data); + } + + @Override + public ByteBuffer encode() { + ByteBuffer bb = ByteBuffer.allocate(16 + target.encode().length + moderator.encode().length + room.length()); + addShort(bb, 6); + addInt(bb, CRC); + addEncodable(bb, target); + addEncodable(bb, moderator); + addInt(bb, result); + addAscii(bb, room); + return bb; + } +} diff --git a/src/network/packets/swg/zone/chat/ChatOnUnbanAvatarFromRoom.java b/src/network/packets/swg/zone/chat/ChatOnUnbanAvatarFromRoom.java new file mode 100644 index 000000000..7dbafe6b8 --- /dev/null +++ b/src/network/packets/swg/zone/chat/ChatOnUnbanAvatarFromRoom.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2015 /// Project SWG /// www.projectswg.com + * + * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on + * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. + * Our goal is to create an emulator which will provide a server for players to + * continue playing a game similar to the one they used to play. We are basing + * it on the final publish of the game prior to end-game events. + * + * This file is part of Holocore. + * + * -------------------------------------------------------------------------------- + * + * Holocore is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Holocore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Holocore. If not, see + ******************************************************************************/ + +package network.packets.swg.zone.chat; + +import network.packets.swg.SWGPacket; +import resources.chat.ChatAvatar; + +import java.nio.ByteBuffer; + +/** + * @author Waverunner + */ +public class ChatOnUnbanAvatarFromRoom extends SWGPacket { + public static final int CRC = getCrc("ChatOnUnbanAvatarFromRoom"); + + private String room; + private ChatAvatar moderator; + private ChatAvatar target; + private int result; + private int sequence; + + public ChatOnUnbanAvatarFromRoom(String room, ChatAvatar moderator, ChatAvatar target, int result, int sequence) { + this.room = room; + this.moderator = moderator; + this.target = target; + this.result = result; + this.sequence = sequence; + } + + @Override + public void decode(ByteBuffer data) { + if (!super.decode(data, CRC)) + return; + room = getAscii(data); + moderator = getEncodable(data, ChatAvatar.class); + target = getEncodable(data, ChatAvatar.class); + result = getInt(data); + sequence = getInt(data); + } + + @Override + public ByteBuffer encode() { + ByteBuffer bb = ByteBuffer.allocate(16 + moderator.encode().length + target.encode().length + room.length()); + addShort(bb, 6); + addInt(bb, CRC); + addAscii(bb, room); + addEncodable(bb, moderator); + addEncodable(bb, target); + addInt(bb, result); + addInt(bb, sequence); + return bb; + } +} diff --git a/src/network/packets/swg/zone/chat/ChatUnbanAvatarFromRoom.java b/src/network/packets/swg/zone/chat/ChatUnbanAvatarFromRoom.java new file mode 100644 index 000000000..029f706f1 --- /dev/null +++ b/src/network/packets/swg/zone/chat/ChatUnbanAvatarFromRoom.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2015 /// Project SWG /// www.projectswg.com + * + * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on + * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. + * Our goal is to create an emulator which will provide a server for players to + * continue playing a game similar to the one they used to play. We are basing + * it on the final publish of the game prior to end-game events. + * + * This file is part of Holocore. + * + * -------------------------------------------------------------------------------- + * + * Holocore is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Holocore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Holocore. If not, see + ******************************************************************************/ + +package network.packets.swg.zone.chat; + +import network.packets.swg.SWGPacket; +import resources.chat.ChatAvatar; + +import java.nio.ByteBuffer; + +/** + * @author Waverunner + */ +public class ChatUnbanAvatarFromRoom extends SWGPacket { + public static final int CRC = getCrc("ChatUnbanAvatarFromRoom"); + + private ChatAvatar avatar; + private String room; + private int sequence; + + @Override + public void decode(ByteBuffer data) { + if (!super.decode(data, CRC)) + return; + avatar = getEncodable(data, ChatAvatar.class); + room = getAscii(data); + sequence = getInt(data); + } + + @Override + public ByteBuffer encode() { + ByteBuffer bb = ByteBuffer.allocate(12 + avatar.encode().length + room.length()); + addShort(bb, 4); + addInt(bb, CRC); + addEncodable(bb, avatar); + addAscii(bb, room); + addInt(bb, sequence); + return bb; + } + + public ChatAvatar getAvatar() { + return avatar; + } + + public String getRoom() { + return room; + } + + public int getSequence() { + return sequence; + } +} diff --git a/src/resources/chat/ChatRoom.java b/src/resources/chat/ChatRoom.java index 98f3ecb53..948d3ce33 100644 --- a/src/resources/chat/ChatRoom.java +++ b/src/resources/chat/ChatRoom.java @@ -183,6 +183,14 @@ public class ChatRoom implements Encodable, Serializable { return avatar.equals(owner) || moderators.contains(avatar); } + public boolean isMember(ChatAvatar avatar) { + return members.contains(avatar); + } + + public boolean isBanned(ChatAvatar avatar) { + return banned.contains(avatar); + } + public void sendMessage(ChatAvatar sender, String message, OutOfBandPackage oob, PlayerManager playerManager) { ChatRoomMessage chatRoomMessage = new ChatRoomMessage(sender, getId(), message, oob); sendPacketToMembers(playerManager, chatRoomMessage); diff --git a/src/services/chat/ChatRoomService.java b/src/services/chat/ChatRoomService.java index d414fc7cf..e5e97cfa8 100644 --- a/src/services/chat/ChatRoomService.java +++ b/src/services/chat/ChatRoomService.java @@ -32,23 +32,29 @@ import intents.chat.ChatRoomUpdateIntent; import intents.network.GalacticPacketIntent; import network.packets.Packet; import network.packets.swg.SWGPacket; +import network.packets.swg.zone.chat.ChatBanAvatarFromRoom; import network.packets.swg.zone.chat.ChatCreateRoom; import network.packets.swg.zone.chat.ChatDestroyRoom; import network.packets.swg.zone.chat.ChatEnterRoomById; import network.packets.swg.zone.chat.ChatInviteAvatarToRoom; +import network.packets.swg.zone.chat.ChatKickAvatarFromRoom; +import network.packets.swg.zone.chat.ChatOnBanAvatarFromRoom; import network.packets.swg.zone.chat.ChatOnCreateRoom; import network.packets.swg.zone.chat.ChatOnDestroyRoom; import network.packets.swg.zone.chat.ChatOnEnteredRoom; import network.packets.swg.zone.chat.ChatOnInviteToRoom; +import network.packets.swg.zone.chat.ChatOnKickAvatarFromRoom; import network.packets.swg.zone.chat.ChatOnLeaveRoom; import network.packets.swg.zone.chat.ChatOnReceiveRoomInvitation; import network.packets.swg.zone.chat.ChatOnSendRoomMessage; +import network.packets.swg.zone.chat.ChatOnUnbanAvatarFromRoom; import network.packets.swg.zone.chat.ChatOnUninviteFromRoom; import network.packets.swg.zone.chat.ChatQueryRoom; import network.packets.swg.zone.chat.ChatQueryRoomResults; import network.packets.swg.zone.chat.ChatRemoveAvatarFromRoom; import network.packets.swg.zone.chat.ChatRequestRoomList; import network.packets.swg.zone.chat.ChatSendToRoom; +import network.packets.swg.zone.chat.ChatUnbanAvatarFromRoom; import network.packets.swg.zone.chat.ChatUninviteFromRoom; import network.packets.swg.zone.insertion.ChatRoomList; import resources.Terrain; @@ -128,8 +134,7 @@ public class ChatRoomService extends Service { enterChatChannel(player, enterRoomById.getRoomId(), enterRoomById.getSequence()); break; } case CHAT_REMOVE_AVATAR_FROM_ROOM: - if (p instanceof ChatRemoveAvatarFromRoom) - leaveChatChannel(player, ((ChatRemoveAvatarFromRoom) p).getPath()); + if (p instanceof ChatRemoveAvatarFromRoom) leaveChatChannel(player, ((ChatRemoveAvatarFromRoom) p).getPath()); break; case CHAT_SEND_TO_ROOM: if (p instanceof ChatSendToRoom) handleChatSendToRoom(player, (ChatSendToRoom) p); @@ -149,6 +154,14 @@ public class ChatRoomService extends Service { case CHAT_UNINVITE_FROM_ROOM: if (p instanceof ChatUninviteFromRoom) handleChatUninviteFromRoom(player, (ChatUninviteFromRoom) p); break; + case CHAT_KICK_AVATAR_FROM_ROOM: + if (p instanceof ChatKickAvatarFromRoom) handleChatKickAvatarFromRoom(player, (ChatKickAvatarFromRoom) p); + break; + case CHAT_BAN_AVATAR_FROM_ROOM: + if (p instanceof ChatBanAvatarFromRoom) handleChatBanAvatarFromRoom(player, (ChatBanAvatarFromRoom) p); + break; + case CHAT_UNBAN_AVATAR_FROM_ROOM: + if (p instanceof ChatUnbanAvatarFromRoom) handleChatUnbanAvatarFromRoom(player, (ChatUnbanAvatarFromRoom) p); default: break; } } @@ -163,6 +176,107 @@ public class ChatRoomService extends Service { /* Chat Rooms */ + private void handleChatUnbanAvatarFromRoom(Player player, ChatUnbanAvatarFromRoom p) { + String path = p.getRoom(); + ChatAvatar target = p.getAvatar(); + int sequence = p.getSequence(); + + ChatRoom room = getRoom(path); + ChatAvatar sender = ChatAvatar.getFromPlayer(player); + + if (room == null) { + player.sendPacket(new ChatOnUnbanAvatarFromRoom(path, sender, target, ChatResult.ROOM_INVALID_NAME.getCode(), sequence)); + return; + } + + if (!room.isModerator(sender)) { + player.sendPacket(new ChatOnUnbanAvatarFromRoom(path, sender, target, ChatResult.ROOM_AVATAR_NO_PERMISSION.getCode(), sequence)); + return; + } + + if (!room.getBanned().remove(target)) { + player.sendPacket(new ChatOnUnbanAvatarFromRoom(path, sender, target, ChatResult.ROOM_AVATAR_BANNED.getCode(), sequence)); + return; + } + + room.sendPacketToMembers(player.getPlayerManager(), new ChatOnUnbanAvatarFromRoom(path, sender, target, ChatResult.SUCCESS.getCode(), sequence)); + } + + private void handleChatBanAvatarFromRoom(Player player, ChatBanAvatarFromRoom p) { + String path = p.getRoom(); + ChatAvatar target = p.getAvatar(); + int sequence = p.getSequence(); + + ChatRoom room = getRoom(path); + ChatAvatar sender = ChatAvatar.getFromPlayer(player); + + if (room == null) { + player.sendPacket(new ChatOnBanAvatarFromRoom(path, sender, target, ChatResult.ROOM_INVALID_NAME.getCode(), sequence)); + return; + } + + if (!room.isModerator(sender)) { + player.sendPacket(new ChatOnBanAvatarFromRoom(path, sender, target, ChatResult.ROOM_AVATAR_NO_PERMISSION.getCode(), sequence)); + return; + } + + if (room.isBanned(target)) { + player.sendPacket(new ChatOnBanAvatarFromRoom(path, sender, target, ChatResult.ROOM_AVATAR_BANNED.getCode(), sequence)); + return; + } + + if (!room.isMember(target)) { + player.sendPacket(new ChatOnBanAvatarFromRoom(path, sender, target, ChatResult.TARGET_AVATAR_DOESNT_EXIST.getCode(), sequence)); + return; + } + + if (room.isModerator(target)) + room.getModerators().remove(target); + + if (room.getInvited().contains(target)) + room.getInvited().remove(target); + + room.getBanned().add(target); + + room.sendPacketToMembers(player.getPlayerManager(), new ChatOnBanAvatarFromRoom(path, sender, target, ChatResult.SUCCESS.getCode(), sequence)); + } + + private void handleChatKickAvatarFromRoom(Player player, ChatKickAvatarFromRoom p) { + String path = p.getRoom(); + ChatAvatar target = p.getAvatar(); + + ChatRoom room = getRoom(path); + ChatAvatar sender = ChatAvatar.getFromPlayer(player); + + if (room == null) { + player.sendPacket(new ChatOnKickAvatarFromRoom(target, sender, ChatResult.ROOM_INVALID_NAME.getCode(), path)); + return; + } + + if (!room.isModerator(sender)) { + player.sendPacket(new ChatOnKickAvatarFromRoom(target, sender, ChatResult.ROOM_AVATAR_NO_PERMISSION.getCode(), path)); + return; + } + + if (!room.isMember(target)) { + player.sendPacket(new ChatOnKickAvatarFromRoom(target, sender, ChatResult.TARGET_AVATAR_DOESNT_EXIST.getCode(), path)); + return; + } + + Player targetPlayer = player.getPlayerManager().getPlayerByCreatureFirstName(target.getName()); + if (targetPlayer == null) { + player.sendPacket(new ChatOnKickAvatarFromRoom(target, sender, ChatResult.TARGET_AVATAR_DOESNT_EXIST.getCode(), path)); + return; + } + + if (room.isMember(target)) { + player.sendPacket(new ChatOnKickAvatarFromRoom(target, sender, ChatResult.NONE.getCode(), path)); + return; + } + + room.sendPacketToMembers(player.getPlayerManager(), new ChatOnKickAvatarFromRoom(target, sender, ChatResult.SUCCESS.getCode(), path)); + } + private void handleChatUninviteFromRoom(Player player, ChatUninviteFromRoom p) { String path = p.getRoom(); ChatRoom room = getRoom(path); @@ -175,18 +289,18 @@ public class ChatRoomService extends Service { return; } + if (room.isPublic()) { + player.sendPacket(new ChatOnUninviteFromRoom(path, sender, invitee, ChatResult.NONE.getCode(), p.getSequence())); + return; + } + if (!room.isModerator(sender)) { player.sendPacket(new ChatOnUninviteFromRoom(path, sender, invitee, ChatResult.ROOM_AVATAR_NO_PERMISSION.getCode(), p.getSequence())); return; } - if (!room.getInvited().contains(invitee)) { - player.sendPacket(new ChatOnUninviteFromRoom(path, sender, invitee, ChatResult.ROOM_PRIVATE.getCode(), p.getSequence())); - return; - } - if (!room.getInvited().remove(invitee)) { - player.sendPacket(new ChatOnUninviteFromRoom(path, sender, invitee, ChatResult.NONE.getCode(), p.getSequence())); + player.sendPacket(new ChatOnUninviteFromRoom(path, sender, invitee, ChatResult.ROOM_PRIVATE.getCode(), p.getSequence())); return; } @@ -203,6 +317,11 @@ public class ChatRoomService extends Service { return; } + if (room.isPublic()) { + player.sendPacket(new ChatOnInviteToRoom(path, sender, p.getAvatar(), ChatResult.NONE.getCode())); + return; + } + if (!room.isModerator(sender)) { player.sendPacket(new ChatOnInviteToRoom(path, sender, p.getAvatar(), ChatResult.ROOM_AVATAR_NO_PERMISSION.getCode())); return;