Get networking working on basic level
This commit is contained in:
parent
5cc0998b26
commit
d4513b84a4
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"java.configuration.updateBuildConfiguration": "automatic",
|
"java.configuration.updateBuildConfiguration": "automatic",
|
||||||
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx4G -Xms100m"
|
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx8G -Xms100m"
|
||||||
}
|
}
|
||||||
@ -151,10 +151,10 @@ public class LoadingThread extends Thread {
|
|||||||
LoggerInterface.loggerEngine.INFO("run server: " + Globals.RUN_SERVER + " run client: " + Globals.RUN_CLIENT);
|
LoggerInterface.loggerEngine.INFO("run server: " + Globals.RUN_SERVER + " run client: " + Globals.RUN_CLIENT);
|
||||||
|
|
||||||
//init the data of the world
|
//init the data of the world
|
||||||
// if(Globals.RUN_SERVER){
|
if(Globals.RUN_SERVER){
|
||||||
// initServerGameWorldData();
|
// initServerGameWorldData();
|
||||||
// initDataCellManager();
|
initDataCellManager();
|
||||||
// }
|
}
|
||||||
|
|
||||||
//initialize the server thread (server only)
|
//initialize the server thread (server only)
|
||||||
if(Globals.RUN_SERVER){
|
if(Globals.RUN_SERVER){
|
||||||
@ -243,7 +243,9 @@ public class LoadingThread extends Thread {
|
|||||||
initServerArenaWorldData();
|
initServerArenaWorldData();
|
||||||
|
|
||||||
//init data cell manager
|
//init data cell manager
|
||||||
initDataCellManager();
|
if(Globals.RUN_SERVER){
|
||||||
|
initDataCellManager();
|
||||||
|
}
|
||||||
|
|
||||||
//initialize the server thread (server only)
|
//initialize the server thread (server only)
|
||||||
if(Globals.RUN_SERVER){
|
if(Globals.RUN_SERVER){
|
||||||
|
|||||||
@ -39,6 +39,7 @@ import electrosphere.game.data.creature.type.rotator.RotatorItem;
|
|||||||
import electrosphere.game.data.creature.type.rotator.RotatorSystem;
|
import electrosphere.game.data.creature.type.rotator.RotatorSystem;
|
||||||
import electrosphere.game.data.creature.type.visualattribute.AttributeVariant;
|
import electrosphere.game.data.creature.type.visualattribute.AttributeVariant;
|
||||||
import electrosphere.game.data.creature.type.visualattribute.VisualAttribute;
|
import electrosphere.game.data.creature.type.visualattribute.VisualAttribute;
|
||||||
|
import electrosphere.game.server.datacell.ServerDataCell;
|
||||||
import electrosphere.logger.LoggerInterface;
|
import electrosphere.logger.LoggerInterface;
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
import electrosphere.main.Main;
|
import electrosphere.main.Main;
|
||||||
@ -424,6 +425,32 @@ public class CreatureUtils {
|
|||||||
public static SprintTree getSprintTree(Entity e){
|
public static SprintTree getSprintTree(Entity e){
|
||||||
return (SprintTree)e.getData(EntityDataStrings.SPRINT_TREE);
|
return (SprintTree)e.getData(EntityDataStrings.SPRINT_TREE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void repositionCreature(Entity creature, Vector3d position){
|
||||||
|
//if server, get current server data cell
|
||||||
|
if(Globals.RUN_SERVER){
|
||||||
|
ServerDataCell oldDataCell = Globals.dataCellManager.getDataCellAtPoint(EntityUtils.getPosition(creature));
|
||||||
|
ServerDataCell newDataCell = Globals.dataCellManager.getDataCellAtPoint(position);
|
||||||
|
if(newDataCell != null){
|
||||||
|
newDataCell.addEntity(creature);
|
||||||
|
if(oldDataCell != null && oldDataCell != newDataCell){
|
||||||
|
oldDataCell.removeEntity(creature);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//if it doesn't already exist, try creating it and if successfull move creature
|
||||||
|
newDataCell = Globals.dataCellManager.tryCreateGroundDataCell(EntityUtils.getPosition(creature));
|
||||||
|
if(newDataCell != null){
|
||||||
|
newDataCell.addEntity(creature);
|
||||||
|
if(oldDataCell != null && oldDataCell != newDataCell){
|
||||||
|
oldDataCell.removeEntity(creature);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//reposition entity
|
||||||
|
CollisionObjUtils.positionCharacter(creature, new Vector3f(Globals.spawnPoint.x,Globals.spawnPoint.y,Globals.spawnPoint.z));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -148,5 +148,38 @@ public class DataCellManager {
|
|||||||
public void unloadPlayerlessChunks(){
|
public void unloadPlayerlessChunks(){
|
||||||
//TODO: implement and actually call it
|
//TODO: implement and actually call it
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ServerDataCell getDataCellAtPoint(Vector3d point){
|
||||||
|
ServerDataCell rVal = null;
|
||||||
|
int worldX = Globals.serverWorldData.convertRealToChunkSpace(point.x);
|
||||||
|
int worldZ = Globals.serverWorldData.convertRealToChunkSpace(point.z);
|
||||||
|
if(
|
||||||
|
//in bounds of array
|
||||||
|
worldX >= 0 && worldX < groundDataCells.length &&
|
||||||
|
worldZ >= 0 && worldZ < groundDataCells[0].length &&
|
||||||
|
//isn't null
|
||||||
|
groundDataCells[worldX][worldZ] != null
|
||||||
|
){
|
||||||
|
rVal = groundDataCells[worldX][worldZ];
|
||||||
|
}
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerDataCell tryCreateGroundDataCell(Vector3d point){
|
||||||
|
int worldX = Globals.serverWorldData.convertRealToChunkSpace(point.x);
|
||||||
|
int worldZ = Globals.serverWorldData.convertRealToChunkSpace(point.z);
|
||||||
|
if(
|
||||||
|
//in bounds of array
|
||||||
|
worldX >= 0 && worldX < groundDataCells.length &&
|
||||||
|
worldZ >= 0 && worldZ < groundDataCells[0].length &&
|
||||||
|
//isn't null
|
||||||
|
groundDataCells[worldX][worldZ] == null
|
||||||
|
){
|
||||||
|
groundDataCells[worldX][worldZ] = new ServerDataCell();
|
||||||
|
}
|
||||||
|
return groundDataCells[worldX][worldZ];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -80,8 +80,9 @@ public class ServerDataCell {
|
|||||||
* @param character
|
* @param character
|
||||||
*/
|
*/
|
||||||
public void addCharacter(Character character){
|
public void addCharacter(Character character){
|
||||||
Entity newEntity = new Entity();
|
// Entity newEntity = new Entity();
|
||||||
loadedEntities.add(newEntity);
|
// loadedEntities.add(newEntity);
|
||||||
|
throw new UnsupportedOperationException("Not implemented yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,7 +102,6 @@ public class ServerDataCell {
|
|||||||
*/
|
*/
|
||||||
public void removeEntity(Entity e){
|
public void removeEntity(Entity e){
|
||||||
loadedEntities.remove(e);
|
loadedEntities.remove(e);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -142,6 +142,10 @@ public class ServerConnectionHandler implements Runnable {
|
|||||||
public int getPlayerCharacterId(){
|
public int getPlayerCharacterId(){
|
||||||
return playerCharacterID;
|
return playerCharacterID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getIPAddress(){
|
||||||
|
return socket.getRemoteSocketAddress().toString();
|
||||||
|
}
|
||||||
|
|
||||||
public void addMessagetoOutgoingQueue(NetworkMessage message){
|
public void addMessagetoOutgoingQueue(NetworkMessage message){
|
||||||
switch(message.getType()){
|
switch(message.getType()){
|
||||||
|
|||||||
@ -28,6 +28,7 @@ public class Player {
|
|||||||
id = idIncrementer;
|
id = idIncrementer;
|
||||||
idIncrementer++;
|
idIncrementer++;
|
||||||
idIncrementerLock.release();
|
idIncrementerLock.release();
|
||||||
|
connectionHandler.setPlayerId(id);
|
||||||
this.simulationRadius = Globals.userSettings.getGameplayPhysicsCellRadius();
|
this.simulationRadius = Globals.userSettings.getGameplayPhysicsCellRadius();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,9 @@ package electrosphere.net.server.protocol;
|
|||||||
|
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
import electrosphere.net.parser.net.message.AuthMessage;
|
import electrosphere.net.parser.net.message.AuthMessage;
|
||||||
|
import electrosphere.net.parser.net.message.PlayerMessage;
|
||||||
import electrosphere.net.server.ServerConnectionHandler;
|
import electrosphere.net.server.ServerConnectionHandler;
|
||||||
|
import electrosphere.net.server.player.Player;
|
||||||
|
|
||||||
public class AuthProtocol {
|
public class AuthProtocol {
|
||||||
|
|
||||||
@ -14,6 +16,12 @@ public class AuthProtocol {
|
|||||||
if(successfulLogin){
|
if(successfulLogin){
|
||||||
//TODO: actually set connection/protocol to authenticated
|
//TODO: actually set connection/protocol to authenticated
|
||||||
connectionHandler.addMessagetoOutgoingQueue(AuthMessage.constructAuthSuccessMessage());
|
connectionHandler.addMessagetoOutgoingQueue(AuthMessage.constructAuthSuccessMessage());
|
||||||
|
Player newPlayer = new Player(connectionHandler);
|
||||||
|
Globals.playerManager.registerPlayer(newPlayer);
|
||||||
|
if(connectionHandler.getIPAddress().contains("127.0.0.1")){
|
||||||
|
Globals.serverPlayer = newPlayer;
|
||||||
|
}
|
||||||
|
connectionHandler.addMessagetoOutgoingQueue(PlayerMessage.constructSet_IDMessage(connectionHandler.getPlayerId()));
|
||||||
} else {
|
} else {
|
||||||
connectionHandler.addMessagetoOutgoingQueue(AuthMessage.constructAuthFailureMessage());
|
connectionHandler.addMessagetoOutgoingQueue(AuthMessage.constructAuthFailureMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package electrosphere.net.server.protocol;
|
package electrosphere.net.server.protocol;
|
||||||
|
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
import electrosphere.entity.Entity;
|
import electrosphere.entity.Entity;
|
||||||
@ -40,41 +41,39 @@ public class CharacterProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void spawnPlayerCharacter(ServerConnectionHandler connectionHandler){
|
static void spawnPlayerCharacter(ServerConnectionHandler connectionHandler){
|
||||||
Player newPlayerObject = new Player(connectionHandler);
|
Player playerObject = Globals.playerManager.getPlayerFromId(connectionHandler.getPlayerId());
|
||||||
Globals.playerManager.registerPlayer(newPlayerObject);
|
|
||||||
//spawn player in world
|
//spawn player in world
|
||||||
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature("human");
|
Entity newPlayerEntity = CreatureUtils.spawnBasicCreature("human");
|
||||||
int playerCharacterId = newPlayerCharacter.getId();
|
int playerCharacterId = newPlayerEntity.getId();
|
||||||
connectionHandler.setPlayerCharacterId(playerCharacterId);
|
connectionHandler.setPlayerCharacterId(playerCharacterId);
|
||||||
CollisionObjUtils.positionCharacter(newPlayerCharacter, new Vector3f(Globals.spawnPoint.x,Globals.spawnPoint.y,Globals.spawnPoint.z));
|
CreatureUtils.repositionCreature(newPlayerEntity, new Vector3d(Globals.spawnPoint.x,Globals.spawnPoint.y,Globals.spawnPoint.z));
|
||||||
|
CreatureUtils.setControllerPlayerId(newPlayerEntity, connectionHandler.getPlayerId());
|
||||||
//attach player object to player character
|
//attach player object to player character
|
||||||
newPlayerObject.setPlayerEntity(newPlayerCharacter);
|
playerObject.setPlayerEntity(newPlayerEntity);
|
||||||
newPlayerObject.setWorldX(Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.x));
|
playerObject.setWorldX(Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.x));
|
||||||
newPlayerObject.setWorldY(Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.z));
|
playerObject.setWorldY(Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.z));
|
||||||
// System.out.println(EntityUtils.getRotation(newPlayerCharacter).set(0,1,0,1).normalize());
|
// System.out.println(EntityUtils.getRotation(newPlayerCharacter).set(0,1,0,1).normalize());
|
||||||
Globals.dataCellManager.addPlayerToGroundCells(newPlayerObject);
|
Globals.dataCellManager.addPlayerToGroundCells(playerObject);
|
||||||
Globals.dataCellManager.movePlayerGroundCells(newPlayerObject, Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.x), Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.z));
|
Globals.dataCellManager.movePlayerGroundCells(playerObject, Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.x), Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.z));
|
||||||
IronSightTree.attachIronSightTree(newPlayerCharacter);
|
IronSightTree.attachIronSightTree(newPlayerEntity);
|
||||||
// //spawn player sword
|
// //spawn player sword
|
||||||
// Entity sword = ItemUtils.spawnBasicItem("Katana");
|
// Entity sword = ItemUtils.spawnBasicItem("Katana");
|
||||||
// AttachUtils.attachEntityToEntityAtBone(newPlayerCharacter, sword, "Bone.031");
|
// AttachUtils.attachEntityToEntityAtBone(newPlayerCharacter, sword, "Bone.031");
|
||||||
//set controller id
|
//set controller id
|
||||||
CreatureUtils.setControllerPlayerId(newPlayerCharacter, playerCharacterId);
|
if(playerObject == Globals.serverPlayer){
|
||||||
if(Globals.RUN_SERVER && Main.playerId == -1){
|
Globals.playerEntity = newPlayerEntity;
|
||||||
Globals.playerEntity = newPlayerCharacter;
|
|
||||||
Globals.serverPlayer = newPlayerObject;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void spawnClientEntity(ServerConnectionHandler connectionHandler){
|
static void spawnClientEntity(ServerConnectionHandler connectionHandler){
|
||||||
spawnPlayerCharacter(connectionHandler);
|
spawnPlayerCharacter(connectionHandler);
|
||||||
//set client initial discrete position
|
//set client initial discrete position
|
||||||
connectionHandler.addMessagetoOutgoingQueue(
|
// connectionHandler.addMessagetoOutgoingQueue(
|
||||||
PlayerMessage.constructSetInitialDiscretePositionMessage(
|
// PlayerMessage.constructSetInitialDiscretePositionMessage(
|
||||||
Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.x),
|
// Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.x),
|
||||||
Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.z)
|
// Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.z)
|
||||||
)
|
// )
|
||||||
);
|
// );
|
||||||
//send spawn point
|
//send spawn point
|
||||||
connectionHandler.addMessagetoOutgoingQueue(
|
connectionHandler.addMessagetoOutgoingQueue(
|
||||||
TerrainMessage.constructSpawnPositionMessage(Globals.spawnPoint.x, Globals.spawnPoint.z)
|
TerrainMessage.constructSpawnPositionMessage(Globals.spawnPoint.x, Globals.spawnPoint.z)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user