20 package net.sf.gridarta.var.atrinik.actions;
22 import java.io.ByteArrayOutputStream;
23 import java.io.IOException;
24 import java.io.OutputStream;
25 import java.net.Socket;
31 import org.jetbrains.annotations.NotNull;
90 private void sendPacket(@NotNull
final ByteArrayOutputStream stream)
throws IOException {
91 final byte[] packet = stream.toByteArray();
92 packet[0] = (byte) ((packet.length - 2) >> 8);
93 packet[1] = (byte) (packet.length - 2);
95 try (Socket socket =
new Socket(
"127.0.0.1", 13327)) {
96 final OutputStream outputStream = socket.getOutputStream();
97 outputStream.write(packet);
98 socket.shutdownOutput();
100 }
catch (
final IOException ex) {
101 throw new IOException(
"127.0.0.1:13327: " + ex.getMessage(), ex);
106 protected void resetMap(@NotNull
final String mapPath)
throws IOException {
107 final ByteArrayOutputStream tmp =
new ByteArrayOutputStream();
110 tmp.write(SERVER_CMD_CONTROL);
111 tmp.write(APPLICATION_NAME_IDENTIFIER.getBytes(CHARSET_NAME));
113 tmp.write(CMD_CONTROL_MAP);
114 tmp.write(CMD_CONTROL_MAP_RESET);
115 tmp.write(mapPath.getBytes(CHARSET_NAME));
121 protected void teleportCharacterToMap(@NotNull
final String mapPath,
final int mapX,
final int mapY)
throws IOException {
122 final ByteArrayOutputStream tmp =
new ByteArrayOutputStream();
125 tmp.write(SERVER_CMD_CONTROL);
126 tmp.write(APPLICATION_NAME_IDENTIFIER.getBytes(CHARSET_NAME));
128 tmp.write(CMD_CONTROL_PLAYER);
129 tmp.write(CMD_CONTROL_PLAYER_TELEPORT);
131 tmp.write(mapPath.getBytes(CHARSET_NAME));
133 tmp.write(mapX >> 8);
135 tmp.write(mapY >> 8);
void teleportCharacterToMap(@NotNull final String mapPath, final int mapX, final int mapY)
final FileControl< G, A, R > fileControl
The file control for saving maps.
Implements Atrinik archetypes.
Handles the Atrinik variants of GameObjects and Archetypes.
AtrinikServerActions(@NotNull final FileControl< GameObject, MapArchObject, Archetype > fileControl)
Creates a new instance.
void sendPacket(@NotNull final ByteArrayOutputStream stream)
Send a bytes packet to the Atrinik server instance.
static final String APPLICATION_NAME_IDENTIFIER
The name of the application requesting control.
static final String CHARSET_NAME
The charset name for encoding strings in the protocol.
static final int SERVER_CMD_CONTROL
Command type.
Actions that require a connection to a game server.
static final int CMD_CONTROL_PLAYER
Control command type: control a player.
Base package of all Gridarta classes.
static final int CMD_CONTROL_MAP_RESET
Control command sub-type: reset a map.
Main package of Gridarta4Atrinik, contains all classes specific to the Atrinik version of the Gridart...
MapArchObject contains the specific meta data about a map that is stored in the map-arch, at the very beginning of the map file.
void resetMap(@NotNull final String mapPath)
static final int CMD_CONTROL_MAP
Control command type: control a map.
The AbstractServerActions implementation for connecting to an Atrinik server.
Handles the Atrinik GameObjects.
static final int CMD_CONTROL_PLAYER_TELEPORT
Control command sub-type: teleport character to map.