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.netty.protocol; 019 020import net.tridentsdk.server.netty.packet.Packet; 021import net.tridentsdk.server.netty.packet.PacketDirection; 022import net.tridentsdk.util.TridentLogger; 023 024import javax.annotation.concurrent.ThreadSafe; 025 026/** 027 * The base implementation for the protocol handling internals 028 * 029 * @author The TridentSDK Team 030 */ 031@ThreadSafe 032public class Protocol { 033 private final Play play = new Play(); 034 private final Status status = new Status(); 035 private final Login login = new Login(); 036 private final Handshake handshake = new Handshake(); 037 038 public Play play() { 039 return this.play; 040 } 041 042 public Status status() { 043 return this.status; 044 } 045 046 public Login login() { 047 return this.login; 048 } 049 050 public Handshake handshake() { 051 return this.handshake; 052 } 053 054 public Packet getPacket(int id, ClientStage stage, PacketDirection type) { 055 switch (stage) { 056 case PLAY: 057 return this.play.packet(id, type); 058 059 case HANDSHAKE: 060 return this.handshake.packet(id, type); 061 062 case STATUS: 063 return this.status.packet(id, type); 064 065 case LOGIN: 066 return this.login.packet(id, type); 067 068 default: 069 TridentLogger.get().error(new IllegalArgumentException(stage + " is not supported for Protocol#packet!")); 070 } 071 return null; 072 } 073 074 public enum ClientStage { 075 // TODO Add this to a more appropriate class 076 PLAY, STATUS, LOGIN, HANDSHAKE 077 } 078}