Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getservers 1 #307

Open
wants to merge 155 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
4ed7231
python 3 upgrade;few code semantics;new py3 bytes vs all string in py2
Dec 12, 2022
d4ec9d3
python2->python3 migration;sqlite->postgresql migration
Dec 13, 2022
fd8ca46
allow NLB health checks without Bad Descriptor exceptions
Dec 13, 2022
dc2eeb0
remove NLB health cheaks disconnected server prints from client
Dec 13, 2022
fcc1eb3
disable auth
Dec 20, 2022
9a44466
disable auth
Dec 20, 2022
cbfeb64
disable auth
Dec 20, 2022
154af52
disable auth
Dec 20, 2022
8e8d1ac
disable auth
Dec 20, 2022
ca25717
disable auth
Dec 21, 2022
f615798
disable auth
Dec 21, 2022
0ffd838
disable auth
Dec 21, 2022
6af174f
disable auth
Dec 21, 2022
f84c472
disable auth
Dec 21, 2022
835f6e9
disable auth
Dec 21, 2022
c63bd1b
disable auth
Dec 21, 2022
4a7adfa
disable auth
Dec 21, 2022
e2646e3
disable auth
Dec 21, 2022
5c06874
disable auth
Dec 21, 2022
faecfed
disable auth
Dec 21, 2022
662a481
disable auth
Dec 21, 2022
70ec4a7
disable auth
Dec 21, 2022
2b02dcb
add user_id to block
Dec 21, 2022
e7c5cce
add user_id to block
Dec 21, 2022
39bca8c
add user_id to block
Dec 21, 2022
8c71cdf
add user_id to block
Dec 21, 2022
20dee3c
add user_id to block
Dec 21, 2022
e403da7
add user_id to block
Dec 21, 2022
ca246ab
add user_id to block
Dec 21, 2022
55f1b45
add user_id to block
Dec 21, 2022
d70a7aa
add user_id to block
Dec 22, 2022
dc31263
add user_id to block
Dec 22, 2022
2578d97
add user_id to block
Dec 22, 2022
aafc55c
add user_id to block
Dec 22, 2022
f674364
add user_id to block
Dec 22, 2022
439d047
bob the builder
Dec 22, 2022
ab523f3
bob the builder
Dec 22, 2022
7b52ab0
bob the builder
Dec 23, 2022
84700c8
bob the builder
Dec 23, 2022
c428f8a
build world
Dec 23, 2022
66ff088
spawn point
Dec 23, 2022
fa17103
spawn point
Dec 23, 2022
3b073e1
spawn point
Dec 23, 2022
d47cb88
agones/craft
Dec 23, 2022
9a56dde
agones
Dec 23, 2022
16765a9
agones
Dec 23, 2022
f510111
agones
Dec 23, 2022
8f1b73e
agones
Dec 23, 2022
a59bc3c
agones
Dec 23, 2022
01ad890
agones
Dec 23, 2022
94bc8ab
agones
Dec 23, 2022
e5c7432
agones
Dec 23, 2022
c4a00bd
agones
Dec 23, 2022
2ac8b0a
agones
Dec 23, 2022
26f09a6
agones
Dec 23, 2022
84a7868
agones
Dec 24, 2022
fd53a2f
agones
Dec 24, 2022
1d83c59
agones
Dec 24, 2022
805b5d8
agones
Dec 24, 2022
01a8295
agones
Dec 24, 2022
ab98955
agones
Dec 24, 2022
6bef3e2
agones
Dec 24, 2022
8f356e9
agones
Dec 24, 2022
6d623be
agones
Dec 24, 2022
5dd74ab
agones
Dec 24, 2022
2084341
agones
Dec 24, 2022
db787dd
agones
Dec 24, 2022
9bd122f
agones
Dec 24, 2022
4e2be4a
Merge pull request #1 from yahavb/agones_25
Dec 24, 2022
05c24df
auth
Dec 25, 2022
0a569a7
auth
Dec 25, 2022
e0bc666
auth
Dec 25, 2022
c4de1cb
auth
Dec 25, 2022
8a8dab5
auth
Dec 25, 2022
5f46544
auth
Dec 25, 2022
1de9e27
auth
Dec 25, 2022
87ae38c
auth
Dec 25, 2022
b9d3d3a
auth
Dec 25, 2022
15bf7b1
auth
Dec 25, 2022
1f170c0
auth
Dec 25, 2022
a70fe8a
auth
Dec 25, 2022
47fe63b
auth
Dec 25, 2022
5910e2f
auth
Dec 25, 2022
afca761
auth
Dec 25, 2022
4c5b64a
auth
Dec 25, 2022
eeea2d3
auth
Dec 25, 2022
c69f16a
auth
Dec 25, 2022
860670f
auth
Dec 25, 2022
436650b
auth
Dec 25, 2022
4884d37
auth
Dec 25, 2022
2286d7f
auth
Dec 25, 2022
ca82963
auth
Dec 25, 2022
1866242
auth
Dec 25, 2022
032daf2
auth
Dec 27, 2022
5b99bbf
auth
Dec 27, 2022
0b7f0d1
auth
Dec 27, 2022
8dd6752
auth
Dec 27, 2022
3cbcf55
auth
Dec 27, 2022
ae607af
Merge pull request #2 from yahavb/auth_36
Dec 27, 2022
774275c
Update README.md
Dec 27, 2022
0224c4a
failover
Dec 27, 2022
dcff75b
failover
Dec 27, 2022
56d2cc1
failover
Dec 27, 2022
29c2970
Merge pull request #3 from yahavb/failover_3
Dec 27, 2022
3219aa2
readme
Dec 27, 2022
2fb769d
failover
Dec 28, 2022
d4470fd
failover
Dec 28, 2022
c31da5f
failover
Dec 28, 2022
55c7148
failover
Dec 28, 2022
147b9b1
failover
Dec 28, 2022
fcdfc62
failover
Dec 28, 2022
1cb116e
failover
Dec 28, 2022
9f57542
failover
Dec 28, 2022
289ea7f
failover
Dec 28, 2022
dcb4a5e
failover
Dec 28, 2022
d9d7c69
failover
Dec 28, 2022
41d3dc8
failover
Dec 28, 2022
78b2cd5
failover
Dec 28, 2022
8ee09ce
failover
Dec 28, 2022
b2d9bf7
failover
Dec 28, 2022
d596f96
failover
Dec 28, 2022
32755e8
failover
Dec 28, 2022
371c3cc
failover
Dec 28, 2022
3e119fc
failover
Dec 28, 2022
866bd63
failover
Dec 28, 2022
2655142
failover
Dec 28, 2022
fa0480a
Merge pull request #4 from yahavb/failover_23
Dec 28, 2022
0759946
build-procedure
Dec 28, 2022
39d3e52
agones_10
Dec 29, 2022
9b7342e
agones_11
Dec 29, 2022
252bc23
agones_12
Dec 29, 2022
7bd01aa
agones_13
Dec 29, 2022
7f7831c
agones_14
Dec 30, 2022
533ec59
agones_15
Dec 30, 2022
6c403f7
agones_16
Dec 30, 2022
72e225c
agones_17
Dec 30, 2022
8fa6dc4
agones_18
Dec 30, 2022
17411d1
agones_19
Dec 30, 2022
4e8740a
agones_20
Dec 30, 2022
404085d
agones_21
Dec 30, 2022
49e5168
agones_22
Dec 30, 2022
6b622a5
agones_23
Dec 30, 2022
75f7fc6
agones_24
Dec 30, 2022
2c610ce
agones_25
Dec 30, 2022
81dab73
agones_26
Dec 30, 2022
06fd4b1
agones_27
Dec 31, 2022
e953e6e
agones_28
Jan 1, 2023
404ef7d
agones_29
Jan 1, 2023
5f7072c
agones_30
Jan 1, 2023
535c7e2
agones_31
Jan 2, 2023
9e4096e
agones_32
Jan 2, 2023
1cda145
agones_33
Jan 2, 2023
8c446e8
Merge pull request #5 from yahavb/agones_33
Jan 2, 2023
682875d
agones-readme
Jan 2, 2023
e0f6d76
getservers_1
Jan 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
## Craft fork

Running on python3, using Amazon Aurora PG instead of sqlite, deployed on Agones/NLB and using craft.auth.yahav.sa.aws.dev/auth/identity/ for auth players.

See all users:
```bash
curl http://craft.auth.yahav.sa.aws.dev/auth/allusers/
```

Create a user:
```bash
curl http://craft.auth.yahav.sa.aws.dev/auth/adduser/?username=yahavb
```

Generate token:
```bash
curl http://craft.auth.yahav.sa.aws.dev/auth/getoken/?username=yahavb
```
Use the token and username to validate your token `/identity username token` in the craf game client.

### Database setup
This fork uses postgresql instead of sqlite so some of the sql were adopted to postgresql.
To spin an aurora postgresql use https://github.com/aws-samples/amazon-aurora-call-to-amazon-sagemaker-sample/tree/master/multiplayer-matchmaker/aurora-pg-cdk

### Making changes
branch=mybranch && git checkout -b $branch && git add server.py&&git commit -m $branch && git push --set-upstream origin $branch
To build a new image manually, use https://github.com/aws-samples/containerized-game-servers/blob/master/craft/ci/craft-server/serverfiles/build.sh.
In `aws-samples/containerized-game-servers/blob/master/craft/ci/craft-server/serverfiles`
```bash
export GITHUB_CRAFT_BRANCH=mybranch && ./build.sh
```
### Agones

Install agones
```bash
helm upgrade agones agones/agones --namespace agones-system --install --wait --create-namespace \
--set agones.featureGates=PlayerTracking=true
```

Enable player tracking
```bash
helm upgrade agones agones/agones --namespace agones-system --set agones.featureGates=PlayerTracking=true
```

Add `IS_AGONES` env parameter
```bash
IS_AGONES=True
```

Use TBD link to https://github.com/aws-samples/containerized-game-servers/tree/master/craft
## Craft

Minecraft clone for Windows, Mac OS X and Linux. Just a few thousand lines of C using modern OpenGL (shaders). Online multiplayer support is included using a Python-based server.
Expand Down
201 changes: 139 additions & 62 deletions builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import socket
import sqlite3
import sys
import os
import time
import boto3

DEFAULT_HOST = '127.0.0.1'
DEFAULT_PORT = 4080
QUEUE_URL = os.environ['SQS_CHECKPOINT_QUEUE_URL']
DEFAULT_HOST = os.environ['CRAFT_HOST']
DEFAULT_PORT = os.environ['CRAFT_PORT']

EMPTY = 0
GRASS = 1
Expand Down Expand Up @@ -45,6 +49,43 @@
(0.5, 0.5, 0.5),
]

sqs=boto3.client('sqs')

def store_checkpoint(checkpoint):
response=sqs.send_message(
QueueUrl=QUEUE_URL,
DelaySeconds=10,
MessageBody=(checkpoint)
)
print(response['MessageId'])
sys.stdout.flush()

def pull_checkpoint():
response=sqs.receive_message(
QueueUrl=QUEUE_URL,
MaxNumberOfMessages=1,
VisibilityTimeout=0,
WaitTimeSeconds=0
)
print('in pull_checkpoint:response:%s'%response)
if 'Messages' in response.keys():
message=response['Messages'][0]
receipt_handle=message['ReceiptHandle']
last_checkpoint=message['Body']
print('in pull_checkpoint:last_checkpoint %s' % last_checkpoint)
sys.stdout.flush()

sqs.delete_message(
QueueUrl=QUEUE_URL,
ReceiptHandle=receipt_handle
)
print('in pull_checkpoint:Received and deleted message:%s'%message)
sys.stdout.flush()
else:
print('in pull_checkpoint: no previous checkpoints in queue')
last_checkpoint="1"
return last_checkpoint

def sphere(cx, cy, cz, r, fill=False, fx=False, fy=False, fz=False):
result = set()
for x in range(cx - r, cx + r + 1):
Expand Down Expand Up @@ -143,7 +184,7 @@ class Client(object):
def __init__(self, host, port):
self.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.conn.connect((host, port))
self.authenticate()
#self.authenticate()
def authenticate(self):
username, identity_token = get_identity()
url = 'https://craft.michaelfogleman.com/api/1/identity'
Expand All @@ -154,11 +195,27 @@ def authenticate(self):
response = requests.post(url, data=payload)
if response.status_code == 200 and response.text.isalnum():
access_token = response.text
self.conn.sendall('A,%s,%s\n' % (username, access_token))
buf=b''
string='A,%s,%s\n' % (username, access_token)
buf=bytes(string,'utf-8')
self.conn.sendall(buf)
print(buf)
sys.stdout.flush()
else:
raise Exception('Failed to authenticate.')
def set_block(self, x, y, z, w):
self.conn.sendall('B,%d,%d,%d,%d\n' % (x, y, z, w))
buf=b''
string='B,%d,%d,%d,%d\n' % (x, y, z, w)
buf=bytes(string,'utf-8')
try:
r=self.conn.sendall(buf)
print('buf={},r={}'.format(buf,r))
sys.stdout.flush()
time.sleep(1)
except Exception as error:
print('in set_block:error:',error)
sys.stdout.flush()
#self.conn.sendall('B,%d,%d,%d,%d\n' % (x, y, z, w))
def set_blocks(self, blocks, w):
key = lambda block: (block[1], block[0], block[2])
for x, y, z in sorted(blocks, key=key):
Expand Down Expand Up @@ -186,63 +243,83 @@ def get_client():
return client

def main():
client = get_client()
set_block = client.set_block
set_blocks = client.set_blocks
# set_blocks(circle_y(0, 32, 0, 16, True), STONE)
# set_blocks(circle_y(0, 33, 0, 16), BRICK)
# set_blocks(cuboid(-1, 1, 1, 31, -1, 1), CEMENT)
# set_blocks(cuboid(-1024, 1024, 32, 32, -3, 3), STONE)
# set_blocks(cuboid(-3, 3, 32, 32, -1024, 1024), STONE)
# set_blocks(cuboid(-1024, 1024, 33, 33, -3, -3), BRICK)
# set_blocks(cuboid(-1024, 1024, 33, 33, 3, 3), BRICK)
# set_blocks(cuboid(-3, -3, 33, 33, -1024, 1024), BRICK)
# set_blocks(cuboid(3, 3, 33, 33, -1024, 1024), BRICK)
# set_blocks(sphere(0, 32, 0, 16), GLASS)
# for y in range(1, 32):
# set_blocks(circle_y(0, y, 0, 4, True), CEMENT)
# set_blocks(circle_x(16, 33, 0, 3), BRICK)
# set_blocks(circle_x(-16, 33, 0, 3), BRICK)
# set_blocks(circle_z(0, 33, 16, 3), BRICK)
# set_blocks(circle_z(0, 33, -16, 3), BRICK)
# for x in range(0, 1024, 32):
# set_blocks(cuboid(x - 1, x + 1, 31, 32, -1, 1), CEMENT)
# set_blocks(cuboid(-x - 1, -x + 1, 31, 32, -1, 1), CEMENT)
# set_blocks(cuboid(x, x, 1, 32, -1, 1), CEMENT)
# set_blocks(cuboid(-x, -x, 1, 32, -1, 1), CEMENT)
# for z in range(0, 1024, 32):
# set_blocks(cuboid(-1, 1, 31, 32, z - 1, z + 1), CEMENT)
# set_blocks(cuboid(-1, 1, 31, 32, -z - 1, -z + 1), CEMENT)
# set_blocks(cuboid(-1, 1, 1, 32, z, z), CEMENT)
# set_blocks(cuboid(-1, 1, 1, 32, -z, -z), CEMENT)
# for x in range(0, 1024, 8):
# set_block(x, 32, 0, CEMENT)
# set_block(-x, 32, 0, CEMENT)
# for z in range(0, 1024, 8):
# set_block(0, 32, z, CEMENT)
# set_block(0, 32, -z, CEMENT)
# set_blocks(pyramid(32, 32+64-1, 12, 32, 32+64-1), COBBLE)
# outer = circle_y(0, 11, 0, 176 + 3, True)
# inner = circle_y(0, 11, 0, 176 - 3, True)
# set_blocks(outer - inner, STONE)
# a = sphere(-32, 48, -32, 24, True)
# b = sphere(-24, 40, -24, 24, True)
# set_blocks(a - b, PLANK)
# set_blocks(cylinder_x(-64, 64, 32, 0, 8), STONE)
# data = [
# '...............................',
# '..xxx..xxxx...xxx..xxxxx.xxxxx.',
# '.x...x.x...x.x...x.x.......x...',
# '.x.....xxxx..xxxxx.xxx.....x...',
# '.x...x.x..x..x...x.x.......x...',
# '..xxx..x...x.x...x.x.......x...',
# '...............................',
# ]
# lookup = {
# 'x': STONE,
# '.': PLANK,
# }
# client.bitmap(0, 32, 32, (1, 0, 0), (0, -1, 0), data, lookup)
client = get_client()
set_block = client.set_block
set_blocks = client.set_blocks
#store_checkpoint('1')
last_checkpoint=pull_checkpoint()
print('in main:lastcheckpoint ',last_checkpoint)
match last_checkpoint:
case '1':
set_blocks(circle_y(0, 32, 0, 16, True), STONE)
set_blocks(circle_y(0, 33, 0, 16), BRICK)
set_blocks(cuboid(-1, 1, 1, 31, -1, 1), CEMENT)
set_blocks(cuboid(-1024, 1024, 32, 32, -3, 3), STONE)
set_blocks(cuboid(-3, 3, 32, 32, -1024, 1024), STONE)
set_blocks(cuboid(-1024, 1024, 33, 33, -3, -3), BRICK)
set_blocks(cuboid(-1024, 1024, 33, 33, 3, 3), BRICK)
set_blocks(cuboid(-3, -3, 33, 33, -1024, 1024), BRICK)
set_blocks(cuboid(3, 3, 33, 33, -1024, 1024), BRICK)
set_blocks(sphere(0, 32, 0, 16), GLASS)
store_checkpoint('1')
case '2':
for y in range(1, 32):
set_blocks(circle_y(0, y, 0, 4, True), CEMENT)
set_blocks(circle_x(16, 33, 0, 3), BRICK)
set_blocks(circle_x(-16, 33, 0, 3), BRICK)
set_blocks(circle_z(0, 33, 16, 3), BRICK)
set_blocks(circle_z(0, 33, -16, 3), BRICK)
store_checkpoint('2')
case '3':
for x in range(0, 1024, 32):
set_blocks(cuboid(x - 1, x + 1, 31, 32, -1, 1), CEMENT)
set_blocks(cuboid(-x - 1, -x + 1, 31, 32, -1, 1), CEMENT)
set_blocks(cuboid(x, x, 1, 32, -1, 1), CEMENT)
set_blocks(cuboid(-x, -x, 1, 32, -1, 1), CEMENT)
store_checkpoint('3')
case '4':
for z in range(0, 1024, 32):
set_blocks(cuboid(-1, 1, 31, 32, z - 1, z + 1), CEMENT)
set_blocks(cuboid(-1, 1, 31, 32, -z - 1, -z + 1), CEMENT)
set_blocks(cuboid(-1, 1, 1, 32, z, z), CEMENT)
set_blocks(cuboid(-1, 1, 1, 32, -z, -z), CEMENT)
store_checkpoint('4')
case '5':
for x in range(0, 1024, 8):
set_block(x, 32, 0, CEMENT)
set_block(-x, 32, 0, CEMENT)
store_checkpoint('5')
case '6':
for z in range(0, 1024, 8):
set_block(0, 32, z, CEMENT)
set_block(0, 32, -z, CEMENT)
store_checkpoint('6')
case '7':
set_blocks(pyramid(32, 32+64-1, 12, 32, 32+64-1), COBBLE)
outer = circle_y(0, 11, 0, 176 + 3, True)
inner = circle_y(0, 11, 0, 176 - 3, True)
set_blocks(outer - inner, STONE)
a = sphere(-32, 48, -32, 24, True)
b = sphere(-24, 40, -24, 24, True)
set_blocks(a - b, PLANK)
set_blocks(cylinder_x(-64, 64, 32, 0, 8), STONE)
store_checkpoint('7')
case '8':
data = [
'...............................',
'..xxx..xxxx...xxx..xxxxx.xxxxx.',
'.x...x.x...x.x...x.x.......x...',
'.x.....xxxx..xxxxx.xxx.....x...',
'.x...x.x..x..x...x.x.......x...',
'..xxx..x...x.x...x.x.......x...',
'...............................',
]
lookup = {
'x': STONE,
'.': PLANK,
}
client.bitmap(0, 32, 32, (1, 0, 0), (0, -1, 0), data, lookup)
store_checkpoint('8')

if __name__ == '__main__':
main()
7 changes: 7 additions & 0 deletions craft.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

while true
do
./craft craft.yahav.sa.aws.dev 4080
sleep 2
done
69 changes: 69 additions & 0 deletions create_db_schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
create SEQUENCE block_rowid start 1;
create SEQUENCE light_rowid start 1;
create SEQUENCE sign_rowid start 1;
create SEQUENCE block_history_rowid start 1;

create table block (
rowid bigint default nextval('public.block_rowid'::regclass) primary key,
updated_at timestamp,
user_id varchar(64) not null,
p int not null,
q int not null,
x int not null,
y int not null,
z int not null,
w int not null
);
alter table block add constraint unique_block_pqxyz unique (p,q,x,y,z);

create table if not exists light (
rowid bigint default nextval('public.light_rowid'::regclass) primary key,
p int not null,
q int not null,
x int not null,
y int not null,
z int not null,
w int not null
);
create unique index if not exists light_pqxyz_idx on light (p, q, x, y, z);

create table if not exists sign (
rowid bigint default nextval('public.sign_rowid'::regclass) primary key,
p int not null,
q int not null,
x int not null,
y int not null,
z int not null,
face int not null,
text text not null
);
create index if not exists sign_pq_idx on sign (p, q);

create unique index if not exists sign_xyzface_idx on sign (x, y, z, face);

create table if not exists block_history (
rowid bigint default nextval('public.block_history_rowid'::regclass),
created_at timestamp,
user_id varchar(64) not null,
p int not null,
q int not null,
x int not null,
y int not null,
z int not null,
w int not null,
primary key (rowid,created_at)
) partition by range (created_at);

CREATE SCHEMA partman;
CREATE EXTENSION pg_partman WITH SCHEMA partman;

SELECT partman.create_parent( p_parent_table => 'public.block_history',
p_control => 'created_at',
p_type => 'native',
p_interval=> 'monthly',
p_premake => 24);

create table user_recent_pos(updated_at timestamp,user_id varchar(64) not null,x int not null,y int not null,z int not null);

alter table user_recent_pos add constraint unique_username unique (user_id);
alter table auth_app_user add constraint unique_authappusername unique (username);
Loading