Advertisement
Guest User

Beta FlagPass Plugin Server Mods

a guest
Sep 14th, 2010
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.46 KB | None | 0 0
  1. // PassTheFlag.cpp : bzfs plugin to enable passing of flags (actually you throw them)
  2. //
  3. // $Id: PassTheFlag.cpp based on HTF plugin code by bullet_catcher $
  4.  
  5.  
  6. #include "bzfsAPI.h"
  7. #include "../../src/bzfs/bzfs.h"
  8. #include "../plugin_utils/plugin_utils.h"
  9. #include "BZDBCache.h"
  10. #include "../../src/bzfs/DropGeometry.h"
  11. #include <stdio.h>
  12. #include <stdarg.h>
  13.  
  14.  
  15.  
  16. BZ_GET_PLUGIN_VERSION
  17.  
  18. #define PASSTHEFLAG_VER "1.00.00"
  19.  
  20. #define DbgLevelAlways  1
  21. #define DbgLevelErr 1
  22. #define DbgLevelWarn    2
  23. #define DbgLevelInfo    3
  24. #define DbgLevelExtraInfo   4
  25. //#define DbgLevelDbgInfo   5
  26. #define DbgLevelDbgInfo 1
  27.  
  28.  
  29.  
  30. class FPassHandler : public bz_EventHandler, public bz_CustomSlashCommandHandler
  31. {
  32. public:
  33.     virtual void process ( bz_EventData *eventData );
  34.     virtual bool handle ( int playerID, bzApiString, bzApiString, bzAPIStringList*);
  35.    
  36. protected:
  37.    
  38. private:
  39. };
  40.  
  41. FPassHandler FlagPassHandler;
  42.  
  43. class PlayerStats   {
  44.    
  45. public:
  46.    
  47.     int thisPlayerID;
  48.     float velocity[3];
  49.     bzApiString callsign;
  50.    
  51.     void SetStats(int playerID, const float *velocity) {
  52.         if (velocity && (this->thisPlayerID == playerID))
  53.             {
  54.                 memcpy(this->velocity, velocity, sizeof(float[3]));
  55.             }
  56.     }
  57.    
  58.     void SetData(int playerID, const float *velocity, const bzApiString *callsign) {
  59.         this->thisPlayerID = playerID;
  60.         this->velocity[0] = velocity?velocity[0]:0.0;
  61.         this->velocity[1] = velocity?velocity[1]:0.0;
  62.         this->velocity[2] = velocity?velocity[2]:0.0;
  63.         this->callsign = callsign?*callsign:bzApiString();
  64.     }
  65.    
  66.     PlayerStats(int playerID, const float *velocity, const bzApiString *callsign) { SetData(playerID, velocity, callsign);  };
  67.     PlayerStats(const PlayerStats& inData) {
  68.         if (this != &inData)
  69.             {
  70.                 SetData(inData.thisPlayerID, inData.velocity, &inData.callsign);
  71.             }
  72.     };
  73.     PlayerStats() { SetData(-1, NULL, NULL);    };
  74.    
  75.     PlayerStats& operator=(const PlayerStats& other);
  76.    
  77.     bool operator==(const PlayerStats& other) const;
  78.     bool operator!=(const PlayerStats& other) const { return !(*this == other); }
  79.    
  80. };
  81.  
  82.  
  83.  
  84. // operator ==
  85. inline bool PlayerStats::operator==(const PlayerStats& inData) const
  86. {
  87.     return (thisPlayerID == inData.thisPlayerID);
  88. }
  89.  
  90.  
  91.  
  92. PlayerStats& PlayerStats::operator=(const PlayerStats& other)
  93. {
  94.     if (this != &other)
  95.         {      
  96.             SetData(other.thisPlayerID, other.velocity, &other.callsign);
  97.         }
  98.     return *this;
  99. }
  100.  
  101.  
  102.  
  103.  
  104. bool FPassEnabled = true;
  105. bool FumbleMsg = true;
  106. float FPassThrowDistance = 6.0;
  107. int MaxSafeZoneTests = 5;
  108.  
  109. std::vector <PlayerStats> gActivePlayers;
  110.  
  111.  
  112.  
  113. PlayerStats *GetActivePlayerStatsByID(int PlayerID)
  114. {
  115.     static PlayerStats UnKnown;
  116.     UnKnown.SetData(-1, NULL, NULL);
  117.    
  118.     for(unsigned int i=0;i<gActivePlayers.size();i++)
  119.         {
  120.             if (gActivePlayers[i].thisPlayerID == PlayerID)
  121.                 {
  122.                     return &gActivePlayers[i];
  123.                 }
  124.         }
  125.     return &UnKnown;
  126. }
  127.  
  128.  
  129. bool RemovePlayerStatsForPlayerID(int PlayerID)
  130. {
  131.     std::vector<PlayerStats>::iterator iter = gActivePlayers.begin();
  132.     while( iter != gActivePlayers.end() )
  133.         {
  134.             if (iter->thisPlayerID == PlayerID)
  135.                 {
  136.                     iter = gActivePlayers.erase( iter );
  137.                     return true;
  138.                 }
  139.             else
  140.                 ++iter;
  141.         }
  142.     return false;
  143. }
  144.  
  145.  
  146. void sendHelp (int who)
  147. {
  148.     bz_sendTextMessage(BZ_SERVER, who, "FPass commands: [off|on|stat|dist=<real num 0.0 or greater>|steps=<integer 0 or greater>]");
  149. }
  150.  
  151. bool do_checkFlagDropAtPoint ( int flagID, float dropPos[3], float landing[3] )
  152. {
  153.     assert(world != NULL);
  154.    
  155.     const float size = BZDBCache::worldSize * 0.5f;
  156.     float pos[3];
  157.     pos[0] = ((dropPos[0] < -size) || (dropPos[0] > size)) ? 0.0f : dropPos[0];
  158.     pos[1] = ((dropPos[1] < -size) || (dropPos[1] > size)) ? 0.0f : dropPos[1];
  159.     //  pos[2] = (dropPos[2] > maxWorldHeight) ? maxWorldHeight : dropPos[2];
  160.     pos[2] = dropPos[2];
  161.    
  162.     FlagInfo& thisFlag = *FlagInfo::get(flagID);
  163.     int flagTeam = thisFlag.flag.type->flagTeam;
  164.    
  165.     const float waterLevel = world->getWaterLevel();
  166.     float minZ = 0.0f;
  167.     if (waterLevel > minZ) {
  168.         minZ = waterLevel;
  169.     }
  170.     const float maxZ = MAXFLOAT;
  171.    
  172.     landing[0] = pos[0];
  173.     landing[1] = pos[1];
  174.     landing[2] = pos[2];
  175.     bool safelyDropped = DropGeometry::dropTeamFlag(landing, minZ, maxZ, flagTeam);     // Pretend we are dropping the team flag
  176.    
  177.     return safelyDropped;
  178.     //return world->getFlagDropPoint(FlagInfo::get(flagID), drop_pos, land_pos);
  179. }
  180.  
  181.  
  182.  
  183.  
  184. /************************** (SUB)COMMAND Implementations ... **************************/
  185.  
  186. void FPassStats (int who)
  187. {
  188.     bz_sendTextMessagef(BZ_SERVER, who, "FPass plugin version %s", PASSTHEFLAG_VER);
  189.     bz_sendTextMessagef(BZ_SERVER, who,  "  Flag Passing is turned %s" , FPassEnabled ? "ON":"OFF");
  190.     bz_sendTextMessagef(BZ_SERVER, who,  "  Flag Throw Distance: %f" , FPassThrowDistance);
  191.     bz_sendTextMessagef(BZ_SERVER, who,  "  Max Attempts to land flag: %d" , MaxSafeZoneTests);
  192.     bz_sendTextMessagef(BZ_SERVER, who,  "  Fumble Messages are turned %s" , FumbleMsg ? "ON":"OFF");
  193. }
  194.  
  195.  
  196. void FPassEnable (bool onoff, int who)
  197. {
  198.     char msg[255];
  199.     char ObserverMsg[] = "an observer";
  200.     const char *PlayerName = ObserverMsg;
  201.     if (onoff == FPassEnabled){
  202.         bz_sendTextMessage(BZ_SERVER, who, "Flag Passing is already that way.");
  203.         return;
  204.     }
  205.     FPassEnabled = onoff;
  206.     PlayerStats *StatsForThisPlayer = GetActivePlayerStatsByID(who);
  207.     if (StatsForThisPlayer->thisPlayerID == who)
  208.         PlayerName = StatsForThisPlayer->callsign.c_str();
  209.     sprintf (msg, "*** Flag Passing turned %s by %s", onoff?"ON":"OFF", PlayerName);
  210.     bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, msg);
  211. }
  212.  
  213.  
  214.  
  215.  
  216. void FumbleMsgEnable (bool onoff, int who)
  217. {
  218.     char msg[255];
  219.     char ObserverMsg[] = "an observer";
  220.     const char *PlayerName = ObserverMsg;
  221.     if (onoff == FumbleMsg){
  222.         bz_sendTextMessage(BZ_SERVER, who, "Fumble Messaging is already that way.");
  223.         return;
  224.     }
  225.     FumbleMsg = onoff;
  226.     PlayerStats *StatsForThisPlayer = GetActivePlayerStatsByID(who);
  227.     if (StatsForThisPlayer->thisPlayerID == who)
  228.         PlayerName = StatsForThisPlayer->callsign.c_str();
  229.     sprintf (msg, "*** Fumble Messages turned %s by %s", onoff?"ON":"OFF", PlayerName);
  230.     bz_sendTextMessage(BZ_SERVER, BZ_ALLUSERS, msg);
  231. }
  232.  
  233.  
  234.  
  235.  
  236. bool getPlayerVelocity(int playerID, float vel[3])
  237. {
  238.     PlayerStats *StatsForThisPlayer = GetActivePlayerStatsByID(playerID);
  239.     memcpy(vel, StatsForThisPlayer->velocity, sizeof(float[3]));
  240.     return (StatsForThisPlayer->thisPlayerID == playerID);
  241. }
  242.  
  243.  
  244.  
  245. bool getPlayerPosition(int playerID, float PlayerPos[3])
  246. {
  247.     bz_PlayerRecord* player = bz_getPlayerByIndex(playerID);
  248.     if (!player) {
  249.         return false;
  250.     }
  251.     memcpy(PlayerPos, player->pos, sizeof(float[3]));
  252.     return true;
  253. }
  254.  
  255.  
  256.  
  257. bool playerIsAdmin(int playerID)
  258. {
  259.     bz_PlayerRecord* player = bz_getPlayerByIndex(playerID);
  260.     if (!player) {
  261.         return false;
  262.     }
  263.     return player->admin;
  264. }
  265.  
  266.  
  267.  
  268. // handle events
  269. void FPassHandler::process ( bz_EventData *eventData )
  270. {
  271.     // Flag Dropped
  272.     if (bz_eFlagDroppedEvent == eventData->eventType)
  273.         {
  274.             if (FPassEnabled)
  275.                 {
  276.                     float PlayerVelocity[3];
  277.                     float PlayerPos[3];
  278.                     float FlagDropPos[3];
  279.                     float FlagLandingPos[3];
  280.                    
  281.                     bz_FlagDroppedEventData *dropData = (bz_FlagDroppedEventData*)eventData;
  282.                     bz_debugMessagef(DbgLevelDbgInfo, "++++++ FPassHandler: Player %s will drop Flag (ID:%d, Flag:%d, drop_pos:(%f, %f, %f))", GetActivePlayerStatsByID(dropData->playerID)->callsign.c_str(), dropData->playerID, dropData->flagID, dropData->pos[0], dropData->pos[1], dropData->pos[2]); fflush (stdout);
  283.                     if (getPlayerVelocity(dropData->playerID, PlayerVelocity))
  284.                         {
  285.                             bz_debugMessagef(DbgLevelDbgInfo, "             velocity: %f, %f, %f", PlayerVelocity[0], PlayerVelocity[1], PlayerVelocity[2]); fflush (stdout);
  286.                         }
  287.                     else
  288.                         {
  289.                             bz_debugMessagef(DbgLevelErr, "++++++ FPassHandler: velocity: ERR"); fflush (stdout);
  290.                             return;
  291.                         }
  292.                     if ((0.0 == PlayerVelocity[0]) && (0.0 == PlayerVelocity[1]))
  293.                         return; // Nothing to do here
  294.                     if (getPlayerPosition(dropData->playerID, PlayerPos))
  295.                         {
  296.                             bz_debugMessagef(DbgLevelDbgInfo, "             PlayerPos: %f, %f, %f", PlayerPos[0], PlayerPos[1], PlayerPos[2]); fflush (stdout);
  297.                         }
  298.                     else
  299.                         {
  300.                             bz_debugMessagef(DbgLevelErr, "++++++ FPassHandler: PlayerPos: ERR"); fflush (stdout);
  301.                             return;
  302.                         }
  303.                     float JumpBoost = 1.0;
  304.                     if (PlayerVelocity[2]>0.0)
  305.                         JumpBoost = 2.0;
  306.                     else
  307.                         if (PlayerVelocity[2]<0.0)
  308.                             JumpBoost = 0.5;
  309.                     FlagDropPos[0] = PlayerPos[0] + FPassThrowDistance * PlayerVelocity[0] * JumpBoost;
  310.                     FlagDropPos[1] = PlayerPos[1] + FPassThrowDistance * PlayerVelocity[1] * JumpBoost;
  311.                     FlagDropPos[2] = dropData->pos[2];
  312.                     bool PassWasFumbled = false;
  313.                     bool ValidFlagThrow;
  314.                     int TriesLeft = MaxSafeZoneTests;
  315.                     float DeltaX, DeltaY ;
  316.                     DeltaX = DeltaY = 0.0;
  317.                     if (0 < MaxSafeZoneTests)
  318.                         {
  319.                             DeltaX = (PlayerPos[0] - FlagDropPos[0])/MaxSafeZoneTests;
  320.                             DeltaY = (PlayerPos[1] - FlagDropPos[1])/MaxSafeZoneTests;
  321.                         }
  322.                     do
  323.                         {
  324.                             ValidFlagThrow = do_checkFlagDropAtPoint(dropData->flagID, FlagDropPos, FlagLandingPos);
  325.                             // Check for flags that were left up high
  326.                             if (ValidFlagThrow)
  327.                                 ValidFlagThrow = FlagLandingPos[2] <= FlagDropPos[2];
  328.                             // Check for flags that need to be moved
  329.                             if (ValidFlagThrow)
  330.                                 ValidFlagThrow = (FlagLandingPos[0] == FlagDropPos[0]) && (FlagLandingPos[1] == FlagDropPos[1]);        // Perhaps we should allow a tolerance here
  331.                             if (!PassWasFumbled)
  332.                                 PassWasFumbled = !ValidFlagThrow;
  333.                             TriesLeft--;
  334.                             if ((!ValidFlagThrow) && (TriesLeft >= 0))
  335.                                 {
  336.                                     FlagDropPos[0] += DeltaX;
  337.                                     FlagDropPos[1] += DeltaY;
  338.                                 }
  339.                         }
  340.                     while ((!ValidFlagThrow) && (TriesLeft >= 0));
  341.                     if (PassWasFumbled && FumbleMsg)
  342.                         {
  343.                             bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "%s fumbled the pass.", GetActivePlayerStatsByID(dropData->playerID)->callsign.c_str());
  344.                         }
  345.                     if (!ValidFlagThrow)
  346.                         {
  347.                             bz_debugMessagef(DbgLevelDbgInfo, "             PlayerPos: Invalid Drop Point!!  DropPos=(%f, %f, %f) FlagLandingPos:  %f, %f, %f", FlagDropPos[0], FlagDropPos[1], FlagDropPos[2], FlagLandingPos[0], FlagLandingPos[1], FlagLandingPos[2]); fflush (stdout);
  348.                         }
  349.                     else
  350.                         {
  351.                             FlagInfo& flag = *FlagInfo::get(dropData->flagID);
  352.                            
  353.                             flag.dropFlag(dropData->pos, FlagLandingPos, false);
  354.                             sendDrop(flag);
  355.                             sendFlagUpdate(flag);
  356.                             bz_debugMessagef(DbgLevelDbgInfo, "             FlagLandingPos:  %f, %f, %f", FlagLandingPos[0], FlagLandingPos[1], FlagLandingPos[2]); fflush (stdout);
  357.                         }
  358.                 }
  359.         }
  360.     else if (bz_ePlayerUpdateEvent == eventData->eventType)
  361.         {
  362.             bz_PlayerUpdateEventData* playerupdatedata = (bz_PlayerUpdateEventData*)eventData;
  363.             //bz_debugMessagef(DbgLevelDbgInfo, "++++++ FPassHandler: PlayerUpdateEvent for player %d velocity = %f, %f, %f", playerupdatedata->playerID, playerupdatedata->velocity[0], playerupdatedata->velocity[1], playerupdatedata->velocity[2]); fflush (stdout);
  364.             PlayerStats *StatsForThisPlayer = GetActivePlayerStatsByID(playerupdatedata->playerID);
  365.             if (StatsForThisPlayer->thisPlayerID == playerupdatedata->playerID)
  366.                 {
  367.                     StatsForThisPlayer->SetStats(playerupdatedata->playerID, playerupdatedata->velocity);
  368.                     //bz_debugMessagef(DbgLevelDbgInfo, "++++++ FPassHandler: PlayerUpdateEvent for player %d", playerupdatedata->playerID); fflush (stdout);
  369.                 }
  370.             else
  371.                 {
  372.                     bz_debugMessagef(DbgLevelErr, "++++++ FPassHandler: PlayerUpdate: ERR"); fflush (stdout);
  373.                 }
  374.         }
  375.     else if (bz_ePlayerJoinEvent == eventData->eventType)
  376.         {
  377.             bz_PlayerJoinPartEventData *joinData = (bz_PlayerJoinPartEventData*)eventData;
  378.             if (joinData->team != eObservers)
  379.                 {
  380.                     float NoVelocity[3];
  381.                     NoVelocity[0] = NoVelocity[1] = NoVelocity[2] = 0.0;
  382.                     PlayerStats NewPlayer(joinData->playerID, NoVelocity, &joinData->callsign);
  383.                     gActivePlayers.push_back(NewPlayer);
  384.                     bz_debugMessagef(DbgLevelDbgInfo, "++++++ FPassHandler: created PlayerStats for %d", joinData->playerID); fflush (stdout);
  385.                 }
  386.         }
  387.     else if (bz_ePlayerPartEvent == eventData->eventType)
  388.         {
  389.             bz_PlayerJoinPartEventData *partingData = (bz_PlayerJoinPartEventData*)eventData;
  390.             if (partingData->team != eObservers)
  391.                 {
  392.                     if (RemovePlayerStatsForPlayerID(partingData->playerID))
  393.                         {
  394.                             bz_debugMessagef(DbgLevelDbgInfo, "++++++ FPassHandler: removed PlayerStats for %d", partingData->playerID); fflush (stdout);
  395.                         }
  396.                     else
  397.                         {
  398.                             bz_debugMessagef(DbgLevelErr, "++++++ FPassHandler: ERR no PlayerStats for player %d", partingData->playerID); fflush (stdout);
  399.                         }
  400.                 }
  401.         }
  402. }
  403.  
  404.  
  405.  
  406. bool checkPerms (int playerID, const char *FPassCmd, const char *permName)
  407. {
  408.     bool HasPerm = false;
  409.     return true;//zxcv
  410.     if ('\0' == *permName)  // Needs Admin
  411.         HasPerm = playerIsAdmin (playerID);
  412.     else
  413.         HasPerm = bz_hasPerm (playerID, permName);
  414.     if (!HasPerm)
  415.         bz_sendTextMessagef (BZ_SERVER, BZ_ALLUSERS, "you need \"%s\" permission to do /FPass %s", *permName?permName:"Admin", FPassCmd);
  416.     return HasPerm;
  417. }
  418.  
  419.  
  420.  
  421. bool SetThrowDistance(const char *FloatStr, int *CharsUsed)
  422. {
  423.     float FloatVal = 0.0;
  424.     char *EndOfNum = (char *) FloatStr;
  425.     FloatVal = strtof (FloatStr, &EndOfNum);
  426.     if (EndOfNum == FloatStr)
  427.         return false;
  428.     if (CharsUsed)
  429.         *CharsUsed = (EndOfNum - FloatStr);
  430.     bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "++++++ FPassHandler: Flag Throw Distance: Chaged from %f to %f", FPassThrowDistance, FloatVal); fflush (stdout);
  431.     FPassThrowDistance = FloatVal;
  432.     return true;
  433. }
  434.  
  435.  
  436.  
  437. bool SetMaxIterations(const char *IntStr)
  438. {
  439.     int IntVal = 0;
  440.     char *EndOfNum = (char *) IntStr;
  441.     IntVal = strtol (IntStr, &EndOfNum, 10);
  442.     if (EndOfNum == IntStr)
  443.         return false;
  444.     bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "++++++ FPassHandler: Max Attempts to land flag: Chaged from %d to %d", MaxSafeZoneTests, IntVal);
  445.     MaxSafeZoneTests = IntVal;
  446.     return true;
  447. }
  448.  
  449.  
  450.  
  451.  
  452. // handle /FPass command
  453. bool FPassHandler::handle ( int playerID, bzApiString cmd, bzApiString, bzAPIStringList* cmdParams )
  454. {
  455.     char subCmd[8];
  456.     if (strcasecmp (cmd.c_str(), "fpass"))   // is it for me ?
  457.         return false;
  458.     if (cmdParams->get(0).c_str()[0] == '\0'){
  459.         FPassStats (playerID);
  460.         return true;
  461.     }
  462.    
  463.  
  464.     bz_debugMessagef(DbgLevelDbgInfo, "++++++ FPassHandler::handle:  cmdParams->get(0).c_str() = \"%s\"",  cmdParams->get(0).c_str()); fflush (stdout);
  465.     strncpy (subCmd, cmdParams->get(0).c_str(), 7);
  466.     subCmd[6] = '\0';
  467.     bz_debugMessagef(DbgLevelDbgInfo, "++++++ FPassHandler::handle:  subCmd = \"%s\"",  subCmd); fflush (stdout);
  468.     if (strncasecmp (subCmd, "dist=", 5) == 0){
  469.         if (checkPerms (playerID, "dist", ""))
  470.             {
  471.                 if (!SetThrowDistance(cmdParams->get(0).c_str() + 5, NULL))
  472.                     {
  473.                         sendHelp(playerID);
  474.                     }
  475.             }
  476.     } else if (strncasecmp (subCmd, "fmsg=", 5) == 0){
  477.         if (checkPerms (playerID, "fmsg", ""))
  478.             {
  479.                 char CmdParam[5];
  480.                 strncpy (CmdParam, cmdParams->get(0).c_str() + 5, 4);
  481.                 if (strcasecmp (CmdParam, "off") == 0)
  482.                     FumbleMsgEnable (false, playerID);
  483.                 else if (strcasecmp (CmdParam, "on") == 0)
  484.                     FumbleMsgEnable (true, playerID);
  485.                 else
  486.                     {
  487.                         sendHelp(playerID);
  488.                     }
  489.             }
  490.     } else if (strcasecmp (subCmd, "steps=") == 0){
  491.         if (checkPerms (playerID, "steps", ""))
  492.             {
  493.                 if (!SetMaxIterations(cmdParams->get(0).c_str() + 6))
  494.                     {
  495.                         sendHelp(playerID);
  496.                     }
  497.             }
  498.     } else if (strcasecmp (subCmd, "off") == 0){
  499.         if (checkPerms (playerID, "off", "COUNTDOWN"))
  500.             FPassEnable (false, playerID);
  501.     } else if (strcasecmp (subCmd, "on") == 0){
  502.         if (checkPerms (playerID, "on", "COUNTDOWN"))
  503.             FPassEnable (true, playerID);
  504.     } else if (strcasecmp (subCmd, "stat") == 0)
  505.         FPassStats (playerID);
  506.     else
  507.         sendHelp (playerID);
  508.     return true;
  509. }
  510.  
  511.  
  512. bool commandLineHelp (void){
  513.     const char *help[] = {
  514.         "Command line args:  PLUGINNAME[,dist=<0.0 .. 10.0>][,steps=<0 .. 20>],",
  515.         NULL
  516.     };
  517.     bz_debugMessage (0, "+++ PassTheFlag plugin command-line error");
  518.     for (int x=0; help[x]!=NULL; x++)
  519.         bz_debugMessage (0, help[x]);
  520.     return true;
  521. }
  522.  
  523.  
  524.  
  525. bool parseCommandLine (const char *cmdLine)
  526. {
  527.     int CharOffset = 0;
  528.     if (cmdLine==NULL || *cmdLine=='\0')
  529.         return false;
  530.     if (strncasecmp (cmdLine, "dist=", 5) == 0)
  531.         {
  532.             if (!SetThrowDistance(cmdLine+5, &CharOffset))
  533.                 return commandLineHelp ();
  534.             else
  535.                 CharOffset += 5 + 1;
  536.         }
  537.     if (strncasecmp (cmdLine + CharOffset, "steps=", 6) == 0)
  538.         {
  539.             if (!SetMaxIterations(cmdLine+6+CharOffset))
  540.                 return commandLineHelp ();
  541.         }
  542.     return false;
  543. }
  544.  
  545.  
  546. BZF_PLUGIN_CALL int bz_Load (const char* cmdLine)
  547. {
  548.     if (parseCommandLine (cmdLine))
  549.         return -1;
  550.    
  551.     bz_registerCustomSlashCommand ("fpass", &FlagPassHandler);
  552.     bz_registerEvent(bz_eFlagDroppedEvent, &FlagPassHandler);
  553.     bz_registerEvent(bz_ePlayerJoinEvent, &FlagPassHandler);
  554.     bz_registerEvent(bz_ePlayerPartEvent, &FlagPassHandler);
  555.     bz_registerEvent(bz_ePlayerUpdateEvent, &FlagPassHandler);
  556.     bz_debugMessagef(DbgLevelAlways, "PassTheFlag plugin loaded - v%s ApiVersion=v%d", PASSTHEFLAG_VER, BZ_API_VERSION);
  557.     return 0;
  558. }
  559.  
  560. BZF_PLUGIN_CALL int bz_Unload (void)
  561. {
  562.     bz_removeCustomSlashCommand ("fpass");
  563.     bz_removeEvent (bz_eFlagDroppedEvent, &FlagPassHandler);
  564.     bz_removeEvent (bz_ePlayerJoinEvent, &FlagPassHandler);
  565.     bz_removeEvent (bz_ePlayerPartEvent, &FlagPassHandler);
  566.     bz_removeEvent (bz_ePlayerUpdateEvent, &FlagPassHandler);
  567.     bz_debugMessage(DbgLevelAlways, "PassTheFlag plugin unloaded");
  568.     return 0;
  569. }
  570.  
  571.  
  572. // Local Variables: ***
  573. // mode:C++ ***
  574. // tab-width: 8 ***
  575. // c-basic-offset: 2 ***
  576. // indent-tabs-mode: t ***
  577. // End: ***
  578. // ex: shiftwidth=2 tabstop=8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement