auth
This commit is contained in:
parent
2fa8099d67
commit
65d7c1ec44
3
Scripts/auth/retrievePassHash.sql
Normal file
3
Scripts/auth/retrievePassHash.sql
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
--given username=testusername
|
||||||
|
SELECT pwdhash FROM accounts WHERE username='testusername';
|
||||||
178
pom.xml
178
pom.xml
@ -12,38 +12,16 @@
|
|||||||
<lwjgl.version>3.2.3</lwjgl.version>
|
<lwjgl.version>3.2.3</lwjgl.version>
|
||||||
<joml.version>1.9.19</joml.version>
|
<joml.version>1.9.19</joml.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.lwjgl</groupId>
|
|
||||||
<artifactId>lwjgl-assimp</artifactId>
|
|
||||||
<version>${lwjgl.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.lwjgl</groupId>
|
|
||||||
<artifactId>lwjgl-glfw</artifactId>
|
|
||||||
<version>${lwjgl.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.lwjgl</groupId>
|
|
||||||
<artifactId>lwjgl-opengl</artifactId>
|
|
||||||
<version>${lwjgl.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.lwjgl</groupId>
|
|
||||||
<artifactId>lwjgl-opengles</artifactId>
|
|
||||||
<version>${lwjgl.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.lwjgl</groupId>
|
|
||||||
<artifactId>lwjgl-openal</artifactId>
|
|
||||||
<version>${lwjgl.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.lwjgl</groupId>
|
|
||||||
<artifactId>lwjgl-stb</artifactId>
|
|
||||||
<version>${lwjgl.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- generic LWJGL runtimes -->
|
<!-- generic LWJGL runtimes -->
|
||||||
|
<!--License: BSD-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.lwjgl</groupId>
|
||||||
|
<artifactId>lwjgl</artifactId>
|
||||||
|
<version>${lwjgl.version}</version>
|
||||||
|
<classifier>${lwjgl.natives}</classifier>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.lwjgl</groupId>
|
<groupId>org.lwjgl</groupId>
|
||||||
<artifactId>lwjgl</artifactId>
|
<artifactId>lwjgl</artifactId>
|
||||||
@ -52,19 +30,108 @@
|
|||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--ASSIMP-->
|
||||||
|
<!--License: BSD-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.lwjgl</groupId>
|
||||||
|
<artifactId>lwjgl-assimp</artifactId>
|
||||||
|
<version>${lwjgl.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.lwjgl</groupId>
|
||||||
|
<artifactId>lwjgl-assimp</artifactId>
|
||||||
|
<version>${lwjgl.version}</version>
|
||||||
|
<classifier>${lwjgl.natives}</classifier>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--GLFW-->
|
||||||
|
<!--License: BSD-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.lwjgl</groupId>
|
||||||
|
<artifactId>lwjgl-glfw</artifactId>
|
||||||
|
<version>${lwjgl.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.lwjgl</groupId>
|
||||||
|
<artifactId>lwjgl-glfw</artifactId>
|
||||||
|
<version>${lwjgl.version}</version>
|
||||||
|
<classifier>${lwjgl.natives}</classifier>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--OpenGL-->
|
||||||
|
<!--License: BSD-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.lwjgl</groupId>
|
||||||
|
<artifactId>lwjgl-opengl</artifactId>
|
||||||
|
<version>${lwjgl.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.lwjgl</groupId>
|
||||||
|
<artifactId>lwjgl-opengl</artifactId>
|
||||||
|
<version>${lwjgl.version}</version>
|
||||||
|
<classifier>${lwjgl.natives}</classifier>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--OpenGL ES-->
|
||||||
|
<!--License: BSD-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.lwjgl</groupId>
|
||||||
|
<artifactId>lwjgl-opengles</artifactId>
|
||||||
|
<version>${lwjgl.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.lwjgl</groupId>
|
||||||
|
<artifactId>lwjgl-opengles</artifactId>
|
||||||
|
<version>${lwjgl.version}</version>
|
||||||
|
<classifier>${lwjgl.natives}</classifier>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--OpenAL-->
|
||||||
|
<!--License: BSD-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.lwjgl</groupId>
|
||||||
|
<artifactId>lwjgl-openal</artifactId>
|
||||||
|
<version>${lwjgl.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.lwjgl</groupId>
|
||||||
|
<artifactId>lwjgl-openal</artifactId>
|
||||||
|
<version>${lwjgl.version}</version>
|
||||||
|
<classifier>${lwjgl.natives}</classifier>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--STD-->
|
||||||
|
<!--License: BSD-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.lwjgl</groupId>
|
||||||
|
<artifactId>lwjgl-stb</artifactId>
|
||||||
|
<version>${lwjgl.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.lwjgl</groupId>
|
||||||
|
<artifactId>lwjgl-stb</artifactId>
|
||||||
|
<version>${lwjgl.version}</version>
|
||||||
|
<classifier>${lwjgl.natives}</classifier>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--JOML-->
|
||||||
|
<!--License: MIT-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.joml</groupId>
|
<groupId>org.joml</groupId>
|
||||||
<artifactId>joml</artifactId>
|
<artifactId>joml</artifactId>
|
||||||
<version>${joml.version}</version>
|
<version>${joml.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--GSON-->
|
||||||
|
<!--License: Apache-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
<artifactId>gson</artifactId>
|
<artifactId>gson</artifactId>
|
||||||
<version>2.8.6</version>
|
<version>2.8.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--jBulletFork-->
|
||||||
|
<!--License: ZLIB-->
|
||||||
<!--
|
<!--
|
||||||
manual: http://www.cs.kent.edu/~ruttan/GameEngines/lectures/Bullet_User_Manual
|
manual: http://www.cs.kent.edu/~ruttan/GameEngines/lectures/Bullet_User_Manual
|
||||||
because their docs ( http://jbullet.advel.cz/javadoc/com/bulletphysics/collision/shapes/CylinderShape.html ) suck
|
because their docs ( http://jbullet.advel.cz/javadoc/com/bulletphysics/collision/shapes/CylinderShape.html ) suck
|
||||||
@ -76,22 +143,8 @@
|
|||||||
<version>0.1</version>
|
<version>0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--
|
<!--SQLITE-JDBC-->
|
||||||
Potential alternative binding for bullet ?
|
<!--License: Apache-->
|
||||||
<dependency>
|
|
||||||
<groupId>com.badlogicgames.gdx</groupId>
|
|
||||||
<artifactId>gdx-bullet</artifactId>
|
|
||||||
<version>1.10.0</version>
|
|
||||||
</dependency>
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-crypto -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-crypto</artifactId>
|
|
||||||
<version>1.1.0</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc -->
|
<!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.xerial</groupId>
|
<groupId>org.xerial</groupId>
|
||||||
@ -138,38 +191,7 @@
|
|||||||
</profile>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
<build>
|
<build>
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>${basedir}/src/main/resources</directory>
|
|
||||||
<includes>
|
|
||||||
<include>**/*</include>
|
|
||||||
</includes>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<addClasspath>true</addClasspath>
|
|
||||||
<mainClass>electrosphere.main.Main</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
<descriptorRefs>
|
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
|
||||||
</descriptorRefs>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>assemble-all</id>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>single</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
|||||||
@ -1,11 +1,81 @@
|
|||||||
package electrosphere.auth;
|
package electrosphere.auth;
|
||||||
|
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.spec.InvalidKeySpecException;
|
||||||
|
import java.security.spec.KeySpec;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
import javax.crypto.SecretKeyFactory;
|
||||||
|
import javax.crypto.spec.PBEKeySpec;
|
||||||
|
|
||||||
|
import electrosphere.game.server.db.DatabaseResult;
|
||||||
|
import electrosphere.game.server.db.DatabaseResultRow;
|
||||||
|
import electrosphere.logger.LoggerInterface;
|
||||||
|
import electrosphere.main.Globals;
|
||||||
|
|
||||||
public class AuthenticationManager {
|
public class AuthenticationManager {
|
||||||
|
|
||||||
|
|
||||||
public boolean authenticate(String username, String password){
|
public boolean authenticate(String username, String password){
|
||||||
boolean rVal = true;
|
//first we hash the input password
|
||||||
//TODO: actually authenticate
|
String hashedPassword = getHashedString(password);
|
||||||
|
//then query the database for the username and hash for the input username
|
||||||
|
DatabaseResult result = Globals.dbController.executePreparedQuery("SELECT id, username, pwdhash FROM accounts WHERE username=?;",username);
|
||||||
|
if(result.hasResult()){
|
||||||
|
boolean foundRow = false;
|
||||||
|
//if we get a valid response from the database, check that it actually matches hashes
|
||||||
|
for(DatabaseResultRow row : result){
|
||||||
|
foundRow = true;
|
||||||
|
String pwdhash = row.getAsString("pwdhash");
|
||||||
|
if(pwdhash.equals(hashedPassword)){
|
||||||
|
LoggerInterface.loggerAuth.INFO("Authenticated user " + username);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//If we didn't find a single account, go ahead and create it
|
||||||
|
if(!foundRow){
|
||||||
|
LoggerInterface.loggerAuth.INFO("Created user " + username);
|
||||||
|
Globals.dbController.executePreparedStatement("INSERT INTO accounts (username, pwdhash) VALUES(?, ?);",username,hashedPassword);
|
||||||
|
//TODO: verify we created the account
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LoggerInterface.loggerAuth.INFO("Failed to authenticate user " + username);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final int saltLength = 16;
|
||||||
|
public static String getHashedString(String input){
|
||||||
|
String rVal = "";
|
||||||
|
|
||||||
|
//generate salt
|
||||||
|
char[] charArray = input.toCharArray();
|
||||||
|
byte[] salt = new byte[saltLength];
|
||||||
|
for(int i = 0; i < saltLength; i++){
|
||||||
|
if(i < charArray.length){
|
||||||
|
salt[i] = (byte)charArray[i];
|
||||||
|
} else {
|
||||||
|
salt[i] = (byte)i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//perform hash
|
||||||
|
KeySpec spec = new PBEKeySpec(charArray, salt, 65536, 512);
|
||||||
|
try {
|
||||||
|
SecretKeyFactory f = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA512");
|
||||||
|
byte[] hash = f.generateSecret(spec).getEncoded();
|
||||||
|
Base64.Encoder enc = Base64.getEncoder();
|
||||||
|
// System.out.printf("salt: %s%n", enc.encodeToString(salt));
|
||||||
|
// System.out.printf("hash: %s%n", enc.encodeToString(hash));
|
||||||
|
// System.out.println(Arrays.toString(hash));
|
||||||
|
rVal = enc.encodeToString(hash);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
LoggerInterface.loggerAuth.ERROR("NoSuchAlgorithmException in hash string", e);
|
||||||
|
} catch (InvalidKeySpecException e) {
|
||||||
|
LoggerInterface.loggerAuth.ERROR("InvalidKeySpecException in hash string", e);
|
||||||
|
}
|
||||||
|
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -773,7 +773,7 @@ public class ControlHandler {
|
|||||||
controls.get(INPUT_CODE_CHARACTER_OPEN).setOnClick(new ControlMethod(){public void execute(){
|
controls.get(INPUT_CODE_CHARACTER_OPEN).setOnClick(new ControlMethod(){public void execute(){
|
||||||
if(InventoryUtils.hasEquipInventory(Globals.playerEntity) && Globals.elementManager.getWindow(WindowStrings.WINDOW_CHARACTER) == null){
|
if(InventoryUtils.hasEquipInventory(Globals.playerEntity) && Globals.elementManager.getWindow(WindowStrings.WINDOW_CHARACTER) == null){
|
||||||
//create window
|
//create window
|
||||||
Window mainMenuWindow = MenuGenerators.createCharacterMenu(InventoryUtils.getEquipInventory(Globals.playerEntity));
|
Window mainMenuWindow = MenuGenerators.createCharacterInventoryMenu(InventoryUtils.getEquipInventory(Globals.playerEntity));
|
||||||
//register
|
//register
|
||||||
Globals.elementManager.registerWindow(WindowStrings.WINDOW_CHARACTER, mainMenuWindow);
|
Globals.elementManager.registerWindow(WindowStrings.WINDOW_CHARACTER, mainMenuWindow);
|
||||||
//make visible
|
//make visible
|
||||||
|
|||||||
@ -427,7 +427,6 @@ public class LoadingThread extends Thread {
|
|||||||
Thread clientThread = null;
|
Thread clientThread = null;
|
||||||
if(Globals.RUN_CLIENT){
|
if(Globals.RUN_CLIENT){
|
||||||
Globals.clientConnection = new ClientNetworking(NetUtils.getAddress(),NetUtils.getPort());
|
Globals.clientConnection = new ClientNetworking(NetUtils.getAddress(),NetUtils.getPort());
|
||||||
System.out.println(Globals.clientConnection.socket);
|
|
||||||
clientThread = new Thread(Globals.clientConnection);
|
clientThread = new Thread(Globals.clientConnection);
|
||||||
clientThread.start();
|
clientThread.start();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,39 +34,70 @@ public class DatabaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// public boolean executeStatement(String statementRaw){
|
/**
|
||||||
// boolean rVal = false;
|
* Executes a write statement to the database
|
||||||
// try {
|
* @param statementRaw The raw string for the statement
|
||||||
// PreparedStatement statement = conn.prepareStatement(statementRaw);
|
* @param arguments The arguments to be inserted into the raw sql
|
||||||
// rVal = statement.execute();
|
*/
|
||||||
// } catch (SQLException ex) {
|
public boolean executePreparedStatement(String statementRaw, Object...arguments){
|
||||||
// LoggerInterface.loggerFileIO.ERROR("SQL statement execution error", ex);
|
|
||||||
// }
|
|
||||||
// return rVal;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public DatabaseResult executeStatement(String statementRaw){
|
|
||||||
DatabaseResult rVal = DatabaseResult.createStatement(statementRaw);
|
|
||||||
try {
|
try {
|
||||||
PreparedStatement statement = conn.prepareStatement(statementRaw);
|
PreparedStatement statement = conn.prepareStatement(statementRaw);
|
||||||
statement.execute();
|
//Set arguments for prepared statements
|
||||||
ResultSet results = statement.getResultSet();
|
int argumentIndex = 1;
|
||||||
if(results != null){
|
for(Object currentArg : arguments){
|
||||||
rVal.addResultSet(results);
|
if(currentArg instanceof String){
|
||||||
|
statement.setString(argumentIndex, (String)currentArg);
|
||||||
|
} else if(currentArg instanceof Integer){
|
||||||
|
statement.setInt(argumentIndex, (int)currentArg);
|
||||||
|
} else if(currentArg instanceof Float){
|
||||||
|
statement.setFloat(argumentIndex, (float)currentArg);
|
||||||
|
} else if(currentArg instanceof Boolean){
|
||||||
|
statement.setBoolean(argumentIndex, (boolean)currentArg);
|
||||||
|
} else if(currentArg instanceof Long){
|
||||||
|
statement.setLong(argumentIndex, (long)currentArg);
|
||||||
|
} else if(currentArg instanceof Double){
|
||||||
|
statement.setDouble(argumentIndex, (double)currentArg);
|
||||||
|
}
|
||||||
|
argumentIndex++;
|
||||||
}
|
}
|
||||||
|
//actually execute
|
||||||
|
return statement.execute();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
rVal.succeeded = false;
|
LoggerInterface.loggerFileIO.ERROR("SQL query execution error", ex);
|
||||||
rVal.hasResultSet = false;
|
|
||||||
LoggerInterface.loggerFileIO.ERROR("SQL statement execution error", ex);
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return rVal;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DatabaseResult executeQuery(String statementRaw){
|
/**
|
||||||
DatabaseResult rVal = DatabaseResult.createStatement(statementRaw);
|
* Executes a query against the database
|
||||||
|
* @param statementRaw The raw sql
|
||||||
|
* @param arguments The arguments to be injected into the raw sql
|
||||||
|
* @return A DatabaseResult representing the results of the query, or null if there was no result
|
||||||
|
*/
|
||||||
|
public DatabaseResult executePreparedQuery(String statementRaw, Object...arguments){
|
||||||
|
DatabaseResult rVal = DatabaseResult.createQuery(statementRaw);
|
||||||
try {
|
try {
|
||||||
PreparedStatement statement = conn.prepareStatement(statementRaw);
|
PreparedStatement statement = conn.prepareStatement(statementRaw);
|
||||||
|
|
||||||
|
//Set arguments for prepared statements
|
||||||
|
int argumentIndex = 1;
|
||||||
|
for(Object currentArg : arguments){
|
||||||
|
if(currentArg instanceof String){
|
||||||
|
statement.setString(argumentIndex, (String)currentArg);
|
||||||
|
} else if(currentArg instanceof Integer){
|
||||||
|
statement.setInt(argumentIndex, (int)currentArg);
|
||||||
|
} else if(currentArg instanceof Float){
|
||||||
|
statement.setFloat(argumentIndex, (float)currentArg);
|
||||||
|
} else if(currentArg instanceof Boolean){
|
||||||
|
statement.setBoolean(argumentIndex, (boolean)currentArg);
|
||||||
|
} else if(currentArg instanceof Long){
|
||||||
|
statement.setLong(argumentIndex, (long)currentArg);
|
||||||
|
} else if(currentArg instanceof Double){
|
||||||
|
statement.setDouble(argumentIndex, (double)currentArg);
|
||||||
|
}
|
||||||
|
argumentIndex++;
|
||||||
|
}
|
||||||
|
//actually execute
|
||||||
ResultSet results = statement.executeQuery();
|
ResultSet results = statement.executeQuery();
|
||||||
if(results != null){
|
if(results != null){
|
||||||
rVal.addResultSet(results);
|
rVal.addResultSet(results);
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import com.google.gson.Gson;
|
|||||||
import electrosphere.logger.LoggerInterface;
|
import electrosphere.logger.LoggerInterface;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -11,7 +12,8 @@ import java.util.logging.Logger;
|
|||||||
*
|
*
|
||||||
* @author amaterasu
|
* @author amaterasu
|
||||||
*/
|
*/
|
||||||
public class DatabaseResult {
|
public class DatabaseResult implements Iterable<DatabaseResultRow> {
|
||||||
|
|
||||||
boolean isQuery = false;
|
boolean isQuery = false;
|
||||||
boolean isStatement = false;
|
boolean isStatement = false;
|
||||||
boolean succeeded = false;
|
boolean succeeded = false;
|
||||||
@ -25,14 +27,14 @@ public class DatabaseResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static DatabaseResult createQuery(String code){
|
protected static DatabaseResult createQuery(String code){
|
||||||
DatabaseResult rVal = new DatabaseResult();
|
DatabaseResult rVal = new DatabaseResult();
|
||||||
rVal.isQuery = true;
|
rVal.isQuery = true;
|
||||||
rVal.code = code;
|
rVal.code = code;
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DatabaseResult createStatement(String code){
|
protected static DatabaseResult createStatement(String code){
|
||||||
DatabaseResult rVal = new DatabaseResult();
|
DatabaseResult rVal = new DatabaseResult();
|
||||||
rVal.isStatement = true;
|
rVal.isStatement = true;
|
||||||
rVal.code = code;
|
rVal.code = code;
|
||||||
@ -40,14 +42,15 @@ public class DatabaseResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void addResultSet(ResultSet rs){
|
protected void addResultSet(ResultSet rs){
|
||||||
|
hasResultSet = true;
|
||||||
this.rs = rs;
|
this.rs = rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultSet getResultSet(){
|
protected ResultSet getResultSet(){
|
||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasResultSet(){
|
public boolean hasResult(){
|
||||||
return hasResultSet;
|
return hasResultSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,4 +80,9 @@ public class DatabaseResult {
|
|||||||
|
|
||||||
public void logRawResult(){
|
public void logRawResult(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseResultIterator iterator() {
|
||||||
|
return new DatabaseResultIterator(rs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,98 @@
|
|||||||
|
package electrosphere.game.server.db;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.ResultSetMetaData;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Types;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import electrosphere.logger.LoggerInterface;
|
||||||
|
|
||||||
|
public class DatabaseResultIterator implements Iterator<DatabaseResultRow> {
|
||||||
|
|
||||||
|
ResultSet rs;
|
||||||
|
ResultSetMetaData metadata;
|
||||||
|
List<Integer> typeList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a result iterator -- used internal to package
|
||||||
|
* @param result
|
||||||
|
*/
|
||||||
|
protected DatabaseResultIterator(ResultSet result){
|
||||||
|
this.rs = result;
|
||||||
|
try {
|
||||||
|
this.metadata = this.rs.getMetaData();
|
||||||
|
int columnCount = metadata.getColumnCount();
|
||||||
|
this.typeList = new LinkedList<Integer>();
|
||||||
|
for(int i = 0; i < columnCount; i++){
|
||||||
|
//result sets are indexed starting at 1
|
||||||
|
this.typeList.add(metadata.getColumnType(i+1));
|
||||||
|
}
|
||||||
|
//the sqlite driver doesn't support reverse navigation unfortunatelly
|
||||||
|
//if it did, we'd call this to be explicitly clear where we want to start
|
||||||
|
//instead the assumption is it always starts ON the first element
|
||||||
|
// this.rs.first();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LoggerInterface.loggerEngine.ERROR("SQL Exception", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lets us know if the result has a next value
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
try {
|
||||||
|
return !rs.isAfterLast();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LoggerInterface.loggerEngine.ERROR("Critical failure in DatabaseResultIterator", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the next value in the result
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public DatabaseResultRow next() {
|
||||||
|
DatabaseResultRow row = new DatabaseResultRow();
|
||||||
|
int columnIncrementer = 0;
|
||||||
|
//basically go through each type and add it to the row object that we return
|
||||||
|
//the types are stored in the typeList field on this object when it is created
|
||||||
|
try {
|
||||||
|
for(int type : typeList){
|
||||||
|
//increment at the beginning because result sets are indexed starting at 1
|
||||||
|
columnIncrementer++;
|
||||||
|
switch(type){
|
||||||
|
case Types.INTEGER:
|
||||||
|
row.putValue(metadata.getColumnName(columnIncrementer), rs.getInt(columnIncrementer));
|
||||||
|
break;
|
||||||
|
case Types.VARCHAR:
|
||||||
|
row.putValue(metadata.getColumnName(columnIncrementer), rs.getString(columnIncrementer));
|
||||||
|
break;
|
||||||
|
case Types.BIGINT:
|
||||||
|
row.putValue(metadata.getColumnName(columnIncrementer), rs.getLong(columnIncrementer));
|
||||||
|
break;
|
||||||
|
case Types.FLOAT:
|
||||||
|
row.putValue(metadata.getColumnName(columnIncrementer), rs.getFloat(columnIncrementer));
|
||||||
|
break;
|
||||||
|
case Types.DOUBLE:
|
||||||
|
row.putValue(metadata.getColumnName(columnIncrementer), rs.getDouble(columnIncrementer));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
LoggerInterface.loggerEngine.WARNING("Unsupported type from database in DatabaseResultIterator " + type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//make sure to increment the result set so we don't infinitely loop the first element
|
||||||
|
this.rs.next();
|
||||||
|
} catch (SQLException e){
|
||||||
|
LoggerInterface.loggerEngine.ERROR("Unhandled SQL exception", e);
|
||||||
|
}
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,76 @@
|
|||||||
|
package electrosphere.game.server.db;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class DatabaseResultRow {
|
||||||
|
|
||||||
|
// protected addColumn(int column)
|
||||||
|
|
||||||
|
//stores all the values of the row in an easily indexible-by-column-name format
|
||||||
|
Map<String,Object> values = new HashMap<String,Object>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used internally for putting values into the row
|
||||||
|
* @param columnName
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
protected void putValue(String columnName, Object value){
|
||||||
|
values.put(columnName,value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the given value
|
||||||
|
* @param columnName the name of the column to check
|
||||||
|
* @return the value on said column
|
||||||
|
*/
|
||||||
|
public Object getValue(String columnName){
|
||||||
|
return values.get(columnName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the given value as a string
|
||||||
|
* @param columnName the name of the column to check
|
||||||
|
* @return the value on said column as a string
|
||||||
|
*/
|
||||||
|
public String getAsString(String columnName){
|
||||||
|
return (String)values.get(columnName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the given value as an integer
|
||||||
|
* @param columnName the name of the column to check
|
||||||
|
* @return the value on said column as an integer
|
||||||
|
*/
|
||||||
|
public int getAsInteger(String columnName){
|
||||||
|
return (Integer)values.get(columnName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the given value as a long
|
||||||
|
* @param columnName the name of the column to check
|
||||||
|
* @return the value on said column as a long
|
||||||
|
*/
|
||||||
|
public long getAsLong(String columnName){
|
||||||
|
return (Long)values.get(columnName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the given value as a float
|
||||||
|
* @param columnName the name of the column to check
|
||||||
|
* @return the value on said column as a float
|
||||||
|
*/
|
||||||
|
public float getAsFloat(String columnName){
|
||||||
|
return (Float)values.get(columnName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the given value as a double
|
||||||
|
* @param columnName the name of the column to check
|
||||||
|
* @return the value on said column as a double
|
||||||
|
*/
|
||||||
|
public double getAsDouble(String columnName){
|
||||||
|
return (Double)values.get(columnName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -55,7 +55,7 @@ public class DatabaseUtils {
|
|||||||
if(line.contains(";")){
|
if(line.contains(";")){
|
||||||
accumulatorString = accumulatorString + line;
|
accumulatorString = accumulatorString + line;
|
||||||
System.out.println("EXECUTE: " + accumulatorString);
|
System.out.println("EXECUTE: " + accumulatorString);
|
||||||
controller.executeStatement(accumulatorString);
|
controller.executePreparedStatement(accumulatorString);
|
||||||
accumulatorString = "";
|
accumulatorString = "";
|
||||||
} else {
|
} else {
|
||||||
accumulatorString = accumulatorString + line;
|
accumulatorString = accumulatorString + line;
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package electrosphere.game.server.structure.virtual;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import electrosphere.game.server.db.DatabaseResult;
|
import electrosphere.game.server.db.DatabaseResult;
|
||||||
|
import electrosphere.game.server.db.DatabaseResultRow;
|
||||||
import electrosphere.logger.LoggerInterface;
|
import electrosphere.logger.LoggerInterface;
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -29,24 +30,19 @@ public class StructureManager {
|
|||||||
public static Structure createStructure(int worldX, int worldY, float localX, float localY, String type){
|
public static Structure createStructure(int worldX, int worldY, float localX, float localY, String type){
|
||||||
structIDIterator++;
|
structIDIterator++;
|
||||||
Structure rVal = new Structure(worldX, worldY, localX, localY, type);
|
Structure rVal = new Structure(worldX, worldY, localX, localY, type);
|
||||||
Globals.dbController.executeStatement("INSERT INTO structWorldPositions (structID,posX,posY) VALUES (" + structIDIterator + "," + worldX + "," + worldY + ");");
|
Globals.dbController.executePreparedStatement("INSERT INTO structWorldPositions (structID,posX,posY) VALUES (?,?,?);",structIDIterator,worldX,worldY);
|
||||||
Globals.dbController.executeStatement("INSERT INTO structData(structID,propName,propValue) VALUES(" + structIDIterator + ",'localX','" + localX + "');");
|
Globals.dbController.executePreparedStatement("INSERT INTO structData(structID,propName,propValue) VALUES(?,'localX','?');",structIDIterator,localX);
|
||||||
Globals.dbController.executeStatement("INSERT INTO structData(structID,propName,propValue) VALUES(" + structIDIterator + ",'localY','" + localY + "');");
|
Globals.dbController.executePreparedStatement("INSERT INTO structData(structID,propName,propValue) VALUES(?,'localY','?');",structIDIterator,localY);
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Structure> getStructuresInChunk(int worldX, int worldY){
|
public static List<Structure> getStructuresInChunk(int worldX, int worldY){
|
||||||
List<Structure> rVal = new LinkedList<Structure>();
|
List<Structure> rVal = new LinkedList<Structure>();
|
||||||
DatabaseResult result = Globals.dbController.executeStatement("SELECT * FROM structWorldPositions WHERE posX = " + worldX + " AND posY = " + worldY + ";");
|
DatabaseResult result = Globals.dbController.executePreparedQuery("SELECT * FROM structWorldPositions WHERE posX = ? AND posY = ?;",worldX,worldY);
|
||||||
List<Integer> returnedIDs = new LinkedList<Integer>();
|
List<Integer> returnedIDs = new LinkedList<Integer>();
|
||||||
if(result.hasResultSet()){
|
if(result.success() && result.hasResult()){
|
||||||
ResultSet positionSet = result.getResultSet();
|
for(DatabaseResultRow row : result){
|
||||||
try {
|
returnedIDs.add(row.getAsInteger("structID"));
|
||||||
while(positionSet.next()){
|
|
||||||
returnedIDs.add(positionSet.getInt("structID"));
|
|
||||||
}
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
LoggerInterface.loggerEngine.ERROR("Error looping through positions returned in StructureManager.getStructuresInChunk", ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(returnedIDs.size() > 0){
|
if(returnedIDs.size() > 0){
|
||||||
@ -55,17 +51,11 @@ public class StructureManager {
|
|||||||
ids = ids + ID + ",";
|
ids = ids + ID + ",";
|
||||||
}
|
}
|
||||||
ids = ids.substring(0, ids.length() - 1);
|
ids = ids.substring(0, ids.length() - 1);
|
||||||
result = Globals.dbController.executeStatement("SELECT * FROM structData WHERE structID IN (" + ids + ");");
|
result = Globals.dbController.executePreparedQuery("SELECT * FROM structData WHERE structID IN (?);",ids);
|
||||||
if(result.success() && result.hasResultSet()){
|
if(result.success() && result.hasResult()){
|
||||||
ResultSet rs = result.getResultSet();
|
for(DatabaseResultRow row : result){
|
||||||
try {
|
Structure newStruct = serializer.fromJson(row.getAsString("dataVal"), Structure.class);
|
||||||
while(rs.next()){
|
rVal.add(newStruct);
|
||||||
String rawData = rs.getString("dataVal");
|
|
||||||
Structure newStruct = serializer.fromJson(rawData, Structure.class);
|
|
||||||
rVal.add(newStruct);
|
|
||||||
}
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
LoggerInterface.loggerEngine.ERROR("Error looping through structures returned in StructureManager.getStructuresInChunk", ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,6 +40,7 @@ public class Logger {
|
|||||||
public void ERROR(String message, Exception e){
|
public void ERROR(String message, Exception e){
|
||||||
if(level == LogLevel.DEBUG || level == LogLevel.INFO || level == LogLevel.WARNING || level == LogLevel.ERROR){
|
if(level == LogLevel.DEBUG || level == LogLevel.INFO || level == LogLevel.WARNING || level == LogLevel.ERROR){
|
||||||
System.out.println(message);
|
System.out.println(message);
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@ public class LoggerInterface {
|
|||||||
public static Logger loggerRenderer;
|
public static Logger loggerRenderer;
|
||||||
public static Logger loggerEngine;
|
public static Logger loggerEngine;
|
||||||
public static Logger loggerStartup;
|
public static Logger loggerStartup;
|
||||||
|
public static Logger loggerAuth;
|
||||||
|
|
||||||
public static void initLoggers(){
|
public static void initLoggers(){
|
||||||
loggerStartup = new Logger(LogLevel.WARNING);
|
loggerStartup = new Logger(LogLevel.WARNING);
|
||||||
@ -24,6 +25,7 @@ public class LoggerInterface {
|
|||||||
loggerGameLogic = new Logger(LogLevel.WARNING);
|
loggerGameLogic = new Logger(LogLevel.WARNING);
|
||||||
loggerRenderer = new Logger(LogLevel.WARNING);
|
loggerRenderer = new Logger(LogLevel.WARNING);
|
||||||
loggerEngine = new Logger(LogLevel.WARNING);
|
loggerEngine = new Logger(LogLevel.WARNING);
|
||||||
|
loggerAuth = new Logger(LogLevel.INFO);
|
||||||
loggerStartup.INFO("Initialized loggers");
|
loggerStartup.INFO("Initialized loggers");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -176,6 +176,8 @@ public class Globals {
|
|||||||
//
|
//
|
||||||
public static PlayerManager playerManager;
|
public static PlayerManager playerManager;
|
||||||
public static Player clientPlayer;
|
public static Player clientPlayer;
|
||||||
|
public static String clientUsername;
|
||||||
|
public static String clientPassword;
|
||||||
|
|
||||||
//
|
//
|
||||||
//Generic OpenGL Statements
|
//Generic OpenGL Statements
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import com.google.gson.Gson;
|
|||||||
import electrosphere.audio.AudioEngine;
|
import electrosphere.audio.AudioEngine;
|
||||||
import electrosphere.audio.AudioSource;
|
import electrosphere.audio.AudioSource;
|
||||||
import electrosphere.audio.AudioUtils;
|
import electrosphere.audio.AudioUtils;
|
||||||
|
import electrosphere.auth.AuthenticationManager;
|
||||||
import electrosphere.controls.ControlHandler;
|
import electrosphere.controls.ControlHandler;
|
||||||
import electrosphere.entity.types.creature.CreatureUtils;
|
import electrosphere.entity.types.creature.CreatureUtils;
|
||||||
import electrosphere.renderer.Material;
|
import electrosphere.renderer.Material;
|
||||||
@ -48,9 +49,14 @@ import java.io.IOException;
|
|||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
|
import java.security.Provider;
|
||||||
|
import java.security.Security;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.crypto.Cipher;
|
||||||
|
|
||||||
import org.joml.Vector3d;
|
import org.joml.Vector3d;
|
||||||
|
|
||||||
|
|
||||||
@ -108,6 +114,16 @@ public class Main {
|
|||||||
//init global variables
|
//init global variables
|
||||||
Globals.initGlobals();
|
Globals.initGlobals();
|
||||||
|
|
||||||
|
// if(1==1){
|
||||||
|
// SaveUtils.loadSave("arena");
|
||||||
|
// Globals.authenticationManager = new AuthenticationManager();
|
||||||
|
// String rawPass = "testpassword";
|
||||||
|
// String hashedPassword = AuthenticationManager.getHashedString(rawPass);
|
||||||
|
// boolean authed = Globals.authenticationManager.authenticate("testuser", hashedPassword);
|
||||||
|
// System.out.println("Authenticated: " + authed);
|
||||||
|
// System.exit(0);
|
||||||
|
// }
|
||||||
|
|
||||||
//world gen testing
|
//world gen testing
|
||||||
//gen terrain
|
//gen terrain
|
||||||
// Globals.serverTerrainManager = new ServerTerrainManager(2000,50,100,0.0f,0);
|
// Globals.serverTerrainManager = new ServerTerrainManager(2000,50,100,0.0f,0);
|
||||||
|
|||||||
@ -102,14 +102,12 @@ public class MenuGenerators {
|
|||||||
arenaButton.addChild(arenaLabel);
|
arenaButton.addChild(arenaLabel);
|
||||||
rVal.addChild(arenaButton);
|
rVal.addChild(arenaButton);
|
||||||
arenaButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
|
arenaButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
|
||||||
LoadingThread clientThread = new LoadingThread(LoadingThread.LOAD_CHARACTER_SERVER);
|
|
||||||
Globals.loadingThreadsList.add(clientThread);
|
|
||||||
LoadingThread serverThread = new LoadingThread(LoadingThread.LOAD_ARENA);
|
LoadingThread serverThread = new LoadingThread(LoadingThread.LOAD_ARENA);
|
||||||
Globals.loadingThreadsList.add(serverThread);
|
Globals.loadingThreadsList.add(serverThread);
|
||||||
Globals.RUN_CLIENT = true;
|
Globals.RUN_CLIENT = true;
|
||||||
Globals.RUN_SERVER = true;
|
Globals.RUN_SERVER = true;
|
||||||
clientThread.start();
|
|
||||||
serverThread.start();
|
serverThread.start();
|
||||||
|
WindowUtils.replaceMainMenuContents(MenuGeneratorsArena.createArenaHostLoginMenu());
|
||||||
return false;
|
return false;
|
||||||
}});
|
}});
|
||||||
|
|
||||||
@ -455,7 +453,7 @@ public class MenuGenerators {
|
|||||||
//clear ui
|
//clear ui
|
||||||
WindowUtils.cleanItemDraggingWindow();
|
WindowUtils.cleanItemDraggingWindow();
|
||||||
String sourceWindowId = WindowStrings.WINDOW_CHARACTER;
|
String sourceWindowId = WindowStrings.WINDOW_CHARACTER;
|
||||||
WindowUtils.replaceWindow(sourceWindowId,MenuGenerators.createCharacterMenu(inventory));
|
WindowUtils.replaceWindow(sourceWindowId,MenuGenerators.createCharacterInventoryMenu(inventory));
|
||||||
//null globals
|
//null globals
|
||||||
Globals.dragSourceInventory = null;
|
Globals.dragSourceInventory = null;
|
||||||
Globals.draggedItem = null;
|
Globals.draggedItem = null;
|
||||||
@ -924,7 +922,7 @@ public class MenuGenerators {
|
|||||||
WindowUtils.cleanItemDraggingWindow();
|
WindowUtils.cleanItemDraggingWindow();
|
||||||
//rerender both inventories
|
//rerender both inventories
|
||||||
//re-render inventory
|
//re-render inventory
|
||||||
WindowUtils.replaceWindow(WindowStrings.WINDOW_CHARACTER, MenuGenerators.createCharacterMenu(sourceInventory));
|
WindowUtils.replaceWindow(WindowStrings.WINDOW_CHARACTER, MenuGenerators.createCharacterInventoryMenu(sourceInventory));
|
||||||
//re-render inventory
|
//re-render inventory
|
||||||
WindowUtils.replaceWindow(WindowUtils.getInventoryWindowID(inventory.getId()), MenuGenerators.createNaturalInventoryMenu(inventory));
|
WindowUtils.replaceWindow(WindowUtils.getInventoryWindowID(inventory.getId()), MenuGenerators.createNaturalInventoryMenu(inventory));
|
||||||
}
|
}
|
||||||
@ -953,7 +951,7 @@ public class MenuGenerators {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Window createCharacterMenu(RelationalInventoryState inventory){
|
public static Window createCharacterInventoryMenu(RelationalInventoryState inventory){
|
||||||
// int screenTop = Globals.WINDOW_HEIGHT - 150;
|
// int screenTop = Globals.WINDOW_HEIGHT - 150;
|
||||||
int width = 500;
|
int width = 500;
|
||||||
int height = 500;
|
int height = 500;
|
||||||
@ -987,7 +985,7 @@ public class MenuGenerators {
|
|||||||
WindowUtils.cleanItemDraggingWindow();
|
WindowUtils.cleanItemDraggingWindow();
|
||||||
//rerender both inventories
|
//rerender both inventories
|
||||||
//re-render inventory
|
//re-render inventory
|
||||||
WindowUtils.replaceWindow(WindowStrings.WINDOW_CHARACTER, MenuGenerators.createCharacterMenu(inventory));
|
WindowUtils.replaceWindow(WindowStrings.WINDOW_CHARACTER, MenuGenerators.createCharacterInventoryMenu(inventory));
|
||||||
//re-render inventory
|
//re-render inventory
|
||||||
WindowUtils.replaceWindow(WindowUtils.getInventoryWindowID(sourceInventory.getId()), MenuGenerators.createNaturalInventoryMenu(sourceInventory));
|
WindowUtils.replaceWindow(WindowUtils.getInventoryWindowID(sourceInventory.getId()), MenuGenerators.createNaturalInventoryMenu(sourceInventory));
|
||||||
}
|
}
|
||||||
@ -1088,7 +1086,7 @@ public class MenuGenerators {
|
|||||||
WindowUtils.cleanItemDraggingWindow();
|
WindowUtils.cleanItemDraggingWindow();
|
||||||
//rerender both inventories
|
//rerender both inventories
|
||||||
//re-render inventory
|
//re-render inventory
|
||||||
WindowUtils.replaceWindow(WindowStrings.WINDOW_CHARACTER, MenuGenerators.createCharacterMenu(inventory));
|
WindowUtils.replaceWindow(WindowStrings.WINDOW_CHARACTER, MenuGenerators.createCharacterInventoryMenu(inventory));
|
||||||
//re-render inventory
|
//re-render inventory
|
||||||
WindowUtils.replaceWindow(WindowUtils.getInventoryWindowID(sourceInventory.getId()), MenuGenerators.createNaturalInventoryMenu(sourceInventory));
|
WindowUtils.replaceWindow(WindowUtils.getInventoryWindowID(sourceInventory.getId()), MenuGenerators.createNaturalInventoryMenu(sourceInventory));
|
||||||
}
|
}
|
||||||
|
|||||||
70
src/main/java/electrosphere/menu/MenuGeneratorsArena.java
Normal file
70
src/main/java/electrosphere/menu/MenuGeneratorsArena.java
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
package electrosphere.menu;
|
||||||
|
|
||||||
|
import electrosphere.auth.AuthenticationManager;
|
||||||
|
import electrosphere.engine.LoadingThread;
|
||||||
|
import electrosphere.main.Globals;
|
||||||
|
import electrosphere.net.NetUtils;
|
||||||
|
import electrosphere.renderer.ui.ClickableElement;
|
||||||
|
import electrosphere.renderer.ui.Element;
|
||||||
|
import electrosphere.renderer.ui.elements.Button;
|
||||||
|
import electrosphere.renderer.ui.elements.Label;
|
||||||
|
import electrosphere.renderer.ui.elements.TextInput;
|
||||||
|
import electrosphere.renderer.ui.events.ClickEvent;
|
||||||
|
import electrosphere.renderer.ui.form.FormElement;
|
||||||
|
|
||||||
|
public class MenuGeneratorsArena {
|
||||||
|
|
||||||
|
public static Element createArenaHostLoginMenu(){
|
||||||
|
FormElement rVal = new FormElement();
|
||||||
|
int screenTop = 150;
|
||||||
|
|
||||||
|
//label (address)
|
||||||
|
Label usernameLabel = new Label(100,screenTop + 50,1.0f);
|
||||||
|
usernameLabel.setText("Username");
|
||||||
|
rVal.addChild(usernameLabel);
|
||||||
|
|
||||||
|
//text entry (address)
|
||||||
|
TextInput usernameInput = new TextInput(100,screenTop + 125,1.0f);
|
||||||
|
usernameInput.setText("");
|
||||||
|
rVal.addChild(usernameInput);
|
||||||
|
|
||||||
|
//label (port)
|
||||||
|
Label passwordLabel = new Label(100,screenTop + 200,1.0f);
|
||||||
|
passwordLabel.setText("Password");
|
||||||
|
rVal.addChild(passwordLabel);
|
||||||
|
|
||||||
|
//text entry (port)
|
||||||
|
TextInput passwordInput = new TextInput(100,screenTop + 275,1.0f);
|
||||||
|
passwordInput.setText("");
|
||||||
|
rVal.addChild(passwordInput);
|
||||||
|
|
||||||
|
//button (connect)
|
||||||
|
Button connectButton = new Button();
|
||||||
|
Label connectLabel = new Label(100,screenTop + 350,1.0f);
|
||||||
|
connectLabel.setText("Login");
|
||||||
|
connectButton.addChild(connectLabel);
|
||||||
|
rVal.addChild(connectButton);
|
||||||
|
connectButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
|
||||||
|
Globals.clientUsername = usernameInput.getText();
|
||||||
|
Globals.clientPassword = AuthenticationManager.getHashedString(passwordInput.getText());
|
||||||
|
LoadingThread clientThread = new LoadingThread(LoadingThread.LOAD_CHARACTER_SERVER);
|
||||||
|
Globals.loadingThreadsList.add(clientThread);
|
||||||
|
clientThread.start();
|
||||||
|
return false;
|
||||||
|
}});
|
||||||
|
|
||||||
|
//button (back)
|
||||||
|
// Button backButton = new Button();
|
||||||
|
// Label backLabel = new Label(100,screenTop + 425,1.0f);
|
||||||
|
// backLabel.setText("Back");
|
||||||
|
// backButton.addChild(backLabel);
|
||||||
|
// rVal.addChild(backButton);
|
||||||
|
// backButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
|
||||||
|
// WindowUtils.replaceMainMenuContents(MenuGenerators.createMultiplayerMenu());
|
||||||
|
// return false;
|
||||||
|
// }});
|
||||||
|
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -26,8 +26,6 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import org.apache.commons.crypto.stream.CryptoInputStream;
|
|
||||||
import org.apache.commons.crypto.stream.CryptoOutputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@ -14,15 +14,19 @@ public class AuthProtocol {
|
|||||||
case AUTHREQUEST:
|
case AUTHREQUEST:
|
||||||
//Try login
|
//Try login
|
||||||
//TODO: actually get user/pass
|
//TODO: actually get user/pass
|
||||||
Globals.clientConnection.queueOutgoingMessage(AuthMessage.constructAuthDetailsMessage("myuser","mypass"));
|
Globals.clientConnection.queueOutgoingMessage(AuthMessage.constructAuthDetailsMessage(Globals.clientUsername,Globals.clientPassword));
|
||||||
break;
|
break;
|
||||||
case AUTHSUCCESS:
|
case AUTHSUCCESS:
|
||||||
|
//clean password hash from memory
|
||||||
|
Globals.clientPassword = "";
|
||||||
//request playable races
|
//request playable races
|
||||||
Globals.clientConnection.queueOutgoingMessage(LoreMessage.constructRequestRacesMessage());
|
Globals.clientConnection.queueOutgoingMessage(LoreMessage.constructRequestRacesMessage());
|
||||||
|
//log that we succeeded
|
||||||
|
LoggerInterface.loggerAuth.INFO("Successfully logged in");
|
||||||
break;
|
break;
|
||||||
case AUTHFAILURE:
|
case AUTHFAILURE:
|
||||||
//TODO: handle better
|
//TODO: handle better
|
||||||
LoggerInterface.loggerEngine.ERROR("Auth failure",new Exception("Auth failure"));
|
LoggerInterface.loggerAuth.ERROR("Auth failure",new Exception("Auth failure"));
|
||||||
break;
|
break;
|
||||||
//ignore stack
|
//ignore stack
|
||||||
case AUTHDETAILS:
|
case AUTHDETAILS:
|
||||||
|
|||||||
@ -35,8 +35,6 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import org.apache.commons.crypto.stream.CryptoInputStream;
|
|
||||||
import org.apache.commons.crypto.stream.CryptoOutputStream;
|
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user