Networking Rework Again!

Mirror Networking

Well, here I go again.
I finished moving my multiplayer TicTacToe to the new networking system using litenetlib and it worked beautifully! I had to do a complete rewrite on the relay server also. In the end, everything worked great and the world was happy!

I then excitedly decided to work on the multiplayer pong game. The whole reason for the TicTacToe game was that it is one of the easiest games to write, its turn based and perfect to use for my first multiplayer game. So when I finished that, I figured I need to work on something that had some live action, synchronized objects, player movement, etc. Thats where pong was a perfect choice.

I got all the way to the end where I was trying to sync the player paddles and the ball. I spent a few weeks trying different things but ultimately in the end, I decided to look at other Networking solutions, preferably something that already had syncing of variables under the hood. With LiteNetLib, you have to write your own syncing algorythms, and that is definitely not something I could pull off. I got pretty close a few times, but something would always cause it to get out of control.

Photon Pun2
The first thing I took a look at was PUN2, or Photon for Unity Networking, version 2. Due to the type of architecture I wanted, I needed to create a seperate server that manages the clients, not so much the game, but the clients themselves, somewhat of a matchmaker with more control. Photon Server seemed to fit the bill perfectly, at first anyways. After diving into it, I came to realize real quick the lack of documentation. Without this, its damn near an impossible task. Getting PUN2 working with the server was pretty easy, but in order to get the server to do what I wanted, was requiring too much research, forum posting and begging for information. I finally decided to go with Mirror.

The downside of Mirror is pretty close to the same as Photon, lack of documentation. Very abstract or high level examples that are tough to understand and not too much information available, at least for what I was looking for. I finally decided to sponsor it and get access to premium help, this was well worth it. In the end, after a few weeks, I got going in a good direction and should hopefully be able to get the Multiplayer TicTacToe rewritten using Mirror soon. A few good things about Mirror is that it was based on the original Unity Multiplayer UNET, its open source for those that get off on that sort of thing, tons of examples (If you can understand them, not for the basic type like me) and once you get a grasp of it, it gets easier to understand and implement.

I just wanted to give a quick update, document my progress and take a break from spewing code, lol.

Ok, back to it! See ya on the next one!

Multiplayer Tic Tac Toe

Well it seems I never did a post on my Tic Tac Toe game so now would appear to be as good as time as any to do a little write up about it, explain the reason behind it and some of the things I ran into while creating Multiplayer Tic Tac Toe!

TGR Multiplayer Tic Tac Toe

I originally picked Tic Tac Toe as my base game as I dove head first into multiplayer coding. Its just about as simple as a game can get and wouldn’t require too much game code as opposed to the multiplayer code required to get things working across networks and devices. During this time I spent months researching all the different architectures, methods and solutions people were using out there from third party addons like Photon, Node.JS, Mirror, Litenet, etc to the integrated Unity UNet solution. I did as much research on each of them as any sane person could tolerate, looked at examples, tested demos and attempted to write basic chat programs with some. In the end I just chose to use Unitys UNet. It was easy to understand and easy to implement. Of course this was after a lot of trial and error.

The main basis for multiplayer is that you have multiple devices sending and receiving messages to each other. The base for my network was how these devices would interpret the messages and act accordingly. One of the first hurdles I ran into was while looking into peer to peer networking. There are quite a lot of issues with this structure which can grow depending on which devices your setting up the network on. With mobile phones, based on what I remember (This was over a year ago (I think)), mobile phones have a tough time hosting games while computers have a hard time punching through the router to host games and allow people outside the network to join. While some of the available network solutions had answers for these kinds of situations, I opted for a simpler remedy, its a called a relay server.

Most big multiplayer networks like Steam for example, will push players onto their relay servers when they can’t get around router issues, from what I read anyways. This was the perfect answer for my situation, especially since I was looking at creating simple turn based card or board games. The downside to this, for me anyways, is that it required a hosted server that I could use to run the relay server on, outside of my home network to make it easier for people to play against each other.

Ultimately I succeeded in writing my relay server that could handle people hosting tic tac toe games or joining tic tac toe games. I ran into a few issues with allowing people to log in in order to save stats, a logged in player playing against a non logged in player, registering players and quite a few other things that needed ironing out. In the end, I was very happy with the overall structure of my multiplayer network.

A bit after I finished the Multiplayer Tic Tac Toe game and my Relay Server, quite a bit after actually, unity decided to trash the UNet and make it obsolete. I said of course they did, thats just because I decided to use it! They are promising a new type of integrated networking system but after they trashed what they already had which I used, why would I use another network system they create? What if they decided to trash that one in the end too?

Here I was again, looking over all the different networking systems I could use. This meant having to port my existing Relay Server and Multiplayer Tic Tac Toe game over to the new library. In the end I decided to go with LiteNetLib due to how light weight it is, how easy it is to understand and how quick it was to implement. Of course my completion of the port is still a work in progress, but once I can get back to being focused on it, I will update this post!

Thanks for reading and if you have any questions, please leave a comment below!

Edit 3/28/20:
Well, its been awhile but after dabbling with mirror a bit and deciding not to use it, I completed the integration of LiteNetLib. So now my networking system is complete using LiteNetLib. I also changed the login sytem so that a user can just use a username, email and password to save their stats, no more logging in or registering to the website.

Edit 5/10/20:
Lol, I completed TicTacToe using LiteNetLib and moved on to Pong. Things didn’t go too good when I tried to get the objects sync’d between clients. I went back to Mirror since they have a Pong example and you can use SyncVar to keep things sync’d!

Multiplayer Browser Games and the Big Deal!

Hello All!
I just wanted to write up a quick update on my progress with the website and creating multiplayer browser games. I’ve been hard at it for months and during that time I have looked into every possible scenario when it comes to creating and publishing browser based games that can be played in a multiplayer environment. After spending all this time writing prototypes, examples and test projects, I have finally decided to move away from it. The biggest reason is due to the very high maintenance of these kinds of projects. The fact that you really have to have a dedicated server to handle the games, data and information. With all the available options out there for this kind of structure, it can get pretty heavy really quick.

One of the biggest setups for this kind of system is the Node.js. In order to incorporate this system along with using wordpress, it quickly become pretty bloated. That was even before I included 1 line of game code! I wrote a log in server and a chat system that were pretty functional, but in the end I just didn’t like it. At all. This was after a few months of trial and error with it. Eventually I decided to move away from the whole Multiplayer browser based game idea and focus on pure stand alone Multiplayer Games.

I will be using Unity of course and I still plan on creating the type of games I have listed on the home page. I pretty much just finished up with my core networking code that will pretty much be used as a template for all my games. Of course, over time this will change as new features get added to the core base code or things change.

The first game I will be completing here shortly will be Tic Tac Toe. Its a basic game that doesn’t require too much game code and an easy to implement way of testing out the network code. As soon as I get done with the game, I will post it in the games section.

As always, if you have any comments, questions or feed back, please let loose in the comments section below!

Thank you!