mirror of
https://github.com/anope/anope.git
synced 2026-07-07 13:53:11 +02:00
the database converter can now convert the operserv database
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2678 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
@@ -731,6 +731,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
/* end of 1.9.0 broken database fix */
|
||||
}
|
||||
close_db(f);
|
||||
}
|
||||
|
||||
/* IIIc: Saving */
|
||||
@@ -781,6 +782,7 @@ int main(int argc, char *argv[])
|
||||
hc->last = NULL;
|
||||
firsthc = hc;
|
||||
}
|
||||
close_db(f);
|
||||
}
|
||||
/* IVb: Saving */
|
||||
for (hc = firsthc; hc; hc = hc->next)
|
||||
@@ -790,6 +792,115 @@ int main(int argc, char *argv[])
|
||||
<< hc->vHost << " " << hc->vIdent << std::endl;
|
||||
} // for (hc)
|
||||
|
||||
/*********************************/
|
||||
/* OPERSERV Section */
|
||||
/*********************************/
|
||||
|
||||
int32 maxusercnt = 0;
|
||||
int32 maxusertime = 0;
|
||||
SList akills, sglines, sqlines, szlines;
|
||||
Akill *ak;
|
||||
SXLine *sx;
|
||||
|
||||
if ((f = open_db_read("OperServ", "oper.db", 13)))
|
||||
{
|
||||
int16 tmp16;
|
||||
int32 tmp32;
|
||||
SAFE(read_int32(&maxusercnt, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
maxusertime = tmp32;
|
||||
|
||||
read_int16(&tmp16, f);
|
||||
slist_setcapacity(&akills, tmp16);
|
||||
for (i = 0; i < akills.capacity; i++)
|
||||
{
|
||||
ak = new Akill;
|
||||
SAFE(read_string(&ak->user, f));
|
||||
SAFE(read_string(&ak->host, f));
|
||||
SAFE(read_string(&ak->by, f));
|
||||
SAFE(read_string(&ak->reason, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
ak->seton = tmp32;
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
ak->expires = tmp32;
|
||||
slist_add(&akills, ak);
|
||||
}
|
||||
|
||||
read_int16(&tmp16, f);
|
||||
slist_setcapacity(&sglines, tmp16);
|
||||
for (i = 0; i < sglines.capacity; i++)
|
||||
{
|
||||
sx = new SXLine;
|
||||
SAFE(read_string(&sx->mask, f));
|
||||
SAFE(read_string(&sx->by, f));
|
||||
SAFE(read_string(&sx->reason, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
sx->seton = tmp32;
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
sx->expires = tmp32;
|
||||
slist_add(&sglines, sx);
|
||||
}
|
||||
|
||||
read_int16(&tmp16, f);
|
||||
slist_setcapacity(&sqlines, tmp16);
|
||||
for (i = 0; i < sqlines.capacity; i++)
|
||||
{
|
||||
sx = new SXLine;
|
||||
SAFE(read_string(&sx->mask, f));
|
||||
SAFE(read_string(&sx->by, f));
|
||||
SAFE(read_string(&sx->reason, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
sx->seton = tmp32;
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
sx->expires = tmp32;
|
||||
slist_add(&sqlines, sx);
|
||||
}
|
||||
|
||||
read_int16(&tmp16, f);
|
||||
slist_setcapacity(&szlines, tmp16);
|
||||
for (i = 0; i < szlines.capacity; i++)
|
||||
{
|
||||
sx = new SXLine;
|
||||
SAFE(read_string(&sx->mask, f));
|
||||
SAFE(read_string(&sx->by, f));
|
||||
SAFE(read_string(&sx->reason, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
sx->seton = tmp32;
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
sx->expires = tmp32;
|
||||
slist_add(&szlines, sx);
|
||||
}
|
||||
close_db(f); // oper.db
|
||||
} // if (open_db_read)
|
||||
/* done reading oper.db, now lets save the data in the new format */
|
||||
|
||||
std::cout << "Writing operserv data (stats, akills, sglines, szlines)" << std::endl;
|
||||
fs << "OS STATS " << maxusercnt << " " << maxusertime << std::endl;
|
||||
|
||||
for (i = 0; i < akills.count; i++)
|
||||
{
|
||||
ak = static_cast<Akill *>(akills.list[i]);
|
||||
fs << "OS AKILL " << ak->user << " " << ak->host << " " << ak->by << " "
|
||||
<< ak->seton << " " << ak->expires << " :" << ak->reason << std::endl;
|
||||
}
|
||||
for (i = 0; i < sglines.count; i++)
|
||||
{
|
||||
sx = static_cast<SXLine *>(sglines.list[i]);
|
||||
fs << "OS SGLINE " << sx->mask << " " << sx->by << " " << sx->seton << " "
|
||||
<< sx->expires << " :" << sx->reason << std::endl;
|
||||
}
|
||||
for (i = 0; i < sqlines.count; i++)
|
||||
{
|
||||
sx = static_cast<SXLine *>(sqlines.list[i]);
|
||||
fs << "OS SQLINE " << sx->mask << " " << sx->by << " " << sx->seton << " "
|
||||
<< sx->expires << " :" << sx->reason << std::endl;
|
||||
}
|
||||
for (i = 0; i < szlines.count; i++)
|
||||
{
|
||||
sx = static_cast<SXLine *>(szlines.list[i]);
|
||||
fs << "OS SZLINE " << sx->mask << " " << sx->by << " " << sx->seton << " "
|
||||
<< sx->expires << " :" << sx->reason << std::endl;
|
||||
}
|
||||
|
||||
/* MERGING DONE \o/ HURRAY! */
|
||||
fs.close();
|
||||
|
||||
@@ -70,6 +70,10 @@ typedef struct chaninfo_ ChannelInfo;
|
||||
typedef struct botinfo_ BotInfo;
|
||||
typedef struct badword_ BadWord;
|
||||
typedef struct hostcore_ HostCore;
|
||||
typedef struct akill_ Akill;
|
||||
typedef struct sxline_ SXLine;
|
||||
typedef struct slist_ SList;
|
||||
typedef struct slistopts_ SListOpts;
|
||||
|
||||
struct memo_ {
|
||||
uint32 number; /* Index number -- not necessarily array position! */
|
||||
@@ -210,6 +214,61 @@ struct hostcore_ {
|
||||
time_t time; /* Date/Time vHost was set */
|
||||
};
|
||||
|
||||
struct akill_ {
|
||||
char *user; /* User part of the AKILL */
|
||||
char *host; /* Host part of the AKILL */
|
||||
|
||||
char *by; /* Who set the akill */
|
||||
char *reason; /* Why they got akilled */
|
||||
|
||||
time_t seton; /* When it was set */
|
||||
time_t expires; /* When it expires */
|
||||
};
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/* Structure for OperServ SGLINE and SZLINE commands */
|
||||
|
||||
struct sxline_ {
|
||||
char *mask;
|
||||
char *by;
|
||||
char *reason;
|
||||
time_t seton;
|
||||
time_t expires;
|
||||
};
|
||||
|
||||
struct slist_ {
|
||||
void **list;
|
||||
|
||||
int16 count; /* Total entries of the list */
|
||||
int16 capacity; /* Capacity of the list */
|
||||
int16 limit; /* Maximum possible entries on the list */
|
||||
|
||||
SListOpts *opts;
|
||||
};
|
||||
|
||||
|
||||
struct slistopts_ {
|
||||
int32 flags; /* Flags for the list. See below. */
|
||||
|
||||
int (*compareitem) (SList *slist, void *item1, void *item2); /* Called to compare two items */
|
||||
int (*isequal) (SList *slist, void *item1, void *item2); /* Called by slist_indexof. item1 can be an arbitrary pointer. */
|
||||
void (*freeitem) (SList *slist, void *item); /* Called when an item is removed */
|
||||
};
|
||||
|
||||
|
||||
#define SLIST_DEFAULT_LIMIT 32767
|
||||
|
||||
#define SLISTF_NODUP 0x00000001 /* No duplicates in the list. */
|
||||
#define SLISTF_SORT 0x00000002 /* Automatically sort the list. Used with compareitem member. */
|
||||
|
||||
/* Note that number is the index in the array + 1 */
|
||||
typedef int (*slist_enumcb_t) (SList *slist, int number, void *item, va_list args);
|
||||
/* Callback to know whether we can delete the entry. */
|
||||
typedef int (*slist_delcheckcb_t) (SList *slist, void *item, va_list args);
|
||||
|
||||
|
||||
|
||||
dbFILE *open_db_write(const char *service, const char *filename, int version);
|
||||
dbFILE *open_db_read(const char *service, const char *filename, int version);
|
||||
NickCore *findcore(const char *nick, int version);
|
||||
@@ -1178,4 +1237,72 @@ int stricmp(const char *s1, const char *s2)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int slist_setcapacity(SList * slist, int16 capacity)
|
||||
{
|
||||
if (slist->capacity == capacity)
|
||||
return 1;
|
||||
slist->capacity = capacity;
|
||||
if (slist->capacity)
|
||||
slist->list = static_cast<void **>(realloc(slist->list, sizeof(void *) * slist->capacity));
|
||||
else {
|
||||
free(slist->list);
|
||||
slist->list = NULL;
|
||||
}
|
||||
if (slist->capacity < slist->count)
|
||||
slist->count = slist->capacity;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int slist_indexof(SList * slist, void *item)
|
||||
{
|
||||
int16 i;
|
||||
void *entry;
|
||||
|
||||
if (slist->count == 0)
|
||||
return -1;
|
||||
|
||||
for (i = 0, entry = slist->list[0]; i < slist->count;
|
||||
i++, entry = slist->list[i]) {
|
||||
if ((slist->opts
|
||||
&& slist->opts->isequal) ? (slist->opts->isequal(slist, item,
|
||||
entry))
|
||||
: (item == entry))
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int slist_add(SList * slist, void *item)
|
||||
{
|
||||
if (slist->limit != 0 && slist->count >= slist->limit)
|
||||
return -2;
|
||||
if (slist->opts && (slist->opts->flags & SLISTF_NODUP)
|
||||
&& slist_indexof(slist, item) != -1)
|
||||
return -3;
|
||||
if (slist->capacity == slist->count)
|
||||
slist_setcapacity(slist, slist->capacity + 1);
|
||||
|
||||
if (slist->opts && (slist->opts->flags & SLISTF_SORT)
|
||||
&& slist->opts->compareitem) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < slist->count; i++) {
|
||||
if (slist->opts->compareitem(slist, item, slist->list[i]) <= 0) {
|
||||
memmove(&slist->list[i + 1], &slist->list[i],
|
||||
sizeof(void *) * (slist->count - i));
|
||||
slist->list[i] = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == slist->count)
|
||||
slist->list[slist->count] = item;
|
||||
} else {
|
||||
slist->list[slist->count] = item;
|
||||
}
|
||||
|
||||
return slist->count++;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user