Author: David

New domain appears to be cursed

New domain appears to be cursed

Web design
span>Image by EstudioWebDoce from Pixabay

Back about ten years ago I gave a few lectures on what it took to setup a website. I’d ask the audience (who were not technical) for ideas, showed them how to search on a registrar, find a domain name, register it and it would be live usually within 15-30 minutes.  Then I’d add some content and publish it. It worked every time.

So you’d think the process would be smooth as silk now. Think again. I registered a domain about three weeks ago. I’d had the .eu version for a game idea but of course being .eu and me not living in a EU country and so on so I decided not to renew it. However the .org of it was available and I registered that.

Last week I decided to configure hosting, buy a SSL certificate and start using it. Only when I added it to the server I rent (a reseller account), it didn’t show up on the domain page. That’s where you get the name servers from. Rather than faff around with A recs and MX records, I usually set up Name Servers to point to the hosting server. For that of course you need to know the name servers.  But the domain was not on the GoDaddy DNS page so no name server informtion. The hassle factor was ramping up a bit quickish. Very odd.

I faffed around for a couple of days and got onto GoDaddy’s technical support. It turned out, well they pointed out that (a) the registrar (123-reg.co.uk) had put parking on it. and (b) there was something a bit weird with the DNS hosting. Weirdly, on Chrome, the page is blank which is why I’d not seen it. When I looked at it on iPhone sure enough there was a parking page with adverts.

So I got name servers from GoDaddy and set them on 123. I gave it two days and looked and no change. The name servers were set but The DNS page on their site did not say that it was being managed by external name servers. You get that on other domains; this one for instance.

Onto 123 support and to be fair to them, they sorted it pretty quickly. Also I found out that 123-reg.co.uk and GoDaddy are sister companies. You learn something every day. So I looked at the site and it was the same Parking page except it now said Parked on GoDaddy instead of Parked on 123-reg.co.uk. Me I find this a bit cheeky; I’m paying for registering a domain and hosting but those companies are making a little (maybe more than a little) by parking my domain. I can understand that they’ve probably got a lot of domains in limbo; alone and unhosted so why not park em. But it seems a bit cheeky just doing it without saying anything.

How long to Wait?

So back to GoDaddy support which isn’t always easy. You can do it online by a chat Window and at one point I got this gem. 371 Minutes! Normally its 4 or 5 minutes… I closed the browser window and came back 30 minutes later.

Slight Delay

So the oddity I mentioned earlier; somehow, the domain was added for hosting against somebody else’s account. I can’t explain it, they can’t explain it. So they asked me to verify ownership by reverting the name servers to 123’s and adding a TXT record in the DNS with a certain name and value. Once they can see that I really do own it, they’ll change ownership of its hosting (not even the domain just the hosting!) to me.

So what used to take me 15-30 minutes is about nine days elapsed time. And it’s not finished yet. I really do think this domain is cursed.

 

A minor whinge about Linux

A minor whinge about Linux

Screenshot of Virtualmin update screenI’ve been a Windows developer since the late 1990s and I got into Linux about 2008. I’m still a Windows developer but now that .NET applications can run on Mac and Linux as well as Windows, it makes it easier to write software in C# that runs on Linux.  Using a Linux VPS is probably the cheapest way to do that.

I still use Visual Studio on Windows for developing and just by changing the publish target can run it on Windows or Linux. If you manage a VPS as I do, you want to keep it up to date and that’s what my whinge is.

It used to be that Windows was a pain with having to reboot after installing software. These days that’s only when you’re doing a major update. But Linux? I’m finding that I have to reboot it after an update on average perhaps once a week. This week it happened twice! I grabbed a screenshot to show it.

The screenshot is of the bottom of the VirtualMin update page. I use Virtualmin for administering it because I prefer to spend my time programming. That blue Reboot Now button appeared because one of the packages that got updated required a reboot. I don’t think there’s anything that can be done except click it; the reboot has to happen and only seems to take a minute at most.  It’s just the irony that for years people complained about Windows reboots and now it’s actually Linux that is the major culprit!

And with a bit of help I got it fixed

And with a bit of help I got it fixed

Visual Studio Publish Target runtime dialogThanks to suggestions in the Reddit CSharp subreddit (you can view the entire thread here), I fixed the missing file issue and SkiaSharp is now happily outputting graphics on the VPS.  I’m referring to the More Programming Joys blog entry I posted yesterday.

There were two things that were needed to fix it.

  1. Add a package to the solution. This was the SkiaSharp.NativeAssets.Linux package and I used Nuget to add it to my Windows solution. If you haven’t used Nuget, it’s a great package manager and makes it very easy to add packages.
  2. On the Visual Studio Publish page, I needed to change the Target Runtime to linux-x64. That’s the dialog above. When I clicked the Publish it put all the files including the library that was missing (libSkiaSharp.so) into the Target location and once uploaded it worked.
More Programming Joys

More Programming Joys

Game MapSo I’ve been doing some .NET programming. First on Windows because I can debug it there then “Publish it” which puts all the files (compiled in release) needed, including any dlls into one folder and upload it to a VPS using WinSCP. I’ve also got a terminal session connected by Putty. I use Serilog for logging and SkiaSharp for graphics.

First bug was a missing file but it was a stupid error on my part. I had the file in a path under the home folder and had used ~ in the file’s path. You can use ~ in Bash- it means your home folder, but not in a file path in an application. Putting in the full path fixed the bug. D’oh.

Because it’s .NET (6) that I’m using, you don’t get configuration stuff the same as you did with .NET Framework. I store some config information in a file and define the path with these lines of code which work on both Linux and Windows.

 bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
 var appSettingsFilePath = IsWindows ? @"c:\turfwar\twConfig.json" : "/home/user/turfwar/twConfig.json";

I like Serilog ( with project on Github at ). Nice and simple logging but flexible enough. As this application is a command line app run whenever, it’s easier to view the logs afterwards.

Why use SkiaSharp?

I was quite happy to use System.Drawing but according to this, There are issues with libgdiplus. So I thought I’d try SkiaSharp as I’m doing stuff with Flutter and Skia is the library that underpins that. This is what it takes to create a 100 x100 grey coloured Bitmap in SkiaSharp, add yellow dots and save it to disk as a .jpg. That’s what you see up above.

        internal void SaveBitMap(int id, string filename, Gang gang)
        {
            var info = new SKImageInfo(100, 100);
            using var surface = SKSurface.Create(info);
            SKCanvas myCanvas = surface.Canvas;

            // clear the canvas / fill with white
            myCanvas.DrawColor(new SKColor(0x99, 0x99, 0x99));

            // draw the dots, one for each block
            foreach (var block in Blocks)
            {
                if (block.Owner == id)
                {
                    myCanvas.DrawPoint(block.X*5/2, block.Y*5/2, SKColors.Yellow);
                }
            }

            // Now save to filename
            var mainCanvasImage = surface.Snapshot();
            var TempTIFbitmap1 = SKBitmap.Decode(mainCanvasImage.Encode());
            using (var image = SKImage.FromBitmap(TempTIFbitmap1))
            using (var data = image.Encode(SKEncodedImageFormat.Jpeg, 100))
            {
                // save the data to a stream
                using (var stream = File.OpenWrite(filename))
                {
                    data.SaveTo(stream);
                }
            }
        }

It works fine on Windows but on Linux, (Ubuntu 20.04) I hit bug #2. “System.TypeInitializationException: The type initializer for ‘SkiaSharp.SKImageInfo’ threw an exception.”. And that’s where I am at the moment.  This is similar.  I’ll keep you informed.

Playdate gets nearer to release

Playdate gets nearer to release

playdateBack in May 2020 (nearly two years ago) it was originally announced and the updated release date now looks to be late 2022. Also it’s $179 not $149. But they have given a lot more details; you can for instance see the hardware spec.

Also more relevant is the way of creating games. Either in Lua + C or just C. The dev tools illustrated are running on a Mac but according to this Twitter thread (worth a read), they’re available for Windows, Mac and Linux.  The SDK looks impressive enough- “It includes helpful functions for things like font handling, drawing, animation, sprites, tilemaps, collision detection, A* pathfinding, audio synthesis, crank handling and more. You can download the SDK which includes a simulator now from the dev page..

Would I get one? I’m toying with the idea. A mono display of 400 x 200 is a bit retroish and my days of creating those types of games are probably long behind me, but it’s tempting.

The Two Dice Calendar Puzzle

The Two Dice Calendar Puzzle

Two dice calendarA few years back I owned a calendar made up of two dice (a bit like the image from Wikipedia) to show the day of the month. The two dice had all the digits needed to display any number from 01 to 31. It’s a neat little puzzle to ask someone if they can figure out what the numbers on each of the two dice must be for this to work.

You can probably find the answer on the web, and it took me just 30 seconds to find one.  But still, it is a fun little puzzle.

What I thought was, could I write a program to solve it? So I’m going to try it. It will be in C# to start with but if that works, I’ll redo it in C and publish both on here.

Dealing with artists for game graphics

Dealing with artists for game graphics

Factory graphicsI’m working on three game projects (my side projects), One is Flutter front end plus C# back end, another is the same but a different type of back end and the third is a mobile game with C# backend but its put to one side until the others are done. These are all side projects.

I’ve bought graphics and they do up to a point- e.g. kenney.nl is very good. But sometimes you need something a bit better or that’s not covered by that library.

Now one of the things I’ve done is use low costs artists from sites like Fivesquid.com and fiverr.com. Many of these artists are very good but live in countries where things are a lot cheaper than here in the West. Exploitation? Maybe, but they are happy to do the work and it saves me a fortune. What might cost me a couple of hundred pounds here in the UK can be done for say £20.

But I’ve found when dealing with them that you can’t take anything for granted. You have to have a bit of patience and explain everything including your expectations. And make sure you nail the price down exactly. I had arranged everything with one to do 35 small graphics and he wanted £35 for each graphic. Despite his advert saying 5 graphics for £10!

So I’ve found, you need to specify file format (.png or .jpg), layout- single files or in a sheet in a grid. Also fivesquid have a thing where when the order is delivered, you have three days to mark it complete or asks for changes. One artist said it was complete but hadn’t quite got it ready and the three day period expired before I’d received anything. So I could hardly accept nothing. It was though a genuine mistake on the part of the artist and I did get the graphics eventually.

It’s that book again

It’s that book again

Basic Computer games bookOne of my favourites and one that I actually bought twice in my life and of course I have mentioned before. Originally I bought it back in 1982 and more recently in 2015 along with the sister “More Computer Games” book. The reason  I mention it because there’s an ongoing project to do the games in it in languages other than BASIC.

The languages they’ve chosen are:

  • Java
  • Python
  • C#
  • VB.NET
  • JavaScript
  • Ruby
  • Delphi / Object Pascal
  • Perl

I no, it’s sad. No C… But given that it includes C#, I’ll let them off.

Using JSON as a datastore in C#

Using JSON as a datastore in C#

Shapes
Image by Gerd Altmann from Pixabay

For some not too complex applications, JSON can be a very handy way to store data rather than say using a database. It also has the advantage of storing data of varying sizes. For instance Lists with varying numbers of items. I created a Saveable generic class below that you use as an ancestor class for that you wish to Save/Load an IList of whatever.

 

 

    public class SaveAble<T>
    {
        private string _error = "";
        string LastError()
        {
            return _error;
        }
        public IList<T>? Load(string filePath)
        {
            if (!File.Exists(filePath))
            {
                Log.Error("Missing file {filePath}");
                _error = $"Missing file {filePath}";
                return null;
            }

            var content = File.ReadAllText(filePath);
            if (string.IsNullOrEmpty(content))
            {
                Log.Error("{filePath} file is empty");
                _error=$"{filePath} file is empty";
                return null;
            }

            return JsonSerializer.Deserialize<IList<T>>(content, new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true
            })!;
        }

        public bool Save(string filename,IList<T> collection)
        {
            var options = new JsonSerializerOptions
            {
                WriteIndented = true,
                PropertyNameCaseInsensitive = true
            };
            try
            {
                var bytes = JsonSerializer.SerializeToUtf8Bytes(collection, options);
                File.WriteAllBytes(filename, bytes);
                return true;
            }catch (Exception ex)
            {
                _error = $"Exception:{ex.Message}";
                return false;
            }
        }

    }

Just define your class MyClasses from SaveAble<MyClass>

where MyClass is the class you have a List of. Then you can do

MyClasses myclasses;
myclasses.Save("filename",List<MyClass>) and

List<MyClass> list = myclasses.Load("filename");

It is fast. On my PC (now six years old), it can load a 99,000 line JSON file in well under a second.

Why C# for the server?

Why C# for the server?

https://commons.wikimedia.org/wiki/File:Csharp_Logo.png
From Wikimedia

There are plenty of other programming languages that would do.  Programming languages are just tools but C# comes with several advantages.

  1. I know it pretty well, having been using it since 2005.
  2. With .NET 6 (and 5), it’s easy to create applications that run on Linux. This lowers the cost for hosting. I’m setting the game on a low cost VPS.
  3. Also on Linux, ASP.NET works pretty well for both Websites and Web Apis.
  4. I like some of the recent changes in C#. And Visual Studio 2022 Community Edition is pretty good. For instance the JSON handling has got better and better.

Do you know what Hello World in C# looks like now? Here it is in its entirety.

Console.WriteLine("Hello, World!");

That’s a console application. One line! Follow the link for more details about the C# templates. Note, there’s no usings there either. That’s because applications now start with a default set in C# 10 and .NET 6 (you get both if you install VS 2022). And if you want a particular namespace that you’ve written to be available to all source code in a project, you can just add this:

global using xyz;

And it becomes available everywhere without needing any more usings.