• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

anyone done any netcode before for online multiplayer?

purbeast0

No Lifer
i'm currently working on a turn based game for mobile platform using the unity3d engine. it's pretty neat/powerful so far. the game is nothing groundbreaking or anything like that, but i have the basic gameplay and scoring working now.

so last night i started to look into the netcode portion of it. this area is 100% a blackbox to me and i have no experience doing anything like it. i started with this tutorial here:

http://www.paladinstudios.com/2013/07/10/how-to-create-an-online-multiplayer-game-with-unity/

i didn't get too far last night just because i was busy wrapping gifts with my wife, but i got to the part where i tried to run two instances of the game to test out the network/hosting stuff, and it didn't work, and i didn't really have time to debug, but i'm going to mess around with it tonight.

i was just curious if anyone here has done this before. the tutorial this is for isn't quite turn based, it's more of having the action update real time. that isn't what i really need to do at all. it's more of a player A waits while player B goes, and vice versa. again, i haven't gotten far in that tutorial at all so they might get into it down in the later parts of it or at least give me an idea how to go about that.

anyone done anything like this before? any tips or things you would do differently if you were to do it again?
 
I've done some amateur stuff using both JMS (which I don't recommend) messaging each other and multiple view's polling a server with RESTful calls.

It was all for turn based games (Othello, Mastermind, Chess, and a Scrabble type game) for a project. It wasn't terrible, but I am sure there are much better ways to do it.
 
so yeah i've been working on this online game in my spare time the past few weeks and man, this is A LOT more complex than i first anticipated lol. but i am finally making some progress.

so i started writing my stuff in javascript. unity uses c# or javascript, you pick.

after basically writing the basic gameplay in JS, where i could play locally with 1-4 players on 1 device, i started looking into the netplay stuff and other libraries.

turns out, javascript was a bad idea. all of the libraries are in c#. i'm using quite a few 3rd party libraries now, and they are all c#.

the problem is you can have the JS and C# code talk, however when you want to go back/forth, it is tricky because you have to make sure the right flies are compiled in the right order.

so i ended up spending like 3-4 hours just rewriting my code in c#.

once that was done i started looking at the online stuff. i'm using a backend service called GameSparks right now, and so far, really liking it.

in my game i have it set up so you can log in with facebook and get a friends list with facebook, and send challenges and game invites to your facebook friends. it's all asynchronous in the way it works. and i'm now at the point where i'm figuring out how to take turns playing the game.

and at this point, i now understand where they say "if you are writing a multiplayer game, write all of that code before the game code" because i'm basically having to re-write everything lol. basically all of the game logic as far as keeping score and taking turns and what not, has to be rewritten.

but the good thing is, it will make the code base significantly smaller and more organized, which also may be an artifact of me getting the hang of unity a little bit more as well.

once i get the multiplayer stuff working, then i'm going to work on the looks of the game because right now i'm just going for functionality.

but man, i have to say, this is A LOT more complex than i initially thought it would be. just so many systems talking together and coming together to make it work. i have the facebook api talking to the unity api talking to the gamesparks api, with it talking to gamespark code running on their cloud server, then i'm using another library called NGUI for the GUI buttons and stuff. it's really cool to see it all coming together though.
 
Just curious, since you are redoing everything, is the code deterministic, and are you going to offer replays (as in, replay a game that has been recorded) ?
 
Just curious, since you are redoing everything, is the code deterministic, and are you going to offer replays (as in, replay a game that has been recorded) ?

i'm not going to be doing any replays. however, the actual game data will be stored on the server once the game is done. i plan to keep some kind of backlog of your previous games if you want to see the scores and stuff.

after every move, it basically updates some data and stores it on the server. the scoring in my game is just one object per player, so that data will be there even when the game is finished, unless i specifically delete it i think.

i'm not sure what you mean by the code being deterministic.
 
I just meant that, since there is a MP aspect to this, you want the same behavior on all machines, no matter what it is run on right ?

If the server does most of the work, that don't matter much, but, once you start getting different clients, and different platforms involved, and each of them do calculations locally, you need to have the same results on each platform.
 
I just meant that, since there is a MP aspect to this, you want the same behavior on all machines, no matter what it is run on right ?

If the server does most of the work, that don't matter much, but, once you start getting different clients, and different platforms involved, and each of them do calculations locally, you need to have the same results on each platform.

i'm still not sure what you mean.

whether the game is being played on android or ios, it will be hitting the same code path on the client and the server.
 
after every move, it basically updates some data and stores it on the server. the scoring in my game is just one object per player, so that data will be there even when the game is finished, unless i specifically delete it i think.
So you're saying every move is stored on the server, even after the game finishes? If so, and if the other actions by NPCs and/or the environment are deterministic (meaning predictable), then the game could be replayed like a movie, but from any position.

Even if a random number generator is involved, the code might be deterministic if you have the right "seed" numbers to plug back in. But that would make it harder.
 
So you're saying every move is stored on the server, even after the game finishes? If so, and if the other actions by NPCs and/or the environment are deterministic (meaning predictable), then the game could be replayed like a movie, but from any position.

Even if a random number generator is involved, the code might be deterministic if you have the right "seed" numbers to plug back in. But that would make it harder.

there are no NPC's or AI in the game. it's strictly user to user play. think the style like a tictactoe game.

every "move" being stored on the server is just because when the game starts, the score (data structure) is zero'd out and initialized. then when the game is over, every value is stored in the structure and each object has a value.

i am not keeping track of when each item get's the score though, so now that i think about it, there isn't a way (right now) you could replay the entire game. you could see the entire scoreboard for every game, but you won't know what order the scores were filled out.
 
I just meant that, since there is a MP aspect to this, you want the same behavior on all machines, no matter what it is run on right ?

If the server does most of the work, that don't matter much, but, once you start getting different clients, and different platforms involved, and each of them do calculations locally, you need to have the same results on each platform.

i'm still not sure what you mean.

whether the game is being played on android or ios, it will be hitting the same code path on the client and the server.

He is asking if you do any kind of any calculations on the client end (i.e. do you add 2+2, or more importantly do you add 2.5+1.5?) because clients on different platforms can and will get different answers to those kinds of things (you would be surprised). It is why a lot of things will be done such that you instruct the server what you are doing from the client, and let the server implement the results.
 
Last edited:
He is asking if you do any kind of any calculations on the client end (i.e. do you add 2+2, or more importantly do you add 2.5+1.5?) because clients on different platforms can and will get different answers to those kinds of things (you would be surprised). It is why a lot of things will be done such that you instruct the server what you are doing from the client, and let the server implement the results.

yeah all game logic that keeps the score is done on the backend. the front end just displays the data to the enduser for the most part. but it is not a logic intense game or anything either.

there is front end logic that calculates some scores though, but it's literally just adding numbers. and if one platform can't get 1+1 = 2 correct, then that platform should probably be made obsolete lol.
 
Back
Top