@@ -132,6 +132,12 @@ def _set_environment(self):
132132 'sc_backup' : os .path .join (self .env ['bwd' ], 'server.config' )
133133 })
134134
135+ server_logs = [os .path .join ('logs' , 'latest.log' ), 'server.log' ]
136+ for i in server_logs :
137+ path = os .path .join (self .env ['cwd' ], i )
138+ if os .path .isfile (path ):
139+ self .env ['log' ] = path
140+
135141 def _load_config (self , load_backup = False , generate_missing = False ):
136142 """Loads server.properties and server.config for a given server.
137143 With load_backup, /backup/ is referred to rather than /servers/.
@@ -809,13 +815,29 @@ def bytesto(num, to, bsize=1024):
809815 return '%s MB' % bytesto (mem , 'm' )
810816 except IOError :
811817 return '0'
812-
818+
813819 @property
814820 def ping (self ):
815821 """Returns a named tuple using the current Minecraft protocol
816822 to retreive versions, player counts, etc"""
817823 import socket
818824
825+ def server_list_packet ():
826+ """Guesses what version minecraft a live server directory is."""
827+ if self .env ['log' ].endswith ('server.log' ):
828+ return '\xfe ' \
829+ '\x01 ' \
830+ '\xfa ' \
831+ '\x00 \x06 ' \
832+ '\x00 \x6d \x00 \x69 \x00 \x6e \x00 \x65 \x00 \x6f \x00 \x73 ' \
833+ '\x00 \x19 ' \
834+ '\x49 ' \
835+ '\x00 \x09 ' \
836+ '\x00 \x6c \x00 \x6f \x00 \x63 \x00 \x61 \x00 \x6c \x00 \x68 ' \
837+ '\x00 \x6f \x00 \x73 \x00 \x74 ' \
838+ '\x00 \x00 \x63 \xdd '
839+ return '\xfe \x01 '
840+
819841 server_ping = namedtuple ('ping' , ['protocol_version' ,
820842 'server_version' ,
821843 'motd' ,
@@ -826,17 +848,7 @@ def ping(self):
826848 try :
827849 s = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
828850 s .connect ((self .ip_address , self .port ))
829- s .send ('\xfe ' #1
830- '\x01 ' #2
831- '\xfa ' #3
832- '\x00 \x06 ' #4
833- '\x00 \x6d \x00 \x69 \x00 \x6e \x00 \x65 \x00 \x6f \x00 \x73 '
834- '\x00 \x19 ' #6
835- '\x49 ' #7
836- '\x00 \x09 ' #8
837- '\x00 \x6c \x00 \x6f \x00 \x63 \x00 \x61 \x00 \x6c \x00 \x68 '
838- '\x00 \x6f \x00 \x73 \x00 \x74 '
839- '\x00 \x00 \x63 \xdd ' ) #10
851+ s .send (server_list_packet ())
840852
841853 d = s .recv (1024 )
842854 s .shutdown (socket .SHUT_RDWR )
@@ -1244,11 +1256,11 @@ def list_last_loglines(self, lines=100):
12441256 """Returns last n lines from logfile"""
12451257 from procfs_reader import tail
12461258
1247- logfiles = ['server.log' , os .path .join ('logs' , 'latest.log' )]
1259+ logfiles = ['server.log' , os .path .join ('logs' , 'latest.log' )]
12481260
12491261 for i in logfiles :
12501262 try :
1251- with open (os .path .join (self .env ['cwd' ], logfiles ), 'rb' ) as log :
1263+ with open (os .path .join (self .env ['cwd' ], i ), 'rb' ) as log :
12521264 return tail (log , int (lines ))
12531265 except IOError :
12541266 pass
0 commit comments