GLBasic forum

Main forum => GLBasic - en => Topic started by: Omadan on 2014-Jan-08

Title: Advice on Turn Based Online Game
Post by: Omadan on 2014-Jan-08
Hi guys, hope all you guys have had a blast during xmas, new year and so on.

It has been a while I have been completely inactive. 6 months with no programming :)

Anyway, I am working on my board game (think of monopoly) and I really want to make this online 2-4 players.

What is the best way to achieve this in GLBasic.

I want to support ios and android, is this achieveable with GLBasic TCP Sock or is there a better way.

Anyone who knows, please give me the best advice.

Regards
Title: Re: Advice on Turn Based Online Game
Post by: MrPlow on 2014-Jan-08
First off - I would think you would need a Webserver Database to store all the turns etc.

Php and Mysql with posting from glbasic app to form parameters on dedicated page for receiving order turns.

Haven't used much of the net commands yet but plan to soon for web high score table database.


Wish you luck!

Title: Re: Advice on Turn Based Online Game
Post by: MrTAToad on 2014-Jan-08
All move information could be handled by the computer running as the server, and which could be passed to each player when needed.

Whilst TCP could be used, you cant use fancy things like broadcasting available games.  You would also need to write a system that detects when someone has left.

You could mix the two though (although not at the same time) - use UDP for broadcasting games and TCP for the actual game (and detecting when someone has left), although not all cases may be detected...
Title: Re: Advice on Turn Based Online Game
Post by: Omadan on 2014-Jan-08
Thanks guys for the replies. Can this be achieved with players hosting their own sessions so I do not have to host a server of my own... Eg Write a php script which will pair you off with other players. Once this happens you get removed from server. This means server is just a central system to match ip's. Will people be able to act as servers from their iPads. At the end of the day it's just a 2-4 player turn based game.

Will I have firewall problems like this? I heard about udp hole punching, is this the way. Then tcp will be used to effectively communicate with each other while sending heartbeats every so often to keep channel alive.

Hope you understand what I want to achieve. But my game needs to be online so I have no other option.
Title: Re: Advice on Turn Based Online Game
Post by: Moru on 2014-Jan-08
A simple lobby coded in PHP on a public webserver for pairing off.

GLBasic server accesses a PHP-page similar to this:
http://www.example.com/server_register.php?ip=xxx&port=yyy&name=zzz

Random port number so more than one player can exist behind the same router. I'm not totally sure they can actually play with eachother though, might have to do some UDP broadcasting to find local games.

The GLBasic client does a simple download of a page with list of all games, ip- and port-numbers.
http://www.example.com/server_list.php:

---clip---
My-server;55.123.2.81:35821
Their server;55.123.2.82:27910
Leet server;55.123.3.89:6823
The neighbours;55.123.6.87:3556
---clip end---

All GLBasic servers continuously sends heartbeat to server with UDP on the randomly selected port given to server. This to keep the UDP hole open.

New players sends request with UDP to the random port on the server and they pair up giving the return IP and port.

All communication with client/server are done over UDP with send/ack/resend if needed.
Make an array of data to send, delete it when you get the ack from server/client (ack = acknowledge received package).
There are very good tutorials on this way of communication for Quake 2 for example.
Title: Re: Advice on Turn Based Online Game
Post by: spacefractal on 2014-Jan-08
You cannot match ip and ports at all only, and also not on UDID stuff too (Apple reject them now, and Android can even change that as well). They can all changes from time to time. Users with Dynamic IP would not play the game, and they can even changes network too as well.

Only way is doing based on a shared group id and send to a server with account system.



Title: Re: Advice on Turn Based Online Game
Post by: Omadan on 2014-Jan-08
Seriously rofl.

How can I turn this into a online game then?

Space can you please expand on how to do it the way you say.

More info is needed if you do not mind.

Can I host a server and people connect directly to that? With sock tcp. What's the point of having sock commands then ?
Server/client model.

I'm a bit baffled. Thanks guys...

Btw: space I think you are Spanish right? I can speak with you in that language if it's better for you. :)
Title: Re: Advice on Turn Based Online Game
Post by: spacefractal on 2014-Jan-09
Im have not tried that, but I'm are from Denmark (so im danish). Here we often don't have real ip number, but internal ip numbers (etc I'm have around 10 connected devices).

I'm did a server based once for over ten years ago, but here the whole game was sololy in php (it's was a Danish 12 dice yatzee game).

When uses a server client model, from glbasic point it's mostly would uses http requests.

Howover if you only plans a internal turn based game, property you coud checkout the game network commands. That should do the job.

Alternative it's could also been a email based game as well (sending savegames trough email). But not sure how that works.
Title: Re: Advice on Turn Based Online Game
Post by: Moru on 2014-Jan-09
Spacefractal, UDP hole punching works fine behind routers on local IP or dynamic IP, doesn't matter.

If you just want a turn-based game you don't need any UDP at all, just do normal http-requests to a server that does all the communication with the devices. All platforms can communicate over http. The tradeoff is how often you want to request new data from the server. Do it too often and you drain more battery, do it too seldom and your users will get bored.

If you get baffled from thinking about network code, don't feel bad. There is a reason not all games have access to network :-)
Title: Re: Advice on Turn Based Online Game
Post by: Moru on 2014-Jan-09
Quote from: spacefractal on 2014-Jan-08
You cannot match ip and ports at all only

What is it you can't match on IP? Is apple blocking network communication for games?
Title: Re: Advice on Turn Based Online Game
Post by: Omadan on 2014-Jan-09
Thanks guys for all replies.

I really appreciate this.

I think http-requests are the way, as I want this to serve for many platforms and a guarantee that it will work.

So for hhtp requests I would use Sock TCP right?

And will apple accept this or do we have another problem there, I really do not like to get down to this and have it rejected, time wasting is a no-no for me :)

Thanks guys.
Title: Re: Advice on Turn Based Online Game
Post by: Moru on 2014-Jan-09
For http requests you just need NETWEBGET$ <--- the $ is important here :-)

If apple accepts or not is a different problem, this I know nothing about.
All I know is that you need a unique user ID and this needs to come from the server, I know they are not happy with using the phones ID-number or anything like that.
Title: Re: Advice on Turn Based Online Game
Post by: spacefractal on 2014-Jan-09
NETWEBGET$ is all matter on this. Most time is used on the server part. On apple and ios7 there is only a ads based is left to been used. MAC address can't even been used anymore (in ios7 all phones returns the same Mac number).

So it's either email and/or account based system.
Title: Re: Advice on Turn Based Online Game
Post by: Omadan on 2014-Jan-09
Guys thanks again. Ye thats what I thought, using Netwebget$. Ive used this on most of my games for online scores together with PHP. Ill create unique id's for every registered person and that will be your ID. This ought to work with Apple terms I hope.

I thank you all.
Title: Re: Advice on Turn Based Online Game
Post by: spacefractal on 2014-Jan-09
its cant really been done for iOS 7 anymore with removed all stable udid (there is a ad id, but that can change on app reinstall). If you uses UDID, you wont been able to upload to iTunes Connect at all, but instead you can create unique ids for the username inserted in the game. Somesort in that whay hiscore works.
Title: Re: Advice on Turn Based Online Game
Post by: Omadan on 2014-Jan-09
Ye that what im talking about Space :)

I am going to let every user have a unique ID - their name for example.

Hope this is okey.
Title: Re: Advice on Turn Based Online Game
Post by: matchy on 2014-Jan-10
Netwebget$ is not enough as commonly used are web api calls to databases. So anyone got a nice json parser?
Title: Re: Advice on Turn Based Online Game
Post by: spacefractal on 2014-Jan-10
or whatever name they using, that is the way to go. Its might still take time to do a account based system for id, if you not planning to do using email for sending games (which would not require such a server).
Title: Re: Advice on Turn Based Online Game
Post by: Moru on 2014-Jan-10
Quote from: matchy on 2014-Jan-10
Netwebget$ is not enough as commonly used are web api calls to databases. So anyone got a nice json parser?

If he is making the server, he gets do decide what to use :-)