1
0
mirror of https://github.com/LOOHP/Limbo.git synced 2026-06-08 05:51:43 +00:00

Re-structure + Adventure

This commit is contained in:
LOOHP
2021-12-22 00:33:31 +00:00
parent 98cb6067e8
commit 2988e605b5
69 changed files with 639 additions and 297 deletions
@@ -0,0 +1,50 @@
package com.loohp.limbo.network;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import com.loohp.limbo.Limbo;
public class ServerConnection extends Thread {
private ServerSocket serverSocket;
private List<ClientConnection> clients;
private String ip;
private int port;
public ServerConnection(String ip, int port) {
clients = new ArrayList<ClientConnection>();
this.ip = ip;
this.port = port;
start();
}
@Override
public void run() {
try {
serverSocket = new ServerSocket(port, 50, InetAddress.getByName(ip));
Limbo.getInstance().getConsole().sendMessage("Limbo server listening on /" + serverSocket.getInetAddress().getHostName() + ":" + serverSocket.getLocalPort());
while (true) {
Socket connection = serverSocket.accept();
ClientConnection sc = new ClientConnection(connection);
clients.add(sc);
sc.start();
}
} catch(IOException e) {
e.printStackTrace();
}
}
public ServerSocket getServerSocket() {
return serverSocket;
}
public List<ClientConnection> getClients() {
return clients;
}
}