Beyond the Night Sky, HaKT Studios, Software

HaKT Studios Reborn

I’ve finally gotten around to working on my HaKT Studios project. HaKT Studios is now an open source game development group, and we are working on our first title. I’ve begun work on the homepage, well the boilerplate code for it anyway, and I will be uploading it too. The HaKT Skull has been re-vamped by Johnnie Ray Timmons, and I think it’s just awesome.  Have a look!
HS Badge

I don’t want to expose too much, but if you follow the HaKT Studios Facebook page, you should be kept up to speed pretty well. I will tell you that our first title is called Beyond the Night Sky, and I plan on having it ready for testing around late-December 2014. I don’t want to give a firm release date at this time, as we are still in the extreme early stages of development. Anyway, keep tuned in, and I’ll let you know when something new happens.

Blog, Software

Developmental Woes

I seem to be stuck. I’m trying to design some forum software from scratch. That’s not so much a problem as that I keep finding myself in this endless loop of what features should be in it, rather than just coding the damn thing. I know that I really need to stop thinking about some “cool” feature that I could implement, and focus on the basics necessary to get the damn thing running. Anyway, that’s basically what I’m going to outline for myself in this post.

The first things that I need to consider are the absolute bare essentials required for forum software, then I need to break it down into sections. There are two parts that will be common to all other parts, storage, and display. That’s a little broad spectrum though. I need to break it down even further, so I need to consider: users, categories, threads, posts, and permissions. I think that should make things pretty manageable.

Seems simple enough, right? Yeah, it is, until I start considering future enhancements, and this is where I get into trouble. I start thinking about how it should all be hooked together, what kind of plugin system I should use, etc… You get the idea. I go into idea overload, and nothing gets done.

You might be asking me by now, “Why the heck are you even bothering with this Mark?” Well, the reason is simple, curiosity. I want to know if I can. I’m not going to say that whatever I should produce will be better than, or even be comparable too, Joe Blow forum software. That really isn’t the point. I’d like to produce something that’s recognized, but that’s only secondary. I’m doing it more of a learning experience than anything else.

Anyway, I’ve still got a lot of planning to do. I really need to start focusing on the immediate task at hand, rather than the end goal that may or may not ever come to fruition. Anyway, thanks for reading my blog, I’m going to attempt to get something done now.

Software

PHP Namespace Rant

In planning my PHP projects, I continually run into the same issue. Roughly ninety percent of the best PHP libraries out there do not use namespaces. This is of course a result of namespaces being relatively new, and many projects wanting to maintain compatibility with PHP 5.2 and earlier. What this really translates into for me is, if I want to add a library to one of my projects, which are designed with PHP 5.4+ in mind, I have to manually namespace all the files in that library, else face likely code conflicts.

Now, I may not have any conflicts with the working files, if I include them into the root namespace, until I start trying to autoload. Every large PHP library seems to have its own autoloader, which is fine, until you realize that they are almost always named autoloader. This of course is the first conflict that I almost always run into. I can load multiple autoloaders, but I can’t do so if they all have the same name and the same namespace. The simplest solution is to give them all the same namespace of the vendor. This does work, but it’s a bit messy. The more difficult solution would be to implement the third party autoloader into my own autoloader. This is just too much of a pain in the ass.

You may think that at this point my solution is simple. It’s not, it’s messy, it’s ugly, and it’s downright disgusting. By doing modifying the files I run into issues when it comes to using version control. I am moving all my projects over to git, due to one of it’s awesome features of using submodules. By using submodules, I can include the repository of another library in my project, and have it keep up to date, without having to manually update it myself. The second I modify one of the files, my only option is to fork the project. What this means is, whenever a project is updated, I have to re-pull all the files downstream, and then do my modifications all over again. This is a glorious waste of time and effort. I chose those libraries because I feel that the vendors of those libraries are the best at what they do, and I don’t want to try and reproduce their work all over again. Namespacing non-namespaced code defeats that purpose, forcing me to fork their code, and hope that I don’t miss any major security updates as time goes on.

As you can see, namespacing is awesome, if everyone uses it. So long as everyone tries to be backwards compatible, and produces non-namespaced code, namespacing is a headache. It’s at this point that people will say, why not just get rid of namespaces. I will tell them, that is not the solution. Without namespaces, the conflicts I had will still be there. Namespacing fixes the conflicts. Namespacing gives code context. Context in any language, programmed or spoken, is important. Context does more than tell us what you said, context tells us what you mean. Namespaces are a step forward, the next step is to actually use them.

Hardware, Software

Development Station

I’ve finally gotten around to reconfiguring my development station. I’ve installed Ubuntu 12.10 on it, and ran into a few problems along the way. Turns out that my Acer P215H didn’t want to play nice with it, and Ubuntu was unable to detect the proper graphics modes for it.

It was an arduous journey, but I did get it to work. It took me two days to come up with the proper fixes. It would have been faster, but I had a little something called a job that sucked up most of the time I could have been spending on it. In the end I didn’t find the solution online. Well, not the complete solution anyway. The mode lines generated by cvt would not work with the monitor, so xrandr was completely useless. Well, not really, but that’s only because I’m stubborn.

I did eventually come up with the proper mode line. It was an effort of trial and error mostly. Now the monitor operates at its native 1920×1080 resolution. So once I got that running, I installed the nVidia drivers, thinking that all the hard work is done. Well, I’m not running the nVidia drivers. Apparently xrandr was unable to use the mode line when I was running those drivers so I’m stuck on Nouveau drivers for now.

Now, xrandr has an interesting caveat, in that all changes made by it are completely temporary. Once you logout, reboot, or do anything, you have to do it all over again. I don’t want to type those commands every time,  so I saved the commands to a file and named the file “.xprofile”, which I then saved to my home directory. The great thing about .xprofile is that any commands in it run every time you log into your desktop via a display manager.

Enough with the bad stuff, on with the good. I’ve fully configured Ubuntu to play NetFlix videos, and Amazon Prime videos as well, since I access to both services, and I’d like to use them. I went ahead and installed Sublime Text 2 as well, and I’m getting ready to set up my Ruby environment as well. Well, that’s all that I’ve done so far. I’ll post more as time goes on.

IRC, Software

Toshiko IRC Bot

Toshiko is a horrible IRC Bot. But she is absolutely wonderful, when you understand why I created her. Toshiko is my attempt at learning the Ruby programming language. For me, the best way to learn anything is to apply it toward something that I enjoy. Now before you get too impressed, I’m not starting from ground zero. What little I know about ruby stems from my experience working with RPG Maker’s RGSS, which is essentially a stripped down version of Ruby with custom game libraries stacked in an embedded scripting environment. It’s a good base.

I had contemplated doing this project in python, however, I decided to not push myself so hard and to work with something that was already familiar to me at some level. Advanced Ruby programmers will probably have lot’s of comments about what I’m doing wrong in my code. That’s fine, I know that I’m not an expert in this language. My knowledge of this language is laughable at best. If you see me doing something that’s genuinely bad, or that I could be doing better, let me know. I’m doing this to learn, I accept the fact that I’ll make horrible mistakes and errors along the way. I also appreciate any advice that I can get.

Alright, now that I have gotten the introduction out of the way, let me show you my script. It’s not fully functional yet, it only idles, but the essentials are there. You’ll notice that I’ve included some stuff that I’m not using yet, such as the thread library. That’s because, at the time of posting, I am getting ready to implement threading. I’m doing some research on it now, and only included the dependency so that I wouldn’t forget once I got to actually coding it. Anyway, enjoy, and try to ignore the fact that there is code in there that’s not actually being used, or has variables that aren’t created yet. This is a work in progress after all

#-------------------------------------------------------------
# Project:   Toshiko IRC Bot
# Version:   0.5.0-alpha
# Author:    Mark LaDoux
# E-mail:    mark.ladoux@gmail.com
# Website:   http://markladoux.com/
# Copyright: Copyright © 2012, Mark LaDoux. ALL RIGHTS RESERVED
#-------------------------------------------------------------

#----------------------------------------------------------
# include dependencies
#----------------------------------------------------------
require 'socket'
require 'thread'

#-------------------------------------------------------------
# Toshiko Bot Class
#-------------------------------------------------------------

class Toshiko

	#-------------------------------------------------------------
	# Attribute Accessors ( Read and Write )
	#-------------------------------------------------------------
	attr_accessor(
		:nick,  # Use this nick
		)

	#-------------------------------------------------------------
	# Attribute Readers ( Read only, no write access)
	#-------------------------------------------------------------
	attr_reader(
		:version,     # Class version
		:socket,      # Network socket
		:dead_socket, # is the network socket dead?
		)

	#-------------------------------------------------------------
	# Attribute Writers ( Write only, no read access )
	#-------------------------------------------------------------
	attr_writer(
		:server,             # Connect to this server
		:port,               # Use this port
		:server_password,    # Use this password
		:nick_password,      # Identify with this nick
		:real_name,          # Use this real name
		:use_vhost,          # use a vhost
		:verbose,            # return verbose error messages
		)

	#-------------------------------------------------------------
	# Initialize class!
	#-------------------------------------------------------------
	def initialize(opts = {})

		# Library Version
		@version = '0.5.0-alpha'

		# Grab user configurations
		@server          = opts[:server]
		@port            = opts[:port] || 6667
		@server_password = opts[:server_password]
		@nick            = opts[:nick]
		@nick_password   = opts[:nick_password]
		@real_name       = opts[:real_name] || "Toshiko IRCBot #{@version}"
		@use_vhost       = opts[:use_vhost]
		@verbose         = opts[:verbose]

		# get defaults
		defaults
	end

	#-------------------------------------------------------------
	# Defaults
	#-------------------------------------------------------------
	def defaults
		@dead_socket = true
		@reconnect   = true
	end

	#----------------------------------------------------------
	# Create socket
	#
	# Creates a TCP connection to the requested server
	#----------------------------------------------------------
	def create_socket
		# set socket dead to false
		@dead_socket = false

		# create our socket
		begin
			@socket = TCPSocket.new(@server, @port)
		rescue StandardError => e
			@dead_socket = true
			puts "[ERROR] Unable to create connection to #{@server}"
			puts "[ERROR] #{e.inspect}"
			raise
		end
	end

	#----------------------------------------------------------
	# Run the bot
	#----------------------------------------------------------
	def run
		# create a socket
		create_socket

		# ident
		@socket.puts "NICK #{@nick}"
		@socket.puts "USER #{@nick} 0 * :#{@real_name}"

		# start main loop
		main_loop
	end

	#----------------------------------------------------------
	# Main processing loop
	#----------------------------------------------------------
	def main_loop
		until @socket.eof do
			# get our data
			@raw = @socket.gets
			if @verbose
				puts "[RECV] #{@raw}"
			end

			# check for pings
			if @raw.match(/^PING :(.*)/)
				@socket.puts "PONG #{$~[1]}"
				if @verbose
					puts "PONG #{$~[1]}"
				end
				# we're done here, go to next loop iteration
				next
			end

			# we'll do more later, this is just to test our
			# connection before I start implementing the threads
		end
		@dead_socket = true

		run unless @reconnect == false
	end

	#----------------------------------------------------------
	# Missing Method
	#
	# Checks if method is prefixed with a term that the script
	# should ignore, and continues processing gracefully.
	# This is for methods that will vary from bot to bot
	# and won't necessarily all be there. Non-prefixed methods
	# will of course be handled normally, and will cause the
	# bot to crash if they are missing. This is necessary, as
	# if we don't treat them normally, certain tests will act
	# strangly. All elements with values of nil or false, will
	# return true. The call to super stops that from happening
	# and causes data to remain as expected.
	#----------------------------------------------------------
	def method_missing(meth, *args, &block)

		# missing data parser, we don't want to die on this one
		if meth =~ /^process_(.+)$/
			if @verbose
				puts "[WARN] No parsers #{@command} data defined"
			end

		# missing trigger case, we don't want to die on this one either
		elsif meth =~ /^on_(.+)$/
			if @verbose
				puts "[WARN] No triggers for #{@command} event defined"
			end

		# Everything else can go to hell!
		else
			super
		end
	end

end