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;
def block_on_challenge(ignore_response, params, at_end=1, stall_time=60, debug=False, eval_response=True): global conn1, heartbeat; if(not conn1 or not heartbeat): MAR_exit(2); xtime = 0; # Give them 60 seconds while(xtime < stall_time): if(xtime == (stall_time-30)): Display.sysMsg('30 seconds remaining...'); elif(xtime == (stall_time-10)): Display.sysMsg('10 seconds remaining...'); sleeptime = time.clock(); if(xtime % 5 == 0): # Setup our internal environment conn1.params = params; conn1.makeNulls = True; response = conn1.request(); # print 'tempresp -> ', response if(response and response != ignore_response): if(eval_response): response = json_decode(response, debug); conn1.makeNulls = False; return response; sleeptime = 1 - (time.clock() - sleeptime); if(sleeptime > 0): time.sleep(sleeptime); xtime = xtime + 1; # We timed-out! else: if(at_end == 1): Display.evnMsg('Request TIMED OUT. Destroying room...'); conn1.params = {"u":u, "p":p, "python":1, "type":"kil", "SID":SID}; response = conn1.request(); Display.sysMsg('Room Destroyed!'); heartbeat.pauseFlag = False; conn1.makeNulls = False; 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);
def status(self): self._stopSpin(); if self._silent == False: Display.sysMsg("NetworkInterface module mounted successfully");
def MAR_battle(opponent, first): print ''; global conn1, heartbeat, loggedIn, userdict, userpowers, ascii_uppercase; if(not conn1 or not loggedIn or not heartbeat or not userdict or not userpowers or not ascii_uppercase): MAR_exit(3); # Letters need re-reversing for some reason. Bad python scoping system is bad and horrible. # ascii_uppercase = ascii_uppercase[::-1]; # Finish setting up our environment actionQueue = {'username':userdict['username'], 'specialdata':{}, 'userdata':{ 'guess':None, 'miniTurns':0, 'remainingTurns':27, 'maxTurns':28, 'letterNum':1, 'answer':None, 'answerStatus1':None, 'answerStatus2':None, 'skipped': False, 'victory': False }}; # Structure the user's powers into a workable menu object powerStructure = [('guess', -1), ('skip', -2)]; for power in userpowers.keys(): powerStructure.insert(0, (str(power).lower(), str(power))); powerStructure = OrderedDict(powerStructure); # Begin the game while(actionQueue['userdata']['remainingTurns'] > 0 and not actionQueue['userdata']['victory']): if(actionQueue['userdata']['letterNum'] <= 4 and not actionQueue['userdata']['victory']): # We're up! if(first): if(not actionQueue['userdata']['skipped']): # Set up our environment if(actionQueue['userdata']['answer'] == None): actionQueue['userdata']['answer'] = ascii_uppercase[randint(0, 25)]; Display.gameMsg('--> For you, this is letter '+str(actionQueue['userdata']['letterNum'])+' of 4.'); Display.gameMsg('[To use your specials, type the special\'s name and press "enter."]'); Display.gameMsg('[To guess, type "guess" followed by your letter guess.]'); Display.gameMsg('[To skip your turn, type "skip."]'); Display.gameMsg('[You have 60 seconds until your turn is automatically skipped]'); # Prompt for selection of powers or guess (60 second time limit) sleeptime = time.clock(); i = Display.menu(powerStructure, initMsg='Your move:', prefix='- ', time_limit=60, limit_phrase='skip'); # User wants to guess normally if(i == -1): if(actionQueue['userdata']['guess'] != None and actionQueue['userdata']['answerStatus2'] != ''): Display.gameMsg('-> You previous guess was:', actionQueue['userdata']['guess'], '('+actionQueue['userdata']['answerStatus2'][:-1].lower()+')'); actionQueue['userdata']['guess'] = Display.timed_input('> Guess a letter, '+actionQueue['username']+': ', 'skip', 60 - (time.clock() - sleeptime)); if(actionQueue['userdata']['guess'] == 'skip'): actionQueue['userdata']['skipped'] = True; elif(actionQueue['userdata']['guess'] in ascii_letters): if(actionQueue['userdata']['guess'].upper() == actionQueue['userdata']['answer']): actionQueue['userdata']['miniTurns'] = actionQueue['userdata']['miniTurns'] + 1; Display.gameMsg("You've guessed correctly! (Total", actionQueue['userdata']['miniTurns'], "turns)"); actionQueue['userdata']['letterNum'] = actionQueue['userdata']['letterNum'] + 1; if(actionQueue['userdata']['letterNum'] <= 4 and not actionQueue['userdata']['victory']): MessageBeep(beep); time.sleep(0.1); MessageBeep(beep); actionQueue['userdata']['answerStatus1'] = actionQueue['username']+" guessed correctly and is onto the next letter! (Letter "+str(actionQueue['userdata']['letterNum'])+" of 4)"; actionQueue['userdata']['answerStatus2'] = ''; actionQueue['userdata']['miniTurns'] = 0; actionQueue['userdata']['answer'] = None; else: actionQueue['userdata']['victory'] = True; finalEvaluation(actionQueue, opponent); break; else: dist = distanceAlgorithm(ascii_uppercase, actionQueue['userdata']['guess'].upper(), actionQueue['userdata']['answer'], 4.0, 40); actionQueue['userdata']['answerStatus1'] = actionQueue['username']+' guessed incorrectly!'; actionQueue['userdata']['answerStatus2'] = "Guess was "+dist; print Display.errorWrapper() + "Incorrect! Your guess was", dist; else: Display.errorMsg("That's not a letter,", actionQueue['username']+". You've lost two turns for that!"); actionQueue['userdata']['answerStatus1'] = actionQueue['username']+' entered an invalid response and was penalized!\n What a fool!'; actionQueue['userdata']['answerStatus2'] = 'Guess was invalid.'; actionQueue['userdata']['remainingTurns'] = actionQueue['userdata']['remainingTurns'] - 2; actionQueue['userdata']['miniTurns'] = actionQueue['userdata']['miniTurns'] + 1; # User wants to skip their turn elif(i == -2): actionQueue['userdata']['skipped'] = True; actionQueue['userdata']['guess'] = actionQueue['userdata']['answerStatus1'] = None; actionQueue['userdata']['answerStatus2'] = ''; actionQueue['userdata']['miniTurns'] = actionQueue['userdata']['miniTurns'] + 1; # A power was chosen, attempt to add it to the specialdata array else: Display.errorMsg('Specials don\'t work yet. Sorry!'); actionQueue['userdata']['skipped'] = True; actionQueue['userdata']['guess'] = actionQueue['userdata']['answerStatus1'] = None; actionQueue['userdata']['answerStatus2'] = ''; actionQueue['userdata']['miniTurns'] = actionQueue['userdata']['miniTurns'] + 1; # actionQueue['specialdata'] = activatePower(userpowers[i], actionQueue['specialdata']); # Evaluate specialdata array & victory conditions actionQueue = evaluateQueue(actionQueue); Display.gameMsg('Turn ended!'); Display.gameMsg("You have", (actionQueue['userdata']['remainingTurns'] if actionQueue['userdata']['remainingTurns'] > 0 else 'no'), "turns remaining."); Display.gameMsg("Synchronizing with server..."); conn1.params = {"u":u, "p":p, "python":1, "type":"upd", "SID":SID, 'data':actionQueue}; response = conn1.request(); # print 'resp:', response if(response == '$UpdateFailed'): Display.errorMsg('Internal Error: server failed to update properly! Report this!'); if(response == '$LookupError'): Display.errorMsg('Internal Error: server-user lookup error! Report this!'); else: actionQueue, doBreak = checkForCommands(response, actionQueue, opponent); if(doBreak): break; actionQueue['userdata']['remainingTurns'] = actionQueue['userdata']['remainingTurns'] - 1; actionQueue['userdata']['miniTurns'] = actionQueue['userdata']['miniTurns'] + 1; actionQueue['userdata']['skipped'] = False; # They're up! (wait for 60[+10] seconds) else: Display.gameMsg('Waiting on', opponent+' (~60 seconds until timeout)...'); response = block_on_challenge('$NoData', {"u":u, "p":p, "python":1, "type":"bat4", "SID":SID, 'opponent':opponent}, at_end=0, stall_time=70); if(is_JSON(response)): if(response['userdata']['victory'] or response['userdata']['letterNum'] > 4): print 'incorrect loss action:', response actionQueue['userdata']['victory'] = False; finalEvaluation(actionQueue, opponent); break; else: if(response['userdata']['answerStatus1']): if(response['userdata']['answerStatus1'].find('guessed correctly and is onto')+1): MessageBeep(MB_OK); time.sleep(0.1); MessageBeep(MB_OK); Display.gameMsg('->', response['userdata']['answerStatus1']); else: Display.gameMsg('->', opponent, 'skipped his turn?! Foolish!'); evaluateQueue(response, False); Display.sysMsg('Opponent\'s turn ended. Your move!'); elif(response == False): # Send the "is alive ne?" packet Display.gameMsg('No response from opponent, clearing victory conditions...'); conn1.params = {"u":u, "p":p, "python":1, "type":"upd", "SID":SID, 'data':'$Alive:'+opponent}; conn1.request(); response = block_on_challenge('$NoData', {"u":u, "p":p, "python":1, "type":"bat4", "SID":SID, 'opponent':opponent, "ignore":'$Alive:'+opponent}, at_end=0, stall_time=10, eval_response=False); if(response == '$Yes'): Display.gameMsg('Opponent\'s turn was skipped.'); conn1.params = {"u":u, "p":p, "python":1, "type":"upd", "SID":SID, 'data':'$Skip:'+actionQueue['username']}; conn1.request(); time.sleep(3); elif(response == False or response[0] == '{'): Display.gameMsg('Opponent has disconnected from the server. You win by default.'); actionQueue['userdata']['victory'] = True; finalEvaluation(actionQueue, opponent); break; else: actionQueue, doBreak = checkForCommands(response, actionQueue, opponent); if(doBreak): break; else: actionQueue, doBreak = checkForCommands(response, actionQueue, opponent); if(doBreak): break; #Change up the order first = not first; else: actionQueue['userdata']['victory'] = True; finalEvaluation(actionQueue, opponent); break; else: if(not actionQueue['userdata']['victory']): finalEvaluation(actionQueue, opponent); Display.sysMsg('Cleaning up room...'); conn1.params = {"u":u, "p":p, "python":1, "type":"kil", "SID":SID}; conn1.request(); Display.sysMsg('Room cleaned successfully.'); Display.gameMsg('Returning to main menu...'); heartbeat.pauseFlag = False; conn1.makeNulls = False;
from DisplayInterface import Display; from Challenger import Challenger; from winsound import MessageBeep, MB_OK, MB_ICONASTERISK as beep; # Establish our connection object conn1 = NetworkInterface(); conn1.baseSite = "dignityice.com"; conn1.target = "/dg/Xunnamius/house2/pyGameInterface.php"; # Set up our environment loggedIn = False; time.clock(); # Clear the timer # Sound-off! # No color support in this version for now, so the Display.*Msg distinctions are only code-deep Display.sysMsg('DO NOT RUN THIS PROGRAM IN THE PYTHON INTERACTIVE CONSOLE (IDLE)! DO NOT!\n\n'); Display.sysMsg('Mini-MAR BETA version', __version__); conn1.status(); Display.sysMsg('Bernard Dickens - Project II -', __author__); # Exit MAR def MAR_exit(status=0): if(status == 0): Display.gameMsg('Program Terminated.'); else: Display.errorMsg('Program Terminated Unexpectedly ('+str(status)+')!'); Display.evnMsg('(C) Copyright 2010 - Dark Gray. All Rights Reserved.'); Display.pause(); os._exit(status); # Is this JSON-like data? def is_JSON(data): data = str(data).strip();
from collections import OrderedDict; from NetworkInterface import NetworkInterface; from DisplayInterface import Display; # Establish our connection object conn1 = NetworkInterface(); conn1.baseSite = "dignityice.com"; conn1.target = "/dg/Xunnamius/house2/pyGameInterface.php"; # Set up our environment usedSpecials = []; loggedIn = False; time.clock(); # Clear the timer # Sound-off! Display.sysMsg('Mini-MAR BETA\'s GOD CHARACTER MAKER v', __version__); conn1.status(); # Login to the server 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']):
from httplib import BadStatusLine from collections import OrderedDict from NetworkInterface import NetworkInterface from DisplayInterface import Display conn1 = NetworkInterface() conn1.status() ascii_uppercase = ascii_uppercase[::-1] try: gameNum = 0 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 >.<