Tuesday, July 24, 2012

DayZ Tutorial, quick tips

The other day I finally got Arma 2 from the Steam Summer Sale and eagerly loaded up DayZ. Unfortunately it wasn't the easiest of tasks and put me in right state of fury! But the game turned out to be fun and I wanted to share some of the basics so people don't get discouraged and stop playing right out the gates.

Steam installation

The DayZ Steam installation was surprisingly easy, but it seems like there's a few spots people might make mistakes. So please follow these instructions carefully:
  1. Download Arma 2 and Arma 2: Operation Arrowhead.
    • NOTE: Arma 2: Combined Operations is simply the name of the expansion pack containing the two games. It just gives you the option to buy them separately or together.
  2. Run Arma 2 and Arma 2: Combined Operations.
    • When launching OA, it gives you multiple options, launch Combined Operations.
    • Also, don't bother configuring controls and settings, it does NOT appear to save them between games.
  3. Close each game and navigate to here. Click "Download v2.9.7pre" or whatever version it's on.
    • You can also use a mirror if necessary.
  4. Install the SIX Updater and launch it.
  5. Once it loads, click the big button on the left which says, "Install" or "Update". Let it run.
  6. If everything went smoothly, it should say "Verify" or appear complete in some way.
    • In the background it is updating/installing beta files and updating/installing DayZ mod files.
  7. You are now set to play.
    • NOTE: the server list takes awhile to load. Be patient if you are looking for a specific server.

Playing DayZ

There are a few key things to know about DayZ:
  1. LOADING: It may take a LONG time to load so be patient. If you think you've froze on a black screen that says "Loading", it is simply just taking a really long time. I almost think they did it on purpose to discourage people from dying...
  2. LOCATION: as the game finally loads up, quickly look at the bottom right corner for some text. This is your starting location. Remember what it is and look here. If that doesn't help, look for signs or determine the shape of the coast to find your location. Knowing where you are is essential if you're playing with friends.
  3. FIRST 10 MINUTES: When you get in for the first time, don't get discouraged about dying. I ran around like an idiot the first couple times not realizing how powerful zombies were. I also couldn't figure out how to use items or where I should go. All I will say is avoid coastal cities and head for the hills.
  4. USING ITEMS: when you press G to open your inventory, you'll be presented with a list of items and bag slots. To use say, a bandage, you would right click on it in the bag slot (NOT the list). Then left click on the dialog that slides open ("use bandage"). For weapons, you use the mouse scroll wheel to bring up item selections in the center of the screen, then press ENTER to select that weapon.
  5. DYING: When you die, you can't simply click respawn. You must abort, disconnect and reconnect. Why? I have no idea, it's dumb.
  6. LOOTING: the interface is terrible. When you see something to loot (a body or pile of shit), you press ENTER to open the menu. The numbers on the left are items you do NOT have. The numbers on the right are items you do have. Click the arrows to exchange items from left-to-right or right-to-left.
  7. FALL DAMAGE: if you fall and break your legs, call over your best mate and have him put a slug in your face. You can only fix broken legs if you visit a hospital (there are only 4 locations in the world). The alternative is you crawl on your stomach which would take ages.
That should get you going. It's a really fun game despite the flaws in interface and controls. My biggest tip through all this is BE PATIENT. Good luck and happy surviving!

Wednesday, July 18, 2012

Encrypted User Signup/Login using hash_hmac

So I've been working with CodeIgniter for awhile now and needed a secure user login system. I chose to develop my own since I wanted to learn as much about building a framework as possible. At one point during development I realized I needed a good user password system that didn't store passwords as a hashed string. So I went online and implemented this solution:

Ok, before we do anything, we need to add a "site_key" to our application/config/config.php file:


/*
|------------------------------------------------------------------------
| Site Key
|------------------------------------------------------------------------
|
| This is the global site key used for secure password generation.
|
*/
$config['site_key'] = 'long_random_alphanumeric_string';


The site_key will be used below. I generated mine through KeePass. Now the signup controller:


// SIGNUP for user account controller:
public function validate_signup()
{
     // Use the form validation library to validate user input
     $this->load->library('form_validation');
     
     $this->form_validation->set_rules('...');

     // Run the form validation
     if ($this->form_validation->run() == FALSE)
     {
          $this->index("Optional custom error message!");
     }
     else // if form validation passed
     {
          // Run the INSERT statement and return TRUE/FALSE
          if ($this->user_model->InsertSanitize($_POST['password']))
          {
               redirect('login');
          }
          else
          {
               $this->index("ERROR: signup failed!");
          }
     }
}

The signup controller handles taking new user information, validating it, and then sending the information to the user model to be INSERTED. Next let's look at the user model:

public function InsertSanitize($password)
{
     // Retrieve user input data through POST:
     $user_name = $this->input->post('user_name');
     // Or passed through the method (choose one or the other, not both):
     $password = $password;


     // Do additional validation here if needed:
     if (!isset($user_name) || $user_name == "")
     {
          // You can also use regex or functions like is_numeric()
          return FALSE;
     }

     return $this->Insert($list_of_safe_values, $password);
}



private function Insert($list_of_safe_values, $password)
{
     // Now it's time for the fun stuff!
     // First we need to use crypt() to hash the input password
     $hashed_pass = crypt($password);
     
     // Next we need to call a custom function below (scroll down):
     $enc_pass = $this->encrypt($password, $hashed_pass);

     // Create an array of user info to INSERT
     // Be sure to store the encrypted and hashed password
     $data = array(
          'list_of_safe_values' => $list_of_safe_values,
          'enc_pass' => $enc_pass,
          'hashed_pass' => $hashed_pass
     );

     // Run the INSERT
     if ($this->db->insert('user_table', $data))
     {
          // Optional: Return the last records ID
          return mysql_insert_id();
          // Or simply:
          return TRUE;
     }
     else // if INSERT failed
     {
          return FALSE;
     }
}


private function encrypt($password, $nonce)
{
     // Retrieve the site_key
     $site_key = $this->config->item('site_key');

     // Return the encrypted password using hash_hmac

     return hash_hmac('sha512', $password . $nonce, $site_key);
}


Be sure when updating your website or overwriting files that you keep the site key! If you forget to re-add it, existing users won't be able to login and new users won't have the site_key attached to their accounts.

Finally, I'll show you how to use this system when logging in:

public function validate_login()
{
     // Just like before, run form validation

     $this->load->library('form_validation');
     
     $this->form_validation->set_rules('...');



     if ($this->form_validation->run() == FALSE)
     {
          $this->index("Optional custom error message!");
     }
     else // if form validation passed
     {
          // Next, run validation in the user model:
          $data = $this->user_model->Validate($_POST['password']);
     }
}



public function Validate($password)
{
     // Retrieve user input data through POST:
     $user_name = $this->input->post('user_name');
     // Or passed through the method:
     $password = $password;


     // Do additional validation here if needed:
     if (!isset($user_name) || $user_name == "")
     {
          // You can also use regex or functions like is_numeric()
          return FALSE;
     }

     // Next we need to call a custom function below (scroll down):
     $enc_pass = $this->retrieve($user_name, $password);



     // With the encrypt password we can now validate our user login
     $sql = sprintf(self::constant . " WHERE user_name = '%s'
          AND password = '%s' LIMIT 1",
          mysql_real_escape_string($user_name),
          mysql_real_escape_string($enc_pass));


     // Run your queries however you normally do
     return $this->LoadFromDb($sql);
}



private function retrieve($user_name, $password)
{
     // Find user by user_name
     $data = $this->FindUser($user_name);

     // Get the hashed user password

     if (isset($data))
     {
          foreach ($data as $obj)
          {
               $hashed_pass = $obj->hashed_pass;
          }
          return $this->encrypt($password, $hashed_pass);
     }
     else
     {
          return FALSE;
     }
}

And that's it! But before I leave, let me explain quickly in case it's a little unclear.

First we created a site key, which is used to further enhance the encryption process.

Then we allowed a user to signup, validating form data and then data that's passed to the model. Within the Insert() function we took the submitted user password and hashed it, creating a randomly generated, alphanumeric string. This is what is used as a key for decrypting the encrypted password. Then we called the encrypt() function which takes the user password and the hashed key, along with the site key and encrypts them altogether. We returned this encrypted password and INSERTED it into the database along with the hashed key and any other user data (like username, email, etc.).

Now that we have a new user account with an encrypted password, we need to login. We validate the login form and data that's passed to the model. If everything looks good, we call the retrieve() function which loads the requested user information. We grab the supposed user's hashed key, along with the password they provided at login, and run it through the encryption process again.

From here we created a query using the provided user_name and processed encrypted password to see if any entries in the database are returned. If there is a record, that means that the username and password the login provided, matched and was successful. If it fails, that means either the username or password was wrong, or the user doesn't even exist.



Hopefully that all makes sense. Good luck!


Note: sorry if the code looks messed up, Blogger apparently sucks at pasting...also we're technically never decrypting anything. Just encrypting again and comparing.

Simple PHP loop script to transfer user table

A while back I was working on my CodeIgniter project and decided to restructure my database. Since I didn't have many rows that actually mattered (it was all test data), the only thing I needed to transfer over was my user table. So here's a simple example of a script that will transfer records over from one database to another.


<?php

// Set the connection information
$con = mysql_connect("localhost", "root", "root");

// Select the original database containing old records
mysql_select_db("old_db", $con);

// Check the connection
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

// Select the records from the database
$query = "SELECT * FROM user_table";

// Run the query
$result = mysql_query($query);

// Now select the new database
mysql_select_db("new_db", $con);

// Loop through each row from the old database
while ($row = mysql_fetch_assoc($result))
{

     // Set each column to a variable
     $user_name = $row['user_name'];
     $password = $row['password'];
     $email = $row['email'];
     // You could also reset defaults or check for NULL columns

     // Here's an example for permissions:
     if ($row['permissions'] == 0)
     {
          $permissions = 1;
     }
     else if ($row['permissions'] > 3)
     {
          $permissions = $row['permissions'] + 1;
     }
     else
     {
          $permissions = $row['permissions'];
     }
     $date = $row['date'];

     // Set up the INSERT query
     $insert = "INSERT INTO new_user_table (user_name, password, email, permissions, date) VALUES ('$user_name', '$password', '$email', '$permissions', '$date')";



     // Run the INSERT query
     mysql_query($insert);


     // Check to make sure this particular INSERT worked
     if (!mysql_insert_id())
     {
          echo "ERROR: there was a problem inserting data.";
     }
}

// Close the connection
mysql_close($con);

?>

That's it! This script is pretty simple and might not be great for really large user tables, but for smaller sites or when you're just testing data, it works fine.

Friday, July 13, 2012

Using CRON and PHP scripts with Dreamhost

As a followup to my previous post regarding inserting RSS feed data into a MySQL database, I wanted to quickly explain how I used DreamHost's CRON to create an automated news feed.

First make sure you have a script ready to use. Something that you want to run at certain time intervals. This could be the RSS feed script from before, something that scans user accounts, looks at site data and publishes an XML document, whatever. Just make sure it works (connects to DB, grabs or modifies data without problems, and closes the connection). Also be sure to change any local settings. For instance, if your script still says "localhost" for the connection string, it's not going to work!

Next we need to set up a Shell account, which is really easy in DreamHost:




It may take a few minutes for the new user to be created. After it's done, FTP into your web server using the new Shell account. I use Filezilla for this. If you don't know how to FTP in or setup Filezilla, this guide will probably help (or just Google it). Once you're in, create a folder called "cron" (or whatever you want to name it) and upload your scripts.




Almost done. Head back to DreamHost and click on "Cron Jobs", then "Add New Cron Job".



Finally we need to enter the cron settings. Select the shell user account you just created and title this cron job whatever you'd like. For "email output to", optionally enter an email address. If you do this, it will email you the results of your script. For instance, if you wrote your script in PHP and had any echo statements, you'll receive them. This is handy for when you first test your cron job so you can check that each part is running successfully. For example, you may want to echo/output any possible errors, success messages for DB connections/inserts/selects/etc., and a message at the end saying "script successful" or "script failed". After a few successful iterations of the cron job you can turn it off if you please.


For status we obviously want it enabled, although you can disable it later if you deem this script unnecessary. I prefer this as opposed to deleting it in case you want it later. For the command, we enter the path to the script. You can also write command code here, but I prefer having an external script I can modify and play with. I also leave locking on. And lastly, you can set your cron interval. This particular script runs every 15 minutes since I need fresh news frequently.




And that should be it. Once you submit it the cron job will run at the next interval and hopefully the script will execute successfully! For me, this allows me to read incoming RSS feeds, insert it into the DB, and then use the data on my website. It works great and I haven't had any problems since implementation. Good luck!


UPDATE: that space between php and /home/ in the command is on purpose! Be sure to do the same.

Tuesday, March 20, 2012

Running an eSports Booth

The other weekend I was in the Twin Cities (MN) for a Teh Pwn Gaming / CSL StarCraft 2 tournament (you can read about it here). It was a ton of fun and I wanted to share a particular aspect about it that might be of interest to some young entrepreneurs out there. Here's what I learned about running an event booth.

The story begins on Facebook. I was contacted by my friend Evva, the president of Teh Pwn, and she asked me if I wanted a booth for the up-coming event. I was initially concerned about agreeing because my operation is small, obscure, and the opposite of well-funded (one of those grassroots, indie-style operations). Anyways, I pictured myself next to Antec, ASUS, and NOS whose booths were epic, decked out with kick-ass banners and voluptuous women distributing tons of free swag. Needless to say I was afraid of looking inadequate and cheap. But Evva assured me that everything would be fine and it was a great opportunity to network and share my website. So I agreed.

To prepare I ordered business cards, spray-painted some t-shirts, and packed my laptop. It was a pretty low-key package, but figured it would do. However, upon arrival I checked out my setup and realized I forgot some sort of banner. Oops... But we ended up making a banner out of cardboard paper which looked pretty legit from a distance. If you do this, make sure it's cool within your industry. Fortunately eSports is pretty young so I don't think it was a big deal.

The best part about my setup was probably the business cards. I would highly recommend getting some. Why? Because you can get a ton of them for relatively cheap and you'll always have something to give out. If you just bring t-shirts, what happens after they're all gone? Now there's nothing for people to look at later and be reminded of your organization. Definitely order some.

Bringing a laptop was another great idea. It helped to physically show my site rather than just explaining it. If you don't have one, find someone who does and borrow it. If you're in technology, Internet, web, whatever, you need a device to show off your work.

One thing I wish I would have done differently is buy professionally made t-shirts. The ones we were wearing looked legit from a distance, but up-close looked cheap. I also wish we would have had some extras to give out. The NOS booth ran through all their free stuff right away because people wanted it. And in exchange they Liked them on Facebook and checked in on Foursquare. Not a bad deal in my opinion.

Overall, if you're thinking about representing yourself at an event. The more professional you can be the better. I'm unfortunately locked down by a small budget so I have to pick and choose, but if you're not, definitely get everything made professionally. A nice banner, solid business cards, free t-shirts, and a laptop will go a long way. But even if you can't do that, just go anyways. I still ended up meeting a ton of cool people and networked with other organizations. Don't doubt yourself, it'll be fun and everyone is a lot nicer and more supportive than you think.

Monday, February 13, 2012

Website Plugs February 2012

I wanted to give a shoutout to a couple websites that have really helped me in various fields of my life.

The first is a website analysis tool I stumbled on during spawnroom.com development last month. It's called WooRank.com. The reason I was so attracted to this site over others was their layout and simplicity. I entered my address, a little dial racked up points, and it told me exactly what to do to increase SEO. If you haven't tried it out, give it a whirl and see what you think. The test takes under a minute.

Next up is Astrid.com, a to-do list manager with apps for mobile devices. For awhile before Christmas I was looking for a website like this to manage all my projects and tasks, but hadn't come across anything spectacular. Most other sites were missing a crucial feature or just looked awful. But Astrid was simple, sleek and had everything I needed. Now I use it everyday and it has helped my productivity immensely. I definitely recommend testing it out.

Just for fun I wanted to shoutout Sputnikmusic.com. I've been using their site for a year or so and love it. Their album reviews are generally spot on and have helped me discover tons of new music. They also track your ratings so you can refer back and listen to great albums you forgot about. The only problem with their site is stability and speed. It seems to be down quite a bit and very slow at times.

Finally I wanted to shoutout my new site that I mentioned above: spawnroom.com. It's a major work in progress, but something I'm extremely excited about. It's an eSports resource website that will act as a centralized database of eSports knowledge. I have a ton of features I'm working on and will be releasing them over the next few months. Check it out and let me know what you think!

Note: I was not paid or asked to shoutout these sites. I'm doing this entirely on my own because I truly use and enjoy these websites.

Ways I manage my productivity

I'm currently in the process of starting a small business and I wanted to share the different ways I help improve productivity using online tools. I'd also love to hear recommendations from readers for new tools they find useful.

The first and most used tool in my inventory is Google Documents. I use docs for almost everything I write down because it's convenient, easy to use, and is safely backed up on a Google server. It's also attached to a Google account I use other services with like Gmail, Calendar, and Talk so this makes it even more useful.

The next best productivity tool I've discovered is Astrid to-do lists. This website and mobile app allows you to create categories, add tasks, schedule due dates, share them with coworkers, and set their priority. It's simple, easy to use, and best of all keeps me on track. I used this extensively for managing not only project development, but in my personal life as well. Easily one of the best, if not the best, to-do list I've ever used.

Next is duo of productivity tools that work amazing in conjunction with each other: Keepass Password Safe and Dropbox. To set this up, there are a few easy steps:

  1. Register for a Dropbox account and download the installer for your operating system.
  2. Install Dropbox and login with your account.
  3. Install Keepass, create a password database and save it in the Dropbox folder.
  4. Voilà! Your Keepass database should sync to your Dropbox account and any computer with the same login credentials.
This combo between Keepass and Dropbox has been amazing for me. My passwords are safe, in a centralized location, searchable AND backed up online and to other computers automatically. I highly recommend this setup so you can sleep easy at night.

Branching off this same idea, I also wanted to encourage readers to save other important documents there as well. Every night after I complete revisions to my projects I zip and copy them to the Dropbox folder. That way if my laptop was stolen or destroyed, I always have an updated copy of my work online and on my desktop. If you're concerned about the security of these files, you can take additional steps to protect them using TrueCrypt.
I won't go into too much detail here since there are plenty of tutorials online, but using TrueCrypt, you can encrypt files or create "containers" to place files in. This way you can encrypt your work and then back it up to Dropbox. This should definitely put any anxiety to rest.

For the last part I wanted to mention a couple other tools I use here and there. Twitter has been great for not only spreading awareness, but reminding myself of cool websites, ideas, and people. When I tweet, I am often times doing it for myself, just as much as for my followers. They also have the list feature which makes it easy to organize others into meaningful groups to reference later.
Google Calendar is another great application that helps me keep track of upcoming tasks and appointments, but is quickly being replaced with Astrid. Sorry Google!
The last one isn't exactly related to productivity but something I wanted to mention anyways. It's YouTube and their queue/playlist feature. I am involved in the eSports world with my website spawnroom.com and part of my job everyday is to follow the community by reading news and watching eSport podcasts and shows. The YouTube playlist feature is awesome for this. I grab the list of shows, hit up their VODs and launch the playlist. Works perfectly and keeps me up-to-date. Now I just wish all these shows used YouTube. Darn you OneMoreGame.tv!!!