]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Fixes
[user/henk/code/inspircd.git] / src / inspircd.cpp
index 0717ee2673cee1456ae22182a670614f9bc32218..79f2d58c450e7b915c5692174b13e4af81cefe88 100644 (file)
@@ -4903,23 +4903,45 @@ int usercount_unknown(void)
        return c;
 }
 
-int chancount(void)
+long chancount(void)
 {
        return chanlist.size();
 }
 
-int servercount(void)
+long count_servs(void)
 {
-       return 1;
+       int c = 0;
+       for (int j = 0; j < 255; j++)
+       {
+               if (servers[j] != NULL)
+                       c++;
+       }
+       return c;
+}
+
+long servercount(void)
+{
+       return count_servs()+1;
+}
+
+long local_count()
+{
+       int c = 0;
+       for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
+       {
+               if ((i->second->fd) && (isnick(i->second->nick)) && (!strcasecmp(i->second->server,ServerName))) c++;
+       }
+       return c;
 }
 
+
 void handle_lusers(char **parameters, int pcnt, userrec *user)
 {
        WriteServ(user->fd,"251 %s :There are %d users and %d invisible on %d servers",user->nick,usercnt()-usercount_invisible(),usercount_invisible(),servercount());
        WriteServ(user->fd,"252 %s %d :operator(s) online",user->nick,usercount_opers());
        WriteServ(user->fd,"253 %s %d :unknown connections",user->nick,usercount_unknown());
        WriteServ(user->fd,"254 %s %d :channels formed",user->nick,chancount());
-       WriteServ(user->fd,"254 %s :I have %d clients and 0 servers",user->nick,usercnt());
+       WriteServ(user->fd,"254 %s :I have %d clients and %d servers",user->nick,local_count(),count_servs());
 }
 
 void handle_admin(char **parameters, int pcnt, userrec *user)
@@ -5340,6 +5362,7 @@ void handle_connect(char **parameters, int pcnt, userrec *user)
                for (int j = 0; j < 255; j++) {
                        if (servers[j] == NULL) {
                                servers[j] = new serverrec;
+                               //servers[j]->initiator = true;
                                strcpy(servers[j]->internal_addr,Link_IPAddr);
                                servers[j]->internal_port = LinkPort;
                                strcpy(servers[j]->name,Link_ServerName);
@@ -5381,6 +5404,16 @@ char islast(serverrec* s)
        return c;
 }
 
+long map_count(serverrec* s)
+{
+       int c = 0;
+       for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
+       {
+               if ((i->second->fd) && (isnick(i->second->nick)) && (!strcasecmp(i->second->server,s->name))) c++;
+       }
+       return c;
+}
+
 void handle_links(char **parameters, int pcnt, userrec *user)
 {
        WriteServ(user->fd,"364 %s %s %s :0 %s",user->nick,ServerName,ServerName,ServerDesc);
@@ -5396,12 +5429,19 @@ void handle_links(char **parameters, int pcnt, userrec *user)
 
 void handle_map(char **parameters, int pcnt, userrec *user)
 {
-       WriteServ(user->fd,"006 %s :%s",user->nick,ServerName);
+       char line[MAXBUF];
+       snprintf(line,MAXBUF,"006 %s :%s",user->nick,ServerName);
+       while (strlen(line) < 50)
+               strcat(line," ");
+       WriteServ(user->fd,"%s%d (%.2f%%)",line,local_count(),(float)(((float)local_count()/(float)usercnt())*100));
        for (int j = 0; j < 255; j++)
        {
                if (servers[j] != NULL)
                {
-                       WriteServ(user->fd,"006 %s :%c-%s",user->nick,islast(servers[j]),servers[j]->name);
+                       snprintf(line,MAXBUF,"006 %s :%c-%s",user->nick,islast(servers[j]),servers[j]->name);
+                       while (strlen(line) < 50)
+                               strcat(line," ");
+                       WriteServ(user->fd,"%s%d (%.2f%%)",line,map_count(servers[j]),(float)(((float)map_count(servers[j])/(float)usercnt())*100));
                }
        }
        WriteServ(user->fd,"007 %s :End of /MAP",user->nick);
@@ -6059,7 +6099,7 @@ 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* from = strtok(NULL," ");
        char* channel = strtok(NULL," ");
        userrec* u = Find(nick);
        userrec* user = Find(from);
@@ -6377,6 +6417,19 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve
                        nb_start = time(NULL);
                        WriteOpers("Server %s is starting netburst.",source->name);
                break;
+               // ?
+               // ping
+               case '?':
+                       reply->SendPacket("!",udp_host,udp_port,MyKey);
+               break;
+               // ?
+               // pong
+               case '!':
+               break;
+               // *
+               // no operation
+               case '*':
+               break;
                // N <TS> <NICK> <HOST> <DHOST> <IDENT> <MODES> <SERVER> :<GECOS>
                // introduce remote client
                case 'N':
@@ -6509,6 +6562,7 @@ void handle_link_packet(long theirkey, char* udp_msg, char* udp_host, int udp_po
                                                                strcpy(servers[j]->description,serverdesc);
                                                                servers[j]->internal_port = udp_port;
                                                                // create a server record for this server
+                                                               WriteOpers("Server %s authenticated, exchanging server keys...",servername);
                                                                snprintf(response,10240,"O %d",MyKey);
                                                                serv->SendPacket(response,udp_host,udp_port,0);
                                                                return;
@@ -6543,7 +6597,7 @@ void handle_link_packet(long theirkey, char* udp_msg, char* udp_host, int udp_po
                                if (!strcasecmp(servers[i]->internal_addr,udp_host)) {
                                        servers[i]->key = atoi(params);
                                        log(DEBUG,"Key for this server is now %d",servers[i]->key);
-                                       DoSync(serv,udp_host,udp_port,MyKey);
+                                       servers[i]->sync_soon = true;
                                        return;
                                }
                        }
@@ -6841,7 +6895,7 @@ int InspIRCd(void)
        {
 
                fd_set sfd;
-               struct timeval tval;
+               timeval tval;
                FD_ZERO(&sfd);
 
                user_hash::iterator count2 = clientlist.begin();
@@ -6861,6 +6915,17 @@ int InspIRCd(void)
                        }
                        fd_reap.clear();
                        reap_counter=0;
+                       for (int j = 0; j < 255; j++)
+                       {
+                               if (servers[j])
+                               {
+                                       if (servers[j]->sync_soon)
+                                       {
+                                               servers[j]->sync_soon = false;
+                                               DoSync(servers[j],servers[j]->internal_addr,servers[j]->internal_port,MyKey);
+                                       }
+                               }
+                       }
                }