diff --git a/RMISSLClientSocketFactory.java b/RMISSLClientSocketFactory.java new file mode 100644 index 0000000..a7a634f --- /dev/null +++ b/RMISSLClientSocketFactory.java @@ -0,0 +1,27 @@ +import java.io.*; +import java.net.*; +import java.rmi.server.*; +import javax.net.ssl.*; + +public class RMISSLClientSocketFactory + implements RMIClientSocketFactory, Serializable { + + public Socket createSocket(String host, int port) throws IOException { + SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault(); + SSLSocket socket = (SSLSocket)factory.createSocket(host, port); + return socket; + } + + public int hashCode() { + return getClass().hashCode(); + } + + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else if (obj == null || getClass() != obj.getClass()) { + return false; + } + return true; + } +} \ No newline at end of file diff --git a/RMISSLServerSocketFactory.java b/RMISSLServerSocketFactory.java new file mode 100644 index 0000000..695fe6b --- /dev/null +++ b/RMISSLServerSocketFactory.java @@ -0,0 +1,62 @@ +import java.io.FileInputStream; +import java.io.IOException; +import java.net.ServerSocket; +import java.rmi.server.RMIServerSocketFactory; +import java.security.KeyStore; + +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLServerSocket; +import javax.net.ssl.SSLServerSocketFactory; + +public class RMISSLServerSocketFactory implements RMIServerSocketFactory{ + private static SSLServerSocketFactory ssf = null; + + final String runRoot = "C:/eclipse/java/WarGame/bin/"; + String ksName = runRoot + ".keystore/SSLSocketServerKey"; + + public RMISSLServerSocketFactory() throws Exception{ + try { + KeyStore ks; + KeyManagerFactory kmf; + SSLContext sc ; + + + char[] keyStorePass = "123456".toCharArray(); + char[] keyPass = "123456".toCharArray(); + + ks = KeyStore.getInstance("JKS"); + ks.load(new FileInputStream(ksName), keyStorePass); + kmf = KeyManagerFactory.getInstance("SunX509"); + kmf.init(ks, keyPass); + + sc = SSLContext.getInstance("TLS"); + sc.init(kmf.getKeyManagers(), null, null); + ssf = sc.getServerSocketFactory(); + + } catch(Exception e) { + e.printStackTrace(); + throw e; + } + } + + + public ServerSocket createServerSocket(int port) throws IOException { + return ssf.createServerSocket(port); + } + + public int hashCode() { + return getClass().hashCode(); + } + + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else if (obj == null || getClass() != obj.getClass()) { + return false; + } + return true; + } + + +} diff --git a/SSLSocketServerKey b/SSLSocketServerKey new file mode 100644 index 0000000..ee6c305 Binary files /dev/null and b/SSLSocketServerKey differ diff --git a/SSLSocketServerKey.cert b/SSLSocketServerKey.cert new file mode 100644 index 0000000..4e5aec5 Binary files /dev/null and b/SSLSocketServerKey.cert differ diff --git a/WarGameClient.java b/WarGameClient.java index 02a53f4..c9b431b 100644 --- a/WarGameClient.java +++ b/WarGameClient.java @@ -1,21 +1,31 @@ import java.rmi.AccessException; import java.rmi.Naming; import java.rmi.RemoteException; -import java.rmi.server.UnicastRemoteObject; -import java.util.Scanner; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.net.InetAddress; import java.net.MalformedURLException; +import java.net.UnknownHostException; import java.rmi.NotBoundException; -import java.net.MalformedURLException; +import java.rmi.server.UnicastRemoteObject; +import java.util.ArrayList; +import java.util.Scanner; import java.rmi.NotBoundException; + + + public class WarGameClient implements Runnable {//handle connection and use rmi function here from client side // private static final long serialVersionUID = 1L; + private static final int PORT = 2019; + private String id; boolean chkLog=false; private WarGame server; boolean boolean_ReadyBtnStatus; boolean boolean_HitBtnStatus; boolean boolean_DropBtnStatus; - + ArrayList client; + WarGameGUI gui; protected WarGameClient(WarGame wg,String id,String pw){ boolean_ReadyBtnStatus=false; boolean_HitBtnStatus=false; @@ -28,72 +38,176 @@ protected WarGameClient(WarGame wg,String id,String pw){ System.out.println("wrong id or wrong passworld"); System.exit(0); } - - + + }catch(RemoteException re) { System.out.println("RemoteException: "+re); - + }catch(java.lang.ArithmeticException ae) { System.out.println("java.lang.ArithmeticException: "+ae); } + + } + void drop() { + boolean_DropBtnStatus=gui.returnDropBtnStatus(); + try { + server.doDrop(id);//id가 필요한지 모르겠음... + }catch(Exception e) { + e.printStackTrace(); + } + } + void hit() { + boolean_HitBtnStatus=gui.returnHitBtnStatus(); + try { + server.doHit(id); + }catch(Exception e) { + e.printStackTrace(); + } } - public void run() { if(chkLog) { System.out.println(id); - WarGameGUI gui=new WarGameGUI(id); + gui=new WarGameGUI(id); + gui.deactivatedHitDropBtn(); try { while(server.checkAllReady()==false) { boolean_ReadyBtnStatus=gui.returnReadyBtnStatus(); - server.setReadyStatus(id, boolean_ReadyBtnStatus); + server.setReadyStatus(id, boolean_ReadyBtnStatus); } - - }catch(Exception e) {//디테일하게 예외 잡아 줘야 할 듯.. 예외처리 사이즈가 + + }catch(Exception e) {//디테일하게 예외 잡아 줘야 할 듯.. 예외처리 사이즈가 e.printStackTrace(); } + gui.activatedHitDropBtn(); System.out.println("game start");//this will be deleted in the end gui.setGameInfo("game start"); gui.deactivateReadyBtn(); - -// try { -// do{//게임중... do while인 이유는 마지막 카드가 공격이어서 기회가 남아 있을수도 있다.. -// //////////////////// -// }while(server.checkStatus()); -// }catch(Exception e) {//디테일하게 예외 잡아 줘야 할 듯..예외처리 사이즈가 커 + try {//최종 참가자 리스트 추가 + client=server.getClientList(); + String tmp=client.get(0); + String tmp2=client.get(1); + gui.setPlayerList("Player1: "+tmp); + gui.setPlayerList("Player2: "+tmp2); + }catch(Exception e) { + e.printStackTrace(); + } +// try {//턴 돌아갈때 마다 올라가는 것으로 바꿔야 할것 같다. 1번에 국한되지 말고... +// if(id.contentEquals(server.whosTurn())) { +// String tmp=server.whosTurn(); +// sendMsgToAll(tmp+"'s turn\n"); +// +// } +// +//// System.out.println(tmp+"'s turn. good luck~!"); +//// gui.setGameInfo(tmp+"'s turn. good luck~!"); +//// String msg=receiveMsg(); +//// gui.setMsgView(msg); +// +// +// }catch(Exception e) { // e.printStackTrace(); // } + try { + while(server.checkEndingStatus()){//게임중... + while(id.equals(server.whosTurn())){//자신의 턴 동안... + boolean_DropBtnStatus=gui.returnDropBtnStatus(); + boolean_HitBtnStatus=gui.returnHitBtnStatus(); + if(boolean_DropBtnStatus) { + drop(); + gui.setMsgView("플레이어 "+ id+" 가 drop을 했습니다."); +// server.doDrop(id);//id는 안쓰고, serverImpl에서 turn보고 알아서 판단하고 있음. 필요 없는거 확실해지면 그때 지우기. + gui.setDropStatusFalse();//버튼 눌리면 true로 변하기 때문에 변경 안하면 항상 true인 효과 한번 버튼 누르면 다시 false로 변환 + //server.changeTurn(); + gui.repaint(); + }else if(boolean_HitBtnStatus) { + hit(); +// server.doHit(id); + gui.setHitStatusFalse(); + + }else { + + } + } + if(!id.equals(server.whosTurn())){//player가 잘못누르는 경우... + boolean_DropBtnStatus=gui.returnDropBtnStatus(); + boolean_HitBtnStatus=gui.returnHitBtnStatus(); + if(boolean_DropBtnStatus){ + System.out.println("it's not your turn..please wait"); + gui.setGameInfo("it's not your turn..please wait"); + gui.setDropStatusFalse(); + } + if(boolean_HitBtnStatus){ + System.out.println("it's not your turn..please wait"); + gui.setGameInfo("it's not your turn..please wait"); + gui.setHitStatusFalse(); + } + } + } + +// gui.deactivatedHitDropBtn(); + + }catch(Exception e) {//디테일하게 예외 잡아 줘야 할 듯..예외처리 사이즈가 커 + e.printStackTrace(); + } + } + } + public void sendMsgToAll(String str) {//행동 취하고 나면 반드시 해당함수를 써서 메시지를 보내야한다. 그리고 바로 receiveMSG도 작동해야한다. + try { + server.sendMsg(str); + + }catch(Exception e) { + e.printStackTrace(); } } +// public String receiveMsg() { +// String msg=""; +// try { +// msg=server.receiveMsg(); +//// gui.setMsgView(msg+"\n"); +// +// }catch(Exception e) { +// e.printStackTrace(); +// +// } +// return msg; +// } public static void main(String[] args) { String mServer="127.0.0.1"; -// String mServer=args[0]; String mServName="WarGame"; - + System.out.println("Remote Method Invocate to "+mServer+", service name: "+mServName); - + try { + System.setProperty("javax.net.ssl.trustStore", "trustedcerts"); + System.setProperty("javax.net.ssl.trustStorePasssword", "123456"); String id; String pw; Scanner sc=new Scanner(System.in);//this is for temporary - System.out.println("enter id: "); + System.out.print("enter id: "); id=sc.nextLine(); - System.out.println("enter pw: "); + System.out.print("enter pw: "); pw=sc.nextLine(); + + + Registry registry = LocateRegistry.getRegistry( + InetAddress.getLocalHost().getHostName(), PORT, + new RMISSLClientSocketFactory()); - WarGame wg=(WarGame)Naming.lookup("rmi://"+mServer+":1099/"+mServName); - new Thread(new WarGameClient(wg,id,pw)).start(); - - }catch(MalformedURLException mue) { - System.out.println("MalformedURLException: "+mue); + WarGame c=(WarGame)registry.lookup("WarGame"/*"rmi://"+mServer+":1099/"+mServName*/); + new Thread(new WarGameClient(c,id,pw)).start(); + }catch(RemoteException re) { System.out.println("RemoteException: "+re); }catch(NotBoundException nbe) { System.out.println("NotBoundException: "+nbe); }catch(java.lang.ArithmeticException ae) { System.out.println("java.lang.ArithmeticException: "+ae); + } catch (UnknownHostException e) { + System.out.println("UnknownHostException: "+e); } } - + } + diff --git a/WarGameGUI.java b/WarGameGUI.java index a695d46..96a37e8 100644 --- a/WarGameGUI.java +++ b/WarGameGUI.java @@ -234,16 +234,24 @@ public void setPlayerList(String str) {//참가자 리스트를 보여줌 public void deactivateReadyBtn() { readyBtn.setEnabled(false); } + public void deactivatedHitDropBtn() { + hitBtn.setEnabled(false); + dropBtn.setEnabled(false); + } + public void activatedHitDropBtn() { + hitBtn.setEnabled(true); + dropBtn.setEnabled(true); + } + public void actionPerformed(ActionEvent ae) { try { if(ae.getSource()==dropBtn) { // System.out.println("drop"); boolean_DropBtn=true; - - } else if(ae.getSource()==hitBtn) { - System.out.println("hit"); + boolean_HitBtn=true; +// System.out.println("hit"); } // else if(ae.getSource()==tf_Send) { // String msg=tf_Send.getText(); diff --git a/WarGameImpl.java b/WarGameImpl.java index a3908fe..0544dd9 100644 --- a/WarGameImpl.java +++ b/WarGameImpl.java @@ -8,37 +8,48 @@ import java.util.Set; public class WarGameImpl extends UnicastRemoteObject implements WarGame { + + private static final int PORT = 2019; private static final long serializedversion=1L; private String clientID[]= {"aaa","bbb"}; private String clientPassword[]= {"1234","1234"}; - private ArrayList clientList; +// private ArrayList clientList; private Game game; private boolean turn=true; + private String msg; private ArrayList deck0,deck1,deck2; private int clientCnt=0; + //private HashMap clientStatus;//어떤 클라이언트의 순서인지 확인할 수 있다(이름,0)/(이름,1) -> 전자는 비활성화, 후자는 활성화 + private ArrayList client; private HashMap readyStatus; private boolean boolean_readyStatus[]; + private int attackCount=-1; + + private boolean isAttack = false; + private int dropCount = 0; + protected WarGameImpl() throws RemoteException{ super(); //clientList=new ArrayList(); + msg=""; game=new Game(); deck1=game.returnDeck1(); deck2=game.returnDeck2(); - deck0=null; + deck0=game.returnDeck0(); readyStatus=new HashMap(); - + client=new ArrayList(); + //clientStatus=new HashMap(); // boolean_readyStatus=new boolean[2]; // boolean_readyStatus[0]=false; // boolean_readyStatus[1]=false; //System.out.println(deck1);//test } - public synchronized boolean checkClientCredentials(WarGame wg,String id,String password) throws RemoteException{ + public synchronized boolean checkClientCredentials(WarGame wg,String id,String password) throws RemoteException{ //id, pw 확인 boolean checkLog=false; for(int i=0;i getClientList() throws RemoteException{ + return client; + } + @Override + public synchronized void sendMsg(String msg) throws RemoteException{ + this.msg=msg; + } + @Override + public synchronized String receiveMsg() throws RemoteException{ + return msg; + } + @Override + public int checkGameStatus() throws RemoteException {//drop을 해야할지 hit를 해야할지, 공격중인 상황인지 평시 상황인지 판단한담에 거기에 맞춰 int리턴 + // TODO Auto-generated method st + int loc = deck0.size(); + String value=deck0.get(loc-1).returnValue(); + System.out.println("Value: "+value); + if(value=="K")//공격카드의 값만큼 리턴 + return 3; + else if(value.equals("Q")) + return 2; + else if(value.equals("J")) + return 1; + else if(value.equals("A")) + return 3; + else if(value.equals("2")) { + System.out.println("2임"); + return 2; + } + else { + System.out.println("Value????: "+value); + return -1;//평시 상태 + } + } + public boolean checkEndingStatus() throws RemoteException{ //deck이 비면 끝남 if(deck1.isEmpty()==true || deck2.isEmpty()==true) return false;//game over else return true; } - public synchronized void setReadyStatus(String id,boolean status) throws RemoteException{ + public String whosTurn() throws RemoteException{ //누구의 턴인지 반환 + if(turn==true) + return client.get(0); + else + return client.get(1); + } + public void changeTurn() throws RemoteException{ + turn=!turn; + } + public synchronized void setReadyStatus(String id,boolean status) throws RemoteException{//플레이어 각각이 레디했는지 확인 int tmp=0; if(status==true) tmp=1; @@ -71,61 +125,173 @@ public synchronized void setReadyStatus(String id,boolean status) throws RemoteE readyStatus.put(id, tmp); else { readyStatus.put(id,tmp); + } } - public synchronized boolean checkAllReady() throws RemoteException{ + public synchronized boolean checkAllReady() throws RemoteException{//player 2명 전부 레디 했는지 확인 int cnt=0; Iterator> itr=readyStatus.entrySet().iterator(); Set>set=readyStatus.entrySet(); while(itr.hasNext()) { Map.Entrye=(Map.Entry)itr.next(); - if(e.getValue()==1) + if(e.getValue()==1) { cnt++; + } } - if(cnt==2) + if(cnt==2) { + client.addAll(readyStatus.keySet()); +// clientStatus.put(client.get(0),1); +// clientStatus.put(client.get(1),0); return true; + } + else return false; } - public synchronized void doDrop() throws RemoteException{ + public synchronized void doDrop(String id) throws RemoteException{ + Card c=null; if(turn==true) {//player 1's drop - c=deck1.get(0); - if(c==null) { - System.out.println("Player2 win!!"); - } - deck0.add(c); - + if(isAttack == false) { + System.out.println("player 1 drop!"); + if(deck1.size() == 0) { + System.out.println("Player2 win!!"); + return; + } + c=deck1.get(0); + pop(); //가져온 카드 1개 제거 + + deck0.add(c); + attackCount = checkGameStatus(); + if(attackCount == -1) { + turn = !turn; + } + else { + isAttack = true; + turn = !turn; + } + + System.out.println("뽑힌카드 : " +c); + } + else if(isAttack == true) { //공격 상태일 때 + System.out.println("player 1 drop! : Attack"); + if(deck1.size() == 0) { + System.out.println("Player2 win!!"); + return; + } + c=deck1.get(0); + pop(); //가져온 카드 1개 제거 + + deck0.add(c); + if(checkGameStatus() == -1) { //공격카드가 아닐 경우 + dropCount++; + System.out.println("AttackCount: "+attackCount+ ", DropCount: "+dropCount); + + if(dropCount == attackCount) { //낸 카드의 수가 조건을 넘어갔을 떄 + dropCount = 0; + isAttack = false; + for(int i = 0; i < deck0.size(); i++) { + deck2.add(deck0.get(i)); + } + deck0 = new ArrayList(); + System.out.println("aaa의 카드 수 : "+deck1.size()); + System.out.println("bbb의 카드 수 : "+deck2.size()); + System.out.println("깔려 있는 카드 수 :"+deck0.size()); + + } + } + else { + isAttack = true; + dropCount = 0; + attackCount = checkGameStatus(); + turn = !turn; + } + System.out.println("뽑힌카드 : " +c); + } + }else {//player 2's drop - c=deck2.get(0); - if(c==null) { - System.out.println("Player1 win!!"); + if(isAttack == false) { + System.out.println("player 2 drop!"); + if(deck2.size() == 0) { + System.out.println("Player1 win!!"); + return; + } + c=deck2.get(0); + pop(); //가져온 카드 1개 제거 + + deck0.add(c); + attackCount = checkGameStatus(); + if(attackCount == -1) { + turn = !turn; + } + else { + isAttack = true; + turn = !turn; + } + + System.out.println("뽑힌카드 : " +c); + } + else if(isAttack == true) { //공격 상태일 때 + System.out.println("player 2 drop! : Attack"); + if(deck2.size() == 0) { + System.out.println("Player1 win!!"); + return; + } + c=deck2.get(0); + pop(); + + deck0.add(c); + + if(checkGameStatus() == -1) { //공격카드가 아닐 경우 + dropCount++; + System.out.println("AttackCount: "+attackCount+ ", DropCount: "+dropCount); + if(dropCount == attackCount) { //낸 카드의 수가 조건을 넘어갔을 떄 + dropCount = 0; + isAttack = false; + for(int i = 0; i < deck0.size(); i++) { + deck1.add(deck0.get(i)); + } + deck0 = new ArrayList(); + System.out.println("aaa의 카드 수 : "+deck1.size()); + System.out.println("bbb의 카드 수 : "+deck2.size()); + System.out.println("깔려 있는 카드 수 :"+deck0.size()); + } + } + else { + isAttack = true; + dropCount = 0; + attackCount = checkGameStatus(); + turn = !turn; + } + System.out.println("뽑힌카드 : " +c); } - deck0.add(c); } } - public synchronized void doHit() throws RemoteException{ + public synchronized void doHit(String id) throws RemoteException{ + System.out.println("hit이 실행됨"); //플레이어 구분해서 해야하는데 아직 못함. Card []c=new Card[2]; - c[0]=deck0.get(0); - c[1]=deck0.get(1); - if(c[0].returnType()==c[1].returnType()) { - System.out.println("Hit Success!!"); - } - else + if(deck0.size() < 2) { System.out.println("Hit Fail..."); - - - } - public boolean changeTurn() { - return !turn; + } + else { + c[0]=deck0.get(0); + c[1]=deck0.get(1); + if(c[0].returnType()==c[1].returnType()) { + System.out.println("Hit Success!!"); + } + else + System.out.println("Hit Fail..."); + + } } + public void pop() { if(turn==true) { - + deck1.remove(0); }else { - + deck2.remove(0); } } public void push() { diff --git a/WarGameServer.java b/WarGameServer.java index f41b75e..ef777f3 100644 --- a/WarGameServer.java +++ b/WarGameServer.java @@ -4,97 +4,113 @@ import java.io.*; import java.rmi.Naming; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.rmi.server.UnicastRemoteObject; -public class WarGameServer { +public class WarGameServer extends UnicastRemoteObject { public int clientCnt=0; -// private WarGameServerRunnable client[]=new WarGameServerRunnable[2]; - public WarGameServer(String server,String servName) { - try { - WarGame wg=new WarGameImpl(); - Naming.rebind("rmi://"+server+":1099/"+servName, wg); - }catch(Exception e) { - System.out.println("Trouble: "+e); - } + private static final int PORT = 2019; + + public WarGameServer(String server,String servName) throws Exception{ + super(PORT, + new RMISSLClientSocketFactory(), + new RMISSLServerSocketFactory()); + } public static void main(String[] args) throws UnknownHostException { -// String mServer=InetAddress.getLocalHost().getHostName(); -// String mServer=args[0]; String mServer="127.0.0.1"; String mServName="WarGame"; System.out.println("started at"+mServer+"and use default port(1099). service name: "+mServName); - new WarGameServer(mServer,mServName); + + try { + + //SSL-based registry 생성 + Registry registry = LocateRegistry.createRegistry(PORT, new RMISSLClientSocketFactory(), new RMISSLServerSocketFactory()); + + //Create new impl object + WarGameImpl warGameImpl = new WarGameImpl(); + + registry.bind("WarGame", warGameImpl); + + System.out.println("WarGame bound in registry"); + + } catch (Exception e) { + System.out.println("WarGame Error : " + e.getMessage()); + e.printStackTrace(); + } } } -// public int whoClient(int clientID) { -// for (int i = 0; i < clientCnt; i++) -// if (client[i].getClientID() == clientID) -// return i; -// return -1; -// } -// public void putClient(int clientID, String inputLine) { -// for (int i = 0; i < clientCnt; i++) -// if (client[i].getClientID() == clientID) { -// System.out.println("writer: "+clientID); -// } else { -// System.out.println("write: "+client[i].getClientID()); -// client[i].out.println(inputLine); -// } -// } - //this is about chatting. so.. -// public void addClient(ServerSocket serverSocket) { -// Socket clientSocket = null; -// -// if (clientCnt < client.length) { -// try { -// clientSocket = serverSocket.accept(); -// clientSocket.setSoTimeout(40000); // 1000/sec -// } catch (IOException i) { -// System.out.println ("Accept() fail: "+i); -// } -// client[clientCnt] = new WarGameServerRunnable(this, clientSocket); -// new Thread(client[clientCnt]).start(); -// clientCnt++; -// System.out.println ("Client connected: " + clientSocket.getPort() -// +", CurrentClient: " + clientCnt); +//public int whoClient(int clientID) { +// for (int i = 0; i < clientCnt; i++) +// if (client[i].getClientID() == clientID) +// return i; +// return -1; +//} +//public void putClient(int clientID, String inputLine) { +// for (int i = 0; i < clientCnt; i++) +// if (client[i].getClientID() == clientID) { +// System.out.println("writer: "+clientID); // } else { -// try { -// Socket dummySocket = serverSocket.accept(); -// WarGameServerRunnable dummyRunnable = new WarGameServerRunnable(this, dummySocket); -// new Thread(dummyRunnable); -// dummyRunnable.out.println(dummySocket.getPort() -// + " < Sorry maximum user connected now"); -// System.out.println("Client refused: maximum connection " -// + client.length + " reached."); -// dummyRunnable.close(); -// } catch (IOException i) { -// System.out.println(i); -// } +// System.out.println("write: "+client[i].getClientID()); +// client[i].out.println(inputLine); // } +//} +//this is about chatting. so.. +//public void addClient(ServerSocket serverSocket) { +// Socket clientSocket = null; +// +// if (clientCnt < client.length) { +// try { +// clientSocket = serverSocket.accept(); +// clientSocket.setSoTimeout(40000); // 1000/sec +// } catch (IOException i) { +// System.out.println ("Accept() fail: "+i); +// } +// client[clientCnt] = new WarGameServerRunnable(this, clientSocket); +// new Thread(client[clientCnt]).start(); +// clientCnt++; +// System.out.println ("Client connected: " + clientSocket.getPort() +// +", CurrentClient: " + clientCnt); +// } else { +// try { +// Socket dummySocket = serverSocket.accept(); +// WarGameServerRunnable dummyRunnable = new WarGameServerRunnable(this, dummySocket); +// new Thread(dummyRunnable); +// dummyRunnable.out.println(dummySocket.getPort() +// + " < Sorry maximum user connected now"); +// System.out.println("Client refused: maximum connection " +// + client.length + " reached."); +// dummyRunnable.close(); +// } catch (IOException i) { +// System.out.println(i); +// } // } -// public synchronized void delClient(int clientID) { -// int pos = whoClient(clientID); -// WarGameServerRunnable endClient = null; -// if (pos >= 0) { -// endClient = client[pos]; -// if (pos < clientCnt-1) -// for (int i = pos+1; i < clientCnt; i++) -// client[i-1] = client[i]; -// clientCnt--; -// System.out.println("Client removed: " + clientID -// + " at client[" + pos +"], CurrentClient: " + clientCnt); -// endClient.close(); -// } +//} +//public synchronized void delClient(int clientID) { +// int pos = whoClient(clientID); +// WarGameServerRunnable endClient = null; +// if (pos >= 0) { +// endClient = client[pos]; +// if (pos < clientCnt-1) +// for (int i = pos+1; i < clientCnt; i++) +// client[i-1] = client[i]; +// clientCnt--; +// System.out.println("Client removed: " + clientID +// + " at client[" + pos +"], CurrentClient: " + clientCnt); +// endClient.close(); // } //} +//} //class WarGameServerRunnable implements Runnable{ // protected WarGameServer warGameServer=null; // protected Socket clientSocket=null; // protected PrintWriter out=null; // protected BufferedReader in=null; // public int clientID=-1; -// +// // Game game=new Game(); // ArrayList deck0=null;//내려놓는 곳 // ArrayList deck1;//p1 deck @@ -108,7 +124,7 @@ public static void main(String[] args) throws UnknownHostException { // clientID=clientSocket.getPort(); // try{ // out=new PrintWriter(clientSocket.getOutputStream(),true); -//// out=new BufferedWriter(clientSocket.getOutputStream()); +// // out=new BufferedWriter(clientSocket.getOutputStream()); // in=new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); // }catch(IOException ioe){} // } @@ -120,7 +136,7 @@ public static void main(String[] args) throws UnknownHostException { // if(in !=null) in.close(); // if(out !=null) out.close(); // if(clientSocket!=null)clientSocket.close(); -// +// // }catch(IOException i) { // i.printStackTrace(); // } @@ -135,6 +151,5 @@ public static void main(String[] args) throws UnknownHostException { // playerCardCnt[0]=deck1.size(); // playerCardCnt[1]=deck2.size(); // deck0Cnt=0; -// +// // } -