| 5454 | //------------------------------------------------------------------------- |
| 5455 | |
| 5456 | BZF_API bool bz_RegisterCustomFlag(const char* abbr, const char* name, |
| 5457 | const char* help, bz_eShotType shotType, |
| 5458 | bz_eFlagQuality quality) { |
| 5459 | // require defined fields |
| 5460 | if (!abbr || !name || !help) { |
| 5461 | return false; |
| 5462 | } |
| 5463 | |
| 5464 | // length limits |
| 5465 | if ((strlen(abbr) > 2) || (strlen(name) > 32) || (strlen(help) > 128)) { |
| 5466 | return false; |
| 5467 | } |
| 5468 | |
| 5469 | // don't register an existing flag (i.e. can't override builtins) |
| 5470 | if (Flag::getDescFromAbbreviation(abbr) != Flags::Null) { |
| 5471 | return false; |
| 5472 | } |
| 5473 | |
| 5474 | FlagEndurance e = FlagUnstable; |
| 5475 | switch (quality) { |
| 5476 | case eGoodFlag: e = FlagUnstable; break; |
| 5477 | case eBadFlag: e = FlagSticky; break; |
| 5478 | default: return false; // shouldn't happen |
| 5479 | } |
| 5480 | |
| 5481 | /* let this pointer dangle. the constructor has taken care of all |
| 5482 | * the real work on the server side. |
| 5483 | */ |
| 5484 | FlagType* tmp = new FlagType(name, abbr, e, (ShotType)shotType, (FlagQuality)quality, NoTeam, help, true); |
| 5485 | |
| 5486 | /* default the shot limit. note that -sl will still take effect, if |
| 5487 | * this plugin is loaded from the command line or config file, since |
| 5488 | * it's processed in finalization |
| 5489 | */ |
| 5490 | clOptions->flagLimit[tmp] = -1; |
| 5491 | |
| 5492 | /* notify existing players (if any) about the new flag type. this |
| 5493 | * behavior is a bit questionable, but seems to be the Right |
| 5494 | * Thing(tm) to do. new clients will get the notification during |
| 5495 | * flag negotiation, which is better. |
| 5496 | */ |
| 5497 | NetMessage netMsg; |
| 5498 | tmp->packCustom(netMsg); |
| 5499 | netMsg.broadcast(MsgFlagType); |
| 5500 | |
| 5501 | return true; |
| 5502 | } |
| 5503 | |
| 5504 | |
| 5505 |
no test coverage detected