Even more commands added to server; net bugfixes

This commit is contained in:
Anuken
2018-01-28 23:18:51 -05:00
parent 3562a70669
commit fabc02f6ef
16 changed files with 151 additions and 35 deletions

View File

@@ -49,7 +49,7 @@ public class Vars{
//how much the zoom changes every zoom button press
public static final int zoomScale = Math.round(Unit.dp.scl(1));
//if true, player speed will be increased, massive amounts of resources will be given on start, and other debug options will be available
public static boolean debug = true;
public static boolean debug = false;
public static boolean debugNet = true;
public static boolean console = false;
//whether the player can clip through walls

View File

@@ -12,6 +12,7 @@ import io.anuke.mindustry.game.SpawnPoint;
import io.anuke.mindustry.game.WaveCreator;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.ucore.core.Effects;
@@ -112,6 +113,7 @@ public class Logic extends Module {
if(world.getCore().block() != ProductionBlocks.core && !state.gameOver){
state.gameOver = true;
NetEvents.handleGameOver();
Events.fire(GameOverEvent.class);
}

View File

@@ -1,7 +1,6 @@
package io.anuke.mindustry.core;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.IntSet;
import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.mindustry.core.GameState.State;
@@ -37,9 +36,6 @@ import java.nio.ByteBuffer;
import static io.anuke.mindustry.Vars.*;
public class NetClient extends Module {
public static final Color[] colorArray = {Color.ORANGE, Color.SCARLET, Color.LIME, Color.PURPLE,
Color.GOLD, Color.PINK, Color.SKY, Color.GOLD, Color.VIOLET,
Color.GREEN, Color.CORAL, Color.CYAN, Color.CHARTREUSE};
boolean connecting = false;
boolean gotData = false;
boolean kicked = false;
@@ -184,7 +180,7 @@ public class NetClient extends Module {
Net.handleClient(EnemyDeathPacket.class, spawn -> {
Enemy enemy = enemyGroup.getByID(spawn.id);
if (enemy != null) enemy.onDeath();
if (enemy != null) enemy.type.onDeath(enemy, true);
dead.add(spawn.id);
});
@@ -260,6 +256,7 @@ public class NetClient extends Module {
//duplicates.
if (enemyGroup.getByID(packet.id) != null ||
recieved.contains(packet.id)) return;
recieved.add(packet.id);
Player player = new Player();
@@ -325,10 +322,6 @@ public class NetClient extends Module {
Net.disconnect();
}
public String colorizeName(int id, String name){
return name == null ? null : "[#" + colorArray[id % colorArray.length].toString().toUpperCase() + "]" + name;
}
public void clearRecieved(){
recieved.clear();
dead.clear();

View File

@@ -204,7 +204,7 @@ public class NetServer extends Module{
}
public void update(){
if(!closing && Net.server() && state.is(State.menu)){
if(!headless && !closing && Net.server() && state.is(State.menu)){
closing = true;
weapons.clear();
ui.loadfrag.show("$text.server.closing");

View File

@@ -224,7 +224,7 @@ public class Renderer extends RendererModule{
Draw.color(0f, 0f, 0f, 0.3f);
Draw.rect("blank", player.x, player.y + 8 - layout.height/2, layout.width + 2, layout.height + 2);
Draw.color();
Draw.tcolor(NetClient.colorArray[player.id % NetClient.colorArray.length]);
Draw.tcolor(NetCommon.colorArray[player.id % NetCommon.colorArray.length]);
Draw.text(player.name, player.x, player.y + 8);
Draw.tcolor();
}
@@ -385,7 +385,7 @@ public class Renderer extends RendererModule{
//draw selected block health
if(input.recipe == null && !ui.hasMouse()){
Tile tile = world.tile(tilex, tiley);
Tile tile = world.tileWorld(Graphics.mouseWorld().x, Graphics.mouseWorld().y);
if(tile != null && tile.block() != Blocks.air){
Tile target = tile;

View File

@@ -5,14 +5,19 @@ import com.badlogic.gdx.Gdx;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.game.Difficulty;
import io.anuke.mindustry.game.EventType.GameOverEvent;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.io.SaveIO;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.net.NetEvents;
import io.anuke.mindustry.net.Packets.ChatPacket;
import io.anuke.mindustry.net.Packets.KickReason;
import io.anuke.mindustry.ui.fragments.DebugFragment;
import io.anuke.mindustry.world.Map;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Events;
import io.anuke.ucore.core.Sounds;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.modules.Module;
import io.anuke.ucore.util.CommandHandler;
import io.anuke.ucore.util.CommandHandler.Command;
@@ -31,6 +36,7 @@ import static io.anuke.ucore.util.Log.*;
public class ServerControl extends Module {
private final CommandHandler handler = new CommandHandler("");
private boolean shuffle = true;
public ServerControl(){
Effects.setScreenShakeProvider((a, b) -> {});
@@ -57,24 +63,46 @@ public class ServerControl extends Module {
thread.setDaemon(true);
thread.start();
Events.on(GameOverEvent.class, () -> {
info("Game over!");
Timers.runTask(10f, () -> {
Net.closeServer();
if(shuffle) {
Map previous = world.getMap();
Map map = previous;
while(map == previous) map = world.maps().getDefaultMaps().random();
info("Selected next map to be {0}.", map.name);
state.set(State.playing);
logic.reset();
world.loadMap(map);
host();
}else{
state.set(State.menu);
}
});
});
info("&lcServer loaded. Type &ly'help'&lc for help.");
}
private void registerCommands(){
handler.register("help", "", "Displays this command list.", arg -> {
handler.register("help", "Displays this command list.", arg -> {
info("Commands:");
for(Command command : handler.getCommandList()){
print(" &y" + command.text + (command.params.isEmpty() ? "" : " ") + command.params + " - &lm" + command.description);
}
});
handler.register("exit", "", "Exit the server application.", arg -> {
handler.register("exit", "Exit the server application.", arg -> {
info("Shutting down server.");
Net.dispose();
Gdx.app.exit();
});
handler.register("stop", "", "Stop hosting the server.", arg -> {
handler.register("stop", "Stop hosting the server.", arg -> {
Net.closeServer();
state.set(State.menu);
});
@@ -93,7 +121,7 @@ public class ServerControl extends Module {
}
if(result == null){
err("No map with name &y'{0}'&lg found.", search);
err("No map with name &y'{0}'&lr found.", search);
return;
}
@@ -116,12 +144,18 @@ public class ServerControl extends Module {
host();
});
handler.register("status", "", "Display server status.", arg -> {
handler.register("status", "Display server status.", arg -> {
if(state.is(State.menu)){
info("&lyStatus: &rserver closed");
}else{
info("&lyStatus: &lcPlaying on map &fi{0}&fb &lb/&lc Wave {1} &lb/&lc {2}",
Strings.capitalize(world.getMap().name), state.wave, Strings.capitalize(state.difficulty.name()));
if(state.enemies > 0){
info("&ly{0} enemies remaining.", state.enemies);
}else{
info("&ly{0} seconds until next wave.", (int)(state.wavetime / 60));
}
if(playerGroup.size() > 0) {
info("&lyPlayers: {0}", playerGroup.size());
for (Player p : playerGroup.all()) {
@@ -153,6 +187,73 @@ public class ServerControl extends Module {
}
});
handler.register("friendlyfire", "<on/off>", "Enable or disable friendly fire", arg -> {
String s = arg[0];
if(s.equalsIgnoreCase("on")){
NetEvents.handleFriendlyFireChange(true);
state.friendlyFire = true;
info("Friendly fire enabled.");
}else if(s.equalsIgnoreCase("off")){
NetEvents.handleFriendlyFireChange(false);
state.friendlyFire = false;
info("Friendly fire disabled.");
}else{
err("Incorrect command usage.");
}
});
handler.register("shuffle", "<on/off>", "Enable or disable automatic random map shuffling after gameovers.", arg -> {
String s = arg[0];
if(s.equalsIgnoreCase("on")){
shuffle = true;
info("Map shuffling enabled.");
}else if(s.equalsIgnoreCase("off")){
shuffle = false;
info("Map shuffling disabled.");
}else{
err("Incorrect command usage.");
}
});
handler.register("kick", "<username>", "Kick a person by name.", arg -> {
if(!state.is(State.playing)) {
err("Not hosting a game yet. Calm down.");
return;
}
if(playerGroup.size() == 0){
err("But this server is empty. A barren wasteland.");
return;
}
Player target = null;
for(Player player : playerGroup.all()){
if(player.name.equalsIgnoreCase(arg[0])){
target = player;
break;
}
}
if(target != null){
Net.kickConnection(target.clientid, KickReason.kick);
info("It is done.");
}else{
info("Nobody with that name could be found...");
}
});
handler.register("runwave", "Trigger the next wave.", arg -> {
if(!state.is(State.playing)) {
err("Not hosting. Host a game first.");
}else if(state.enemies > 0){
err("There are still {0} enemies remaining.", state.enemies);
}else{
logic.runWave();
info("Wave spawned.");
}
});
handler.register("load", "<slot>", "Load a save from a slot.", arg -> {
if(state.is(State.playing)){
err("Already hosting. Type 'stop' to stop hosting first.");
@@ -191,7 +292,7 @@ public class ServerControl extends Module {
info("Saved to slot {0}.", slot);
});
handler.register("info", "", "Print debug info", arg -> {
handler.register("info", "Print debug info", arg -> {
info(DebugFragment.debugInfo());
});
}

View File

@@ -164,7 +164,7 @@ public class Player extends SyncEntity{
boolean shooting = !Inputs.keyDown("dash") && Inputs.keyDown("shoot") && control.input().recipe == null
&& !ui.hasMouse() && !control.input().onConfigurable();
if(shooting){
weaponLeft.update(player, true);
weaponRight.update(player, false);

View File

@@ -71,7 +71,7 @@ public class Enemy extends SyncEntity {
@Override
public void onDeath(){
type.onDeath(this);
type.onDeath(this, false);
}
@Override

View File

@@ -236,16 +236,18 @@ public class EnemyType {
public void onShoot(Enemy enemy, BulletType type, float rotation){}
public void onDeath(Enemy enemy){
public void onDeath(Enemy enemy, boolean force){
if(Net.server()){
NetEvents.handleEnemyDeath(enemy);
}
Effects.effect(Fx.explosion, enemy);
Effects.shake(3f, 4f, enemy);
Effects.sound("bang2", enemy);
enemy.remove();
enemy.dead = true;
if(!Net.client() || force) {
Effects.effect(Fx.explosion, enemy);
Effects.shake(3f, 4f, enemy);
Effects.sound("bang2", enemy);
enemy.remove();
enemy.dead = true;
}
}
public void removed(Enemy enemy){

View File

@@ -40,8 +40,8 @@ public class BlastType extends EnemyType {
}
@Override
public void onDeath(Enemy enemy){
super.onDeath(enemy);
public void onDeath(Enemy enemy, boolean force){
super.onDeath(enemy, force);
explode(enemy);
}

View File

@@ -50,8 +50,8 @@ public class TargetType extends EnemyType {
}
@Override
public void onDeath(Enemy enemy){
super.onDeath(enemy);
public void onDeath(Enemy enemy, boolean force){
super.onDeath(enemy, force);
Timers.run(100f, ()->{
new Enemy(EnemyTypes.target).set(enemy.x, enemy.y).add();
});

View File

@@ -18,6 +18,7 @@ import static io.anuke.mindustry.Vars.*;
public class Maps implements Disposable{
private IntMap<Map> maps = new IntMap<>();
private ObjectMap<String, Map> mapNames = new ObjectMap<>();
private Array<Map> defaultMaps = new Array<>();
private Map networkMap;
private int lastID;
private Json json = new Json();
@@ -32,6 +33,10 @@ public class Maps implements Disposable{
return maps.values();
}
public Array<Map> getDefaultMaps(){
return defaultMaps;
}
public void setNetworkMap(Map map){
if(networkMap != null){
networkMap.pixmap.dispose();
@@ -147,6 +152,9 @@ public class Maps implements Disposable{
maps.put(map.id, map);
mapNames.put(map.name, map);
lastID = Math.max(lastID, map.id);
if(!map.custom){
defaultMaps.add(map);
}
}
}
return true;

View File

@@ -10,7 +10,6 @@ import io.anuke.mindustry.net.Packets.*;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.Entity;
import static io.anuke.mindustry.Vars.*;
@@ -29,7 +28,7 @@ public class NetEvents {
public static void handleGameOver(){
Net.send(new GameOverPacket(), SendMode.tcp);
state.gameOver = true;
Timers.runTask(30f, () -> state.set(State.menu));
state.set(State.menu);
}
public static void handleBullet(BulletType type, Entity owner, float x, float y, float angle, short damage){

View File

@@ -178,6 +178,10 @@ public class ChatFragment extends Table implements Fragment{
return chatOpen;
}
public int getMessagesSize(){
return messages.size;
}
public void addMessage(String message, String sender){
messages.insert(0, new ChatMessage(message, sender));

View File

@@ -1,6 +1,7 @@
package io.anuke.mindustry.ui.fragments;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.entities.enemies.EnemyTypes;
import io.anuke.mindustry.net.Net;
@@ -75,7 +76,11 @@ public class DebugFragment implements Fragment {
row();
new button("dump", () -> {
try{
Gdx.files.local("packet-dump.txt").writeString(debugInfo(), false);
FileHandle file = Gdx.files.local("packet-dump.txt");
file.writeString("--INFO--\n", false);
file.writeString(debugInfo(), true);
file.writeString("--LOG--\n\n", true);
file.writeString(log.toString(), true);
}catch (Exception e){
ui.showError("Error dumping log.");
}
@@ -101,6 +106,8 @@ public class DebugFragment implements Fragment {
return join(
"net.active: " + Net.active(),
"net.server: " + Net.server(),
"chat.open: " + ui.chatfrag.chatOpen(),
"chat.messages: " + ui.chatfrag.getMessagesSize(),
"players: " + playerGroup.size(),
"enemies: " + enemyGroup.size(),
"tiles: " + tileGroup.size(),