// 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:   messageServer.java

package boggle.server;

import boggle.server.comms.serverClient;
import boggle.settings;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

// Referenced classes of package boggle.server:
//            messageServerInterface, playerPool

public class messageServer extends UnicastRemoteObject
    implements messageServerInterface
{

    private static void bcast(String s, int i)
    {
        for(int j = 0; j < settings.getMaxPlayers(); j++)
            if(languageList[j] == i || i == -1)
                message[j] += s + "\n";

    }

    public static void broadcast(String s, int i)
        throws RemoteException
    {
        bcast(s, i);
        netSync.broadcast(settings.getHostName(), s, i);
    }

    public static void broadcast(String s, String s1, int i)
        throws RemoteException
    {
        bcast(s1, i);
        netSync.broadcast(s, s1, i);
    }

    public messageServer(serverClient serverclient)
        throws RemoteException
    {
        message = new String[settings.getMaxPlayers()];
        languageList = new int[settings.getMaxPlayers()];
        for(int i = 0; i < settings.getMaxPlayers(); i++)
        {
            message[i] = "";
            languageList[i] = -2;
        }

        netSync = serverclient;
    }

    public void declareLanguage(int i, int j)
        throws RemoteException
    {
        languageList[i] = j;
        message[i] = "";
    }

    public static void declarelanguage(int i, int j)
    {
        languageList[i] = j;
        message[i] = "";
    }

    public String send(String s, int i)
        throws RemoteException
    {
        String s1 = playerPool.getPlayerName(i) + ": " + s;
        broadcast(s1, languageList[i]);
        return get(i);
    }

    public String get(int i)
        throws RemoteException
    {
        String s = new String(message[i]);
        message[i] = "";
        return s;
    }

    public void quit(int i)
        throws RemoteException
    {
        String s = "System: " + playerPool.getPlayerName(i) + " has logged out of MessageServer";
        broadcast(s, languageList[i]);
        languageList[i] = -2;
    }

    public static void logout(int i)
    {
        languageList[i] = -2;
    }

    private static String message[];
    private static int languageList[];
    private static serverClient netSync;
}
