PageRenderTime 35ms CodeModel.GetById 23ms app.highlight 9ms RepoModel.GetById 0ms app.codeStats 0ms

/addons/sourcemod/scripting/SourceIRC/sourceirc-ticket.sp

https://bitbucket.org/kimoto/sushi
Unknown | 258 lines | 225 code | 33 blank | 0 comment | 0 complexity | 2a272e6dfe251029fb05778a62badeba MD5 | raw file
  1/*
  2       This file is part of SourceIRC.
  3
  4    SourceIRC is free software: you can redistribute it and/or modify
  5    it under the terms of the GNU General Public License as published by
  6    the Free Software Foundation, either version 3 of the License, or
  7    (at your option) any later version.
  8
  9    SourceIRC is distributed in the hope that it will be useful,
 10    but WITHOUT ANY WARRANTY; without even the implied warranty of
 11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12    GNU General Public License for more details.
 13
 14    You should have received a copy of the GNU General Public License
 15    along with SourceIRC.  If not, see <http://www.gnu.org/licenses/>.
 16*/
 17
 18#include <sdktools>
 19#undef REQUIRE_PLUGIN
 20#include <sourceirc>
 21
 22#pragma semicolon 1
 23
 24new Float:SprayLocation[MAXPLAYERS+1][3];
 25new String:ReportString[MAXPLAYERS+1][512];
 26
 27new Handle:kv;
 28
 29public Plugin:myinfo = {
 30	name = "SourceIRC -> Ticket",
 31	author = "Azelphur",
 32	description = "Adds a report command in game for players to report problems to staff in an IRC channel",
 33	version = IRC_VERSION,
 34	url = "http://Azelphur.com/project/sourceirc"
 35};
 36
 37public OnPluginStart() {	
 38	LoadTranslations("common.phrases");
 39	RegConsoleCmd("report", Command_Support);
 40	RegConsoleCmd("reply", Command_Reply);
 41	AddTempEntHook("Player Decal", PlayerSpray);
 42	kv = CreateKeyValues("SourceIRC");
 43	decl String:file[512];
 44	BuildPath(Path_SM, file, sizeof(file), "configs/sourceirc.cfg");
 45	FileToKeyValues(kv, file);
 46}
 47
 48public OnAllPluginsLoaded() {
 49	if (LibraryExists("sourceirc"))
 50		IRC_Loaded();
 51}
 52
 53public OnLibraryAdded(const String:name[]) {
 54	if (StrEqual(name, "sourceirc"))
 55		IRC_Loaded();
 56}
 57
 58IRC_Loaded() {
 59	IRC_CleanUp(); // Call IRC_CleanUp as this function can be called more than once.
 60	IRC_RegAdminCmd("to", Command_To, ADMFLAG_CHAT, "to <name|#userid> <text> - Send a message to a player");
 61}
 62
 63public Action:Command_Reply(client, args) {
 64	decl String:Args[256], String:name[64], String:auth[64];
 65	GetCmdArgString(Args, sizeof(Args));
 66	if (StrEqual(Args, ""))
 67		return Plugin_Handled;
 68	GetClientName(client, name, sizeof(name));
 69	GetClientAuthString(client, auth, sizeof(auth));
 70	IRC_MsgFlaggedChannels("ticket", "%s (%s) :  %s", name, auth, Args);
 71	PrintToChat(client, "To ADMIN :  %s", Args);
 72	return Plugin_Handled;
 73}
 74
 75public Action:Command_To(const String:nick[], args) {
 76	decl String:destination[64], String:text[IRC_MAXLEN];
 77	IRC_GetCmdArgString(text, sizeof(text));
 78	new startpos = BreakString(text, destination, sizeof(destination));
 79	new target = FindTarget(0, destination, true, false);
 80	if (target != -1) {
 81		PrintToChat(target, "\x01[\x04IRC\x01] \x03(ADMIN) %s\x01 :  %s", nick, text[startpos]);
 82	}
 83	else {
 84		IRC_ReplyToCommand(nick, "Unable to find %s", destination);
 85	}
 86	return Plugin_Handled;
 87}
 88
 89public Action:PlayerSpray(const String:te_name[],const clients[],client_count,Float:delay) {
 90	new client=TE_ReadNum("m_nPlayer");
 91	TE_ReadVector("m_vecOrigin", SprayLocation[client]);
 92}
 93
 94TraceSpray(client) {
 95 	new Float:pos[3];
 96	if(GetPlayerEye(client, pos) >= 1){
 97		new Float:MaxDis = 50.0;
 98	 	for(new i = 1; i<= MAXPLAYERS; i++) {
 99			if(GetVectorDistance(pos, SprayLocation[i]) <= MaxDis)
100				return i;
101		}
102	}
103	return 0;
104}
105
106stock GetPlayerEye(client, Float:pos[3]) {
107	new Float:vAngles[3], Float:vOrigin[3];
108	GetClientEyePosition(client,vOrigin);
109	GetClientEyeAngles(client, vAngles);
110	
111	new Handle:trace = TR_TraceRayFilterEx(vOrigin, vAngles, MASK_SHOT, RayType_Infinite, TraceEntityFilterPlayer);
112	
113	if(TR_DidHit(trace)) {
114		TR_GetEndPosition(pos, trace);
115		if(GetVectorDistance(pos, vOrigin) <= 128.0)
116			return 2;
117		return 1;
118	}
119	return 0;
120}
121
122public bool:TraceEntityFilterPlayer(entity, contentsMask) {
123 	new String:classname[64];
124 	GetEntityNetClass(entity, classname, 64);
125 	return !StrEqual(classname, "CTFPlayer");
126}
127
128public Action:Command_Support(client, args) {
129	new Handle:hMenu=CreateMenu(MenuHandler_Report);
130	SetMenuTitle(hMenu,"What do you want to report for?");
131	if (!KvJumpToKey(kv, "Ticket")) return;
132	if (!KvJumpToKey(kv, "Menu")) return;
133	if (!KvGotoFirstSubKey(kv, false)) return;
134	decl String:key[64], String:value[64];
135	do
136	{
137		KvGetSectionName(kv, key, sizeof(key));
138		KvGetString(kv, NULL_STRING, value, sizeof(value));
139		AddMenuItem(hMenu, key, value);
140	} while (KvGotoNextKey(kv, false));
141
142	KvRewind(kv);
143	
144	DisplayMenu(hMenu, client, MENU_TIME_FOREVER);
145}
146
147public MenuHandler_Report(Handle:hMenu, MenuAction:action, param1, param2) {
148	if(action==MenuAction_Select) {
149		GetMenuItem(hMenu, param2, ReportString[param1], sizeof(ReportString[]));
150		if (StrEqual(ReportString[param1], "{Special:Spray}"))
151			SprayMenu(param1);
152		else
153			ShowPlayerList(param1);
154	}
155}
156
157SprayMenu(client) {
158	new Handle:hMenu = CreateMenu(MenuHandler_SprayMenu);
159	SetMenuTitle(hMenu, "Aim at the spray you wish to report, then press ok.");
160	AddMenuItem(hMenu, "Ok", "Ok");
161	SetMenuExitBackButton(hMenu, true);
162	DisplayMenu(hMenu, client, MENU_TIME_FOREVER);
163}
164
165public MenuHandler_SprayMenu(Handle:menu, MenuAction:action, param1, param2)
166{
167	if (action == MenuAction_Cancel && param2 == MenuCancel_ExitBack) {
168		Command_Support(param1, 0);
169	}
170	else if (action == MenuAction_Select) {
171		new target = TraceSpray(param1);
172		if (!target) {
173			PrintToChat(param1, "No spray found where you are looking, try getting closer!");
174			SprayMenu(param1);
175		}
176		else {
177			decl String:decalfile[256];
178			GetPlayerDecalFile(target, decalfile, sizeof(decalfile));
179			decl String:sprayurl[128];
180			sprayurl[0] = '\x00';
181			Format(ReportString[param1], sizeof(ReportString[]), "Bad spray");
182			if ((KvJumpToKey(kv, "Ticket")) && (KvJumpToKey(kv, "Settings"))) {
183				KvGetString(kv, "spray_url", sprayurl, sizeof(sprayurl), "");
184				if (!StrEqual(sprayurl, "")) {
185					ReplaceString(sprayurl, sizeof(sprayurl), "{SPRAY}", decalfile);
186					StrCat(ReportString[param1], sizeof(ReportString), " ");
187					StrCat(ReportString[param1], sizeof(ReportString), sprayurl);
188				}
189			}
190			KvRewind(kv);
191			
192			Report(param1, target, ReportString[param1]);
193		}
194	}
195}
196
197ShowPlayerList(client) {
198	new Handle:hMenu = CreateMenu(MenuHandler_PlayerList);
199	decl String:title[256];
200	Format(title, sizeof(title), "Who do you want to report for %s", ReportString[client]);
201	SetMenuTitle(hMenu, title);
202	SetMenuExitBackButton(hMenu, true);
203	new maxclients = GetMaxClients();
204	decl String:disp[64], String:info[64];
205	for (new i = 1; i <= maxclients; i++) {
206		if (IsClientConnected(i) && !IsFakeClient(i)) {
207			GetClientName(i, disp, sizeof(disp));
208			IntToString(GetClientUserId(i), info, sizeof(info));
209			AddMenuItem(hMenu, info, disp);
210		}
211	}
212	DisplayMenu(hMenu, client, MENU_TIME_FOREVER);
213}
214
215public MenuHandler_PlayerList(Handle:menu, MenuAction:action, param1, param2)
216{
217	if (action == MenuAction_Cancel && param2 == MenuCancel_ExitBack) {
218		Command_Support(param1, 0);
219	}
220	else if (action == MenuAction_Select) {
221		decl String:info[32];
222		GetMenuItem(menu, param2, info, sizeof(info));
223		new client = GetClientOfUserId(StringToInt(info));
224
225		if (!client) {
226			PrintToChat(param1, "Player disconnected, sorry!");
227		}
228		else {
229			Report(param1, client, ReportString[param1]);
230		}
231	}
232}
233
234Report(client, target, String:info[]) {
235	decl String:name[64], String:auth[64], String:targetname[64], String:targetauth[64], String:mynick[64];
236	GetClientName(client, name, sizeof(name));
237	GetClientAuthString(client, auth, sizeof(auth));
238	GetClientName(target, targetname, sizeof(targetname));
239	GetClientAuthString(target, targetauth, sizeof(targetauth));
240	IRC_GetNick(mynick, sizeof(mynick));
241	if ((KvJumpToKey(kv, "Ticket")) && (KvJumpToKey(kv, "Settings"))) {
242		decl String:custom_msg[IRC_MAXLEN];
243		KvGetString(kv, "custom_msg", custom_msg, sizeof(custom_msg), "");
244		if (!StrEqual(custom_msg, "")) {
245			IRC_MsgFlaggedChannels("ticket", custom_msg);
246		}
247	}
248	KvRewind(kv);
249	IRC_MsgFlaggedChannels("ticket", "%s (%s) has reported %s (%s) for %s", name, auth, targetname, targetauth, info);
250	IRC_MsgFlaggedChannels("ticket", "use %s to #%d <text> - To reply", mynick, GetClientUserId(client));
251	PrintToChat(client, "\x01Your report has been sent. Type \x04/reply your text here\x01 to chat with the admins.");
252}
253
254public OnPluginEnd() {
255	IRC_CleanUp();
256}
257
258// http://bit.ly/defcon