// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   ClientServer.java

import java.io.*;
import java.net.Socket;

public class ClientServer
    implements Runnable
{

    ClientServer(Socket socket, BoggleGrid bogglegrid, HighScoreTable ahighscoretable[])
    {
        clientSock = socket;
        theGrid = bogglegrid;
        theHighScores = ahighscoretable;
    }

    public void run()
    {
        int i;
        try
        {
            DataInputStream datainputstream = new DataInputStream(clientSock.getInputStream());
            i = datainputstream.readInt();
        }
        catch(IOException ioexception)
        {
            System.err.println(ioexception);
            try
            {
                clientSock.close();
            }
            catch(IOException ioexception5)
            {
                System.err.println(ioexception5);
            }
            return;
        }
        switch(i)
        {
        case 12: // '\f'
            try
            {
                ObjectOutputStream objectoutputstream = new ObjectOutputStream(clientSock.getOutputStream());
                objectoutputstream.writeObject(theGrid);
                objectoutputstream.close();
            }
            catch(IOException ioexception1)
            {
                System.err.println(ioexception1);
            }
            break;

        case 14: // '\016'
            try
            {
                ObjectOutputStream objectoutputstream1 = new ObjectOutputStream(clientSock.getOutputStream());
                synchronized(theHighScores[0])
                {
                    objectoutputstream1.writeObject(theHighScores[0]);
                }
                objectoutputstream1.close();
            }
            catch(IOException ioexception2)
            {
                System.err.println(ioexception2);
            }
            break;

        case 16: // '\020'
            try
            {
                ObjectInputStream objectinputstream = new ObjectInputStream(clientSock.getInputStream());
                Score score = (Score)objectinputstream.readObject();
                try
                {
                    synchronized(theHighScores[0])
                    {
                        theHighScores[0].addScore((Score)score.clone());
                    }
                    synchronized(theHighScores[score.getGridNumber() + 1])
                    {
                        theHighScores[score.getGridNumber() + 1].addScore((Score)score.clone());
                    }
                }
                catch(CloneNotSupportedException clonenotsupportedexception)
                {
                    System.err.println(clonenotsupportedexception);
                }
                ObjectOutputStream objectoutputstream2 = new ObjectOutputStream(clientSock.getOutputStream());
                synchronized(theHighScores[score.getGridNumber() + 1])
                {
                    objectoutputstream2.writeObject(theHighScores[score.getGridNumber() + 1]);
                }
                objectinputstream.close();
                objectoutputstream2.close();
            }
            catch(IOException ioexception3)
            {
                System.err.println(ioexception3);
            }
            catch(ClassNotFoundException classnotfoundexception)
            {
                System.err.println(classnotfoundexception);
            }
            break;

        case 13: // '\r'
        case 15: // '\017'
        default:
            System.err.println("Warning: Invalid request");
            break;
        }
        try
        {
            clientSock.close();
        }
        catch(IOException ioexception4)
        {
            System.err.println(ioexception4);
        }
    }

    private Socket clientSock;
    private BoggleGrid theGrid;
    private HighScoreTable theHighScores[];
}

