<?php
namespace entities\evr\security;

class Registrar
{
   public function register()
   {
      $this->set_username();
      $this->set_password();
      $this->set_email_address();
      $this->set_join_flag();
      if ($this->username && $this->password && $this->email)
      {
         if (Security::validate_key())
         {
            $this->add_user();
            Security::remove_key();
            Security::show_success($this->username . " registered");
            return true;
         }
      }
      return false;
   }
   private function set_username()
   {
      $name = Security::get_post_parameter("username");
      if (!$this->check_username_length($name))
      {
         Security::show_error("Please change username length");
         $name = null;
      }
      if (!$this->check_username_content($name))
      {
         Security::show_error("Please use only a-z, A-Z, 0-9, or _");
         $name = null;
      }
      if (Security::find_user_directory($name))
      {
         Security::show_error("Username $name is already taken");
         $name = null;
      }
      $this->username = $name;
   }
   private function check_username_length($name)
   {
      $min = $GLOBALS["USER_NAME_MIN_LENGTH"];
      $max = $GLOBALS["USER_NAME_MAX_LENGTH"];
      return $this->check_length($name, $min, $max);
   }
   private function check_length($string, $min, $max)
   {
      $length = strlen($string);
      return $length >= $min && $length <= $max;
   }
   private function check_username_content($name)
   {
      return preg_match("/^[a-zA-Z0-9_]*$/", $name);
   }
   private function set_password()
   {
      $passwords = Security::get_post_parameter("password");
      $password = $passwords[0];
      if ($passwords[0] != $passwords[1])
      {
         Security::show_error("Two different passwords submitted");
         $password = null;
      }
      if (!$this->check_password_length($passwords[0]))
      {
         Security::show_error("Please change password length");
         $password = null;
      }
      if (!$this->check_password_characters($passwords[0]))
      {
         Security::show_error("Please mix letters and numbers in the password");
         $password = null;
      }
      $this->password = $password;
   }
   private function check_password_length($password)
   {
      $min = $GLOBALS["PASSWORD_MIN_LENGTH"];
      $max = $GLOBALS["PASSWORD_MAX_LENGTH"];
      return $this->check_length($password, $min, $max);
   }
   private function check_password_characters($password)
   {
      $chars = "/[a-zA-Z]/";
      $numerals = "/[0-9]/";
      return preg_match($chars, $password) && preg_match($numerals, $password);
   }
   private function set_email_address()
   {
      $email = Security::get_post_parameter("email_address");
      if (!preg_match("/.+@.+\..+/", $email))
      {
         Security::show_error("Please use a different e-mail address format");
         $email = null;
      }
      $this->email = $email;
   }
   private function set_join_flag()
   {
      if (Security::get_post_parameter("join"))
      {
         $this->join = "1";
      }
      else
      {
         $this->join = "0";
      }
   }
   private function add_user()
   {
      $this->create_user_directory();
      $this->store_password();
      $this->store_email_address();
      $this->create_addresses_file();
      $this->create_history_file();
      $this->create_expert_file();
      $this->initialize_progress_file();
   }
   private function create_user_directory()
   {
      $saved = umask(0);
      mkdir($this->get_user_path(), 0770);
      umask($saved);
   }
   private function store_password()
   {
      $hash = $this->hash_password();
      $path = $this->create_file($GLOBALS["USER_HASH_PATH"]);
      file_put_contents($path, $hash . "\n");
   }
   private function create_file($name)
   {
      $path = $this->get_user_path() . $name;
      touch($path);
      chmod($path, octdec($GLOBALS["USER_FILE_PERMISSIONS"]));
      return $path;
   }
   private function get_user_path()
   {
      return $GLOBALS["USERS_PATH"] . "/" . $this->username . "/";
   }
   private function hash_password()
   {
      $salt = $this->generate_salt();
      return crypt($this->password, $salt);
   }
   private function generate_salt()
   {
      return chr(rand(65, 90)) . rand(0, 9);
   }
   private function store_email_address()
   {
      $content = $this->email . " " . $this->join . "\n";
      $path = $this->create_file($GLOBALS["USER_EMAIL_ADDRESS_PATH"]);
      file_put_contents($path, $content);
   }
   private function create_addresses_file()
   {
      $this->create_file($GLOBALS["USER_ADDRESSES_PATH"]);
   }
   private function create_history_file()
   {
      $this->create_file($GLOBALS["USER_HISTORY_PATH"]);
   }
   private function create_expert_file()
   {
      $this->create_file($GLOBALS["USER_EXPERT_PROGRESS_PATH"]);
   }
   private function initialize_progress_file()
   {
      $path = $this->create_file($GLOBALS["USER_PROGRESS_PATH"]);
      file_put_contents($path, "0\n");
   }
   public function change_password()
   {
      $this->username = Security::get_post_parameter("username");
      $password = Security::get_post_parameter("old_password");
      if (Security::verify_credentials($this->username, $password))
      {
         $this->set_password();
         if ($this->password)
         {
            $this->store_password();
            Security::show_success("password changed");
            return true;
         }
      }
      return false;
   }
   public function reset_password()
   {
      $this->username = Security::get_post_parameter("username");
      $this->password = $this->generate_password();
      if (Security::find_user_directory($this->username))
      {
         $this->store_password();
         return $this->send_password($this->password);
      }
      Security::show_error("Username not found");
      return false;
   }
   private function generate_password()
   {
      $length = $GLOBALS["GENERATED_PASSWORD_LENGTH"];
      $set = $this->generate_character_set();
      $password = "";
      for ($ii = 0; $ii < $length; $ii++)
      {
         $password .= $set[rand(0, strlen($set) - 1)];
      }
      return $password;
   }
   private function generate_character_set()
   {
      $set = "";
      for ($ii = 0; $ii <= 90 - 65; $ii++)
      {
         $set .= chr($ii + 65);
      }
      for ($ii = 0; $ii <= 122 - 97; $ii++)
      {
         $set .= chr($ii + 97);
      }
      for ($ii = 0; $ii <= 9; $ii++)
      {
         $set .= $ii;
      }
      return $set;
   }
   private function send_password($password)
   {
      $email_address = $this->get_email_address();
      $mail = new Password_Mail($email_address, $password);
      if ($mail->send())
      {
         Security::show_success("New password emailed");
         return true;
      }
      Security::show_error("Mail delivery failed");
      return false;
   }
   private function get_email_address()
   {
      $path = $this->get_user_path() . $GLOBALS["USER_EMAIL_ADDRESS_PATH"];
      $fields = explode(" ", file_get_contents($path, FILE_IGNORE_NEW_LINES));
      return $fields[0];
   }
}
54.227.96.5
54.227.96.5
54.227.96.5
 
June 5, 2016

September 30, 2015


Edge of Life is a form I made with Babycastles and Mouth Arcade for an event in New York called Internet Yami-ichi, a flea market of internet-ish goods. We set up our table to look like a doctor's office and pharmacy and offered free examinations and medication prescriptions, a system described by one person as "a whole pharmacy and medical industrial complex".

Diagnoses were based on responses to the form and observations by our doctor during a short examination. The examination typically involved bizarre questions, toy torpedoes being thrown at people and a plastic bucket over the patient's head. The form combined ideas from Myers-Briggs Type Indicators, Codex Seraphinianus and chain-mail personality tests that tell you which TV show character you are. In our waiting room, we had Lake of Roaches installed in a stuffed bat (GIRP bat). It was really fun!

The icons for the food pyramid are from Maple Story and the gun icons are from the dingbat font Outgunned. I'm also using Outgunned to generate the items in Food Spring.

January 28, 2014


E F F L U E N C E

December 3, 2013

Where in the mind's prism does light shine, inward, outward, or backward, and where in a plane does it intersect, experientially and literally, while possessing itself in a dripping wet phantasm?


Fig 1.1 What happens after you turn on a video game and before it appears?

The taxonomy of fun contains the difference between gasps of desperation and exaltation, simultaneously identical and opposite; one inspires you to have sex, while the other to ejaculate perpetually. A destruction and its procession are effervescent, while free play is an inseminated shimmer hatching inside you. Unlikely to be resolved, however, in such a way, are the climaxes of transitions between isolated, consecutive game states.

You walk through a door or long-jump face first (your face, not Mario's) into a painting. A moment passes for eternity, viscerally fading from your ego, corpus, chakra, gaia, the basis of your soul. It happens when you kill too, and especially when you precisely maim or obliterate something. It's a reason to live, a replicating stasis.


Fig 1.2 Sequence in a video game

Video games are death reanimated. You recurse through the underworld toward an illusion. Everything in a decision and logic attaches permanently to your fingerprint. At the core, you use its energy to soar, comatose, back into the biosphere, possibly because the formal structure of a mind by human standards is useful in the next world.

November 9, 2013


Food Spring - Watermelon Stage

Getting the fruit as far as possible is the object of each level, collecting bigger, more valuable guns. The final result is determined by the size of the fruits' collection when the monkey arrives in North America and either survives or perishes in the fruits' attack.

Watermelon Peach
Pineapple Grapes
September 13, 2013

from array import array
from time import sleep

import pygame
from pygame.mixer import Sound, get_init, pre_init

class Note(Sound):

    def __init__(self, frequency, volume=.1):
        self.frequency = frequency
        Sound.__init__(self, self.build_samples())
        self.set_volume(volume)

    def build_samples(self):
        period = int(round(get_init()[0] / self.frequency))
        samples = array("h", [0] * period)
        amplitude = 2 ** (abs(get_init()[1]) - 1) - 1
        for time in xrange(period):
            if time < period / 2:
                samples[time] = amplitude
            else:
                samples[time] = -amplitude
        return samples

if __name__ == "__main__":
    pre_init(44100, -16, 1, 1024)
    pygame.init()
    Note(440).play(-1)
    sleep(5)

This program generates and plays a 440 Hz tone for 5 seconds. It can be extended to generate the spectrum of notes with a frequency table or the frequency formula. Because the rewards in Send are idealized ocean waves, they can also be represented as tones. Each level has a tone in its goal and a tone based on where the player's disc lands. Both play at the end of a level, sounding harmonic for a close shot and discordant for a near miss. The game can dynamically create these tones using the program as a basis.

I'm also building an algorithmically generated song: Silk Routes (Scissored). Here is an example of how it sounds so far:

August 12, 2013

I've been researching tartan/plaid recently for decoration in my updated version of Ball & Cup, now called Send. I want to create the atmosphere of a sports event, so I plan on drawing tartan patterns at the vertical edges of the screen as backgrounds for areas where spectator ants generate based on player performance. I figured I would make my own patterns, but after browsing tartans available in the official register, I decided to use existing ones instead.

I made a list of the tartans that had what I thought were interesting titles and chose 30 to base the game's levels on. I sequenced them, using their titles to form a loose narrative related to the concept of sending. Here are three tartans in the sequence (levels 6, 7 and 8) generated by an algorithm I inferred by looking at examples that reads a tartan specification and draws its pattern using a simple dithering technique to blend the color stripes.


Acadia


Eve


Spice Apple

It would be wasting an opportunity if I didn't animate the tartans, so I'm thinking about animations for them. One effect I want to try is making them look like water washing over the area where the ants are spectating. I've also recorded some music for the game. Here are the loops for the game over and high scores screens.

Game Over

High Scores

June 29, 2013

A few weeks ago, for Fishing Jam, I made a fishing simulation from what was originally designed to be a time attack arcade game. In the program, Dark Stew, the player controls Aphids, an anthropod who fishes for aquatic creatures living in nine pools of black water.



Fishing means waiting by the pool with the line in. The longer you wait before pulling the line out, the more likely a creature will appear. Aside from walking, it's the only interaction in the game. The creatures are drawings of things you maybe could find underwater in a dream.

The background music is a mix of clips from licensed to share songs on the Free Music Archive. Particularly, Seed64 is an album I used a lot of songs from. The full list of music credits is in the game's README file.

I'm still planning to use the original design in a future version. There would be a reaction-based mini game for catching fish, and the goal would be to catch as many fish as possible within the time limit. I also want to add details and obstacles to the background, which is now a little boring, being a plain, tiled, white floor.

If you want to look at all the drawings or hear the music in the context of the program, there are Windows and source versions available. The source should work on any system with Python and Pygame. If it doesn't, bug reports are much appreciated. Comments are also welcome :)

Dark Stew: Windows, Pygame Source

I wrote in my last post that I would be working on an old prototype about searching a cloud for organisms for Fishing Jam. I decided to wait a while before developing that game, tentatively titled Xenographic Barrier. Its main interactive element is a first-person scope/flashlight, so I'd like to make a Wii version of it.

I'm about to start working on a complete version of Ball & Cup. If I make anything interesting for it, I'll post something. There are a lot of other things I want to write about, like game analyses, my new GP2X and arcades in Korea, and there's still music to release. Lots of fun stuff coming!

May 19, 2013

Welcome! I will be posting here about open-source games and music I am making for free online distribution. Most recently, I made Ball & Cup for Ludum Dare 26, a game I will work on more in June. After finishing, if it's fun, I will build an arcade cabinet for it! Next week, I am joining the 7-Day Fishing Jam to develop an A-life prototype about searching a cloud of noise for organisms.

Before Ball & Cup, I was adding features like vehicle engines, new graphics and effects and detailed scoring to an updated version of E.S.P. Hadouken, currently a prototype about navigating five psychic hadoukens to save your Game Boy. The new version will be similar with a clearer story and more ways to judge your performance. I plan on finishing it after making a public version of Ball & Cup.

I will also upload some digital albums soon. One, Man's Womb, is a solo collection of chiptunes from Emoticon Vs. Rainbow, an online racing/rhythm game. The other, Tor Ghul/Spin Ghul is a guitar and synth record recorded with my friends last summer. The recording and sequencing are finished for both -- I just have to make their web pages and artwork and package them for downloading.

Later, I hope to write about games in their early stages, an abstract action-RPG called Panopticon: Swarm, a massively multiplayer exploration, voting, post-catastrophic city simulation, Vomit Inspector and a mobile mini-game compilation project that includes an external digital pet raising and social networking mode. I also plan to post analyses of games I'm playing as a design exercise and for fun.

I will write about more game stuff like arcade trips, game jams and electronics! Plus whatever I haven't thought of! If you use RSS, subscribe to my feed!


↠ RSS Feed ↞