Skip to content

Commit 128006d

Browse files
authored
Merge pull request #33 from habecker/feat/docker
Feat/docker
2 parents 8b6f788 + 5df0a97 commit 128006d

File tree

410 files changed

+179514
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

410 files changed

+179514
-16
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ test/
2121
gamemodes/reloadable-gamemode/
2222
gamemodes/remote-client/
2323
gamemodes/remote-server/
24-
server/
24+
server/
25+
target/

docker/.DS_Store

6 KB
Binary file not shown.

docker/make.Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
ARG BASE
2+
3+
FROM $BASE
4+
5+
6+
RUN apt-get update && apt-get install -y build-essential g++ cmake g++-multilib git
7+
RUN apt-get install -f
8+
9+
# install dependencies
10+
11+
RUN mkdir /root/sampgdk
12+
13+
RUN git clone https://github.com/Zeex/sampgdk.git /root/sampgdk
14+
RUN git clone https://github.com/Zeex/samp-plugin-sdk.git /root/sampsdk
15+
16+
RUN apt-get update && apt-get install -y python2.7 python-pip
17+
RUN pip install ply
18+
19+
RUN mkdir /root/sampgdk/build
20+
RUN cd /root/sampgdk/build && cmake .. -DSAMP_SDK_ROOT=/root/sampsdk -DSAMPGDK_STATIC=ON -DSAMPGDK_BUILD_AMALGAMATION=ON
21+
RUN cmake --build /root/sampgdk/build --config Release
22+
RUN cmake --build /root/sampgdk/build --config Release --target install
23+
24+
RUN dpkg --add-architecture i386
25+
RUN apt-get update && apt-get install -y software-properties-common
26+
RUN add-apt-repository ppa:deadsnakes/ppa
27+
28+
RUN apt-get update && apt-get install -y python3.8-dev:i386 libpython3.8-dev:i386
29+
# RUN apt-get install -f
30+
31+
# RUN apt-get update && apt-get install -y wget
32+
33+
# RUN mkdir /root/python
34+
# RUN cd /root/python && wget https://github.com/python/cpython/archive/v3.8.3.tar.gz && tar xvf v3.8.3.tar.gz
35+
36+
37+
WORKDIR /usr/src/pysamp
38+
COPY . .
39+
40+
RUN [ "cmake", "./src", "-G", "Unix Makefiles", "-DSAMPSDK_DIR=/root/sampsdk", "-DSAMPGDK_DIR=/root/sampgdk", "-DCMAKE_BUILD_TYPE=Debug", "-DPYTHON_INCLUDE_DIRS=/usr/include/i386-linux-gnu/python3.8", "-DPYTHON_LIBRARY=/usr/lib/i386-linux-gnu/libpython3.8.so" ]
41+
CMD make; cp ./PySAMP.so /target/

docker/make.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
docker build -f ./make.Dockerfile -t pysamp/make --build-arg BASE=ubuntu:bionic ../
2+
3+
#docker build -f ./base.Dockerfile -t pysamp/eoan --build-arg BASE=ubuntu:eoan ../
4+
#docker build -f ./base.Dockerfile -t pysamp/focal --build-arg BASE=ubuntu:focal ../
5+
6+
#docker build -f ./base.Dockerfile -t pysamp/stretch --build-arg BASE=debian:stretch ../
7+
#docker build -f ./base.Dockerfile -t pysamp/buster --build-arg BASE=debian:buster ../
8+
9+
docker run --name pysamp -v "$(cd ../ && pwd)"/target:/target --rm pysamp/make

docker/scripts/check_server_config.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!python3
2+
import sys, os, random, string
3+
4+
if __name__ == "__main__":
5+
if len(sys.argv) < 2:
6+
print("Error, missing argument for server.cfg path")
7+
exit(1)
8+
updated_config = ''
9+
added_plugins = False
10+
with open(os.path.join(sys.argv[1], 'server.cfg')) as f:
11+
for line in f:
12+
if line.lstrip()[0] == '#':
13+
continue
14+
line = line.rstrip(' \r\n')
15+
k,v = line.split(' ', 1)
16+
17+
if k == 'gamemode0' and v != 'empty 1':
18+
v = 'empty 1'
19+
20+
if k == 'plugins' and 'PySAMP.so' not in v:
21+
added_plugins = True
22+
v += 'PySAMP.so'
23+
elif k == 'plugins' and 'PySAMP.so' in v:
24+
added_plugins = True
25+
if k == 'rcon_password' and v == 'changeme':
26+
print("Changed default password!")
27+
v = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(12))
28+
updated_config += '%s %s\n' % (k, v)
29+
30+
if not added_plugins:
31+
updated_config += 'plugins PySAMP.so\n'
32+
33+
with open(os.path.join(sys.argv[1], 'server.cfg'), 'w') as f:
34+
f.write(updated_config)
35+
36+

docker/scripts/empty.amx

1.31 KB
Binary file not shown.

docker/scripts/empty.pwn

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
// This is a comment
2+
// uncomment the line below if you want to write a filterscript
3+
//#define FILTERSCRIPT
4+
5+
#include <a_samp>
6+
7+
8+
9+
main()
10+
{
11+
}
12+
13+
public OnGameModeInit()
14+
{
15+
return 1;
16+
}
17+
18+
public OnGameModeExit()
19+
{
20+
return 1;
21+
}
22+
23+
public OnPlayerRequestClass(playerid, classid)
24+
{
25+
return 1;
26+
}
27+
28+
public OnPlayerConnect(playerid)
29+
{
30+
return 1;
31+
}
32+
33+
public OnPlayerDisconnect(playerid, reason)
34+
{
35+
return 1;
36+
}
37+
38+
public OnPlayerSpawn(playerid)
39+
{
40+
return 1;
41+
}
42+
43+
public OnPlayerDeath(playerid, killerid, reason)
44+
{
45+
return 1;
46+
}
47+
48+
public OnVehicleSpawn(vehicleid)
49+
{
50+
return 1;
51+
}
52+
53+
public OnVehicleDeath(vehicleid, killerid)
54+
{
55+
return 1;
56+
}
57+
58+
public OnPlayerText(playerid, text[])
59+
{
60+
return 1;
61+
}
62+
63+
public OnPlayerCommandText(playerid, cmdtext[])
64+
{
65+
return 0;
66+
}
67+
68+
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
69+
{
70+
return 1;
71+
}
72+
73+
public OnPlayerExitVehicle(playerid, vehicleid)
74+
{
75+
return 1;
76+
}
77+
78+
public OnPlayerStateChange(playerid, newstate, oldstate)
79+
{
80+
return 1;
81+
}
82+
83+
public OnPlayerEnterCheckpoint(playerid)
84+
{
85+
return 1;
86+
}
87+
88+
public OnPlayerLeaveCheckpoint(playerid)
89+
{
90+
return 1;
91+
}
92+
93+
public OnPlayerEnterRaceCheckpoint(playerid)
94+
{
95+
return 1;
96+
}
97+
98+
public OnPlayerLeaveRaceCheckpoint(playerid)
99+
{
100+
return 1;
101+
}
102+
103+
public OnRconCommand(cmd[])
104+
{
105+
return 1;
106+
}
107+
108+
public OnPlayerRequestSpawn(playerid)
109+
{
110+
return 1;
111+
}
112+
113+
public OnObjectMoved(objectid)
114+
{
115+
return 1;
116+
}
117+
118+
public OnPlayerObjectMoved(playerid, objectid)
119+
{
120+
return 1;
121+
}
122+
123+
public OnPlayerPickUpPickup(playerid, pickupid)
124+
{
125+
return 1;
126+
}
127+
128+
public OnVehicleMod(playerid, vehicleid, componentid)
129+
{
130+
return 1;
131+
}
132+
133+
public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
134+
{
135+
return 1;
136+
}
137+
138+
public OnVehicleRespray(playerid, vehicleid, color1, color2)
139+
{
140+
return 1;
141+
}
142+
143+
public OnPlayerSelectedMenuRow(playerid, row)
144+
{
145+
return 1;
146+
}
147+
148+
public OnPlayerExitedMenu(playerid)
149+
{
150+
return 1;
151+
}
152+
153+
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
154+
{
155+
return 1;
156+
}
157+
158+
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
159+
{
160+
return 1;
161+
}
162+
163+
public OnRconLoginAttempt(ip[], password[], success)
164+
{
165+
return 1;
166+
}
167+
168+
public OnPlayerUpdate(playerid)
169+
{
170+
return 1;
171+
}
172+
173+
public OnPlayerStreamIn(playerid, forplayerid)
174+
{
175+
return 1;
176+
}
177+
178+
public OnPlayerStreamOut(playerid, forplayerid)
179+
{
180+
return 1;
181+
}
182+
183+
public OnVehicleStreamIn(vehicleid, forplayerid)
184+
{
185+
return 1;
186+
}
187+
188+
public OnVehicleStreamOut(vehicleid, forplayerid)
189+
{
190+
return 1;
191+
}
192+
193+
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
194+
{
195+
return 1;
196+
}
197+
198+
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
199+
{
200+
return 1;
201+
}

docker/scripts/start_server.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
./samp03svr 2>&1

docker/server.Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ARG BASE
2+
3+
FROM $BASE
4+
5+
# install dependencies
6+
RUN dpkg --add-architecture i386
7+
RUN apt-get update && apt-get install -y software-properties-common
8+
RUN add-apt-repository ppa:deadsnakes/ppa
9+
RUN apt-get update && apt-get install -y python3.8:i386 libpython3.8:i386
10+
RUN apt-get update && apt-get install -y libstdc++6:i386
11+
12+
WORKDIR /server
13+
14+
CMD "./start_server.sh"

docker/server.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
# build PySAMP
4+
./make.sh
5+
6+
# create server dir if it doesn't exist
7+
if [[ ! -d ../server ]]; then
8+
mkdir ../server
9+
cd ../server
10+
wget http://files.sa-mp.com/samp037svr_R2-1.tar.gz
11+
tar xvf samp037svr_R2-1.tar.gz
12+
mv samp03/* ./
13+
rm -rf samp03
14+
cd ../docker
15+
fi
16+
17+
# add empty gamemode if it doesn't exist
18+
if [[ ! -f ../server/gamemodes/empty.amx ]]; then
19+
cp ./scripts/empty.amx ../server/gamemodes/
20+
fi
21+
22+
# create plugins folder
23+
if [[ ! -d ../server/plugins ]]; then
24+
mkdir ../server/plugins
25+
fi
26+
27+
# copy plugin to server
28+
cp ../target/PySAMP.so ../server/plugins/
29+
30+
# create python gamemode directory (if it doesn't exist)
31+
if [[ ! -d ../server/python ]]; then
32+
mkdir ../server/python
33+
cp -r ../gamemodes/empty/* ../server/python
34+
fi
35+
36+
# copy start script to server
37+
cp scripts/start_server.sh ../server
38+
chmod +x ../server/start_server.sh
39+
40+
# add plugin to server config and set password if it's still changeme
41+
python3 scripts/check_server_config.py ../server/
42+
43+
44+
docker build -f ./server.Dockerfile -t pysamp/server --build-arg BASE=ubuntu:bionic ../
45+
docker run --name pysamp_server -v "$(cd ../ && pwd)"/server:/server -p 7777:7777 -p 7777:7777/udp --rm -it pysamp/server

0 commit comments

Comments
 (0)