# .-=[ dreamgrab.py ]=======================================================-. # # | Furcadia Dream Grabber 1.0 (c) by IceDragon | # # |==========================================================================| # # | This script scans all the main maps on Furcadia for dream portals and | # # | reports back to the terminal with a list of parental dreams and the | # # | dreams they have within themselves along with their coordinates. | # # |==[ Changelog ]===========================================================| # # | 1.0.0 - Initial release. | # # '-==============================================================[ 1.0.0 ]=-' # ###--# Imports #--### from socket import * from select import select from time import time,sleep from struct import unpack ###--# Configuration #--### # Server address we should use. furc_addr = ( 'lightbringer.furcadia.com', 6500 ) # Account information we should use. furc_login = ( "Username", "Password" ) # A list of main maps and their names. You can use FURL or GOMAP characters here. furc_maps = { ' ': "Vinca", '#': "Allegria Island", '$': "Challenges", '%': "Furrabian Nights (FurN)", '&': "Meovanni Village", "'": "Hawthorne", '(': "Imaginarium", '*': "Acropolis", 'B': "Silver Showcase", 'D': "Naia Square", 'F': "Festival Map" } # Interval between dream hops in seconds. furc_interval = 3 ###--# Global Variables #--### fdClient = None dreamCounter = 0 totalDreams = 0 ###--# Functions #--### # Converter from base95 numeric system back to decimal. def fdg_fromBase95 ( base95 ): number = 0 multiplier = 1 base95 = list( base95 ) base95.reverse() for digit in base95: number += ( unpack( 'B', digit )[0] - 32 ) * multiplier multiplier *= 95 #for return number # fdg_fromBase95 # Adds a dream to the dreamlist or announces it to the terminal - whatever is # programmed here... def fdg_addDream ( dream_name, dream_text, coords ): global dreamCounter dreamCounter += 1 if not dream_text: dream_text = '' print "(%3d,%3d) %-30s (%s)" % ( coords[0]*2, coords[1], dream_name.replace('|',' '), dream_text.replace('|',' ') ) # fdg_addDream() # This function establishes a connection and logs into Furcadia for us. def fdg_connectClient ( addr ): global fdClient, furc_login sock = socket ( AF_INET, SOCK_STREAM, 0 ) sock.connect ( addr ) connPhase = True phaseName = 'MOTD' while connPhase: data = sock.recv( 4096 ) if len( data ) == 0: sock.close() raise Exception( 'Unexpected EOF from server!' ) if phaseName == 'MOTD': if data[-8:] != "END\n\n\n\n\n": sock.close() raise Exception( 'Incorrect end-of-MOTD command received! Possibly not a gameserver.' ) else: sock.send( 'connect %s %s\n' % furc_login ) phaseName = 'LOGIN' continue elif phaseName == 'LOGIN': if data[:5] == '&'*5: phaseName == 'CONNECT' connPhase = False elif data[:6] == ']#xxxx': message = data[9:] sock.close() raise Exception( 'Access denied: %s' % message ) #while fdClient = sock # fdgLconnectClient() ###--# Initialization #--### print "--+ DreamGrabber 1.0 by IceDragon +--\n" # Connecting... #print "--> Connecting to %s:%d..." % furc_addr try: fdg_connectClient( furc_addr ) except Exception,(data): print "-X- %s" % data raise SystemExit #print "--> Proceeding to dream polls...\n" # Polling dreams for dream in furc_maps.keys(): dreamName = furc_maps[dream] dreamCounter = 0 # Entering dream... print "-- %s" % dreamName if dream[:7] == 'furc://': fdClient.send( 'fdl %s\n' % dream ) else: fdClient.send( 'gomap %s\n' % dream ) fdClient.send( 'onln __FDG__\n' ) # Reading data... dreamList = False nextDream = False while not nextDream: data = fdClient.recv( 4096 ) for line in data.split( '\n' ): if line[:2] == ']s': (x,y) = ( fdg_fromBase95( line[2:4] ), fdg_fromBase95( line[4:6] ) ) dream_name = line[8:].split(' ') if len( dream_name ) > 1: ( dream_name,dream_text ) = dream_name else: dream_name = dream_name[0] dream_text = '' fdg_addDream( dream_name, dream_text, (x,y) ) elif line[:2] == ']%' and line[3:] == '__FDG__': print "-> %d dream(s) found.\n\n" % dreamCounter nextDream = True #while totalDreams += dreamCounter #for print "--> End of scan (%d dreams found)" % totalDreams fdClient.send( 'quit\n' ) fdClient.close() raise SystemExit