forked from t3rminalV/PyRat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
184 lines (136 loc) · 3.97 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# Remote ArmA Server Administration Tool
# Written by Adam McKissock
import os, sys, socket, wmi, urllib, time, zipfile, fileinput
from subprocess import Popen
server = "";
action = "";
pid = "";
codever = "";
actionfile = "";
def header():
os.system("cls");
print '''
##########################################
## ##
## Remote Administration Tool ##
## Server Application ##
## Written by Adam McKissock ##
## ##
##########################################
''';
def openSocket():
try:
print "\nWaiting For Connection..."
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
sock.bind (("", 1337));
sock.listen(1);
except socket.error, (value,message):
if sock:
sock.close();
print "Could not open socket: " + message;
while True:
channel, details = sock.accept();
print "We have opened a connection with", details;
temp = channel.recv(100);
channel.close();
print "Connection with", details, "closed.";
return temp;
break;
def getPid(name):
filename = "pid/" + name + ".txt";
file = open(filename,"r");
content = file.read();
return content;
def isRunning():
global pid;
pid = getPid(server);
c = wmi.WMI();
count = 0
for process in c.Win32_Process (ProcessId=pid):
print process.ProcessId, process.Name;
count = count + 1;
if count > 0:
return 1;
else:
return 0;
def stopServer():
global pid;
pid = getPid(server);
isrunning = isRunning();
if isrunnning == 1:
c = wmi.WMI()
for process in c.Win32_Process (ProcessId=pid):
process.Terminate ();
print "Stopped!";
def startServer():
args = "start ..\\arma2oaserver.exe -port=2302 -mod=@dayz;@CBA;@JayArma2Lib -name=cfgdayz"+server+" -config=cfgdayz"+server+"\\server.cfg -cfg=cfgdayz"+server+"\\arma2.cfg -profiles=cfgdayz"+server+" -cpuCount=2 -world=Chernarus -noFilePatching -pid=dayzrat\\pid\\"+server+".txt";
#args = "start calc.exe"
p = Popen(args, bufsize=0, executable=None,stdin=None, stdout=None, stderr=None,preexec_fn=None, close_fds=False, shell=True);
time.sleep(5);
class MyThread ( threading.Thread ):
def run ( self ):
os.system("..\\dayz" + server + ".bat");
sys.exit();
def updateServer():
stopServer();
time.sleep(2);
if actionfile == "core":
urllib.urlretrieve("http://www.armafiles.info/" + "dayz/dayz_v" + codever + ".rar", "..\\@dayz\\Addons\\" + actionfile + ".zip");
else:
urllib.urlretrieve("http://www.armafiles.info/" + "dayz/dayz_"+ actionfile + "_v" + codever + ".rar", "..\\@dayz\\Addons\\" + actionfile + ".zip");
time.sleep(1);
os.rename("..\\@dayz\\Addons\\" + actionfile + ".rar","..\\@dayz\\Addons\\" + actionfile + ".zip");
zip = zipfile.ZipFile("..\\@dayz\\Addons\\" + actionfile + ".zip");
zip.extractall(path="..\\@dayz\\Addons\\");
print "Unziped!";
if actionfile == "code":
filename = "..\\" + "cfgdayz" + server + "\\server.cfg";
writestring = 'hostname = "DayZ Zombie RPG - NZ (v' + codever + ') www.dayzmod.com";\n';
f = open(filename,'r');
lines = f.readlines();
f.close();
f = open(filename,'w');
f.write(writestring);
f.write(''.join(lines[1:]));
f.close();
startServer();
def mainLoop():
global server;
global action;
global actionfile;
global codever;
data = "";
data = openSocket();
data = data.split(",");
print "TIST";
print data;
if "anim" in data[1] or "code" in data[1] or "equip" in data[1] or "sfx" in data[1]or "core" in data[1] or "vehicles" in data[1] or "weapons" in data[1]:
print "1";
server = data[0];
action = data[1];
temp = action.split();
action = temp[0];
actionfile = temp[1];
codever = temp[2];
else:
print "2";
server = data[0];
action = data[1];
print "server: " + server;
print "action: " + action;
print "codever: " + codever;
if action == "stop":
stopServer();
mainLoop();
elif action == "start":
startServer();
mainLoop();
elif action == "update":
updateServer();
mainLoop();
else:
print "Wrong command."
mainLoop();
#Main code shizzle.
header();
mainLoop();