Methapolis  0.27
 All Classes Namespaces Files Functions Variables Enumerator
RemoteDistributor.java
Go to the documentation of this file.
1 package micropolisj.network;
2 
3 import java.io.ByteArrayOutputStream;
4 import java.io.FileInputStream;
5 import java.rmi.RemoteException;
6 import java.rmi.server.UnicastRemoteObject;
7 import java.util.Collections;
8 import java.util.HashMap;
9 import java.util.Map;
10 
11 import micropolisj.engine.Micropolis;
12 import micropolisj.engine.PlayerInfo;
13 
19 public class RemoteDistributor extends UnicastRemoteObject implements IMicropolisServer{
20 
21 
22  private transient ServerMicropolis micropolis;
23  private MapInfo mapInfo;
24  private Map<PlayerInput, Integer> events;
25 
26  private String levelName;
27 
28  private static int playerCount = 1;
29 
30 
31  protected RemoteDistributor(ServerMicropolis micropolis) throws RemoteException {
32  super();
33  this.micropolis = micropolis;
34  events = Collections.synchronizedMap(new HashMap<PlayerInput, Integer>());
35  }
36 
37 
38 
39  @Override
40  public synchronized MapInfo getLatestMap() throws RemoteException {
41  // TODO --- Threadsafety
42  return mapInfo;
43  }
44 
45  public synchronized void setMapInfo(MapInfo mI) {
46  mapInfo = mI;
47  }
48 
49  @Override
50  public synchronized void storeInput(int playerID, PlayerInput input) throws RemoteException {
51  events.put(input, playerID);
52  }
53 
54  public synchronized Map<PlayerInput, Integer> getInput() {
55  return events;
56  }
57 
58  @Override
59  public void setRemoteClient(RemoteClient client) throws RemoteException {
60 
61  }
62 
63  public void clearInput() {
64  events.clear();
65  }
66 
67  @Override
68  public byte[] getLevel() throws RemoteException {
69  return null;
70  //send .cty-file
71  }
72 
73 
74 
75  @Override
76  public int getNewID() throws RemoteException {
78  return playerCount++;
79  }
80 
81 
82 
83  @Override
84  public synchronized PlayerInfo getPlayerInfo(int ID) throws RemoteException{
85  return micropolis.getPlayerInfo(ID);
86  }
87 
88 }