Exemple #1
0
def finalEvaluation(data, opponent):
    # print data;
    if(data['userdata']['victory'] != -1):
        if(data['userdata']['victory'] == True):
            MessageBeep(beep); time.sleep(0.1); MessageBeep(beep); time.sleep(0.1); MessageBeep(beep);
            conn1.params = {"u":u, "p":p, "python":1, "type":"upd", "SID":SID, 'data':'$Win:'+data['username']};
            conn1.request();
            xp = str(int(floor(data['userdata']['remainingTurns'] / 4)));
            data2 = xp+',0,1';
            Display.playerMsg('Good job,', data['username']+'!');
            Display.gameMsg("You've defeated", opponent, 'in', (data['userdata']['maxTurns'] - data['userdata']['remainingTurns']), 'turns.');
            Display.gameMsg("You've earned", xp, 'SP point(s)!');
            
        elif(data['userdata']['victory'] == False):
            MessageBeep(MB_OK); time.sleep(0.1); MessageBeep(MB_OK); time.sleep(0.1); MessageBeep(MB_OK);
            conn1.params = {"u":u, "p":p, "python":1, "type":"upd", "SID":SID, 'data':'$Win:'+opponent};
            conn1.request();
            data2 = '1,1,0';
            Display.errorMsg("You failed", data['username']+".");
            Display.errorMsg("You've lost to", opponent+".");
            Display.errorMsg("The correct answer was " + data['userdata']['answer'] + ".");
            Display.gameMsg("You've received 1 SP point.");

        conn1.params = {"u":u, "p":p, "python":1, "type":"psh", "SID":SID, 'data':data2};
        response = conn1.request();
        if(response != False):
            if(response[0:7] == 'Leveled'): Display.gameMsg('-+-+-+-+ Congratulations! You are now level '+response[8:]+' +-+-+-+-');
            elif(response == 'Updated'): Display.gameMsg('Server updated successfully.');
            else: Display.errorMsg('Server update failed! ('+str(response)+')');
        else: Display.errorMsg('Server update failed! (could not establish connection)');
        Display.errorMsg('Game Over.');
Exemple #2
0
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;
Exemple #3
0
                            Display.gameMsg("You've guessed correctly! (Total", (tries + 1), "turns)");
                            answer = -1;
                            break;
                        
                        else:
                            print Display.errorWrapper() + "Incorrect! Your guess was", distanceAlgorithm(ascii_uppercase, guess.upper(), answer, 4.0, 40);
                                
                    else:
                        Display.errorMsg("That's not a letter,", name+". You've lost two turns for that!");
                        maxTries = maxTries - 2;
                        
                    report = maxTries - (tries + 1);
                    Display.gameMsg("You have", (report if report > 0 else 'no'), "tries remaining.");
                    tries = tries + 1;
                    
                if(answer == -1): Display.playerMsg('Good job!');
                else:
                    Display.errorMsg("You failed", name+".");
                    Display.errorMsg("The correct answer was " + answer + ".");
                state = Display.cooked_input('> Try again? (y/n) ');
            
        # Play mode which would allow players to grab their stats from the server and play a local head2head match
        elif(i == 1): Display.gameMsg('Unfortunately, this gameplay mode is not available yet!');
        
        # We're in Online Play mode!
        elif(i == 2):
            # Tell the user that we're asking the server for a new encryption key
            Display.sysMsg("Handshaking with server..."); # Go pre-emptive handshake!

            # Ask for, obtain, and store the the encryption key
            switch = False;
Exemple #4
0
                    Display.errorMsg("Please try again.");
                    continue;

                # Finish packaging the data
                p = str(hashlib.sha1(hashlib.md5(p).hexdigest()).hexdigest());
                conn1.params["p"] = p;
                conn1.params["class"] = 4;
                conn1.params["type"] = "reg";

                # Send the data off for processing
                response = conn1.request();

                # Alert the user of the result, and display the proper options accordingly
                if response != False:
                    if response == "Approved":
                        Display.playerMsg("The username", u, "has been registered successfully!");
                        
                    elif response == "Malformed":
                        Display.errorMsg("Error: The selected username is illegal.");
                        Display.errorMsg("Note that usernames should only contain letters & numbers.");
                        Display.errorMsg("Feel free to contact DG should you require assistance.");
                        
                    elif response == "Denied":
                        Display.errorMsg("The username", u, "is not available for use.");
                        Display.errorMsg("Please select a different one.");
                        
                    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);
                        # Based on the distance from the answer, print a different result (to the same line)
                        if fdist <= length * modifiers[0] / 100:
                            print "slightly off."
                        elif dist > 0:
                            if fdist <= length * modifiers[1] / 100:
                                print "too low."
                            else:
                                print "WAY too low!"
                        else:
                            if fdist <= length * modifiers[1] / 100:
                                print "too high."
                            else:
                                print "WAY too high!"
                else:
                    Display.errorMsg("That's not a letter,", name + ". You've lost two turns for that!")
                    maxTries = maxTries - 2
                report = maxTries - (tries + 1)
                Display.gameMsg("You have", (report if report > 0 else "no"), "tries remaining.")
                tries = tries + 1
            if answer == -1:
                Display.playerMsg("Good job!")
            else:
                Display.errorMsg("You failed", name + ".\nThe correct answer was " + answer + ".")
            state = Display.cooked_input("Try again? (y/n) ")
    Display.evnMsg("(C) Copyright 2010 - Dark Gray. All Rights Reserved.")
except KeyboardInterrupt:
    pass
Display.errorMsg("Program Terminated.")
Display.pause()