126 lines
2.4 KiB
C
126 lines
2.4 KiB
C
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <malloc.h>
|
|
|
|
|
|
struct aServer {
|
|
struct aServer *next;
|
|
struct aServer *down;
|
|
char *name;
|
|
|
|
};
|
|
|
|
struct aServData {
|
|
int count;
|
|
int list;
|
|
};
|
|
|
|
struct aServer *MYuplink=NULL;
|
|
struct aServData ServerData;
|
|
|
|
|
|
int LinkServer(char *server, char *uplink)
|
|
{
|
|
struct aServer *ServerID;
|
|
|
|
ServerID=newserver();
|
|
ServerID->name=strdup(server);
|
|
|
|
if(MYuplink==NULL)
|
|
{ MYuplink=ServerID;
|
|
ServerData.list=1;
|
|
return 1;
|
|
}
|
|
return (AddServer(ServerID,uplink,&MYuplink));
|
|
}
|
|
|
|
struct aServer *newserver()
|
|
{ struct aServer *newserver;
|
|
|
|
newserver= (struct aServer *) calloc(1,sizeof(struct aServer));
|
|
ServerData.count++;
|
|
|
|
return newserver;
|
|
}
|
|
|
|
|
|
int AddServer(struct aServer *newserver,char *uplink,struct aServer **Startid)
|
|
{
|
|
struct aServer **UplinkID;
|
|
struct aServer *ServerID;
|
|
|
|
Uplinkid=FindServer(uplink,Startid);
|
|
if(Uplinkid == NULL) return 0; /* ERROR HERE */
|
|
ServerID= *Uplinkid;
|
|
|
|
/* This is a DOWNLINK of the said server..
|
|
** Downlinks go DOWN ->next -> next -> next ...
|
|
*/
|
|
if( ServerID->down == NULL)
|
|
{ ServerID->down = newserver;
|
|
ServerData.list++;
|
|
return 1;
|
|
}
|
|
ServerID=Serverid->down;
|
|
while(ServerID->next !=NULL) ServerID=ServerID->next;
|
|
ServerID->next=newserver;
|
|
ServerData.list++;
|
|
return 1;
|
|
}
|
|
|
|
struct aServer **FindServer(char *name,struct aServer **Startid)
|
|
{
|
|
struct aServer *SearchID;
|
|
struct aServer **ServerID;
|
|
|
|
if(!StartID ) return NULL;
|
|
|
|
SearchID= *Startid;
|
|
|
|
if(!strcasecmp(name,StartID->name)) return Startid;
|
|
|
|
/* This is not the server we are looking for */
|
|
** First scan NEXT as far as we can... Then try Down
|
|
** We are not modifying the information in the structures
|
|
** in this calls
|
|
*/
|
|
|
|
if( (ServerID=FindServer(name,&(SearchID->next))) != NULL) return ServerID;
|
|
if( (ServerID=FindServer(name,&(SearchID->down))) != NULL) return ServerID;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
|
|
void dumpsubmap(struct aServer *server)
|
|
{
|
|
static char prefix[80]="";
|
|
static int offset=0;
|
|
char localbuf[512];
|
|
|
|
if(server==NULL)
|
|
return;
|
|
|
|
if(server->next==NULL)
|
|
{ sprintf(localbuf,"PRIVMSG WildThang :%s`-%s",prefix,server->name);
|
|
}
|
|
else
|
|
{ sprintf(localbuf,"PRIVMSG WildThang :%s|-%s",prefix,server->name);
|
|
}
|
|
writeln(botsck,localbuf);
|
|
|
|
|
|
if(server->next!=NULL)
|
|
strcpy(prefix+offset,"| ");
|
|
else
|
|
strcpy(prefix+offset," ");
|
|
|
|
offset+=2;
|
|
dumpsubmap(server->down);
|
|
offset-=2;
|
|
prefix[offset]='\0';
|
|
dumpsubmap(server->next);
|
|
}
|