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

  1. $curVoteTopic = "";
  2. $curVoteAction = "";
  3. $curVoteOption = "";
  4. $curVoteCount = 0;
  5.  
  6. function Admin::changeMissionMenu(%clientId)
  7. {
  8.    Client::buildMenu(%clientId, "Pick Mission Type", "cmtype", true);
  9.    %index = 1;
  10.    for(%type = 1; %type < $MLIST::TypeCount; %type++)
  11.       if($MLIST::Type[%type] != "Training")
  12.       {
  13.          Client::addMenuItem(%clientId, %index @ $MLIST::Type[%type], %type @ " 0");
  14.          %index++;
  15.       }
  16. }
  17.  
  18. function processMenuCMType(%clientId, %options)
  19. {
  20.    %curItem = 0;
  21.    %option = getWord(%options, 0);
  22.    %first = getWord(%options, 1);
  23.    Client::buildMenu(%clientId, "Pick Mission", "cmission", true);
  24.    
  25.    for(%i = 0; (%misIndex = getWord($MLIST::MissionList[%option], %first + %i)) != -1; %i++)
  26.    {
  27.       if(%i > 6)
  28.       {
  29.          Client::addMenuItem(%clientId, %i+1 @ "More missions...", "more " @ %first + %i @ " " @ %option);
  30.          break;
  31.       }
  32.       Client::addMenuItem(%clientId, %i+1 @ $MLIST::EName[%misIndex], %misIndex @ " " @ %option);
  33.    }
  34. }
  35.  
  36. function processMenuCMission(%clientId, %option)
  37. {
  38.    if(getWord(%option, 0) == "more")
  39.    {
  40.       %first = getWord(%option, 1);
  41.       %type = getWord(%option, 2);
  42.       processMenuCMType(%clientId, %type @ " " @ %first);
  43.       return;
  44.    }
  45.    %mi = getWord(%option, 0);
  46.    %mt = getWord(%option, 1);
  47.  
  48.    %misName = $MLIST::EName[%mi];
  49.    %misType = $MLIST::Type[%mt];
  50.  
  51.    // verify that this is a valid mission:
  52.    if(%misType == "" || %misType == "Training")
  53.       return;
  54.    for(%i = 0; true; %i++)
  55.    {
  56.       %misIndex = getWord($MLIST::MissionList[%mt], %i);
  57.       if(%misIndex == %mi)
  58.          break;
  59.       if(%misIndex == -1)
  60.          return;
  61.    }
  62.    if(%clientId.isAdmin)
  63.    {
  64.       messageAll(0, Client::getName(%clientId) @ " changed the mission to " @ %misName @ " (" @ %misType @ ")");
  65.         Vote::changeMission();
  66.       Server::loadMission(%misName);
  67.    }
  68.    else
  69.    {
  70.       Admin::startVote(%clientId, "change the mission to " @ %misName @ " (" @ %misType @ ")", "cmission", %misName);
  71.       Game::menuRequest(%clientId);
  72.    }
  73. }
  74.  
  75. function remoteAdminPassword(%client, %password)
  76. {
  77.    if($AdminPassword != "" && %password == $AdminPassword)
  78.    {
  79.       %client.isAdmin = true;
  80.       %client.isSuperAdmin = true;
  81.    }
  82. }
  83.  
  84. function remoteSetPassword(%client, %password)
  85. {
  86.    if(%client.isSuperAdmin)
  87.       $Server::Password = %password;
  88. }
  89.  
  90. function remoteSetTimeLimit(%client, %time)
  91. {
  92.    %time = floor(%time);
  93.    if(%time == $Server::timeLimit || (%time != 0 && %time < 1))
  94.       return;
  95.    if(%client.isAdmin)
  96.    {
  97.       $Server::timeLimit = %time;
  98.       if(%time)
  99.          messageAll(0, Client::getName(%client) @ " changed the time limit to " @ %time @ " minute(s).");
  100.       else
  101.          messageAll(0, Client::getName(%client) @ " disabled the time limit.");
  102.          
  103.    }
  104. }
  105.  
  106. function remoteSetTeamInfo(%client, %team, %teamName, %skinBase)
  107. {
  108.    if(%team >= 0 && %team < 8 && %client.isAdmin)
  109.    {
  110.       $Server::teamName[%team] = %teamName;
  111.       $Server::teamSkin[%team] = %skinBase;
  112.       messageAll(0, "Team " @ %team @ " is now \"" @ %teamName @ "\" with skin: " 
  113.          @ %skinBase @ " courtesy of " @ Client::getName(%client) @ ".  Changes will take effect next mission.");
  114.    }
  115. }
  116.  
  117. function Admin::setTeamDamageEnable(%admin, %enabled)
  118. {
  119.    if(%admin == -1 || %admin.isAdmin)
  120.    {
  121.       if(%enabled)
  122.       {
  123.          $Server::TeamDamageScale = 1;
  124.          if(%admin == -1)
  125.             messageAll(0, "Team damage set to ENABLED by consensus.");
  126.          else
  127.             messageAll(0, Client::getName(%admin) @ " ENABLED team damage.");
  128.       }
  129.       else
  130.       {
  131.          $Server::TeamDamageScale = 0;
  132.          if(%admin == -1)
  133.             messageAll(0, "Team damage set to DISABLED by consensus.");
  134.          else
  135.             messageAll(0, Client::getName(%admin) @ " DISABLED team damage.");
  136.       }
  137.    }
  138. }
  139.  
  140. function Admin::kick(%admin, %client)
  141. {
  142.    if(%admin == -1 || %admin.isAdmin)
  143.    {
  144.       if(%client.isSuperAdmin)
  145.       {
  146.          if(%admin == -1)
  147.             messageAll(0, "A super admin cannot be kicked.");
  148.          else
  149.             Client::sendMessage(%admin, 0, "A super admin cannot be kicked.");
  150.          return;
  151.       }
  152.       %ip = Client::getTransportAddress(%client);
  153.       if(%ip == "")
  154.          return;
  155.       BanList::add(%ip, 60);
  156.       if(%admin == -1)
  157.          Net::kick(%client, "You were kicked by consensus.");
  158.       else
  159.          Net::kick(%client, "You were kicked by " @ Client::getName(%admin));
  160.    }
  161. }
  162.  
  163. function Admin::setModeFFA(%clientId)
  164. {
  165.    if($Server::TourneyMode && (%clientId == -1 || %clientId.isAdmin))
  166.    {
  167.       if(%clientId == -1)
  168.          messageAll(0, "Server switched to Free-For-All Mode.");
  169.       else
  170.          messageAll(0, "Server switched to Free-For-All Mode by " @ Client::getName(%clientId) @ ".");
  171.  
  172.       $Server::TourneyMode = false;
  173.       if(!$matchStarted && !$countdownStarted)
  174.       {
  175.          if($Server::warmupTime)
  176.             Server::Countdown($Server::warmupTime);
  177.          else   
  178.             Game::startMatch();
  179.       }
  180.    }
  181. }
  182.  
  183. function Admin::setModeTourney(%clientId)
  184. {
  185.    if(!$Server::TourneyMode && (%clientId == -1 || %clientId.isAdmin))
  186.    {
  187.       if(%clientId == -1)
  188.          messageAll(0, "Server switched to Tournament Mode.");
  189.       else
  190.          messageAll(0, "Server switched to Tournament Mode by " @ Client::getName(%clientId) @ ".");
  191.  
  192.       $Server::TourneyMode = true;
  193.       Server::nextMission();
  194.    }
  195. }
  196.  
  197. function Admin::voteFailed()
  198. {
  199.    if($curVoteAction == "kick" || $curVoteAction == "admin")
  200.       $curVoteOption.voteTarget = "";
  201. }
  202.  
  203. function Admin::voteSucceded()
  204. {
  205.    if($curVoteAction == "kick")
  206.    {
  207.       if($curVoteOption.voteTarget)
  208.          Admin::kick(-1, $curVoteOption);
  209.    }
  210.    else if($curVoteAction == "admin")
  211.    {
  212.       if($curVoteOption.voteTarget)
  213.       {
  214.          $curVoteOption.isAdmin = true;
  215.          messageAll(0, Client::getName($curVoteOption) @ " has become an administrator.");
  216.          if($curVoteOption.menuMode == "options")
  217.             Game::menuRequest($curVoteOption);
  218.       }
  219.       $curVoteOption.voteTarget = false;
  220.    }
  221.    else if($curVoteAction == "cmission")
  222.    {
  223.       messageAll(0, "Changing to mission " @ $curVoteOption @ ".");
  224.         Vote::changeMission();
  225.       Server::loadMission($curVoteOption);
  226.    }
  227.    else if($curVoteAction == "tourney")
  228.       Admin::setModeTourney(-1);
  229.    else if($curVoteAction == "ffa")
  230.       Admin::setModeFFA(-1);
  231.    else if($curVoteAction == "etd")
  232.       Admin::setTeamDamageEnable(-1, true);
  233.    else if($curVoteAction == "dtd")
  234.       Admin::setTeamDamageEnable(-1, false);
  235. }
  236.  
  237. function Admin::countVotes(%curVote)
  238. {
  239.    // if %end is true, cancel the vote either way
  240.    if(%curVote != $curVoteCount)
  241.       return;
  242.  
  243.    %votesFor = 0;
  244.    %votesAgainst = 0;
  245.    %totalClients = 0;
  246.    %totalVotes = 0;
  247.    for(%cl = Client::getFirst(); %cl != -1; %cl = Client::getNext(%cl))
  248.    {
  249.       %totalClients++;
  250.       if(%cl.vote == "yes")
  251.       {
  252.          %votesFor++;
  253.          %totalVotes++;
  254.       }
  255.       else if(%cl.vote == "no")
  256.       {
  257.          %votesAgainst++;
  258.          %totalVotes++;
  259.       }
  260.    }
  261.    if(%totalVotes / %totalClients >= $Server::MinVotesPct &&
  262.       %votesFor / %totalVotes >= $Server::VoteWinMargin &&
  263.       %totalVotes >= $Server::MinVotes)
  264.    {
  265.       messageAll(0, "Vote to " @ $curVoteTopic @ " passed: " @ %votesFor @ " to " @ %votesAgainst @ " with " @ %totalClients - (%votesFor + %votesAgainst) @ " abstentions.");
  266.       Admin::voteSucceded();
  267.    }
  268.    else
  269.    {
  270.       messageAll(0, "Vote to " @ $curVoteTopic @ " did not pass: " @ %votesFor @ " to " @ %votesAgainst @ " with " @ %totalClients - (%votesFor + %votesAgainst) @ " abstentions.");
  271.       Admin::voteFailed();
  272.    }
  273.    $curVoteTopic = "";
  274. }
  275.  
  276. function Admin::startVote(%clientId, %topic, %action, %option)
  277. {
  278.    if(%clientId.lastVoteTime == "")
  279.       %clientId.lastVoteTime = -$Server::MinVoteTime;
  280.    %diff = %clientId.lastVoteTime + $Server::MinVoteTime - getSimTime();
  281.  
  282.    if(%diff > 0)
  283.    {
  284.       Client::sendMessage(%clientId, 0, "You can't start another vote for " @ floor(%diff) @ " seconds.");
  285.       return;
  286.    }
  287.    if($curVoteTopic == "")
  288.    {
  289.       %clientId.lastVoteTime = getSimTime();
  290.       $curVoteTopic = %topic;
  291.       $curVoteAction = %action;
  292.       $curVoteOption = %option;
  293.       $curVoteCount++;
  294.       bottomprintall("<jc><f1>" @ Client::getName(%clientId) @ " <f0>initiated a vote to <f1>" @ $curVoteTopic, 10);
  295.       for(%cl = Client::getFirst(); %cl != -1; %cl = Client::getNext(%cl))
  296.          %cl.vote = "";
  297.       %clientId.vote = "yes";
  298.       for(%cl = Client::getFirst(); %cl != -1; %cl = Client::getNext(%cl))
  299.          if(%cl.menuMode == "options")
  300.             Game::menuRequest(%clientId);
  301.       schedule("Admin::countVotes(" @ $curVoteCount @ ", true);", $Server::VotingTime, 35);
  302.    }
  303.    else
  304.    {
  305.       Client::sendMessage(%clientId, 0, "Voting already in progress.");
  306.    }
  307. }
  308.  
  309. function Game::menuRequest(%clientId)
  310. {
  311.    %curItem = 0;
  312.    Client::buildMenu(%clientId, "Options", "options", true);
  313.    if(!$matchStarted || !$Server::TourneyMode)
  314.    {
  315.       Client::addMenuItem(%clientId, %curItem++ @ "Change Teams/Observe", "changeteams");
  316.    }
  317.    if(%clientId.selClient)
  318.    {
  319.       %sel = %clientId.selClient;
  320.       %name = Client::getName(%sel);
  321.  
  322.       if($curVoteTopic == "" && !%clientId.isAdmin)
  323.       {
  324.          Client::addMenuItem(%clientId, %curItem++ @ "Vote to admin " @ %name, "vadmin " @ %sel);
  325.          Client::addMenuItem(%clientId, %curItem++ @ "Vote to kick " @ %name, "vkick " @ %sel);
  326.       }
  327.       if(%clientId.isAdmin)
  328.       {
  329.          Client::addMenuItem(%clientId, %curItem++ @ "Kick " @ %name, "kick " @ %sel);
  330.          Client::addMenuItem(%clientId, %curItem++ @ "Change " @ %name @ "'s team", "fteamchange " @ %sel);
  331.       }
  332.       if(%clientId.muted[%sel])
  333.          Client::addMenuItem(%clientId, %curItem++ @ "Unmute " @ %name, "unmute " @ %sel);
  334.       else
  335.          Client::addMenuItem(%clientId, %curItem++ @ "Mute " @ %name, "mute " @ %sel);
  336.    
  337.    }
  338.    if($curVoteTopic != "" && %clientId.vote == "")
  339.    {
  340.       Client::addMenuItem(%clientId, %curItem++ @ "Vote YES to " @ $curVoteTopic, "voteYes " @ $curVoteCount);
  341.       Client::addMenuItem(%clientId, %curItem++ @ "Vote NO to " @ $curVoteTopic, "voteNo " @ $curVoteCount);
  342.    }
  343.    else if($curVoteTopic == "" && !%clientId.isAdmin)
  344.    {
  345.       Client::addMenuItem(%clientId, %curItem++ @ "Vote to change mission", "vcmission");
  346.       if($Server::TeamDamageScale == 1.0)
  347.          Client::addMenuItem(%clientId, %curItem++ @ "Vote to disable team damage", "vdtd");
  348.       else
  349.          Client::addMenuItem(%clientId, %curItem++ @ "Vote to enable team damage", "vetd");
  350.                
  351.       if($Server::TourneyMode)
  352.          Client::addMenuItem(%clientId, %curItem++ @ "Vote to enter FFA mode", "vcffa");
  353.       else
  354.          Client::addMenuItem(%clientId, %curItem++ @ "Vote to enter Tournament mode", "vctourney");
  355.  
  356.    }
  357.    else if(%clientId.isAdmin)
  358.    {
  359.       Client::addMenuItem(%clientId, %curItem++ @ "Change mission", "cmission");
  360.       if($Server::TeamDamageScale == 1.0)
  361.          Client::addMenuItem(%clientId, %curItem++ @ "Disable team damage", "dtd");
  362.       else
  363.          Client::addMenuItem(%clientId, %curItem++ @ "Enable team damage", "etd");
  364.  
  365.       if($Server::TourneyMode)
  366.          Client::addMenuItem(%clientId, %curItem++ @ "Change to FFA mode", "cffa");
  367.       else
  368.          Client::addMenuItem(%clientId, %curItem++ @ "Change to Tournament mode", "ctourney");
  369.    }
  370. }
  371.  
  372. function remoteSelectClient(%clientId, %selId)
  373. {
  374.    if(%clientId.selClient != %selId)
  375.    {
  376.       %clientId.selClient = %selId;
  377.       if(%clientId.menuMode == "options")
  378.          Game::menuRequest(%clientId);
  379.       remoteEval(%clientId, "setInfoLine", 1, "Player Info for " @ Client::getName(%selId) @ ":");
  380.       remoteEval(%clientId, "setInfoLine", 2, "Real Name: " @ $Client::info[%selId, 1]);
  381.       remoteEval(%clientId, "setInfoLine", 3, "Email Addr: " @ $Client::info[%selId, 2]);
  382.       remoteEval(%clientId, "setInfoLine", 4, "Tribe: " @ $Client::info[%selId, 3]);
  383.       remoteEval(%clientId, "setInfoLine", 5, "URL: " @ $Client::info[%selId, 4]);
  384.       remoteEval(%clientId, "setInfoLine", 6, "Other: " @ $Client::info[%selId, 5]);
  385.    }
  386. }
  387.  
  388. function processMenuFPickTeam(%clientId, %team)
  389. {
  390.    if(%clientId.isAdmin)
  391.       processMenuPickTeam(%clientId.ptc, %team, %clientId);
  392.    %clientId.ptc = "";
  393. }
  394.  
  395. function processMenuPickTeam(%clientId, %team, %adminClient)
  396. {
  397.     checkPlayerCash(%clientId);
  398.    if(%team != -1 && %team == Client::getTeam(%clientId))
  399.       return;
  400.  
  401.    if(%clientId.observerMode == "justJoined")
  402.    {
  403.       %clientId.observerMode = "";
  404.       centerprint(%clientId, "");
  405.    }
  406.  
  407.    if((!$matchStarted || !$Server::TourneyMode || %adminClient) && %team == -2)
  408.    {
  409.       if(Observer::enterObserverMode(%clientId))
  410.       {
  411.          if(%adminClient == "") 
  412.             messageAll(0, Client::getName(%clientId) @ " became an observer.");
  413.          else
  414.             messageAll(0, Client::getName(%clientId) @ " was forced into observer mode by " @ Client::getName(%adminClient) @ ".");
  415.             Game::resetScores(%clientId);    
  416.            Game::refreshClientScore(%clientId);
  417.         }
  418.       return;
  419.    }
  420.  
  421.    %player = Client::getOwnedObject(%clientId);
  422.    if(%player != -1 && getObjectType(%player) == "Player" && !Player::isDead(%player)) {
  423.         playNextAnim(%clientId);
  424.        Player::kill(%clientId);
  425.     }
  426.    %clientId.observerMode = "";
  427.    if(%adminClient == "")
  428.       messageAll(0, Client::getName(%clientId) @ " changed teams.");
  429.    else
  430.       messageAll(0, Client::getName(%clientId) @ " was teamchanged by " @ Client::getName(%adminClient) @ ".");
  431.  
  432.    if(%team == -1)
  433.    {
  434.       Game::assignClientTeam(%clientId);
  435.       %team = Client::getTeam(%clientId);
  436.    }
  437.    GameBase::setTeam(%clientId, %team);
  438.    %clientId.teamEnergy = 0;
  439.     Client::clearItemShopping(%clientId);
  440.     if(Client::getGuiMode(%clientId) != 1)
  441.         Client::setGuiMode(%clientId,1);        
  442.     Client::setControlObject(%clientId, -1);
  443.  
  444.    Game::playerSpawn(%clientId, false);
  445.     %team = Client::getTeam(%clientId);
  446.     if($TeamEnergy[%team] != "Infinite")
  447.         $TeamEnergy[%team] += $InitialPlayerEnergy;
  448.  
  449.    if($Server::TourneyMode && !$CountdownStarted)
  450.    {
  451.       // loop through all the clients and see if any are still in
  452.       // pickingTeam observer mode:
  453.       %playerCount = 0;
  454.       for(%cl = Client::getFirst(); %cl != -1; %cl = Client::getNext(%cl))
  455.       {
  456.          if(%cl.observerMode == "pickingTeam")
  457.             return;
  458.          if(%cl.observerMode == "pregame")
  459.             %playerCount++;
  460.       }
  461.       if(%playerCount != 0)
  462.          Server::Countdown(30);
  463.    }
  464. }
  465.  
  466. function processMenuOptions(%clientId, %option)
  467. {
  468.    %opt = getWord(%option, 0);
  469.    %cl = getWord(%option, 1);
  470.  
  471.    if(%opt == "fteamchange")
  472.    {
  473.       %clientId.ptc = %cl;
  474.       Client::buildMenu(%clientId, "Pick a team:", "FPickTeam", true);
  475.       Client::addMenuItem(%clientId, "0Observer", -2);
  476.       Client::addMenuItem(%clientId, "1Automatic", -1);
  477.       for(%i = 0; %i < getNumTeams(); %i = %i + 1)
  478.          Client::addMenuItem(%clientId, (%i+2) @ getTeamName(%i), %i);
  479.       return;
  480.    }      
  481.    else if(%opt == "changeteams")
  482.    {
  483.       if(!$matchStarted || !$Server::TourneyMode)
  484.       {
  485.          Client::buildMenu(%clientId, "Pick a team:", "PickTeam", true);
  486.          Client::addMenuItem(%clientId, "0Observer", -2);
  487.          Client::addMenuItem(%clientId, "1Automatic", -1);
  488.          for(%i = 0; %i < getNumTeams(); %i = %i + 1)
  489.             Client::addMenuItem(%clientId, (%i+2) @ getTeamName(%i), %i);
  490.          return;
  491.       }
  492.    }
  493.    else if(%opt == "mute")
  494.       %clientId.muted[%cl] = true;
  495.    else if(%opt == "unmute")
  496.       %clientId.muted[%cl] = "";
  497.    else if(%opt == "vkick")
  498.    {
  499.       %cl.voteTarget = true;
  500.       Admin::startVote(%clientId, "kick " @ Client::getName(%cl), "kick", %cl);
  501.    }
  502.    else if(%opt == "vadmin")
  503.    {
  504.       %cl.voteTarget = true;
  505.       Admin::startVote(%clientId, "admin " @ Client::getName(%cl), "admin", %cl);
  506.    }
  507.    else if(%opt == "vetd")
  508.       Admin::startVote(%clientId, "enable team damage", "etd", 0);
  509.    else if(%opt == "vdtd")
  510.       Admin::startVote(%clientId, "disable team damage", "dtd", 0);
  511.    else if(%opt == "etd")
  512.       Admin::setTeamDamageEnable(%clientId, true);
  513.    else if(%opt == "dtd")
  514.       Admin::setTeamDamageEnable(%clientId, false);
  515.    else if(%opt == "vcffa")
  516.       Admin::startVote(%clientId, "change to Free For All mode", "ffa", 0);
  517.    else if(%opt == "vctourney")
  518.       Admin::startVote(%clientId, "change to Tournament mode", "tourney", 0);
  519.    else if(%opt == "cffa")
  520.       Admin::setModeFFA(%clientId);
  521.    else if(%opt == "ctourney")
  522.       Admin::setModeTourney(%clientId);
  523.    else if(%opt == "voteYes" && %cl == $curVoteCount)
  524.       %clientId.vote = "yes";
  525.    else if(%opt == "voteNo" && %cl == $curVoteCount)
  526.       %clientId.vote = "no";
  527.    else if(%opt == "kick")
  528.    {
  529.       Client::buildMenu(%clientId, "Confirm kick:", "kaffirm", true);
  530.       Client::addMenuItem(%clientId, "1Kick " @ Client::getName(%cl), "yes " @ %cl);
  531.       Client::addMenuItem(%clientId, "2Don't kick " @ Client::getName(%cl), "no " @ %cl);
  532.       return;
  533.    }
  534.    else if(%opt == "vcmission" || %opt == "cmission")
  535.    {
  536.       Admin::changeMissionMenu(%clientId, %opt == "cmission");
  537.       return;
  538.    }
  539.    Game::menuRequest(%clientId);
  540. }
  541.  
  542. function processMenuKAffirm(%clientId, %opt)
  543. {
  544.    if(getWord(%opt, 0) == "yes")
  545.       Admin::kick(%clientId, getWord(%opt, 1));
  546.    Game::menuRequest(%clientId);
  547. }