示例#1
0
文件: Matrix.c 项目: jayminer81/NiKom
void __saveds __asm LIBMatrix2NiKom(register __a6 struct NiKomBase *NiKomBase) {
	struct FidoText *fidotext;
	struct FidoLine *fl;
	int going=TRUE,anv,brev;
	BPTR fh;
	char buffer[100],*foo,filnamn[20];
	struct TagItem ti = { TAG_DONE };

	if(!NiKomBase->Servermem) return;

	LIBLockNiKomBase(NiKomBase);
	while(going) {
		strcpy(buffer,NiKomBase->Servermem->fidodata.matrixdir);
		sprintf(filnamn,"%d.msg",NiKomBase->lastmatrix);
		AddPart(buffer,filnamn,99);
		if(!(fidotext = LIBReadFidoText(buffer,&ti,NiKomBase))) break;
		NiKomBase->lastmatrix++;
		if(fidotext->attribut & FIDOT_LOCAL) {
			continue;
		}
		sprintf(buffer,"Brev %d till %s (%d:%d/%d.%d)",NiKomBase->lastmatrix-1,fidotext->touser,fidotext->tozone,fidotext->tonet,
			fidotext->tonode,fidotext->topoint);
		writelog(NiKomBase->Servermem->fidodata.fidologfile,buffer);
		anv=fidoparsenamn(fidotext->touser,NiKomBase->Servermem);
		if(anv==-1) {
			sprintf(buffer,"Hittar inte %s",fidotext->touser);
			writelog(NiKomBase->Servermem->fidodata.fidologfile,buffer);
			continue;
		}
		brev=updatenextletter(anv);
		if(brev==-1) {
			continue;
		}
		sprintf(buffer,"NiKom:Users/%d/%d/%d.letter",anv/100,anv,brev);
		if(!(fh=Open(buffer,MODE_NEWFILE))) {
			continue;
		}
		FPuts(fh,"System-ID: Fido\n");
		sprintf(buffer,"From: %s (%d:%d/%d.%d)\n",fidotext->fromuser,fidotext->fromzone,fidotext->fromnet,
			fidotext->fromnode,fidotext->frompoint);
		FPuts(fh,buffer);
		sprintf(buffer,"To: %s (%d:%d/%d.%d)\n",fidotext->touser,fidotext->tozone,fidotext->tonet,
			fidotext->tonode,fidotext->topoint);
		FPuts(fh,buffer);
		sprintf(buffer,"Message-ID: %s\n",fidotext->msgid);
		FPuts(fh,buffer);
		sprintf(buffer,"Date: %s\n",fidotext->date);
		FPuts(fh,buffer);
		foo = hittaefter(fidotext->subject);
		if(fidotext->subject[0] == 0 || (fidotext->subject[0] == ' ' && foo[0] == 0)) strcpy(buffer,"Subject: -\n");
		else sprintf(buffer,"Subject: %s\n",fidotext->subject);
		FPuts(fh,buffer);
		for(fl=(struct FidoLine *)fidotext->text.mlh_Head;fl->line_node.mln_Succ;fl=(struct FidoLine *)fl->line_node.mln_Succ) {
			FPuts(fh,fl->text);
			FPutC(fh,'\n');
		}
		Close(fh);
		FreeFidoText(fidotext);
	}
	sprintf(buffer,"%d",NiKomBase->lastmatrix);
	SetVar("NiKom:DatoCfg/LastMatrix",buffer,-1,GVF_GLOBAL_ONLY);
	LIBUnLockNiKomBase(NiKomBase);
}
示例#2
0
int __saveds __asm LIBCreateUser(register __d0 LONG nodnummer, register __a0 struct TagItem *taglist, register __a6 struct NiKomBase *NiKomBase)
{
	struct User *newuser;
	struct ShortUser *allokpek;
	struct Mote *motpek=(struct Mote *)NiKomBase->Servermem->mot_list.mlh_Head;
	long tid, anvnummer = -1;
	char dirnamn[100],filnamn[40], bitmap[MAXTEXTS/8];
	BPTR lock,fh;
	ULONG tmp;
	
	if(!(newuser=AllocMem(sizeof(struct User),MEMF_CLEAR | MEMF_PUBLIC))) return(-1);

	strcpy(newuser->namn,(char *)GetTagData(US_Name,NULL,taglist));
	if(newuser->namn == NULL)
	{
		FreeMem(newuser,sizeof(struct User));
		return(-2);
	}
	else
		if(NiKomBase->Servermem != NULL)
		{
			if(parsenamn(newuser->namn, NiKomBase) != -1)
			{
				FreeMem(newuser,sizeof(struct User));
				return(-3);
			}
		}
		else
		{
			sprintf(filnamn,"NiKom:Users/0/0/Data");
			if(fh=Open(filnamn, MODE_OLDFILE))
			{
				Close(fh);
				FreeMem(newuser,sizeof(struct User));
				return(-6);
			}
			anvnummer = 0;
		}

	strcpy(newuser->gata,(char *)GetTagData(US_Street,NULL,taglist));
	if(newuser->gata == NULL)
	{
		FreeMem(newuser,sizeof(struct User));
		return(-2);
	}

	strcpy(newuser->postadress,(char *)GetTagData(US_Address,NULL,taglist));
	if(newuser->postadress == NULL)
	{
		FreeMem(newuser,sizeof(struct User));
		return(-2);
	}

	strcpy(newuser->land,(char *)GetTagData(US_Country,NULL,taglist));
	if(newuser->land == NULL)
	{
		FreeMem(newuser,sizeof(struct User));
		return(-2);
	}

	strcpy(newuser->prompt,(char *)GetTagData(US_Prompt,NULL,taglist));
	if(newuser->land == NULL)
	{
		FreeMem(newuser,sizeof(struct User));
		return(-2);
	}

	strcpy(newuser->telefon,(char *)GetTagData(US_Phonenumber,NULL,taglist));
	if(newuser->telefon == NULL)
	{
		FreeMem(newuser,sizeof(struct User));
		return(-2);
	}

	strcpy(newuser->annan_info,(char *)GetTagData(US_OtherInfo,NULL,taglist));
	if(newuser->annan_info == NULL)
	{
		FreeMem(newuser,sizeof(struct User));
		return(-2);
	}

	strcpy(newuser->losen,(char *)GetTagData(US_Password,NULL,taglist));
	if(newuser->losen == NULL)
	{
		FreeMem(newuser,sizeof(struct User));
		return(-2);
	}

	tmp = GetTagData(US_Status,-1,taglist);
	if(tmp == -1)
	{
		FreeMem(newuser,sizeof(struct User));
		return(-2);
	}
	else
	{
		newuser->status = tmp;
	}

	tmp = GetTagData(US_Rader, -2,taglist);
	if(tmp == -2)
	{
		FreeMem(newuser,sizeof(struct User));
		return(-2);
	}
	else
	{
		newuser->rader = tmp;
	}

	tmp = GetTagData(US_Charset,-1,taglist);
	if(tmp == -1)
	{
		FreeMem(newuser,sizeof(struct User));
		return(-2);
	}
	else
	{
		newuser->chrset = tmp;
	}

	tmp = GetTagData(US_Flags,-1,taglist);
	if(tmp == -1)
	{
		FreeMem(newuser,sizeof(struct User));
		return(-2);
	}
	else
	{
		newuser->flaggor = tmp;
	}

	if(newuser->flaggor == -1)
		newuser->flaggor = NiKomBase->Servermem->cfg.defaultflags;

	if(newuser->rader == -1)
		newuser->rader = NiKomBase->Servermem->cfg.defaultrader;

	if(NiKomBase->Servermem->cfg.cfgflags & NICFG_CRYPTEDPASSWORDS)
		strcpy(newuser->losen, LIBCryptPassword(newuser->losen, NiKomBase));

	newuser->tot_tid = 0L;
	newuser->senast_in = 0L;
	newuser->read = 0L;
	newuser->skrivit = 0L;
	newuser->upload = 0;
	newuser->download = 0;
	newuser->loggin = 0;
	newuser->grupper = 0L;
	newuser->defarea = 0L;
	newuser->shell = 0;
	newuser->brevpek = 0;

	memset((void *)newuser->motmed, 0, MAXMOTE/8);
	memset((void *)newuser->motratt, 0, MAXMOTE/8);

	time(&tid);
	newuser->forst_in = tid;

	memset((void *)bitmap,~0,MAXTEXTS/8);

	if(anvnummer == -1)
	{
		anvnummer = ((struct ShortUser *)NiKomBase->Servermem->user_list.mlh_TailPred)->nummer+1;
		newuser->textpek = NiKomBase->Servermem->info.lowtext;
		newuser->status = NiKomBase->Servermem->cfg.defaultstatus;
		newuser->protokoll = NiKomBase->Servermem->cfg.defaultprotokoll;

		for(;motpek->mot_node.mln_Succ;motpek=(struct Mote *)motpek->mot_node.mln_Succ)
		{
			if(motpek->status & (SKRIVSTYRT | SLUTET)) BAMCLEAR(newuser->motratt,motpek->nummer);
			else BAMSET(newuser->motratt,motpek->nummer);
		}

		if(!(allokpek=(struct ShortUser *)AllocMem(sizeof(struct ShortUser),MEMF_CLEAR | MEMF_PUBLIC)))
		{
			FreeMem(newuser,sizeof(struct User));
			return(-1);
		}
		strcpy(allokpek->namn,newuser->namn);
		allokpek->nummer=anvnummer;
		allokpek->status=newuser->status;
		AddTail((struct List *)&NiKomBase->Servermem->user_list,(struct Node *)allokpek);

		if(nodnummer != -1) memcpy((void *)&NiKomBase->Servermem->inne[nodnummer],(void *)newuser,sizeof(newuser));
	}
	else
	{
		newuser->textpek = newuser->protokoll = 0;
	}

	LIBLockNiKomBase(NiKomBase);

	sprintf(dirnamn,"NiKom:Users/%d",anvnummer/100);
	if(!(lock=Lock(dirnamn,ACCESS_READ)))
		if(!(lock=CreateDir(dirnamn)))
		{
			FreeMem(newuser,sizeof(struct User));
			return(-4);
		}
	UnLock(lock);
	sprintf(dirnamn,"NiKom:Users/%d/%d",anvnummer/100,anvnummer);
	if(!(lock=Lock(dirnamn,ACCESS_READ)))
		if(!(lock=CreateDir(dirnamn)))
		{
			FreeMem(newuser,sizeof(struct User));
			return(-4);
		}
	UnLock(lock);

	sprintf(filnamn,"NiKom:Users/%d/%d/Data",anvnummer/100,anvnummer);
	if(!(fh=Open(filnamn,MODE_NEWFILE)))
	{
		FreeMem(newuser,sizeof(struct User));
		LIBUnLockNiKomBase(NiKomBase);
		return(-4);
	}
	if(Write(fh,(void *)newuser,sizeof(struct User))==-1) {
		Close(fh);
		FreeMem(newuser,sizeof(struct User));
		LIBUnLockNiKomBase(NiKomBase);
		return(-4);
	}
	Close(fh);
	sprintf(filnamn,"NiKom:Users/%d/%d/Bitmap0",anvnummer/100,anvnummer);
	if(!(fh=Open(filnamn,MODE_NEWFILE)))
	{
		FreeMem(newuser,sizeof(struct User));
		LIBUnLockNiKomBase(NiKomBase);
		return(-4);
	}
	if(Write(fh,(void *)bitmap,MAXTEXTS/8)==-1) {
		Close(fh);
		FreeMem(newuser,sizeof(struct User));
		LIBUnLockNiKomBase(NiKomBase);
		return(-4);
	}
	Close(fh);
	sprintf(filnamn,"Nikom:Users/%d/%d/.firstletter",anvnummer/100,anvnummer);
	if(!(fh=Open(filnamn,MODE_NEWFILE)))
	{
		FreeMem(newuser,sizeof(struct User));
		LIBUnLockNiKomBase(NiKomBase);
		return(-4);
	}
	Write(fh,"0",1);
	Close(fh);
	sprintf(filnamn,"Nikom:Users/%d/%d/.nextletter",anvnummer/100,anvnummer);
	if(!(fh=Open(filnamn,MODE_NEWFILE)))
	{
		FreeMem(newuser,sizeof(struct User));
		LIBUnLockNiKomBase(NiKomBase);
		return(-4);
	}
	Write(fh,"0",1);
	Close(fh);
	LIBUnLockNiKomBase(NiKomBase);
	return(anvnummer);
}