Skip to content

Commit 4c73cf7

Browse files
authored
Merge pull request #3 from germangb/docker-friendly
Cool, I just had time to test today. I was looking at the code and was about to say that changing the global IP inside the Constants class was a very bad style, but investigating it I found out it was put there by me originally. I am just saying that this was a bad design by my part and no one should ever do something like this, so let's avoid this in the future =).
2 parents ba80cd9 + 853da74 commit 4c73cf7

10 files changed

Lines changed: 68 additions & 9 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.swp
2+
/bin
3+
*.jar

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM java:openjdk-7-jdk
2+
3+
RUN mkdir /compile
4+
5+
WORKDIR /compile
6+
7+
CMD [ "./compile.sh" ]

compile.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
mkdir -p bin
4+
javac -Xlint:deprecation -d bin/ -sourcepath src/ -classpath bin/ src/Graphwar/*.java src/GraphServer/*.java src/GlobalServer/*.java src/RoomServer/*.java
5+
6+
cp -r bin/Graphwar Graphwar
7+
cp -r bin/GraphServer GraphServer
8+
cp -r bin/GlobalServer GlobalServer
9+
cp -r bin/RoomServer RoomServer
10+
11+
jar cfe graphwar.jar Graphwar.Graphwar GraphServer Graphwar rsc
12+
jar cfe roomServer.jar RoomServer.RoomServer GraphServer RoomServer rsc
13+
jar cfe globalServer.jar GlobalServer.GlobalServer GraphServer GlobalServer rsc
14+
15+
rm -rf Graphwar
16+
rm -rf GraphServer
17+
rm -rf GlobalServer
18+
rm -rf RoomServer

globalServer.jar

-469 KB
Binary file not shown.

graphwar.jar

-564 KB
Binary file not shown.

makefile

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
21
all:
32

43
mkdir -p bin
5-
javac -d bin/ -sourcepath src/ -classpath bin/ src/Graphwar/*.java src/GraphServer/*.java src/GlobalServer/*.java src/RoomServer/*.java
6-
4+
javac -Xlint:deprecation -d bin/ -sourcepath src/ -classpath bin/ src/Graphwar/*.java src/GraphServer/*.java src/GlobalServer/*.java src/RoomServer/*.java
75
cp -r bin/Graphwar Graphwar
86
cp -r bin/GraphServer GraphServer
97
cp -r bin/GlobalServer GlobalServer
@@ -15,7 +13,30 @@ all:
1513
rm -rf GraphServer
1614
rm -rf GlobalServer
1715
rm -rf RoomServer
18-
16+
17+
docker-graphwar:
18+
19+
## build graphwar inside of a container
20+
docker run --rm \
21+
-v ${PWD}:/compile \
22+
graphwar/build
23+
24+
docker-image:
25+
26+
## build docker image
27+
docker build -t graphwar/build .
28+
29+
run-client:
30+
31+
## run graphwar on a container
32+
docker run --rm \
33+
-v ${PWD}:/compile \
34+
-v /tmp/.X11-unix:/tmp/.X11-unix \
35+
-e DISPLAY=${DISPLAY} \
36+
--network host \
37+
graphwar/build \
38+
java -jar graphwar.jar
39+
1940
clean:
2041

2142
rm -r bin

readme.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,5 @@ To run a local server and connect to it you must pass the ip of the local server
109109
and to the globalServer as a command line argument. So to start a server locally the commands are:
110110

111111
* java -jar globalServer.jar [your-server-ip]
112-
* java -jar roomServer.jar
112+
* java -jar roomServer.jar [your-server-ip]
113113
* java -jar graphwar.jar [your-server-ip]
114-
115-
The roomServer must be run on the same machine as the globalServer.
116-

roomServer.jar

-468 KB
Binary file not shown.

src/RoomServer/Room.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public Room(int roomNum) throws IOException
4040

4141
new Thread(gameServer).start();
4242

43-
globalClient.joinGlobalServer("localhost", Constants.GLOBAL_PORT, Constants.DUMMY_NAME);
43+
globalClient.joinGlobalServer(Constants.GLOBAL_IP, Constants.GLOBAL_PORT, Constants.DUMMY_NAME);
4444
globalClient.createRoom("Public Room "+roomNum, port);
4545
}
4646

src/RoomServer/RoomServer.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.List;
2424
import java.util.ListIterator;
2525

26+
import GraphServer.Constants;
27+
2628
public class RoomServer implements Runnable
2729
{
2830
private List<Room> rooms;
@@ -139,9 +141,20 @@ else if(numEmpty > 3)
139141
}
140142

141143
}
144+
145+
public static void handleArgs(String[] args)
146+
{
147+
if(args.length > 0)
148+
{
149+
// Overrides ip to create local server
150+
Constants.GLOBAL_IP = args[0];
151+
}
152+
}
142153

143154
public static void main(String[] args)
144155
{
156+
handleArgs(args);
157+
145158
RoomServer roomServer = new RoomServer();
146159

147160
new Thread(roomServer).start();

0 commit comments

Comments
 (0)