Delete Server directory
This commit is contained in:
Generated
-8
@@ -1,8 +0,0 @@
|
|||||||
<component name="ArtifactManager">
|
|
||||||
<artifact type="jar" name="Server:jar">
|
|
||||||
<output-path>$PROJECT_DIR$/out/artifacts/Server_jar</output-path>
|
|
||||||
<root id="archive" name="Server.jar">
|
|
||||||
<element id="module-output" name="Server" />
|
|
||||||
</root>
|
|
||||||
</artifact>
|
|
||||||
</component>
|
|
||||||
Generated
-6
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="corretto-1.8" project-jdk-type="JavaSDK">
|
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
Generated
-8
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/Server.iml" filepath="$PROJECT_DIR$/Server.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
Generated
-6
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
Generated
-110
@@ -1,110 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ArtifactsWorkspaceSettings">
|
|
||||||
<artifacts-to-build>
|
|
||||||
<artifact name="Server:jar" />
|
|
||||||
</artifacts-to-build>
|
|
||||||
</component>
|
|
||||||
<component name="AutoImportSettings">
|
|
||||||
<option name="autoReloadType" value="SELECTIVE" />
|
|
||||||
</component>
|
|
||||||
<component name="ChangeListManager">
|
|
||||||
<list default="true" id="6d89163f-4054-4765-8ee3-ac6da16b6997" name="Changes" comment="" />
|
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
||||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
||||||
</component>
|
|
||||||
<component name="FileTemplateManagerImpl">
|
|
||||||
<option name="RECENT_TEMPLATES">
|
|
||||||
<list>
|
|
||||||
<option value="Class" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
<component name="Git.Settings">
|
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
|
|
||||||
</component>
|
|
||||||
<component name="MarkdownSettingsMigration">
|
|
||||||
<option name="stateVersion" value="1" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectId" id="2KuyzwPxozzNerRoAmXTliGxiKN" />
|
|
||||||
<component name="ProjectViewState">
|
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
|
||||||
<option name="showLibraryContents" value="true" />
|
|
||||||
</component>
|
|
||||||
<component name="PropertiesComponent">{
|
|
||||||
"keyToString": {
|
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
|
||||||
"WebServerToolWindowFactoryState": "false",
|
|
||||||
"last_opened_file_path": "C:/flufflparty/Server",
|
|
||||||
"node.js.detected.package.eslint": "true",
|
|
||||||
"node.js.detected.package.tslint": "true",
|
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
|
||||||
"project.structure.last.edited": "Artifacts",
|
|
||||||
"project.structure.proportion": "0.0",
|
|
||||||
"project.structure.side.proportion": "0.2",
|
|
||||||
"vue.rearranger.settings.migration": "true"
|
|
||||||
}
|
|
||||||
}</component>
|
|
||||||
<component name="RunManager">
|
|
||||||
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
|
||||||
<option name="MAIN_CLASS_NAME" value="Main" />
|
|
||||||
<module name="Server" />
|
|
||||||
<method v="2">
|
|
||||||
<option name="Make" enabled="true" />
|
|
||||||
</method>
|
|
||||||
</configuration>
|
|
||||||
<recent_temporary>
|
|
||||||
<list>
|
|
||||||
<item itemvalue="Application.Main" />
|
|
||||||
</list>
|
|
||||||
</recent_temporary>
|
|
||||||
</component>
|
|
||||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
|
||||||
<component name="TaskManager">
|
|
||||||
<task active="true" id="Default" summary="Default task">
|
|
||||||
<changelist id="6d89163f-4054-4765-8ee3-ac6da16b6997" name="Changes" comment="" />
|
|
||||||
<created>1674839030210</created>
|
|
||||||
<option name="number" value="Default" />
|
|
||||||
<option name="presentableId" value="Default" />
|
|
||||||
<updated>1674839030210</updated>
|
|
||||||
<workItem from="1674839031467" duration="221000" />
|
|
||||||
<workItem from="1674839402490" duration="20380000" />
|
|
||||||
<workItem from="1674897525328" duration="3823000" />
|
|
||||||
<workItem from="1674904474316" duration="988000" />
|
|
||||||
<workItem from="1674921351528" duration="2368000" />
|
|
||||||
<workItem from="1674945364389" duration="7759000" />
|
|
||||||
<workItem from="1675011672827" duration="777000" />
|
|
||||||
<workItem from="1675111963945" duration="610000" />
|
|
||||||
<workItem from="1675193290788" duration="3495000" />
|
|
||||||
<workItem from="1675279163903" duration="1346000" />
|
|
||||||
<workItem from="1675375598032" duration="1379000" />
|
|
||||||
<workItem from="1675545849238" duration="11000" />
|
|
||||||
<workItem from="1675628256814" duration="1286000" />
|
|
||||||
<workItem from="1675795807134" duration="411000" />
|
|
||||||
<workItem from="1676926021732" duration="612000" />
|
|
||||||
<workItem from="1677445028345" duration="816000" />
|
|
||||||
<workItem from="1677520608630" duration="13000" />
|
|
||||||
<workItem from="1677789901008" duration="661000" />
|
|
||||||
<workItem from="1677881295823" duration="3489000" />
|
|
||||||
</task>
|
|
||||||
<servers />
|
|
||||||
</component>
|
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
|
||||||
<option name="version" value="3" />
|
|
||||||
</component>
|
|
||||||
<component name="Vcs.Log.Tabs.Properties">
|
|
||||||
<option name="TAB_STATES">
|
|
||||||
<map>
|
|
||||||
<entry key="MAIN">
|
|
||||||
<value>
|
|
||||||
<State />
|
|
||||||
</value>
|
|
||||||
</entry>
|
|
||||||
</map>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
Binary file not shown.
Binary file not shown.
@@ -1,3 +0,0 @@
|
|||||||
Manifest-Version: 1.0
|
|
||||||
Main-Class: Main
|
|
||||||
|
|
||||||
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.
@@ -1,23 +0,0 @@
|
|||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.net.Socket;
|
|
||||||
|
|
||||||
public class Client
|
|
||||||
{
|
|
||||||
public DataOutputStream output;
|
|
||||||
public DataInputStream input;
|
|
||||||
public Socket socket;
|
|
||||||
|
|
||||||
public String name;
|
|
||||||
|
|
||||||
public long lastTimeSendTimeOutCheck = -1;
|
|
||||||
|
|
||||||
|
|
||||||
public Client(DataOutputStream output, DataInputStream input, Socket socket, String name)
|
|
||||||
{
|
|
||||||
this.output = output;
|
|
||||||
this.input = input;
|
|
||||||
this.socket = socket;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Manifest-Version: 1.0
|
|
||||||
Main-Class: Main
|
|
||||||
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
public class Main
|
|
||||||
{
|
|
||||||
public static void main(String[] args)
|
|
||||||
{
|
|
||||||
new Server().start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,368 +0,0 @@
|
|||||||
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;
|
|
||||||
import java.util.TimerTask;
|
|
||||||
|
|
||||||
public class Room
|
|
||||||
{
|
|
||||||
private Client[] players = new Client[2];
|
|
||||||
private Vector3[] startPositions;
|
|
||||||
private String roomCode;
|
|
||||||
private Server server;
|
|
||||||
|
|
||||||
private List<Thread> threads = new ArrayList<>();
|
|
||||||
|
|
||||||
private int playerCount = 0;
|
|
||||||
|
|
||||||
private int currentPlayer = 0;
|
|
||||||
|
|
||||||
private long timeOut = 0;
|
|
||||||
private Timer t;
|
|
||||||
|
|
||||||
public Room(String roomCode, Server server)
|
|
||||||
{
|
|
||||||
timeOut = System.currentTimeMillis();
|
|
||||||
|
|
||||||
this.roomCode = roomCode;
|
|
||||||
startPositions = new Vector3[4];
|
|
||||||
|
|
||||||
startPositions[0] = new Vector3(96, 1, 126);
|
|
||||||
startPositions[1] = new Vector3(92, 1, 126);
|
|
||||||
startPositions[2] = new Vector3(96, 1, 128);
|
|
||||||
startPositions[3] = new Vector3(92, 1, 128);
|
|
||||||
|
|
||||||
this.server = server;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
t = new Timer();
|
|
||||||
TimerTask tt = new TimerTask()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
for (int p = 0; p < players.length; p++)
|
|
||||||
{
|
|
||||||
if (players[p] != null)
|
|
||||||
{
|
|
||||||
if (System.currentTimeMillis() - players[p].lastTimeSendTimeOutCheck > 30000 && players[p].lastTimeSendTimeOutCheck != -1)
|
|
||||||
{
|
|
||||||
server.deleteRoom(roomCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
players[p].output.write(new byte[]{126, 0, 0, 0, 0, 0, 0, 0, 0, 0});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (System.currentTimeMillis() - timeOut > 600000)
|
|
||||||
{
|
|
||||||
System.out.println("[" + Server.getDateTime() + "] Room " + roomCode + " closed due to timeout!");
|
|
||||||
server.deleteRoom(roomCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
t.scheduleAtFixedRate(tt, 0, 10000);
|
|
||||||
} catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addClient(Client client)
|
|
||||||
{
|
|
||||||
timeOut = System.currentTimeMillis();
|
|
||||||
|
|
||||||
for (int i = 0; i < players.length; i++)
|
|
||||||
{
|
|
||||||
if (players[i] == null)
|
|
||||||
{
|
|
||||||
players[i] = client;
|
|
||||||
playerCount++;
|
|
||||||
|
|
||||||
System.out.println("[" + Server.getDateTime() + "] " + client.name.replace(" ", "") + " joined room " + roomCode + " successfully as player " + i);
|
|
||||||
|
|
||||||
Thread t = new Thread(new Runnable()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
int player = playerCount - 1;
|
|
||||||
|
|
||||||
DataInputStream input = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
input = new DataInputStream(players[player].socket.getInputStream());
|
|
||||||
} catch (IOException e)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
byte[] readData = new byte[10];
|
|
||||||
|
|
||||||
input.read(readData);
|
|
||||||
|
|
||||||
timeOut = System.currentTimeMillis();
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
----------------------------------------
|
|
||||||
----------------------------------------
|
|
||||||
----------------------------------------
|
|
||||||
HERE IS THE ROOM / GAME LOGIC
|
|
||||||
----------------------------------------
|
|
||||||
----------------------------------------
|
|
||||||
----------------------------------------
|
|
||||||
*/
|
|
||||||
switch (readData[0])
|
|
||||||
{
|
|
||||||
|
|
||||||
//spieler hat gewürfelt
|
|
||||||
//1 x, x = zahl
|
|
||||||
case 3:
|
|
||||||
for (int i = 0; i < players.length; i++)
|
|
||||||
{
|
|
||||||
if (i != player)
|
|
||||||
{
|
|
||||||
players[i].output.write(new byte[]{3, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//pfeil wurde ausgewählt
|
|
||||||
//1 x, x = idx
|
|
||||||
case 4:
|
|
||||||
for (int i = 0; i < players.length; i++)
|
|
||||||
{
|
|
||||||
if (i != player)
|
|
||||||
{
|
|
||||||
players[i].output.write(new byte[]{4, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
//Spieler ist fertig mit seinem Zug
|
|
||||||
//1 x, x = next player
|
|
||||||
case 5:
|
|
||||||
currentPlayer++;
|
|
||||||
if (currentPlayer >= players.length)
|
|
||||||
{
|
|
||||||
currentPlayer = 0;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < players.length; i++)
|
|
||||||
{
|
|
||||||
players[i].output.write(new byte[]{2, (byte) currentPlayer, 0, 0, 0, 0, 0, 0, 0, 0});
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
//Es wurde auf ein CoinField getreten (Rot oder Blau)
|
|
||||||
//1 x, x = player; 2 y, y = Loose or Get
|
|
||||||
case 6:
|
|
||||||
for (int i = 0; i < players.length; i++)
|
|
||||||
{
|
|
||||||
if (i != player)
|
|
||||||
{
|
|
||||||
players[i].output.write(new byte[]{6, (byte)player, readData[1], 0, 0, 0, 0, 0, 0, 0});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
//Eventstop (ItemShop, BuyStar, ...) ist fertig
|
|
||||||
//1 x, x = player
|
|
||||||
case 7:
|
|
||||||
for (int i = 0; i < players.length; i++)
|
|
||||||
{
|
|
||||||
players[i].output.write(new byte[]{7, (byte)player, 0, 0, 0, 0, 0, 0, 0, 0});
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
//Spieler hat einen Stern gekauft
|
|
||||||
case 8:
|
|
||||||
for (int i = 0; i < players.length; i++)
|
|
||||||
{
|
|
||||||
if (i != player)
|
|
||||||
{
|
|
||||||
players[i].output.write(new byte[]{8, (byte)player, 0, 0, 0, 0, 0, 0, 0, 0});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
//Spieler hat ein Item Gekauft
|
|
||||||
//1 x, x = player; 2 y, y = Item.Type (byte)
|
|
||||||
case 9:
|
|
||||||
for (int i = 0; i < players.length; i++)
|
|
||||||
{
|
|
||||||
if (i != player)
|
|
||||||
{
|
|
||||||
players[i].output.write(new byte[]{9, (byte)player, readData[1], 0, 0, 0, 0, 0, 0, 0});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 126:
|
|
||||||
players[player].lastTimeSendTimeOutCheck = System.currentTimeMillis();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (IOException e)
|
|
||||||
{
|
|
||||||
server.deleteRoom(roomCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
t.setName("Thread Player: " + (playerCount - 1));
|
|
||||||
t.start();
|
|
||||||
threads.add(t);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Make clients add all players to the world
|
|
||||||
if (playerCount == players.length)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < players.length; j++)
|
|
||||||
{
|
|
||||||
for (int k = 0; k < players.length; k++)
|
|
||||||
{
|
|
||||||
//0 1 create new player
|
|
||||||
//1 0 no playable player
|
|
||||||
//1 1 playable character
|
|
||||||
//2-3-4 default pos
|
|
||||||
//5 player index
|
|
||||||
if (j == k)
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//0 2, activate a player
|
|
||||||
//1 x, x = idx
|
|
||||||
try
|
|
||||||
{
|
|
||||||
for (Client c : players)
|
|
||||||
{
|
|
||||||
c.output.write(new byte[]{2, 0, 0, 0, 0, 0, 0, 0, 0, 0});
|
|
||||||
}
|
|
||||||
} catch (IOException e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void closeRoom()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
|
|
||||||
if (players[0] != null)
|
|
||||||
{
|
|
||||||
players[0].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0});
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception ex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (players[1] != null)
|
|
||||||
{
|
|
||||||
players[1].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0});
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception ex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (players[2] != null)
|
|
||||||
{
|
|
||||||
players[2].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0});
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception ex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (players[3] != null)
|
|
||||||
{
|
|
||||||
players[3].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0});
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception ex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < threads.size(); i++)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
threads.get(i).interrupt();
|
|
||||||
} catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
t.cancel();
|
|
||||||
} catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,145 +0,0 @@
|
|||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.ServerSocket;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class Server
|
|
||||||
{
|
|
||||||
private ServerSocket serverSocket;
|
|
||||||
private HashMap<String, Room> rooms = new HashMap<>();
|
|
||||||
|
|
||||||
//hier ArrayList für public rooms
|
|
||||||
|
|
||||||
private final Server server = this;
|
|
||||||
|
|
||||||
private static DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
|
|
||||||
|
|
||||||
public static String getDateTime()
|
|
||||||
{
|
|
||||||
return dtf.format(LocalDateTime.now());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteRoom(String code)
|
|
||||||
{
|
|
||||||
rooms.get(code).closeRoom();
|
|
||||||
rooms.remove(code);
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println("[" + getDateTime() + "] Room" + code + " successfully deleted");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start()
|
|
||||||
{
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
serverSocket = new ServerSocket(8051);
|
|
||||||
|
|
||||||
System.out.println("[" + getDateTime() + "] Server started! IP 185.245.96.48 PORT 8051");
|
|
||||||
|
|
||||||
while(true)
|
|
||||||
{
|
|
||||||
Socket tempClient = serverSocket.accept();
|
|
||||||
|
|
||||||
System.out.println("[" + getDateTime() + "] Client with IP " + tempClient.getInetAddress().getHostName() + " connected!");
|
|
||||||
|
|
||||||
new Thread(new Runnable()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
Socket client = tempClient;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
DataInputStream input = new DataInputStream(client.getInputStream());
|
|
||||||
DataOutputStream output = new DataOutputStream(client.getOutputStream());
|
|
||||||
byte[] readData = new byte[10];
|
|
||||||
|
|
||||||
input.read(readData);
|
|
||||||
|
|
||||||
switch(readData[0])
|
|
||||||
{
|
|
||||||
//hier case 3 für public match making
|
|
||||||
//dsfjlksdfjlöasdfjlsdkjflksdjflksdjflksdjflksdjflksdjflksdjflkjsdlkfjsdlkfsdjlkfsdlkfjsdlkfjsdlkfjlsdkfjlsdkjfldksjfjlk
|
|
||||||
//fsjfklsdjflksdjflsdjflksdjflksdfjlksdjflksdjflksdjflksdjflksdjflksdjflksdjflksdjflksdjflsdkjflksdjflksdjflksdjflksdjf
|
|
||||||
|
|
||||||
//schleife um zu checken ob ein offener room existiert (Liste)
|
|
||||||
//ansonsten einen neuen room erstellen und zur liste inhzufügen
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
byte[] code = generateRoomCode();
|
|
||||||
output.write(code);
|
|
||||||
|
|
||||||
Room room = new Room(new String(code, StandardCharsets.US_ASCII), server);
|
|
||||||
rooms.put(new String(code, StandardCharsets.US_ASCII), room);
|
|
||||||
|
|
||||||
System.out.println("[" + getDateTime() + "] Room " + new String(code, StandardCharsets.US_ASCII) + " successfully created!");
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
|
|
||||||
input.read(readData);
|
|
||||||
|
|
||||||
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, name);
|
|
||||||
|
|
||||||
rooms.get(roomCode).addClient(client1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0});
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e){}
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] generateRoomCode()
|
|
||||||
{
|
|
||||||
byte[] code = new byte[10];
|
|
||||||
|
|
||||||
for(int i = 0; i < code.length; i++)
|
|
||||||
{
|
|
||||||
if(i < code.length / 2)
|
|
||||||
{
|
|
||||||
code[i] = (byte)(Math.random() * 8 + 49);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
code[i] = (byte)(Math.random() * 25 + 97);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String roomCode = new String(code, StandardCharsets.US_ASCII);
|
|
||||||
|
|
||||||
//avoide double codes (just in case^^)
|
|
||||||
if(rooms.containsKey(roomCode))
|
|
||||||
{
|
|
||||||
code = generateRoomCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
public class Vector3
|
|
||||||
{
|
|
||||||
public float x, y, z;
|
|
||||||
|
|
||||||
public Vector3(float x, float y, float z)
|
|
||||||
{
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector3 zero()
|
|
||||||
{
|
|
||||||
return new Vector3(0, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user