mirror of https://github.com/LucaBongiorni/Ratty
Sogomn
9 years ago
4 changed files with 67 additions and 46 deletions
-
12Ratty/src/de/sogomn/rat/Ratty.java
-
49Ratty/src/de/sogomn/rat/server/ActiveServer.java
-
11Ratty/src/de/sogomn/rat/server/IServerObserver.java
-
41Ratty/src/de/sogomn/rat/server/ServerGuiController.java
@ -0,0 +1,11 @@ |
|||||
|
package de.sogomn.rat.server; |
||||
|
|
||||
|
import de.sogomn.rat.ActiveClient; |
||||
|
|
||||
|
public interface IServerObserver { |
||||
|
|
||||
|
void clientConnected(final ActiveServer server, final ActiveClient client); |
||||
|
|
||||
|
void closed(final ActiveServer server); |
||||
|
|
||||
|
} |
@ -0,0 +1,41 @@ |
|||||
|
package de.sogomn.rat.server; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
|
||||
|
import de.sogomn.rat.ActiveClient; |
||||
|
import de.sogomn.rat.IClientObserver; |
||||
|
import de.sogomn.rat.packet.IPacket; |
||||
|
|
||||
|
public final class ServerGuiController implements IServerObserver, IClientObserver { |
||||
|
|
||||
|
private ArrayList<ActiveClient> clients; |
||||
|
|
||||
|
public ServerGuiController() { |
||||
|
clients = new ArrayList<ActiveClient>(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void packetReceived(final ActiveClient client, final IPacket packet) { |
||||
|
packet.execute(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void disconnected(final ActiveClient client) { |
||||
|
client.setObserver(null); |
||||
|
client.close(); |
||||
|
clients.remove(client); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void clientConnected(final ActiveServer server, final ActiveClient client) { |
||||
|
client.setObserver(this); |
||||
|
clients.add(client); |
||||
|
client.start(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void closed(final ActiveServer server) { |
||||
|
System.out.println("Server closed"); |
||||
|
} |
||||
|
|
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue