package electrosphere.net.server.protocol; import org.joml.Vector3f; import electrosphere.entity.Entity; import electrosphere.entity.EntityUtils; import electrosphere.entity.state.ironsight.IronSightTree; import electrosphere.entity.types.attach.AttachUtils; import electrosphere.entity.types.collision.CollisionObjUtils; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.item.ItemUtils; import electrosphere.game.server.terrain.manager.ServerTerrainChunk; import electrosphere.game.server.terrain.models.TerrainModification; import electrosphere.logger.LoggerInterface; import electrosphere.main.Globals; import electrosphere.main.Main; import electrosphere.net.NetUtils; import electrosphere.net.parser.net.message.AuthMessage; import electrosphere.net.parser.net.message.CharacterMessage; import electrosphere.net.parser.net.message.EntityMessage; import electrosphere.net.parser.net.message.InventoryMessage; import electrosphere.net.parser.net.message.LoreMessage; import electrosphere.net.parser.net.message.NetworkMessage; import electrosphere.net.parser.net.message.PlayerMessage; import electrosphere.net.parser.net.message.ServerMessage; import electrosphere.net.parser.net.message.TerrainMessage; import electrosphere.net.parser.net.message.NetworkMessage.MessageType; import electrosphere.net.parser.net.message.ServerMessage.ServerMessageType; import electrosphere.net.server.ServerConnectionHandler; import electrosphere.net.server.player.Player; public class ServerProtocol { ServerConnectionHandler connectionHandler; boolean echoPings = false; public ServerProtocol(ServerConnectionHandler connectionHandler){ this.connectionHandler = connectionHandler; } public void handleMessage(NetworkMessage message){ //print out message printMessage(message); //actually handle message switch(message.getType()){ case ENTITY_MESSAGE: EntityProtocol.handleEntityMessage(connectionHandler, (EntityMessage)message); break; case TERRAIN_MESSAGE: TerrainProtocol.handleTerrainMessage(connectionHandler, (TerrainMessage)message); break; case PLAYER_MESSAGE: PlayerProtocol.handlePlayerMessage(connectionHandler, (PlayerMessage)message); break; case AUTH_MESSAGE: AuthProtocol.handleAuthenticationMessage(connectionHandler, (AuthMessage)message); break; case SERVER_MESSAGE: handleServerMessage((ServerMessage)message); break; case CHARACTER_MESSAGE: CharacterProtocol.handleCharacterMessage(connectionHandler, (CharacterMessage)message); break; case LORE_MESSAGE: LoreProtocol.handleLoreMessage(connectionHandler, (LoreMessage)message); break; case INVENTORY_MESSAGE: InventoryProtocol.handleInventoryMessage(connectionHandler, (InventoryMessage)message); break; } } void handleServerMessage(ServerMessage message){ switch(message.getMessageSubtype()){ case PING: connectionHandler.addMessagetoOutgoingQueue(ServerMessage.constructPongMessage()); break; case PONG: connectionHandler.markReceivedPongMessage(); break; } } /** * Print out the network message type, this only prints ping and pong if echoPings is true */ void printMessage(NetworkMessage message){ //only print ping and pong if echoPings is true if(message.getType() == MessageType.SERVER_MESSAGE){ if((((ServerMessage)message).getMessageSubtype()) == ServerMessageType.PING || (((ServerMessage)message).getMessageSubtype()) == ServerMessageType.PONG ){ if(this.echoPings == true){ LoggerInterface.loggerNetworking.DEBUG("[Server] New message " + message.getType()); } } else { LoggerInterface.loggerNetworking.DEBUG("[Server] New message " + message.getType()); } } else { LoggerInterface.loggerNetworking.DEBUG("[Server] New message " + message.getType()); } } }