-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
mottofilter.cpp
111 lines (94 loc) · 3.76 KB
/
mottofilter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
League Over Seer Plug-in
Copyright (C) 2012 Ned Anderson & Vladimir Jimenez
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "bzfsAPI.h"
#include "PlayerInfo.h"
#include "../../src/bzfs/GameKeeper.h"
#include "../../src/bzfs/RejoinList.h"
class mottofilter : public bz_Plugin, bz_CustomSlashCommandHandler
{
virtual const char* Name (){return "Motto Replacer";}
virtual void Init ( const char* config);
virtual void Cleanup (void);
virtual bool SlashCommand ( int , bz_ApiString, bz_ApiString, bz_APIStringList* );
virtual void Event ( bz_EventData * /* eventData */ );
const char* getGuTeamFromBzId(std::string bzid);
};
BZ_PLUGIN(mottofilter)
void mottofilter::Init ( const char* /*commandLine*/ )
{
bz_debugMessage(4,"mottofilter plugin loaded");
Register(bz_eAllowPlayer);
Register(bz_ePlayerJoinEvent);
bz_registerCustomSlashCommand("spawn", this);
// init events here with Register();
}
const char* mottofilter::getGuTeamFromBzId(std::string bzid)
{
//get team name from GU website.
const char* playerTeam = "allejo needs to do this:p";
return playerTeam;
}
bool mottofilter::SlashCommand ( int playerID, bz_ApiString command, bz_ApiString message, bz_APIStringList* cmdParams )
{
bz_BasePlayerRecord *player = bz_getPlayerByIndex(playerID);
if (!player)
return true;
if(command == "spawn" && player->admin) {
if(cmdParams->size() == 1) {
const char* msg = message.c_str() + 6;
while ((*msg != '\0') && isspace(*msg)) msg++;
if(isdigit(msg[0])) {
int grantee = (int) atoi(cmdParams->get(0).c_str());
bz_grantPerm(grantee, "spawn");
} else if(!isdigit(msg[0])) {
int grantee = GameKeeper::Player::getPlayerIDByName(cmdParams->get(0).c_str());
bz_grantPerm(grantee, "spawn");
}
}
} else if(!player->admin){
bz_sendTextMessage(BZ_SERVER,playerID,"You do not have permission to use that command.");
bz_freePlayerRecord(player);
return true;
}
bz_freePlayerRecord(player);
return true;
}
void mottofilter::Event(bz_EventData * eventData) {
//substitute motto with team name/abbv.
if(eventData->eventType == bz_eAllowPlayer) {
bz_AllowPlayerEventData_V1 *allowData = (bz_AllowPlayerEventData_V1*)eventData;
GameKeeper::Player *playerData = GameKeeper::Player::getPlayerByIndex(allowData->playerID);
bz_BasePlayerRecord *record = bz_getPlayerByIndex(allowData->playerID);
std::string mottoBefore = playerData->player.getMotto();
const char* newMotto = getGuTeamFromBzId(playerData->getBzIdentifier());
bz_debugMessagef(4, "Player Joined: MottoFilter: BzId value == %s", playerData->getBzIdentifier().c_str());
playerData->player.PlayerInfo::setMotto(newMotto);
std::string mottoAfter = playerData->player.getMotto();
bz_debugMessagef(4, "Player Joined: MottoFilter: Replaced Motto %s with %s", mottoBefore.c_str(), mottoAfter.c_str());
bz_freePlayerRecord(record);
}
}
void mottofilter::Cleanup(void)
{
Flush();
bz_removeCustomSlashCommand("spawn");
}
// Local Variables: ***
// mode:C++ ***
// tab-width: 8 ***i
// c-basic-offset: 2 ***
// indent-tabs-mode: t ***
// End: ***
// ex: shiftwidth=2 tabstop=8