View Single Post
blackcat
Junior Member
Join Date: Oct 2005
Old 05-25-2006 , 14:11  
Reply With Quote #20

Okay, so I updated the code to use /admin in console rather than !needadmin in say. Also updated so the script now uses a cfg-file (irc.cfg) rather than having to recompile every time you need to change any settings.

Code:
// Original code by devicenull (IRC <-> HLDS) // modified to do just one simple thing, contact admins on irc. // Be shure to modify the cvars for your use. The vars set her is an example for use on quakenet. // The /admin trigger in chat must contain a message, or the user will get a error message telling how to use it. // SteamID of the user using the trigger is also displayed on irc, so that we can ban abusers easily. // // Define these cvars in irc.cfg in order for the plugin to function properly // // irc_debug "0" (Set to 1 to enable debug messages) // irc_server "irc.quakenet.org" // irc_nick "nick" // irc_username "username" // irc_port "6667" // irc_channel "#channel chan-key" // irc_joindelay "10" // irc_identify" "1" (If you want to auth witch Q, or any other nickserv) // irc_idbot "[email protected]" // irc_uname "username" (username to auth/identify) // irc_passwd "username" (password to auth/identify) #include <amxmodx> #include <amxmisc> #include <engine> #include <sockets> #pragma dynamic 8000 #define ACCESS_IRC ADMIN_CFG #define MAX_USERS 32 new server[64], port, nick[32], username[32], chan[32], uname[32], passwd[32], feil // Stuff needed to connect new irc_socket //Connection new temp[1024] //Put together messages with this new curmesg //Message counter for sending new pending[256][1024] //Messages Pending to be sent new i //Loop Counter new pings //Keep track of pings public plugin_init() {     register_plugin("Needamin trigger","1.1","Stein_R")         register_dictionary("admincmd.txt")         register_dictionary("common.txt")         register_dictionary("pausecfg.txt")         new configsDir[64]         get_configsdir(configsDir, 63)         server_cmd("exec %s/irc.cfg", configsDir) // Execute main configuration file        //Various Messages     register_cvar("irc_msg_srvsay","<$name - $steamid> $message")     register_cvar("irc_clientport","0",FCVAR_PROTECTED&FCVAR_UNLOGGED)     register_concmd("irc","parseirc",0," args are connect disconnect status join or ident")         // Commands     register_concmd("/admin","irc_saytext")     set_task(1.0,"irc_datacheck",_,_,_,"b")     set_task(2.0,"sendnext",_,_,_,"b")     if (get_cvar_num("irc_clientport") == 0)     {         set_task(get_cvar_float("irc_joindelay"),"irc_connect")     }     else     {         irc_socket = get_cvar_num("irc_clientport")     } } public parseirc(id) {     if (!(get_user_flags(id)&ACCESS_IRC))     {         console_print(id,"[IRC] Access Denied")         return PLUGIN_HANDLED     }     new arg1[32]     read_argv(1,arg1,32)     if (equali(arg1,"connect") || equali(arg1,"reconnect"))     {         irc_connect()         console_print(id,"[IRC] Attempting to connect")         return PLUGIN_HANDLED     }     else if (equali(arg1,"disconnect"))     {         end()         console_print(id,"[IRC] Disconnecting")         return PLUGIN_HANDLED     }     else if (equali(arg1,"join"))     {         irc_joinchannel()         console_print(id,"[IRC] Attempting to join %s",chan)     }     else if (equali(arg1,"status"))     {         console_print(id,"[IRC] Status:")         console_print(id,"[IRC] Cvar reports port %i, irc_socket reports %i",get_cvar_num("irc_clientport"),irc_socket)         console_print(id,"[IRC] Internal vars: Nick: %s/Username: %s/Chan: %s/Server: %s/Port: %i",nick,username,chan,server,port)         console_print(id,"[IRC] Ping counter at %i, message counter at %i",pings,curmesg)     }     else if (equali(arg1,"ident") || equali(arg1,"identify"))     {         irc_identify()         console_print(id,"[IRC] Identifying")     }     else     {         console_print(id,"[IRC] Command not found")     }     return PLUGIN_HANDLED } public irc_connect() {     get_cvar_string("irc_server",server,64)     get_cvar_string("irc_nick",nick,32)     get_cvar_string("irc_channel",chan,32)     get_cvar_string("irc_username",username,32)     port = get_cvar_num("irc_port")     irc_socket = socket_open(server,port,SOCKET_TCP,feil)     set_cvar_num("irc_clientport",irc_socket)     switch (feil)     {         case 1:         {             log_amx("[IRC] Error creating socket to %s:%i",server,port)             return -1         }         case 2:         {             log_amx("[IRC] Error resolving hostname %s",server)             return -2         }         case 3:         {             log_amx("[IRC] Couldn't connect to %s:%i",server,port)             return -3         }     }     format(temp,1024,"NICK %s^r^nUSER %s 0 * :csP Bot^r^n",nick,username)     additem(temp)     return irc_socket } public irc_datacheck() {     if (socket_change(irc_socket,1))     {         new rdata[1024] //, data[1024]         socket_recv(irc_socket,rdata,1024)         copyc(rdata,1024,rdata,10)         irc_dataparse(rdata)         copy(temp,1024,rdata[strlen(rdata)+1])         if (containi(temp,"^r"))         {             irc_dataparse(rdata[strlen(rdata)+1])         }     } } public irc_dataparse(rdata[]) {     if(strlen(rdata) > 0)     { //If there is data         new arg1[128],arg1len,arg2[128] ,arg2len, arg3[128]         copyc(arg1,128,rdata,32)         arg1len = strlen(arg1)         copyc(arg2,128,rdata[arg1len+1],32)         arg2len = strlen(arg2)         copyc(arg3,128,rdata[arg1len+arg2len+2],32)         switch (str_to_num(arg2))         { //Numeric Events             case 001:             {                 server_print("[IRC] Connected sucessfully");                 irc_joinchannel()                 set_cvar_num("irc_clientport",irc_socket)                 irc_identify()                          return 0             } //Occurs after successful connection                  case 403: { server_print("[IRC] Warning: We are not in the channel, but we tried to send a message to it and the channel is empty, channel %s",chan); return 0; }             case 405: { server_print("[IRC] Error: Can't join any more channels, the server won't allow it"); return 0; }             case 432: { server_print("[IRC] Error: Invalid characters in nickname"); return 0; }             case 433: { server_print("[IRC] Error: Nickname in use"); return 0; }             case 437: { server_print("[IRC] Error: Can't change nick, we are in a channel we are banned from"); return 0; }             case 471: { server_print("[IRC] Error: Limit on channel reached, remove +l and try again"); return 0; }             case 473: { server_print("[IRC] Error: Channel is +i, invite us in and try again"); return 0; }             case 474: { server_print("[IRC] Error: We are banned from that channel"); return 0; }             case 475: { server_print("[IRC] Error: Channel is +k and we don't have the key!"); return 0; }             case 482: { server_print("[IRC] Error: Can't set modes when we aren't op"); return 0; }             case 513: { server_print("[IRC] Error: Registration failed, try again later"); end(); return 0; }         }         if (get_cvar_num("irc_debug") == 1)             server_print("[IRC]-> %s",rdata)         if (equali(arg1,"PING"))         {             format(temp,1024,"PONG %s^r^n",arg2)             additem(temp)             pings++             return 0         }         else if (equali(arg1,"ERROR"))         {             end()             server_print("[IRC] Disconnected, trying to reconnect")             set_task(Float:60,"irc_connect")         }     }     return 0 } public additem(item[]) {     if(curmesg <= 255)     {         copy(pending[curmesg],1024,item)         curmesg++     }     else     {         new quicksend[201]         format(quicksend,200,"PRIVMSG %s :IRC message overflow, clearing stack.^r^n",chan)         socket_send(irc_socket,quicksend,0)         for(new inum=0;inum<256;inum++)         {             copy(pending[inum],1024,"")         }         curmesg = 0     }     return 0    } public sendnext() {     if (curmesg >= 1)     {         remove_quotes(pending[0])         socket_send(irc_socket,pending[0],0)         if (get_cvar_num("irc_debug") == 1)             server_print("[IRC]<- %s",pending[0])         for (i=0;i<=curmesg;i++)         {             copy(pending[i],1024,pending[i+1])         }         curmesg--     } } public end() {     format(temp,1024,"QUIT :Shutting down")     socket_send(irc_socket,temp,0)     set_cvar_num("irc_clientport",0) } public irc_joinchannel() {     get_cvar_string("irc_channel",chan,32)     format(temp,1024,"JOIN %s^r^n",chan)     additem(temp)     return 0 } public irc_identify() {     if (get_cvar_num("irc_identify") != 0)     {           new ident[256]         get_cvar_string("irc_uname",uname,256)         get_cvar_string("irc_passwd",passwd,256)         get_cvar_string("irc_idbot",idbot,256)         format(ident,256,"PRIVMSG %s :auth %s %s^r^n",idbot,uname,passwd)         additem(ident)     }     return 0 } public parsemessage(id,input[],output[],amsg[]) {     // Replaces $name $team $message with the right things     new name[32], authid[32]     new mtemp[1024]     get_user_name(id,name,32)     get_user_authid(id,authid,32)     copy(mtemp,512,input)     remove_quotes(amsg)     replace(mtemp,512,"$name",name)     replace(mtemp,512,"$message",amsg)     replace(mtemp,512,"$steamid",authid)     remove_quotes(mtemp)     remove_quotes(mtemp)     copy(output,1024,mtemp) } public irc_saytext(id) {     if (irc_socket > 0)     {         new msg[1024]         read_args(msg,1024)         new tmsg[1024]         if(strlen(msg) >= 2)             {             get_cvar_string("irc_msg_srvsay",tmsg,1024)             parsemessage(id,tmsg,temp,msg)             format(temp,1024,"PRIVMSG %s :%s^r^n",chan,temp)             additem(temp)             console_print(id,"[NeedAdmin] Message sent to admins on irc. Repeating/Abuse will lead to ban!",0,"")             return PLUGIN_HANDLED             }             else             {             console_print(id,"[NeedAdmin] No message specified. Please use /admin followed by a cheattype and nick of the cheater",0,"")                         return PLUGIN_HANDLED             }     }     return 0 }
Attached Files
File Type: sma Get Plugin or Get Source (irc.sma - 973 views - 8.9 KB)
blackcat is offline