// Path: core/src/com/laststandstudio/space/engine/Networking/Common/PacketRegistry.java
// public class PacketRegistry {
// 
//     private static HashMap<Integer, Class<? extends Packet>> registeredPackets = new HashMap<>();
//     private static HashMap<Integer, Object> registeredPacketHandlers = new HashMap<>();
// 
// 
//     public static boolean registerPacket(Integer id, Class<? extends Packet> packet, PacketHandler handler) {
//         if (registeredPackets.containsKey(id) || registeredPackets.containsValue(packet) || registeredPacketHandlers.containsKey(id)) {
//             return false;
//         } else {
//             registeredPackets.put(id, packet);
//             registeredPacketHandlers.put(id, handler);
//             return true;
//         }
//     }
// 
//     public static Class<? extends Packet> getPacket(Integer id) {
//         if (registeredPackets.containsKey(id)) {
//             return registeredPackets.get(id);
//         } else {
//             return null;
//         }
//     }
// 
//     public static void submitPacket(Packet packet) {
// 
//         if (registeredPackets.containsKey(packet.getPacketId())) {
//             ((PacketHandler)registeredPacketHandlers.get(packet.getPacketId())).handlePacket(packet);
//         }
//     }
// }


import com.laststandstudio.space.engine.Networking.Common.Packet;
import com.laststandstudio.space.engine.Networking.Common.Packet01Text;
import com.laststandstudio.space.engine.Networking.Common.Packet03ServerDisconnect;
import com.laststandstudio.space.engine.Networking.Common.PacketRegistry;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
/******************************************************************************
 * Space Shooter Software License
 * Version 0.0.2-alpha
 *
 * Copyright (C) 2015 Last Stand Studio
 *
 *  SpaceShooter is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  SpaceShooter 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with SpaceShooter.  If not, see <http://www.gnu.org/licenses/>.
 *****************************************************************************/

package com.laststandstudio.space.engine.Networking.Server;



/**
 * @author Joshua Freedman
 */
public class ClientConnection extends Thread {

    /** Socket Object that stores the Client's Socket Connection */
    Socket socket = null;

    /** A reference to the OutputStream of the socket. */
    ObjectOutputStream out;

    /** A reference to the InputStream of the socket. */
    ObjectInputStream in;

    /**
     * Parameter is the socket object of the client.
     * @param socket
     */
    ClientConnection(Socket socket) {
        this.socket = socket;
        start();
    }

    public void run() {
        System.out.println("New Client Communication Thread Started");

        try {
            out = new ObjectOutputStream(socket.getOutputStream());
            in = new ObjectInputStream(socket.getInputStream());

            Object inObj;
            while ((inObj = in.readObject()) != null) {
                Packet packet = (Packet) inObj;

// Path: core/src/com/laststandstudio/space/engine/Networking/Common/PacketRegistry.java
// public class PacketRegistry {
// 
//     private static HashMap<Integer, Class<? extends Packet>> registeredPackets = new HashMap<>();
//     private static HashMap<Integer, Object> registeredPacketHandlers = new HashMap<>();
// 
// 
//     public static boolean registerPacket(Integer id, Class<? extends Packet> packet, PacketHandler handler) {
//         if (registeredPackets.containsKey(id) || registeredPackets.containsValue(packet) || registeredPacketHandlers.containsKey(id)) {
//             return false;
//         } else {
//             registeredPackets.put(id, packet);
//             registeredPacketHandlers.put(id, handler);
//             return true;
//         }
//     }
// 
//     public static Class<? extends Packet> getPacket(Integer id) {
//         if (registeredPackets.containsKey(id)) {
//             return registeredPackets.get(id);
//         } else {
//             return null;
//         }
//     }
// 
//     public static void submitPacket(Packet packet) {
// 
//         if (registeredPackets.containsKey(packet.getPacketId())) {
//             ((PacketHandler)registeredPacketHandlers.get(packet.getPacketId())).handlePacket(packet);
//         }
//     }
// }


// Path: core/src/com/laststandstudio/space/engine/Networking/Server/ClientConnection.java
import com.laststandstudio.space.engine.Networking.Common.Packet;
import com.laststandstudio.space.engine.Networking.Common.Packet01Text;
import com.laststandstudio.space.engine.Networking.Common.Packet03ServerDisconnect;
import com.laststandstudio.space.engine.Networking.Common.PacketRegistry;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

/******************************************************************************
 * Space Shooter Software License
 * Version 0.0.2-alpha
 *
 * Copyright (C) 2015 Last Stand Studio
 *
 *  SpaceShooter is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  SpaceShooter 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with SpaceShooter.  If not, see <http://www.gnu.org/licenses/>.
 *****************************************************************************/

package com.laststandstudio.space.engine.Networking.Server;



/**
 * @author Joshua Freedman
 */
public class ClientConnection extends Thread {

    /** Socket Object that stores the Client's Socket Connection */
    Socket socket = null;

    /** A reference to the OutputStream of the socket. */
    ObjectOutputStream out;

    /** A reference to the InputStream of the socket. */
    ObjectInputStream in;

    /**
     * Parameter is the socket object of the client.
     * @param socket
     */
    ClientConnection(Socket socket) {
        this.socket = socket;
        start();
    }

    public void run() {
        System.out.println("New Client Communication Thread Started");

        try {
            out = new ObjectOutputStream(socket.getOutputStream());
            in = new ObjectInputStream(socket.getInputStream());

            Object inObj;
            while ((inObj = in.readObject()) != null) {
                Packet packet = (Packet) inObj;

                PacketRegistry.submitPacket(packet);