home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58b_TRIBES.iso / Tribes / base / scripts.vol / server.cs < prev    next >
Encoding:
Text File  |  1998-12-16  |  8.4 KB  |  325 lines

  1. // putting a global variable in the argument list means:
  2. // if an argument is passed for that parameter it gets
  3. // assigned to the global scope, not the scope of the function
  4.  
  5. function createTrainingServer()
  6. {
  7.    $SinglePlayer = true;
  8.    createServer($pref::lastTrainingMission, false);
  9. }
  10.  
  11. function remoteSetCLInfo(%clientId, %skin, %name, %email, %tribe, %url, %info, %autowp)
  12. {
  13.    $Client::info[%clientId, 0] = %skin;
  14.    $Client::info[%clientId, 1] = %name;
  15.    $Client::info[%clientId, 2] = %email;
  16.    $Client::info[%clientId, 3] = %tribe;
  17.    $Client::info[%clientId, 4] = %url;
  18.    $Client::info[%clientId, 5] = %info;
  19.    if(%autowp)
  20.       %clientId.autoWaypoint = true;
  21. }
  22.  
  23. function Server::onClientConnect(%clientId)
  24. {
  25.    if(!String::NCompare(Client::getTransportAddress(%clientId), "LOOPBACK", 8))
  26.    {
  27.       // force admin the loopback dude
  28.       %clientId.isAdmin = true;
  29.       %clientId.isSuperAdmin = true;
  30.    }
  31.    echo("CONNECT: " @ %clientId @ " \"" @ 
  32.       escapeString(Client::getName(%clientId)) @ 
  33.       "\" " @ Client::getTransportAddress(%clientId));
  34.    %clientId.noghost = true;
  35.    remoteEval(%clientId, SVInfo, version(), $Server::Hostname, $modList, $Server::Info);
  36.  
  37.    // clear out any client info:
  38.    for(%i = 0; %i < 10; %i++)
  39.       $Client::info[%clientId, %i] = "";
  40.  
  41.    Game::onPlayerConnected(%clientId);
  42. }
  43.  
  44. function createServer(%mission, %dedicated)
  45. {
  46.    $loadingMission = false;
  47.    if(%mission == "")
  48.       %mission = $pref::lastMission;
  49.  
  50.    if(%mission == "")
  51.    {
  52.       echo("Error: no mission provided.");
  53.       return "False";
  54.    }
  55.  
  56.    if(!$SinglePlayer)
  57.       $pref::lastMission = %mission;
  58.  
  59.     //display the "loading" screen
  60.     cursorOn(MainWindow);
  61.     GuiLoadContentCtrl(MainWindow, "gui\\Loading.gui");
  62.     renderCanvas(MainWindow);
  63.  
  64.    if(!%dedicated)
  65.    {
  66.       deleteServer();
  67.       purgeResources();
  68.       newServer();
  69.       focusServer();
  70.    }
  71.    if($SinglePlayer)
  72.       newObject(serverDelegate, FearCSDelegate, true, "LOOPBACK", $Server::Port);
  73.    else
  74.       newObject(serverDelegate, FearCSDelegate, true, "IP", $Server::Port, "IPX", $Server::Port, "LOOPBACK", $Server::Port);
  75.    
  76.    exec(admin);
  77.    exec(Marker);
  78.    exec(Trigger);
  79.    exec(NSound);
  80.    exec(BaseExpData);
  81.    exec(BaseDebrisData);
  82.     exec(BaseProjData);
  83.    exec(ArmorData);
  84.    exec(Mission);
  85.     exec(Item);
  86.     exec(Player);
  87.     exec(Vehicle);
  88.     exec(Turret);
  89.     exec(Beacon);
  90.     exec(StaticShape);
  91.     exec(Station);
  92.     exec(Moveable);
  93.     exec(Sensor);
  94.     exec(Mine);
  95.     exec(AI);
  96.     exec(InteriorLight);
  97.    
  98.    // NOTE!! You must have declared all data blocks BEFORE you call
  99.    // preloadServerDataBlocks.
  100.  
  101.    preloadServerDataBlocks();
  102.  
  103.    Server::loadMission( ($missionName = %mission), true );
  104.  
  105.    if(!%dedicated)
  106.    {
  107.       focusClient();
  108.  
  109.         if ($IRC::DisconnectInSim == "")
  110.         {
  111.             $IRC::DisconnectInSim = true;
  112.         }
  113.         if ($IRC::DisconnectInSim == true)
  114.         {
  115.             ircDisconnect();
  116.             $IRCConnected = FALSE;
  117.             $IRCJoinedRoom = FALSE;
  118.         }
  119.       // join up to the server
  120.       $Server::Address = "LOOPBACK:" @ $Server::Port;
  121.         $Server::JoinPassword = $Server::Password;
  122.       connect($Server::Address);
  123.    }
  124.    return "True";
  125. }
  126.  
  127. function Server::nextMission(%replay)
  128. {
  129.    if(%replay || $Server::TourneyMode)
  130.       %nextMission = $missionName;
  131.    else
  132.       %nextMission = $nextMission[$missionName];
  133.    echo("Changing to mission ", %nextMission, ".");
  134.    // give the clients enough time to load up the victory screen
  135.    Server::loadMission(%nextMission);
  136. }
  137.  
  138. function remoteCycleMission(%clientId)
  139. {
  140.    if(%clientId.isAdmin)
  141.    {
  142.       messageAll(0, Client::getName(%playerId) @ " cycled the mission.");
  143.       Server::nextMission();
  144.    }
  145. }
  146.  
  147. function remoteDataFinished(%clientId)
  148. {
  149.    Client::setDataFinished(%clientId);
  150.    %clientId.svNoGhost = ""; // clear the data flag
  151.    if($ghosting)
  152.    {
  153.       %clientId.ghostDoneFlag = true; // allow a CGA done from this dude
  154.       startGhosting(%clientId);  // let the ghosting begin!
  155.    }
  156. }
  157.  
  158. function remoteCGADone(%playerId)
  159. {
  160.    if(!%playerId.ghostDoneFlag || !$ghosting)
  161.       return;
  162.    %playerId.ghostDoneFlag = "";
  163.  
  164.    Game::initialMissionDrop(%playerid);
  165.  
  166.     if ($cdTrack != "")
  167.         remoteEval (%playerId, setMusic, $cdTrack, $cdPlayMode);
  168.    remoteEval(%playerId, MInfo, $missionName);
  169. }
  170.  
  171. function Server::loadMission(%missionName, %immed)
  172. {
  173.    if($loadingMission)
  174.       return;
  175.  
  176.    %missionFile = "missions\\" $+ %missionName $+ ".mis";
  177.    if(File::FindFirst(%missionFile) == "")
  178.    {
  179.       %missionName = $firstMission;
  180.       %missionFile = "missions\\" $+ %missionName $+ ".mis";
  181.       if(File::FindFirst(%missionFile) == "")
  182.       {
  183.          echo("invalid nextMission and firstMission...");
  184.          echo("aborting mission load.");
  185.          return;
  186.       }
  187.    }
  188.    echo("Notfifying players of mission change: ", getNumClients(), " in game");
  189.    for(%cl = Client::getFirst(); %cl != -1; %cl = Client::getNext(%cl))
  190.    {
  191.       Client::setGuiMode(%cl, $GuiModeVictory);
  192.       %cl.guiLock = true;
  193.       %cl.nospawn = true;
  194.       remoteEval(%cl, missionChangeNotify, %nextMission);
  195.    }
  196.  
  197.    $loadingMission = true;
  198.    $missionName = %missionName;
  199.    $missionFile = %missionFile;
  200.    $prevNumTeams = getNumTeams();
  201.  
  202.    deleteObject("MissionGroup");
  203.    deleteObject("MissionCleanup");
  204.    deleteObject("ConsoleScheduler");
  205.    resetPlayerManager();
  206.    resetGhostManagers();
  207.    $matchStarted = false;
  208.    $countdownStarted = false;
  209.    $ghosting = false;
  210.  
  211.    newObject(ConsoleScheduler, SimConsoleScheduler);
  212.    if(!%immed)
  213.       schedule("Server::finishMissionLoad();", 12);
  214.    else
  215.       Server::finishMissionLoad();      
  216. }
  217.  
  218. function Server::finishMissionLoad()
  219. {
  220.    $loadingMission = false;
  221.    // instant off of the manager
  222.    setInstantGroup(0);
  223.    newObject(MissionCleanup, SimGroup);
  224.  
  225.    exec($missionFile);
  226.    Mission::init();
  227.     Mission::reinitData();
  228.    if($prevNumTeams != getNumTeams())
  229.    {
  230.       // loop thru clients and setTeam to -1;
  231.       messageAll(0, "New teamcount - resetting teams.");
  232.       for(%cl = Client::getFirst(); %cl != -1; %cl = Client::getNext(%cl))
  233.          GameBase::setTeam(%cl, -1);
  234.    }
  235.  
  236.    $ghosting = true;
  237.    for(%cl = Client::getFirst(); %cl != -1; %cl = Client::getNext(%cl))
  238.    {
  239.       if(!%cl.svNoGhost)
  240.       {
  241.          %cl.ghostDoneFlag = true;
  242.          startGhosting(%cl);
  243.       }
  244.    }
  245.    if($SinglePlayer)
  246.    {
  247.       Game::startMatch();
  248.    }
  249.    else if($Server::warmupTime && !$Server::TourneyMode)
  250.    {
  251.       Server::Countdown($Server::warmupTime);
  252.    }
  253.    else if(!$Server::TourneyMode)
  254.    {
  255.       Game::startMatch();
  256.    }
  257.    $teamplay = (getNumTeams() != 1);
  258.    purgeResources(true);
  259.    return "True";
  260. }
  261.  
  262. function Server::Countdown(%time)
  263. {
  264.    $countdownStarted = true;
  265.    schedule("Game::startMatch();", %time);
  266.    Game::notifyMatchStart(%time);
  267.    if(%time > 30)
  268.       schedule("Game::notifyMatchStart(30);", %time - 30);
  269.    if(%time > 15)
  270.       schedule("Game::notifyMatchStart(15);", %time - 15);
  271.    if(%time > 10)
  272.       schedule("Game::notifyMatchStart(10);", %time - 10);
  273.    if(%time > 5)
  274.       schedule("Game::notifyMatchStart(5);", %time - 5);
  275. }
  276.  
  277. function Client::setInventoryText(%clientId, %txt)
  278. {
  279.    remoteEval(%clientId, "ITXT", %txt);
  280. }
  281.  
  282. function centerprint(%clientId, %msg, %timeout)
  283. {
  284.    if(%timeout == "")
  285.       %timeout = 5;
  286.    remoteEval(%clientId, "CP", %msg, %timeout);
  287. }
  288.  
  289. function bottomprint(%clientId, %msg, %timeout)
  290. {
  291.    if(%timeout == "")
  292.       %timeout = 5;
  293.    remoteEval(%clientId, "BP", %msg, %timeout);
  294. }
  295.  
  296. function topprint(%clientId, %msg, %timeout)
  297. {
  298.    if(%timeout == "")
  299.       %timeout = 5;
  300.    remoteEval(%clientId, "TP", %msg, %timeout);
  301. }
  302.  
  303. function centerprintall(%msg, %timeout)
  304. {
  305.    if(%timeout == "")
  306.       %timeout = 5;
  307.    for(%clientId = Client::getFirst(); %clientId != -1; %clientId = Client::getNext(%clientId))
  308.       remoteEval(%clientId, "CP", %msg, %timeout);
  309. }
  310.  
  311. function bottomprintall(%msg, %timeout)
  312. {
  313.    if(%timeout == "")
  314.       %timeout = 5;
  315.    for(%clientId = Client::getFirst(); %clientId != -1; %clientId = Client::getNext(%clientId))
  316.       remoteEval(%clientId, "BP", %msg, %timeout);
  317. }
  318.  
  319. function topprintall(%msg, %timeout)
  320. {
  321.    if(%timeout == "")
  322.       %timeout = 5;
  323.    for(%clientId = Client::getFirst(); %clientId != -1; %clientId = Client::getNext(%clientId))
  324.       remoteEval(%clientId, "TP", %msg, %timeout);
  325. }