jasonwupilly.com www.jasonwupilly.com

16Apr/120

Programming an IRC Chat Bot in C#

ircbotthumb

IRC, an abbreviated form of “Internet Relay Chat”, is a common chatting interface that is quite prominent throughout the internet. However, many of these channels are plagued by insufficient or inadequate moderation. To fix this, a site owner can either assign “human” moderators, who unfortunately must give up some of their time to control the chat room, or he/she can make an IRC Chat Moderation Bot.

To program this bot, I chose to use the Microsoft .NET language C# because of its relative simple syntax and vast number of functions built into the Microsoft .NET Framework. For this program I used Microsoft Visual C# 2010 and I compiled it to run on the .NET 4.0 Client Profile, although it could also theoretically run on .NET 3.5 or Mono (GTK+).

Basically some features I wanted my bot to have in this version are:

  1. Random greetings and farewells in different languages
  2. A “user” system where an IRC member can register and log-in to perform various actions on the bot
  3. An “operator Mode” where the bot can kick people for misbehaving in the IRC Channel.
  4. Bad language detection.
  5. Multithreading capability
  6. Spam Control (even if it’s basic)

Some things I plan to add for the next release are:

  1. Ability to integrate a PandoraBot (http://www.pandorabots.com/botmaster/en/home) and have the IRC bot use the PandoraBot to respond to user chats
  2. A special set of actions only an “owner” can make the bot perform (ex. remotely executing batch or python scripts – nothing compiled)
  3. A “!log” command that can allow the bot to record the IRC chat messages and store them in a file (perhaps using a GZip compressed .bin)
  4. Maybe a built-in calculator to perform basic math.

I won’t hide the fact that I obtained a good bit of this source code from jakash3’s Visual Basic IRC Chat client here: http://jakash3.wordpress.com/2010/02/28/vb-net-irc-client/

However, since I wanted to make my bot in C#, I needed to translate the Basic code into C# – which proved quite bothersome (especially with some of the Visual Basic constants and functions). I also tweaked a couple of things here and there.

I wanted to use many of the functions in this bot for future projects – so I created two separate DLLs with the majority of the functions on them. One of the DLLs is geared toward bot administration, while the other is more for chat interaction.

For the random multi-lingual greetings and farewells, I made a list of greetings, farewells, and their corresponding languages. I had the program automatically write them in order in a .bin file (using a symbol to separate them). Then, when the program started up, it used a streamreader to gather the information from the saved greetings/farewells and split the string using the delimiter symbol. Then, a function on the chat interaction DLL chose a random integer from 0 to the size of the greeting/farewell string array and displayed it – along with the corresponding language.

The user system was quite complicated. First, I had to find a way to allow the user to register with the bot. I tried a copious amount of times using an unregistered IRC nick name to privately talk to the bot, but it seemed the bot wasn’t receiving any of the messages. After about an hour of writing, and rewriting source code, it was brought to my attention that only registered users could send private chat messages. Basically, I then set up a system where if a user wanted to register, he/she would need to type “/msg <IRCBotName> <password they want to log in with>”. The bot would then create an md5 hash of the password and write the nickname and hashed password of the register-requested user in a .bin file. Then, when someone, who is already an approved user can type the command “!registerlist” which would display all the nicknames of the people who have requested registration. The approved user can use the command “!adduser <usertobeadded>”. This removes the person’s nick and hashed password from the “registers” .bin and moves them to the “user/password” .bin. Now, to login, a person would just need to message the IRC Chat Bot “!active <passwordchosen>”. By doing this, the bot adds them to an “.activeusers” file. Every time a person requests for the bot to perform an “approved-user” only action, the bot checks for the person’s nick in the “.activeusers” file. When a person logs out, his/her name is removed from the list.  The bot generates a blank active users file everytime it starts – so user sessions are ended if the bot disconnects. 

Making an “operator mode” was actually very simple – every time a new OPS is added to the channel, a “MODE” message is broadcast throughout the channel. All I had to do was make the bot look for its name in “MODE” messages. If it was there, they were either added or removed (+o and –o).

Once again, bad language detection was also easy to implement. The owner of the bot can add a file called “badlang.bin”. The program checks to see if the file exists; if it does, it splits the string inside using “:” as a delimiter. The resulting array is used to parse all “PRIVMSG “ messages received from the server. If a string in the array is detected to be in the message, the offender is either kicked or given a “warning” – depending on the bot’s operator status.

Multithreading is kind of self-explanatory. Basically, I imported “System.threading” and whenever I created a “void” that didn’t have SIGNIFICANT relation to other functions in the program, I put it on a new thread.

The Spam Control on this bot is quite primitive. Every time a “PRIVMSG” is received, the nick and message are temporarily stored along with a “counter” integer. When the update timer refreshes again, the bot checks for more “PRIVMSG” messages. If the new one is the same as the old one, the “counter” integer is increased by one. If the integer reaches a set number, the user is either kicked or warned – depending on the bot’s operator status.

NOW FOR THE SOURCE CODE

======MAIN CLASS======

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Security.Cryptography;
using ObsidianFunctions;
using FervorLibrary;

namespace Obsidian
{
    public partial class Form1 : Form
    {
        int port;
        string buf;
        string nick;
        string owner;
        string server;
        string channel;
        System.Net.Sockets.Socket sock;
        string mail;
        int greetnumber;
        string rmsg;
        int farewellnumber;
        string password;
        bool isregistered;
        string rnick;
        string old;
        bool isOperator;
        string ownernick;
        string oldmail;
        int spamcount;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            string IRCInfo = textBox1.Text + "|" + textBox2.Text + "|" + textBox3.Text + "|" + textBox4.Text + "|" + textBox6.Text;
            System.IO.StreamWriter IRCInfoWrite = new System.IO.StreamWriter("IRCInfo.bin");
            IRCInfoWrite.Write(IRCInfo);
            IRCInfoWrite.Close();
            port = Int32.Parse(textBox2.Text);
            server = textBox1.Text;
            channel = textBox3.Text;
            nick = textBox4.Text;
            password = textBox6.Text;
            owner = "Obsidian";
            System.Net.IPHostEntry ipHostInfo = System.Net.Dns.GetHostEntry(server);
            System.Net.IPEndPoint EP = new System.Net.IPEndPoint(ipHostInfo.AddressList[0], port);
            sock = new System.Net.Sockets.Socket(EP.Address.AddressFamily, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
            sock.Connect(server, port);
            send("NICK " + nick);
            send("USER " + nick + " 0 * :FervorBot");
            send("JOIN " + channel);
            send("MODE " + nick + " +B");;
            timer1.Enabled = true;
            timer2.Enabled = true;
            if (textBox6.Text != null)
            {
                timer3.Enabled = true;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            spamcount = 0;
            loadIRCInfo();
            isOperator = false;
            Thread configGreet = new Thread(GreetConfig);
            configGreet.Start();
            Thread configFarewell = new Thread(FarewellConfig);
            configFarewell.Start();
            if (System.IO.File.Exists("users.bin") == false | System.IO.File.Exists("passwords.bin") == false | System.IO.File.Exists("registers.bin") == false | System.IO.File.Exists(".activeusers") == false)
            {
                Thread configUser = new Thread(startUserList);
                configUser.Start();
            }
            StreamWriter sw = new StreamWriter(".activeusers");
            sw.Close();
            if (System.IO.File.Exists("owner.bin") == false)
            {
                ownerConfiguration();
            }
            else
            {
                setOwner();
            }
        }

        public void send(string msg)
        {
            msg += "\r\n";
            Byte[] data = System.Text.ASCIIEncoding.UTF8.GetBytes(msg);
            sock.Send(data, msg.Length, System.Net.Sockets.SocketFlags.None);
        }
        public string recv()
        {
            byte[] data = new byte[3072];
            sock.Receive(data, 3072, System.Net.Sockets.SocketFlags.None);
            string mail = System.Text.ASCIIEncoding.UTF8.GetString(data);
            if (mail.Contains(" "))
            {
                if (mail.Substring(0, 4) == "PING")
                {
                    string pserv = mail.Substring(mail.IndexOf(":"), mail.Length - mail.IndexOf(":"));
                    pserv = pserv.TrimEnd((char)0);
                    mail = "PING from " + pserv + "\r" + "PONG to " + pserv;
                    send("PONG " + pserv);
                }
                else if (mail.Substring(mail.IndexOf(" ") + 1, 7) == "PRIVMSG")
                {
                    string[] tmparr = null;
                    mail = mail.Remove(0, 1);
                    tmparr = mail.Split('!');
                    rnick = tmparr[0];
                    tmparr = mail.Split(':');
                    rmsg = tmparr[1];
                    if (rmsg.Contains("!respond") == true)
                    {
                        string response = "PRIVMSG " + textBox3.Text + " :Response";
                        send(response);
                    }
                    else if (rmsg.Contains("!greet "))
                    {
                        string query = rmsg.Remove(0, 7);
                        try
                        {
                            int queryindex = Int32.Parse(query);
                            if (queryindex <= greetnumber)
                            {
                                FervorLibrary.Library Greeting = new FervorLibrary.Library();
                                string returngreet = Greeting.greet(queryindex);

                                string response = "PRIVMSG " + channel + " :" + returngreet;
                                send(response);
                            }
                            else
                            {
                                send("PRIVMSG " + channel + " :I don't know that many languages!");
                            }
                        }
                        catch (Exception ex)
                        {
                            send("PRIVMSG " + channel + " :Something went wrong: " + ex);
                        }

                       
                    }
                    else if (rmsg.Contains("!farewell "))
                    {
                        string query = rmsg.Remove(0, 10);
                        try
                        {
                            int queryindex = Int32.Parse(query);
                            if (queryindex <= greetnumber)
                            {
                                FervorLibrary.Library Farewelling = new FervorLibrary.Library();
                                string returnfarewell = Farewelling.farewell(queryindex);
                                string response = "PRIVMSG " + channel + " :" + returnfarewell;
                                send(response);
                            }
                            else
                            {
                                send("PRIVMSG " + channel + " :I don't know that many languages!");
                            }
                        }
                        catch (Exception ex)
                        {
                            send("PRIVMSG " + channel + " :Something went wrong: " + ex);
                        }
                    }
                    else if (rmsg.Contains("!md5 "))
                    {
                        Thread md5calc = new Thread(generateMD5message);
                        md5calc.Start();
                    }
                    else if (rmsg.Contains("!register "))
                    {
                        Thread requestregistration = new Thread(reqreguser);
                        requestregistration.Start();
                    }
                    else if (rmsg.Contains("!registerlist"))
                    {
                        Thread listreg = new Thread(listregs);
                        listreg.Start();
                    }
                    else if (rmsg.Contains("!clearregisterlist"))
                    {
                        Thread clearreg = new Thread(clearregs);
                        clearreg.Start();
                    }
                    else if (rmsg.Contains("!active "))
                    {
                        Thread activate = new Thread(activateUser);
                        activate.Start();
                    }
                    else if (rmsg.Contains("!deactivate"))
                    {
                        Thread deactive = new Thread(deactivateUser);
                        deactive.Start();
                    }
                    else if (rmsg.Contains("!adduser "))
                    {
                        System.IO.StreamReader sr = new StreamReader(".activeusers");
                        string[] users = sr.ReadToEnd().Split(':');
                        sr.Close();
                        foreach (string x in users)
                        {
                            if (x.Contains(rnick))
                            {
                                string query = rmsg.Remove(0, 9);
                                ObsidianFunctions.Functions obsidfunc = new ObsidianFunctions.Functions();
                                string list = obsidfunc.addUser(query);
                                send("PRIVMSG " + channel + " :" + list);
                            }
                        }
                    }

                    else if (rmsg.Contains("!removeuser "))
                    {
                        System.IO.StreamReader sr = new StreamReader(".activeusers");
                        string[] users = sr.ReadToEnd().Split(':');
                        sr.Close();
                        foreach (string x in users)
                        {
                            if (x.Contains(rnick))
                            {
                                string query = rmsg.Remove(0, 12);
                                ObsidianFunctions.Functions obsidfunc = new ObsidianFunctions.Functions();
                                string list = obsidfunc.removeUser(query);
                                send("PRIVMSG " + channel + " :" + list);
                            }
                        }
                    }
                    else if (rmsg.Contains("!userlist"))
                    {
                        System.IO.StreamReader sr = new StreamReader(".activeusers");
                        string[] users = sr.ReadToEnd().Split(':');
                        sr.Close();
                        foreach (string x in users)
                        {
                            if (x.Contains(rnick))
                            {
                                StreamReader sr2 = new StreamReader("users.bin");
                                string currentusers = sr2.ReadToEnd();
                                sr2.Close();
                                send("PRIVMSG " + channel + " :" + currentusers);
                            }
                        }
                    }
                    else if (rmsg.Contains("!botquit"))
                    {
                        bool nickisuser = isActiveUser(rnick);
                        if (nickisuser == true)
                        {
                            send("QUIT");
                        }
                        else
                        {
                            send("PRIVMSG " + channel + " :Insufficient permissions!");
                        }
                    }
                    else if (rmsg.Contains("!addops "))
                    {
                        if (isOperator == true)
                        {
                            string query = rmsg.Remove(0, 8);
                            bool nickisuser = isActiveUser(rnick);
                            if (nickisuser == true)
                            {
                                send("MODE " + channel + " +o " + query);
                            }
                            else
                            {
                                send("PRIVMSG " + channel + " :Insufficient permissions!");
                            }
                        }
                    }
                    else if (rmsg.Contains("!removeops "))
                    {
                        if (isOperator == true)
                        {
                            string query = rmsg.Remove(0, 11);
                            bool nickisuser = isActiveUser(rnick);
                            if (nickisuser == true)
                            {
                                send("MODE " + channel + " -o " + query);
                            }
                            else
                            {
                                send("PRIVMSG " + channel + " :Insufficient permissions!");
                            }
                        }
                    }
                    else if (rmsg.Contains("!kick "))
                    {
                        if (isOperator == true)
                        {
                            string query = rmsg.Remove(0, 6);
                            bool nickuser = isActiveUser(rnick);
                            if (nickuser == true)
                            {
                                send("KICK " + channel + " " + query + " User-requested kick");
                            }
                            else
                            {
                                send("PRIVMSG " + channel + " :Insufficient permissions!");
                            }
                        }
                    }

                    detectLang();
                }
                else if (mail.Substring(mail.IndexOf(" ") + 1, 4) == "JOIN")
                {
                    string[] tmparr = null;
                    mail = mail.Remove(0, 1);
                    tmparr = mail.Split('!');
                    string rnick = tmparr[0];
                    FervorLibrary.Library Greetings = new FervorLibrary.Library();
                    Random rand = new Random();
                    int indexgreet = rand.Next(0, greetnumber);
                    string greeting = Greetings.Greeting(rnick, indexgreet);
                    string greetingmessage = "PRIVMSG " + textBox3.Text + " :" + greeting;
                    send(greetingmessage);
                }
                else if (mail.Substring(mail.IndexOf(" ") + 1, 4) == "PART" | mail.Substring(mail.IndexOf(" ") + 1, 4) == "QUIT")
                {
                    string[] tmparr = null;
                    mail = mail.Remove(0, 1);
                    tmparr = mail.Split('!');
                    string rnick = tmparr[0];
                    FervorLibrary.Library Farewells = new FervorLibrary.Library();
                    Random rand = new Random();
                    int indexfarewell = rand.Next(0, farewellnumber);
                    string farewell = Farewells.Farewell(rnick, indexfarewell);
                    string farewellmessage = "PRIVMSG " + textBox3.Text + " :" + farewell;
                    send(farewellmessage);
                    Thread deactive = new Thread(deactivateUser);
                    deactive.Start();
                }
                else if (mail.Substring(mail.IndexOf(" ") + 1, 4) == "MODE")
                {
                    mail = mail.Replace("\0", "").Trim();
                    int nameopslength = nick.Length + 3;
                    string action = mail.Substring(mail.Length - nameopslength);
                    if (action.StartsWith("+o") | action.StartsWith("+r"))
                    {
                        isOperator = true;
                        send("PRIVMSG " + channel + " :isOperator = true");

                    }
                    else if (action.StartsWith("-o") | action.StartsWith("-r"))
                    {
                        isOperator = false;
                        send("PRIVMSG " + channel + " :isOperator = false");
                    }

                }
            }
            return mail;
           
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Thread updateirc = new Thread(ircupdate);
            updateirc.Start();
        }
        public void GreetConfig()
        {
            if (System.IO.File.Exists("greet.bin") == false)
            {
                System.IO.StreamWriter greetwrite = new System.IO.StreamWriter("greet.bin");
                greetwrite.Write("Hallo,Ahalan,Ni Hao,Ahoj,Goddag,Goede dag,Hello,Bonjour,Guten Tag,Aloha,Shalom,Namaste,Dia dhuit,Ciao,Kon-nichiwa,Zdravstvuyte,Hola,Hej,Sawubona~");
                greetwrite.Write("Afrikaans,Arabic,Chinese,Czech,Danish,Dutch,English,French,German,Hawaiian,Hebrew,Hindi,Irish,Italian,Japanese,Russian,Spanish,Swedish,Zulu");
                greetwrite.Close();
                System.IO.StreamReader greetread = new System.IO.StreamReader("greet.bin");
                string greetraw = greetread.ReadToEnd();
                string[] split = greetraw.Split(',');
                greetnumber = split.Length / 2;
            }
            else if (System.IO.File.Exists("greet.bin") == true)
            {
                System.IO.StreamReader greetread = new System.IO.StreamReader("greet.bin");
                string greetraw = greetread.ReadToEnd();
                string[] split = greetraw.Split(',');
                greetnumber = split.Length / 2;
            }
        }
        public void FarewellConfig()
        {
            if (System.IO.File.Exists("farewell.bin") == false)
            {
                System.IO.StreamWriter farewellwrite = new System.IO.StreamWriter("farewell.bin");
                farewellwrite.Write("Tosiens,Ma'a as-salaama,Zai Jian,Sbohem,Farvel,Afscheid,Goodbye,Au revoir,Aurf Wiedersehen,Aloha,Kol Tuv,Ach-ha,Slan agat,Addio,Sayonara,Pa-ka,Adios,Adjo,Hamba kahle~");
                farewellwrite.Write("Afrikaans,Arabic,Chinese,Czech,Danish,Dutch,English,French,German,Hawaiian,Hebrew,Hindi,Irish,Italian,Japanese,Russian,Spanish,Swedish,Zulu");
                farewellwrite.Close();
                System.IO.StreamReader farewellread = new System.IO.StreamReader("farewell.bin");
                string farewellraw = farewellread.ReadToEnd();
                string[] split = farewellraw.Split(',');
                farewellnumber = split.Length / 2;
            }
            else if (System.IO.File.Exists("farewell.bin") == true)
            {
                System.IO.StreamReader farewellread = new System.IO.StreamReader("farewell.bin");
                string farewellraw = farewellread.ReadToEnd();
                string[] split = farewellraw.Split(',');
                farewellnumber = split.Length / 2;
            }
        }
        public void loadIRCInfo()
        {
            if (System.IO.File.Exists("IRCInfo.bin") == true)
            {
                System.IO.StreamReader IRCInfoRead = new System.IO.StreamReader("IRCInfo.bin");
                string IRCInfo = IRCInfoRead.ReadToEnd();
                string[] IRCInfoSplit = IRCInfo.Split('|');
                textBox1.Text = IRCInfoSplit[0];
                textBox2.Text = IRCInfoSplit[1];
                textBox3.Text = IRCInfoSplit[2];
                textBox4.Text = IRCInfoSplit[3];
                textBox6.Text = IRCInfoSplit[4];
                IRCInfoRead.Close();

            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            textBox5.Text = mail;
        }
        public void ircupdate()
        {
            mail = recv().Replace("\0", "").Trim();

            if (mail == oldmail)
            {
                spamcount++;
                if (spamcount >= 4)
                {
                    if (isOperator == true)
                    {
                        send("KICK " + channel + " " + rnick + " No Spamming or Repeating one's self");
                        spamcount = 0;
                    }
                    else
                    {
                        send("PRIVMSG " + channel + " :Try not to spam or excessively repeat yourself");
                        spamcount = 0;
                    }
                }
               
            }
            oldmail = mail;
        }
        public void generateMD5message()
        {
            string query = rmsg.Remove(0, 5);
            try
            {
                ObsidianFunctions.Functions ObsidFunc = new ObsidianFunctions.Functions();
                string md5encrypt = ObsidFunc.md5calc(query.ToString()).ToLower();
                string response = "PRIVMSG " + channel + " :" + md5encrypt;
                send(response);
            }
            catch (Exception ex)
            {
                send("PRIVMSG " + channel + " :Something went wrong: " + ex);
            }
        }
        public void startUserList()
        {
            StreamWriter sw1 = new StreamWriter("users.bin");
            sw1.Close();
            StreamWriter sw2 = new StreamWriter("passwords.bin");
            sw2.Close();
            StreamWriter sw3 = new StreamWriter("registers.bin");
            sw3.Write("|");
            sw3.Close();
            StreamWriter sw4 = new StreamWriter(".activeusers");
            sw4.Close();
        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            send("PRIVMSG " + "NickServ" + " :IDENTIFY " + textBox6.Text);
            isregistered = true;
            timer3.Enabled = false;
        }
        public void reqreguser()
        {
            string query = rmsg.Remove(0, 10);
            ObsidianFunctions.Functions requestreg = new ObsidianFunctions.Functions();
            string pass = requestreg.reqreguser(rnick, query);
            send("PRIVMSG " + rnick + " :You have been requested registration - user=" + rnick + " password=" + pass + " (hashed)");
        }
        public void listregs()
        {
            System.IO.StreamReader sr = new StreamReader(".activeusers");
            string[] users = sr.ReadToEnd().Split(':');
            sr.Close();
            foreach (string x in users)
            {
                if (x.Contains(rnick))
                {
                    StreamReader sr2 = new StreamReader("registers.bin");
                    string[] registered = sr2.ReadToEnd().Split('|');
                    string usernames = registered[0];
                    sr2.Close();
                   
                    send("PRIVMSG " + channel + " :" + usernames);
                   
                }
               
            }
        }
        public void clearregs()
        {
            System.IO.StreamReader sr = new StreamReader(".activeusers");
            string[] users = sr.ReadToEnd().Split(':');
            sr.Close();
            foreach (string x in users)
            {
                if (x.Contains(rnick))
                {
                    System.IO.File.Delete("registers.bin");
                    System.IO.StreamWriter sw = new StreamWriter("registers.bin");
                    sw.Write("|");
                    sw.Close();
                    send("PRIVMSG " + channel + " :Cleared!");
                }
               
            }
        }
        public void activateUser()
        {
            StreamReader sr2 = new StreamReader(".activeusers");
            old = sr2.ReadToEnd();
            sr2.Close();
            System.IO.StreamReader sr = new StreamReader("users.bin");
            string[] registeredusers = sr.ReadToEnd().Split(':');
            sr.Close();
            foreach (string x in registeredusers)
            {
                if (x.Contains(rnick))
                {
                    string query = rmsg.Remove(0, 8);
                    int indexuser = Array.IndexOf(registeredusers, rnick);
                    ObsidianFunctions.Functions obsidfunc = new ObsidianFunctions.Functions();
                    bool passcorrect = obsidfunc.isVerified(indexuser, query);
                    StreamWriter sw = new StreamWriter(".activeusers");
                    if (passcorrect == true)
                    {
                        sw.Write(old + rnick + ":");
                        send("PRIVMSG " + channel + " :Success! You are logged in!");
                    }
                   
                    sw.Close();
                }
            }
        }
        public void deactivateUser()
        {
            StreamReader sr = new StreamReader(".activeusers");
            string[] listofactiveusers = sr.ReadToEnd().Split(':');
            sr.Close();
            foreach (string x in listofactiveusers)
            {
                if (x.Contains(rnick))
                {
                    listofactiveusers = listofactiveusers.Where(val => val != rnick).ToArray();
                    string listuser = null;
                    foreach (string y in listofactiveusers)
                    {
                        listuser = listuser + y + ":";
                    }
                    StreamWriter sw = new StreamWriter(".activeusers");
                    sw.Write(listuser);
                    sw.Close();
                    send("PRIVMSG " + channel + " :User has been deactivated!");
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }
        public bool isActiveUser(string nickname)
        {
            StreamReader sr = new StreamReader(".activeusers");
            string[] listofactiveusers = sr.ReadToEnd().Split(':');
            sr.Close();
            bool userbool = false;
            foreach (string x in listofactiveusers)
            {
                if (x.Contains(nickname))
                {
                    userbool = true;
                }
            }
            return userbool;
        }
        public void ownerConfiguration()
        {
            ownerConfig form2 = new ownerConfig();
            form2.Show();
        }
        public void setOwner()
        {
            StreamReader sr = new StreamReader("owner.bin");
            ownernick = sr.ReadToEnd();

        }
        public void detectLang()
        {
            if (System.IO.File.Exists("badlang.bin") == true)
            {
                StreamReader sr = new StreamReader("badlang.bin");
                string[] badlist = sr.ReadToEnd().Split(':');
                foreach (string x in badlist)
                {
                    if (rmsg.Contains(x) == true)
                    {
                        if (isOperator == true)
                        {
                            send("KICK " + channel + " " + rnick + " No bad language allowed!");
                        }
                        else
                        {
                            send("PRIVMSG " + channel + " :" + rnick + ", I must request for you to change your word choice.");
                        }
                    }
                }
            }
        }
    }
}

 

======BOT ADMINISTRATION DLL======

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;

namespace ObsidianFunctions
{
    public class Functions
    {
        public string md5calc(string input)
        {
            input = input.Replace("\0", "").Trim();
            MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
            byte[] hash = md5.ComputeHash(inputBytes);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hash.Length; i++)
            {
                sb.Append(hash[i].ToString("X2"));
            }
            return sb.ToString().ToLower();
        }
        public string reqreguser(string nickname, string password)
        {
            nickname = nickname.Replace("\0", "").Trim();
            password = password.Replace("\0", "").Trim();
            System.IO.StreamReader sr = new System.IO.StreamReader("registers.bin");
            string[] old = sr.ReadToEnd().Split('|');
            sr.Close();
            string users = old[0];
            string pass = old[1];
            users = users + nickname + ":";
            pass = pass + md5calc(password) + ":";
            System.IO.StreamWriter sw = new System.IO.StreamWriter("registers.bin");
            sw.Write(users + "|" + pass);
            sw.Close();
            return md5calc(password);
        }
        public bool isVerified(int index, string password)
        {
            password = password.Replace("\0", "").Trim();
            password = md5calc(password);
            bool iscorrect;
            StreamReader sr = new StreamReader("passwords.bin");
            string[] allpass = sr.ReadToEnd().Split(':');
            sr.Close();
            string verifypass = allpass[index];
            if (verifypass == password)
            {
                iscorrect = true;
            }
            else
            {
                iscorrect = false;
            }
            return iscorrect;
        }
        public string addUser(string nickname)
        {
            nickname = nickname.Replace("\0", "").Trim();
            StreamReader sr = new StreamReader("registers.bin");
            string[] registereduserlist = sr.ReadToEnd().Split('|');
            string[] registeredusers = registereduserlist[0].Split(':');
            string[] registeredpasswords = registereduserlist[1].Split(':');
            sr.Close();
            StreamReader sru = new StreamReader("users.bin");
            StreamReader srp = new StreamReader("passwords.bin");
            string oldusers = sru.ReadToEnd();
            string oldpasswords = srp.ReadToEnd();
            sru.Close();
            srp.Close();
           
            foreach (string x in registeredusers)
            {
                if (x.Contains(nickname))
                {
                    int userregIndex = Array.IndexOf(registeredusers, nickname);
                    StreamWriter sw = new StreamWriter("users.bin");
                    sw.Write(oldusers + registeredusers[userregIndex] + ":");
                    StreamWriter sw2 = new StreamWriter("passwords.bin");
                    sw2.Write(oldpasswords + registeredpasswords[userregIndex] + ":");
                    sw.Close();
                    sw2.Close();
                    registeredusers = registeredusers.Where(val => val != nickname).ToArray();
                    registeredpasswords = registeredpasswords.Where(val => val != registeredpasswords[userregIndex]).ToArray();
                    string newuserlist = String.Join(":", registeredusers);
                    string newpasslist = string.Join(":", registeredpasswords);
                    StreamWriter newwrite = new StreamWriter("registers.bin");
                    newwrite.Write(newuserlist + "|" + newpasslist);
                    newwrite.Close();
                }

            }
            StreamReader sr3 = new StreamReader("users.bin");
            string newregusers = sr3.ReadToEnd();
            sr3.Close();
            return newregusers;
        }
        public string removeUser(string nickname)
        {
            nickname = nickname.Replace("\0", "").Trim();
            StreamReader sr = new StreamReader("users.bin");
            string[] userlist = sr.ReadToEnd().Split(':');
            sr.Close();
            StreamReader sr2 = new StreamReader("passwords.bin");
            string[] passwordlist = sr2.ReadToEnd().Split(':');
            sr2.Close();
            foreach (string x in userlist)
            {
                if (x.Contains(nickname))
                {
                    int userregIndex = Array.IndexOf(userlist, nickname);
                    userlist = userlist.Where(val => val != nickname).ToArray();
                    passwordlist = passwordlist.Where(val => val != passwordlist[userregIndex]).ToArray();
                    string newuserlist = String.Join(":", userlist);
                    string newpasslist = string.Join(":", passwordlist);
                    StreamWriter newsw1 = new StreamWriter("users.bin");
                    newsw1.Write(newuserlist);
                    newsw1.Close();
                    StreamWriter newsw2 = new StreamWriter("passwords.bin");
                    newsw2.Write(newpasslist);
                    newsw2.Close();
                   
                }
            }
            StreamReader newuserread = new StreamReader("users.bin");
            string updateuser = newuserread.ReadToEnd();
            newuserread.Close();
            return updateuser;
        }
       
    }
}

 

======CHAT INTERACTION DLL======

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FervorLibrary
{
    public class Library
    {
        public string Greeting(string name, int index)
        {
            System.IO.StreamReader greetreader = new System.IO.StreamReader("greet.bin");
            string[] list = greetreader.ReadToEnd().Split('~');
            string greetslist = list[0];
            string languageslist = list[1];
            string[] greets = greetslist.Split(',');
            string[] languages = languageslist.Split(',');

            int greetslength = greets.Length;
            int languageslength = languages.Length;
            string greetlang = greets[index] + " " + name + "! You learned how to greet in " + languages[index];
            return greetlang;

        }
        public string Farewell(string name, int index)
        {
            System.IO.StreamReader farewellreader = new System.IO.StreamReader("farewell.bin");
            string[] list = farewellreader.ReadToEnd().Split('~');
            string farewellslist = list[0];
            string languageslist = list[1];
            string[] farewells = farewellslist.Split(',');
            string[] languages = languageslist.Split(',');
            int farewellslength = farewells.Length;
            int languageslength = languages.Length;
            string farewelllang = farewells[index] + " " + name + "! You learned how to say goodbye in " + languages[index];
            return farewelllang;
        }
        public string greet(int index)
        {
           
                System.IO.StreamReader greetreader = new System.IO.StreamReader("greet.bin");
                string[] list = greetreader.ReadToEnd().Split('~');
                string greetslist = list[0];
                string languageslist = list[1];
                string[] greets = greetslist.Split(',');
                string[] languages = languageslist.Split(',');
              
                int greetslength = greets.Length;
                int languageslength = languages.Length;
                string greetlang = greets[index] + "! You learned how to greet in " + languages[index];
                return greetlang;
        }
        public string farewell(int index)
        {
            System.IO.StreamReader farewellreader = new System.IO.StreamReader("farewell.bin");
            string[] list = farewellreader.ReadToEnd().Split('~');
            string farewelllist = list[0];
            string languageslist = list[1];
            string[] farewells = farewelllist.Split(',');
            string[] languages = languageslist.Split(',');
            int farewellslist = farewells.Length;
            int languageslength = languages.Length;
            string farewelllang = farewells[index] + "! You learned how to say goodbye in " + languages[index];
            return farewelllang;
        }

    }
}

 

 

If you want a download, most of my projects can be found in my github repositories - https://github.com/jasonwupilly/Obsidian

6Mar/120

C# Multithreading Tutorial

CSharp

C# is a powerful language developed by Microsoft that utilizes the .NET framework. In this tutorial, I’ll be showing you how to allow a C# to utilize multiple threads.

 

C# Multithreading

 

Lets say you want to have a program that writes “1”, “2”, “3”, “4”, “5”, “6”, “7”, and “8” 20 times each in a Console Window not taking subsequence into account. If your program was single-threaded, you would have to first get the thread to write “1” 20 times, then proceed to writing “2”… etc. Not only is this inefficient, it is also time consuming. If this program was a multithread-enabled program, you could have 8 separate threads that each writes a different number. Then, you could start all 8 threads simultaneously and achieve the same result much more quickly.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace CSMultithreading
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("This is Multithreading in C#! \n");
            Console.Write("You have ");
            int NumberofCores = Environment.ProcessorCount;
            string CoreNumber = NumberofCores.ToString();
            Console.Write(CoreNumber);
            Console.Write(" Processor Threads in your System. \n");
            Console.Write("Enter how many threads you would like to utilize: \n");
            string threadresponse = Console.ReadLine();
            int howmanythreadstouse = Int32.Parse(threadresponse);
            Console.Write("Press Any Key to Continue: \n");
            Console.ReadKey();
            Thread one = new Thread(ThreadOne);
            Thread two = new Thread(ThreadTwo);
            Thread three = new Thread(ThreadThree);
            Thread four = new Thread(ThreadFour);
            Thread five = new Thread(ThreadFive);
            Thread six = new Thread(ThreadSix);
            Thread seven = new Thread(ThreadSeven);
            Thread eight = new Thread(ThreadEight);

            if (howmanythreadstouse >= 1)
            {
                one.Start();
            }
            if (howmanythreadstouse >= 2)
            {
                two.Start();
            }
            if (howmanythreadstouse >= 3)
            {
                three.Start();
            }
            if (howmanythreadstouse >= 4)
            {
                four.Start();
            }
            if (howmanythreadstouse >= 5)
            {
                five.Start();
            }
            if (howmanythreadstouse >= 6)
            {
                six.Start();
            }
            if (howmanythreadstouse >= 7)
            {
                seven.Start();
            }
            if (howmanythreadstouse >= 8)
            {
                eight.Start();
            }

            Console.ReadKey();

        }
        static void ThreadOne()
        {
            for (int i = 1; i < 20; i++)
            {
                Console.Write("1");
            }
        }
        static void ThreadTwo()
        {
            for (int i = 1; i < 20; i++)
            {
                Console.Write("2");
            }
        }
        static void ThreadThree()
        {
            for (int i = 1; i < 20; i++)
            {
                Console.Write("3");
            }
        }
        static void ThreadFour()
        {
            for (int i = 1; i < 20; i++)
            {
                Console.Write("4");
            }
        }
        static void ThreadFive()
        {
            for (int i = 1; i < 20; i++)
            {
                Console.Write("5");
            }
        }
        static void ThreadSix()
        {
            for (int i = 1; i < 20; i++)
            {
                Console.Write("6");
            }
        }
        static void ThreadSeven()
        {
            for (int i = 1; i < 20; i++)
            {
                Console.Write("7");
            }
        }
        static void ThreadEight()
        {
            for (int i = 1; i < 20; i++)
            {
                Console.Write("8");
            }
        }

    }
}

Here's the gitHub link:

https://github.com/jasonwupilly/CSharpMultithreadingTutorialFiles

14Feb/120

Visual Basic .NET–Remote Command Prompt Utility

In this tutorial, I’ll be showing  you how to remotely send command prompt commands for your computer to execute from any internet-connected device.

First, it would be beneficial to explain how this program works. I personally do not know of a way in which a program can make a remote, direct connection to a client PC using the .NET Framework. So, in order to get a computer to remotely “send messages” to another PC, the only way I could think of is to get the “commanding PC” to write to an online text file (via PHP), then have another program installed on the client PC that checks a specified online text file every 30 seconds. If there IS a command, the program will download the string, write it to a batch file and execute it.

 

This is demonstrated in my crudely drawn “Paint” diagram which clearly needs better antialiasing -

diagramklinkhammer

 

The first step would be to download the coding software to use for this project. I like to program in Microsoft Visual Basic .NET. This language, as the name implies, requires the PC the program is installed on to have the Microsoft .NET Framework installed (http://www.microsoft.com/download/en/details.aspx?id=17851).

To write code that utilizes this framework, download Microsoft Visual Studio:

Express is free (all you need for this project) - http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express

Other version provide more features that are not relevant for this project - http://www.microsoft.com/visualstudio/en-us/products/2010-editions

There are two parts to this program – the command sender the command receiver

COMMAND SENDER

  1. Download Visual Studio 2010 and the .NET Framework (I believe .NET framework is automatically installed with Visual Studio) http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express
  2. Open Microsoft Visual Basic Express 2010
  3. Click File –> New Project
  4. Name the Project whatever you want… make sure it is a Windows Form Application
  5. You should see a blank Windows Application Form
  6. Add 3 Textboxes and make the last textbox a multi-line textbox. The first textbox is where the user will enter the “post.php” URL, the second textbox will be the “clear.php” URL, and the third textbox will contains the commands to send.
  7. Optionally, you can add labels to clearly identify the purpose of each textbox.
  8. Add 2 buttons to the Windows Form.
  9. Name the first button “Submit” and name the second button “Clear Queue”khgpic
  10. Double click on “Submit”
  11. You should see a new "tab” opening up containing all the code for the application.
  12. On the top of the code window, you should see “Public Class Form1”
  13. Before, that type “Imports System.Net”
  14. Below “Public Class Form1”, you should see “Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click”
  15. Immediately below that, type “Dim request as WebRequest = WebRequest.Create(TextBox1.Text & TextBox2.Text)”
  16. On the next line, type “request.GetResponse()
  17. On the line after that, type “TextBox2.Text = Nothing”
  18. Go back to your “Designer” tab and double-click the “Clear Queue” button
  19. You should now see your code tab pop up again with a new line of code: “Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click”
  20. Immediately after that, type “Dim request As WebRequest = WebRequest.Create(TextBox3.Text)
  21. Below that: “request.GetResponse()”
  22. Below that: “TextBox2.Text = Nothing”
  23. Press “F5” on your keyboard to compile
  24. You’re done!

Source Code:


COMMAND RECEIVER

This part of the program is a little more complicated…

  1. If you do not already have VB.NET, download it here: http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express
  2. Open Visual Basic Express
  3. Create a new Windows Forms Application Project; you can name this whatever.
  4. First, create two textboxes – make the second one multi-line
  5. Next, create a button. Name it “Save Info”
  6. Drag a “timer” from the toolbox on your left hand side into the Form. Set it Enabled = False and Interval = 30000
  7. In the multiline textbox, type: vbs
  8. Copy+Paste the code found here (I could explain it step-by-step but they would be meaningless and take forever): http://pastie.org/3239401
  9. Basically, when the application loads, it checks to see if a file called “url.txt” exists (containing the URL address of the web server). If it does, the application stays hidden. If not, the application shows itself for the user to enter the information.
  10. If url.txt exists, the application starts a timer that checks the web address specified in url.txt every 30 seconds. It downloads the string and executes them.

khspic

PHP FILES

These are the files you need to upload on your webserver for this program to work:

clear.php

<?php
file_put_contents("command.txt", "");
?>

 

post.php

 

<?php
$msg = $_GET['w'];
$logfile= 'data.txt';
$fp = fopen($logfile, "a");
fwrite($fp, $msg);
fclose($fp);
?>

 

Create an empy text file named “command.txt”

 

 

 

 

download a pre-compiled copy of Klink Hammer here:

http://bit.ly/AAYMGD

18Sep/110

Windows 8 – Screenshot Gallery

I just got my hands on a Developer Preview .iso for Windows 8. I installed it on one of the many drives in my PC (a 5400RPM 640GB).

 

 

 

7Sep/110

Programming Tutorial: Creating a Simple Console Calculator using the C/C++ Programming Language

C++ is one of the many derivatives of the C programming language. Just like the Ubuntu Linux operating system, each "variant" of the original programming language or operating shares many characteristics and similarities with its "parent."

In this tutorial, I'm going to show you how to create your very own C/C++ calculator that can do basic functions such as adding, subtracting, multiplying, dividing, and exponents.

Be aware that this is a really quick run-through guide on the C/C++ programming language.

To start off, you'll need a C/C++ compiler. The purpose of a compiler is to create an executable that will launch and contain our calculator program. Since C++ is a derivative of C, any C++ compiler can understand anything from C, but not vice versa. My compiler of choice is the bloodshed.net dev C++ compiler, because it is easy to use, portable, open-source, and free. You can find and download it here: http://www.bloodshed.net/devcpp.html

To download, just click on the link and click "Go to download page" next to the "Download:". I would recommend downloading a stable version, as the beta version of any software most likely contains bugs. Since the bloodshed.net dev compiler is published under the GNU license, you can download it for free and modify its source code in any way (it's written in Delphi).

You should have downloaded an installer, go through the installer and just install everything that the installer program is trying to install (check all of the boxes). When the installer program is through installing the C++ compiler, open it up by clicking the "devcpp.exe" application. In the upper-left hand corner of your screen, click "File", "New", the "Project." Click "Console Application," give your project a name, and choose where your want to save it. I recommend creating a folder dedicated for this project, as things might get disorganized otherwise.

Right now you should see:

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    system("PAUSE");
    return EXIT_SUCCESS;
}

change "#include <cstdlib>" to "#include <conio.h>". Then, add "#include <math.h>" under "#include <iostream>, change "system("PAUSE");" to "getch();" and you should end up with something like:

#include <conio.h>
#include <iostream>
#include <math.h>
using namespace std;

int main(int argc, char *argv[])
{

    getch();
    return EXIT_SUCCESS;
}

The first thing to learn about C++ is variables. In math, variables refer to values that can change. Constants refer to values that stay constant (hence the name). In the C++ programming language, variables and constants are much the same as they are in math. You can change the value of a variable throughout the course of a program, and the number 4, a constant, will always equal 4, no matter what. There are 3 types of variables: integers, floating points, and characters. Integers are basically whole numbers that can be negative or positive. Examples of integers are 1, -5, 70, and 3. Floating points are basically decimals in math. Like integers, they can be both positive and negative. Since they are always decimals, even a whole number answer, like 3-9, would be expressed as -6.00000000. Examples of floating points include 11.5, 31.3, 25.2, and 1.0000. Characters are basically letters and symbols. Here are some examples: y,x,n,i,e,+,=,s,and ^. In C and C++, integers are abbreviated as "int", characters are abbreviated as "char", and floating points are abbreviated as "float". To declare the value of a variable, you basically put the abbreviation of the variable, =, a value, then a semicolon (ALWAYS REMEMBER TO PUT A SEMICOLON AFTER EVERY STATEMENT IN C AND C++). You can also declare variables to equal other variables. Examples of declaring integers:

int x;
int y;
x = 3;
y = x;
float pi;
pi = 3.1415926535897932384;
char letter;
letter = 'x';

In the first line, I declared that there was an integer variable named "x". In the second line, I declared that there was another integer variable named "y". In the 3rd line, I said that the value of x was equal to 3. In the fourth line, I told the computer that the value of y was equal to the value of x, so the value of y is also 3. Next, I said that there was a floating point variable named "pi". I set its value to 3.1415926535897932384 in the 6th line. Here's where it gets a little tricky. In the seventh line I made a new character variable called "letter"; then, I said that the value of "letter" would be the LETTER x, not the variable. To declare the value of a character variable to a letter constant, be sure to put '   ' around the letter to differentiate between a constant and a variable. The next thing to learn in C would the the "printf" command. All this command does is to tell the computer to display a line of text. To use this command, type: printf("ENTER TEXT HERE"); Example:

printf("The cake is a lie!");

If you typed "printf("The cake is a lie!");" twice, the program would display them on the same line. To tell the program to skip a line, type "\n".   OK, so right now, you should have these lines of code:

#include <conio.h>
#include <iostream>
#include <math.h>
using namespace std;

int main(int argc, char *argv[])
{

    getch();
    return EXIT_SUCCESS;
}

The first thing you want to add in a program is a welcome message. Using the printf(); function, we can do this. Before "getch();" type: printf("Welcome to the Calculator Password Program! \n");

Since our program is going to have a password, you can go ahead and type: printf("Please enter your password:");

even though we'll come back at the end to add password functionality.

Right now, you should have:

#include <conio.h>
#include <iostream>
#include <math.h>
using namespace std;

int main(int argc, char *argv[]) { printf("Welcome to the Calculator Password Program! \n"); printf("Please enter your password:"); getch(); return EXIT_SUCCESS; }

Before the welcome message, create 3 new floating points. I'm going to name one of them "firstnumber", the second number "secondnumber "secondnumber", and the third number "answer". Basically, what we're going to have the user do is input the first and the second number with and an operation, then the calculator program will display the answer as "answer." Now, make a new character variable for the operation that the use will define. Name this "operation."

 

You should have this:

#include <conio.h>
#include <iostream>
#include <math.h>
using namespace std;

int main(int argc, char *argv[])
{
    float firstnumber;
    float secondnumber;
    float answer;
    char operation;

    printf("Welcome to the Calculator Password Program! \n");
    printf("Please enter your password:");

    getch();
    return EXIT_SUCCESS;
}

The next step in the program is asking the user to input the value of "firstnumber" and "secondnumber". To do that, type: scanf(", then type %f if you want the user to input the value of an integer, %f if you want the user to input the value of a floating point, and %c if you want the user to input a value of a character. Then close the quotes, put a comma and a space, then type & followed by the name of the variable you want the user to input. Confused? An example might help:

#include <conio.h>
#include <iostream>
#include <math.h>
using namespace std;

int main(int argc, char *argv[])
{
    float firstnumber;
    float secondnumber;
    float answer;
    char operation;

    printf("Welcome to the Calculator Password Program! \n");
    printf("Please enter your password:");

    scanf("%f", &firstnumber);

    getch();
    return EXIT_SUCCESS;
}

So, whatever the user enters now becomes to value of the variable "firstnumber". We're going to ask for the value of three variables in the same line of code. It should look like:

scanf("%f%c%f", &firstnumber, &operation, &secondnumber);

The next thing to learn is the "if" statement. The syntax of the "if" statement is:

if (variable == variable/constant) { What you want to happen if the variable is equal to another variable or constant }

You can actually have any condition (doesn't have to be an "equal to" condition), but I'm not going to cover all of that in this tutorial. "==" means equal in a condition, and "!=" means not equal to in a condition. We're going to make 6 different if statements:

#include <conio.h>
#include <iostream>
#include <math.h>
using namespace std;

int main(int argc, char *argv[])
{
    float firstnumber;
    float secondnumber;
    float answer;
    char operation;

    printf("Welcome to the Calculator Password Program! \n");
    printf("Please enter your password:");

    scanf("%f%c%f", &firstnumber, &operation, &secondnumber);

    if (operation == '+')
    {
                  answer = firstnumber + secondnumber;
                  printf("%f", answer);
                  }

    if (operation == '-')
    {
                  answer = firstnumber - secondnumber;
                  printf("%f", answer);
                  }
    if (operation == '*')
    {
                  answer = firstnumber * secondnumber;
                  printf("%f", answer);
                  }

    if (operation == 'x')
    {
                  answer = firstnumber * secondnumber;
                  printf("%f", answer);
                  }
    if (operation == '/')
    {
                  answer = firstnumber / secondnumber;
                  printf("%f", answer);
                  }

    if (operation == '^')
    {
                  answer = pow(firstnumber, secondnumber);
                  printf("%f", answer);
                  }

    getch();
    return EXIT_SUCCESS;
}

To display the answer, use the %f function the same way you would in a scanf function in a printf function, but don't but don't put a & in front of the variable you want to display. The 6th function uses the "pow" function, which can only be found in <math.h> Finally, we need to add a password. Create a new integer called "password", and make a scanf function for the password after the "printf("Please enter your password:");" line of code.

#include <conio.h>
#include <iostream>
#include <math.h>
using namespace std;

int main(int argc, char *argv[])
{
    float firstnumber;
    float secondnumber;
    float answer;
    char operation;
    int password;

    printf("Welcome to the Calculator Password Program! \n");
    printf("Please enter your password:");
    scanf("%i", &password);

    scanf("%f%c%f", &firstnumber, &operation, &secondnumber);

    if (operation == '+')
    {
                  answer = firstnumber + secondnumber;
                  printf("%f", answer);
                  }

    if (operation == '-')
    {
                  answer = firstnumber - secondnumber;
                  printf("%f", answer);
                  }
    if (operation == '*')
    {
                  answer = firstnumber * secondnumber;
                  printf("%f", answer);
                  }

    if (operation == 'x')
    {
                  answer = firstnumber * secondnumber;
                  printf("%f", answer);
                  }
    if (operation == '/')
    {
                  answer = firstnumber / secondnumber;
                  printf("%f", answer);
                  }

    if (operation == '^')
    {
                  answer = pow(firstnumber, secondnumber);
                  printf("%f", answer);
                  }

    getch();
    return EXIT_SUCCESS;
}

Now, we're going to make one GIANT if statement. Type:

if (password == 123456789)

{

(or whatever you want your password to be, has to be a number) in front of scanf("%f%c%f", &firstnumber, &operation, &secondnumber);

Then, place a closing bracket after the closing bracket of the last operation.

It should look like this:

#include <conio.h>
#include <iostream>
#include <math.h>
using namespace std;

int main(int argc, char *argv[])
{
    float firstnumber;
    float secondnumber;
    float answer;
    char operation;
    int password;

    printf("Welcome to the Calculator Password Program! \n");
    printf("Please enter your password:");
    scanf("%i", &password);
    if (password == 123456789)
    {

    scanf("%f%c%f", &firstnumber, &operation, &secondnumber);

    if (operation == '+')
    {
                  answer = firstnumber + secondnumber;
                  printf("%f", answer);
                  }

    if (operation == '-')
    {
                  answer = firstnumber - secondnumber;
                  printf("%f", answer);
                  }
    if (operation == '*')
    {
                  answer = firstnumber * secondnumber;
                  printf("%f", answer);
                  }

    if (operation == 'x')
    {
                  answer = firstnumber * secondnumber;
                  printf("%f", answer);
                  }
    if (operation == '/')
    {
                  answer = firstnumber / secondnumber;
                  printf("%f", answer);
                  }

    if (operation == '^')
    {
                  answer = pow(firstnumber, secondnumber);
                  printf("%f", answer);
                  }
}

    getch();
    return EXIT_SUCCESS;
}

Now, make another if statement for what happens if the user entered a password that was incorrect.

type:

if (password != 123456789)

{

printf("Sorry your password was incorrect");

}

Now you're done with your calculator password program! Your code should look something like this:

#include <conio.h>
#include <iostream>
#include <math.h>
using namespace std;

int main(int argc, char *argv[])
{
    float firstnumber;
    float secondnumber;
    float answer;
    char operation;
    int password;

    printf("Welcome to the Calculator Password Program! \n");
    printf("Please enter your password:");
    scanf("%i", &password);
    if (password == 123456789)
    {

    scanf("%f%c%f", &firstnumber, &operation, &secondnumber);

    if (operation == '+')
    {
                  answer = firstnumber + secondnumber;
                  printf("%f", answer);
                  }

    if (operation == '-')
    {
                  answer = firstnumber - secondnumber;
                  printf("%f", answer);
                  }
    if (operation == '*')
    {
                  answer = firstnumber * secondnumber;
                  printf("%f", answer);
                  }

    if (operation == 'x')
    {
                  answer = firstnumber * secondnumber;
                  printf("%f", answer);
                  }
    if (operation == '/')
    {
                  answer = firstnumber / secondnumber;
                  printf("%f", answer);
                  }

    if (operation == '^')
    {
                  answer = pow(firstnumber, secondnumber);
                  printf("%f", answer);
                  }
}
   if (password != 123456789)
   {
                printf("Sorry, the password you've entered is incorrect!");
                }
    getch();
    return EXIT_SUCCESS;
}

 

Press F9 to compile and run your script and you're all done!

 

Here's a video:

3Aug/11Off

Nvidia’s Sweetspot GPU – Nvidia Geforce GTX 460 1GB Review

Packed with 1GB of GDDR5 VRAM, 336 CUDA cores, and a powerful GF104 GPU, the Nvidia Geforce GTX 460 hits a home-run when it comes to performance/price. The GTX 460 was released in early July of 2010 as a successor to their GTX 465 GPU launch. The GTX 465 was Nvidia's first attempt at a sub-$300 Fermi GPU; however, being based on a "cut-down" GF100, it had the power draw of a GTX 470 but was out-performed by the Radeon 5850.

The Geforce GTX 460 was released to fix that. The GF104 GPU is the second member of Nvidia's family of Fermi GPUs. The GTX 460 launched with two variants - the GTX 460 1GB and the GTX 460 768MB. Despite using the same GPU, the 1GB card and its 768MB variant have 2 main differences. For one, the GTX 460 768MB doesn't need a 256-bit memory bus, so Nvidia outfitted the GPU with a 192-bit bus instead. Also, the GTX 460 1GB has 32 ROPs while the GTX 460 768MB only has 24.

With both variants of the GTX 460 sitting in the $200 price range, AMD's only competitor, the Radeon HD 5830, sits at $200, it will become the main competitor for the GTX 460 768MB version.

As a result of AMD's $80-$100 price gap between the 5830 and the 5850, there has been some price drops for the 5xxx series cards.

 

Now for the test:

I'll be running Futuremark's 3DMark 11 in the "Performance" preset, Furmark 1.8, 3DMark Vantage, Cinebench's OpenGL benchmark, Modern Warfare 2, Heaven DX11, and just for fun, Half-Life 2: Lost Coast's GPU benchmark.

First up, 3DMark 11. This benchmark is pretty straight-forward - set your preset and click "run." I was running 3DMark 11 on the "performance" preset (that means it'll be running at 1280x720), and got a score of P3366: with a graphics score of 3018, physics score of 8556, and combined score of 3227.

For Furmark, I used the highest possible settings at 1080p. I did this benchmark time-based for a total of 60000ms (60 seconds/1minute). After the benchmark, I got a score of 2351 points (mininum FPS was 33, max was 58, average was 39) and my GPU Temp reached 78C.

For both 3DMark 11 and this next benchmark, 3DMark Vantage, I used an Intel i7-2600K 3.4GHz CPU, so there shouldn't be any bottlenecking. Also, I did NOT run this test with a Z68 motherboard, so I didn't have Quick Sync or Virtu enabled.

3DMark Vantage is an older GPU benchmarking test that uses DX10, so although this benchmark doesn't test the tessellation abilities of the GTX 460, it gives you a good idea of how well this card can perform in older titles.

As you can see, I got a total score of 14631, a CPU score of 23760, and a GPU score of 12970. In both GPU tests, the GTX 460 maintained a healthy 38-40 fps average (39.23 for the first test, 38.71 for the second).

Up next, Cinebench 11.5. The graphics test in this benchmarks is similar to that of Furmark, as they both use OpenGL. The GTX 460 received a score of 54.01 as an average framerate.

 

For the next few benchmarks, I decided to run the benchmark once with the GTX 460 1GB at stock clocks and once overclocked. I used my favorite overclocking utility (MSI Afterburner) and settled for an 808Mhz core clock, 1616Mhz shader clock, and 1800Mhz memory clock (I decided to leave that untouched.)

This next benchmark isn't really a benchmark at all... it's actually Call of Duty: Modern Warfare 2, a title that was released around two years ago. Despite not being an incredibly graphically-demanding game, I chose it because it is easy to get reproducible results.

Stock clocks:

Overclocked:


Unlike Crysis Warhead or Mafia 2, Modern Warfare 2 doesn't have a built-in benchmarking features, so I had to use Fraps' benchmarking tool. Basically, what this tool does is take the mininum framerate, the maximum framerate, and the average framerate over the course of one minute (time is adjustable). I used the first level, "team player", because there isn't a lot of movement at the beginning of the level and there are a lot of explosions and water effects.

As you can tell from the graph, an overclock of 133MHz yields an increase (for average framerate) of 7.333 frames per second. Interestingly, the GTX 460 at stock clocks achieved higher minimum framerates AND maximum framerates than the GTX 460 did when it was overclocked.

Next benchmark: Heaven 2.5. I decided to run this benchmark because none of the other tests tested the DX 11 abilities (like tessellation) of the GTX 460. Once againn, I decided to run this once at stock clocks and once with the GTX 460 overclocked. This time I decided to combine both the stock clocked run and the overclocked run into one video.

I ran Heaven with DX11 enabled, 3D disabled, shaders at high, tessellation at normal, Anisotropy at 4, and AA at 8x. At stock clocks, i got an average FPS of 18.7 (minimum 6.1, max 39.7), which resulted in a score of 470 points. In the overclocked run, (once again 808 MHz core, 1616 shader, 1800 memory), there was a 2.2 FPS increase for the average framerate (minum 6.7, maximum 46.4) and the score also increased by 46 points (526 points).

In all honesty, the final benchmark, the Half-life 2 Lost Coast Video Stress Test was not meant to measure the performance of the GTX 460.
Stock Clocked:

Overclocked:


For the Half-Life 2 Video stress test, I maxxed out all the settings, but did NOT enable AA because I forgot to do so on the first run, so I didn't want to change any variables. I also turned color correction OFF because I was getting some weird colors (purple, green, blue) when I ran it with Color correction on. I ended up getting 260.14 fps at stock GTX 460 clocks and 262.33 fps with the 808MHz overclock. I don't think that OC'ing will improve your score by much in a DIRECT X 9.0 VIDEO "stress" TEST. The reason I put quotation marks around stress was because if your "GTX" GPU doesn't get a framerate of over 200, something is wrong. That is why in the test, I questioned my results when I got a "59.88 fps" the first time I ran the test (I think Fraps was capping the framerate) and decided to rerun the test.

 

 

 

 

So, in summary, the GTX 460 was, and still is, the "sweet-spot" GPU for Nvidia. While the newer 500 series Fermi cards are better performers, they remain pricey compared to their 400 series counterparts. With support for all of Nvidia's main technologies (3D vision, SLI, PhsX, and CUDA), the GTX 460 provides a sweet package that is "DirectX 11 Done Right."

 

 

 

 

 

31Jul/111

CoolerMaster Hyper 212 Plus Review – The Universal Socket Value Overclocking CPU Cooler

Outfitted with a low-noise 120mm fan, direct contact copper heat-pipes, and a rifle style form factor, the CoolerMaster Hyper 212 Plus offers features traditionally found in higher-end CPU coolers at an appealing price point.

One of the reasons why CoolerMaster's Hyper 212 Plus CPU cooler is so popular is that it supports almost every desktop socket in existence. That way, owners of 775, 1155, 1156, 1366, AM2, AM2+, and AM3 processors can enjoy the same amazing cooling the Hyper 212+ can offer. The reason the Hyper 212+ is able to support all these different sockets is the innovative back-plate design.

Despite it's innovative "universal" design, it was really annoying to install!

I have this cooler installed on my Intel Core i7-2600K processor so I had to install this with the "shiny" side facing towards the back of the motherboard. AMD users flip the backplate and install it with the shiny side facing the cover of their case.

When I got this cooler, I was upgrading from the stock Intel low-profile cooler that came with my i7-2600K.

How's this for size comparison?

I saw SIGNIFICANT temperature drops when I installed the new cooler. That makes sense considering the 212+ has 4 Direct contact heat-pipes compared to Intel's tiny copper slug that doesn't even completely cover the die.

One of the awesome features about this cooler is that it is upgradeable. Although the quiet 600-2000 RPM 12 cm fan provides plenty of airflow for an Intel chip running at stock speeds, I didn't think it would be enough to keep an i7-2600K running at 4.4 GHz under 65C.

I installed a Kingwin 120mm fan in a "push-pull" configuration with the Coolermaster fan.

Installation was quite simple, especially with the fan retention clips that CoolerMaster was nice enough to include in this package.

If you don't know how to install, take the screws that CAME WITH YOUR EXTRA FAN and use them to attach the retention clips to the top and bottom of the 120mm fan. Then, just snap on the "modified fan" onto the other side of your heat-sink.

I booted up into Windows 7 and fired up Prime 95 and Core Temp. I ran the test for 3 minutes, and my highest temperature was only 56C. Even though the load temperature is more than double the idle temperature (25C) it is still a VERY acceptable temperature considering that Prime 95 is one of the most stressful CPU and RAM tests.

Next, I decided to OC my i7-2600K 1GHz to 4.4 GHz. This time around, I decided to test my CPU temperatures with Cinebench too, just for good measure.

Temperatures, yet again, were very impressive. Core Temp showed 25C with 0% load, same as non-overclocked. When I ran Cinebench, the temperature maxxed out at 59C, which is very acceptable for a 1GHz overclock. When I did a Prime 95 Torture Test, however, the temperature reached 62C. I consider any temperature below 60C a "safe" temperature for CPU's. Although the 62C temperature was out of my comfort zone, I felt it was a very good temperature for a 4.4 GHz OC on an i7-2600K chip.

 

In conclusion, the Hyper 212+ is a great cooler for the money. As a result, it is one of the most popular overclocking CPU coolers. Whether you're looking for value, performance, or upgradeability, the CoolerMaster Hyper 212+ is a great CPU cooler.

 

 

 

30Jul/113

AMD’s Thuban Hexa-cores – Phenom II x6 1100T Black Edition Review

How's the dark lighting for the "Black Edition" processor?

The AMD Phenom II x6 line of processors was originally released in April of 2010 as a response to the 6-core Intel Gulftown processor, the i7-980X Extreme Edition CPU, released a month earlier. While these AMD flagship Thuban CPUs don't deliver the same performance as their Intel Gulftown counterparts, they bring hexa-core processing to a whole new price point.

AMD Thuban CPUs are basically hexa-core processors manufactured on a 45nm process, so even though they ARE 6-core processors like the i7-970 or the i7-980X, they won't deliver nearly the same amount of performance. The AMD's 1055T, 1090T, and 1100T are aimed at Intel's  Lynnfield and Bloomfield CPUs (i5-760, i7-860, i7-920, and i7-960). Since they are both built on the older 45nm process and are priced about the same, AMD's Thuban Hexa-cores seem to offer a better value.

To compete with Lynnfield's Intel Turboboost technology, AMD had to come up with its own version of it: AMD Turbo Core (the "T" at the end of 1100T stands for Turbo). Essentially both the technologies address the same issue - optimizing quad-cores or hexa-cores to run single or dual-threaded apps.

Here's how it works (here's a cool guide that shows you what I'm talking about: http://www.anandtech.com/show/3674/amds-sixcore-phenom-ii-x6-1090t-1055t-reviewed/2 )

If you had a Phenom 1100T with only 1 core and drew 125W, then that one core could get pretty high clock speeds (let's say 4GHz) because it doesn't need to share any of that power with other cores.

On the other hand, if you had a dual-core CPU, each of the cores could only get 72.5W of power because it needs to evenly share the 125W of power with the other core. Since you have less power flowing to each core, you have to down-clock the core to a lower clock speed, like 3.8 GHz.

The AMD Phenom II x6 1100T has SIX cores. Let's do the math:

125W / 6 cores = 20.833333W

That means that each core only gets a little over 20W of power. As a result, each core must be clocked much lower than what a processor using only one core would need to be clocked at. In this case, the 1100T has 6 cores each clocked at 3.3 GHz, which brings me to why we need Turbo boost/Turbo Core.

Most apps (browsers, Microsoft Word, even some games) only utilize one or two cores. Since the 1100T has 6 cores clocked at 3.3 GHz, the application you're running can only get up to 6.6 GHz of processing power total (3.3GHz x 2), whereas if you used an i5-680 dual-core processor, which has 2 cores each clocked at 3.6 GHz, the application could get up to 7.2 GHz of total processing power (3.6 GHz x 2).

Here's where Intel Turboboost technology and AMD Turbo core come in. With Turbo technology, the CPU can essentially "shut off" 3 cores (they aren't really off, they are actually idle) and divert the power to the three active cores, increasing clock speed and performance in the process.

Let's go back to our "application" scenario. With Turbo core, the Phenom can "turn off" 3 of it's cores, so that the 125W only needs to be split between the 3 remaining cores.

125W / 3 cores = 41.666666W

Since each core can get nearly DOUBLE the wattage it could when Turbo mode was off, three of the remaining cores could each achieve clock speeds of up to 3.7 GHz, so in this "application scenario," you could get up to 7.4 GHz of processing power.

Not ALL applications only use 1 or 2 cores. Some intensive games can take up to 4 threads while video rendering and some archiving software can take up to 8 (Sony Vegas Pro and 7-zip). More cores/threads are also preferred by most multi-threaded benchmarks, like Cinebench, because they are typically heavily threaded workloads on your CPU that are sure to make all of your cores run at 100% load.

Speaking of benchmarks, more importantly, speaking of Cinebench, here is our first performance benchmark for the Phenom II x6 1100T : Cinebench 11.5!

Despite the i7-960 having 8 threads versus the Phenom's 6 threads, the Phenom II x6 1100T still beats the i7 by a 0.3 point margin, which, in this case, is a clear advantage the 1100T has over the 960.

As you can see, I also measured temperatures in this video, and I must say compared to the Intel stock cooler it includes with it's Sandy Bridge processors, the AMD stock cooler is rather amazing.

AMD's cooler includes copper heat-pipes and a decent number of aluminium fins.

The stock cooler features the same "latch-on" design that AMD's stock coolers had for years. In addition, the four copper heat pipes, the copper base, the 0.31mm aluminium fins, and the 3280 RPM 65mm fan keep the 6-core processor frosty.

Next up: the Geekbench Benchmark!

 

The cool thing about Primate Lab's Geekbench benchmark is that it isn't synthetic. If you don't know what I mean, take Cinebench for example. When are you ever going to be rendering a picture of THAT size in reality? While it is true that video/3d rendering is common (I do rendering myself), the "compression, decompression, image sharpening" tasks done in the Geekbench are done much more commonly  by more users. In other words, you are more likely to be doing file compressing that rendering, so Geekbench is a more practical measurement of what your CPU can do.

The 1100T does very well in this benchmark. Its score of 8024 is enough to beat the i7-870, i7-940, i7-930, i7-920, i7-860, and the quad-core Lynnfield i5 models. In terms of score, the i7-960 beats the 1100T by roughly 400 points. That's nothing a quick overclock can't fix! After all, this is an AMD Black Edition processor... let's put that name to the test!

I decided NOT to over-volt this CPU, although doing so would have gotten better results. I got to around 3.78GHz with a BCLK of 210 MHz and a CPU Ratio of 18.0.

After running Cinebench 11.5 again, I was surprised that the max temperature stayed at around 50C. The OC'ed Phenom got a score of 6.49, a 0.7 point score increase from its stock speeds result.

The Geekbench results were even more awesome! The overclocked 1100T got a score of 9036, more than enough to surpass the i7-960. The CPU overclocking tweak resulted in a 1012 point increase, enough to beat the i7-965, i5-2500K, and the i7-875K at stock speeds. All that was spared in the Phenom's overclocking madness was the i7-975, the Sandy bridge desktop i7's and the Intel 6-core Gulftown processors.

AMD's response to Intel's Lynnfield was a smart one. Not only does the Thuban processors offer more performance than Lynnfield at roughly the same price point, who can resist 6 cores?

 

 

 

 

 

 

 

28Jul/110

A look at Sandy Bridge and Intel Core i7-2600K Review

The Intel Sandy Bridge Platform, released early this year, has been dominating Lynnfield, Clarksfield, Deneb, and even Gulftown in some cases in benchmarks. However, it is not just the benchmark scores that are awesome; the i7-2600K can overclock up to an amazing 4.4-4.6 GHz on air. The i7-2600K was released along with the i3-2100, the i5-2300, the i5-2400, the i5-2500, the i5-2500K, and the i7-2600 early this year. The i3-2100, the i7-2600, and the i7-2600K all have the Intel Hyperthreading 2.0 technology. Basically, this allows each core in the processor to handle up to 2 threads; it creates 2 virtual cores for each physical core in the processor. So, if you have a quad-core processor with Hyperthreading enabled, you see 8 "cores" in Windows Device manager and 8 "cores" in Windows Task Manager.

 

 

 

Sandy Bridge CPU's aren't overclocked by BCLK, they are overclocked by the turbo multiplier, which brings us to the next feature Sandy bridge has to offer...

While the i5's do NOT have Hyperthreading, they are all quad-cores (the desktop versions) and support Turbo Boost, just like the i7's. i7's and i5's support Turbo boost 2.0 which was a feature introduced with the release of Lynnfield that allows the CPU to automatically overclock itself when the CPU is under load and within the thermal and power constraints. Basically, the CPU can down-clock three of its cores and overclock the 4th core up to 3.8 GHz, OR it can gate two of its cores and turbo the 3rd and the 4th core up to 3.7 GHz.

Sandy Bridge overclocking works by adjusting how much each core gets "turbo-boosted." If you have an i5-2300, an i5-2400, or an i5-2500, you can "turn up the turbo" (clever alliteration?) up to 4 speed bins past the default "boosted" frequency.

*Note that as of right now, only P67 and Z68 motherboards support Sandy Bridge overclocking. *

Confused? So was I when I first saw this. Let's try to clear this up.

Let's say you have a i5-2300. The stock clocks (the speed without turbo) is 2.8 GHz. So, that means when 3 of the cores are being gated, the 4th core gets turboed 0.4 GHz. That would make the 4th core 3.2 GHz. Since a i5-2300 can be overclocked up to 4 speed bins past the default turbo frequency, you can force the 4th core 0.4GHz MORE to 3.6 GHz.

Let's do the math:

2.8 GHz + 0.4 GHz = 3.2 GHz (the default turbo speed)

since you can overclock 4 more speed bins,

3.2 GHz + 0.4 GHz = 3.6 GHz (you can overclock as high as 3.6 GHz on the i5-2300)

 

To make it even more complicated, Intel has also released "K" edition processors. K processors offer HD 3000 integrated graphics. In addition, K processors are FULLY unlocked so you can overclock pretty much as high as you want.

Let's say you have an i7-2600K. The default speeds for the 2600K are 3.4 GHz. That means when using a default turbo-boost configuration, you can turbo one core up to 3.8 GHz while gating the other 3 cores.  Now here comes the difference: since the i7-2600K ends with a "K" you can overclock this CPU as high as you want (although there is a 5.7 GHz limit). That means you could theoretically have 4 core running at 5.7 GHz each (you'll need some pretty extreme cooling for that though).

More math?

3.4 GHz + 0.4 GHz = 3.8 GHz (default turbo)

3.4 GHz + X GHz [less than or equal to] 5.7 GHz (overclocked)

 

 

Now let's have a look at the i7-2600K:

 

When you open up the box, you'll find a stock Intel cooler (takes up 90% of the box), an instruction booklet, an "Intel i7" sticker for your case (nice and glittery), and the processor itself.

 

Even at stock clocks, the i7-2600K is a pretty good chip. In the Maxxon Cinebench CPU test, it out performs easily out-performs the i7-960 3.20 GHz quad-core chip by 1.38 points. To put that in perspective, the 12-core AMD Opteron 2435 server processor outperforms the i7-2600K at stock speeds by 1.09 points


Time to overclock... this is a K series chip after all right? While other reviewers said that they got to 4.4 GHz using the stock Intel cooler, I wasn't to impressed with it.

Maybe I installed the heatsink wrong, but I was getting temperatures over 80C (sometimes even over 90C) while I was running Cinebench. I decided not to fry my CPU, so I installed a better cooler.

 

The CoolerMaster Hyper 212+ isn't that different from Intel's Gulftown Stock cooler (maybe that's what they used) in terms of form factor, so I used it to cool my CPU instead. I must say the results were pretty amazing.

Here's a video for overclocking the i7-2600K and benchmarking it with Cinebench

As you can see, I didn't even adjust the voltage or power settings for the CPU. All I did was change the Turbo multiplier.

This time around, the i7-2600K DID in fact outperform the AMD 12-core Opteron by 0.22 points in the Cinebench CPU benchmark.

While using the CoolerMaster Hyper 212+ CPU cooler, I got a maximum temperature of 64C on one of the cores while at 100%. This is a VERY acceptable temperature, especially considering that the CPU has been overclocked 1 full GHz.

I also ran the Primate Labs Geekbench 32-bit CPU benchmark.

At stock speeds, 3.4 GHz, the i7-2600K scored a geekbench score of 9510 points.

Using the "PC Benchmarks" table at  http://www.primatelabs.ca/geekbench/pc-benchmarks/ , it shows that the i7-970 six-core processor is beating the i7-2600K by 1980 points and the i7-980x outperforms the i7-2600k by 2956 points... that is unacceptable! Time for overclocking!

I OC'ed my chip to 4.4 GHz and got within reach of the i7-970 - 11051 points vs 11490. Although the Sandy Bridge processor wasn't enough to slay the 6-core Gulftown beast, it came very close to it's score.

 

To sum it up, Sandy Bridge has been a pretty successful release for Intel. In terms of value, Sandy Bridge is king. As of right now, Intel has no direct competitors for it's 2nd generation K series chips (i5-2500K and the i7-2600K). They easily out perform the Phenom six-cores and even rival the performance of 6-core Gulftown CPUs. However, with AMD Bulldozer releasing soon, will Sandy Bridge be able to hold on to that dominance?

 

 

 

 

 

 

 

 

27Jul/110

How to Upgrade your PC with a Solid State Drive

IMG_1669

 

In terms of reliability, ruggedness, and performance, solid state drives, better known as SSDs, are superior to traditional hard drives. As the name suggests, solid state drives do not have any moving parts. As a result, SSDs don’t have “seek times” like hard drives do. Also, since SSDs typically have awesome random read speeds, a 40GB- 60GB SSD is perfect for use as a “boot drive” or an “application drive” in a Desktop PC. Since laptops usually only have one storage bay, you might need a SSD with a larger capacity (120GB-256GB).

There are two main drawbacks to solid state drives. The main drawback is the price. At around $2 per GB, a 120 GB SSD would cost well over $200. In comparison, a 1 TB hard drive would only cost $60. There are two types of SSDs: single level cells and multi level cells. SLCs store one bit per flash memory cell while MLCs store two or more bits per cell. Since manufacturers can cram more space into less room, MLCs often sell for less than SLCs. This brings us to the next drawback of solid state drives: wear. Unlike traditional hard drives, solid state drives will gradually degrade or “wear” after a period of use, MLCs faster than SLCs. Since every write to a cell wears it, the more you write, the faster it will become “worn”, or unusable. This decreases the capacity of the cell and decreases the speed of the SSD. However, OS’s like Windows 7 have special features like TRIM that “level the wear” and maintain the speed.

In this guide, I use a Corsair Force 3 60GB MLC drive that I will be using as a Windows 7 boot drive for my Desktop PC.

Before you start, consider the following:

  • Does your PC’s BIOS support SSD’s?
  • If you bought your PC from a manufacturer, you can type your PC model into Google and see if others had success in installing an SSD.
  • Ex. Dell XPS 15 SSD
  • Ex. Toshiba Satellite A665 SSD
  • If you built your own PC, type in the name of the motherboard you got into Google.
    • Ex. Gigabyte GA-Z68X-UD7-B3 BIOS SSD
    • Ex. ECS P67H2-A3 BIOS SSD
  • Does your PC run Windows Vista SP1 or Windows 7?
    • Windows Vista and Windows 7 are the best optimized OS’s for SSDs. If you have Vista, be sure to update to the latest service pack.
  • Can your PC be physically upgraded?
    • If you built your own computer, the chances are that you bought a case with more than one hard drive bay.
    • If you bought a desktop PC from a manufacturer, you can check if it comes with additional hard drive bays. If you bought an Alienware Desktop, chances are, there are extra storage bays. If your desktop case doesn’t come with extra slots, you can simply use velcro to stick it on the side of your case (normally this would be a problem with regular hard drives, but since SSDs have no moving parts, it won’t damage your drive).
    • Some laptops allow you to change out hard drives, but some others, like Macbooks, Macbook Pros, and Macbook Airs don’t. Basically, if you flip your laptop over and notice that there are no screws on the back, your laptop can’t be upgraded.
  • If you’re going to use the SSD as a boot drive in a desktop that you bought from a manufacturer, check to make sure the power supply in your desktop has enough LP4 SATA power cables to power your SSD and enough SATA ports on your motherboard to hook up you SSD.
  • If you bought a PC from a manufacturer, does it use SATA?
    • Most modern PC’s that are sold from companies like Dell, HP, Apple, and Lenovo use SATA connections for data transfer between the hard drive and motherboard. However, if you have an old PC, make sure that it uses SATA connections because most, if not all, SSDs use SATA. If your old PC uses IDE, you can buy a SATA PCI card for around $7 that can be used with an SSD.
  • Have you backed up your data?
    • Copy all your important files to a safe location (Ex. cloud storage or an external hard drive.)
    • Make a Windows recovery disk for your PC!
    • Windows 7 gives you the feature to automatically back up everything to an external hard drive; it also makes a bootable recovery disk so you can restore your system in case anything goes wrong.
  • If you have a drive imaging software like Acronis True Image or Driveimage XML, use that to make a clone/image to backup your PC. We’ll also need that later when moving your files from your HDD to your SSD.
  • Do you have a large enough SSD? (does not apply to those who wish to make a clean Windows install on their new SSD)
    • When you clone your HDD to your SSD, you’ll need to make sure that there is enough room on your SSD to account for all the data stored on the HDD that you will clone/move over to the SSD. If you have too much stuff on your HDD, move some to an external hard drive to make room. You can also buy the “Paragon Migrate OS to SSD 2.0” software that lets you choose what to move from your HDD to your SSD. (saves a lot of trouble) http://www.paragon-software.com/technologies/components/migrate-OS-to-SSD/

     

     

    Now, time to start!

     

    The first way of doing this is via a clean installation of Windows. If you have an older version of Windows and want to upgrade in the process, this method is perfect. However, it requires a copy+license of Windows ($109 for Home premium). If you’re using this method on a manufacturer-bought PC, you’ll also need Windows Easy Transfer or Laplink PC mover to move over all your files but more importantly, your hardware drivers. If you built your own PC, you can just reinstall the drivers on your SSD via the disc that came with the parts, then update it by downloading the latest drivers from the parts website.

     

    I prefer the next way, which is using drive-cloning software. Since I’m keeping both my drives for my desktop (the old HDD is now used for storage), I can clone the OS from my HDD to my SSD then use the SSD as the boot drive and the HDD for keeping files. If my solid state drive stops working, I can boot into the Windows 7 installed on my HDD and try to recover data from the SSD. If that doesn’t work, I can keep using the HDD as if nothing happened.

    If you are trying to upgrade a laptop, skip this part because I will be explaining how to install a SSD in a desktop first:

    DESKTOP

     

    1. If you have a Desktop, the first step is to put the SSD inside your case and connect it to your motherboard and power supply.
    2. BE SURE TO TURN OFF YOUR COMPUTER WHILE DOING THIS. To be even more safe, wear an anti-static wristband and turn off your power supply.
    3. Open up your case (most desktops have two screws on each side panel that holds it in place; remove those and the side panel should be easy to pop out) to check if there is any extra hard drive bays.
    4. If your PC does, install a 2.5” to 3.5” adapter on your SSD (most SSDs are 2.5” and most desktops have 3.5” bays). Usually SSD’s should come with an adapter, but if your doesn’t you can usually pick one up for under $10. Pop your SSD into a drive bay in your PC and connect your SSD to your motherboard via SATA cable and plug in a SATA power cable into your SSD.
    5. If you PC does not have a hard drive bay, you can use velcro and stick the SSD on the side of your case. Hook up the SATA data and power cables to your SSD. Make sure you velcro your SSD in a place where it won’t block airflow to other parts, and make sure the cables that you plugged into your SSD won’t get caught in any fans that your case might have.
    6. That’s all you have to do for physical installation

     

    LAPTOP

     

    If you’re upgrading your laptop’s hard drive, I recommend you check out this guide here: http://www.pcworld.com/article/192930/how_to_upgrade_your_laptops_hard_drive_to_an_ssd.html

    1. If you have a laptop, you won’t have any space to mount a second hard drive, so you’ll have to buy a SATA hard drive dock (external USB enclosure).
    2. Put the SSD into the USB enclosure and plug the power cable int the wall, and plug the USB cable in your laptop.
    3. Wait for the drive to be recognized
    4. You’ll still have to do some “physical installation” later on.

     

    DESKTOP AND LAPTOP

     

    1. Click on your Start orb and right-click “Computer” and hit “Manage”
    2. You should see “Storage” on the left column… click that then hit “Disk Management”
    3. You should be able to see two hard drives (minus any other removable storage that you’ve plugged in) – one is your regular hard drive and one is the SSD that you just connected to your computer.
    4. If you aren’t able to see your SSD, check the connections between your SSD drive and your PC.
    5. Open up Acronis True Image or Driveimage XML
    1. In Acronis, go to “go to main screen”
    2. Click “tools and utilities” on the upper right hand corner
    3. Under Disk management, click “Clone disk”
  • In Acronis, I suggest using “Automatic”
  • For the source disk CLICK THE HARD DRIVE THAT YOU ARE CURRENTLY USING.
    1. Be sure you have moved files away so that the total amount of used space on your hard drive is less than or equal to the amount of space available on your SSD
  • For the destination disk CLICK THE SOLID STATE DRIVE
  • Click finish and the wizard should ask you to restart your computer after a few seconds
  • When you boot up into Windows, you should see something like this:
    1. IMG_1675
  • This is the part of the process where Acronis is copying all your files on your hard drive onto your SSD.
  • This takes a while, so you can come back later when it’s done
  •  

    DESKTOP

    1. When the Cloning software is done cloning your drive, reboot your computer. Right after you see it turn off and turn back on, start pressing the “delete” button (this varies for different motherboards/BIOSes) to get into the BIOS.
    2. Change the Boot priorities so that the SSD has a higher boot priority than the hard drive.
    3. Save the changes and you are done changing installing your SSD!

     

    LAPTOP

    1. When the cloning software is done, shut off your computer and remove the SSD from the External hard drive enclosure.
    2. Open up your laptop and carefully remove the old hard drive. (more tips on how here: http://www.pcworld.com/article/192930/how_to_upgrade_your_laptops_hard_drive_to_an_ssd.html)
    3. Insert your new SSD and close the lid on your laptop.
    4. You should now be able to boot to Windows.
    5. If you want to keep the files on your old hard drive, you can put it in the external USB hard drive enclosure and use it as an external hard drive.

     

     

    OPTIMIZING PERFORMANCE – DESKTOP AND LAPTOP

     

    1. As I mentioned earlier, SSDs gradually degrade over time when data is written and erased from the “cells” for a long period of time.
    2. Windows 7 has a TRIM function that helps reduce the “wear” that decreases the size and speed of SSDs.
    3. To enable TRIM, open command prompt as an administrator.
    4. To check if you have TRIM already enabled from Windows auto-detecting an SSD, type
    1. “fsutil behavior query disabledeletenotify”
  • If you get “DisableDeleteNotify = 0” that means that Windows 7 is already using TRIM and you don’t need to do anything further.
  • If you get “DisableDeleteNotify = 1” that means TRIM is turned off.
  • To enable TRIM, type in
    1. “fsutil behavior set disabledeletenotify 0”
  • When you’re done, check that Windows is now using TRIM by typing the command in step 4
  • You are now done installing your SSD!
  •  

    MY OWN RESULTS

     

    I installed my Corsair Force 3 60GB SSD as a Windows 7 boot drive, and I must say I am very satisfied with its performance.

    Here is a comparison of Windows 7 booting up from the Corsair SSD and my old Hitachi Deskstar HDD:

    Stop SOPA!

    SOPA breaks our internet freedom!
    Any site can be shut down whether or not we've done anything wrong.

    Stop SOPA!