@@ -89,6 +89,10 @@ if ! [ $1 == "install" ]; then
89
89
FIFO=" ${WRITE_DIR} /server.fifo"
90
90
fi
91
91
92
+ if [ -z " ${CMDOUT} " ]; then
93
+ CMDOUT=" ${WRITE_DIR} /server.out"
94
+ fi
95
+
92
96
# Finally, set up the invocation
93
97
INVOCATION=" ${BINARY} --config ${FCONF} --port ${PORT} --start-server-load-latest --server-settings ${SERVER_SETTINGS} --autosave-interval ${AUTOSAVE_INTERVAL} --autosave-slots ${AUTOSAVE_SLOTS} --latency-ms ${LATENCY} ${RCON} ${EXTRA_BINARGS} "
94
98
@@ -151,7 +155,7 @@ start_service() {
151
155
return 1
152
156
fi
153
157
154
- as_user " tail -f ${FIFO} |${INVOCATION} > /dev/null 2>&1 & echo \$ ! > ${PIDFILE} "
158
+ as_user " tail -f ${FIFO} |${INVOCATION} > ${CMDOUT} 2>&1 & echo \$ ! > ${PIDFILE} "
155
159
156
160
ps -p $( cat ${PIDFILE} ) > /dev/null 2>&1
157
161
if [ " $? " -ne " 0" ]; then
@@ -200,9 +204,20 @@ stop_service() {
200
204
send_cmd (){
201
205
if is_running; then
202
206
if [ -p ${FIFO} ]; then
203
- echo $@
207
+ # Grab a random 16 character id for our command
208
+ cmdid=$( cat /dev/urandom | tr -dc ' a-zA-Z0-9' | fold -w 16 | head -n 1)
209
+ # Whisper that unknown player named after our random id
210
+ echo " /w ${cmdid} " > ${FIFO}
211
+ # Wait for factorio to read stdin
212
+ sleep 0.5
213
+ # Run the actual command
204
214
echo $@ > ${FIFO}
205
- sleep 1
215
+ # Wait again, this might need more sleep for larger command output - time will tell (sorry future self for any head aches)
216
+ sleep 0.5
217
+ # Read the output file backwards - capture everything between the end of file until
218
+ # factorio tells us our random command id player does not exist
219
+ response=$( sed " /Player ${cmdid} doesn't exist./q" <( tac ${CMDOUT} ) | grep -v ${cmdid} )
220
+ echo " ${response} "
206
221
else
207
222
echo " ${FIFO} is not a pipe!"
208
223
return 1
@@ -235,6 +250,11 @@ check_permissions(){
235
250
exit 1
236
251
fi
237
252
fi
253
+
254
+ if ! as_user " touch ${CMDOUT} " ; then
255
+ echo " Check Permissions. Cannot touch cmd output file ${CMDOUT} "
256
+ exit 1
257
+ fi
238
258
}
239
259
240
260
test_deps (){
0 commit comments