Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import threading
- import time
- import random
- from Tkinter import *
- #Chatango Client
- #Made by MegaLoler
- #Alpha
- #Changes:
- #Fixed some formatting and style bugs, made your name underlined, converted some html codes, and made the windows fixed-size. The chat window will soon be properly resiable
- #Added BBCode support, [b], [u], and [i]
- #Todo:
- #Cleanup weird box characters that sometimes appear at end of messages
- #limit the amount of messages
- #Click on names to put @username in the message field
- #If a message contains @yourusername then it will be highlighted
- #make hyperlinks clickable
- #Add style options
- #Add people here list
- #On connect, load previous messages and other data about the room
- #Add times
- #add avatars
- #add image embedding, and youtube embedding (maybe)
- #catch login errors
- #Preferences window
- #some preferences will unclude... Bypass censor, ...
- #Save prefs, styles, and user info
- #Add smilies, and custom smileys (maybe)
- #Sound
- #PM window
- #window that accesses all your actualy chatango settings
- cons = []
- HOST = '72.172.232.90'
- PORT = 443
- COLOR = '6A0'
- SIZE = '10'
- NAMECOLOR = '8F0'
- FONT = "0"
- fonts = ("Arial", "Comic", "Georgia", "Handwriting", "Impact", "Palatino", "Papyrus", "Times", "Typewriter")
- running = 1
- class IdleThread (threading.Thread):
- def run(self):
- while running:
- time.sleep(30)
- if running:
- for i in cons:
- i[0].send(chr(13) + chr(10) + chr(0))
- def con(room, USER, PASS):
- print "Connecting..."
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.connect((HOST, PORT))
- s.send("v" + chr(0))
- data = s.recv(1024)
- print "Connected!"
- print "Logging in..."
- s.send("bauth:"+room+":7202053138505182:"+USER+":"+PASS + chr(0))
- rid = random.random()
- cons.append((s,room,[], rid))
- print "You are now talking in " + room + "!"
- return (s, rid)
- class ConWin:
- def __init__(self, master, s):
- master.resizable(width=FALSE, height=FALSE)
- self.s = s[0]
- self.NAME = s[1]
- self.rid = s[2]
- self.master = master
- frame = Frame(master)
- frame.pack()
- self.e = Entry(frame)
- self.e.focus_set()
- self.e.pack(fill=X, side=BOTTOM, expand=1)
- scrollbar = Scrollbar(frame)
- scrollbar.pack(side=RIGHT, fill=Y, expand=1)
- self.t = Text(frame)
- self.t.config(font=('courier', 10, 'normal'), state=DISABLED)
- self.t.pack(fill=BOTH, expand=1)
- self.t.config(yscrollcommand=scrollbar.set)
- scrollbar.config(command=self.t.yview)
- def sendd(self, event):
- global NAMECOLOR, COLOR, SIZE, FONT, cons
- ddd = self.e.get()
- if ddd != "":
- if ddd[0] == "/":
- ddd = ddd[1:]
- ddds = ddd.split(" ")
- if len(ddds) == 1:
- print "Set to what?"
- else:
- if ddds[0] == "name":
- NAMECOLOR = ddds[1]
- if len(NAMECOLOR) < 3:
- NAMECOLOR = "0" + NAMECOLOR
- if len(NAMECOLOR) < 3:
- NAMECOLOR = "0" + NAMECOLOR
- if len(NAMECOLOR) < 3:
- NAMECOLOR = "0" + NAMECOLOR
- print "Name color set to " + NAMECOLOR
- elif ddds[0] == "color":
- COLOR = ddds[1]
- if len(COLOR) < 3:
- COLOR = "0" + COLOR
- if len(COLOR) < 3:
- COLOR = "0" + COLOR
- if len(COLOR) < 3:
- COLOR = "0" + COLOR
- print "Color set to " + COLOR
- elif ddds[0] == "size":
- SIZE = ddds[1]
- if len(SIZE) == 1:
- SIZE = "0" + SIZE
- print "Size set to " + SIZE
- elif ddds[0] == "font":
- FONT = ddds[1]
- if FONT == "":
- FONT = "0"
- print "Font set to " + FONT
- else:
- print "Unknown command!"
- else:
- ddd = ddd.replace("\"",""")
- ddd = ddd.replace("'","'")
- ddd = ddd.replace(">",">")
- ddd = ddd.replace("<","<")
- ddd = ddd.replace("[b]","<B>")
- ddd = ddd.replace("[u]","<U>")
- ddd = ddd.replace("[i]","<I>")
- ddd = ddd.replace("[/b]","</B>")
- ddd = ddd.replace("[/u]","</U>")
- ddd = ddd.replace("[/i]","</I>")
- ddd = ddd.replace("[B]","<B>")
- ddd = ddd.replace("[U]","<U>")
- ddd = ddd.replace("[I]","<I>")
- ddd = ddd.replace("[/B]","</B>")
- ddd = ddd.replace("[/U]","</U>")
- ddd = ddd.replace("[/I]","</I>")
- ppp = "bmsg:<n"+NAMECOLOR+"/><f x"+SIZE+COLOR+"=\""+FONT+"\">" + ddd + chr(13) + chr(10) + chr(0)
- self.s.send(ppp)
- self.e.delete(0, END)
- def startloop(self):
- while running:
- try:
- for i in cons:
- if i[3] == self.rid:
- buf = i[2]
- for a in buf:
- if a[0] == "b":
- self.t.config(state=NORMAL)
- aa = a.split(":")
- an = aa[2]
- am = ":".join(aa[9:len(aa)])
- am = am[0:len(am)-3]
- n = am.count("<n")
- nc = "#000"
- if n > 0:
- nc = "#" + am[2:5]
- am = am[7:len(am)]
- nametag = str(random.random())
- un = ""
- if an.lower() == self.NAME.lower():
- un = " underline"
- self.t.tag_config(nametag, foreground=nc, font=('courier', 12, 'bold' + un))
- self.t.tag_bind(nametag, "<Button-1>", self.clickname)
- self.t.insert(END, an, nametag)
- self.t.insert(END, ": ")
- styles = am.split("<f ")
- for st in styles:
- if st == '':
- continue
- pos = st.split(">")
- std = pos[0]
- st = ">".join(pos[1:len(pos)])
- std = std.split('="')
- d1 = std[0][1:len(std[0])]
- d2 = std[1][0:len(std[1])-1]
- siz = 10
- col = "#000"
- fon = "Arial"
- if len(d1) == 2:
- siz = int(d1)
- elif len(d1) == 3:
- col = "#" + d1
- elif len(d1) == 5:
- siz = int(d1[0:2])
- col = "#" + d1[2:5]
- elif len(d1) == 6:
- col = "#" + d1
- elif len(d1) == 8:
- siz = int(d1[0:2])
- col = "#" + d1[2:8]
- if d2 != '':
- try:
- d2 = int(d2)
- except ValueError:
- pass
- else:
- d2 = fonts[d2]
- fon = d2
- st = "".join(st.split("</f>"))
- if st.count("<") > 0:
- B = 0
- U = 0
- I = 0
- st2 = st.split("<")
- for st in st2:
- if st == '':
- continue
- op = "normal"
- if st[1] == ">":
- if st[0].lower() == "b":
- B = B + 1
- if st[0].lower() == "u":
- U = U + 1
- if st[0].lower() == "i":
- I = I + 1
- st = st[2:len(st)]
- elif st[0] == "/" and st[2] == ">":
- if st[1].lower() == "b":
- B = B - 1
- if st[1].lower() == "u":
- U = U - 1
- if st[1].lower() == "i":
- I = I - 1
- st = st[3:len(st)]
- if st == '':
- continue
- if B or U or I:
- B2 = B
- U2 = U
- I2 = I
- if B2 > 1: B2 = 1
- if U2 > 1: U2 = 1
- if I2 > 1: I2 = 1
- bt = (""," bold")[B2]
- ut = (""," underline")[U2]
- it = (""," italic")[I2]
- op = bt + ut + it
- mestag = str(random.random())
- self.t.tag_config(mestag, foreground=col, font=(fon, siz, op))
- st = st.replace(""","\"")
- st = st.replace("'","'")
- st = st.replace(">",">")
- st = st.replace("<","<")
- self.t.insert(END, st, mestag)
- else:
- mestag = str(random.random())
- self.t.tag_config(mestag, foreground=col, font=(fon, siz, 'normal'))
- st = st.replace(""","\"")
- st = st.replace("'","'")
- st = st.replace(">",">")
- st = st.replace("<","<")
- self.t.insert(END, st, mestag)
- self.t.insert(END, "\n", mestag)
- self.t.config(state=DISABLED)
- self.t.yview(END)
- del i[2][0:len(i[2])]
- break
- self.master.update()
- except TclError:
- break
- def clickname(self, event):
- self.e.insert(END, "@" + self.NAME)
- class ListenThread (threading.Thread):
- def run(self):
- while running and self.runnin:
- s = self.s
- data = s[0].recv(1024)
- if self.runnin and running:
- for i in cons:
- if i[3] == s[2]:
- i[2].append(data)
- def conwin(USER, PASS, ROOM):
- s = con(ROOM, USER, PASS)
- rid = s[1]
- s = s[0]
- root2 = Tk()
- root2.title("Chatango - " + ROOM + " - " + USER)
- thewin = ConWin(root2,(s,USER,rid))
- root2.bind("<Return>", thewin.sendd)
- l = ListenThread()
- l.s = (s,ROOM,rid)
- l.runnin = 1
- l.start()
- thewin.startloop()
- print "Disconnecting from " + ROOM + "..."
- s.send(chr(13) + chr(10) + chr(0))
- s.close()
- l.runnin = 0
- i = 0
- for a in cons:
- if a[1] == ROOM:
- del cons[i]
- break
- i = i + 1
- print "Disconnected from " + ROOM
- root = Tk()
- root.title("Login/Join")
- root.resizable(width=FALSE, height=FALSE)
- def makeentry(parent, caption, r, **options):
- Label(parent, text=caption).grid(row=r, sticky=E)
- entry = Entry(parent, **options)
- entry.config(width=20)
- entry.grid(row=r, column=1)
- return entry
- frame = Frame(root)
- frame.pack()
- user = makeentry(frame, "Username:", 0)
- password = makeentry(frame, "Password:", 1, show="*")
- room = makeentry(frame, "Room:", 2)
- user.focus_set()
- def login(event=None):
- USER = user.get()
- PASS = password.get()
- ROOM = room.get()
- conwin(USER, PASS, ROOM)
- Button(frame, text="Login/Join", command=login).grid(row=3, column=1, sticky=E)
- root.bind("<Return>", login)
- IdleThread().start()
- root.mainloop()
- print "Closing all connections..."
- running = 0
- for s in cons:
- s[0].close()
- print "Bye!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement