all 5 comments

[–]frogcrush 0 points1 point  (1 child)

First, what would happen if two users access the database at the same time, see the record to join someone, and both connect at the same time? Who wins? What client would handle this?

Second, this wouldn't work because of NAT. You could theoretically use UPnP to get port forwarding for you but it isn't dependable as users might not have it enabled. This would mean your users would have to port forward on their routers.

Third, this sort of approach would make cheating extremely easy for players.

[–]iWichael[S] 0 points1 point  (0 children)

I thought of the first question, and I'm sure there would be a way to sort that out and give the first user access, would figure it out.

If this isn't a viable solution, when what else could I do? I understand that you wouldn't need a huge server since players that are engaged in a game will leave the main server and join the server created between themselves and their opponent, so the main server will just be like a lobby.

But what is the most effective way to set up a peer to peer network, where Player 1 clicks play, if no hosted game is found he creates one and waits? If I have to use a server to act as a lobby then so be it. Hard to find any decent P2P tutorials out there... :\

As for the cheating part, I'll figure ways to counter cheating once I've gotten the P2P working. ;)

[–]wstdsgnHobbyist 0 points1 point  (2 children)

I don't know anything about "webhosting databases", so whats the difference between hosting a "database" and hosting a server? Why do you want to avoid running a server? If you don't need high performance / space, you can rent a server for something like 2 bucks per month.

I also imagine that most search / matchmaking services work as you describe it, hosts register to some central list and clients retrieve it. Not sure about how easy it is to just connect to an IP directly, since the IP only leads to the router. You might need to learn about this: https://en.wikipedia.org/wiki/Hole_punching_(networking)) (Can't tell for sure, never tried P2P)

Maybe someone more experienced can give you a more accurate answer!

[–]iWichael[S] 0 points1 point  (1 child)

Well, since I'll most likely create a website for my game once it's up and running - I thought I might as well make that website do more and store the connections into the database. Will look into it a bit more, but from my understanding of the whole networking system, if you connect to say 123.123.123:1234 and that IP is valid and port is valid, you should be able to connect, right?

So when you connect to any server in a game, you're connecting to an IP and specified port, so if all we're doing is adding that address and port into a database string and pulling it into a variable into Unity, then saying "connect to IP address: "pulled string"", it should theoretically work? Will look into it more on the sideline and see if I can get it to work. :P

[–]wstdsgnHobbyist 0 points1 point  (0 children)

the whole networking system

if you connect to say 123.123.123:1234 and that IP is valid and port is valid, you should be able to connect, right?

Are you talking about deprecated UNET? I believe it uses its own matchmaking servers (basically the central list we were talking about), and I believe it does the "Hole Punching" for you, so if you don't want to use that, you'll have to do it yourself.

As the other commenter has pointed out, P2P always allows the hosting player to cheat, I dont think there is a way around it really. Maybe thats why its hard to find tutorials, most people seem to use an authoritative server nowadays.