Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
RCM7 committed Aug 4, 2016
0 parents commit 2073c71
Show file tree
Hide file tree
Showing 231 changed files with 2,291 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ubuntu:trusty

ENV APP_PATH="/app"

RUN mkdir -p $APP_PATH

COPY . $APP_PATH

EXPOSE 8080

WORKDIR $APP_PATH

CMD ["./gameserver.sh"]
5 changes: 5 additions & 0 deletions gameserver.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
port=3905
ssl=false
authenticate=false
host=$(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
hostname=$(hostname -f)
46 changes: 46 additions & 0 deletions gameserver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
#
# This is a sample "gameserver" that answers with a quote to new connections.
# This game assumes you are the only player and that you don't make more than
# one request per second :) Have fun
#

# include config
source $(dirname $0)/gameserver.conf

#variables
LISTEN_PORT=8080
QUOTES_DIR=$(dirname $0)/quotes
QUOTE_NUMBER=227
QUOTE_RANDOM_NUMBER=$(shuf -i 0-$QUOTE_NUMBER -n 1)
WELCOME_MESSAGE_PERIODICITY=5
WELCOME_MESSAGE="
Hey there!
Welcome to the Quote gameserver. Not quite a game, but will do the job!
This is an automatic message from:
$hostname -> [$host]
We share our dirty secrets through port ${port}. Port is blocked though.
Just to let you know, SSL is set to $ssl and Authentication to $authenticate.
Connect again for a quote. Have a nice quoting day!
-- The Quote Gameserver
"

# Control variable to enforce periodicity in loop
X=$(expr $WELCOME_MESSAGE_PERIODICITY + 1)
X=$(shuf -i 0-$X -n 1)

# send a quote on each connection forever
while true; do

# show welcome message
if [ "$X" == $(expr $WELCOME_MESSAGE_PERIODICITY + 1) ]; then
echo -e "$WELCOME_MESSAGE" | nc -lp $LISTEN_PORT -vq0
X=0
else # print a quote
cat ${QUOTES_DIR}/quote${QUOTE_RANDOM_NUMBER}.txt | nc -lp $LISTEN_PORT -vq0
QUOTE_RANDOM_NUMBER=$(shuf -i 0-$QUOTE_NUMBER -n 1)
fi

X=$(expr $X + 1)

done
Loading

0 comments on commit 2073c71

Please sign in to comment.