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

package boggle.server.comms;

import boggle.server.*;
import boggle.settings;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

// Referenced classes of package boggle.server.comms:
//            serverClient, serverInterface

public class serverServer extends UnicastRemoteObject
    implements serverInterface
{

    public serverServer(serverClient serverclient)
        throws RemoteException
    {
        netsync = serverclient;
    }

    public void addNewPlayer(String s, int i, player player)
        throws RemoteException
    {
        playerPool.addPlayer(s, i, player);
    }

    public void login(String s, int i, int j)
        throws RemoteException
    {
        playerPool.Login(s, i, j);
        messageServer.declarelanguage(i, j);
    }

    public void logout(String s, int i)
        throws RemoteException
    {
        playerPool.logout(s, i);
        messageServer.logout(i);
    }

    public void newgame(String s, int i, String s1, String s2, int j, int k)
        throws RemoteException
    {
        gamePool.newgame(s, i, s1, s2, j, k);
    }

    public void joingame(String s, int i, int j)
        throws RemoteException
    {
        gamePool.joingame(s, i, j);
    }

    public void finalscore(String s, int i, int j, int k)
        throws RemoteException
    {
        gamePool.finalscore(s, i, j, k);
    }

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

    public boolean attach(String s)
        throws RemoteException
    {
        int i = settings.otherServers.length;
        if(i == settings.getMaxConnectedServers())
            return false;
        String as[] = new String[i + 1];
        for(int j = 0; j < i; j++)
            as[j] = settings.otherServers[j];

        as[i] = s;
        settings.otherServers = as;
        return true;
    }

    public String[] getAlternateServers()
        throws RemoteException
    {
        return settings.otherServers;
    }

    public void takeOver(String s, String as[])
        throws RemoteException
    {
        if(as.length + settings.otherServers.length > settings.getMaxConnectedServers())
            try
            {
                serverInterface serverinterface = (serverInterface)Naming.lookup("//" + settings.otherServers[settings.otherServers.length - 1] + "/ServerServer");
                serverinterface.takeOver(s, as);
                return;
            }
            catch(Exception exception)
            {
                throw new RemoteException("Error in serverServer propagate takeOver.", exception);
            }
        int i = -1;
        for(int j = 0; j < settings.otherServers.length; j++)
            if(settings.otherServers[j].equals(s))
                i = j;

        String as1[];
        if(i == -1)
        {
            as1 = new String[settings.otherServers.length + as.length];
            for(int k = 0; k < settings.otherServers.length; k++)
                as1[k] = settings.otherServers[k];

            for(int i1 = 0; i1 < as.length; i1++)
                as1[i1 + settings.otherServers.length] = as[i1];

        } else
        {
            as1 = new String[(settings.otherServers.length + as.length) - 1];
            for(int l = 0; l < as.length; l++)
                as1[l] = as[l];

            for(int j1 = 0; j1 < settings.otherServers.length; j1++)
                if(i > j1)
                    as1[j1 + as.length] = settings.otherServers[j1];
                else
                if(i < j1)
                    as1[(j1 - 1) + as.length] = settings.otherServers[j1];

        }
        settings.otherServers = as1;
        netsync.informChangeServer(settings.getHostName(), s, settings.getHostName());
    }

    public void changeServer(String s, String s1)
        throws RemoteException
    {
        for(int i = 0; i < settings.otherServers.length; i++)
            if(settings.otherServers[i].equals(s))
                settings.otherServers[i] = s1;

    }

    public String[] getGameNames()
        throws RemoteException
    {
        return settings.getGameNames();
    }

    public String[] getLanguages()
        throws RemoteException
    {
        return settings.getLanguages();
    }

    public String[] getGameDescriptions()
        throws RemoteException
    {
        return gamePool.getDescriptions();
    }

    public String[] getGameDefinitions()
        throws RemoteException
    {
        return gamePool.getDefinitions();
    }

    public int[] getGameLanguageList()
        throws RemoteException
    {
        return gamePool.getLanguages();
    }

    public int[] getGameTypeList()
        throws RemoteException
    {
        return gamePool.getTypes();
    }

    public player[] getPlayerList()
        throws RemoteException
    {
        return playerPool.getPlayerList();
    }

    public int[] getLoggedInList()
        throws RemoteException
    {
        return playerPool.getLoggedInList();
    }

    private serverClient netsync;
}
