MCPcopy Create free account
hub / github.com/catabriga/graphwar / addClient

Method addClient

src/GraphServer/GraphServer.java:105–150  ·  view source on GitHub ↗
(Socket socket)

Source from the content-addressed store, hash-verified

103 }
104
105 public synchronized void addClient(Socket socket)
106 {
107 if(clients.size() < Constants.MAX_CLIENTS)
108 {
109 try
110 {
111 ClientConnection client = new ClientConnection(this, socket);
112
113 if(clients.size() == 0)
114 {
115 client.setLeader(true);
116 }
117
118 clients.add(client);
119 new Thread(client).start();
120
121 sendAllInfoMessage(client);
122
123 if(client.isLeader())
124 {
125 sendLeaderMessage(client);
126 }
127 }
128 catch (IOException e)
129 {
130 System.out.println("Adding new client failed.");
131 e.printStackTrace();
132 }
133 }
134 else
135 {
136 try
137 {
138 ClientConnection client = new ClientConnection(this, socket);
139
140 String message = NetworkProtocol.GAME_FULL+"";
141 client.sendMessage(message);
142
143 client.disconnect();
144 }
145 catch (IOException e)
146 {
147 e.printStackTrace();
148 }
149 }
150 }
151
152 public int getPort()
153 {

Callers 1

runMethod · 0.95

Calls 7

setLeaderMethod · 0.95
sendAllInfoMessageMethod · 0.95
isLeaderMethod · 0.95
sendLeaderMessageMethod · 0.95
sendMessageMethod · 0.95
disconnectMethod · 0.95
startMethod · 0.80

Tested by

no test coverage detected