This commit is contained in:
brausjonas
2023-01-29 00:25:54 +01:00
parent a6dd6752c1
commit da8ce4b425
19 changed files with 950 additions and 22 deletions
+1 -1
View File
@@ -75,7 +75,7 @@
<workItem from="1674897525328" duration="3823000" />
<workItem from="1674904474316" duration="988000" />
<workItem from="1674921351528" duration="2368000" />
<workItem from="1674945364389" duration="295000" />
<workItem from="1674945364389" duration="2872000" />
</task>
<servers />
</component>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4 -1
View File
@@ -8,11 +8,14 @@ public class Client
public DataInputStream input;
public Socket socket;
public String name;
public Client(DataOutputStream output, DataInputStream input, Socket socket)
public Client(DataOutputStream output, DataInputStream input, Socket socket, String name)
{
this.output = output;
this.input = input;
this.socket = socket;
this.name = name;
}
}
+24 -1
View File
@@ -2,6 +2,7 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
@@ -68,7 +69,7 @@ public class Room
players[i] = client;
playerCount++;
System.out.println("[" + Server.getDateTime() + "] Client joined room " + roomCode + " successfully as player " + i);
System.out.println("[" + Server.getDateTime() + "] " + client.name.replace(" ", "") + " joined room " + roomCode + " successfully as player " + i);
Thread t = new Thread(new Runnable()
{
@@ -179,6 +180,17 @@ public class Room
try
{
players[j].output.write(new byte[]{1, 1, (byte) startPositions[k].x, (byte) startPositions[k].y, (byte) startPositions[k].z, (byte) k, 0, 0, 0, 0});
byte[] name = players[k].name.substring(0, 8).getBytes(StandardCharsets.US_ASCII);
byte[] send = new byte[10];
send[0] = 5;
send[1] = (byte)k;
for(int i = 2; i < send.length; i++)
{
send[i] = name[i - 2];
}
players[j].output.write(send);
} catch (IOException e)
{
e.printStackTrace();
@@ -188,6 +200,17 @@ public class Room
try
{
players[j].output.write(new byte[]{1, 0, (byte) startPositions[k].x, (byte) startPositions[k].y, (byte) startPositions[k].z, (byte) k, 0, 0, 0, 0});
byte[] name = players[k].name.substring(0, 8).getBytes(StandardCharsets.US_ASCII);
byte[] send = new byte[10];
send[0] = 5;
send[1] = (byte)k;
for(int i = 2; i < send.length; i++)
{
send[i] = name[i - 2];
}
players[j].output.write(send);
} catch (IOException e)
{
e.printStackTrace();
+6 -1
View File
@@ -78,9 +78,14 @@ public class Server
String roomCode = new String(readData, StandardCharsets.US_ASCII);
input.read(readData);
String name = new String(readData, StandardCharsets.US_ASCII);
name = name.replace("?", " ");
if(rooms.containsKey(roomCode))
{
Client client1 = new Client(output, input, client);
Client client1 = new Client(output, input, client, name);
rooms.get(roomCode).addClient(client1);
}