// Programmierpraktikum WS99/00, LMU Informatik, LFE Theoretische Informatik
package catan;

import java.rmi.*;
import java.rmi.server.*; 

public class Catan extends UnicastRemoteObject
                           implements RemoteCatan {
    static final boolean DEBUG=false;
    int anzahl=0;
    static final int MAX_ANZAHL=4;
    RemoteCatanView[] view = new RemoteCatanView[MAX_ANZAHL];
    public Catan() throws RemoteException {
	super();
    }
    public void addView(RemoteCatanView cv) {
	if (anzahl<MAX_ANZAHL) {
	    this.view[anzahl++]=cv;
	    System.err.println("\n"+anzahl+"te View eingetragen.");
	}
    }
    public void update(RemoteCatanView cv){
	try {
	    for (int i=0;i<anzahl;i++){
		// Nun der "Beweis", daß keine Schlüssel nötig sind.
		if (cv.equals(this.view[i]))
		    if (DEBUG) {
			System.err.println((i+1)+"ter Spieler handelt.");
		    } else {
			System.out.print(i+1);
		    }
		this.view[i].modiWert((int)(Math.random()*3)-1);
	    }
	} catch (Exception e){
            System.err.println("Catan exception: " + e.getMessage());
            e.printStackTrace();
        }
    }
    public static void main(String[] args){
	try {
	    Catan insel=new Catan();
	    Naming.rebind("Catan",insel);
	    System.out.println("Catan erfolgreich registriert.");
	} catch (Exception e){
            System.err.println("Catan exception: " + e.getMessage());
            e.printStackTrace();
        }
    }
}
