Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jalbarracinv authored Dec 26, 2021
1 parent ffef0b6 commit b56d6cf
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 65 deletions.
114 changes: 53 additions & 61 deletions bbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,56 +35,50 @@
def do_welcome(connection):

#CLEAR SCREEN
connection.send(cbmcursor("clear"))
connection.send(cbmcursor("home"))
send_cr(connection, "clear") #sends a coded cursor
send_cr(connection, "home") #sends a coded cursor

#SEND HEADER FILE (.SEQ)
# print ("STATUS > will send seq")
connection.send(cbmencode("\n\n"))
send_file(connection, "welcome.seq")
send_ln(connection, "\n\n") #sends text
send_seq(connection, "welcome.seq") #sends a seq file to screen

#THIS SECTION SENDS RANDOM THINGS (FOR YOU TO LEARN HOW)
connection.send(cbmcursor("red")) #cbmcursor sends color red code
connection.send(cbmencode("\n\nWelcome")) #cbmencode sends message
connection.send(cbmcursor("blue"))
connection.send(cbmencode(" a "))
connection.send(cbmcursor("purple"))
connection.send(cbmencode("CBMBBS\n\n"))
connection.send(cbmcursor("grey"))
send_cr(connection, "red") #cbmcursor sends color red code
send_ln(connection, "\n\nWelcome") # sends message
send_cr(connection, "blue") #cbmcursor sends color blue code
send_ln(connection, " to ") # sends message
send_cr(connection, "purple") #cbmcursor sends color purple code
send_ln(connection, "CBMBBS\n\n") # sends message
send_cr(connection, "gray") #cbmcursor sends color gray code
welcome2="This is a text is a text" #You can also declare a string
connection.send(cbmencode(welcome2)) #and send it after cbmencode it
send_ln(connection, welcome2) #and send it after cbmencode it
cursorxy(connection,1,1) #cursorxy positions cursor on x,y on screen
connection.send(cbmencode("i am at 1,1"))
send_ln(connection, "up1")
cursorxy(connection,1,25)
connection.send(cbmencode("i am at 1,25"))
time.sleep(8)
send_ln(connection, "down25")

def do_login(connection):

#CLEAR SCREEN
connection.send(cbmcursor("clear"))
connection.send(cbmcursor("home"))
send_cr(connection,"clear")
send_cr(connection,"home")
cursorxy(connection,1,3) #positions cursor on third line
imf=0 #sets a flag for an infinite loop in while
maxtries=3 #max tries
attempts=0

while True:
#Login (not finished)
connection.send(cbmencode("Username (new): "))
namex=input_line(connection) #input_line function reads a line
print("decoded name: ",cbmdecode(namex)) # this is displayed on system side
uname=cbmdecode(namex) #receives the name of the user
send_ln(connection,"Username (or 'new'): ")
uname=input_line(connection) #input_line function reads a line

if (uname=="new"):
uname,realid = do_newuser(connection)
print("new user created")
break

connection.send(cbmencode("Password: "))
pword=input_pass(connection) #input_pass reads a line but shows '*'
print("decoded pass: ",cbmdecode(pword)) # this is displayed on system side
upass=cbmdecode(pword) #receives the password of the user
upass=input_pass(connection) #input_pass reads a line but shows '*'

# Define QUERY
query="SELECT id,username,password FROM accounts WHERE username='%s'"
Expand All @@ -95,7 +89,7 @@ def do_login(connection):
myresult = mycursor.fetchone()

if (myresult == None):
connection.send(cbmencode("\n\nIncorrect username or password.\n\n"))
send_ln(connection, "\n\nIncorrect username or password.\n\n")
attempts=attempts+1
else:
realpass = myresult['password']
Expand All @@ -106,7 +100,7 @@ def do_login(connection):
print("match!!")
break
else:
connection.send(cbmencode("\n\nIncorrect username or password.\n\n"))
send_ln(connection, "\n\nIncorrect username or password.\n\n")
attempts=attempts+1
if (attempts>=maxtries):
connection.send(cbmencode("\n\nSorry maximum number of attempts reached..\n\n"))
Expand All @@ -117,19 +111,18 @@ def do_login(connection):

def do_newuser(connection):
#CLEAR SCREEN
connection.send(cbmcursor("clear"))
connection.send(cbmcursor("home"))
send_cr(connection, "clear")
send_cr(connection, "home")
cursorxy(connection,1,3) #positions cursor on third line
connection.send(cbmencode("Welcome new user!\nLet's create a new username.\n\n"))
send_ln(connection, "Welcome new user!\nLet's create a new username.\n\n")

#DEFINE Variables to control loop
maxtries=3 #max tries
maxtries=5 #max tries
attempts=0

while True:
connection.send(cbmencode("Type your username: "))
namex=input_line(connection) #input_line function reads a line
uname=cbmdecode(namex)
send_ln(connection, "Type your username: ")
uname=input_line(connection) #input_line function reads a line

# Define QUERY
query="SELECT id,username,password FROM accounts WHERE username='%s'"
Expand All @@ -139,60 +132,57 @@ def do_newuser(connection):
mycursor.execute(query)
myresult = mycursor.fetchone()

if(myresult == None):
connection.send(cbmencode("Your username is: "+uname+"\nAre you sure? (y/n): "))
letter=cbmdecode(get_char(connection))
#IF user does not exists
if(myresult == None and uname!="" and uname !="new"):
send_ln(connection, "Your username is: "+uname+"\nAre you sure? (y/n): ")
letter=get_char(connection)
print("letra: ",letter)
connection.send(cbmencode("\n\n"))
send_ln(connection, "\n\n")
attempts=attempts+1
if(letter=="y" or letter=="Y"):
print("YES!")
break
else:
connection.send(cbmencode("\nError: User already exists.\n"))
send_ln(connection, "\nError: User already exists.\n")
attempts=attempts+1

if attempts >=maxtries:
connection.send(cbmencode("Sorry, maximum number of attempts.\nConnection closed. "))
send_ln(connection, "Sorry, maximum number of attempts.\nConnection closed.")
connection.close()

attempts=0

#Asks for password
while True:
connection.send(cbmencode("\nType your password: "))
send_ln(connection,"\nType your password: ")
pass1=input_pass(connection) #input_line function reads a line
pass1=cbmdecode(pass1)
connection.send(cbmencode("\nRepeat your password: "))
send_ln(connection, "\nRepeat your password: ")
pass2=input_pass(connection) #input_line function reads a line
pass2=cbmdecode(pass2)
if(pass2==pass1):
if(pass1!="" and pass2==pass1):
print("->"+pass1+"<-")
break
attempts=attempts+1
if attempts >= maxtries:
connection.send(cbmencode("Sorry, maximum number of attempts.\nConnection closed. "))
send_ln(connection, "Sorry, maximum number of attempts.\nConnection closed. ")
connection.close()
connection.send(cbmencode("\nError: Passwords don't match.\nTry Again.\n\n"))
send_ln(connection, "\nError: Passwords don't match.\nTry Again.\n\n")

attempts=0

#Asks for email
while True:
connection.send(cbmencode("\nType your email: "))
send_ln(connection, "\nType your email: ")
mail1=input_line(connection) #input_line function reads a line
mail1=cbmdecode(mail1)
connection.send(cbmencode("\nRepeat your email: "))
send_ln(connection, "\nRepeat your email: ")
mail2=input_line(connection) #input_line function reads a line
mail2=cbmdecode(mail2)
if(mail2==mail1):
if(mail1!="" and mail2==mail1):
print("email matches!")
break
attempts=attempts+1
if attempts >= maxtries:
connection.send(cbmencode("Sorry, maximum number of attempts.\nConnection closed. "))
send_ln(connection, "Sorry, maximum number of attempts.\nConnection closed. ")
connection.close()
connection.send(cbmencode("\nError: Emails don't match.\nTry Again.\n\n"))
send_ln(connection,"\nError: Emails don't match.\nTry Again.\n\n")

print("Creating account:",uname)
## Creates user here
Expand All @@ -207,13 +197,11 @@ def do_newuser(connection):
def do_bucle(connection,namex,idx):

while True:
#Borra Pantalla y ENVIA MENU
print("Hola, ",namex,"->",idx)
connection.send(cbmencode("\n\nSelecciona Opcion: "))
#Clears Screen and sends MENU
print("USER -> ",namex,"->",idx)
send_ln(connection, "\n\nChoose an option: ")
bucl=get_char(connection)
print(bucl)
print("decoded: ",cbmdecode(bucl))


###########################################
# MAIN BBS FUNCTIONS
Expand All @@ -223,10 +211,14 @@ def user_session(connection):

while True:

#initializes terminal
#initializes terminal
send_cr(connection,"clear")
send_cr(connection,"home")
send_ln(connection, "Connected. Hit any key...")
bucl=get_char(connection)

do_welcome(connection)
time.sleep(2)
time.sleep(6)

userx,idx = do_login(connection)

Expand Down
21 changes: 17 additions & 4 deletions funct.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'\x12':b'\x12','\x92':b'\x92','\x81':b'\x81','\x90':b'\x90','\x95':b'\x95','\x96':b'\x96',
'\x97':b'\x97','\x98':b'\x98','\x99':b'\x99','\x9a':b'\x9a','\x9b':b'\x9b','\x9e':b'\x9e',
'\x9f':b'\x9f','\x13':b'\x13',
"'":b"\x27"}
"'":b"\x27","=":b"\x3d","[":b"[","]":b"]",";":b";","↑":b"\x5e","←":b"\x5f"}

#This function moves the cursor and changes color, clear screen
def cbmcursor(tx):
Expand All @@ -33,6 +33,8 @@ def cbmcursor(tx):
if tx=="brown": out =b'\x95'
if tx=="pink": out =b'\x96'
if tx=="dark grey": out=b'\x97'
if tx=="dark gray": out=b'\x97'
if tx=="gray": out=b'\x98'
if tx=="grey": out=b'\x98'
if tx=="lightgreen": out=b'\x99'
if tx=="lightblue": out=b'\x9a'
Expand All @@ -42,7 +44,7 @@ def cbmcursor(tx):
if tx=="cyan": out=b'\x9f'
if tx=="revon": out=b'\x12'
if tx=="revoff": out=b'\x92'
if tx=="rand":
if tx=="randc":
m=random.randint(0, 15)
if m==0: out =b'\x1f'
if m==1: out =b'\x81'
Expand Down Expand Up @@ -143,6 +145,7 @@ def input_line(connection):
tline=tline
else:
tline=tline+data
tline=cbmdecode(tline)
return tline

#reads a password (and when typing it shows '*' to the user)
Expand Down Expand Up @@ -176,22 +179,24 @@ def input_pass(connection):
tline=tline
else:
tline=tline+data
tline=cbmdecode(tline)
return tline

#similar to commodore basic get command (it just wait to type one char)
def get_char(connection):
while True:
data = connection.recv(256, 0x40) #funciona como un input
data = connection.recv(256, 0x40) #works like a get
if not data:
print("no data - closed connection")
connection.close()
break
rchar=data[0:1]
connection.send(rchar)
rchar=cbmdecode(rchar)
return(rchar)

#this is to send the SEQ file to the user (useful for petscii graphics portions)
def send_file(connection, filen):
def send_seq(connection, filen):
print (filen)
with open(filen, "rb") as f:
nb=b''
Expand All @@ -200,3 +205,11 @@ def send_file(connection, filen):
nb = byte
connection.send(nb)
byte = f.read(1)

def send_ln(connection, line):
linet=cbmencode(line)
connection.send(linet)

def send_cr(connection, charx):
chrxx=cbmcursor(charx)
connection.send(chrxx)

0 comments on commit b56d6cf

Please sign in to comment.