Fixed #308 and added foundation work for chat channels

This commit is contained in:
Waverunner
2014-03-29 16:47:05 -04:00
parent ac2f2e1e17
commit dfab6ac265
17 changed files with 668 additions and 17 deletions
+47
View File
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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;
import services.chat.ChatRoom;
public class ChatOnCreateRoom extends SWGMessage {
private ChatRoom room;
public ChatOnCreateRoom(ChatRoom room) {
this.room = room;
}
@Override
public void deserialize(IoBuffer data) {
}
@Override
public IoBuffer serialize() {
// TODO Auto-generated method stub
return null;
}
}
+70
View File
@@ -0,0 +1,70 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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 java.nio.ByteOrder;
import main.NGECore;
import org.apache.mina.core.buffer.IoBuffer;
import engine.resources.common.CRC;
import resources.common.Opcodes;
public class ChatOnEnteredRoom extends SWGMessage {
private String characterName;
private int success;
private int roomId;
private boolean join;
public ChatOnEnteredRoom(String characterName, int success, int roomId, boolean join) {
this.characterName = characterName;
this.success = success;
this.roomId = roomId;
}
@Override
public void deserialize(IoBuffer data) {
}
@Override
public IoBuffer serialize() {
String galaxy = NGECore.getInstance().getGalaxyName();
IoBuffer buffer = IoBuffer.allocate(27 + galaxy.length() + characterName.length()).order(ByteOrder.LITTLE_ENDIAN);
buffer.putShort((short) 5);
if (join)
buffer.putInt(Opcodes.ChatOnEnteredRoom);
else
buffer.putInt(CRC.StringtoCRC("ChatOnLeaveRoom"));
buffer.put(getAsciiString("SWG"));
buffer.put(getAsciiString(galaxy));
buffer.put(getAsciiString(characterName));
buffer.putInt(success);
buffer.putInt(roomId);
return buffer.flip();
}
public static final int JOIN_SUCCESS = 0;
public static final int JOIN_FAIL_NO_INVITE = 0x10;
}
@@ -0,0 +1,54 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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 java.nio.ByteOrder;
import org.apache.mina.core.buffer.IoBuffer;
public class ChatOnSendRoomMessage extends SWGMessage {
private int errorCode;
public ChatOnSendRoomMessage(int errorCode) {
this.errorCode = errorCode;
}
@Override
public void deserialize(IoBuffer data) {
}
@Override
public IoBuffer serialize() {
IoBuffer buffer = IoBuffer.allocate(14).order(ByteOrder.LITTLE_ENDIAN);
buffer.putShort((short) 3);
buffer.putInt(0xE7B61633);
buffer.putInt(errorCode);
buffer.putInt(1); // msg id
return buffer.flip();
}
public static final int SUCCESS = 0;
public static final int FAILED_MODERATOR = 9;
public static final int FAILED_LENGTH = 16;
}
+76
View File
@@ -0,0 +1,76 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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 java.nio.ByteOrder;
import java.util.concurrent.ConcurrentHashMap;
import main.NGECore;
import org.apache.mina.core.buffer.IoBuffer;
import services.chat.ChatRoom;
public class ChatRoomList extends SWGMessage {
private ConcurrentHashMap<Integer, ChatRoom> chatRooms;
public ChatRoomList(ConcurrentHashMap<Integer, ChatRoom> chatRooms) {
this.chatRooms = chatRooms;
}
@Override
public void deserialize(IoBuffer data) {
}
@Override
public IoBuffer serialize() {
String server = NGECore.getInstance().getGalaxyName();
IoBuffer buffer = IoBuffer.allocate(100).order(ByteOrder.LITTLE_ENDIAN);
buffer.setAutoExpand(true);
buffer.putShort((short) 2);
buffer.putInt(0x70DEB197);
buffer.putInt(chatRooms.size());
chatRooms.forEach((key, value) -> {
if (value.isVisible()) {
buffer.putInt(value.getRoomId());
buffer.putInt((int) ((value.isPrivateRoom() ? 1 : 0)));
buffer.put((byte) ((value.isModeratorsOnly() ? 1 : 0)));
buffer.put(getAsciiString(value.getRoomAddress()));
buffer.put(getAsciiString("SWG"));
buffer.put(getAsciiString(server));
buffer.put(getAsciiString(value.getOwner()));
buffer.put(getAsciiString("SWG"));
buffer.put(getAsciiString(server));
buffer.put(getAsciiString(value.getCreator()));
buffer.put(getUnicodeString(value.getDescription()));
buffer.putInt(0); // moderator list (not used by client)
buffer.putInt(0); // user list (not used by client)
}
});
return buffer.flip();
}
}
+63
View File
@@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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 java.nio.ByteOrder;
import main.NGECore;
import org.apache.mina.core.buffer.IoBuffer;
public class ChatRoomMessage extends SWGMessage {
private String character;
private String message;
private int roomId;
public ChatRoomMessage(int roomId, String player, String message) {
this.roomId = roomId;
this.character = player;
this.message = message;
}
@Override
public void deserialize(IoBuffer data) {
}
@Override
public IoBuffer serialize() {
String server = NGECore.getInstance().getGalaxyName();
IoBuffer buffer = IoBuffer.allocate(27 + server.length() + character.length() + (message.length() * 2)).order(ByteOrder.LITTLE_ENDIAN);
buffer.putShort((short) 5);
buffer.putInt(0xCD4CE444);
buffer.put(getAsciiString("SWG"));
buffer.put(getAsciiString(server));
buffer.put(getAsciiString(character));
buffer.putInt(roomId);
buffer.put(getUnicodeString(message));
buffer.putInt(0); // out of band package ?
return buffer.flip();
}
}