rendered paste bodyimport threading
import socket
import Queue
import time
myHost = ''
myPort = 6544
furcHost = "lightbringer.furcadia.com"
furcPort = 6500
client_path = 'C:\\progra~1\\furcadia\\'
client_name = 'furcadia.exe'
ini_path = r'C:\docume~1\me\mydocu~1\furcadia\furcad~1\stimpy.ini'
bot_dir = 'C:\\Documents and Settings\\me\\My Documents\\programming\\python\\furcadia\\rose_seller\\'
bot_name = "Stimpy"
class ConnectionToClient(threading.Thread):
def __init__(self, clnt, sevr, message_queue, timer_queue):
self.sevr = sevr
self.clnt = clnt
self.message_queue = message_queue
self.timer_queue = timer_queue
threading.Thread.__init__(self)
def run(self):
while 1:
try:
data = from_client(self.clnt)
except socket.error:
print "Need to reconnect."
break
if data:
self.message_queue.put(('from client', data))
else:
print "Client closed."
self.message_queue.put(('from client', 'quit'))
self.message_queue.put(('exit',0))
break
class ConnectionToServer(threading.Thread):
def __init__(self, clnt, sevr, message_queue, timer_queue):
self.sevr = sevr
self.clnt = clnt
self.message_queue = message_queue
self.timer_queue = timer_queue
threading.Thread.__init__(self)
def run(self):
data = ''
while 1:
(new_data, reconnect) = from_server(self.sevr)
if new_data:
if new_data[-1] == '\x0a':
data += new_data
self.message_queue.put(('from server', data))
if data == "(Communications error.\x0a":
self.message_queue.put(('reconnect', 0))
print "A communications error was encountered."
self.clnt.close()
break
data = ''
else:
data += new_data
else:
if reconnect:
self.message_queue.put(('reconnect', 0))
print "Connection to furcadia server lost."
self.clnt.close()
break
def proxy_ini(myPort):
# fisrt we write the proxy.ini file
try:
f = open(r'c:\program files\furcadia\proxy.ini','r')
saved = f.read()
f.close()
except:
saved = "127.0.0.1 " + str(myPort) + '\n'
f = open(r'c:\program files\furcadia\proxy.ini','w')
f.write("127.0.0.1 " + str(myPort) + '\n')
f.close()
return saved
##############################
class Timers(threading.Thread):
def __init__(self, timer_queue, message_queue):
self.timer_queue = timer_queue
self.message_queue = message_queue
threading.Thread.__init__(self)
def run(self):
times = []
while 1:
if len(times) != 0:
time_remaining = times[len(times)-1][0]-time.time()
if time_remaining < 0:
time_remaining = 0
else: time_remaining = None
try:
(new_time,id) = self.timer_queue.get(timeout = time_remaining) # waits until either time til next one runs out, or
except Queue.Empty: # a new timer trigger comes along.
self.message_queue.put(('timer', times[len(times)-1][1]))
times.pop()
else:
if new_time != -1:
times.append((new_time+time.time(), id))
else:
break
# sort it so the last time is the earliest, then we can pop it later.
for i in range(len(times)-1):
for j in range(len(times)-i-1):
if times[j][0] < times[j+1][0]:
temp = times[j+1]
times[j+1] = times[j]
times[j] = temp
def to_client(data, clnt):
try:
clnt.send(data)
except socket.error:
print "Interruption from ISP"
def from_client(clnt):
data = clnt.recv(32768)
return data
def to_server(data, sevr):
sevr.send(data + '\x0a')
def from_server(sevr):
try:
data = sevr.recv(1024)
except socket.error:
print "Connection to furcadia lost when receiving!"
return ('',1) # 1 signifies reconnect
else:
return (data,0)
def getTimerId(variables):
i = 1
while i in variables.timer_ids:
i+= 1
return i
class ConnectTimeOut(threading.Thread):
def __init__(self, timeout_queue, sevr):
self.timeout_queue = timeout_queue
self.sevr = sevr
threading.Thread.__init__(self)
def run(self):
try:
command = self.timeout_queue.get(timeout = 30)
except Queue.Empty: #if we received no message, we timed out.
print "Connection timed out!"
self.sevr.close()
else:
return 0 # otherwise we just let the function return.
class attrs():
whisper = False
emote = False
speech = False
enter_dream = False
furre_move = False
furre_appear = False
furre_enters = False
furre_vanish = False
bot_ds_trig = False
furre_ds_trig = False
any_ds_trig = False
eight_trigger = False
join_req = False
summon_req = False
emit = False
name = ""
short_name = ""
message = ""
pcxfile = ""
pos_from = (0,0)
pos_to = (0,0)
pos_at = (0,0)
pose = 0
uid = 0
random_seed = 0
ds_lines = []
given_value = 0
direction = ""
entrycode = 0
paw_object = 0
furres_in_dream = 0
class Variables():
def __init__(self, pid, connections):
self.pid = pid
self.connections = connections