Code game logic and then add server logic?

I have been coding away basic functionality on my game, getting stuff to work. However its core design is a multiplayer game, so there will have to be server/client code put in there. Should I be doing this now, or should I try and code it from the ground up to be netcode?

The reason I ask is because looking at the scripts, there are some things that might be global variables, which means only one player at a time can be affected.

Any advice is totally appreciated.

anothervenue,

When I make multiplayer games I tend to start off with everything being multiplayer so that I don’t accidentally paint myself into a corner. Certainly if there is some kind of logic that is definitely standalone you can work on it in a bubble first, and then bring it into the game. But I typically write my ElectroServer code and client (Flash or Unity) code in lock step. Although I sometimes I wait till down the road to add any server validation.

Well right now the code is basically player behavior on their own, movement, control, basic level/collisions and the collecting of items. The items should be a networkInstantiate so I don’t think I am too far off the beaten track.

Does electrotank have its own set of coding to learn or does it just hold the info for unity? I guess I mean, what are the upsides?

-Lucas

Lucas,

ElectroServer has a C# API that can be used with Unity (through JavaScript or C#). It doesn’t have any special Unity things built into it though, like networkInstantiate - that isn’t part of the API.

Benefits to using ElectroServer over Master server? Scale is a big reason. From what I’ve read by others on this forum, Master server seems to only support up to maybe a few dozen to maybe 100 or so concurrent users. I’m sure someone will chime in to correct me on that statement.

Obviously it depends on what you are doing, but ElectroServer can support extremely high numbers of concurrent users. The API is well written and the server has tons of features that have been added over the last 8+ years. TCP, UDP, HTTP connection types. Built-in AES security (optional). You can work with strictly typed objects that are serializable over the network in a very light-weight way. etc

ES does not have server-side authentication of Unity maps built-in. That is a bit plus for the Master server, so long as you are ok with low concurrency.

The Master Server is just a lobby server, “brokering” P2P connections. A host game registers with the MS, then clients query it for a list of available games. Once the client connects to a given host, the MS is not longer part of the picture (apart from possible NAT punch through using the Facilitator). Concurrency is irrelevant where the MS is concerned. Not sure what you mean by “server-side authentication of Unity maps” either.

Perhaps you are confusing the purpose of the MS with a “headless server” version of a game, which is a “multiplayer server” in the more accurate sense of the word. I.e. an authoritative simulation of the game that clients connect to. Genuine client/server, as opposed to P2P where either one of the clients is also a game host, and/or each client is authoritative over gameobjects it owns/creates.

In terms of security and performance, you generally want to have a headless server running on a fast machine with fat pipe. This is where latency and concurrency become an issue. Nothing wrong with a P2P game – MP games did this for decades, and many continue to support this, esp. on PC – just that you are going to have to “trust” the security and performance of an user’s machine running your game server.

All that said, you should definitely code your game with MP in mind from the very beginning. You will save yourself a lot of time and trouble in the long run. “Putting multiplayer in” at the end generally results in bad, buggy MP.

EDIT: On further thought, perhaps your Electrotank product performs both MS and game server functionality, I don’t know. But in strict Unity terms, the purpose and function of the MS is limited to brokering, and is often misunderstood/misrepresented. It is NOT a game/multiplayer server.

Bren,

Thanks for the added information. Indeed I was confusing Master server with running Unity headless on the server for validation. I do think that concurrency is still an issue with P2P because of that type of network structure…you just can’t scale all that huge. I know that it works for some games, but when you want to go massive I think you need to go with a server-client structure.

To respond to your edit - ElectroServer doesn’t facilitate P2P connections. It just works for client-server games.

I guess I don’t need massive scaling as a session of my game is 6 players.

Where would I start? I looked at the networking code example, but that doesn’t really tell me much.

The Zero to Hero Networking guide is a great place to start, I went through it last weekend and have just about everything i need working.

Is that the code example you are referring to? I would have a hard time believing you didnt get anything from it.

I was talking about the one you can download from the Resources page.

http://unity3d.com/support/resources/example-projects/networking-example