From 64bfdb2b8be108213a5a53db66f35f4c174df47e Mon Sep 17 00:00:00 2001 From: Waverunner Date: Sun, 30 Mar 2014 15:09:48 -0400 Subject: [PATCH] Added pistol to frog, more work on chat channels --- src/protocol/swg/ChatCreateRoom.java | 38 +++++++++++ src/protocol/swg/ChatEnterRoomById.java | 50 +++++++++++++++ src/protocol/swg/ChatOnSendRoomMessage.java | 6 +- src/protocol/swg/ChatSendToRoom.java | 71 +++++++++++++++++++++ src/resources/common/Opcodes.java | 2 + src/services/DevService.java | 10 +++ src/services/EntertainmentService.java | 2 +- src/services/GroupService.java | 2 +- src/services/chat/ChatService.java | 59 +++++++++++++++-- 9 files changed, 229 insertions(+), 11 deletions(-) create mode 100644 src/protocol/swg/ChatCreateRoom.java create mode 100644 src/protocol/swg/ChatEnterRoomById.java create mode 100644 src/protocol/swg/ChatSendToRoom.java diff --git a/src/protocol/swg/ChatCreateRoom.java b/src/protocol/swg/ChatCreateRoom.java new file mode 100644 index 00000000..5f63614a --- /dev/null +++ b/src/protocol/swg/ChatCreateRoom.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2013 + * + * This File is part of NGECore2. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Using NGEngine to work with NGECore2 is making a combined work based on NGEngine. + * Therefore all terms and conditions of the GNU Lesser General Public License cover the combination. + ******************************************************************************/ +package protocol.swg; + +import org.apache.mina.core.buffer.IoBuffer; + +public class ChatCreateRoom extends SWGMessage { + + @Override + public void deserialize(IoBuffer data) { + + } + + @Override + public IoBuffer serialize() { + return null; + } + +} diff --git a/src/protocol/swg/ChatEnterRoomById.java b/src/protocol/swg/ChatEnterRoomById.java new file mode 100644 index 00000000..29fd69cd --- /dev/null +++ b/src/protocol/swg/ChatEnterRoomById.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2013 + * + * This File is part of NGECore2. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Using NGEngine to work with NGECore2 is making a combined work based on NGEngine. + * Therefore all terms and conditions of the GNU Lesser General Public License cover the combination. + ******************************************************************************/ +package protocol.swg; + +import org.apache.mina.core.buffer.IoBuffer; + +public class ChatEnterRoomById extends SWGMessage { + + private int roomId; + + public ChatEnterRoomById() { } + + @Override + public void deserialize(IoBuffer data) { + setRoomId(data.getInt()); + } + + @Override + public IoBuffer serialize() { + return null; + } + + public int getRoomId() { + return roomId; + } + + public void setRoomId(int roomId) { + this.roomId = roomId; + } + +} diff --git a/src/protocol/swg/ChatOnSendRoomMessage.java b/src/protocol/swg/ChatOnSendRoomMessage.java index 4ab43d6c..0d7729e5 100644 --- a/src/protocol/swg/ChatOnSendRoomMessage.java +++ b/src/protocol/swg/ChatOnSendRoomMessage.java @@ -28,9 +28,11 @@ import org.apache.mina.core.buffer.IoBuffer; public class ChatOnSendRoomMessage extends SWGMessage { private int errorCode; + private int msgId; - public ChatOnSendRoomMessage(int errorCode) { + public ChatOnSendRoomMessage(int errorCode, int msgId) { this.errorCode = errorCode; + this.msgId = msgId; } @Override @@ -43,7 +45,7 @@ public class ChatOnSendRoomMessage extends SWGMessage { buffer.putShort((short) 3); buffer.putInt(0xE7B61633); buffer.putInt(errorCode); - buffer.putInt(1); // msg id + buffer.putInt(msgId); // msg id return buffer.flip(); } diff --git a/src/protocol/swg/ChatSendToRoom.java b/src/protocol/swg/ChatSendToRoom.java new file mode 100644 index 00000000..c3a07dac --- /dev/null +++ b/src/protocol/swg/ChatSendToRoom.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2013 + * + * This File is part of NGECore2. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Using NGEngine to work with NGECore2 is making a combined work based on NGEngine. + * Therefore all terms and conditions of the GNU Lesser General Public License cover the combination. + ******************************************************************************/ +package protocol.swg; + +import org.apache.mina.core.buffer.IoBuffer; + +public class ChatSendToRoom extends SWGMessage { + + private String message; + private int roomId; + private int msgId; + + public ChatSendToRoom() { } + + @Override + public void deserialize(IoBuffer data) { + setMessage(getUnicodeString(data)); + data.getInt(); + setRoomId(data.getInt()); + setMsgId(data.getInt()); + } + + @Override + public IoBuffer serialize() { + return null; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public int getRoomId() { + return roomId; + } + + public void setRoomId(int roomId) { + this.roomId = roomId; + } + + public int getMsgId() { + return msgId; + } + + public void setMsgId(int msgId) { + this.msgId = msgId; + } + +} diff --git a/src/resources/common/Opcodes.java b/src/resources/common/Opcodes.java index 9f906000..4ac4d5ad 100644 --- a/src/resources/common/Opcodes.java +++ b/src/resources/common/Opcodes.java @@ -25,6 +25,8 @@ import engine.resources.common.CRC; public class Opcodes { + public static int ChatEnterRoomById = CRC.StringtoCRC("ChatEnterRoomById"); + public static int ChatSendToRoom = CRC.StringtoCRC("ChatSendToRoom"); public static int ChatDeletePersistentMessage = 0x8F251641; public static int ChatInstantMessageToCharacter = 0x84BB21F7; public static int ChatPersistentMessageToServer = 0x25A29FA6; diff --git a/src/services/DevService.java b/src/services/DevService.java index 6359957d..9ea45006 100644 --- a/src/services/DevService.java +++ b/src/services/DevService.java @@ -93,6 +93,7 @@ public class DevService implements INetworkDispatch { break; case 4: // [Items] Misc Items suiOptions.put((long) 40, "Unity Ring"); + break; } final SUIWindow window = core.suiService.createListBox(ListBoxType.LIST_BOX_OK_CANCEL, "Character Builder Terminal", "Select the desired option and click OK.", suiOptions, creature, null, 10); @@ -275,6 +276,15 @@ public class DevService implements INetworkDispatch { rifle1.setStringAttribute("cat_wpn_damage.damage", "800-1250"); inventory.add(rifle1); + + SWGObject pistol = core.objectService.createObject("object/weapon/ranged/pistol/shared_pistol_cdef.iff", planet); + pistol.setIntAttribute("required_combat_level", 90); + pistol.setFloatAttribute("cat_wpn_damage.wpn_attack_speed", 1); + pistol.setStringAttribute("class_required", "None"); + pistol.setStringAttribute("cat_wpn_damage.wpn_damage_type", "Energy"); + pistol.setStringAttribute("cat_wpn_damage.damage", "400-559"); + + inventory.add(pistol); return; case 40: TangibleObject ring = (TangibleObject) core.objectService.createObject("object/tangible/wearables/ring/shared_ring_s01.iff", planet); diff --git a/src/services/EntertainmentService.java b/src/services/EntertainmentService.java index 8b64175e..970d6f2d 100644 --- a/src/services/EntertainmentService.java +++ b/src/services/EntertainmentService.java @@ -67,7 +67,7 @@ public class EntertainmentService implements INetworkDispatch { private ConcurrentHashMap designMap = new ConcurrentHashMap(); - private Random ranWorkshop = new Random(); + //private Random ranWorkshop = new Random(); private Map performanceEffects = new ConcurrentHashMap(); diff --git a/src/services/GroupService.java b/src/services/GroupService.java index dc2cf39b..472c4f80 100644 --- a/src/services/GroupService.java +++ b/src/services/GroupService.java @@ -153,7 +153,7 @@ public class GroupService implements INetworkDispatch { addGroupBuffsToMember(group, leader); addGroupBuffsToMember(group, invited); - //ChatRoom groupChat = core.chatService.createChatRoom(leader.getCustomName() + group.getObjectID(), "GroupChat", leader.getCustomName(), true); + //ChatRoom groupChat = core.chatService.createChatRoom("GroupChat", "group." + group.getObjectID(), leader.getCustomName(), true); //group.setChatRoomId(groupChat.getRoomId()); //core.chatService.joinChatRoom(leader, groupChat.getRoomId()); diff --git a/src/services/chat/ChatService.java b/src/services/chat/ChatService.java index c5b5bb5e..562686dc 100644 --- a/src/services/chat/ChatService.java +++ b/src/services/chat/ChatService.java @@ -49,6 +49,7 @@ import resources.common.*; import resources.objects.creature.CreatureObject; import resources.objects.player.PlayerObject; import protocol.swg.AddIgnoreMessage; +import protocol.swg.ChatEnterRoomById; import protocol.swg.ChatOnChangeFriendStatus; import protocol.swg.ChatDeletePersistentMessage; import protocol.swg.ChatFriendsListUpdate; @@ -64,6 +65,7 @@ import protocol.swg.ChatPersistentMessageToServer; import protocol.swg.ChatRequestPersistentMessage; import protocol.swg.ChatRoomList; import protocol.swg.ChatRoomMessage; +import protocol.swg.ChatSendToRoom; import protocol.swg.ChatSystemMessage; import protocol.swg.ObjControllerMessage; import protocol.swg.objectControllerObjects.PlayerEmote; @@ -367,9 +369,53 @@ public class ChatService implements INetworkDispatch { }); swgOpcodes.put(Opcodes.ChatCreateRoom, (session, data) -> { + //System.out.println("CREATE:"); + //StringUtilities.printBytes(data.array()); }); swgOpcodes.put(Opcodes.ChatQueryRoom, (session, data) -> { + //System.out.println("QUERY: "); + //StringUtilities.printBytes(data.array()); + }); + + swgOpcodes.put(Opcodes.ChatSendToRoom, (session, data) -> { + Client client = core.getClient(session); + + if(client == null) + return; + + SWGObject obj = client.getParent(); + + if (obj == null) + return; + + ChatSendToRoom sentPacket = new ChatSendToRoom(); + sentPacket.deserialize(data); + + //ChatRoom room = getChatRoom(sentPacket.getRoomId()); + + sendChatRoomMessage((CreatureObject) obj, sentPacket.getRoomId(), sentPacket.getMsgId(), sentPacket.getMessage()); + + }); + + swgOpcodes.put(Opcodes.ChatEnterRoomById, (session, data) -> { + Client client = core.getClient(session); + + if(client == null) + return; + + SWGObject obj = client.getParent(); + + if (obj == null) + return; + + ChatEnterRoomById sentPacket = new ChatEnterRoomById(); + sentPacket.deserialize(data); + + joinChatRoom((CreatureObject) obj, sentPacket.getRoomId()); + + //System.out.println("Entering room..."); + }); } @@ -687,10 +733,12 @@ public class ChatService implements INetworkDispatch { return; ChatOnEnteredRoom enterRoom = new ChatOnEnteredRoom(playerName, 0, roomId, true); - player.getClient().getSession().write(enterRoom.serialize()); if (!room.getUserList().contains(player)) room.getUserList().add(player); + + room.getUserList().stream().forEach(user -> user.getClient().getSession().write(enterRoom.serialize())); + } public void leaveChatRoom(CreatureObject player, int roomId) { @@ -711,7 +759,7 @@ public class ChatService implements INetworkDispatch { room.getUserList().remove(player); } - public void sendChatRoomMessage(CreatureObject sender, int roomId, String message) { + public void sendChatRoomMessage(CreatureObject sender, int roomId, int msgId, String message) { String senderName = sender.getCustomName().toLowerCase(); if (senderName.contains(" ")) @@ -720,17 +768,14 @@ public class ChatService implements INetworkDispatch { ChatRoom room = getChatRoom(roomId); if (room == null) return; - - ChatOnSendRoomMessage onSend = new ChatOnSendRoomMessage(ChatOnSendRoomMessage.SUCCESS); + + ChatOnSendRoomMessage onSend = new ChatOnSendRoomMessage(0, msgId); sender.getClient().getSession().write(onSend.serialize()); ChatRoomMessage roomMessage = new ChatRoomMessage(roomId, senderName, message); Vector users = room.getUserList(); for (CreatureObject user : users) { - if (user == sender) - continue; - user.getClient().getSession().write(roomMessage.serialize()); } }