Game Development Community

T2D Turn Based MP

by Chris Labombard · in Torque Game Builder · 11/22/2005 (7:34 am) · 40 replies

I saw Matt's plan about his awesome multiplayer advancements in T2D but I can't find the actual code anywhere... or how to use it (if it's in the current build)

Could someone please point me at it? I'd really like to build a MP game this weekend.

About the author

I have been a professional game programmer for over 5 years now. I've worked on virtually every platform, dozens of games and released a few of my own games, including 2 iPhone titles and a title waiting release on Big Fish Games.

Page«First 1 2 Next»
#21
11/22/2005 (1:26 pm)
While I agree that T2D in its current state (on my Mac, and at idle, it takes 90% of my processor, which is fine for a single-player game but unacceptable on a server), it is not a perfect match for a server app. There is nothing saying one CANNOT use it on the server side.

As far as I know, the TScript still has "listen" properly built into TCPObject. That alone makes T2D a match for a server. I know for a fact the TCPObject works extremely well as a client (I have an MP base laid out, but I'm using a TCL script to act as my server).
#22
11/22/2005 (2:32 pm)
OK, perhap "CANNOT" is a little too harsh... because there are several kinds of online games... but I've been commenting on casual games, not dedicated full-screen games. Here's the 2D break-down as I see it:
1) Arcade -- think of Gauntlet on Xbox 360 Live Arcade, where you have up to four players simultaneous, all on their own Xbox 360 game console.
2) RTS -- think of Warcraft II, AoE 1 or 2, etc.
3) Hearts & Casino games (casual games)
4) Turn-based "play by web" -- think of Laser Squad Nemesis

I'm sure there's others... for example, I'm not sure where Civ falls.

OK, of these, #1 and #2 are going to use peer-to-peer networking. They will probably use a web server to do "game discovery". A great GG example here is Zap! For #3, these games typically have a different client than server. The client is flash, PopCap, ActiveX, Java, T2D, etc... but the server is generally going to be something much cheaper to host like PHP, Java, ASP, etc. Category #4 is what used to be known as "play by e-mail" where the server manages the "truth" and dispatches "moves" to each player. These are now largely built with Web Services using ASP.NET or Java.

CommandToServer and CommandToClient help with you do peer networking with one machine "acting" as a server. I'm not trying get people to think that these commands aren't valuable. I'm just trying to help people put them into perspective for when they are useful, when also overlaid with how games of different network styles use different backends. I've been commenting on case #3 all throughout this thread and still stand by my claims. I would not use T2D as my server app for category #3, because you are going to have to go and build a whole "game discovery service" then, which cannot be powered by a Torque backend.
#23
11/22/2005 (2:38 pm)
Actually, here's another way to slice it:

If you want peer networking you can:
- use T2D as client and server
- you will need to build a game discovery model using a different server backend
- because one of the players "is" the server, hacks to that game give that player an advantage in a way imperceptible to others

If you want true client/server with server-side protection:
- do everything as above, but host the servers yourself and broadcast the URLs to people.
- get ready to pay a pretty premium for web hosting

If you want client/server with server-side protection and lower hosting costs:
- build a rich T2D client
- build a game discovery PHP page on your server
- build a "game backend" that stores the game state from turn-to-turn for each player in each active game
- have your T2D client request the game state from server at appropriate intervals
- hosting will be as cheap as you need backend power, with PHP being cheapest
#24
11/22/2005 (3:04 pm)
Chris, recall the thread where we discussed high score fetching/saving to PHP? You can use this exact approach to also implement a multiplayer client/server arrangement, whether the 'server' is a host Torque machine that is 'listen()'-ing on a port for the connection, or a java/php/whatever server that represents the state of the game and players connected.

I started with php and had a few things working fine, but switched to java because I wanted a lot more stateful-ness and flexibility in my connections.

As Jason points out, unless you're aiming at small groups of players that trust each-other (or don't care), you'll probably want to investigate a dedicated game server implementation so you can govern the fairness of the game state.
#25
11/22/2005 (3:15 pm)
I thought Zap used the master server included with TNL.
#26
11/24/2005 (10:55 pm)
Btw the T2D 1.1 Alpha should have commandToClient and commandToServer working, check out the chat room example :)
#27
11/25/2005 (3:59 am)
Thanks Matt. I figured it did.
#28
11/30/2005 (12:39 pm)
I took a socket library wrapper I wrote and added it to the T2D engine. Then I created a server executable for the client(t2d) to communicate with. It works well and wasn't all that difficult.

If you have any knowledge of tcp socket programming it shouldnt be hard to get something working.
#29
03/17/2006 (5:20 am)
Could someone please clarify something for me?

I'm about to implement a turn based multiplayer game but I don't know enough about the concepts behind what's going on. I've been through the checkers demo code and that's where the majority of my questions are from.

1. I noticed 2 commandToClient calls being made for each action. So one client acts as a server and a client but it still has to communicate with itself through commandToClient()?

2. Does the client, who is the server, hold 2 checkerboards? One of his own and one that is the servers?

3. Is the server just making sure all the clients have the same gamestate or is it supposed to be responsible for something else as well?
#30
03/17/2006 (7:54 am)
Through reading the forums I eventually found out that you can instantiate 2 isntances of your game on the same machine if you are using a debug build (which I am)... So I put in a wack of echos and started mucking around to see if I could figure out what was going on.

It looks like the server and client both create a ClientCheckerBoard and a ServerCheckerBoard, even though the one client doesn't appear to need it.

Both instances of the app are treated as clients, with one client running the server commands. The server portions of code run the game logic, with the client portions of code just make things look right and allow the user to do things.

If I'm wrong please correct me, as I'm about to start coding my own implementation.
#31
03/17/2006 (8:38 am)
So far what you have discovered is correct :) Though there is a ClientCheckerBoard and ServerCheckerBoard for a reason... both derive from the same CheckerBoard ScriptObject class and have access to the same move checking function... so the client has an identical board as the server so when the use requests to move a piece and/or requests to place a piece it checks its own board first to see if its legal, if not it doesn't bother requesting it from the server, if it is valid then it sends a request to the server and the server then checks its board.

This way the server is the final word, though it doesn't send any 'obvious' moves that aren't legal. The client boards should match the server board exactly, but if for some reason someone were to exploit the game and manipulate their board it wouldn't make a difference since the server does the deciding check :)

Since one client is acting the server as well you could say it may not need it, but I wanted to design it to not have special cases for the hosting client, I wanted it to treat them both the same, that way the hosting client still has to go through the same checking process and still doesn't have direct access to the server board.
#32
03/17/2006 (8:39 am)
Btw on the first page of the Checkers Tutorial I inform you that you can run two instances of TGB in DEBUG on the same machine :)
#33
03/17/2006 (8:46 am)
I never found the checkers tutorial in my searches. I just studied the source code.

Is there a reason that both clients have an instance of the ServerCheckerBoard? You'd think they should both have a ClientCheckerBoard and only 1 should have a ServerCheckerBoard.
#34
03/17/2006 (8:49 am)
In Torque networking one client hosts and the other client connects, though you still treat both as clients.

Only the hosting cilent has an instance of the ServerCheckerBoard.
#35
03/17/2006 (8:51 am)
If you have the latest version (1.1beta 1.1) then the Checkers Tutorial .pdf should be in the documentation/tutorials folder :)
#36
03/17/2006 (8:54 am)
I put an echo statement in both initClient and initServer right before the boards are created and both clients echoed both statements. Does one get deleted? or does one just not get used? or am I insane ?
#37
03/17/2006 (8:56 am)
Sorry, I should've said that only one ServerCheckerBoard gets used... I still called the creation scripts on both side but only the one on the hosting side is ever referenced... (forgot I never went back and made that a little better, though the extra script object really has no relevance in game memory- I did the Checkers Game in about 2 days).
#38
03/17/2006 (8:58 am)
Ya, that's what I figured (I know the code fairly well now)

Thanks for the clarification.
#39
03/17/2006 (9:01 am)
Glad you are looking at the demo scripts... I think the tutorial is very good though the Checkers Demo has a lot more to it than I could get into a 45 page tutorial.
#40
03/17/2006 (9:07 am)
I can only imagine the difficulty of cramming all that info into the tutorial. I almost always learn faster from reading code, so having access to the source for it is awesome.
Page«First 1 2 Next»