Patrick’s development blog

Drawing rectangles SDL

Posted in SDL / OpenGL by Patrick on June 24, 2009

Drawing rectangles can become such a pain in the ass after drawing them a couple of times. I made a helper function that makes this easier.

void FillRect(int x, int y, int w, int h, int color) {
SDL_Rect rect = {x,y,w,h};
SDL_FillRect(screen, &rect, color);
}

I want to add a 100×150 rectangle at the position (25,25) with the color white.

FillRect(25,25,100,150,0xFFFFFF);

Great, no more headache and code memorizing.

Getting mouse state in SDL

Posted in SDL / OpenGL by Patrick on June 23, 2009

I’ve decided to finally start a programming project after a very long break. I found the need to use mouse states when creating a Level editor for my RPG because regular events doesn’t really do what I want.

I want to add tiles fast and be able to hold the mouse key down, instead of clicking every time I want to add a tile.

Mouse states

int cx,cy;
Uint8 ms = SDL_GetMouseState(&cx, &cy);
if (ms & SDL_BUTTON(SDL_BUTTON_LEFT)) {
// the left mouse key is pressed
} else if (ms & SDL_BUTTON(SDL_BUTTON_RIGHT)) {
// the right mouse key is pressed
}

Using the OpenBSD package system

Posted in BSD by Patrick on June 15, 2009

The package system in OpenBSD consists of pre-compiled programs that can be managed with the pkg tool. The packages may not necessarily contain the same kind of security and realibility as the base system, but pkg is useful for installing “third party” software.

1. Create the environment variabel PKG_PATH with the value of the right directory to fetch the packages.
export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/4.5/packages/i386/

2. Add this line into the startup file, ~/.profiles so we don’t have to export it every time we use pkg.

Installing a package
pkg_add -i firefox

Removing a package
pkg_delete firefox

Information about installed packages
pkg_info

Mount ntfs drive on Linux

Posted in Linux/GNU by Patrick on April 28, 2009

1. Install ntfs-3g.
2. Create a folder in /media or /mnt (mkdir /media/windows)
3. Use fdisk -l to get the name of the NTFS drive (example: dev/sda1)
4. Add the drive into /etc/fstab so it mounts automatically.

/etc/fstab
/dev/sda1 /media/windows ntfs-3g defaults 0 0

Using X with SSH

Posted in Diary, Linux/GNU by Patrick on April 17, 2009

I was working on the school computers from home trough SSH and needed to use X. Using the “-X” parameter gave me error messages when I used the keyboard mouse if I remember correctly. This worked without any error messages though.

ssh -Y -l user server

Encrypt chat conversations in Pidgin using pidgin-otr

Posted in Articles, Security by Patrick on March 17, 2009

Pidgin is an excellent “chat client” or instant messaging client. I’ve even replaced the MSN client on my Windows system with Pidgin. It’s open source and has support for many different chat networks like MSN, ICQ…

There’s a plugin called pidgin-otr (Off-the-Record messaging) which allows you to encrypt your conversations (assuming the other part also has pidgin-otr installed). Regretfully, people never seems to care about encryption even if they seem to get close to crazy if someone invades their privacy, quite the paradox… Well that’s just another story which i’m not going to post here, as i’m just spreading the word about everything that’s good : )

The Off-the-Record messaging plugin uses public and private keys. It’s very easy to use. Just download the plugin, activate it in the Pidgin add-on menu and generate a key. In the conversation window, a button will appear that makes it easy to toggle encryption on/off.

Download Pidgin from: http://www.pidgin.im/download/
Download Pidgin-otr from: http://www.cypherpunks.ca/otr/index.php#downloads

Encrypting mail in Thunderbird using GnuPG and Enigmail

Posted in Articles, Security by Patrick on March 17, 2009

Thunderbird is a mail user agent developed by Mozilla. GnuPG is an encryption program (free software) that uses the standard OpenPGP. This standard is based on encryption using a private and public key. The private key is used to decrypt the data while the public key is used to encrypt the data.

The Thunderbird add-on Enigmail, provides an “back-end” interface to GnuPG so the user can use Thunderbird to encrypt/decrypt mail. After installing Enigmail, generate a keypair. This will create a public and private key for the current account. The public key is meant to be distributed so other people can send mail encrypted to you. The private key however, is important NOT to distribute. Since it is used to encrypt the messages sent to you with your public key. The public key is usually uploaded to a keyserver.

It’s possible to search for public keys on the keyservers and add public keys into a local list and configure Thunderbird to encrypt all messages by default (supposing the public key to the person in question is added into your key list). Both Thunderbird, GnuPG and Enigmail, are very useful indeed : )

For more information about GnuPG and Enigmail:
http://www.gnupg.org/
http://enigmail.mozdev.org/home/index.php

Compile SDL/OpenGL applications using g++

Posted in SDL / OpenGL by Patrick on February 16, 2009

This is how I compile a C++ program with SDL and the OpenGL libraries GL and GLU.

g++ -o appname opengl.cpp `sdl-config –libs –cflags` -lGL -lGLU

sdl-config –libs –cflags is used to get the library path and include path for SDL. This can be used instead of manually specifying the libraries for SDL.

Burn DVD in Linux using dvd+rw-tools

Posted in Linux/GNU by Patrick on February 11, 2009

Install dvd+rw-tools with your package manager or download it from here. And then invoke the following commands…

Format disc where /dev/dvd is the device name:

dvd+rw-format -force /dev/dvd

Burn the directory (/home/user/stuff) onto the DVD:

growisofs -Z /dev/dvd -R -J /home/user/stuff

More information:
http://fy.chalmers.se/~appro/linux/DVD+RW/

become anonymous on the internet using Tor

Posted in Articles, Security by Patrick on July 23, 2008

Tor is a platform independent program that protects you from traffic analysis. Traffic analysis is a form of surveillance of your network traffic which is a threat to your personal integrity. Tor is usually used to surf anonymously, but can also be used with for example instant-messaging applications.

How Tor works
When using Tor, your communication with the internet is protected by distributing it trough a network of different relays trough the world which are run by volunteers. The communication is also encrypted so no one can see what you’re doing or learn your location.

I recommend using the Firefox add-on Torbutton which provides an easy way to disable/enable Tor in Firefox. This way, you don’t have to configure your browser either.

Pitfalls with Tor
Watch out for cookies, flash files, java applets and similiar web applications. They can reveal your IP-address even if you use Tor. Using Add-ons for Mozilla Firefox like No Script and Flash Block can prevent this. Be sure that you don’t fall for things like this.

Even if Tor encrypts your traffic inside the Tor-network and makes you anonymous. The last relay you are connected to, which is directly communication with the webserver can still see your traffic. Don’t use Tor if you do things that can expose your identity, for example logging in to your webmail (if you truly want to be anonymous that is). Using an encrypted protocol like HTTPS prevents this though.

Read more about potential pitfalls here: http://www.torproject.org/download.html.en#Warning

To sum it up
If you want to surf anonymously, this is a very useful program as it also hides your IP-address. But remember that web apps like Flash can still expose your IP. A lot of people believes that installing Tor will automagically make them anonymous. That’s wrong however. You have to configure the application correctly you want to use with Tor. If you’re using Firefox, the Torbutton add-on makes this automatically.

A good idea might be to install a portable browser which you use only when you want to be anonymous. Configure this browser so it doesn’t accept cookies and install a flash blocker, block java and other “media” that could expose your IP-address. It’s recommended to only use services like webmail if the site uses SSL or another secure connection.

There is a portable version of Firefox called Firefoxportable.
Tor’s official website: http://www.torproject.org/