summaryrefslogtreecommitdiff
path: root/athena-start
blob: 85cc18bc2680aa29fa7bbd270bd764bc7d3ae52e (plain) (blame)
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/bin/sh
# athena starting script by rowla

# chkconfig: 345 99 01
# description: start and stop athena service

PATH=./:$PATH

L_SRV=./bin/login-server
C_SRV=./bin/char-server
M_SRV=./bin/map-server
L_SRV_C=./conf/login_athena.conf
C_SRV_C=./conf/char_athena.conf
C_SRV_C2=./conf/inter_athena.conf
M_SRV_C=./conf/map_athena.conf
M_SRV_C2=./conf/battle_athena.conf
M_SRV_C3=./conf/atcommand_athena.conf
M_SRV_C4=./conf/script_athena.conf
M_SRV_C5=./conf/msg_athena.conf
M_SRV_C6=./conf/grf-files.txt

print_start() {
#	more << EOF
echo "Athena Starting..."
echo "			(c) 2003 Athena Project."
echo "			URL:http://project-yare.de/"
echo ""
echo "Debug informations will appear,"
echo "since this is a test release."
echo ""
echo "checking..."
#EOF
}

check_account() {
	if [ ! -d ./save ]; then
		mkdir ./save
	fi

	if [ ! -d ./log ]; then
		mkdir ./log
	fi

	if [ ! -d ./conf/import ]; then
		mkdir ./conf/import
	fi

	if [ ! -f ./save/account.txt ]; then
		i=0
		while [ $i -le 4 ];
		do
			echo -e "$i\ts`expr $i + 1`\tp`expr $i + 1`\t-\tS\t0\t0\r" >> save/account.txt
			i=`expr $i + 1`
		done
	fi

	if [ ! -f ./save/athena.txt ]; then
		echo -n > save/athena.txt
	fi

	if [ ! -f ./save/bank.txt ]; then
		echo -n > save/bank.txt
	fi

	if [ ! -f ./save/guild.txt ]; then
		echo -n > save/guild.txt
	fi

	if [ ! -f ./save/party.txt ]; then
		echo -n > save/party.txt
	fi

	if [ ! -f ./save/pet.txt ]; then
		echo -n > save/pet.txt
	fi

	if [ ! -f ./save/storage.txt ]; then
		echo -n > save/storage.txt
	fi

	if [ ! -f ./save/castle.txt ]; then
		i=0
		while [ $i -le 19 ];
		do
			echo -e "$i,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0\r" >> save/castle.txt
			i=`expr $i + 1`
		done
	fi

	if [ ! -f ./conf/import/atcommand_conf.txt ]; then
		echo -n > conf/import/atcommand_conf.txt
	fi

	if [ ! -f ./conf/import/battle_conf.txt ]; then
		echo -n > conf/import/battle_conf.txt
	fi

	if [ ! -f ./conf/import/char_conf.txt ]; then
		echo -n > conf/import/char_conf.txt
	fi

	if [ ! -f ./conf/import/inter_conf.txt ]; then
		echo -n > conf/import/inter_conf.txt
	fi

	if [ ! -f ./conf/import/login_conf.txt ]; then
		echo -n > conf/import/login_conf.txt
	fi

	if [ ! -f ./conf/import/map_conf.txt ]; then
		echo -n > conf/import/map_conf.txt
	fi
}

check_files() {

	for i in ${L_SRV} ${C_SRV} ${M_SRV} ${L_SRV_C} ${C_SRV_C} ${C_SRV_C2} ${M_SRV_C} ${M_SRV_C2} ${M_SRV_C3} ${M_SRV_C4} ${M_SRV_C5} ${M_SRV_C6}
	do
		if [ ! -f ./$i ]; then
    		echo "$i does not exist, or can't run."
    		echo "Stoped, Check your compile or configuration file."
    		exit 1;
		fi
	done

#	more << EOF
echo "Check done."
echo "Looks good, have a nice athena!"
#EOF
}

process_check() {
	# check login server
	if [ ! -f ${L_SRV}.pid ]; then
		login=0
	else
		login=`cat ${L_SRV}.pid`
		login=$(ps ax | grep "${L_SRV}" | grep "${login}" | wc -l)
	fi

	# check char server
	if [ ! -f ${C_SRV}.pid ]; then
		char=0
	else
		char=`cat ${C_SRV}.pid`
		char=$(ps ax | grep "${C_SRV}" | grep "${char}" | wc -l)
	fi

	# check map server
	if [ ! -f ${M_SRV}.pid ]; then
		map=0
	else
		map=`cat ${M_SRV}.pid`
		map=$(ps ax | grep "${M_SRV}" | grep "${map}" | wc -l)
	fi

	# echo "check: ${login} ${char} ${map}"
	echo `expr ${login} + ${char} + ${map}`
}

case $1 in
	'start')
		if [ `process_check` -eq 0 ]; then
			print_start
			check_account
			check_files

			exec ${L_SRV} ${L_SRV_C}&
#			exec ${C_SRV} ${C_SRV_C} ${C_SRV_C2} > /dev/null&
#			exec ${M_SRV} ${M_SRV_C} ${M_SRV_C2} > /dev/null&
			exec ${C_SRV} ${C_SRV_C} ${C_SRV_C2}&
#			exec nice -n -20 ${M_SRV} ${M_SRV_C} ${M_SRV_C2} ${M_SRV_C3} ${M_SRV_C4} ${M_SRV_C5} ${M_SRV_C6}&
			exec ${M_SRV} ${M_SRV_C} ${M_SRV_C2} ${M_SRV_C3} ${M_SRV_C4} ${M_SRV_C5} ${M_SRV_C6}&

			echo "Now Started Athena."
		else
			echo "Athena is already running..."
		fi
;;
	'stop')
		# check map server
		if [ -f ${M_SRV}.pid ]; then
			map=`cat ${M_SRV}.pid`
			map=$(ps ax | grep "${M_SRV}" | grep "${map}" | wc -l)
			if [ ${map} -ne 0 ]; then
				kill `cat ${M_SRV}.pid`
			fi
		fi

		# check char server
		if [ -f ${C_SRV}.pid ]; then
			char=`cat ${C_SRV}.pid`
			char=$(ps ax | grep "${C_SRV}" | grep "${char}" | wc -l)
			if [ ${char} -ne 0 ]; then
				kill `cat ${C_SRV}.pid`
			fi
		fi

		# check login server
		if [ -f ${L_SRV}.pid ]; then
			login=`cat ${L_SRV}.pid`
			login=$(ps ax | grep "${L_SRV}" | grep "${login}" | wc -l)
			if [ ${login} -ne 0 ]; then
				kill `cat ${L_SRV}.pid`
			fi
		fi
	;;
	'kill')
		# check map server
		if [ -f ${M_SRV}.pid ]; then
			map=`cat ${M_SRV}.pid`
			map=$(ps ax | grep "${M_SRV}" | grep "${map}" | wc -l)
			if [ ${map} -ne 0 ]; then
				kill -9 `cat ${M_SRV}.pid`
			fi
		fi

		# check char server
		if [ -f ${C_SRV}.pid ]; then
			char=`cat ${C_SRV}.pid`
			char=$(ps ax | grep "${C_SRV}" | grep "${char}" | wc -l)
			if [ ${char} -ne 0 ]; then
				kill -9 `cat ${C_SRV}.pid`
			fi
		fi

		# check login server
		if [ -f ${L_SRV}.pid ]; then
			login=`cat ${L_SRV}.pid`
			login=$(ps ax | grep "${L_SRV}" | grep "${login}" | wc -l)
			if [ ${login} -ne 0 ]; then
				kill -9 `cat ${L_SRV}.pid`
			fi
		fi
	;;
	'restart')
		if [ `process_check` -eq 0 ]; then
			$0 start
		else
			# check login server
			if [ ! -f ${L_SRV}.pid ]; then
				login=0
			else
				login=`cat ${L_SRV}.pid`
				login=$(ps ax | grep "${L_SRV}" | grep "${login}" | wc -l)
			fi
			if [ ${login} -eq 0 ]; then
				exec ${L_SRV} ${L_SRV_C}&
			fi

			# check char server
			if [ ! -f ${C_SRV}.pid ]; then
				char=0
			else
				char=`cat ${C_SRV}.pid`
				char=$(ps ax | grep "${C_SRV}" | grep "${char}" | wc -l)
			fi
			if [ ${char} -eq 0 ]; then
				exec ${C_SRV} ${C_SRV_C} ${C_SRV_C2}&
			fi

			# check map server
			if [ ! -f ${M_SRV}.pid ]; then
				map=0
			else
				map=`cat ${M_SRV}.pid`
				map=$(ps ax | grep "${M_SRV}" | grep "${map}" | wc -l)
			fi
			if [ ${map} -eq 0 ]; then
				exec ${M_SRV} ${M_SRV_C} ${M_SRV_C2} ${M_SRV_C3} ${M_SRV_C4} ${M_SRV_C5} ${M_SRV_C6}&
			fi
		fi
	;;
	*)
		echo "Usage: athena-start { start | stop | kill | restart }"
	;;
esac