Advertisement
Guest User

DRAWBALL

a guest
Apr 25th, 2015
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.24 KB | None | 0 0
  1. from __future__ import division
  2. import math, string, socket, random, Image
  3.  
  4. class NioSock:
  5.     def __init__(self):
  6.         self.id = 0
  7.         self.conn = socket.socket();
  8.         self.conn.connect(("207.115.84.38", 8009))
  9.         self.conn.setblocking(0)
  10.         self.onConnect()
  11.    
  12.     def send_str(self, str):
  13.         self.send_raw(str + "\x00")
  14.    
  15.     def send_raw(self, data):
  16.         #self.printData(data, False)
  17.         self.conn.send(data);
  18.    
  19.     def update(self):
  20.         try: data = self.conn.recv(1024)
  21.         except socket.error: pass
  22.         else:
  23.             #self.printData(data, True)
  24.             self.onRecv(data)
  25.    
  26.     @staticmethod
  27.     def i2s(data, _len):
  28.         ret = ""
  29.         multiplier = 0
  30.         v = data
  31.         _pow = math.pow(127, _len - 1)
  32.         it = 1
  33.        
  34.         while (it <= _len):
  35.             multiplier = int(math.floor(v / _pow))
  36.             v -= multiplier * _pow
  37.             ret += chr(multiplier + 1)
  38.             if (it != _len):
  39.                 _pow /= 127
  40.             it += 1
  41.         return ret
  42.    
  43.     @staticmethod
  44.     def s2i(data):
  45.         ret = 0
  46.         multiplier = 1
  47.         it = len(data) - 1
  48.         while (it >= 0):
  49.             ret += (ord(data[it]) - 1) * multiplier
  50.             multiplier *= 127
  51.             it -= 1
  52.         return ret
  53.    
  54.     @staticmethod
  55.     def rgb(r, g, b):
  56.         return 65536 * r + 256 * g + b
  57.    
  58.     def randrgb(self):
  59.         return self.rgb(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
  60.    
  61.     def onConnect(self):
  62.         self.loginstep = 0
  63.         self.send_str("<policy-file-request/>")
  64.    
  65.     def dot(self, size, color, x, y):
  66.         Color = self.i2s(color, 4)
  67.         X = self.i2s(x, 3)
  68.         Y = self.i2s(y, 3)
  69.         self.send_raw("\x61\x01\x01\x09" + chr(size+1+3) + Color + X + Y + self.i2s(x+1, 3) + self.i2s(y+1, 3) + "\x00")
  70.        
  71.     def printData(self, data, incoming):
  72.         n = 16
  73.         chunks = [data[i:i+n] for i in range(0, len(data), n)]
  74.        
  75.         print((incoming and "RECV" or "SEND") + ": " + str(len(data)) + " bytes")
  76.         for chunk in chunks:
  77.             print(" ".join("{:02x}".format(ord(c)).upper() for c in chunk).ljust(16*2 + 15, " ") + "  " + "".join((c in string.printable.replace("\x0A", "").replace("\x09", "")) and c or "." for c in chunk))
  78.         print("")
  79.    
  80.     def onRecv(self, data):
  81.         if (self.loginstep == 2):
  82.             if (data.startswith("r")):
  83.                 self.ink = 9000 * (self.s2i(data[1: 5]) - 1000) / (2000000 - 1000)
  84.                 print("INK AVAILABLE: " + str(self.ink))
  85.                 print("\n")
  86.             self.send_raw("\x00")
  87.             self.doWork()
  88.         else: self.login(data)
  89.    
  90.     def login(self, data):
  91.         if (self.loginstep == 1):
  92.             self.loginstep = 2
  93.             it = 0
  94.             pck = b""
  95.             while (it < 7):
  96.                 pck += chr(ord("ayylmao"[it]) - (ord(data[it*2])-65))
  97.                 it += 1
  98.             self.send_raw(pck + "\x00e\x00i\x00b\x01\x01\x01\x01\x07\x00")
  99.             self.initWork()
  100.        
  101.         if (data.startswith("<cross-")):
  102.             self.send_str("ayylmao")
  103.             self.loginstep = 1
  104.    
  105.     def initWork(self):
  106.         self.startX = 30000
  107.         self.startY = 20000
  108.         self.pSize = 10
  109.         self.imageRGB = Image.open("creepy.jpg").convert("RGB")
  110.         self.xIt = 0
  111.         self.yIt = 0
  112.    
  113.     def doWork(self):
  114.         _w, _h = self.imageRGB.size
  115.         _x, _y, _z = self.imageRGB.getpixel((self.xIt * self.pSize, self.yIt * self.pSize))
  116.         self.dot(self.pSize, self.rgb(_x, _y, _z), self.startX + self.xIt * self.pSize, self.startY + self.yIt * self.pSize)
  117.         self.xIt += 1
  118.         if (self.pSize * self.xIt >= _w):
  119.             self.xIt = 0
  120.             self.yIt += 1
  121.         if (self.pSize * self.yIt >= _h):
  122.             self.yIt = 0
  123.  
  124. sock = NioSock()
  125. while True:
  126.     sock.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement