diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2004-04-11 13:08:31 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2004-04-11 13:08:31 +0000 |
commit | c12034634020cac5c17b6845613c2c168d174d3d (patch) | |
tree | 7c2cb55433c3cde9ca6daabb12d6a43f779cd38b | |
parent | ec8a311cccb90f1397dca47c200300678a4e36aa (diff) |
Added 'i' and 't' type link datagrams
Fixed /mode #channel +b glitch
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@521 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/ctables.h | 10 | ||||
-rw-r--r-- | include/inspircd.h | 2 | ||||
-rw-r--r-- | include/modules.h | 13 | ||||
-rw-r--r-- | src/InspIRCd.layout | 42 | ||||
-rw-r--r-- | src/inspircd.cpp | 127 | ||||
-rw-r--r-- | src/modules.cpp | 5 |
6 files changed, 161 insertions, 38 deletions
diff --git a/include/ctables.h b/include/ctables.h index 5ca5e13b3..ab39bf5f3 100644 --- a/include/ctables.h +++ b/include/ctables.h @@ -27,17 +27,17 @@ typedef void (handlerfunc) (char**, int, userrec*); class command_t : public classbase { public: - /** Command name - */ + /** Command name + */ char command[MAXBUF]; /** Handler function as in typedef - */ + */ handlerfunc *handler_function; /** User flags needed to execute the command or 0 */ char flags_needed; - /** Minimum number of parameters command takes - */ + /** Minimum number of parameters command takes + */ int min_params; /** used by /stats m */ diff --git a/include/inspircd.h b/include/inspircd.h index 8409c391d..6da27ce3f 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -112,4 +112,6 @@ chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool void force_nickchange(userrec* user,const char* newnick); void kill_link(userrec *user,const char* r); int usercount(chanrec *c); +void call_handler(const char* commandname,char **parameters, int pcnt, userrec *user); +void send_network_quit(const char* nick, const char* reason); diff --git a/include/modules.h b/include/modules.h index 691e6eda1..91688b622 100644 --- a/include/modules.h +++ b/include/modules.h @@ -458,6 +458,19 @@ class Server : public classbase * Returns true if the literal successfully matches the pattern, false if otherwise. */ virtual bool MatchText(std::string sliteral, std::string spattern); + + /** Calls the handler for a command, either implemented by the core or by another module. + * You can use this function to trigger other commands in the ircd, such as PRIVMSG, JOIN, + * KICK etc, or even as a method of callback. By defining command names that are untypeable + * for users on irc (e.g. those which contain a \r or \n) you may use them as callback identifiers. + * The first parameter to this method is the name of the command handler you wish to call, e.g. + * PRIVMSG. This will be a command handler previously registered by the core or wih AddCommand(). + * The second parameter is an array of parameters, and the third parameter is a count of parameters + * in the array. If you do not pass enough parameters to meet the minimum needed by the handler, the + * functiom will silently ignore it. The final parameter is the user executing the command handler, + * used for privilage checks, etc. + */ + virtual void CallCommandHandler(std::string commandname, char** parameters, int pcnt, userrec* user); }; /** Allows reading of values from configuration files diff --git a/src/InspIRCd.layout b/src/InspIRCd.layout index 001dbf33f..20f417d4d 100644 --- a/src/InspIRCd.layout +++ b/src/InspIRCd.layout @@ -1,5 +1,5 @@ [Editors] -Focused=1 +Focused=-1 Order=1,2,-1,4,6,3,7,25,5 [Editor_0] @@ -12,10 +12,10 @@ LeftChar=1 [Editor_1] Open=1 -Top=1 -CursorCol=53 -CursorRow=1768 -TopLine=1725 +Top=0 +CursorCol=25 +CursorRow=5168 +TopLine=5141 LeftChar=1 [Editor_2] @@ -37,9 +37,9 @@ LeftChar=1 [Editor_4] Open=1 Top=0 -CursorCol=60 -CursorRow=164 -TopLine=133 +CursorCol=57 +CursorRow=180 +TopLine=145 LeftChar=1 [Editor_5] @@ -83,11 +83,11 @@ TopLine=1 LeftChar=1 [Editor_10] -Open=0 +Open=1 Top=0 CursorCol=31 CursorRow=75 -TopLine=37 +TopLine=94 LeftChar=1 [Editor_11] @@ -115,10 +115,10 @@ TopLine=18 LeftChar=1 [Editor_14] -Open=0 -Top=0 +Open=1 +Top=1 CursorCol=1 -CursorRow=23 +CursorRow=45 TopLine=1 LeftChar=1 @@ -141,9 +141,9 @@ LeftChar=1 [Editor_17] Open=1 Top=0 -CursorCol=86 -CursorRow=111 -TopLine=60 +CursorCol=25 +CursorRow=115 +TopLine=62 LeftChar=1 [Editor_18] @@ -165,9 +165,9 @@ LeftChar=1 [Editor_20] Open=1 Top=0 -CursorCol=20 -CursorRow=517 -TopLine=472 +CursorCol=36 +CursorRow=471 +TopLine=425 LeftChar=1 [Editor_21] @@ -246,8 +246,8 @@ LeftChar=4 [Editor_31] Open=1 Top=0 -CursorCol=22 -CursorRow=32 +CursorCol=2 +CursorRow=40 TopLine=8 LeftChar=1 [Editor_32] diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 7ef71ff3a..a6cd98139 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -2988,6 +2988,7 @@ void handle_mode(char **parameters, int pcnt, userrec *user) WriteServ(user->fd,"367 %s %s %s %s %d",user->nick, Ptr->name, i->data, i->set_by, i->set_time); } WriteServ(user->fd,"368 %s %s :End of channel ban list",user->nick, Ptr->name); + return; } } @@ -4024,6 +4025,21 @@ void handle_invite(char **parameters, int pcnt, userrec *user) u->InviteTo(c->name); WriteFrom(u->fd,user,"INVITE %s :%s",u->nick,c->name); WriteServ(user->fd,"341 %s %s %s",user->nick,u->nick,c->name); + + // i token must go to ALL servers!!! + char buffer[MAXBUF]; + snprintf(buffer,MAXBUF,"i %s %s %s",u->nick,user->nick,c->name); + for (int j = 0; j < 255; j++) + { + if (servers[j] != NULL) + { + if (strcmp(servers[j]->name,ServerName)) + { + me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey); + log(DEBUG,"Sent i token"); + } + } + } } void handle_topic(char **parameters, int pcnt, userrec *user) @@ -4078,6 +4094,21 @@ void handle_topic(char **parameters, int pcnt, userrec *user) strcpy(Ptr->setby,user->nick); Ptr->topicset = time(NULL); WriteChannel(Ptr,user,"TOPIC %s :%s",Ptr->name, Ptr->topic); + + // t token must go to ALL servers!!! + char buffer[MAXBUF]; + snprintf(buffer,MAXBUF,"t %s %s :%s",user->nick,Ptr->name,topic); + for (int j = 0; j < 255; j++) + { + if (servers[j] != NULL) + { + if (strcmp(servers[j]->name,ServerName)) + { + me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey); + log(DEBUG,"Sent t token"); + } + } + } } else { @@ -4644,6 +4675,20 @@ void handle_whois(char **parameters, int pcnt, userrec *user) } } +void send_network_quit(const char* nick, const char* reason) +{ + char buffer[MAXBUF]; + snprintf(buffer,MAXBUF,"Q %s :%s",nick,reason); + for (int j = 0; j < 255; j++) + { + if (servers[j] != NULL) + { + me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey); + log(DEBUG,"Sent Q token"); + } + } +} + void handle_quit(char **parameters, int pcnt, userrec *user) { user_hash::iterator iter = clientlist.find(user->nick); @@ -4675,12 +4720,9 @@ void handle_quit(char **parameters, int pcnt, userrec *user) { if (servers[j] != NULL) { - if (CommonOnThisServer(user,servers[j]->name)) - { - me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey); - log(DEBUG,"Sent Q token"); - } - } + me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey); + log(DEBUG,"Sent Q token"); + } } } else @@ -4695,12 +4737,9 @@ void handle_quit(char **parameters, int pcnt, userrec *user) { if (servers[j] != NULL) { - if (CommonOnThisServer(user,servers[j]->name)) - { - me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey); - log(DEBUG,"Sent Q token"); - } - } + me[defaultRoute]->SendPacket(buffer,servers[j]->internal_addr,servers[j]->internal_port,MyKey); + log(DEBUG,"Sent Q token"); + } } } FOREACH_MOD OnUserQuit(user); @@ -5146,6 +5185,28 @@ void handle_modules(char **parameters, int pcnt, userrec *user) } } +// calls a handler function for a command + +void call_handler(const char* commandname,char **parameters, int pcnt, userrec *user) +{ + for (int i = 0; i < cmdlist.size(); i++) + { + if (!strcasecmp(cmdlist[i].command,commandname)) + { + if (cmdlist[i].handler_function) + { + if (pcnt>=cmdlist[i].min_params) + { + if (strchr(user->modes,cmdlist[i].flags_needed)) + { + cmdlist[i].handler_function(parameters,pcnt,user); + } + } + } + } + } +} + void handle_stats(char **parameters, int pcnt, userrec *user) { if (pcnt != 1) @@ -6001,6 +6062,37 @@ void handle_P(char token,char* params,serverrec* source,serverrec* reply, char* } +void handle_i(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port) +{ + char* nick = strtok(params," "); + char* from = strtok(params," "); + char* channel = strtok(NULL," "); + userrec* u = Find(nick); + userrec* user = Find(from); + chanrec* c = FindChan(channel); + if ((c) && (u) && (user)) + { + u->InviteTo(c->name); + WriteFrom(u->fd,user,"INVITE %s :%s",u->nick,c->name); + } +} + +void handle_t(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port) +{ + char* setby = strtok(params," "); + char* channel = strtok(NULL," :"); + char* topic = strtok(NULL,"\r\n"); + topic++; + userrec* u = Find(setby); + chanrec* c = FindChan(channel); + if ((c) && (u)) + { + WriteChannelLocal(c,u,"TOPIC %s :%s",c->name,topic); + strncpy(c->topic,topic,MAXTOPIC); + strncpy(c->setby,u->nick,NICKMAX); + } +} + void handle_T(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,int udp_port) { @@ -6296,7 +6388,18 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve case 'N': handle_N(token,params,source,reply,udp_host,udp_port); break; + // t <NICK> <CHANNEL> :<TOPIC> + // change a channel topic + case 't': + handle_t(token,params,source,reply,udp_host,udp_port); + break; + // i <NICK> <CHANNEL> + // invite a user to a channel + case 'i': + handle_i(token,params,source,reply,udp_host,udp_port); + break; // k <SOURCE> <DEST> <CHANNEL> :<REASON> + // kick a user from a channel case 'k': handle_k(token,params,source,reply,udp_host,udp_port); break; diff --git a/src/modules.cpp b/src/modules.cpp index d2c3f21f9..548f6fdcb 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -171,9 +171,14 @@ void Server::ChangeUserNick(userrec* user, std::string nickname) void Server::QuitUser(userrec* user, std::string reason) { + send_network_quit(user->nick,reason.c_str()); kill_link(user,reason.c_str()); } +void Server::CallCommandHandler(std::string commandname, char** parameters, int pcnt, userrec* user) +{ + call_handler(commandname.c_str(),parameters,pcnt,user); +} void Server::Log(int level, std::string s) { |