mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-19 18:46:43 +00:00
add secretKey field to GameServer
This commit is contained in:
parent
98402dd45b
commit
71f96f27d1
@ -1,12 +1,12 @@
|
|||||||
package net.simon987.server;
|
package net.simon987.server;
|
||||||
|
|
||||||
|
|
||||||
import com.mongodb.MongoClient;
|
import com.mongodb.MongoClient;
|
||||||
import com.mongodb.client.MongoCollection;
|
import com.mongodb.client.MongoCollection;
|
||||||
import com.mongodb.client.MongoCursor;
|
import com.mongodb.client.MongoCursor;
|
||||||
import com.mongodb.client.MongoDatabase;
|
import com.mongodb.client.MongoDatabase;
|
||||||
import com.mongodb.client.model.ReplaceOptions;
|
import com.mongodb.client.model.ReplaceOptions;
|
||||||
import net.simon987.server.crypto.CryptoProvider;
|
import net.simon987.server.crypto.CryptoProvider;
|
||||||
|
import net.simon987.server.crypto.SecretKeyGenerator;
|
||||||
import net.simon987.server.event.GameEvent;
|
import net.simon987.server.event.GameEvent;
|
||||||
import net.simon987.server.event.GameEventDispatcher;
|
import net.simon987.server.event.GameEventDispatcher;
|
||||||
import net.simon987.server.event.TickEvent;
|
import net.simon987.server.event.TickEvent;
|
||||||
@ -54,6 +54,8 @@ public class GameServer implements Runnable {
|
|||||||
|
|
||||||
private GameRegistry gameRegistry;
|
private GameRegistry gameRegistry;
|
||||||
|
|
||||||
|
private String secretKey;
|
||||||
|
|
||||||
public GameServer() {
|
public GameServer() {
|
||||||
this.config = new ServerConfiguration("config.properties");
|
this.config = new ServerConfiguration("config.properties");
|
||||||
|
|
||||||
@ -76,6 +78,12 @@ public class GameServer implements Runnable {
|
|||||||
|
|
||||||
dayNightCycle = new DayNightCycle();
|
dayNightCycle = new DayNightCycle();
|
||||||
|
|
||||||
|
SecretKeyGenerator keyGenerator = new SecretKeyGenerator();
|
||||||
|
secretKey = config.getString("secret_key");
|
||||||
|
if (secretKey == null) {
|
||||||
|
secretKey = keyGenerator.generate();
|
||||||
|
}
|
||||||
|
|
||||||
//Load all plugins in plugins folder, if it doesn't exist, create it
|
//Load all plugins in plugins folder, if it doesn't exist, create it
|
||||||
File pluginDir = new File("plugins/");
|
File pluginDir = new File("plugins/");
|
||||||
File[] pluginDirListing = pluginDir.listFiles();
|
File[] pluginDirListing = pluginDir.listFiles();
|
||||||
@ -176,12 +184,10 @@ public class GameServer implements Runnable {
|
|||||||
user.getControlledUnit().getCpu().reset();
|
user.getControlledUnit().getCpu().reset();
|
||||||
int cost = user.getControlledUnit().getCpu().execute(timeout);
|
int cost = user.getControlledUnit().getCpu().execute(timeout);
|
||||||
user.getControlledUnit().spendEnergy(cost);
|
user.getControlledUnit().spendEnergy(cost);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogManager.LOGGER.severe("Error executing " + user.getUsername() + "'s code");
|
LogManager.LOGGER.severe("Error executing " + user.getUsername() + "'s code");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,4 +318,12 @@ public class GameServer implements Runnable {
|
|||||||
public GameRegistry getRegistry() {
|
public GameRegistry getRegistry() {
|
||||||
return gameRegistry;
|
return gameRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSecretKey() {
|
||||||
|
return secretKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecretKey(String secretKey) {
|
||||||
|
this.secretKey = secretKey;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user