コード例 #1
0
ファイル: ns_qdbban.c プロジェクト: GeekShed/anope-modules
/**
* Load data from the db file, and populate our ChanBanInfo lines
* @return 0 for success
**/
int mLoadData(void)
{
	FILE *in;

	char *nick = NULL;
	int len = 0;

	NickCore *nc = NULL;

	/* will _never_ be this big thanks to the 512 limit of a message */
	char buffer[2000];
	if ((in = fopen(qdbBanDBName, "r")) == NULL) {
		alog("ns_qdbban: WARNING: can not open the %s database file! (it might not exist, this is not fatal)", qdbBanDBName);
		return 1;
	} else {
		while (fgets(buffer, 1500, in)) {
			nick = myStrGetToken(buffer, ' ', 0);
			if (nick) {
				len = strlen(nick);
				/* Take the \n from the end of the nick */
				nick[len - 1] = '\0';
				if ((nc = findcore(nick))) {
					moduleAddData(&nc->moduleData, "qdbban", "on");
				}
				free(nick);
			}
		}
		return 0;
	}
	return 0;
}
コード例 #2
0
ファイル: os_oper.cpp プロジェクト: xxgrunge/anope196
	static void unserialize(serialized_data &data)
	{
		OperType *ot = OperType::Find(data["type"].astr());
		if (ot == NULL)
			return;
		NickCore *nc = findcore(data["name"].astr());
		if (nc == NULL)
			return;

		nc->o = new MyOper(nc->display, ot);
		Log(LOG_NORMAL, "operserv/oper") << "Tied oper " << nc->display << " to type " << ot->GetName();
	}
コード例 #3
0
ファイル: os_staff.c プロジェクト: Elemental-IRCd/anope
/**
 * The /os staff command.
 * @param u The user who issued the command
 * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing.
 **/
static int do_staff(User * u)
{
    int idx = 0;
    User *au = NULL;
    NickCore *nc;
    NickAlias *na;
    int found;
    int i;

    notice_lang(s_OperServ, u, OPER_STAFF_LIST_HEADER);
    slist_enum(&servopers, NULL, &opers_list_callback, u, "OPER");
    slist_enum(&servadmins, NULL, &opers_list_callback, u, "ADMN");

    for (idx = 0; idx < RootNumber; idx++) {
        found = 0;
        if ((au = finduser(ServicesRoots[idx]))) {      /* see if user is online */
            found = 1;
            notice_lang(s_OperServ, u, OPER_STAFF_FORMAT, '*', "ROOT",
                        ServicesRoots[idx]);
        } else if ((nc = findcore(ServicesRoots[idx]))) {
            for (i = 0; i < nc->aliases.count; i++) {   /* check all aliases */
                na = nc->aliases.list[i];
                if ((au = finduser(na->nick))) {        /* see if user is online */
                    found = 1;
                    notice_lang(s_OperServ, u, OPER_STAFF_AFORMAT,
                                '*', "ROOT", ServicesRoots[idx], na->nick);
                }
            }
        }

        if (!found)
            notice_lang(s_OperServ, u, OPER_STAFF_FORMAT, ' ', "ROOT",
                        ServicesRoots[idx]);

    }
    notice_lang(s_OperServ, u, END_OF_ANY_LIST, "Staff");
    return MOD_CONT;
}
コード例 #4
0
ファイル: combo.c プロジェクト: julesy89/ttp-java
extern stype combo(item *f, item *l, stype c, stype lb, stype ub,
            boolean def, boolean relx)
/* f,l : first, last item                                               */
/* c   : capacity of knapsack                                           */
/* lb  : lower bound. Solution vector is only updated if better z found */
/* ub  : upper bound. When upper bound is reached terminate immediately */
/* def : should solution vector be defined or just find objective value */
/* relx: relaxed problem is solved (no more relaxations will be made)   */
/* returns the objective value of the problem                           */
{
  allinfo a;
  interval *inttab;
  boolean heur, rudi;

  if ((ub != 0) && (lb == ub)) return lb;

  heur     = FALSE;
  rudi     = FALSE;
  inttab   = palloc(sizeof(interval), SORTSTACK);
  a.intv1b = &inttab[0];
  a.intv2b = &inttab[SORTSTACK - 1];
  a.intv1  = a.intv1b;
  a.intv2  = a.intv2b;
  a.fitem  = f;
  a.litem  = l;
  a.c      = c;
  a.z      = lb;
  a.lb     = lb;
  a.relx   = relx;
  a.master = (def && !relx);
  a.coresize = 0;

  partsort(&a, a.fitem, a.litem, 0, a.c, PARTITION);
  findbreak(&a);
  a.ub = (ub == 0 ? a.dantzig : ub);

  /* find and enumerate core */
  findcore(&a);
  reduceset(&a);

  while ((a.d.size > 0) && (a.z < a.ub)) {
    if (a.t <= a.lsort) {
      if (haschance(&a, a.t, RIGHT)) multiply(&a, a.t,  RIGHT);
       a.t++;
    }
    reduceset(&a);
    if (a.s >= a.fsort) {
      if (haschance(&a, a.s, LEFT)) multiply(&a, a.s,  LEFT);
      a.s--;
    }
    reduceset(&a);

    /* find better lower bound when needed */
    if ((!heur) && (a.d.size > MINHEUR)) { heuristic(&a); heur = TRUE; }

    /* find tight bound when needed */
    if ((!relx) && (a.d.size > MINSET)) { surrelax(&a); relx = TRUE; }

    /* use rudimentary divisibility to decrease c */
    if ((!rudi) && (a.d.size > MINRUDI)) { rudidiv(&a); rudi = TRUE; }
  }
  pfree(a.d.set1);
  pfree(inttab);

  if ((def) && (a.z > a.lb)) definesolution(&a);
  pfree(a.ffull);

  return a.z;
}
コード例 #5
0
ファイル: main.c プロジェクト: fallen/anope2mysql
void load_ns_dbase(void)
{
    dbFILE *f;
    int ver, i, j, c;
    NickAlias *na, **nalast, *naprev;
    NickCore *nc, **nclast, *ncprev;
    int failed = 0;
    uint16 tmp16;
    uint32 tmp32;
    char *s, *pass;

    if (!(f = open_db(s_NickServ, NickDBName, NICK_VERSION)))
        return;

    ver = get_file_version(f);

    if (ver <= 11) {
//        close_db(f);
//        load_old_ns_dbase();
        printf("old database gtfo !\n");
        return;
    }

    /* First we load nick cores */
    for (i = 0; i < 1024 && !failed; i++) {
    
    
        nclast = &nclists[i];
        ncprev = NULL;

        while ((c = getc_db(f)) == 1) {
            if (c != 1)
                printf("Invalid format in %s", NickDBName);

            nc = scalloc(1, sizeof(NickCore));
            *nclast = nc;
            nclast = &nc->next;
            nc->prev = ncprev;
            ncprev = nc;

            slist_init(&nc->aliases);

            SAFE(read_string(&nc->display, f));
            printf("%s", nc->display);
            if (ver < 14) {
                SAFE(read_string(&pass, f));
                if (pass) {
                    memset(nc->pass, 0, PASSMAX);
                    memcpy(nc->pass, pass, strlen(pass));
                } else
                    memset(nc->pass, 0, PASSMAX);
            } else
                SAFE(read_buffer(nc->pass, f));
//            printf(" %s", nc->pass);
            SAFE(read_string(&nc->email, f));
//            printf(" %s", nc->email);
            SAFE(read_string(&nc->greet, f));
//            printf(" %s", nc->greet);
            SAFE(read_int32(&nc->icq, f));
//            printf(" %d", nc->icq);
            SAFE(read_string(&nc->url, f));
//	    printf(" %s\n", nc->url);
            SAFE(read_int32(&nc->flags, f));
            if (!NSAllowKillImmed)
                nc->flags &= ~NI_KILL_IMMED;
            SAFE(read_int16(&nc->language, f));

            /* Add services opers and admins to the appropriate list, but
               only if the database version is more than 10. */
/*            if (nc->flags & NI_SERVICES_ADMIN)
                slist_add(&servadmins, nc);
            if (nc->flags & NI_SERVICES_OPER)
                slist_add(&servopers, nc); */ 
                
// OSEF des axx Sop et Sadmin !

            SAFE(read_int16(&nc->accesscount, f));
            if (nc->accesscount) {
                char **access;
                access = scalloc(sizeof(char *) * nc->accesscount, 1);
                nc->access = access;
                for (j = 0; j < nc->accesscount; j++, access++)
                    SAFE(read_string(access, f));
            }

            SAFE(read_int16(&tmp16, f));
            nc->memos.memocount = (int16) tmp16;
            SAFE(read_int16(&tmp16, f));
            nc->memos.memomax = (int16) tmp16;
            if (nc->memos.memocount) {
                Memo *memos;
                memos = scalloc(sizeof(Memo) * nc->memos.memocount, 1);
                nc->memos.memos = memos;
                for (j = 0; j < nc->memos.memocount; j++, memos++) {
                    SAFE(read_int32(&memos->number, f));
                    SAFE(read_int16(&memos->flags, f));
                    SAFE(read_int32(&tmp32, f));
                    memos->time = tmp32;
                    SAFE(read_buffer(memos->sender, f));
                    SAFE(read_string(&memos->text, f));
                    memos->moduleData = NULL;
                }
            }

            SAFE(read_int16(&nc->channelcount, f));
            SAFE(read_int16(&tmp16, f));
            nc->channelmax = CSMaxReg;

            if (ver < 13) {
                /* Used to be dead authentication system */
                SAFE(read_int16(&tmp16, f));
                SAFE(read_int32(&tmp32, f));
                SAFE(read_int16(&tmp16, f));
                SAFE(read_string(&s, f));
            }

        }                       /* while (getc_db(f) != 0) */
        *nclast = NULL;
    }                           /* for (i) */

    for (i = 0; i < 1024 && !failed; i++) {
        nalast = &nalists[i];
        naprev = NULL;
        while ((c = getc_db(f)) == 1) {
            if (c != 1)
                printf("Invalid format in %s", NickDBName);

            na = scalloc(1, sizeof(NickAlias));

            SAFE(read_string(&na->nick, f));

            SAFE(read_string(&na->last_usermask, f));
            SAFE(read_string(&na->last_realname, f));
            SAFE(read_string(&na->last_quit, f));

            SAFE(read_int32(&tmp32, f));
            na->time_registered = tmp32;
            SAFE(read_int32(&tmp32, f));
            na->last_seen = tmp32;
            SAFE(read_int16(&na->status, f));
            na->status &= ~NS_TEMPORARY;

            SAFE(read_string(&s, f));
            na->nc = findcore(s);
            free(s);

            slist_add(&na->nc->aliases, na);

            if (!(na->status & NS_VERBOTEN)) {
                if (!na->last_usermask)
                    na->last_usermask = sstrdup("");
                if (!na->last_realname)
                    na->last_realname = sstrdup("");
            }

            na->nc->flags &= ~NI_SERVICES_ROOT;

            *nalast = na;
            nalast = &na->next;
            na->prev = naprev;
            naprev = na;

        }                       /* while (getc_db(f) != 0) */

        *nalast = NULL;
    }                           /* for (i) */

//    close_db(f);
// nevermind wasting memory

    for (i = 0; i < 1024; i++) {
        NickAlias *next;

        for (na = nalists[i]; na; na = next) {
            next = na->next;
            /* We check for coreless nicks (although it should never happen) */
            if (!na->nc) {
                printf("%s: while loading database: %s has no core! We delete it (here just ignore it !).", s_NickServ, na->nick);
//                delnick(na);
                continue;
            }

            /* Add the Services root flag if needed. */
/*            for (j = 0; j < RootNumber; j++)
                if (!stricmp(ServicesRoots[j], na->nick))
                    na->nc->flags |= NI_SERVICES_ROOT; */
// OSEF de savoir si Paul Pierre ou Jacques est Services Root !                    
                    
        }
    }
}
コード例 #6
0
ファイル: chanserv.cpp プロジェクト: xxgrunge/anope196
	void OnDelCore(NickCore *nc)
	{
		// XXX this is slightly inefficient
		for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end;)
		{
			ChannelInfo *ci = it->second;
			++it;

			if (ci->GetFounder() == nc)
			{
				NickCore *newowner = NULL;
				if (ci->successor && (ci->successor->IsServicesOper() || !Config->CSMaxReg || ci->successor->channelcount < Config->CSMaxReg))
					newowner = ci->successor;
				else
				{
					ChanAccess *highest = NULL;
					for (unsigned j = 0; j < ci->GetAccessCount(); ++j)
					{
						ChanAccess *ca = ci->GetAccess(j);
						NickCore *anc = findcore(ca->mask);

						if (!anc || (!anc->IsServicesOper() && Config->CSMaxReg && anc->channelcount >= Config->CSMaxReg) || (anc == nc))
							continue;
						if (!highest || *ca > *highest)
							highest = ca;
					}
					if (highest)
						newowner = findcore(highest->mask);
				}

				if (newowner)
				{
					Log(LOG_NORMAL, "chanserv/expire") << "Transferring foundership of " << ci->name << " from deleted nick " << nc->display << " to " << newowner->display;
					ci->SetFounder(newowner);
					ci->successor = NULL;
				}
				else
				{
					Log(LOG_NORMAL, "chanserv/expire") << "Deleting channel " << ci->name << " owned by deleted nick " << nc->display;

					delete ci;
					continue;
				}
			}

			if (ci->successor == nc)
				ci->successor = NULL;

			for (unsigned j = 0; j < ci->GetAccessCount(); ++j)
			{
				ChanAccess *ca = ci->GetAccess(j);
				NickCore *anc = findcore(ca->mask);

				if (anc && anc == nc)
				{
					ci->EraseAccess(j);
					break;
				}
			}

			for (unsigned j = ci->GetAkickCount(); j > 0; --j)
			{
				AutoKick *akick = ci->GetAkick(j - 1);
				if (akick->HasFlag(AK_ISNICK) && akick->nc == nc)
					ci->EraseAkick(j - 1);
			}
		}
	}