Compare commits
29 Commits
Author | SHA1 | Date | |
---|---|---|---|
949549caff | |||
3b5ca90cfb | |||
95d52a8866 | |||
3b9e5d2ece | |||
9145747e20 | |||
ee233c52f0 | |||
948b379f9d | |||
ddf5275a37 | |||
ce9afe339c | |||
fee56c6042 | |||
e2a8f446bb | |||
bec4209232 | |||
b93240f992 | |||
31831ff9d1 | |||
db37a8c924 | |||
11a41fdca7 | |||
f4e1d3a3b8 | |||
4caab69266 | |||
15f6a8df22 | |||
fb236647a3 | |||
5fbbfba593 | |||
84f6ca7434 | |||
9a6ba77e72 | |||
b94b469c39 | |||
6eaa057da8 | |||
7ca5c63131 | |||
70b8236f4e | |||
77965b715f | |||
1ceff14887 |
84
.github/workflows/build_stage.yml
vendored
Normal file
84
.github/workflows/build_stage.yml
vendored
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
name: Build Stage
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
godot:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
platform: [linux]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Download Export Template
|
||||||
|
env:
|
||||||
|
PLATFORM: ${{ matrix.platform }}
|
||||||
|
run: |
|
||||||
|
mkdir -p client/templates
|
||||||
|
wget http://godot-enet.cloudsumu.com.s3-website-us-east-1.amazonaws.com/export-templates/debug/$PLATFORM -O client/templates/$PLATFORM
|
||||||
|
- name: Build
|
||||||
|
id: build
|
||||||
|
uses: josephbmanley/build-godot-action@v1.4.0
|
||||||
|
with:
|
||||||
|
name: defend-together
|
||||||
|
preset: ${{ matrix.platform }}
|
||||||
|
projectDir: client
|
||||||
|
debugMode: 'true'
|
||||||
|
package: 'true'
|
||||||
|
- name: Upload Artifact
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: Client - ${{ matrix.platform }}
|
||||||
|
path: ${{ github.workspace }}/${{ steps.build.outputs.build }}
|
||||||
|
docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
- name: Push Tag to Docker Hub
|
||||||
|
uses: opspresso/action-docker@master
|
||||||
|
with:
|
||||||
|
args: --docker
|
||||||
|
env:
|
||||||
|
USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
BUILD_PATH: "server"
|
||||||
|
DOCKERFILE: "server/Dockerfile"
|
||||||
|
IMAGE_NAME: "josephbmanley/defend-together"
|
||||||
|
TAG_NAME: "stage"
|
||||||
|
LATEST: "false"
|
||||||
|
cloudformation:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@v2.1.0
|
||||||
|
with:
|
||||||
|
submodules: 'true'
|
||||||
|
- name: Ship to S3
|
||||||
|
uses: jakejarvis/s3-sync-action@master
|
||||||
|
with:
|
||||||
|
args: --follow-symlinks --delete
|
||||||
|
env:
|
||||||
|
SOURCE_DIR: infrastructure/cloudformation
|
||||||
|
AWS_REGION: "us-east-1"
|
||||||
|
DEST_DIR: dt/stage/cloudformation
|
||||||
|
AWS_S3_BUCKET: sumu-stacks
|
||||||
|
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||||
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||||
|
- name: Configure AWS Credentials
|
||||||
|
uses: aws-actions/configure-aws-credentials@v1
|
||||||
|
with:
|
||||||
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||||
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||||
|
aws-region: us-east-1
|
||||||
|
- name: Deploy to AWS CloudFormation
|
||||||
|
uses: aws-actions/aws-cloudformation-github-deploy@v1
|
||||||
|
with:
|
||||||
|
name: dt-infrastructure-stage
|
||||||
|
template: infrastructure/cloudformation/dt/top.yaml
|
||||||
|
capabilities: "CAPABILITY_NAMED_IAM,CAPABILITY_IAM"
|
||||||
|
parameter-overrides: VpcId=${{ secrets.VPC_ID }},SubDomain=stage.dt,Domain=${{ secrets.DOMAIN }},environment=stage,DockerTag=stage,release=stage,PublicSubnets=${{ secrets.SUBNET_IDS }}
|
26
.github/workflows/push_dev_infrastructure.yml
vendored
Normal file
26
.github/workflows/push_dev_infrastructure.yml
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
name: Push Dev Infrastructure
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches-ignore:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@v2.1.0
|
||||||
|
with:
|
||||||
|
submodules: 'true'
|
||||||
|
- name: Ship to S3
|
||||||
|
uses: jakejarvis/s3-sync-action@master
|
||||||
|
with:
|
||||||
|
args: --follow-symlinks --delete
|
||||||
|
env:
|
||||||
|
SOURCE_DIR: infrastructure/cloudformation
|
||||||
|
AWS_REGION: "us-east-1"
|
||||||
|
DEST_DIR: dt/develop/cloudformation
|
||||||
|
AWS_S3_BUCKET: sumu-stacks
|
||||||
|
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||||
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
142
.github/workflows/release.yml
vendored
Normal file
142
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
name: Release Server
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types:
|
||||||
|
- created
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
godot:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
platform: [linux]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Download Export Template
|
||||||
|
env:
|
||||||
|
PLATFORM: ${{ matrix.platform }}
|
||||||
|
run: |
|
||||||
|
mkdir -p client/templates
|
||||||
|
wget http://godot-enet.cloudsumu.com.s3-website-us-east-1.amazonaws.com/export-templates/debug/$PLATFORM -O client/templates/$PLATFORM
|
||||||
|
- name: Build
|
||||||
|
id: build
|
||||||
|
uses: josephbmanley/build-godot-action@v1.4.0
|
||||||
|
with:
|
||||||
|
name: defend-together
|
||||||
|
preset: ${{ matrix.platform }}
|
||||||
|
projectDir: client
|
||||||
|
debugMode: 'true'
|
||||||
|
package: 'true'
|
||||||
|
- id: get_tag
|
||||||
|
name: Get Tag
|
||||||
|
env:
|
||||||
|
GITHUB_HEAD_REF: $${{ github.head_ref }}
|
||||||
|
GITHUB_BASE_REF: ${{ github.base_ref }}
|
||||||
|
run: |
|
||||||
|
TAG=$(jq --raw-output '.release.tag_name' $GITHUB_EVENT_PATH)
|
||||||
|
echo ::set-output name=TAG::$TAG
|
||||||
|
- name: Push to Itch
|
||||||
|
uses: josephbmanley/butler-publish-itchio-action@v1.0.1
|
||||||
|
env:
|
||||||
|
BUTLER_CREDENTIALS: ${{ secrets.BUTLER_CREDENTIALS }}
|
||||||
|
CHANNEL: ${{ matrix.platform }}
|
||||||
|
ITCH_GAME: defend-together
|
||||||
|
ITCH_USER: josephbmanley
|
||||||
|
PACKAGE: ${{ github.workspace }}/${{ steps.build.outputs.build }}
|
||||||
|
VERSION: ${{ steps.get_tag.outputs.TAG }}
|
||||||
|
docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
- id: get_tag
|
||||||
|
name: Get Tag
|
||||||
|
env:
|
||||||
|
GITHUB_HEAD_REF: $${{ github.head_ref }}
|
||||||
|
GITHUB_BASE_REF: ${{ github.base_ref }}
|
||||||
|
run: |
|
||||||
|
TAG=$(jq --raw-output '.release.tag_name' $GITHUB_EVENT_PATH)
|
||||||
|
echo ::set-output name=TAG::$TAG
|
||||||
|
- name: Push Tag to Docker Hub
|
||||||
|
uses: opspresso/action-docker@master
|
||||||
|
with:
|
||||||
|
args: --docker
|
||||||
|
env:
|
||||||
|
USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
BUILD_PATH: "server"
|
||||||
|
DOCKERFILE: "server/Dockerfile"
|
||||||
|
IMAGE_NAME: "josephbmanley/defend-together"
|
||||||
|
TAG_NAME: ${{ steps.get_tag.outputs.TAG }}
|
||||||
|
LATEST: "false"
|
||||||
|
- name: Push Latest to Docker Hub
|
||||||
|
uses: opspresso/action-docker@master
|
||||||
|
with:
|
||||||
|
args: --docker
|
||||||
|
env:
|
||||||
|
USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
BUILD_PATH: "server"
|
||||||
|
DOCKERFILE: "server/Dockerfile"
|
||||||
|
IMAGE_NAME: "josephbmanley/defend-together"
|
||||||
|
TAG_NAME: ${{ steps.get_tag.outputs.TAG }}
|
||||||
|
LATEST: "true"
|
||||||
|
- name: Push Tag to GitHub Package
|
||||||
|
uses: opspresso/action-docker@master
|
||||||
|
with:
|
||||||
|
args: --docker
|
||||||
|
env:
|
||||||
|
USERNAME: ${{ github.actor }}
|
||||||
|
PASSWORD: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
REGISTRY: "docker.pkg.github.com"
|
||||||
|
BUILD_PATH: "server"
|
||||||
|
DOCKERFILE: "server/Dockerfile"
|
||||||
|
IMAGE_NAME: "defend-together"
|
||||||
|
TAG_NAME: ${{ steps.get_tag.outputs.TAG }}
|
||||||
|
LATEST: "false"
|
||||||
|
- name: Push Latest to GitHub Package
|
||||||
|
uses: opspresso/action-docker@master
|
||||||
|
with:
|
||||||
|
args: --docker
|
||||||
|
env:
|
||||||
|
USERNAME: ${{ github.actor }}
|
||||||
|
PASSWORD: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
REGISTRY: "docker.pkg.github.com"
|
||||||
|
BUILD_PATH: "server"
|
||||||
|
DOCKERFILE: "server/Dockerfile"
|
||||||
|
IMAGE_NAME: "defend-together"
|
||||||
|
TAG_NAME: ${{ steps.get_tag.outputs.TAG }}
|
||||||
|
LATEST: "true"
|
||||||
|
cloudformation:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@v2.1.0
|
||||||
|
with:
|
||||||
|
submodules: 'true'
|
||||||
|
- name: Ship to S3
|
||||||
|
uses: jakejarvis/s3-sync-action@master
|
||||||
|
with:
|
||||||
|
args: --follow-symlinks --delete
|
||||||
|
env:
|
||||||
|
SOURCE_DIR: infrastructure/cloudformation
|
||||||
|
AWS_REGION: "us-east-1"
|
||||||
|
DEST_DIR: dt/production/cloudformation
|
||||||
|
AWS_S3_BUCKET: sumu-stacks
|
||||||
|
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||||
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||||
|
- name: Configure AWS Credentials
|
||||||
|
uses: aws-actions/configure-aws-credentials@v1
|
||||||
|
with:
|
||||||
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||||
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||||
|
aws-region: us-east-1
|
||||||
|
- name: Deploy to AWS CloudFormation
|
||||||
|
uses: aws-actions/aws-cloudformation-github-deploy@v1
|
||||||
|
with:
|
||||||
|
name: dt-infrastructure
|
||||||
|
template: infrastructure/cloudformation/dt/top.yaml
|
||||||
|
capabilities: "CAPABILITY_NAMED_IAM,CAPABILITY_IAM"
|
||||||
|
parameter-overrides: VpcId=${{ secrets.VPC_ID }},Domain=${{ secrets.DOMAIN }},PublicSubnets=${{ secrets.SUBNET_IDS }}
|
71
.github/workflows/release_server.yml
vendored
71
.github/workflows/release_server.yml
vendored
@ -1,71 +0,0 @@
|
|||||||
name: Release Server
|
|
||||||
|
|
||||||
on:
|
|
||||||
release:
|
|
||||||
types:
|
|
||||||
- created
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
docker:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v1
|
|
||||||
- id: get_tag
|
|
||||||
name: Get Tag
|
|
||||||
env:
|
|
||||||
GITHUB_HEAD_REF: $${{ github.head_ref }}
|
|
||||||
GITHUB_BASE_REF: ${{ github.base_ref }}
|
|
||||||
run: |
|
|
||||||
TAG=$(jq --raw-output '.release.tag_name' $GITHUB_EVENT_PATH)
|
|
||||||
echo ::set-output name=TAG::$TAG
|
|
||||||
- name: Push Tag to Docker Hub
|
|
||||||
uses: opspresso/action-docker@master
|
|
||||||
with:
|
|
||||||
args: --docker
|
|
||||||
env:
|
|
||||||
USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
|
||||||
PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
|
||||||
BUILD_PATH: "server"
|
|
||||||
DOCKERFILE: "server/Dockerfile"
|
|
||||||
IMAGE_NAME: "josephbmanley/defend-together"
|
|
||||||
TAG_NAME: ${{ steps.get_tag.outputs.TAG }}
|
|
||||||
LATEST: "false"
|
|
||||||
- name: Push Latest to Docker Hub
|
|
||||||
uses: opspresso/action-docker@master
|
|
||||||
with:
|
|
||||||
args: --docker
|
|
||||||
env:
|
|
||||||
USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
|
||||||
PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
|
||||||
BUILD_PATH: "server"
|
|
||||||
DOCKERFILE: "server/Dockerfile"
|
|
||||||
IMAGE_NAME: "josephbmanley/defend-together"
|
|
||||||
TAG_NAME: ${{ steps.get_tag.outputs.TAG }}
|
|
||||||
LATEST: "true"
|
|
||||||
- name: Push Tag to GitHub Package
|
|
||||||
uses: opspresso/action-docker@master
|
|
||||||
with:
|
|
||||||
args: --docker
|
|
||||||
env:
|
|
||||||
USERNAME: ${{ github.actor }}
|
|
||||||
PASSWORD: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
REGISTRY: "docker.pkg.github.com"
|
|
||||||
BUILD_PATH: "server"
|
|
||||||
DOCKERFILE: "server/Dockerfile"
|
|
||||||
IMAGE_NAME: "defend-together"
|
|
||||||
TAG_NAME: ${{ steps.get_tag.outputs.TAG }}
|
|
||||||
LATEST: "false"
|
|
||||||
- name: Push Latest to GitHub Package
|
|
||||||
uses: opspresso/action-docker@master
|
|
||||||
with:
|
|
||||||
args: --docker
|
|
||||||
env:
|
|
||||||
USERNAME: ${{ github.actor }}
|
|
||||||
PASSWORD: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
REGISTRY: "docker.pkg.github.com"
|
|
||||||
BUILD_PATH: "server"
|
|
||||||
DOCKERFILE: "server/Dockerfile"
|
|
||||||
IMAGE_NAME: "defend-together"
|
|
||||||
TAG_NAME: ${{ steps.get_tag.outputs.TAG }}
|
|
||||||
LATEST: "true"
|
|
1
client/.gitignore
vendored
1
client/.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
builds
|
builds
|
||||||
|
templates
|
@ -1,6 +1,6 @@
|
|||||||
[preset.0]
|
[preset.0]
|
||||||
|
|
||||||
name="Linux/X11"
|
name="linux"
|
||||||
platform="Linux/X11"
|
platform="Linux/X11"
|
||||||
runnable=true
|
runnable=true
|
||||||
custom_features=""
|
custom_features=""
|
||||||
@ -21,28 +21,5 @@ texture_format/etc2=false
|
|||||||
texture_format/no_bptc_fallbacks=true
|
texture_format/no_bptc_fallbacks=true
|
||||||
binary_format/64_bits=true
|
binary_format/64_bits=true
|
||||||
binary_format/embed_pck=false
|
binary_format/embed_pck=false
|
||||||
custom_template/release="/var/home/vetra/Projects/godot-enet/bin/godot.x11.opt.64"
|
custom_template/release="templates/linux"
|
||||||
custom_template/debug="/var/home/vetra/Projects/godot-enet/bin/godot.x11.opt.debug.64"
|
custom_template/debug="templates/linux"
|
||||||
|
|
||||||
[preset.1]
|
|
||||||
|
|
||||||
name="HTML5"
|
|
||||||
platform="HTML5"
|
|
||||||
runnable=true
|
|
||||||
custom_features=""
|
|
||||||
export_filter="all_resources"
|
|
||||||
include_filter=""
|
|
||||||
exclude_filter=""
|
|
||||||
export_path="builds/client.html"
|
|
||||||
patch_list=PoolStringArray( )
|
|
||||||
script_export_mode=1
|
|
||||||
script_encryption_key=""
|
|
||||||
|
|
||||||
[preset.1.options]
|
|
||||||
|
|
||||||
vram_texture_compression/for_desktop=true
|
|
||||||
vram_texture_compression/for_mobile=false
|
|
||||||
html/custom_html_shell=""
|
|
||||||
html/head_include=""
|
|
||||||
custom_template/release=""
|
|
||||||
custom_template/debug=""
|
|
||||||
|
@ -24,6 +24,14 @@ config/icon="res://icon.png"
|
|||||||
MusicManager="*res://nodes/MusicManager.tscn"
|
MusicManager="*res://nodes/MusicManager.tscn"
|
||||||
NetworkManager="*res://nodes/NetworkManager.tscn"
|
NetworkManager="*res://nodes/NetworkManager.tscn"
|
||||||
|
|
||||||
|
[input]
|
||||||
|
|
||||||
|
send_chat_message={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777221,"unicode":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[rendering]
|
[rendering]
|
||||||
|
|
||||||
environment/default_environment="res://default_env.tres"
|
environment/default_environment="res://default_env.tres"
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -3,17 +3,21 @@ extends KinematicBody2D
|
|||||||
export var user : String = ""
|
export var user : String = ""
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
set_username("")
|
||||||
|
|
||||||
|
func set_username(username):
|
||||||
|
print(username)
|
||||||
|
user = username
|
||||||
$Label.text = user
|
$Label.text = user
|
||||||
#$Label.text = $"/root/NetworkManager".username
|
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
var movePos : Vector2 = Vector2(0,0)
|
var movePos : Vector2 = Vector2(0,0)
|
||||||
|
|
||||||
|
|
||||||
if(Input.is_action_just_pressed("ui_up")):
|
if(Input.is_action_just_pressed("ui_up")):
|
||||||
movePos.y = movePos.y + 1
|
|
||||||
if(Input.is_action_just_pressed("ui_down")):
|
|
||||||
movePos.y = movePos.y - 1
|
movePos.y = movePos.y - 1
|
||||||
|
if(Input.is_action_just_pressed("ui_down")):
|
||||||
|
movePos.y = movePos.y + 1
|
||||||
if(Input.is_action_just_pressed("ui_right")):
|
if(Input.is_action_just_pressed("ui_right")):
|
||||||
movePos.x = movePos.x + 1
|
movePos.x = movePos.x + 1
|
||||||
if(Input.is_action_just_pressed("ui_left")):
|
if(Input.is_action_just_pressed("ui_left")):
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
const SERVER_HOST : String = "192.168.1.34"
|
var server_host : String = "127.0.0.1"
|
||||||
|
|
||||||
const SERVER_PORT : int = 7777
|
const SERVER_PORT : int = 7777
|
||||||
|
|
||||||
signal disconnection
|
signal disconnection
|
||||||
@ -9,6 +10,7 @@ signal error_occured
|
|||||||
signal logged_in
|
signal logged_in
|
||||||
|
|
||||||
signal world_data_recieved
|
signal world_data_recieved
|
||||||
|
signal chat_message_recieved
|
||||||
|
|
||||||
var username : String = ""
|
var username : String = ""
|
||||||
|
|
||||||
@ -27,15 +29,17 @@ var connection_timer : Timer
|
|||||||
func _init():
|
func _init():
|
||||||
server_address = GDNetAddress.new()
|
server_address = GDNetAddress.new()
|
||||||
|
|
||||||
server_address.set_host(SERVER_HOST)
|
|
||||||
server_address.set_port(SERVER_PORT)
|
|
||||||
|
|
||||||
client = GDNetHost.new()
|
client = GDNetHost.new()
|
||||||
|
client.set_max_channels(2)
|
||||||
client.set_max_peers(1)
|
client.set_max_peers(1)
|
||||||
client.set_event_wait(250)
|
client.set_event_wait(250)
|
||||||
client.bind()
|
client.bind()
|
||||||
|
|
||||||
func connect_to_server():
|
func connect_to_server():
|
||||||
|
if peer:
|
||||||
|
peer.disconnect_now()
|
||||||
|
server_address.set_host(server_host)
|
||||||
|
server_address.set_port(SERVER_PORT)
|
||||||
peer = client.host_connect(server_address)
|
peer = client.host_connect(server_address)
|
||||||
if not connection_timer:
|
if not connection_timer:
|
||||||
connection_timer = Timer.new()
|
connection_timer = Timer.new()
|
||||||
@ -50,13 +54,13 @@ func timeout_check():
|
|||||||
|
|
||||||
func request_world_map():
|
func request_world_map():
|
||||||
var request_packet : PoolByteArray = "2|".to_ascii()
|
var request_packet : PoolByteArray = "2|".to_ascii()
|
||||||
packetQueue.append(request_packet)
|
send_packet(request_packet)
|
||||||
|
|
||||||
func connect_as_user(username : String):
|
func connect_as_user(username : String):
|
||||||
connect_to_server()
|
connect_to_server()
|
||||||
var username_packet : PoolByteArray = ("1|" + username).to_ascii()
|
var username_packet : PoolByteArray = ("1|" + username).to_ascii()
|
||||||
|
|
||||||
packetQueue.append(username_packet)
|
send_packet(username_packet)
|
||||||
|
|
||||||
func display_error(error = "Unknown error occured!"):
|
func display_error(error = "Unknown error occured!"):
|
||||||
error_info = error
|
error_info = error
|
||||||
@ -73,18 +77,22 @@ func process_events():
|
|||||||
var event_type = event.get_event_type()
|
var event_type = event.get_event_type()
|
||||||
|
|
||||||
if(event_type == GDNetEvent.RECEIVE):
|
if(event_type == GDNetEvent.RECEIVE):
|
||||||
var ascii_data : String = str(event.get_packet().get_string_from_ascii())
|
if event.get_channel_id() == 0:
|
||||||
if len(ascii_data) > 0:
|
var ascii_data : String = str(event.get_packet().get_string_from_ascii())
|
||||||
if ascii_data[0] == '1':
|
if len(ascii_data) > 0:
|
||||||
if ascii_data.substr(2,2) == "OK":
|
if ascii_data[0] == '1':
|
||||||
username = ascii_data.substr(4)
|
if ascii_data.substr(2,2) == "OK":
|
||||||
print("Logged in as: " + username)
|
username = ascii_data.substr(4)
|
||||||
emit_signal("logged_in")
|
print("Logged in as: " + username)
|
||||||
else:
|
emit_signal("logged_in")
|
||||||
display_error("Username not accepted! Reason: " + ascii_data.substr(2))
|
else:
|
||||||
elif ascii_data[0] == '2':
|
display_error("Username not accepted! Reason: " + ascii_data.substr(2))
|
||||||
world_data = ascii_data.substr(2)
|
elif ascii_data[0] == '2':
|
||||||
emit_signal("world_data_recieved")
|
world_data = ascii_data.substr(2)
|
||||||
|
emit_signal("world_data_recieved")
|
||||||
|
elif event.get_channel_id() == 1:
|
||||||
|
var chat_message : String = str(event.get_packet().get_string_from_ascii())
|
||||||
|
emit_signal("chat_message_recieved", chat_message)
|
||||||
elif(event_type == GDNetEvent.CONNECT):
|
elif(event_type == GDNetEvent.CONNECT):
|
||||||
print("Connected to server with hostname: " + server_address.get_host() + ":" + str(server_address.get_port()))
|
print("Connected to server with hostname: " + server_address.get_host() + ":" + str(server_address.get_port()))
|
||||||
connected = true
|
connected = true
|
||||||
@ -94,16 +102,24 @@ func process_events():
|
|||||||
connected = false
|
connected = false
|
||||||
emit_signal("disconnection")
|
emit_signal("disconnection")
|
||||||
|
|
||||||
|
|
||||||
|
func send_chat_message(msg : String):
|
||||||
|
var pckt : PoolByteArray = (msg + '\n').to_ascii()
|
||||||
|
send_packet(pckt, 1)
|
||||||
|
|
||||||
|
func send_packet(packet : PoolByteArray, channel = 0):
|
||||||
|
packetQueue.append({'channel':channel, 'packet' : packet})
|
||||||
|
|
||||||
func move_player(x,y):
|
func move_player(x,y):
|
||||||
var pckt : PoolByteArray = ("3|" + str(x) + "," + str(y)).to_ascii()
|
var pckt : PoolByteArray = ("3|" + str(x) + "," + str(y)).to_ascii()
|
||||||
|
|
||||||
packetQueue.append(pckt)
|
send_packet(pckt)
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
process_events()
|
process_events()
|
||||||
|
|
||||||
if len(packetQueue) > 0 and connected:
|
if len(packetQueue) > 0 and connected:
|
||||||
peer.send_packet(packetQueue[0], 0, GDNetMessage.RELIABLE)
|
peer.send_packet(packetQueue[0]['packet'], packetQueue[0]['channel'], GDNetMessage.RELIABLE)
|
||||||
packetQueue.remove(0)
|
packetQueue.remove(0)
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,7 +10,10 @@ func _on_world_update():
|
|||||||
var data = $"/root/NetworkManager".world_data.split('\n')
|
var data = $"/root/NetworkManager".world_data.split('\n')
|
||||||
for tileUpdate in data:
|
for tileUpdate in data:
|
||||||
if len(tileUpdate) > 3:
|
if len(tileUpdate) > 3:
|
||||||
if ',' in tileUpdate:
|
if "delete," in tileUpdate:
|
||||||
|
var delete_data = tileUpdate.substr(len("delete,")).split(':')
|
||||||
|
delete_entity(delete_data[1],delete_data[0])
|
||||||
|
elif ',' in tileUpdate:
|
||||||
var tile_data = tileUpdate.split(',')
|
var tile_data = tileUpdate.split(',')
|
||||||
if ':' in tile_data[2]:
|
if ':' in tile_data[2]:
|
||||||
var pos : Vector2 = $Tiles.map_to_world(Vector2(int(tile_data[0]), int(tile_data[1])))
|
var pos : Vector2 = $Tiles.map_to_world(Vector2(int(tile_data[0]), int(tile_data[1])))
|
||||||
@ -47,3 +50,11 @@ func update_entity(entity_id : String, pos : Vector2, type : String):
|
|||||||
display_error("Trying to load entity of type: " + type + ", but failed.")
|
display_error("Trying to load entity of type: " + type + ", but failed.")
|
||||||
if entity:
|
if entity:
|
||||||
entity.position = pos
|
entity.position = pos
|
||||||
|
if entity.has_method("set_username"):
|
||||||
|
entity.set_username(entity_id)
|
||||||
|
|
||||||
|
func delete_entity(entity_id : String, type : String):
|
||||||
|
var entity : Node2D = get_node_or_null( str(type + "-" + entity_id))
|
||||||
|
if entity:
|
||||||
|
entity.queue_free()
|
||||||
|
|
||||||
|
44
infrastructure/cloudformation/dt/dns.yaml
Normal file
44
infrastructure/cloudformation/dt/dns.yaml
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
AWSTemplateFormatVersion: "2010-09-09"
|
||||||
|
Description: DT DNS stack
|
||||||
|
Parameters:
|
||||||
|
#------------------------
|
||||||
|
# Deployment Information
|
||||||
|
#------------------------
|
||||||
|
environment:
|
||||||
|
Type: String
|
||||||
|
Description: Name of the environment
|
||||||
|
Default: production
|
||||||
|
|
||||||
|
#-----------------------
|
||||||
|
# Route53 Configuration
|
||||||
|
#-----------------------
|
||||||
|
Domain:
|
||||||
|
Type: String
|
||||||
|
Description: The HostedZoneName to create the endpoint on
|
||||||
|
SubDomain:
|
||||||
|
Type: String
|
||||||
|
Description: The subdomain to be used by dt
|
||||||
|
|
||||||
|
#-----------
|
||||||
|
# Resources
|
||||||
|
#-----------
|
||||||
|
DtDNS:
|
||||||
|
Type: String
|
||||||
|
Description: Load balancer dns name for dt endpoint
|
||||||
|
|
||||||
|
Resources:
|
||||||
|
DtEndpoint:
|
||||||
|
Type: AWS::Route53::RecordSet
|
||||||
|
Properties:
|
||||||
|
HostedZoneName: !Sub "${Domain}."
|
||||||
|
Comment: 'DNS name for dt'
|
||||||
|
Name: !Sub "${SubDomain}.${Domain}."
|
||||||
|
Type: CNAME
|
||||||
|
TTL: '300'
|
||||||
|
ResourceRecords:
|
||||||
|
- !Ref DtDNS
|
||||||
|
|
||||||
|
Outputs:
|
||||||
|
Endpoint:
|
||||||
|
Description: 'DNS name for Defend Together'
|
||||||
|
Value: !Sub "${SubDomain}.${Domain}."
|
69
infrastructure/cloudformation/dt/load_balancing.yaml
Normal file
69
infrastructure/cloudformation/dt/load_balancing.yaml
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
AWSTemplateFormatVersion: "2010-09-09"
|
||||||
|
Description: DT load balancing stack
|
||||||
|
Parameters:
|
||||||
|
environment:
|
||||||
|
Type: String
|
||||||
|
Description: Name of the environment
|
||||||
|
Default: production
|
||||||
|
release:
|
||||||
|
Type: String
|
||||||
|
Description: Name of the release name of the stack version to use.
|
||||||
|
Default: production
|
||||||
|
PublicSubnets:
|
||||||
|
Description: The public subnets for the ALB to run in.
|
||||||
|
Type: String
|
||||||
|
VpcId:
|
||||||
|
Description: ID of the VPC
|
||||||
|
Type: AWS::EC2::VPC::Id
|
||||||
|
|
||||||
|
Resources:
|
||||||
|
|
||||||
|
#-- Network Load Balancer --#
|
||||||
|
PublicNLB:
|
||||||
|
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
|
||||||
|
Properties:
|
||||||
|
Type: network
|
||||||
|
LoadBalancerAttributes:
|
||||||
|
- Key: deletion_protection.enabled
|
||||||
|
Value: false
|
||||||
|
Scheme: internet-facing
|
||||||
|
Subnets: !Split [",", !Ref PublicSubnets]
|
||||||
|
Tags:
|
||||||
|
- Key: Name
|
||||||
|
Value: !Sub "DT-${environment}-NLB"
|
||||||
|
- Key: environment
|
||||||
|
Value: !Ref environment
|
||||||
|
|
||||||
|
NlbTargetGroup:
|
||||||
|
Type: AWS::ElasticLoadBalancingV2::TargetGroup
|
||||||
|
Properties:
|
||||||
|
HealthCheckProtocol: TCP
|
||||||
|
HealthCheckPort: 80
|
||||||
|
Port: 7777
|
||||||
|
Protocol: TCP_UDP
|
||||||
|
TargetGroupAttributes:
|
||||||
|
- Key: deregistration_delay.timeout_seconds
|
||||||
|
Value: '20'
|
||||||
|
VpcId: !Ref 'VpcId'
|
||||||
|
Tags:
|
||||||
|
- Key: Name
|
||||||
|
Value: !Sub 'DT-${release}'
|
||||||
|
|
||||||
|
NlbListener:
|
||||||
|
Type: AWS::ElasticLoadBalancingV2::Listener
|
||||||
|
Properties:
|
||||||
|
DefaultActions:
|
||||||
|
- Type: forward
|
||||||
|
TargetGroupArn: !Ref NlbTargetGroup
|
||||||
|
LoadBalancerArn: !Ref PublicNLB
|
||||||
|
Port: 7777
|
||||||
|
Protocol: TCP_UDP
|
||||||
|
|
||||||
|
|
||||||
|
Outputs:
|
||||||
|
TargetGroup:
|
||||||
|
Description: ""
|
||||||
|
Value: !Ref NlbTargetGroup
|
||||||
|
NlbDnsName:
|
||||||
|
Description: ""
|
||||||
|
Value: !GetAtt PublicNLB.DNSName
|
52
infrastructure/cloudformation/dt/task.yaml
Normal file
52
infrastructure/cloudformation/dt/task.yaml
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
AWSTemplateFormatVersion: '2010-09-09'
|
||||||
|
Description: Defend Togeher ECS Task
|
||||||
|
Parameters:
|
||||||
|
LogGroupName:
|
||||||
|
Type: String
|
||||||
|
Description: The AWS CloudWatch log group to output logs to.
|
||||||
|
Default: "/ecs/dt"
|
||||||
|
|
||||||
|
environment:
|
||||||
|
Type: String
|
||||||
|
Description: Name of the environment to use in naming.
|
||||||
|
Default: production
|
||||||
|
|
||||||
|
DockerTag:
|
||||||
|
Description: Tag in DockerHub to deploy
|
||||||
|
Type: String
|
||||||
|
Default: "latest"
|
||||||
|
|
||||||
|
Resources:
|
||||||
|
|
||||||
|
LogGroup:
|
||||||
|
Type: AWS::Logs::LogGroup
|
||||||
|
Properties:
|
||||||
|
RetentionInDays: 7
|
||||||
|
LogGroupName: !Sub "${LogGroupName}/${environment}"
|
||||||
|
|
||||||
|
TaskDefinition:
|
||||||
|
Type: AWS::ECS::TaskDefinition
|
||||||
|
Properties:
|
||||||
|
ContainerDefinitions:
|
||||||
|
- Name: defend-together
|
||||||
|
Essential: 'true'
|
||||||
|
Image: !Sub "josephbmanley/defend-together:${DockerTag}"
|
||||||
|
MemoryReservation: 250
|
||||||
|
PortMappings:
|
||||||
|
- HostPort: 7777
|
||||||
|
ContainerPort: 7777
|
||||||
|
Protocol: udp
|
||||||
|
- HostPort: 80
|
||||||
|
ContainerPort: 80
|
||||||
|
Protocol: tcp
|
||||||
|
LogConfiguration:
|
||||||
|
LogDriver: awslogs
|
||||||
|
Options:
|
||||||
|
awslogs-region:
|
||||||
|
Ref: AWS::Region
|
||||||
|
awslogs-group:
|
||||||
|
Ref: LogGroup
|
||||||
|
Outputs:
|
||||||
|
TaskArn:
|
||||||
|
Description: ARN of the TaskDefinition
|
||||||
|
Value: !Ref TaskDefinition
|
117
infrastructure/cloudformation/dt/top.yaml
Normal file
117
infrastructure/cloudformation/dt/top.yaml
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
AWSTemplateFormatVersion: '2010-09-09'
|
||||||
|
Description: Defend Together ECS Infrastructure
|
||||||
|
Parameters:
|
||||||
|
#------------------------
|
||||||
|
# Deployment Information
|
||||||
|
#------------------------
|
||||||
|
environment:
|
||||||
|
Type: String
|
||||||
|
Description: Name of the environment to use in naming.
|
||||||
|
Default: production
|
||||||
|
release:
|
||||||
|
Type: String
|
||||||
|
Description: Name of the release name of the stack version to use.
|
||||||
|
Default: production
|
||||||
|
AllowedValues: ['develop', 'stage', 'production']
|
||||||
|
ConstraintDescription: "Must be a possible release version."
|
||||||
|
VpcId:
|
||||||
|
Description: ID of the VPC
|
||||||
|
Type: AWS::EC2::VPC::Id
|
||||||
|
DockerTag:
|
||||||
|
Description: Tag in DockerHub to deploy
|
||||||
|
Type: String
|
||||||
|
Default: "latest"
|
||||||
|
|
||||||
|
#-----------------
|
||||||
|
# Load Balancing
|
||||||
|
#-----------------
|
||||||
|
PublicSubnets:
|
||||||
|
Description: The public subnets for the ALB to run in. (Space seperated)
|
||||||
|
Type: String
|
||||||
|
|
||||||
|
#-----
|
||||||
|
# DNS
|
||||||
|
#-----
|
||||||
|
Domain:
|
||||||
|
Type: String
|
||||||
|
Description: The domain to create the endpoint on (Must have an existing hosted zone ex. `example.com`) Leave blank to skip DNS.
|
||||||
|
Default: ""
|
||||||
|
SubDomain:
|
||||||
|
Type: String
|
||||||
|
Description: The subdomain to be used by dt. (ex. `dt.example.com`)
|
||||||
|
Default: dt
|
||||||
|
|
||||||
|
#------------
|
||||||
|
# CloudWatch
|
||||||
|
#------------
|
||||||
|
LogGroup:
|
||||||
|
Type: String
|
||||||
|
Description: The AWS CloudWatch log group to output logs to.
|
||||||
|
Default: "/ecs/dt"
|
||||||
|
|
||||||
|
Conditions:
|
||||||
|
CreateDns: !Not [!Equals [!Ref Domain, ""]]
|
||||||
|
|
||||||
|
Resources:
|
||||||
|
|
||||||
|
#-----
|
||||||
|
# DNS
|
||||||
|
#-----
|
||||||
|
DnsRecords:
|
||||||
|
Condition: CreateDns
|
||||||
|
Type: AWS::CloudFormation::Stack
|
||||||
|
Properties:
|
||||||
|
TemplateURL: !Sub 'https://s3.${AWS::Region}.amazonaws.com/sumu-stacks/dt/${release}/cloudformation/dt/dns.yaml'
|
||||||
|
Parameters:
|
||||||
|
environment: !Ref environment
|
||||||
|
Domain: !Ref Domain
|
||||||
|
SubDomain: !Ref SubDomain
|
||||||
|
DtDNS: !GetAtt LoadBalancing.Outputs.NlbDnsName
|
||||||
|
|
||||||
|
#-----------------
|
||||||
|
# Load Balancing
|
||||||
|
#-----------------
|
||||||
|
LoadBalancing:
|
||||||
|
Type: AWS::CloudFormation::Stack
|
||||||
|
Properties:
|
||||||
|
TemplateURL: !Sub 'https://s3.${AWS::Region}.amazonaws.com/sumu-stacks/dt/${release}/cloudformation/dt/load_balancing.yaml'
|
||||||
|
Parameters:
|
||||||
|
environment: !Ref environment
|
||||||
|
release: !Ref release
|
||||||
|
VpcId: !Ref VpcId
|
||||||
|
PublicSubnets: !Join [",", !Split [" ", !Ref PublicSubnets]]
|
||||||
|
|
||||||
|
EcsCluster:
|
||||||
|
Type: AWS::CloudFormation::Stack
|
||||||
|
Properties:
|
||||||
|
TemplateURL: !Sub 'https://s3.${AWS::Region}.amazonaws.com/sumu-stacks/dt/${release}/cloudformation/cluster/top.yaml'
|
||||||
|
Parameters:
|
||||||
|
Environment: !Ref environment
|
||||||
|
VpcId: !Ref VpcId
|
||||||
|
SubnetIds: !Join [",", !Split [" ", !Ref PublicSubnets]]
|
||||||
|
Project: "DT"
|
||||||
|
|
||||||
|
#-------------------
|
||||||
|
# ECS Task & Service
|
||||||
|
#-------------------
|
||||||
|
TaskDefinition:
|
||||||
|
Type: AWS::CloudFormation::Stack
|
||||||
|
Properties:
|
||||||
|
TemplateURL: !Sub 'https://s3.${AWS::Region}.amazonaws.com/sumu-stacks/dt/${release}/cloudformation/dt/task.yaml'
|
||||||
|
Parameters:
|
||||||
|
environment: !Ref environment
|
||||||
|
LogGroupName: !Ref LogGroup
|
||||||
|
DockerTag: !Ref DockerTag
|
||||||
|
|
||||||
|
|
||||||
|
EcsService:
|
||||||
|
DependsOn: LoadBalancing
|
||||||
|
Type: AWS::ECS::Service
|
||||||
|
Properties:
|
||||||
|
Cluster: !GetAtt EcsCluster.Outputs.Cluster
|
||||||
|
DesiredCount: 1
|
||||||
|
TaskDefinition: !GetAtt TaskDefinition.Outputs.TaskArn
|
||||||
|
LoadBalancers:
|
||||||
|
- ContainerName: "defend-together"
|
||||||
|
ContainerPort: 7777
|
||||||
|
TargetGroupArn: !GetAtt LoadBalancing.Outputs.TargetGroup
|
@ -1,9 +1,15 @@
|
|||||||
FROM fedora:32
|
FROM fedora:32
|
||||||
|
|
||||||
RUN /bin/bash -c "dnf install g++ enet-devel gtest gmock gmock-devel gtest-devel -y"
|
# Build and setup app
|
||||||
|
RUN dnf install g++ enet-devel gtest gmock gmock-devel gtest-devel nginx -y
|
||||||
|
|
||||||
ADD / /dt
|
ADD / /dt
|
||||||
|
|
||||||
RUN cd /dt; /dt/build.sh
|
RUN cd /dt; /dt/build.sh
|
||||||
|
|
||||||
CMD ["/dt/builds/server.out"]
|
RUN echo "Container is healthy!" > /usr/share/nginx/html/index.html
|
||||||
|
|
||||||
|
CMD /usr/sbin/nginx ; /dt/builds/server.out
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
EXPOSE 7777/udp
|
@ -8,3 +8,10 @@ if [ -f builds/server.out ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
g++ main.cpp -o builds/server.out -lenet -lpthread
|
g++ main.cpp -o builds/server.out -lenet -lpthread
|
||||||
|
|
||||||
|
if [ $? = 0 ]
|
||||||
|
then
|
||||||
|
echo "Build successfully!"
|
||||||
|
else
|
||||||
|
exit -1
|
||||||
|
fi
|
@ -1,9 +1,9 @@
|
|||||||
#ifndef CONSOLE_HPP
|
#ifndef CONSOLE_HPP
|
||||||
#define CONSOLE_HPP
|
#define CONSOLE_HPP
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
|
||||||
@ -22,19 +22,22 @@ class ServerConsole
|
|||||||
|
|
||||||
void * console_logic(void *)
|
void * console_logic(void *)
|
||||||
{
|
{
|
||||||
printf("Started server console...\n");
|
std::cout << "Started server console..." << std::endl;
|
||||||
|
|
||||||
|
std::string input_string;
|
||||||
|
|
||||||
while(console_is_running)
|
while(console_is_running)
|
||||||
{
|
{
|
||||||
char c [256];
|
if(std::getline(std::cin, input_string))
|
||||||
fgets(c,sizeof(c), stdin);
|
|
||||||
if(c[0] == 'q')
|
|
||||||
{
|
{
|
||||||
console_is_running = false;
|
if(input_string == "stop")
|
||||||
}
|
{
|
||||||
else
|
console_is_running = false;
|
||||||
{
|
}
|
||||||
printf("Invalid console command!\n");
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Invalid console command!" << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -17,8 +17,13 @@ class GameMap
|
|||||||
std::string get_entity_dump(void);
|
std::string get_entity_dump(void);
|
||||||
std::string spawn_entity(std::string,std::string,int,int);
|
std::string spawn_entity(std::string,std::string,int,int);
|
||||||
std::string move_entity(std::string,std::string,int,int);
|
std::string move_entity(std::string,std::string,int,int);
|
||||||
|
int get_entity_pos_x(std::string,std::string);
|
||||||
|
int get_entity_pos_y(std::string,std::string);
|
||||||
int get_size_x(void);
|
int get_size_x(void);
|
||||||
int get_size_y(void);
|
int get_size_y(void);
|
||||||
|
bool entity_exists(std::string, std::string);
|
||||||
|
bool remove_entity(std::string, std::string);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int ** map_data;
|
int ** map_data;
|
||||||
int size_x;
|
int size_x;
|
||||||
@ -66,12 +71,36 @@ std::string GameMap::move_entity(std::string entity_id, std::string entity_type,
|
|||||||
{
|
{
|
||||||
if(entities[i].get_id() == entity_id && entities[i].get_type() == entity_type)
|
if(entities[i].get_id() == entity_id && entities[i].get_type() == entity_type)
|
||||||
{
|
{
|
||||||
if(map_data[entities[i].get_x() + x][entities[i].get_y() + y] % 2 == 1)
|
GameEntity* entity = &entities[i];
|
||||||
|
//if(map_data[entities[i].get_x() + x][entities[i].get_y() + y] % 2 == 1)
|
||||||
|
//{
|
||||||
|
if(entity->get_x() + x < 0)
|
||||||
{
|
{
|
||||||
entities[i].set_x(entities[i].get_x() + x);
|
entity->set_x(0);
|
||||||
entities[i].set_y(entities[i].get_y() + y);
|
|
||||||
}
|
}
|
||||||
return entities[i].get_dump();
|
else if(entity->get_x() + x >= this->get_size_x())
|
||||||
|
{
|
||||||
|
entity->set_x(this->get_size_x() - 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
entity->set_x(entities[i].get_x() + x);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entity->get_y() + y < 0)
|
||||||
|
{
|
||||||
|
entity->set_y(0);
|
||||||
|
}
|
||||||
|
else if(entity->get_y() + y >= this->get_size_y())
|
||||||
|
{
|
||||||
|
entity->set_y(this->get_size_y() - 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
entity->set_y(entities[i].get_y() + y);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entity->get_dump();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
@ -137,4 +166,84 @@ int GameMap::get_size_y(void)
|
|||||||
return size_y;
|
return size_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GameMap::entity_exists(std::string entity_id, std::string entity_type)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < entities.size(); i++)
|
||||||
|
{
|
||||||
|
GameEntity* entity = &entities[i];
|
||||||
|
if(entity->get_id() == entity_id)
|
||||||
|
{
|
||||||
|
if(entity->get_type() == entity_type)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool erase(std::vector<GameEntity> &v, GameEntity key)
|
||||||
|
{
|
||||||
|
for(auto it = v.begin(); it != v.end();)
|
||||||
|
{
|
||||||
|
if (it->get_id() == key.get_id())
|
||||||
|
{
|
||||||
|
it = v.erase(it);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GameMap::remove_entity(std::string entity_id, std::string entity_type)
|
||||||
|
{
|
||||||
|
|
||||||
|
for(int i = 0; i < entities.size(); i++)
|
||||||
|
{
|
||||||
|
if(entities[i].get_id() == entity_id && entities[i].get_type() == entity_type)
|
||||||
|
{
|
||||||
|
return erase(entities, entities[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int GameMap::get_entity_pos_x(std::string entity_id, std::string entity_type)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < entities.size(); i++)
|
||||||
|
{
|
||||||
|
GameEntity* entity = &entities[i];
|
||||||
|
if(entity->get_id() == entity_id)
|
||||||
|
{
|
||||||
|
if(entity->get_type() == entity_type)
|
||||||
|
{
|
||||||
|
return entity->get_x();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int GameMap::get_entity_pos_y(std::string entity_id, std::string entity_type)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < entities.size(); i++)
|
||||||
|
{
|
||||||
|
GameEntity* entity = &entities[i];
|
||||||
|
if(entity->get_id() == entity_id)
|
||||||
|
{
|
||||||
|
if(entity->get_type() == entity_type)
|
||||||
|
{
|
||||||
|
return entity->get_y();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -39,7 +39,7 @@ int main (int argc, char ** argv)
|
|||||||
address.port = SERVER_PORT;
|
address.port = SERVER_PORT;
|
||||||
|
|
||||||
|
|
||||||
const int CHANNEL_COUNT = 1;
|
const int CHANNEL_COUNT = 2;
|
||||||
server = enet_host_create (&address, MAX_PLAYERS, CHANNEL_COUNT, 0, 0);
|
server = enet_host_create (&address, MAX_PLAYERS, CHANNEL_COUNT, 0, 0);
|
||||||
|
|
||||||
if (server == NULL)
|
if (server == NULL)
|
||||||
@ -67,7 +67,8 @@ int main (int argc, char ** argv)
|
|||||||
std::cout << "A packet of length " << event.packet -> dataLength << " containing "
|
std::cout << "A packet of length " << event.packet -> dataLength << " containing "
|
||||||
<< event.packet -> data << " was received from " << event.peer -> data << " on channel"
|
<< event.packet -> data << " was received from " << event.peer -> data << " on channel"
|
||||||
<< event.channelID << std::endl;
|
<< event.channelID << std::endl;
|
||||||
|
if (event.channelID == 0)
|
||||||
|
{
|
||||||
char c [1];
|
char c [1];
|
||||||
c[0] = event.packet->data[0];
|
c[0] = event.packet->data[0];
|
||||||
|
|
||||||
@ -89,19 +90,49 @@ int main (int argc, char ** argv)
|
|||||||
std::cout << "Invalid packet recieved!" <<std::endl;
|
std::cout << "Invalid packet recieved!" <<std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Destroy packet now that it has been used
|
|
||||||
enet_packet_destroy (event.packet);
|
enet_packet_destroy (event.packet);
|
||||||
|
}
|
||||||
|
else if(event.channelID == 1)
|
||||||
|
{
|
||||||
|
int peer_id = event.peer -> incomingPeerID;
|
||||||
|
if(usernames[peer_id] != "")
|
||||||
|
{
|
||||||
|
//Parse input string
|
||||||
|
std::stringstream ss((char*)event.packet->data);
|
||||||
|
std::string chat_message;
|
||||||
|
std::getline(ss, chat_message, '\n');
|
||||||
|
std::string resp = "<" + usernames[peer_id] + "> " + chat_message;
|
||||||
|
const char* data = resp.c_str();
|
||||||
|
|
||||||
|
std::cout << data << std::endl;
|
||||||
|
|
||||||
|
ENetPacket* packet = enet_packet_create(data, strlen(data) + 1, ENET_PACKET_FLAG_RELIABLE);
|
||||||
|
enet_host_broadcast(server, 1, packet);
|
||||||
|
}
|
||||||
|
enet_packet_destroy (event.packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ENET_EVENT_TYPE_DISCONNECT:
|
case ENET_EVENT_TYPE_DISCONNECT:
|
||||||
std::cout << event.peer -> data << " disconnected." << std::endl;
|
std::cout << event.peer -> data << " disconnected." << std::endl;
|
||||||
//Remove peer data on disconnect
|
|
||||||
|
|
||||||
// DELETE ENTITY HERE
|
//Clear username data and remove entity
|
||||||
|
std::string username = usernames[event.peer -> incomingPeerID];
|
||||||
|
if(username != "")
|
||||||
|
{
|
||||||
|
std::cout << "Removing '" << username << "'s player data!" << std::endl;
|
||||||
|
gamemap.remove_entity(username,"player");
|
||||||
|
usernames[event.peer -> incomingPeerID] = "";
|
||||||
|
|
||||||
usernames[event.peer -> incomingPeerID] = "";
|
std::string resp = "2|delete,player:" + username;
|
||||||
|
const char* data = resp.c_str();
|
||||||
|
ENetPacket* packet = enet_packet_create(data, strlen(data) + 1, ENET_PACKET_FLAG_RELIABLE);
|
||||||
|
enet_host_broadcast(server, 0, packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Open peer for new connection
|
||||||
event.peer -> data = NULL;
|
event.peer -> data = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
server/nginx.conf
Normal file
10
server/nginx.conf
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
server {
|
||||||
|
location / {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /health {
|
||||||
|
return 200 'alive';
|
||||||
|
add_header Content-Type text/plain;
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
mkdir -p builds
|
mkdir -p builds
|
||||||
g++ tests.cpp -o builds/tests.out -lgtest
|
g++ tests.cpp -o builds/tests.out -lgtest
|
||||||
./builds/tests.out
|
if [ $? = 0 ]
|
||||||
|
then
|
||||||
|
./builds/tests.out
|
||||||
|
else
|
||||||
|
exit -1
|
||||||
|
fi
|
@ -1,6 +1,7 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "gameentity.hpp"
|
#include "gameentity.hpp"
|
||||||
#include "gamemap.hpp"
|
#include "gamemap.hpp"
|
||||||
@ -61,6 +62,87 @@ TEST(GameMapTest, CheckMapSize)
|
|||||||
EXPECT_EQ(map.get_size_x(), 16);
|
EXPECT_EQ(map.get_size_x(), 16);
|
||||||
EXPECT_EQ(map.get_size_y(), 4);
|
EXPECT_EQ(map.get_size_y(), 4);
|
||||||
}
|
}
|
||||||
|
TEST(GameMapTest, CreateEntity)
|
||||||
|
{
|
||||||
|
GameMap map = CreateMapEntity();
|
||||||
|
map.spawn_entity(TEST_ENTITY_ID, TEST_ENTITY_TYPE);
|
||||||
|
|
||||||
|
EXPECT_TRUE(map.entity_exists(TEST_ENTITY_ID, TEST_ENTITY_TYPE));
|
||||||
|
}
|
||||||
|
TEST(GameMapTest, IntialEntityPos)
|
||||||
|
{
|
||||||
|
GameMap map = CreateMapEntity();
|
||||||
|
map.spawn_entity(TEST_ENTITY_ID, TEST_ENTITY_TYPE, 0,0);
|
||||||
|
|
||||||
|
EXPECT_EQ(map.get_entity_pos_x(TEST_ENTITY_ID, TEST_ENTITY_TYPE), 0);
|
||||||
|
EXPECT_EQ(map.get_entity_pos_y(TEST_ENTITY_ID, TEST_ENTITY_TYPE), 0);
|
||||||
|
}
|
||||||
|
TEST(GameMapTest, MoveEntityFromZero)
|
||||||
|
{
|
||||||
|
GameMap map = CreateMapEntity();
|
||||||
|
map.spawn_entity(TEST_ENTITY_ID, TEST_ENTITY_TYPE, 0,0);
|
||||||
|
|
||||||
|
//Move entity
|
||||||
|
map.move_entity(TEST_ENTITY_ID, TEST_ENTITY_TYPE, 2, 1);
|
||||||
|
|
||||||
|
EXPECT_EQ(map.get_entity_pos_x(TEST_ENTITY_ID, TEST_ENTITY_TYPE), 2);
|
||||||
|
EXPECT_EQ(map.get_entity_pos_y(TEST_ENTITY_ID, TEST_ENTITY_TYPE), 1);
|
||||||
|
}
|
||||||
|
TEST(GameMapTest, MoveEntityRelative)
|
||||||
|
{
|
||||||
|
|
||||||
|
GameMap map = CreateMapEntity();
|
||||||
|
map.spawn_entity(TEST_ENTITY_ID, TEST_ENTITY_TYPE, 0,0);
|
||||||
|
|
||||||
|
//Move entity
|
||||||
|
map.move_entity(TEST_ENTITY_ID, TEST_ENTITY_TYPE, 2, 1);
|
||||||
|
|
||||||
|
//Move entity again!
|
||||||
|
map.move_entity(TEST_ENTITY_ID, TEST_ENTITY_TYPE, 1, 1);
|
||||||
|
|
||||||
|
EXPECT_EQ(map.get_entity_pos_x(TEST_ENTITY_ID, TEST_ENTITY_TYPE), 3);
|
||||||
|
EXPECT_EQ(map.get_entity_pos_y(TEST_ENTITY_ID, TEST_ENTITY_TYPE), 2);
|
||||||
|
}
|
||||||
|
TEST(GameMapTest, MoveEntityNegativeFromZero)
|
||||||
|
{
|
||||||
|
GameMap map = CreateMapEntity();
|
||||||
|
map.spawn_entity(TEST_ENTITY_ID, TEST_ENTITY_TYPE, 0, 0);
|
||||||
|
|
||||||
|
//Move entity
|
||||||
|
map.move_entity(TEST_ENTITY_ID, TEST_ENTITY_TYPE, -1, -1);
|
||||||
|
|
||||||
|
EXPECT_EQ(map.get_entity_pos_x(TEST_ENTITY_ID, TEST_ENTITY_TYPE), 0);
|
||||||
|
EXPECT_EQ(map.get_entity_pos_y(TEST_ENTITY_ID, TEST_ENTITY_TYPE), 0);
|
||||||
|
}
|
||||||
|
TEST(GameMapTest, MoveEntityNegativeFromNonZero)
|
||||||
|
{
|
||||||
|
GameMap map = CreateMapEntity();
|
||||||
|
map.spawn_entity(TEST_ENTITY_ID, TEST_ENTITY_TYPE, 1, 1);
|
||||||
|
|
||||||
|
//Move entity
|
||||||
|
std::cout << std::string(map.move_entity(TEST_ENTITY_ID, TEST_ENTITY_TYPE, -2, -2)) << std::endl;
|
||||||
|
|
||||||
|
EXPECT_EQ(map.get_entity_pos_x(TEST_ENTITY_ID, TEST_ENTITY_TYPE), 0);
|
||||||
|
EXPECT_EQ(map.get_entity_pos_y(TEST_ENTITY_ID, TEST_ENTITY_TYPE), 0);
|
||||||
|
}
|
||||||
|
TEST(GameMapTest, StopEntityFromMovingOutOfBounds)
|
||||||
|
{
|
||||||
|
GameMap map = CreateMapEntity();
|
||||||
|
map.spawn_entity(TEST_ENTITY_ID, TEST_ENTITY_TYPE, map.get_size_x()-1, map.get_size_y()-1);
|
||||||
|
|
||||||
|
//Move entity
|
||||||
|
map.move_entity(TEST_ENTITY_ID, TEST_ENTITY_TYPE, 2, 2);
|
||||||
|
|
||||||
|
EXPECT_EQ(map.get_entity_pos_x(TEST_ENTITY_ID, TEST_ENTITY_TYPE), map.get_size_x() - 1);
|
||||||
|
EXPECT_EQ(map.get_entity_pos_y(TEST_ENTITY_ID, TEST_ENTITY_TYPE), map.get_size_y() - 1);
|
||||||
|
}
|
||||||
|
TEST(GameMapTest, RemoveMapEntity)
|
||||||
|
{
|
||||||
|
GameMap map = CreateMapEntity();
|
||||||
|
map.spawn_entity(TEST_ENTITY_ID, TEST_ENTITY_TYPE);
|
||||||
|
EXPECT_TRUE(map.remove_entity(TEST_ENTITY_ID, TEST_ENTITY_TYPE));
|
||||||
|
EXPECT_FALSE(map.entity_exists(TEST_ENTITY_ID, TEST_ENTITY_TYPE));
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user