Game Development Community

Multiple clients on TGB without source?

by Love Dahlgren · in Torque Game Builder · 03/12/2008 (8:40 am) · 14 replies

I'm new to TGB and didn't buy the pro version with the source. It seems that the engine doesn't support more than two players, is this true?

I want to create a turnbased strategy game (risk-like) with support for at least 6-8 players.

Thanks

About the author

Recent Threads


#1
03/12/2008 (9:14 am)
No, that's not true. I'm not even sure where you read that. Could you provide a link? I've tested up to 8 so far on my project, although it's only designed for 4. Just make sure you propagate the updates to every client.
#2
03/12/2008 (10:16 am)
Ok. That was a relief!
I didn't read that anywhere. Just thought it was limited to two clients after seeing so many discussions related to TGB pro/networking, c++ engines etc. As I wrote, this engine is very new to me. My only coding experience is in Actionscript, and now, a little Torquescript.

Thanks Jason
#3
03/12/2008 (1:09 pm)
Jason, would you happen to have something to share along the lines of establishing that multi-connection? I've been scrounging the forums and content here, and have only found how to handle the 2 clients. I'm looking for a way to determine how many participants want to join in a game, and use that to send messages to each client of the game. I'd appreciate any info you could share on the subject.

Thanks
#4
03/12/2008 (2:30 pm)
When I get home, I'll post a little function I use to enumerate the clients. Basically, you have the first player start and he's the first connection, then every player can connect and they are 2nd, 3rd, 4th, etc. When the player limit is reached, it just start the game. It's crude and eventually will go into a pre-game lobby, but it works reasonably well.

It's one of those things that looks really imposing when you first view the challenge, but when you see how I approached it, you'll easily be able to improve on my crude implementation.
#5
03/12/2008 (11:11 pm)
for (%i = 0; %i < ClientGroup.getCount(); %i++)
{
   %clientConnection = ClientGroup.getObject(%i);
   commandToClient(%clientConnection, 'myFunction', myArgs ... );
}

ClientGroup is a SimSet which stores all of the connections. "ClientGroup" can only be used by the server.
#6
03/13/2008 (6:53 am)
Phillip, that's the communication to all the clients, that much I understand. I guess logically then after the $firstConnection, you would add in additional connections to the SimSet ClientGroup. Can the value of the max players in the network menu be used to actaully evaluate into the client connections? I suppose it can so long as you can retrieve the value. I guess I can figure out how to use it, it doesn't seem that difficult, I was just a little dismayed when the only network example (checkers) only allows for a 2 person connection. I'm working on a multiplayer network game, and actaully made some good progree. I'm hoping to add it as a resource for the community here to give another example of network code in action, as well as having a game capable of handling more than just two players.
#7
03/13/2008 (8:33 am)
I'm going to have to retool a bit to use that Phillip. Where was that documented?
#8
03/13/2008 (10:56 am)
What I did was after a client connected is to have it compare to the number I wish to connect. When they matched, the game started (well, more specifically it told the clients to load a particular mission).
#9
03/13/2008 (1:03 pm)
I've got a working network lobby set up, selects missions, min/max players, chat system, kick ban and launches the game at the same time. I've still gotta sort out a few issues, I might throw it up at some stage.
#10
03/13/2008 (3:47 pm)
Philip, I'd really like to see that set up, I'm working on getting something finished by the end of the month for a tutorial on Network games. I'd like to include a "lobby-like" setup so that way it'd be more user friendly. If you could either put something up here, or e-mail me I'd really appreciate it. (You can use my e-mail in my profile.)

Thanks.
#11
03/13/2008 (6:47 pm)
Eventually, I hope to add them to a chat system like Phillip discussed with our own master server, but for now it just starts the game. All of the gamestate is kept using something akin to arrays instead of datablocks. That's mostly a matter of preference since it makes post-disconnect re-joining mid-game a bit easier to manage.

function onServerCreated()
{
	echo("SERVER: Server Created");
	$playerMax = 2;
	$playerCount = 0;
	for(%player=1; %player<=$playerMax; %player++)
	{
		$playerSocket[%player] = false;
	}
	$turn = 1;
	$phase = 1;
}

function onClientConnected(%client)
{
	for(%connection=1; %connection<=$playerMax; %connection++) 
    { 
		if($playerSocket[%connection] == true)
		{
			echo("SERVER: PlayerSocket"@%connection SPC "Already True");
		}

		if($playerSocket[%connection] == false) 
		{ 
		%client.player = "player"@%connection;
		echo("SERVER: Assigning player" SPC %client.player SPC "TO" SPC %client.name);
		$playerSocket[%connection] = %client;       
		$playerSocket[%connection].player.moved = false;
		commandToClient(%client, 'initializePlayer', %client.player, $turn, $phase, $playerMax); 
		break;
        }

	}

	if(serverSocketCheck() == 1)
	{
		echo("SERVER: BOTH SOCKETS ARE NOW TRUE");
		
		for(%socket = 1; %socket <= $playerMax ; %socket++)
		{
			commandToClient($playerSocket[%socket], 'loadLevel', expandFilename($Game::DefaultScene));
			for(%id = 1; %id <= $playerMax; %id++)
			{
				commandToClient($playerSocket[%socket], 'introducePlayer', "player"@%id, $playerSocket[%id].name);
			}
		}
	}
	else
	{
		echo("SERVER: MORE SOCKETS EMPTY");
	}
}

For an example, I update turns like this:
function serverUpdateTurn()
{

	echo("SERVER: SETTING TURN TO" SPC $turn SPC "AND GOING BACK TO PHASE" SPC $phase);
	for(%connection=1 ; %connection<=$playerMax ; %connection++)
	{
		commandToClient($playerSocket[%connection], 'updateTurn', $turn);
		commandToClient($playerSocket[%connection], 'updatePhase', $phase);
	}
}
#12
03/13/2008 (7:00 pm)
Really, really cool Jason! This will speed up my learning progress 'lot!
Thanks for sharing your knowledge!
#13
03/14/2008 (7:12 am)
Very nice, I think I might actually be able to get this working. I was debating over whether or not I wanted to add in more than 2 player functionality, and now that I have the ability to allow it, I think I am definately going to go for it! Besides, I think it would be that much more useful to share with the community not just a 2 player network game, but a larger scale variant. The game I am making could hold up to at least 8 players, maybe more if I decided to. Now, I just need to finish it up!
Also, I'm going to try and figure out another type of game that can hold even more players! I think the more and more get done with the TGB networking, the more enhancement we might see in the future.
#14
04/17/2008 (11:00 am)
Just a note, I'll update my new stuff tonight. The code for setting up a multi-player session has been improved.

Also, I never gave the details for the ServerSocketCheck. That'll be posted, too.