Work in progress create game API

This commit is contained in:
Retera 2022-04-23 00:39:12 -04:00
parent 5240f17480
commit 528d228c9a
8 changed files with 59 additions and 20 deletions

View File

@ -11,6 +11,7 @@ import net.warsmash.uberserver.GamingNetworkClientToServerWriter;
import net.warsmash.uberserver.GamingNetworkConnection;
import net.warsmash.uberserver.GamingNetworkServerToClientListener;
import net.warsmash.uberserver.GamingNetworkServerToClientListener.GamingNetworkServerToClientNotifier;
import net.warsmash.uberserver.HostedGameVisibility;
import net.warsmash.uberserver.LobbyGameSpeed;
import net.warsmash.uberserver.TCPGamingNetworkServerToClientParser;
@ -104,9 +105,9 @@ public class GamingNetworkConnectionImpl implements GamingNetworkConnection {
@Override
public void createGame(final long sessionToken, final String gameName, final String mapName, final int totalSlots,
final LobbyGameSpeed gameSpeed, final long gameCreationTimeMillis) {
final LobbyGameSpeed gameSpeed, final long gameCreationTimeMillis, final HostedGameVisibility visibility) {
this.gamingNetworkClientToServerWriter.createGame(sessionToken, gameName, mapName, totalSlots, gameSpeed,
gameCreationTimeMillis);
gameCreationTimeMillis, visibility);
}
@Override

View File

@ -8,7 +8,7 @@ public class WarsmashConstants {
* With version, we use 0 for RoC, 1 for TFT emulation, and probably 2+ or
* whatever for custom mods and other stuff
*/
public static int GAME_VERSION = 1;
public static int GAME_VERSION = 0;
public static final int REPLACEABLE_TEXTURE_LIMIT = 64;
public static final float SIMULATION_STEP_TIME = 1 / 20f;
public static final int PORT_NUMBER = 6115;

View File

@ -224,7 +224,7 @@ public class CSimulation implements CPlayerAPI {
this.handleIdToUnit.put(unit.getHandleId(), unit);
this.worldCollision.addUnit(unit);
if (unit.getHeroData() != null) {
this.heroCreateEvent(unit);
heroCreateEvent(unit);
}
return unit;
}
@ -325,11 +325,11 @@ public class CSimulation implements CPlayerAPI {
}
this.handleIdToUnit.remove(unit.getHandleId());
this.simulationRenderController.removeUnit(unit);
this.getPlayerHeroes(unit.getPlayerIndex()).remove(unit);
getPlayerHeroes(unit.getPlayerIndex()).remove(unit);
unit.onRemove(this);
}
}
this.finishAddingNewUnits();
finishAddingNewUnits();
final Iterator<CAttackProjectile> projectileIterator = this.projectiles.iterator();
while (projectileIterator.hasNext()) {
final CAttackProjectile projectile = projectileIterator.next();
@ -343,23 +343,23 @@ public class CSimulation implements CPlayerAPI {
pathfindingProcessor.update(this);
}
this.gameTurnTick++;
final float timeOfDayBefore = this.getGameTimeOfDay();
final float timeOfDayBefore = getGameTimeOfDay();
if (!this.timeOfDaySuspended) {
this.currentGameDayTimeElapsed = (this.currentGameDayTimeElapsed + WarsmashConstants.SIMULATION_STEP_TIME)
% this.gameplayConstants.getGameDayLength();
}
final float timeOfDayAfter = this.getGameTimeOfDay();
final float timeOfDayAfter = getGameTimeOfDay();
this.daytime = (timeOfDayAfter >= this.gameplayConstants.getDawnTimeGameHours())
&& (timeOfDayAfter < this.gameplayConstants.getDuskTimeGameHours());
for (final CTimer timer : this.addedTimers) {
this.internalRegisterTimer(timer);
internalRegisterTimer(timer);
}
this.addedTimers.clear();
while (!this.activeTimers.isEmpty() && (this.activeTimers.peek().getEngineFireTick() <= this.gameTurnTick)) {
this.activeTimers.pop().fire(this);
}
for (final CTimer timer : this.removedTimers) {
this.internalUnregisterTimer(timer);
internalUnregisterTimer(timer);
}
this.removedTimers.clear();
for (final TimeOfDayVariableEvent timeOfDayEvent : this.timeOfDayVariableEvents) {
@ -384,7 +384,7 @@ public class CSimulation implements CPlayerAPI {
}
this.handleIdToUnit.remove(unit.getHandleId());
this.simulationRenderController.removeUnit(unit);
this.getPlayerHeroes(unit.getPlayerIndex()).remove(unit);
getPlayerHeroes(unit.getPlayerIndex()).remove(unit);
unit.onRemove(this);
}
this.removedUnits.clear();
@ -493,7 +493,7 @@ public class CSimulation implements CPlayerAPI {
}
public void heroCreateEvent(final CUnit hero) {
this.getPlayerHeroes(hero.getPlayerIndex()).add(hero);
getPlayerHeroes(hero.getPlayerIndex()).add(hero);
}
public void unitPickUpItemEvent(final CUnit cUnit, final CItem item) {
@ -511,7 +511,7 @@ public class CSimulation implements CPlayerAPI {
public void unitsLoaded() {
// called on startup after the system loads the map's units layer, but not any
// custom scripts yet
this.finishAddingNewUnits();
finishAddingNewUnits();
for (final CUnit unit : this.units) {
final CPlayer player = this.players.get(unit.getPlayerIndex());
player.setUnitFoodUsed(unit, unit.getUnitType().getFoodUsed());
@ -588,7 +588,7 @@ public class CSimulation implements CPlayerAPI {
}
public void heroDissipateEvent(final CUnit cUnit) {
this.getPlayer(cUnit.getPlayerIndex()).onHeroDeath(cUnit);
getPlayer(cUnit.getPlayerIndex()).onHeroDeath(cUnit);
}
public void removeItem(final CItem cItem) {

View File

@ -2,6 +2,7 @@ package com.etheller.warsmash.networking.uberserver;
import net.warsmash.nio.channels.WritableOutput;
import net.warsmash.uberserver.GamingNetworkClientToServerListener;
import net.warsmash.uberserver.HostedGameVisibility;
import net.warsmash.uberserver.LobbyGameSpeed;
public class DefaultGamingNetworkServerClientBuilder implements GamingNetworkServerClientBuilder {
@ -69,7 +70,8 @@ public class DefaultGamingNetworkServerClientBuilder implements GamingNetworkSer
@Override
public void createGame(final long sessionToken, final String gameName, final String mapName,
final int totalSlots, final LobbyGameSpeed gameSpeed, final long gameCreationTimeMillis) {
final int totalSlots, final LobbyGameSpeed gameSpeed, final long gameCreationTimeMillis,
final HostedGameVisibility visibility) {
throw new UnsupportedOperationException();
}
};

View File

@ -8,6 +8,8 @@ import com.etheller.warsmash.util.War3ID;
import net.warsmash.nio.channels.tcp.TCPClientParser;
import net.warsmash.uberserver.GamingNetwork;
import net.warsmash.uberserver.GamingNetworkClientToServerListener;
import net.warsmash.uberserver.HostedGameVisibility;
import net.warsmash.uberserver.LobbyGameSpeed;
public class TCPGamingNetworkServerClientParser implements TCPClientParser {
private final GamingNetworkClientToServerListener listener;
@ -61,6 +63,31 @@ public class TCPGamingNetworkServerClientParser implements TCPClientParser {
this.listener.emoteMessage(sessionToken, text);
break;
}
case GamingNetworkClientToServerListener.Protocol.QUERY_GAMES_LIST: {
final long sessionToken = data.getLong();
this.listener.queryGamesList(sessionToken);
}
case GamingNetworkClientToServerListener.Protocol.QUERY_GAME_INFO: {
final long sessionToken = data.getLong();
final String gameName = readString(GamingNetwork.CHANNEL_NAME_MAX_LENGTH, data);
this.listener.queryGameInfo(sessionToken, gameName);
}
case GamingNetworkClientToServerListener.Protocol.JOIN_GAME: {
final long sessionToken = data.getLong();
final String gameName = readString(GamingNetwork.CHANNEL_NAME_MAX_LENGTH, data);
this.listener.joinGame(sessionToken, gameName);
}
case GamingNetworkClientToServerListener.Protocol.CREATE_GAME: {
final long sessionToken = data.getLong();
final String gameName = readString(GamingNetwork.CHANNEL_NAME_MAX_LENGTH, data);
final String mapName = readString(GamingNetwork.MAP_NAME_MAX_LENGTH, data);
final int totalSlots = data.getInt();
final LobbyGameSpeed gameSpeed = LobbyGameSpeed.VALUES[data.getInt()];
final long gameCreationTimeMillis = data.getLong();
final HostedGameVisibility visibility = HostedGameVisibility.VALUES[data.getInt()];
this.listener.createGame(sessionToken, gameName, mapName, totalSlots, gameSpeed,
gameCreationTimeMillis, visibility);
}
default:
break;
}

View File

@ -21,8 +21,8 @@ public interface GamingNetworkClientToServerListener extends DisconnectListener
void joinGame(long sessionToken, String gameName);
void createGame(long sessionToken, String gameName, String mapName, int totalSlots, LobbyGameSpeed gameSpeed,
long gameCreationTimeMillis);
void createGame(final long sessionToken, final String gameName, final String mapName, final int totalSlots,
final LobbyGameSpeed gameSpeed, final long gameCreationTimeMillis, HostedGameVisibility visibility);
class Protocol {
public static final int HANDSHAKE = 1;

View File

@ -97,7 +97,8 @@ public class GamingNetworkClientToServerWriter extends AbstractWriter implements
@Override
public void queryGamesList(final long sessionToken) {
beginMessage(Protocol.QUERY_GAMES_LIST, 0);
beginMessage(Protocol.QUERY_GAMES_LIST, 8);
this.writeBuffer.putLong(sessionToken);
send();
}
@ -129,7 +130,7 @@ public class GamingNetworkClientToServerWriter extends AbstractWriter implements
@Override
public void createGame(final long sessionToken, String gameName, String mapName, final int totalSlots,
final LobbyGameSpeed gameSpeed, final long gameCreationTimeMillis) {
final LobbyGameSpeed gameSpeed, final long gameCreationTimeMillis, final HostedGameVisibility visibility) {
if (gameName.length() > GamingNetwork.CHANNEL_NAME_MAX_LENGTH) {
gameName = gameName.substring(0, GamingNetwork.CHANNEL_NAME_MAX_LENGTH);
}
@ -138,7 +139,7 @@ public class GamingNetworkClientToServerWriter extends AbstractWriter implements
mapName = mapName.substring(0, GamingNetwork.MAP_NAME_MAX_LENGTH);
}
final byte[] mapNameBytes = mapName.getBytes(Charset.forName("utf-8"));
beginMessage(Protocol.CREATE_GAME, 8 + 4 + channelNameBytes.length + 4 + mapNameBytes.length + 4 + 4 + 8);
beginMessage(Protocol.CREATE_GAME, 8 + 4 + channelNameBytes.length + 4 + mapNameBytes.length + 4 + 4 + 8 + 4);
this.writeBuffer.putLong(sessionToken);
this.writeBuffer.putInt(channelNameBytes.length);
this.writeBuffer.put(channelNameBytes);
@ -147,6 +148,7 @@ public class GamingNetworkClientToServerWriter extends AbstractWriter implements
this.writeBuffer.putInt(totalSlots);
this.writeBuffer.putInt(gameSpeed.ordinal());
this.writeBuffer.putLong(gameCreationTimeMillis);
this.writeBuffer.putInt(visibility.ordinal());
send();
}

View File

@ -0,0 +1,7 @@
package net.warsmash.uberserver;
public enum HostedGameVisibility {
PUBLIC, PRIVATE;
public static HostedGameVisibility VALUES[] = values();
}