Methapolis  0.27
 All Classes Namespaces Files Functions Variables Enumerator
RemoteClient.java
Go to the documentation of this file.
1 package micropolisj.network;
2 
3 import java.io.Serializable;
4 import java.net.MalformedURLException;
5 import java.rmi.Naming;
6 import java.rmi.NotBoundException;
7 import java.rmi.RemoteException;
8 import java.rmi.server.UnicastRemoteObject;
9 
10 import micropolisj.engine.PlayerInfo;
11 
12 public class RemoteClient extends UnicastRemoteObject implements Serializable{
13 
14  private transient IMicropolisServer server;
15 
16  private String IP;
17 
18  private int playerID;
19 
20  public RemoteClient(String ip) throws RemoteException{
21  try {
22  // TODO: make constants for address
23  if(ip.equalsIgnoreCase("local") || ip.equalsIgnoreCase("localhost")) {
24  ip = "127.0.0.1";
25  System.out.println("local");
26  }
27  IP = ip;
28  server = (IMicropolisServer) Naming.lookup("rmi://" + IP + "/" + NetworkServer.NAMING_BIND);
29 // server.setRemoteClient(this);
30  System.out.println(">>> connected to server...");
32  // System.out.println(playerID);
33  } catch (MalformedURLException | NotBoundException e) {
34  // TODO Auto-generated catch block
35  e.printStackTrace();
36  }
37  }
38 
40  try {
42  } catch (RemoteException e) {
43  // TODO Auto-generated catch block
44  e.printStackTrace();
45  }
46  return null;
47  }
48 
49  public int getID() {
50  return playerID;
51  }
52 
53  public void sendInput(PlayerInput input){
54  try {
55  server.storeInput(playerID, input);
56  } catch (RemoteException e) {
57  // TODO Auto-generated catch block
58  e.printStackTrace();
59  }
60  }
61 
62  public MapInfo getMap() {
63  try {
64  return server.getLatestMap();
65  } catch (RemoteException e) {
66  // TODO Auto-generated catch block
67  e.printStackTrace();
68  }
69  return null;
70  }
71 
72  public String getIP() {
73  return IP;
74  }
75 
76 }