Game Development Community

dev|Pro Game Development Curriculum

Map Triggers that send you to another server

by Edward Gardner · 03/27/2002 (5:58 pm) · 20 comments

Ok, this is short, but I thought I'd get it written down. More to come hopefully.

Say you have a couple of dedicated servers, and you want your players to hop between them without quitting and querying the master server again.

This is how you do it.

You'll need two files (or modify 2 files, depending on whether or not you have it).

Trigger.cs in fps/server/scripts

and

TriggerClient.cs in fps/client/scripts

First things first, define the new trigger on the server:

Open up Trigger.cs, if you don't have it, make a new cs file in server/scripts.

Add the following:

datablock TriggerData(ServerPortalTrigger)
{
tickPeriodMS = 100;
};

and:

function ServerPortalTrigger::onEnterTrigger(%data, %obj, %colObj)
{
%client = %colObj.client;
if (%client) {
commandToClient(%client, 'connectserverPortal');
} else {
echo ("Not a client");
}

}


function ServerPortalTrigger::onLeaveTrigger(%data, %obj, %colObj)
{
echo ("Left ServerPortal Trigger");
}



function ServerPortalTrigger::onTickTrigger(%data, %obj)
{
}



Ok, save and exec that in game.cs


Now, in client/scripts, make a new cs file called triggerclient.cs and add this to it:

function clientCmdconnectserverPortal()
{
connect("127.0.0.1:28001",$Client::Password,$pref::Player::Name);
}

Where 127.0.0.1 is your destination server.

Save, exec that in client/init.cs and start TQ.

Add a trigger, give it a name and size it.

Voila! When you player collides with it, he or she is whisked away to the new server :)

#1
03/27/2002 (2:25 pm)
This does open up some interesting doors (no pun intended). Now, about that semi-persistance idea..
#2
03/27/2002 (8:49 pm)
great stuff. I would like to trigger to a picture in a database or even to a live video cam.Any help gratefully received.
#3
03/27/2002 (10:04 pm)
heh,good job, how hard would it be to make it go to a specific map on the same server (for single player)
thanks.
#4
03/28/2002 (8:39 am)
Maps on the same server should be easy, have a look at Realm Wars, where they change the map when vicotry conditions are met. I'd expect you could just modify that :)

As for databases, I just compiled the mySQL stuff and I know there is an ODBC enabling tutorial for torque. As for semi persistence, I have an architecture in mind, need to write it all down. If you want a preview, there is a great peer-peer networking thread on the forums from last summer, that's the kernel of my idea.
#5
04/02/2002 (7:40 am)
Hey, cool. I remember that discussion, it was very interesting. It's great to see people progressing towards the implementation of those ideas.
#6
04/04/2005 (7:32 am)
Do these scripts only exist on the server?
#7
07/17/2005 (2:46 pm)
usefull for my rpg (i've stopped the terrain from repeating, and every terrain block is a part of the huge world, you can go to another part though a portal). This can be done with this server hopping... Allthough i'd much rather have everybody in 1 server, instead of having like 30 servers running...
#8
02/07/2006 (7:13 pm)
I just thought I'd mention something about this resource (besides that it is from 2002).
You will need to do a full disconnect() as the connect() function does not unload the mission.
If you use this out of the box it will have both missions loaded ontop of eachother when you try to zone.
The reason is because it is not calling the following (found in function disconnect):
// Dump anything we're not using
   clearTextureHolds();
   purgeResources();
I'm finishing my zoning (uses RPGDialog and not a trigger) and realized that this hadn't been posted here.
I hope this helps anyone trying to use this resource.

Ari
#9
04/26/2006 (10:45 am)
function clientCmdconnectserverPortal()
{
ServerConnection.delete();
clearTextureHolds();
purgeResources();
connect("10.0.0.254:28000",$Client::Password,$pref::Player::Name);
}

This is the way i managed to get it to unload the current map and reload the new one, the disconnecting from the first server is seamless.
#10
10/21/2006 (7:46 pm)
You don't really have to pass the player to a "new server"... just a new mission...
I run serveral missions at the same time on the same server.... it's simple to do.

I just make a batch file that contain the startup command below:

torqueDemo_DEBUG.exe -dedicated -game starter.fps -prefs starter.fps/server/Server1.cs -mission starter.fps/data/missions/stronghold.mis
torqueDemo_DEBUG.exe -dedicated -game starter.fps -prefs starter.fps/server/Server2.cs -mission starter.fps/data/missions/stronghold.mis
torqueDemo_DEBUG.exe -dedicated -game starter.fps -prefs starter.fps/server/Server3.cs -mission starter.fps/data/missions/stronghold.mis

you can name any mission you want.... go into the server folder and make as many copies as you want of the defaults.cs file and name them what you want (server1.cs, server2.cs, server3.cs).... then alter the name and info fields to suit the game... then just change the command in the server1.cs, server2.cs, server3.cs....etc.... files:

// The network port is also defined by the client, this value
// overrides pref::net::port for dedicated servers
$Pref::Server::Port = 28002; // Change for each dedicated server

Just make sure each server file uses a seperate port....

there you have it.... one machine... 20 missions... all linked... same i.p. number

use it with the trigger code above by setting the port numbers you designated in the server cs files and you get a whole lot of game play on just one machine.
#11
02/07/2007 (7:34 am)
Ok I purchased Dreamers MMO enhancment kit and for some reason when i try to use the code above to conect to another server the client crashes. The client conects to the other server, but nuthing else. I added this code tell me if it will fix it

function clientCmdconnectserverPortal()
{
ServerConnection.delete();
clearTextureHolds();
purgeResources();
connect("192.168.0.199:28000",$Client::Password,$pref::Player::Name,$GameConnection::loadMission);
}

Game connection is the added part.
#12
04/01/2007 (3:24 pm)
Managed to get this working and it's really sweet :)

However, I have 2 servers with gates between them. When I play on my machine (also hosting the servers) it works fine, but how can I get it to work with players outside my network?

connect("127.0.0.1:28001",$Client::Password,$pref::Player::Name);

Obviously, 127.0.0.1 is the loopback thing so that won't work ;)

I can use my i.p. (or the ip taken from $ServerInfo::Address) but because I'm behind a firewall, the ports get mapped totally differently.

xx.xx.xx.xx:28002 --> xx.xx.xx.xx:63153 (basically a random port)
xx.xx.xx.xx:28003 --> xx.xx.xx.xx:64882 (basically a random port)

for example.

Is this to do with network address translation? (NAT). I don't know much about networking and don't know the best way to get around this :( Obviously this is what the master server is for.

I'm using a shared SQL database for some stuff - I guess I could store the i.p. addresses in there when the server starts up (so level1 saves it's ip address and level2 looks up 'level1' in the database). Would this be a good solution? How can a server find out what it's i.p. address looks like outside the network?

Lots of questions, I'm a bit stuck :)

ta!
#13
11/11/2007 (6:28 am)
@Buddy Lednum: Thanks for your post. It cleared up some questions I had but of course created some new ones. My question to you is how do you move from one dedicated server/level to another since they all share the same ip. I appreciate your answer and hope this gets to you.
#14
11/12/2007 (8:38 am)
@Shon - you just run the missions using different port numbers....

quote -
you can name any mission you want.... go into the server folder and make as many copies as you want of the defaults.cs file and name them what you want (server1.cs, server2.cs, server3.cs).... then alter the name and info fields to suit the game... then just change the command in the server1.cs, server2.cs, server3.cs....etc.... files:

// The network port is also defined by the client, this value
// overrides pref::net::port for dedicated servers
$Pref::Server::Port = 28002; // Change for each dedicated server

Just make sure each server file uses a seperate port....


ok... for me server1.cs would use $Pref::Server::Port = 28001;
server2.cs would use $Pref::Server::Port = 28002;
server3.cs would use $Pref::Server::Port = 28003;

and so on.....

@ Jim... do you have a static or dynamic i.p. on the other side of your firewall ?
if it's static you can use nat and just use your static i.p., if it's dynamic you should be able to use one of the free services for dynamic i.p.s and just enter a domain name instead of an i.p.

or if your firewall also has DMZ settings you can always set it up there... without knowing your particular setup it's hard to work on a solution that may work...
#15
11/12/2007 (9:36 am)
@Buddy Lednum: Thanks for your quick response to my question, but I am happy to say I just got it working this morning. I have my own master server list now and can load my game from that list. I am now setting up multiple computers with multiple levels, etc.
What I love about the dedicated server setup is the equipment requirements are so low. I currently have dedicated servers setup on a 2GHZ AMD, a 2.66 P4 single core, 3.2GHZ P4 dual core, and I just got one of the new dual core Celerons. It runs great on all of them. I can take my old computers and give them new life as servers. Oh happy day.
#16
11/12/2007 (9:45 am)
@Shon: I'm glad you got it running.... yeah, that's what I am doing... without the graphics of the client running the server itself really doesn't use much of the processor.... I have even ported several of the server tests i've done to various flavors of unix/linux... i have almost no problems from them.. even running communication server and database servers all on the same system
#17
11/12/2007 (9:49 am)
@Buddy: Yes next comes the database stuff, had to the master up and running first before I setup the database and communications stuff. Thanks for ypur input, it is greatly appreciated.
#18
10/13/2008 (4:00 am)
I have checked this with the last version of the engine TGEA 1.7.1 and it crashes my computer sometimes not always. Does anyone know what I'm doing wrong?. I'm excuting the following code:

function clientCmdconnectserverPortal()
{
if ($game_server !$= "") {
// Disconnecting from the server.
// Delete the connection if it's still there.
if (isObject(ServerConnection))
ServerConnection.delete();

disconnectedCleanup();

// Delete all the data blocks...
deleteDataBlocks();

// Connecting with the server [Added]
%conn = new GameConnection(ServerConnection);
RootGroup.add(ServerConnection);
%conn.setConnectArgs($pref::Player::Name);
%conn.setJoinPassword($Client::Password);

%conn.schedule(2000, "connect", $game_server @ ":28001");
}
}
#19
11/18/2008 (4:33 pm)
After testing this resource I have found that this method of connecting works the best for me.

function clientCmdconnectserverPortal()
{
schedule(0, 0, "Disconnect");
schedule(0, 0, "joinServerPortal");
}


function joinServerPortal()
{
%conn = new GameConnection(ServerConnection);
%conn.setConnectArgs($pref::Player::Name);
%conn.setJoinPassword($Client::Password);
%conn.connect("192.168.0.1:28003");
}
#20
01/18/2010 (10:07 pm)
2 years later...I need to know how to do this in T3D with multi-player. Has anyone figured it out?