Skip to content

Commit

Permalink
Fixed Memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Azelphur committed Sep 13, 2012
1 parent 426697f commit 4ec47b4
Show file tree
Hide file tree
Showing 12 changed files with 2,529 additions and 0 deletions.
64 changes: 64 additions & 0 deletions configs/sourceirc.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"SourceIRC"
{
"Access"
{
"Hostmasks"
{
// Put hostmasks followed by SourceMod admin permissions here, Just like you would in IRC, * and ? wildcards are supported.
"[email protected]" "z"
}
}
"Server"
{
"server" "irc.gamesurge.net" // Server to connect to
"port" "6667"
"nickname" "SourceIRC"
"realname" "SourceIRC"
"channels"
{
"#sourceirc"
{
"relay" "1" // Tell the RelayAll module to relay messages to this channel
"cmd_prefix" "!" // Ontop of calling the bot by name, you can also use "!" in this channel
}
"#sourceirc-admin"
{
"ticket" "1" // Tell the ticket module to send tickets to this channel
}
}
}
"Settings"
{
"msg-rate" "1.0" // Seconds to wait between sending messages, set to 0 to disable. Setting this too low can cause the bot to be kicked from the server for "Excess flood".
// Team colors, use -1 to set no color.
"teamcolor-0" "15" // Unassigned
"teamcolor-1" "15" // Spectators
"teamcolor-2" "04" // Red / Terrorist
"teamcolor-3" "12" // Blue / Counter Terrorist
"server-domain" "" // Servers domain/external IP. Leave blank for autodetect. Good if your server is running behind a router and has a local IP or you use a domain. This is only used for cosmetic purposes.
}
"Ticket"
{
"Menu"
{
"Abusive" "Abusive"
"Racism" "Racism"
"General cheating/exploits" "General cheating/exploits"
"Wallhack" "Wallhack"
"Aimbot" "Aimbot"
"Speedhacking" "Speedhacking"
"Mic spamming" "Mic spamming"
"Admin disrepect" "Admin disrepect"
"Camping" "Camping"
"Team killing" "Team killing"
"Unacceptable Spray" "Unacceptable Spray"
"Breaking Server Rules" "Breaking Server Rules"
"Other" "Other"
}
"Settings"
{
"spray_url" "" // If you have a URL where sprays can be downloaded, put it here and the bot will link to it in bad spray reports. Use {SPRAY} to insert the ID of the spray that's being reported. Leave blank to disable.
"custom_msg" "" // Send this message when a ticket is submitted, good for mass highlighting everyone when a ticket is received.
}
}
}
133 changes: 133 additions & 0 deletions scripting/SourceIRC/sourceirc-ban.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
This file is part of SourceIRC.
SourceIRC 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.
SourceIRC 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 SourceIRC. If not, see <http://www.gnu.org/licenses/>.
*/

#undef REQUIRE_PLUGIN
#include <sourceirc>

#pragma semicolon 1
#pragma dynamic 65535


public Plugin:myinfo = {
name = "SourceIRC -> Ban",
author = "Azelphur",
description = "Adds ban command to SourceIRC",
version = IRC_VERSION,
url = "http://Azelphur.com/project/sourceirc"
};

public OnPluginStart() {
LoadTranslations("common.phrases");
LoadTranslations("plugin.basecommands");
}

public OnAllPluginsLoaded() {
if (LibraryExists("sourceirc"))
IRC_Loaded();
}

public OnLibraryAdded(const String:name[]) {
if (StrEqual(name, "sourceirc"))
IRC_Loaded();
}

IRC_Loaded() {
IRC_CleanUp(); // Call IRC_CleanUp as this function can be called more than once.
IRC_RegAdminCmd("ban", Command_Ban, ADMFLAG_BAN, "ban <#userid|name> <minutes|0> [reason] - Bans a player from the server");
}

public Action:Command_Ban(const String:nick[], args) {
// Blatently borrowed code from basebans/bans
if (args < 2)
{
IRC_ReplyToCommand(nick, "Usage: ban <#userid|name> <minutes|0> [reason]");
return Plugin_Handled;
}

decl len, next_len;
decl String:Arguments[256];
IRC_GetCmdArgString(Arguments, sizeof(Arguments));

decl String:arg[65];
len = BreakString(Arguments, arg, sizeof(arg));

new target = IRC_FindTarget(nick, arg, true);
if (target == -1)
{
return Plugin_Handled;
}

decl String:s_time[12];
if ((next_len = BreakString(Arguments[len], s_time, sizeof(s_time))) != -1)
{
len += next_len;
}
else
{
len = 0;
Arguments[0] = '\0';
}

new time = StringToInt(s_time);

PrepareBan(nick, target, time, Arguments[len]);

return Plugin_Handled;
}

PrepareBan(const String:nick[], target, time, const String:reason[])
{
decl String:authid[64], String:name[32];
GetClientAuthString(target, authid, sizeof(authid));
GetClientName(target, name, sizeof(name));

if (!time)
{
if (reason[0] == '\0')
{
IRC_ReplyToCommand(nick, "%t", "Permabanned player", name);
} else {
IRC_ReplyToCommand(nick, "%t", "Permabanned player reason", name, reason);
}
} else {
if (reason[0] == '\0')
{
IRC_ReplyToCommand(nick, "%t", "Banned player", name, time);
} else {
IRC_ReplyToCommand(nick, "%t", "Banned player reason", name, time, reason);
}
}

decl String:hostmask[IRC_MAXLEN];
IRC_GetHostMask(hostmask, sizeof(hostmask));
LogAction(-1, target, "\"%s\" banned \"%L\" (minutes \"%d\") (reason \"%s\")", hostmask, target, time, reason);

if (reason[0] == '\0')
{
BanClient(target, time, BANFLAG_AUTO, "Banned", "Banned", "sourceirc_ban", 0);
}
else
{
BanClient(target, time, BANFLAG_AUTO, reason, reason, "sourceirc_ban", 0);
}
}

public OnPluginEnd() {
IRC_CleanUp();
}

// http://bit.ly/defcon
92 changes: 92 additions & 0 deletions scripting/SourceIRC/sourceirc-changemap.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
This file is part of SourceIRC.
SourceIRC 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.
SourceIRC 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 SourceIRC. If not, see <http://www.gnu.org/licenses/>.
*/

#undef REQUIRE_PLUGIN
#include <sourceirc>

#pragma semicolon 1
#pragma dynamic 65535

public Plugin:myinfo = {
name = "SourceIRC -> Change Map",
author = "Azelphur",
description = "Adds a changemap command to SourceIRC",
version = IRC_VERSION,
url = "http://Azelphur.com/project/sourceirc"
};

public OnPluginStart() {
LoadTranslations("sourceirc.phrases");
}

public OnAllPluginsLoaded() {
if (LibraryExists("sourceirc"))
IRC_Loaded();
}

public OnLibraryAdded(const String:name[]) {
if (StrEqual(name, "sourceirc"))
IRC_Loaded();
}

IRC_Loaded() {
IRC_CleanUp(); // Call IRC_CleanUp as this function can be called more than once.
IRC_RegAdminCmd("changemap", Command_ChangeMap, ADMFLAG_CHANGEMAP, "changemap <map> - Changes the current map, you can use a partial map name.");
}

public Action:Command_ChangeMap(const String:nick[], args) {
decl String:text[IRC_MAXLEN];
IRC_GetCmdArgString(text, sizeof(text));
if (IsMapValid(text)) {
IRC_ReplyToCommand(nick, "%t", "Changing Map", text);
ForceChangeLevel(text, "Requested from IRC");
}
else {
decl String:storedmap[64], String:map[64];
new Handle:maps = CreateArray(64);
ReadMapList(maps);
new bool:foundmatch = false;
for (new i = 0; i < GetArraySize(maps); i++) {
GetArrayString(maps, i, storedmap, sizeof(storedmap));
if (StrContains(storedmap, text, false) != -1) {
if (!foundmatch) {
strcopy(map, sizeof(map), storedmap);
foundmatch = true;
}
else {
IRC_ReplyToCommand(nick, "%t", "Multiple Maps", text);
return Plugin_Handled;
}
}
}
if (foundmatch) {
IRC_ReplyToCommand(nick, "%t", "Changing Map", map);
ForceChangeLevel(map, "Requested from IRC");
return Plugin_Handled;
}
else {
IRC_ReplyToCommand(nick, "%t", "Invalid Map", text);
}
}
return Plugin_Handled;
}

public OnPluginEnd() {
IRC_CleanUp();
}

// http://bit.ly/defcon
60 changes: 60 additions & 0 deletions scripting/SourceIRC/sourceirc-hostmasks.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
This file is part of SourceIRC.
SourceIRC 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.
SourceIRC 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 SourceIRC. If not, see <http://www.gnu.org/licenses/>.
*/

#undef REQUIRE_PLUGIN
#include <sourceirc>

public Plugin:myinfo = {
name = "SourceIRC -> Hostmasks",
author = "Azelphur",
description = "Provides access based on hostmask",
version = IRC_VERSION,
url = "http://Azelphur.com/project/sourceirc"
};

new Handle:kv;

public OnConfigsExecuted() {
kv = CreateKeyValues("SourceIRC");
decl String:file[512];
BuildPath(Path_SM, file, sizeof(file), "configs/sourceirc.cfg");
FileToKeyValues(kv, file);
}

public IRC_RetrieveUserFlagBits(const String:hostmask[], &flagbits) {
if (!KvJumpToKey(kv, "Access")) return;
if (!KvJumpToKey(kv, "Hostmasks")) return;
if (!KvGotoFirstSubKey(kv, false)) return;
decl String:key[64], String:value[64];
new AdminFlag:tempflag;
do
{
KvGetSectionName(kv, key, sizeof(key));
if (IsWildCardMatch(hostmask, key)) {
KvGetString(kv, NULL_STRING, value, sizeof(value));
for (new i = 0; i <= strlen(value); i++) {
if (FindFlagByChar(value[i], tempflag)) {
flagbits |= 1<<_:tempflag;
}
}
}
} while (KvGotoNextKey(kv, false));

KvRewind(kv);
}

// http://bit.ly/defcon
Loading

0 comments on commit 4ec47b4

Please sign in to comment.