Advertisement
Guest User

sac

a guest
Dec 10th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.27 KB | None | 0 0
  1. import socket
  2. import struct
  3. import random
  4. import threading
  5.  
  6. class SABot:
  7. def __init__(self, Username, Password, IP, Port):
  8. self.NullByte = struct.pack('B', 0)
  9. self.BufSize = 4096
  10. self.CommandChar = '$'
  11. self.OnlineUsers = {}
  12. self.OnlineUserMap = {}
  13. self.Dead = []
  14.  
  15. self.NameToIP = {'2D Central': '74.86.43.9:1138', 'Paper Thin City': '74.86.43.8:1138', 'Fine Line Island': '198.58.106.101:1138', 'U of SA': '69.164.207.72:1138',
  16. 'Amsterdam': '139.162.151.57:1138', 'Mobius Metro': '45.56.72.83:1138', 'Cartesian': '198.58.106.101:1139'}
  17.  
  18. self.IPToName = {'74.86.43.9:1138': '2D Central', '74.86.43.8:1138': 'Paper Thin City', '198.58.106.101:1138': 'Fine Line Island', '69.164.207.72:1138': 'U of SA',
  19. '139.162.151.57:1138': 'Amsterdam', '45.56.72.83:1138': 'Mobius Metro', '198.58.106.101:1139': 'Cartesian'}
  20.  
  21. self.ServerIP = IP
  22. self.ServerPort = Port
  23. self.Commands = True
  24. self.BotAdmin = 'Seminary9500' # SET THIS TO THE account you want to be able to use admin commands with
  25. self.BotServer = self.IPToName[ '{}:{}'.format(self.ServerIP, self.ServerPort)]
  26. self.BotPassword = Password
  27.  
  28. self.connectToServer(Username, Password, self.ServerIP, self.ServerPort)
  29.  
  30. def sendPacket(self, Socket, PacketData, Receive = False):
  31. Packet = bytes(PacketData, 'utf-8')
  32.  
  33. if Socket:
  34. Socket.send(Packet + self.NullByte)
  35.  
  36. if Receive:
  37. return Socket.recv(self.BufSize).decode('utf-8')
  38.  
  39. def startKeepAlive(self, TimerSeconds = 20):
  40. if hasattr(self, 'SocketConn'):
  41. KeepAliveTimer = threading.Timer(TimerSeconds, self.startKeepAlive)
  42. KeepAliveTimer.daemon = True
  43. KeepAliveTimer.start()
  44.  
  45. self.sendPacket(self.SocketConn, '0')
  46.  
  47. def sendPrivateMessage(self, UserID, Message):
  48. if UserID != self.BotID:
  49. if UserID in self.OnlineUsers:
  50. self.sendPacket(self.SocketConn, '00' + UserID + 'P' + Message)
  51.  
  52. def sendPublicMessage(self, Message):
  53. self.sendPacket(self.SocketConn, '9' + Message)
  54.  
  55. def connectionHandler(self):
  56. Buffer = b''
  57.  
  58. while hasattr(self, 'SocketConn'):
  59. try:
  60. Buffer += self.SocketConn.recv(self.BufSize)
  61. except ConnectionAbortedError:
  62. return
  63.  
  64. if len(Buffer) == 0:
  65. print('{} has disconnected'.format(self.BotUsername))
  66. self.SocketConn.shutdown(socket.SHUT_RD)
  67. self.SocketConn.close()
  68.  
  69. break
  70. elif Buffer.endswith(self.NullByte):
  71. Receive = Buffer.split(self.NullByte)
  72. Buffer = b''
  73.  
  74. for Data in Receive:
  75. Data = Data.decode('utf-8')
  76.  
  77. if Data.startswith('U'):
  78. UserID = Data[1:][:3]
  79. Username = Data[4:][:20].replace('#', '')
  80.  
  81. self.parseUserData(Data)
  82. elif Data.startswith('D'):
  83. UserID = Data[1:][:3]
  84. Username = self.OnlineUsers[UserID]
  85.  
  86. del self.OnlineUserMap[Username]
  87. del self.OnlineUsers[UserID]
  88. elif Data.startswith('M'):
  89. UserID = Data[1:][:3]
  90.  
  91. self.parseUserMessage(UserID, Data)
  92. elif Data.startswith('0g') or Data.startswith('0j'):
  93. print('{{Server}}: {}'.format(Data[2:]))
  94. elif Data.startswith('0f') or Data.startswith('0e'):
  95. Time, Reason = Data[2:].split(';')
  96. print('This account has just been banned [Time: {} / Reason: {}]'.format(Time, Reason))
  97.  
  98. def connectToServer(self, Username, Password, ServerIP, ServerPort):
  99. try:
  100. self.SocketConn = socket.create_connection((self.ServerIP, self.ServerPort))
  101. except Exception as Error:
  102. print(Error)
  103. return
  104.  
  105. Handshake = self.sendPacket(self.SocketConn, '08HxO9TdCC62Nwln1P', True).strip(self.NullByte.decode('utf-8'))
  106.  
  107. if Handshake == '08':
  108. Credentials = '09{};{}'.format(Username, Password)
  109. RawData = self.sendPacket(self.SocketConn, Credentials, True).split(self.NullByte.decode('utf-8'))
  110.  
  111. for Data in RawData:
  112. if Data.startswith('A'):
  113. self.BotID = Data[1:][:3]
  114. self.BotUsername = Data[4:][:20].replace('#', '')
  115. self.BotCred = Data[43:].split(';')[8]
  116.  
  117. print('Bot Username: {} | Bot ID: {} | Bot Cred: {} | Located in {}'.format(self.BotUsername, self.BotID, self.BotCred, self.BotServer))
  118.  
  119. EntryPackets = ['02Z900_', '03_', '0a', '01']
  120.  
  121. for Packet in EntryPackets:
  122. self.sendPacket(self.SocketConn, Packet)
  123.  
  124. self.startKeepAlive()
  125. ConnectionThread = threading.Thread(target=self.connectionHandler)
  126. ConnectionThread.start()
  127. break
  128. elif Data == '09':
  129. print('Incorrect password')
  130. break
  131. elif Data == '091':
  132. print('Currently banned')
  133. break
  134. else:
  135. print('Server capacity check failed')
  136.  
  137. def parseUserData(self, Packet, Password = None):
  138. StatsString = Packet.replace('\x00', '')
  139. UserID = StatsString[1:][:3]
  140. Type = StatsString[:1]
  141.  
  142. if Type == 'U':
  143. Username = StatsString[4:][:20].replace('#', '')
  144. StatsString = StatsString[24:]
  145.  
  146. self.OnlineUsers[UserID] = Username
  147. self.OnlineUserMap[Username] = UserID
  148.  
  149. def parseUserMessage(self, SenderID, Packet):
  150. if SenderID in self.OnlineUsers:
  151. Sender = self.OnlineUsers[SenderID]
  152.  
  153. NoUseTypes = ['1', '2', '4', '5', '6', '7', '8', '~']
  154. MessageType = Packet[4:][:1]
  155. SenderMessage = Packet[5:]
  156. RawMessage = Packet[1:].replace(SenderID, '')
  157.  
  158. if MessageType in NoUseTypes:
  159. return
  160. elif MessageType == '9':
  161. if self.Commands:
  162. self.handleCommand(SenderID, Sender, SenderMessage, False)
  163. elif MessageType == 'P':
  164. if self.Commands:
  165. self.handleCommand(SenderID, Sender, SenderMessage, True)
  166. else:
  167. self.handleCommand(SenderID, Sender, RawMessage, True)
  168.  
  169. try:
  170. print('[' + Sender + ']: ' + RawMessage)
  171. except:
  172. pass
  173.  
  174. def handleCommand(self, SenderID, Sender, SenderMessage, Private):
  175. RespondByPM = (False if Private == False else True)
  176. Message = SenderMessage.strip()
  177. MessageCheck = Message.split()
  178.  
  179. if Message.startswith(self.CommandChar):
  180. Command = MessageCheck[0][1:].lower()
  181. HasArguments = (True if len(MessageCheck) > 1 else False)
  182. Arguments = (' '.join(MessageCheck[1:]) if HasArguments else None)
  183.  
  184. if Command == 'reset':
  185. RespondByPM = True
  186. self.Dead = []
  187.  
  188. Response = 'RR list has been reset.'
  189. elif Command == 'users':
  190. RespondByPM = True
  191. UserList = []
  192.  
  193. for User in self.OnlineUserMap:
  194. UserList .append(User)
  195.  
  196. Response = 'There are {} people in the lobby. Users: {}'.format(len(UserList), ', '.join(UserList))
  197. elif Command == 'addcol' or Command == 'getcol':
  198. RespondByPM = True
  199.  
  200. if Private:
  201. if HasArguments:
  202. SpinnerType = Arguments.split()[0]
  203. RGB = Arguments.split()[1]
  204. Password = Arguments.replace(' ', '')[12:]
  205. Response = 'Color hackin aint cool but I don\'t give a fuck'
  206.  
  207. ColorRequest = threading.Thread(target=self.handleColorRequest, args=(SenderID, Sender, SpinnerType, RGB, Password))
  208. ColorRequest.daemon = True
  209. ColorRequest.start()
  210. elif Command == 'rr':
  211. if Sender not in self.Dead:
  212. GoodNumber = random.randint(0, 2)
  213. BadNumber = random.randint(0, 2)
  214.  
  215. if GoodNumber == BadNumber:
  216. self.Dead.append(Sender)
  217. Response = 'Bang'
  218. else:
  219. Response = 'Click'
  220. if Command == 'blacklist':
  221. RespondByPM = True
  222.  
  223. if HasArguments:
  224. Target = Arguments.replace(' ', '').lower()
  225. Username = Sender
  226.  
  227. Results = self.executeDatabaseQuery("SELECT * FROM blacklist WHERE username = ?", [(Username)], False, True)
  228.  
  229. if Results:
  230. if Target == 'color':
  231. Blacklisted = Results[0][1]
  232.  
  233. if Blacklisted:
  234. self.executeDatabaseQuery("UPDATE blacklist SET color = 0 WHERE username = ?", [(Username)])
  235. Response = 'Your color codes can now be publicly requested.'
  236. else:
  237. self.executeDatabaseQuery("UPDATE blacklist SET color = 1 WHERE username = ?", [(Username)])
  238. Response = 'Your color codes can no longer be publicly requested.'
  239. elif Target == 'location':
  240. Blacklisted = Results[0][2]
  241.  
  242. if Blacklisted:
  243. self.executeDatabaseQuery("UPDATE blacklist SET location = 0 WHERE username = ?", [(Username)])
  244. Response = 'Your location can now be publicly requested.'
  245. else:
  246. self.executeDatabaseQuery("UPDATE blacklist SET location = 1 WHERE username = ?", [(Username)])
  247. Response = 'Your location can no longer be publicly requested.'
  248. else:
  249. Username = Sender
  250.  
  251. Results = self.executeDatabaseQuery("SELECT * FROM blacklist WHERE username = ?", [(Username)], False, True)
  252.  
  253. if Results:
  254. ColorBlacklisted = Results[0][1]
  255. LocationBlacklisted = Results[0][2]
  256.  
  257. if ColorBlacklisted:
  258. ColorBlacklisted = 0
  259. self.executeDatabaseQuery("UPDATE blacklist SET color = 0 WHERE username = ?", [(Username)])
  260. else:
  261. ColorBlacklisted = 1
  262. self.executeDatabaseQuery("UPDATE blacklist SET color = 1 WHERE username = ?", [(Username)])
  263.  
  264. if LocationBlacklisted:
  265. LocationBlacklisted = 0
  266. self.executeDatabaseQuery("UPDATE blacklist SET location = 0 WHERE username = ?", [(Username)])
  267. else:
  268. LocationBlacklisted = 1
  269. self.executeDatabaseQuery("UPDATE blacklist SET location = 1 WHERE username = ?", [(Username)])
  270.  
  271. ColorBlacklisted = ('Your color codes can no longer be publicly requested' if ColorBlacklisted else 'Your color codes can be publicly requested')
  272. LocationBlacklisted = ('Your location can no longer be publicly requested' if LocationBlacklisted else 'Your location can be publicly requested')
  273.  
  274. Response = '{}; {}'.format(ColorBlacklisted, LocationBlacklisted)
  275. elif Command == 'ajkdhakdhaw' or Command == 'awdjkhda':
  276. RespondByPM = True
  277.  
  278. if HasArguments:
  279. Arguments = Arguments.replace(' ', '')
  280. Target = Arguments
  281. else:
  282. Target = Sender
  283.  
  284. Results = self.executeDatabaseQuery("SELECT * FROM blacklist WHERE lower(username) = ?", [(Target.lower())], False, True)
  285.  
  286. if Results:
  287. Username = Results[0][0]
  288. Blacklisted = Results[0][1]
  289. else:
  290. Username = Target
  291. Blacklisted = 0
  292.  
  293. Results = self.executeDatabaseQuery("SELECT * FROM users WHERE lower(username) = ?", [(Username.lower())], False, True)
  294.  
  295. if Results:
  296. RGB = Results[0][1]
  297. Hex = Results[0][2]
  298.  
  299. if Sender.lower() == Username.lower():
  300. BlacklistCheck = ('blacklisted.' if Blacklisted else 'not blacklisted.')
  301. Response = 'Your color codes: [RGB]: {} | [Hex]: {} / You are {}'.format(RGB, Hex, BlacklistCheck)
  302. else:
  303. if Blacklisted:
  304. if Sender == self.BotAdmin:
  305. Response = '[Blacklisted] {}\'s color codes: [RGB]: {} | [Hex]: {}'.format(Username, RGB, Hex)
  306. else:
  307. Response = '{} isn\'t allowing requests for their color.'.format(Username)
  308. else:
  309. Response = '{}\'s color codes: [RGB]: {} | [Hex]: {}'.format(Username, RGB, Hex)
  310.  
  311. else:
  312. Response = 'There are currently no color codes stored for "{}"'.format(Target)
  313.  
  314. elif Command == 'mud':
  315. Response = 'muddy shit goin down'
  316. elif Command == 'congrats':
  317. if HasArguments:
  318. Response = 'Congratulations on Your new rank, {}!'.format(Arguments.split()[0])
  319. elif Command == 'muddy':
  320. Response = 'so muddy'
  321. elif Command == 'fuckmods':
  322. Response = 'fuck mods and there pussy ass shit'
  323. elif Command == 'carlos':
  324. Response = 'that bitch a power hungry nnniiiggggaaaa'
  325. elif Command == 'luis':
  326. Response = 'worst guy you could ever pick 4 mod'
  327. elif Command == 'krux':
  328. Response = 'that nigga aint done nothin to me'
  329. elif Command == 'lawjax':
  330. Response = 'I wear color hacked spinners infront of him'
  331. elif Command == 'kendry':
  332. Response = 'His afro be lookin like my pubes.'
  333. elif Command == 'sin':
  334. Response = 'he ight'
  335. elif Command == 'ava':
  336. Response = 'nigga got stitched lips'
  337. elif Command == 'getmoney':
  338. Response = 'he cool i guess nigga needs to come online more'
  339. elif Command == 'shot':
  340. Response = 'hit him up for color hacks'
  341. elif Command == 'lileep':
  342. Response = 'He trolled me :\'('
  343. elif Command == 'schallmeister':
  344. Response = 'SCHALLNOOBSTA'
  345. elif Command == 'neo':
  346. Response = 'wait dis nigga inactive but a mod?'
  347. elif Command == 'mousy':
  348. Response = 'Mousy = Big Rat'
  349. elif Command == 'glitch1':
  350. Response = '%' * 135
  351.  
  352.  
  353. if 'Response' in locals():
  354. try:
  355. if Private:
  356. print('[PM from {} in {}] Response: {}'.format(Sender, self.BotServer, Response))
  357. else:
  358. print('[{} in {}] Response: {}'.format(Sender, self.BotServer, Response))
  359. except:
  360. print("failure on print; passing the exception")
  361.  
  362. if RespondByPM:
  363. self.sendPrivateMessage(SenderID, Response)
  364. else:
  365. self.sendPublicMessage(Response)
  366.  
  367. def handleColorRequest(self, SenderID, Sender, SpinnerType, RGB, Password):
  368. SocketConn = socket.create_connection((self.ServerIP, self.ServerPort))
  369. Handshake = self.sendPacket(SocketConn, '08HxO9TdCC62Nwln1P', False).strip(self.NullByte.decode('utf-8'))
  370.  
  371. if Handshake == '08':
  372. Credentials = '09{};{}'.format(Sender, Password)
  373. RawData = self.sendPacket(SocketConn, Credentials, True)
  374.  
  375. for Data in RawData:
  376. if Data.startswith('A'):
  377. self.sendPacket(SocketConn, '02Z900_')
  378. self.sendPacket(SocketConn, '03_')
  379.  
  380. self.sendPacket(SocketConn, '0b' + SpinnerType + RGB + RGB)
  381. elif Data == '09':
  382. SentMessage = False
  383.  
  384. while not SentMessage:
  385. if SenderID in self.OnlineUsers:
  386. SentMessage = True
  387. self.sendPrivateMessage(SenderID, 'Incorrect password')
  388. break
  389.  
  390. break
  391.  
  392. SocketConn.shutdown(socket.SHUT_RD)
  393. SocketConn.close()
  394. del SocketConn
  395.  
  396. if __name__ == '__main__':
  397. Username = '' #username
  398. Password = '' #password
  399.  
  400. SABot(Username, Password, '198.58.106.101', 1139)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement