Category: Other stuff

Adding an SSL Cert

Adding an SSL Cert

SSL connectionThese days, if you have a website or even a game server then you probably should have an SSL (or TLS to be more precise) certificate. Have you heard of telnet? It’s an old protocol that allows you to connect to a remote computer and issue commands. Do you know why you don’t hear of it any more? Because it was designed for an era where hackers didn’t spend all their time attempting to compromise computers. Telnet, like FTP has a flaw. Passwords and login details are sent in the clear. Not hashed, or encrypted.

Why don’t I use SSH to connect to it? I do. SSH has more functionality than SSL and is very good for encrypting remote connections. SSL needs a certificate, whereas SSH doesn’t but many think you should use a SSH certificate as a substitute for username/password and I intend to. If you’re not sure of the technical differences between SSL and SSH, this article isn’t a bad place.

So today I paid for an SSL certificate. I’d pointed a domain I had handy to the vps a few days ago, to give DNS a chance to settle, (24 hours max but usually much less) paid £20 for five years of SSL cert and installed it today. Thankfully, virtualmin which I use for configuring the server makes it straightforward to request a SSL by generating the CSR (Certificate Request an Private Key) . This blog uses an SSL cert from the same place (CheapSSL). Despite the low price the certificates are very good.

Although the world won’t see what the cert is protecting, you almost have to have them nowadays. This is for the connection between smartphone and server. As I found today, Apple is ramping up security and Google is doing the same. I have iOS 14 on my iPhone (upgraded yesterday) and it refused to connect to WiFi in my local coffeeshop. Their certificate doesn’t expire for another month but I suspect it is now over 398 days old. As far as Apple is concerned, that certificate is past its use by date. This is Apple’s new policy since earlier this year. My wife’s iPhone, still on iOS 13 connected quite happily.

For those who have bought a multi-year certificate as I have today, it just means you have to generate another CSR and install a newer certificate once every 400 days or so. I’ve started taking screenshots of the details so I get them correct! I believe Google is moving to this 398 day maximum as well.

So the commands from smartphone to game server are now sent over https and encrypted in flight as are the results. It’s one less thing to worry about.

 

 

My code is buried in the Arctic!

My code is buried in the Arctic!

Svalbard taken from a cruise ship in 2015It’s true. Well my code and that of thousands of others on Svalbard, a set of islands halfway between Norway and the North pole. I’ve actually been to Svalbard on a cruise a few years back. It was cold and a bit damp. That’s one of a bunch of photos I took.

GitHub shipped 21 terabytes to be stored in long term storage under the ice. It should be good for a few hunded years at least so thats my backups taken care of. I wish!

Normal blogging will be resumed tomorrow. Hey after 200 posts I’m allowed a semi-off topic post once in a while!

Changing your default Font

Changing your default Font

This is one of those subjective things. Do you use the default font in text editors or do you switch to a programmer’s font when the option is possible?

For example in Visual Studio, you can select any font you want. The Monotype fonts (i.e. fixed width) are shown bold.

JetBrains, the people behind the Resharper tool for C#, Intellij Idea (the editor used in Android studio) and the Kotlin programming language have given away a new programmers font.

After downloading the font zip file, open it and unzip the multiple versions of the font. There’s 14 variations (extralight, italic etc) and also web versions that you can use in a website. I just took the regular and installed it in Windows. If you Preview the font then you get the option to install it.

In Visual Studio you have to go to Project Options then Font and Colors and select the font. After that you have to close Visual Studio and reopen it.

One interesting thing is that this font supports ligatures.  These are special characters that replace things like !=. Here’s what that looks like after installing this font.

Visual Studio Font with ligatures

Of course if you don’t like JetBrains Mono or want to try others programmer’s fonts, here’s an article with eleven listed.

It’s not just Visual Studio that this works with, you can change the font in Visual Studio Code and others.

A simple Rock, Paper, Scissors game

A simple Rock, Paper, Scissors game

Rock, Paper, Scissors
Image by OpenClipart-Vectors from Pixabay

One of the easiest games to program is Rock, Paper, Scissors. All you are doing is a simple comparison, but programming it so the computer player can win more games than the player is not quite so easy.

The easiest strategy is always guess paper as Rock is apparently the most often chosen. That might work for the first couple of games but after that… A better strategy is count what the player plays each time to try and detect a bias. Guess randomly but make the %age of guesses favour the move that defeats the players most common move. If the player pays paper 50% of the time, guess scissors 50% of the time.

Then there’s variations on this, try and analyse past moves to give an edge. That could get quite complicated. You have to program it for pattern recognition. If the player favours scissors after losing with rock etc.

Here is a simple implementation of RPS in C.

 

Programming Language Surveys

Programming Language Surveys

Arduino board
Image by Seven_au from Pixabay

It’s that time of year when several infrequent programming language surveys burst on the scene and I’m now beginning to doubt the veracity of the IEEE survey, along with the eternally mad Tiobe which has C at #1. The IEEE has C at #3 in popularity, but also counts Arduino as a programming language because people search for Arduino code. Such lack of rigour does you no favour chaps, so much for engineers!

Arduino (that’s one in the picture) is, like a Raspberry Pi; a hardware platform.  Given that Raspberry Pis have sold over 30  million which seems a lot more sold than Arduinos, why are they not listed?

RedMonk came out with their June survey recently (they do a small number each year)  which is based on popularity of GitHub project’s programming languages. They put C at 11th and C++/C# as joint 5th.  IEEE didn’t have C# in their  top ten which is completely at odds with every other programming survey. Even Tiobe has it at #5.

As always, I value Reddit’s programming language sub-reddits which has C at 9th and C# at 4th with C++ at 5th based on the numbers of members of each group. There is always a lag between the numbers shown on the summary and the actual numbers in each sub-reddit when you click into it.

A test of resource loading in MonoGame

A test of resource loading in MonoGame

Ace of ClubsAce of DiamondsAce of HeartsAce of SpadesLoading resources into RAM on a smartphone can be a relatively slowish process. I’d been working on a card game and had both a set of 52 individual playing cards plus a sheet of 52 in one image. I have two Android phones so used the opportunity to test which is quicker loading 52 small images or one larger image. MonoGame ‘s Draw routines can copy from part of an image; you just specify the source.

In this case I was comparing loading 52 images, each 100 x 153 pixels (the four aces shown are the same images) or one image that is 1500 x 633. On the face of it, loading one image should be faster- there’s a certain overhead with loading each image so you get that x 52. But larger images can be problematic especially on devices like smartphones with less smaller amounts of RAM than desktops.

The two smartphones are both older, one is a BLU STUDIO ONE; the other a Chinese beast which shows up in Visual Studio as an Alps X27 Plus. It was bought on Ebay and claims to have 6 GB of RAm and 128 GB storage. In practice, when I tested the storage, it ran out after 12 GB! The phone only cost me £29 so I cn’t really complain…Although it claims to be Android 9.1 in the Developer information in Settings, it like the BLU seem to be running Android Lollipop. (5,1 – level 22) when plugged into my PC/Visual Studio.

I first ran the load code on the 52 images in Debug mode. Possibly not the best way to test code.

        private string LoadCards()

        {
            Stopwatch stopWatch = new Stopwatch();
            const string suits = "HCDS";
            const string ranks = "A23456789TJQK";
            stopWatch.Start();
            int i = 0;
            foreach (char c in suits)
            {
                int j = 0;
                foreach (char r in ranks)
                {
                    string s = @"Cards\"+r + c;
                    cards[i, j++] = Content.Load(s);
                }
                i++;
            }
            stopWatch.Stop();
            TimeSpan ts = stopWatch.Elapsed;

            string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                ts.Hours, ts.Minutes, ts.Seconds,
                ts.Milliseconds / 10);
            return elapsedTime;
        }

That is the C# code to load the 52 images. The Alps which is a newer phone took 0.28 seconds to load them. The older BLU took 0.18. Neither are great times. To load the single image I commented the code out between the two stopWatch calls (Start() and Stop()) and then added this one line.

 allcards = Content.Load<Texture2D>("allcards");

The single image took 0.10 seconds on the Alps and 0.06 seconds on the BLU, both roughly three times faster loading one big image than loading all 52 images.  Information like this is useful and I’ll now create my own tools for building sprite sheets of multiple images.

 

A game development website recommendation

A game development website recommendation

Games
Image by Maria_Alberto from Pixabay

In my previous post I mentioned that I’d had to discover a lot of stuff for myself. Just before the Web came into being ie 1994-1995 I’d been working on a hexagon map based game.  I figured out how to draw hexagons, how to store a hexagon map (as a 2D grid), how to click on a map location and discover exactly which hexagon you clicked.

I still have source code that I wrote 30 years ago for the postal game Quest and likewise for the hexagon game which I called Onslaught. Both were written for a 16-bit Turbo Pascal and probably could with a bit of effort be transformed into 32-bit or 64-bit Delphi had I the time and desire, both of which I lack.  Given that Quest is still run, that’s probably not a good idea anyway! Plus I had only been writing Pascal code for a few years and my old code is far from being comprehensible!

Anyway, a lot of the wisdom and stuff that I taught myself can be found on the excellent Amit’s Game Programming Information website (particularly the hexagon stuff) and I highly recommend it if you have any desires to be a game programmer.

 

 

 

 

Playing with VSCodium

Playing with VSCodium

open-vsx.orgThere are some subtle differences between it and Visual Studio Code. The main one is the not having access to the VisualStudio market place. The C/C++ template isn’t there but instead is installed by default.

However I have found that the tasks and launch json files created from the F1 menu don’t have the C++ choices. What this means is that you have to get them from an official Visual Studio source, like Visual Studio Code installed on 64-bit Windows/Ubuntu/Mac.

I’d already done this so I used WinSCP to send them via ssh from my Windows box to the Pi. It’s a slight irritation but once you’ve got them setup it works ok. I can build applications haven’t got debugging working yet though.

There is an alternate Extensions Marketplace which has 266 items in it.  That’s a screenshot of the programming language extensions.

Creative computing games

Creative computing games

Hammurabi BASIC listYesterday’s post reminded me of one of the joys of my youth. The Creative Computing magazines’ “BASIC Computer games” book and it’s sequel “More BASIC Computer games.” . I bought these in 1982, and they weren’t cheap then- about £20 each.

Of course over the years they got lost but I bought them again a few years back. Some of the games in here are classics- A simple Star Trek game, Hammurabi, mugwump, golf, various landers. Of course they are all in BASIC but relatively easy to convert to C.

You don’t have to buy the books (they are pretty expensive on Amazon and no I’m not selling mine!) as many of the games are available online. One source is this classic BASIC games web page. Here’s another link  with more games but they are scans of the pages.

I promise I won’t be putting any more BASIC listings up. These are just an  inspiration to create small games in C or adapt these.

While at Uni in my first year, I adapted a copy of the Star Trek game adding in a whole lot of new features. It doesn’t say much about the interactive mainframe there that with just four people playing the game, the mainframe was brought to its knees!