def login(): global loggedIn, SID; if(loggedIn): return 2; # We're attempting to log someone in u = Display.cooked_input("> Username: "******"> Password:"******"\n Conversing with server..."); if(u not in ['Xunnamius']): Display.sysMsg("Invalid username/permissions."); return False; # Package the new data conn1.params = {"u":u, "python":1, "type":"", "SID":SID}; # 1. Split the key in half # 2. Place chunks at both the front and the end (double salt) # 3. SHA-1 the whole thing again eKeyPiece1 = KEY[0:20]; eKeyPiece2 = KEY[20:40]; p = str(hashlib.sha1(eKeyPiece1 + hashlib.sha1(hashlib.md5(p).hexdigest()).hexdigest() + eKeyPiece2).hexdigest()); u = str(hashlib.sha1(eKeyPiece1 + u + eKeyPiece2).hexdigest()); conn1.params["u"] = u; conn1.params["p"] = p; conn1.params["type"] = "lin"; # Authenticate the user's information response = conn1.request(); # Alert the user of the result, and display the proper options accordingly if response != False: if response == "Approved": Display.playerMsg("Login Successful."); Display.sysMsg('Loading...'); loggedIn = True; return loggedIn; elif response == "Denied": Display.errorMsg("Invalid username/password combination."); Display.errorMsg("Remember your username/password is case sensitive!"); elif response == "Malformed": Display.errorMsg("You have illegal characters in your username/password."); Display.errorMsg("(Usernames are only allowed letters and numbers!)"); Display.errorMsg("Contact Dark Gray for assistance or create a new account."); else: if(not response): Display.errorMsg("Connection to server was dropped. Please try again."); else: Display.errorMsg("Error. The response received from server was unrecognizable."); Display.errorMsg(">>", response); else: Display.errorMsg("Connection to server was dropped. Please try again."); return False;
import sys, threading, os, time; from DisplayInterface import Display; class Autodeath(threading.Thread): """ Die after x seconds """ def __init__(self): # Clear the timer self.countdown = time.clock(); threading.Thread.__init__(self, None, None, "Autodeath Thread"); self.daemon = True; self.start(); def run(self): self.countdown = time.clock(); while(self.countdown + 30 > time.clock()): time.sleep(1); os._exit(1); challenger = sys.argv[1]; if(challenger and 0 < len(challenger) <= 25): death = Autodeath(); Display.sysMsg(('----- MAR Battle Request Warning! -----').center(53)); Display.sysMsg(time.strftime("%m/%d/%Y @ [%I:%M:%S]").center(51),"\n\n\n"); Display.evnMsg("You have a pending battle request from " +challenger+"!"); Display.evnMsg("Type 'Challenge' and then '"+challenger+"'"); Display.evnMsg("in the main window to accept or do nothing to decline.\n"); Display.sysMsg('This window will automatically close in 30 seconds.'); Display.cooked_input(' Press "Enter" to immediately close this window.', True);
Display.sysMsg('Room cleaned successfully.'); Display.gameMsg('Returning to main menu...'); heartbeat.pauseFlag = False; conn1.makeNulls = False; # Begin the main python code try: while(True): # Staying away from my complex menu object, since explaining it in a write up would be... well, complex. i = Display.menu(OrderedDict([('free play', 0), ('local play', 1), ('online play', 2), ('exit', 3)]), initMsg='Select Your Gameplay Mode:', prefix='# '); # Free play mode, which is basically the game as it was originally intended if(i == 0): gameNum = 0; state = 'y'; name = Display.cooked_input("> What's your name? "); # Python doesn't even have a do-while?! Wow. Really? ... Really? What a waste of code. while not re.match('^[0-9a-zA-Z_]{4}[0-9a-zA-Z_]*$', name) and 4 <= name <= 25: # ^[0-9a-zA-Z_]{4,25}$ wasn't working for some odd reason >.< Display.errorMsg('Invalid name! Numbers/Letters only (between 4 and 25 chars).'); name = Display.cooked_input("> What's your name? "); Display.gameMsg('Welcome to the Letter Guessing Game,', name+'!'); while state == 'y': # Finish setting up our environment tries = 0; maxTries = 7; # ascii_uppercase = ascii_uppercase[::-1]; answer = ascii_uppercase[randint(0, 25)]; gameNum = gameNum + 1;
Display.sysMsg("Handshaking with server..."); # Go pre-emptive handshake! # Ask for, obtain, and store the the encryption key response = conn1.requestKey(); if(response != False): KEY = response[0]; SID = response[2]; else: Display.errorMsg('Connection was rejected (maybe to too many people playing for too long?)'); Display.errorMsg('Please try again later.'); MAR_exit(1); while(True): zzz=lambda(zz):z==zz; while(not zzz(zz)): z = Display.cooked_input('> 暗証? '); if(not loggedIn): while(not login()): login(); i = Display.menu(OrderedDict([('create', 0), ('moderate', 1), ('delete', 2), ('exit', 3)]), initMsg='Select Mode:', prefix='# '); # Creation mode, which allows for the creation of God accounts if(i == 0): response = None; while(response != "Approved"): # Ask the user for his/her information Display.gameMsg('Type "Back" at any time to go back to the previous menu.'); Display.gameMsg('(This means "Back" cannot be your username/password!)'); u = Display.cooked_input("> Desired Username: "******"> Desired Password:"); # The user wants to go back instead of registering
i = 1 state = "y" # No color support in this version, so the Display.*Msg distinctions are only code-deep Display.sysMsg("Bernard Dickens - Letter Guessing Game (Project II) - ", __author__) while i == 1: i = Display.menu( OrderedDict([("free play", False), ("load profile", 1), ("online play", True), ("exit", 2)]), initMsg="Please Select Your Gameplay Mode:", prefix="# ", ) if i == 1: Display.gameMsg("This gameplay mode is not available yet.") if i != 2: name = Display.cooked_input("What's your name? ") while ( not re.match("^[0-9a-zA-Z_]{4}[0-9a-zA-Z_]*$", name) and 4 <= name <= 25 ): # ^[0-9a-zA-Z_]{4,25}$ wasn't working for some odd reason >.< Display.errorMsg("Invalid name! Numbers/Letters only (between 4 and 25 chars).") name = Display.cooked_input("What's your name? ") Display.gameMsg("Welcome to the Letter Guessing Game,", name + "!") while state == "y": tries = 0 maxTries = 7 answer = ascii_uppercase[randint(0, 25)] gameNum = gameNum + 1 Display.gameMsg("For you, this is game #" + str(gameNum) + ".") while tries < maxTries: