001/* 002 * Trident - A Multithreaded Server Alternative 003 * Copyright 2014 The TridentSDK Team 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package net.tridentsdk.server.packets.login; 019 020import io.netty.buffer.ByteBuf; 021import net.tridentsdk.meta.MessageBuilder; 022import net.tridentsdk.server.netty.ClientConnection; 023import net.tridentsdk.server.netty.Codec; 024import net.tridentsdk.server.netty.packet.Packet; 025import net.tridentsdk.server.netty.packet.PacketDirection; 026import net.tridentsdk.util.TridentLogger; 027 028/** 029 * Packet used to disconnect the client from the login stage for whatsoever reason 030 * 031 * @author The TridentSDK Team 032 */ 033public class PacketLoginOutDisconnect implements Packet { 034 /** 035 * Disconnect message, represented JSON 036 */ 037 protected String jsonMessage; 038 039 @Override 040 public int id() { 041 return 0x00; 042 } 043 044 @Override 045 public PacketDirection direction() { 046 return PacketDirection.OUT; 047 } 048 049 @Override 050 public void encode(ByteBuf buf) { 051 Codec.writeString(buf, this.jsonMessage); 052 } 053 054 @Override 055 public void handleReceived(ClientConnection connection) { 056 } 057 058 // Here too... 059 public String jsonMessage() { 060 return this.jsonMessage; 061 } 062 063 public Packet setJsonMessage(String jsonMessage) { 064 this.jsonMessage = new MessageBuilder(jsonMessage).build().asJson(); 065 return this; 066 } 067 068 /** 069 * {@inheritDoc} 070 * 071 * <p>Cannot be decoded</p> 072 */ 073 @Override 074 public Packet decode(ByteBuf buf) { 075 TridentLogger.get().error(new UnsupportedOperationException("PacketLoginOutDisconnect cannot be encoded!")); 076 return null; 077 } 078}