Game Development Community

[Solved] Request - Step by Step Guide on how to seporate T3D Client From Server

by Lee Wickham · in Torque 3D Professional · 01/27/2011 (1:55 pm) · 38 replies

Note: For a step by step guide see reply #14 onward


Hi every my name is lee

Just want to say that i am over the moon that GG is back and i have just purchased T3D myself


I am wondering if their is any one that would be kind enough to provide me (and any others that may be searching for this) a guide or step by step instructions on Splitting up the Client and Server sides of Torque 3D, the aim of this is to:


To Create a Seporate Build of my game to be used as:

  1. A Dedicated Server.
  2. A Client to connect to the dedi server.

Currently i have Installed:


  1. Torque 3D 1.1 Beta 3.
  2. All Prerequasits Installed to the latest version at time of posting this request for help.
  3. Created a Fresh "Full" Project.

The game will be MOFPS (Multiplayer Online First Person Shooter)

If any further information is required please let me know and ill reply as soon as possible.

Thank you for taking the time to read this thread

Regards

Lee.
Page «Previous 1 2
#1
01/27/2011 (2:32 pm)
I am not sure about question two. But to make a simple dedicated server, I would create a .bat file. Then use this:
start GameName.exe -dedicated -map MapName
There maybe a better way to do it, but that's how I make one.
#2
01/27/2011 (3:31 pm)
Thank you for the reply, thats handy information to have.

However i think you may has mis understood what i was asking, currently as it stands when you install torque 3D and create a project, you have both client (Front end of the game that players will install - holds most of the games assets e.t.c) and server files (the back end of the game that dose most of the calculations and work and controls accounts) all together in the project folder, i was asking if any one could detail how to seporate them.

that being said i do apreciate the responce and as i said previously the information you provided is very handy thank you kindly :D
#3
01/27/2011 (8:44 pm)
Ok, Sorry I could not help you further.
#4
01/28/2011 (2:09 am)
Not a problem fella thanx again for the information have provided :D
#5
01/28/2011 (10:43 am)
Someone has done this a few months ago... I just don't remember who or the title of the Forum Thread, but keep looking knowing that it is there.
#6
01/28/2011 (1:58 pm)
@Michael - Thank you!! ill keep searching.
#7
01/28/2011 (2:07 pm)
Here ya go. This should help.
http://www.garagegames.com/community/forums/viewthread/38720
#8
01/29/2011 (2:44 am)
@sam thank you however that wasent exactly what i was after but it will definatly help :D
#9
01/29/2011 (3:14 am)
From what I can tell is that there is still some overlap between client and server, even by seperating most of it. I enquiried about this some time back to see if it was at all possible. However this may not be the case anymore.
#10
01/29/2011 (3:32 am)
@Julian thanx for the heads up :D
#11
04/22/2011 (11:52 am)
This link may have more on what you're looking for
http://www.garagegames.com/community/forums/viewthread/107671
#12
04/25/2011 (6:01 am)
Thank you Scot, that helped me sepporate the 1.1 preview in to client and server, had to do some extra work as torque has been updated since that thread was created however i now have a working dedicated server for windows.

And thank you to every one else who posted most appreciated guys !!
#13
04/25/2011 (10:32 am)
I started doing this ... haven't finished yet ... it is like a little side project, but the basic steps I followed are as follows:

1). Compile a Brand New Executable for Server and Client.
2). Start adding scripts and functions one-by-one.
3). Use an "EMPTY" project as reference as you follow this process.

This is the best way I have found to do this ... as you get to learn the engine from the inside out as you move along and this knowledge will prove invaluable.

My idea behind this approach is to create specific templates for my needs and as I roll out new projects I can expand on these.

As I said ... I haven't finished this yet ... and there is no guarantee it will work, but this is the approach I am taking.
#14
04/26/2011 (12:39 pm)
@QuintonD nice aproach would love to see the outcome.

Just for reference and incase any one else is looking to do the same this is the way i went about it:

WARNING Almost 2 pages of post's on this step by step!

Torque 3D Version: 1.1 Preview
Platform: Windows

1. Create a new project named "test" using the "full" template.
2. Duplicate the "test" project and rename the folder to "test - server".
3. Rename "test.exe" to "test_w32ded.exe".
4. Rename "test.dll" to test_w32ded.dll".
5. Rename "test.torison" to "test_w32ded.torison"
6. Removed the following files: - as no need for web deployment in my project.
a. IE test Plugin.dll
b. NP test Plugin.dll
7. Removed the following Directories:
a. game\web
b. game\shaders
c. game\art\gui
d. game\core\fonts
e. game\core\unifiedshell
f. game\core\scripts\client
g. game\core\scripts\gui
h. game\core\art\gui
i. game\scripts\gui
j. game\scripts\client

Continued in next post.
#15
04/26/2011 (12:41 pm)
8. Removed any referances to client material in game\main.cs (see code block below)
//-----------------------------------------------------------------------------
// Torque Game Engine Advanced
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

// Set the name of our application
$isDedicated = true;
$appName = "test";
%mission = "levels/Empty Terrain.mis";


// The directory it is run from
$defaultGame = "scripts";

// Set profile directory
$Pref::Video::ProfilePath = "core/profile";

function createCanvas(%windowTitle)
{
   if ($isDedicated)
   {
      GFXInit::createNullDevice();
      return true;
   }

   // Create the Canvas
   %foo = new GuiCanvas(Canvas);
   
   // Set the window title
   if (isObject(Canvas))
      Canvas.setWindowTitle(getEngineName() @ " - " @ $appName);
   
   return true;
}

// Display the optional commandline arguements
$displayHelp = false;

// Use these to record and play back crashes
//saveJournal("editorOnFileQuitCrash.jrn");
//playJournal("editorOnFileQuitCrash.jrn", false);

//------------------------------------------------------------------------------
// Check if a script file exists, compiled or not.
function isScriptFile(%path)
{
   if( isFile(%path @ ".dso") || isFile(%path) )
      return true;
   
   return false;
}

//------------------------------------------------------------------------------
// Process command line arguments
exec("core/parseArgs.cs");


$dirCount = 2;
$userDirs = $defaultGame @ ";art;levels";

// load tools scripts if we're a tool build
if (isToolBuild())
    $userDirs = "tools;" @ $userDirs;


// Parse the executable arguments with the standard
// function from core/main.cs
defaultParseArgs();


if($dirCount == 0) {
      $userDirs = $defaultGame;
      $dirCount = 1;
}

//-----------------------------------------------------------------------------
// Display a splash window immediately to improve app responsiveness before
// engine is initialized and main window created
if (!$isDedicated)
   displaySplashWindow();


//-----------------------------------------------------------------------------
// The displayHelp, onStart, onExit and parseArgs function are overriden
// by mod packages to get hooked into initialization and cleanup.

function onStart()
{
   // Default startup function
}

function onExit()
{
   // OnExit is called directly from C++ code, whereas onStart is
   // invoked at the end of this file.
}

function parseArgs()
{
   // Here for mod override, the arguments have already
   // been parsed.
}

function compileFiles(%pattern)
{  
   %path = filePath(%pattern);

   %saveDSO    = $Scripts::OverrideDSOPath;
   %saveIgnore = $Scripts::ignoreDSOs;
   
   $Scripts::OverrideDSOPath  = %path;
   $Scripts::ignoreDSOs       = false;
   %mainCsFile = makeFullPath("main.cs");

   for (%file = findFirstFileMultiExpr(%pattern); %file !$= ""; %file = findNextFileMultiExpr(%pattern))
   {
      // we don't want to try and compile the primary main.cs
      if(%mainCsFile !$= %file)      
         compile(%file, true);
   }

   $Scripts::OverrideDSOPath  = %saveDSO;
   $Scripts::ignoreDSOs       = %saveIgnore;
   
}

if($compileAll)
{
   echo(" --- Compiling all files ---");
   compileFiles("*.cs");
   compileFiles("*.gui");
   compileFiles("*.ts");  
   echo(" --- Exiting after compile ---");
   quit();
}

if($compileTools)
{
   echo(" --- Compiling tools scritps ---");
   compileFiles("tools/*.cs");
   compileFiles("tools/*.gui");
   compileFiles("tools/*.ts");  
   echo(" --- Exiting after compile ---");
   quit();
}

Continued Below
#16
04/26/2011 (12:43 pm)
Continued game\main.cs from above

package Help {
   function onExit() {
      // Override onExit when displaying help
   }
};

function displayHelp() {
   activatePackage(Help);

      // Notes on logmode: console logging is written to console.log.
      // -log 0 disables console logging.
      // -log 1 appends to existing logfile; it also closes the file
      // (flushing the write buffer) after every write.
      // -log 2 overwrites any existing logfile; it also only closes
      // the logfile when the application shuts down.  (default)

   error(
      "Torque Demo command line options:n"@
      "  -log <logmode>         Logging behavior; see main.cs comments for detailsn"@
      "  -game <game_name>      Reset list of mods to only contain <game_name>n"@
      "  <game_name>            Works like the -game argumentn"@
      "  -dir <dir_name>        Add <dir_name> to list of directoriesn"@
      "  -console               Open a separate consolen"@
      "  -show <shape>          Deprecatedn"@
      "  -jSave  <file_name>    Record a journaln"@
      "  -jPlay  <file_name>    Play back a journaln"@
      "  -jDebug <file_name>    Play back a journal and issue an int3 at the endn"@
      "  -help                  Display this help messagen"
   );
}

//--------------------------------------------------------------------------

// Default to a new logfile each session.
if( !$logModeSpecified )
{
   if( $platform !$= "xbox" && $platform !$= "xenon" )
      setLogMode(6);
}

// Get the first dir on the list, which will be the last to be applied... this
// does not modify the list.
nextToken($userDirs, currentMod, ";");

// Execute startup scripts for each mod, starting at base and working up
function loadDir(%dir)
{
   pushback($userDirs, %dir, ";");

   if (isScriptFile(%dir @ "/main.cs"))
   exec(%dir @ "/main.cs");
}

echo("--------- Loading DIRS ---------");
function loadDirs(%dirPath)
{
   %dirPath = nextToken(%dirPath, token, ";");
   if (%dirPath !$= "")
      loadDirs(%dirPath);

   if(exec(%token @ "/main.cs") != true)
   {
      error("Error: Unable to find specified directory: " @ %token );
      $dirCount--;
   }
}
loadDirs($userDirs);
echo("");

if($dirCount == 0) {
   enableWinConsole(true);
   error("Error: Unable to load any specified directories");
   quit();
}



// Parse the command line arguments
echo("--------- Parsing Arguments ---------");
parseArgs();

// Either display the help message or startup the app.
if ($displayHelp) {
   enableWinConsole(true);
   displayHelp();
   quit();
}
else {
   onStart();
   echo("Engine initialized...");
   
   // Auto-load on the 360
   if( $platform $= "xenon" )
   {
      %mission = "levels/Empty Terrain.mis";
      
      echo("Xbox360 Autoloading level: '" @ %mission @ "'");
      
      
      if ($pref::HostMultiPlayer)
         %serverType = "MultiPlayer";
      else
         %serverType = "SinglePlayer";

      createAndConnectToLocalServer( %serverType, %mission );
   }
}

// Display an error message for unused arguments
for ($i = 1; $i < $Game::argc; $i++)  {
   if (!$argUsed[$i])
      error("Error: Unknown command line argument: " @ $Game::argv[$i]);
}

// Automatically start up the appropriate eidtor, if any
if ($startWorldEditor) {
   Canvas.setCursor("DefaultCursor");
   Canvas.setContent(EditorChooseLevelGui);
} else if ($startGUIEditor) {
   Canvas.setCursor("DefaultCursor");
   Canvas.setContent(EditorChooseGUI);
}

Steps Continue Below
#17
04/26/2011 (12:44 pm)
9. Removed any referances to client material in game\core\main.cs (see code block below)
//---------------------------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------

// Constants for referencing video resolution preferences
$WORD::RES_X = 0;
$WORD::RES_Y = 1;
$WORD::FULLSCREEN = 2;
$WORD::BITDEPTH = 3;
$WORD::REFRESH = 4;
$WORD::AA = 5;

//---------------------------------------------------------------------------------------------
// CorePackage
// Adds functionality for this mod to some standard functions.
//---------------------------------------------------------------------------------------------
package CorePackage
{
//---------------------------------------------------------------------------------------------
// onStart
// Called when the engine is starting up. Initializes this mod.
//---------------------------------------------------------------------------------------------
function onStart()
{
   Parent::onStart();

   // Here is where we will do the video device stuff, so it overwrites the defaults
   // First set the PCI device variables (yes AGP/PCI-E works too)
   $isFirstPersonVar = 1;

   // Uncomment to enable AdvancedLighting on the Mac (T3D 2009 Beta 3)
   //$pref::machax::enableAdvancedLighting = true;

   // Uncomment to disable ShaderGen, useful when debugging
   //$ShaderGen::GenNewShaders = false;
   
   // Uncomment to dump disassembly for any shader that is compiled to disk.
   // These will appear as shadername_dis.txt in the same path as the
   // hlsl or glsl shader.   
   //$gfx::disassembleAllShaders = true;

   // Uncomment useNVPerfHud to allow you to start up correctly
   // when you drop your executable onto NVPerfHud
   //$Video::useNVPerfHud = true;
   
   // Uncomment these to allow you to force your app into using
   // a specific pixel shader version (0 is for fixed function)
   //$pref::Video::forcePixVersion = true;
   //$pref::Video::forcedPixVersion = 0;

   if ($platform $= "macos")
      $pref::Video::displayDevice = "OpenGL";
   else
      $pref::Video::displayDevice = "D3D9";
   
   // Initialise stuff.
   exec("./scripts/server/core.cs");
   initializeCore();
   
   exec("./scripts/server/server.cs");  
   echo(" % - Initialized Core");
}

//---------------------------------------------------------------------------------------------
// onExit
// Called when the engine is shutting down. Shutdowns this mod.
//---------------------------------------------------------------------------------------------
function onExit()
{   
   // Shutdown stuff.
   shutdownCore();

   Parent::onExit();
}

function loadKeybindings()
{
   $keybindCount = 0;
   // Load up the active projects keybinds.
   if(isFunction("setupKeybinds"))
      setupKeybinds();
}

Continued Below
#18
04/26/2011 (12:45 pm)
Continued game\core\main.cs
//---------------------------------------------------------------------------------------------
// displayHelp
// Prints the command line options available for this mod.
//---------------------------------------------------------------------------------------------
function displayHelp() {
   // Let the parent do its stuff.
   Parent::displayHelp();

   error("Core Mod options:n" @
         "  -fullscreen            Starts game in full screen moden" @
         "  -windowed              Starts game in windowed moden" @
         "  -autoVideo             Auto detect video, but prefers OpenGLn" @
         "  -openGL                Force OpenGL accelerationn" @
         "  -directX               Force DirectX accelerationn" @
         "  -voodoo2               Force Voodoo2 accelerationn" @
         "  -prefs <configFile>    Exec the config filen");
}

//---------------------------------------------------------------------------------------------
// parseArgs
// Parses the command line arguments and processes those valid for this mod.
//---------------------------------------------------------------------------------------------
function parseArgs()
{
   // Let the parent grab the arguments it wants first.
   Parent::parseArgs();

   // Loop through the arguments.
   for (%i = 1; %i < $Game::argc; %i++)
   {
      %arg = $Game::argv[%i];
      %nextArg = $Game::argv[%i+1];
      %hasNextArg = $Game::argc - %i > 1;
   
      switch$ (%arg)
      {
         case "-fullscreen":
            setFullScreen(true);
            $argUsed[%i]++;

         case "-windowed":
            setFullScreen(false);
            $argUsed[%i]++;

         case "-openGL":
            $pref::Video::displayDevice = "OpenGL";
            $argUsed[%i]++;

         case "-directX":
            $pref::Video::displayDevice = "D3D";
            $argUsed[%i]++;

         case "-voodoo2":
            $pref::Video::displayDevice = "Voodoo2";
            $argUsed[%i]++;

         case "-autoVideo":
            $pref::Video::displayDevice = "";
            $argUsed[%i]++;

         case "-prefs":
            $argUsed[%i]++;
            if (%hasNextArg) {
               exec(%nextArg, true, true);
               $argUsed[%i+1]++;
               %i++;
            }
            else
               error("Error: Missing Command Line argument. Usage: -prefs <path/script.cs>");
      }
   }
}

};

activatePackage(CorePackage);

Steps Continued Below
#19
04/26/2011 (12:47 pm)
10. removed any referances to client material in game\scripts\main.cs (see code block below)
//-----------------------------------------------------------------------------
// Torque Shader Engine 
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

// Load up core script base
loadDir("core"); // Should be loaded at a higher level, but for now leave -- SRZ 11/29/07

//-----------------------------------------------------------------------------
// Package overrides to initialize the mod.
package fps {

function displayHelp() {
   Parent::displayHelp();
   error(
      "Fps Mod options:n"@
      "  -dedicated             Start as dedicated servern"@
      "  -connect <address>     For non-dedicated: Connect to a game at <address>n" @
      "  -mission <filename>    For dedicated: Load the missionn"
   );
}

function parseArgs()
{
   // Call the parent
   Parent::parseArgs();

   // Arguments, which override everything else.
   for (%i = 1; %i < $Game::argc ; %i++)
   {
      %arg = $Game::argv[%i];
      %nextArg = $Game::argv[%i+1];
      %hasNextArg = $Game::argc - %i > 1;
   
      switch$ (%arg)
      {
         //--------------------
         case "-dedicated":
            $Server::Dedicated = true;
            enableWinConsole(true);
            $argUsed[%i]++;

         //--------------------
         case "-mission":
            $argUsed[%i]++;
            if (%hasNextArg) {
               $missionArg = %nextArg;
               $argUsed[%i+1]++;
               %i++;
            }
            else
               error("Error: Missing Command Line argument. Usage: -mission <filename>");

         //--------------------
         case "-connect":
            $argUsed[%i]++;
            if (%hasNextArg) {
               $JoinGameAddress = %nextArg;
               $argUsed[%i+1]++;
               %i++;
            }
            else
               error("Error: Missing Command Line argument. Usage: -connect <ip_address>");
      }
   }
}
Continued Below
#20
04/26/2011 (12:48 pm)
Continued game\scripts\main.cs
function onStart()
{
   // The core does initialization which requires some of
   // the preferences to loaded... so do that first.  
   exec( "./server/defaults.cs" );
             
   Parent::onStart();
   echo("n--------- Initializing Directory: scripts ---------");

   // Load the scripts that start it all...
   exec("./server/init.cs");
   
   // Init the physics plugin.
   physicsInit();
      
   // Start up the audio system.
   sfxStartup();

   
   // Server gets loaded for all sessions, since clients
   // can host in-game servers.
   initServer();

   // Start up in either client, or dedicated server mode
   initDedicated();
}

function onExit()
{
   // Ensure that we are disconnected and/or the server is destroyed.
   // This prevents crashes due to the SceneGraph being deleted before
   // the objects it contains.
   if ($Server::Dedicated)
      destroyServer();
   else
      disconnect();
   
   // Destroy the physics plugin.
   physicsDestroy();
      
   echo("Exporting server prefs");
   export("$Pref::Server::*", "./server/prefs.cs", False);
   BanList::Export("./server/banlist.cs");

   Parent::onExit();
}

}; // package fps

// Activate the game package.
activatePackage(fps);

Steps Continue Below
Page «Previous 1 2