// Processed by NMI's Java Code Viewer 4.8.2 © 1997-2000 B. Lemaire // Website: http://njcv.htmlplanet.com E-mail: info@njcv.htmlplanet.com // Copy registered to Evaluation Copy // Source File Name: Receptionist.java import java.awt.Event; import java.io.*; import java.net.ServerSocket; import java.net.Socket; class Receptionist extends Thread { ClientHandler clientHandler; MultiServer target; ServerSocket serverSocket; Socket clientSocket; DataOutputStream os; DataInputStream is; int connectionStatus; boolean gameInProgress; Receptionist(MultiServer multiserver) { connectionStatus = -1; gameInProgress = false; target = multiserver; } public void run() { ChatArea.addText(">>> Server has started listening", 142); while(serverSocket == null) try { serverSocket = new ServerSocket(ServerData.port); } catch(IOException _ex) { ChatArea.addText(">>> Could not listen on port: " + ServerData.port, 141); closeReceptionist(); } do { clientSocket = null; os = null; is = null; try { clientSocket = serverSocket.accept(); } catch(IOException _ex) { closeReceptionist(); } try { os = new DataOutputStream(clientSocket.getOutputStream()); is = new DataInputStream(clientSocket.getInputStream()); } catch(IOException _ex) { } try { connectionStatus = is.readInt(); } catch(IOException _ex) { } switch(connectionStatus) { case 154: ServerData.clientsCurrentlyConnected++; if(gameInProgress) { try { os.writeInt(125); os.close(); clientSocket.close(); clientSocket = null; } catch(IOException _ex) { } ServerData.clientsCurrentlyConnected--; } else if(ServerData.clientsCurrentlyConnected > C.MAX_NUM_OF_PLAYERS) { try { os.writeInt(130); os.close(); clientSocket.close(); clientSocket = null; } catch(IOException _ex) { } ServerData.clientsCurrentlyConnected--; } if(!gameInProgress && ServerData.clientsCurrentlyConnected <= C.MAX_NUM_OF_PLAYERS) { try { os.writeInt(115); } catch(IOException _ex) { } for(int i = 0; i < C.MAX_NUM_OF_PLAYERS; i++) { if(ServerData.connected[i]) continue; clientHandler = new ClientHandler(target, clientSocket, os, is, i); clientHandler.setPriority(3); ServerData.tempClientHandler = clientHandler; target.handleEvent(new Event(this, 0L, 1001, 154, i, 0, 0, null)); break; } } break; case 180: closeConnections(); clientSocket = null; gameInProgress = true; target.handleEvent(new Event(this, 0L, 1001, 180, 0, 0, 0, null)); break; case 172: closeConnections(); gameInProgress = false; target.handleEvent(new Event(this, 0L, 1001, 172, 0, 0, 0, null)); break; case 190: target.handleEvent(new Event(this, 0L, 1001, 190, 0, 0, 0, null)); break; case 181: closeConnections(); target.handleEvent(new Event(this, 0L, 1001, 181, 0, 0, 0, null)); closeReceptionist(); break; } } while(true); } private void closeConnections() { try { is.close(); is = null; os.close(); os = null; clientSocket.close(); clientSocket = null; return; } catch(IOException _ex) { closeReceptionist(); } } private void closeReceptionist() { try { if(is != null) is.close(); if(os != null) os.close(); if(serverSocket != null) { serverSocket.close(); serverSocket = null; } if(clientSocket != null) { clientSocket.close(); clientSocket = null; } } catch(IOException _ex) { } stop(); } }