Skip to content

Commit

Permalink
- fixed messaging protocol (expect 8-byte length header).
Browse files Browse the repository at this point in the history
- added tag option to UE4Python git pull
  • Loading branch information
sven1977 committed Feb 19, 2018
1 parent bae83c9 commit c388324
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 18 deletions.
28 changes: 22 additions & 6 deletions Plugins/MaRLEnE/Scripts/marlene_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,31 @@ def send_message(message, writer):
# this is called whenever a new client connects
async def new_client_connected(reader, writer):
name = writer.get_extra_info("peername")
ue.log("new client connection from {0}".format(name))
unpacker = msgpack.Unpacker()
ue.log("New client connection from {0}".format(name))
unpacker = msgpack.Unpacker(encoding="utf-8")
while True:
# wait for a line
# TODO: what if incoming command is longer than 8192? -> Add len field to beginning of messages (in both directions)
data = await reader.read(8192)
data = await reader.read(8) # read the num-byte header
if not data:
break
unpacker.feed(data)

# Read the incoming message.
orig_len = int(data)
received_len = 0
while True:
data = reader.read(min(orig_len - received_len, 8192))
if not data:
send_message({"status": "error",
"message": "No data of len {} received by socket.recv in call to method `recv`!".
format(orig_len - received_len)}, writer)
data_len = len(data)
received_len += data_len
unpacker.feed(data)

if received_len == orig_len:
break

# Get the data.
for message in unpacker:
if not isinstance(message, dict):
response = {"status": "error", "message": "Unknown message type ({})!".format(type(message).__name__)}
Expand All @@ -277,7 +293,7 @@ async def new_client_connected(reader, writer):
send_message(response, writer)
# async calls -> do nothing here (async will handle it)

ue.log('client {0} disconnected'.format(name))
ue.log('Client {0} disconnected'.format(name))


# this spawns the server
Expand Down
3 changes: 1 addition & 2 deletions Plugins/MaRLEnE/Scripts/ue_site.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Basic python file that gets executed when the UE4 Game starts
# - place imports here to start our modules

import marlene_server
import unreal_engine as ue

# load the GeneralProjjectSettings class
# (could be that classes are not loaded yet when ue_site (this script) is executed)
ue.load_class("/Script/EngineSettings.GeneralProjectSettings")


import marlene_server
10 changes: 5 additions & 5 deletions docker/ue4_exec_game/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# to build a final game image that only contains the cooked game executable

ARG base_img=ue4_alien
ARG base_img=ducandu/ue4_alien_invaders

# the base image to copy from
FROM ducandu/$base_img AS game_img
FROM $base_img AS game_img

# new container based on Ubuntu
FROM ubuntu:xenial
Expand Down Expand Up @@ -32,13 +32,13 @@ COPY --from=game_img --chown=ue4:ue4 /home/ue4/UnrealEngine/${GAME}/Build/LinuxN
RUN mkdir -p AlienInvaders/Content/Scripts
COPY --from=game_img --chown=ue4:ue4 /home/ue4/UnrealEngine/${GAME}/Content/Scripts ${GAME}/Content/Scripts/

# add to PYTHONPATH: Games/[the GAME]/Content/Scripts to env
# add to PYTHONPATH: Games/[the GAME]/Content/Scripts
ENV PYTHONPATH=/home/ue4/Games/${GAME}/Content/Scripts

# start the game automatically when running this container
CMD /home/ue4/Games/${GAME}.sh -NullRHI -nosound

# run this container with
# `docker run -d --name aliens ducandu/ue4_[game]_final`
# run this container (detached) and with port 6025 open for listening with (no need for --network option!!):
# `docker run -it -d --name [e.g aliens] -p 6025:6025 ducandu/ue4_[game]_final`
# login to this container via
# `docker exec -ti [container name] bash`
15 changes: 10 additions & 5 deletions docker/ue4_game/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,41 @@
# game=[the project's name, e.g. AlienInvaders (default)]
# base_img=[the base image to use: `ue4` for initial build, or `ue4_alien_invaders` for an already built game]

ARG base_img=ue4
ARG base_img=ducandu/ue4

FROM ducandu/$base_img
FROM $base_img

USER ue4
WORKDIR /home/ue4

# default game; override this via `--build-arg game=` on `docker build` command line
ARG base_img=ue4
ARG base_img=ducandu/ue4
ENV BASE_IMG=$base_img
ARG game=AlienInvaders
ENV GAME=$game
ARG ue4python_tag=20180217
ENV UE4PYTHON_TAG=$ue4python_tag

COPY --chown=ue4:ue4 build_game_init.sh .
COPY --chown=ue4:ue4 build_game_incr.sh .
RUN dos2unix build_game_init.sh
RUN dos2unix build_game_incr.sh
RUN chmod 0777 build_game_init.sh && chmod 0777 build_game_incr.sh
RUN if [ "${BASE_IMG}" = "ue4" ] ; then /bin/sh ./build_game_init.sh ; else /bin/sh ./build_game_incr.sh ; fi
RUN if [ "${BASE_IMG}" = "ducandu/ue4" ] ; then /bin/sh ./build_game_init.sh ; else /bin/sh ./build_game_incr.sh ; fi

WORKDIR UnrealEngine
## Modify the UnrealEnginePython build cs file to add the python lib and include paths
# not necessary as ubuntu is covered by the default values in UEPython build cs
#RUN sed -i 's/\/usr\/local\/include\/python3.6//' AlienInvaders/Plugins/UnrealEnginePython/Source/UnrealEnginePython/UnrealEnginePython.Build.cs

# TODO: remove again (overwrite UEPython plugin as it's sometimes full of build errors)
#COPY --chown=ue4:ue4 test ${GAME}/Plugins

# - copy necessary scripts from the plugin to the game's content folder
RUN mkdir -p ${GAME}/Content/Scripts/
RUN cp -u ${GAME}/Plugins/MaRLEnE/Scripts/* ${GAME}/Content/Scripts/.

# build and cook the game
RUN Engine/Build/BatchFiles/RunUAT.sh BuildCookRun -project=${GAME}/${GAME}.uproject -nop4 -build -cook -compressed -stage -platform=Linux -clientconfig=Development -pak -archive -archivedirectory="${GAME}/Build" -utf8output
#RUN Engine/Build/BatchFiles/RunUAT.sh BuildCookRun -project=${GAME}/${GAME}.uproject -nop4 -build -cook -compressed -stage -platform=Linux -clientconfig=Development -pak -archive -archivedirectory="${GAME}/Build" -utf8output

CMD ["bash"]
6 changes: 6 additions & 0 deletions docker/ue4_game/build_game_init.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/sh

echo "GAME=$GAME"
echo "UE4PYTHON_TAG=$UE4PYTHON_TAG"

cd

mkdir -p UnrealEngine/${GAME}/Plugins

Expand All @@ -11,5 +14,8 @@ cp -r marlene/examples/UE4Games/${GAME} UnrealEngine/.
cp -r marlene/Plugins/MaRLEnE UnrealEngine/${GAME}/Plugins/.

git clone https://github.com/20tab/UnrealEnginePython.git
cd UnrealEnginePython
git checkout tags/${UE4PYTHON_TAG}
cd ../
cp -r UnrealEnginePython UnrealEngine/${GAME}/Plugins/.

0 comments on commit c388324

Please sign in to comment.