Exemple #1
0
bool Client::SaveToDB()
{
	typedef Poco::Tuple<string, string, string, string, int32_t, string, int32_t, string, string, int32_t, int16_t, int32_t, double, double, double, bool, int8_t, string, int64_t> ClientSave;


	ClientSave savedata(DBBuffs(), DBResearch(), DBItems(), DBMisc(), m_status, m_ipaddress, m_sex, m_flag, m_faceurl, m_allianceid, m_alliancerank, m_cents, m_prestige, m_honor, m_lastlogin, m_changedface, m_icon, m_allianceapply, m_allianceapplytime);


	try
	{
		Session ses(m_main->serverpool->get());
		ses << "UPDATE `accounts` SET buffs=?,`research`=?,items=?,misc=?,`status`=?,ipaddress=?,sex=?,flag=?,faceurl=?,allianceid=?,alliancerank=?,cents=?,prestige=?,honor=?,lastlogin=?,changedface=?,icon=?,allianceapply=?,allianceapplytime=? WHERE accountid=?;", use(savedata), use(m_accountid), now;
		return true;
	}
	catch (Poco::Data::MySQL::ConnectionException& e)\
	{
		m_main->consoleLogger->error(Poco::format("ConnectionException: %s", e.displayText()));
	}
	catch (Poco::Data::MySQL::StatementException& e)
	{
		m_main->consoleLogger->error(Poco::format("StatementException: %s", e.displayText()));
	}
	catch (Poco::Data::MySQL::MySQLException& e)
	{
		m_main->consoleLogger->error(Poco::format("MySQLException: %s", e.displayText()));
	}
	catch (Poco::InvalidArgumentException& e)
	{
		m_main->consoleLogger->error(Poco::format("InvalidArgumentException: %s", e.displayText()));
	}
	return false;
}
int readserial::check_sign(char *buffer)
{
		if(buffer[0] == 'E' && buffer[1] == 'N' && buffer[2] == 'D'){
				//数据全部录入temp_data后进行数据转存
				if(counter++ == 4){
						savedata(&p_type, &temp_data);
				}
				//countinue - 1
				//break -0
				return 1;
		}else if(buffer[0] == 'E' && buffer[1] == 'O' && buffer[2] == 'F'){
				return 0;
				//Emergency Event
		}else if(buffer[0] == 'E' && buffer[1] == 'M' && buffer[2] == 'E'){
				emergency = 1;
				//0 is false
				//1 is true
				return 1;

		}else{
				node_name = NULL;
				//This is Debug massaage, change it when this module complete.
				Serial.println("Data Transfer ERROR");
				return 0;
		}
		return 0;
}
Exemple #3
0
bool PlayerCity::SaveToDB()
{
	typedef Poco::Tuple<string, int8_t, bool, string, int32_t, string, string, string, string, string, string, bool, bool, double, double, double, double, double> CitySave;


	CitySave savedata(DBMisc(), m_status, m_allowalliance, m_logurl, m_tileid, DBTransingtrades(), DBTroops(), m_cityname, DBBuildings(), DBFortifications(), DBTrades(), m_gooutforbattle, m_hasenemy, m_resources.gold, m_resources.food, m_resources.wood, m_resources.iron, m_resources.stone);


	try
	{
		Session ses(m_client->m_main->serverpool->get());
		ses << "UPDATE `cities` SET misc=?,status=?,allowalliance=?,logurl=?,fieldid=?,transingtrades=?,troop=?,name=?,buildings=?,fortification=?,trades=?,gooutforbattle=?,hasenemy=?,gold=?,food=?,wood=?,iron=?,stone=? WHERE id=?;", use(savedata), use(this->m_castleinternalid), now;
		return true;
	}
	catch (Poco::Data::MySQL::ConnectionException& e)\
	{
		m_client->m_main->consoleLogger->error(Poco::format("ConnectionException: %s", e.displayText()));
	}
	catch (Poco::Data::MySQL::StatementException& e)
	{
		m_client->m_main->consoleLogger->error(Poco::format("StatementException: %s", e.displayText()));
	}
	catch (Poco::Data::MySQL::MySQLException& e)
	{
		m_client->m_main->consoleLogger->error(Poco::format("MySQLException: %s", e.displayText()));
	}
	catch (Poco::InvalidArgumentException& e)
	{
		m_client->m_main->consoleLogger->error(Poco::format("InvalidArgumentException: %s", e.displayText()));
	}
	return false;
}
void CLoginMsg::checkdata()
{
	Cuserinfo m_set;
	m_set.Open();
	m_set.MoveFirst();
	while (!m_set.IsEOF())
	{
		if(m_set.m_username==username) 
		{
			LoginMessage.Format(_T("RU"));
			m_set.Close();
			return;
		}
		if(m_set.m_email==email)
		{
			LoginMessage.Format(_T("RE"));
			m_set.Close();
			return;
		}
		m_set.MoveNext();
	}
	LoginMessage.Format(_T("RY"));
	m_set.Close();
	savedata();
}
Exemple #5
0
	void halt() {
		std::fstream savedata("resources\\savedata.txt", std::ofstream::out, std::ofstream::trunc);
		if (savedata.is_open()) {
			float x, y;
			x = myPlayer->GetXPosition();
			y = myPlayer->GetYPosition();
			savedata << x;
			savedata << " ";
			savedata << y;
			savedata.close();
		}

		delete fnt;
		delete mouseSprite;
		delete ani;
		delete camera;
		delete portal;
		delete portalSprite;
		delete myPlayer;
		hge->Texture_Free(hPortal);
		hge->Texture_Free(hMouseTexture);
		hge->Texture_Free(anitex);
		hge->Texture_Free(quad.tex);
		hge->Effect_Free(snd);

		delete world[TEXT("desert")];
		delete world[TEXT("little")];
		


		//delete gui;
		//delete imageLoader;
		//delete input;
		//delete graphics;
		gui->shutdown();
		delete gui;
		gui = nullptr;
		//hge->System_Shutdown();
		hge->Release();
	}
Exemple #6
0
	void process_cli(CLIENT *client, char* recvbuf, int len)
	{
	char sendbuf[MAXDATASIZE];

	recvbuf[len-1] = '\0';
	if (strlen(client->name) == 0) {
	   /* Got client's name from client */
	   memcpy(client->name,recvbuf, len);
	   printf("Client's name is %s.\n",client->name);
	   return;
	   }

	/* save client's data */
	printf("Received client( %s ) message: %s\n",client->name, recvbuf);
	/* save user's data */
	savedata(recvbuf,len, client->data);
	/* reverse usr's data */
	for (int i1 = 0; i1 < len - 1; i1++) {
	   sendbuf[i1] = recvbuf[len - i1 -2];
	}
	sendbuf[len - 1] = '\0';

	send(client->fd,sendbuf,strlen(sendbuf),0); 
	}
Exemple #7
0
void
ldobj1(Biobuf *f, char *pkg, int64 len, char *pn)
{
	int32 ipc;
	Prog *p;
	int v, o, r, skip;
	Sym *h[NSYM], *s;
	uint32 sig;
	int ntext;
	int32 eof;
	char *name, *x;
	char src[1024];
	Prog *lastp;

	lastp = nil;
	ntext = 0;
	eof = Boffset(f) + len;
	src[0] = 0;


newloop:
	memset(h, 0, sizeof(h));
	version++;
	histfrogp = 0;
	ipc = pc;
	skip = 0;

loop:
	if(f->state == Bracteof || Boffset(f) >= eof)
		goto eof;
	o = Bgetc(f);
	if(o == Beof)
		goto eof;
	o |= Bgetc(f) << 8;
	if(o <= AXXX || o >= ALAST) {
		if(o < 0)
			goto eof;
		diag("%s:#%lld: opcode out of range: %#ux", pn, Boffset(f), o);
		print("	probably not a .%c file\n", thechar);
		errorexit();
	}

	if(o == ANAME || o == ASIGNAME) {
		sig = 0;
		if(o == ASIGNAME)
			sig = Bget4(f);
		v = Bgetc(f);	/* type */
		o = Bgetc(f);	/* sym */
		r = 0;
		if(v == D_STATIC)
			r = version;
		name = Brdline(f, '\0');
		if(name == nil) {
			if(Blinelen(f) > 0) {
				fprint(2, "%s: name too long\n", pn);
				errorexit();
			}
			goto eof;
		}
		x = expandpkg(name, pkg);
		s = lookup(x, r);
		if(x != name)
			free(x);

		if(debug['S'] && r == 0)
			sig = 1729;
		if(sig != 0){
			if(s->sig != 0 && s->sig != sig)
				diag("incompatible type signatures"
					"%ux(%s) and %ux(%s) for %s",
					s->sig, s->file, sig, pn, s->name);
			s->sig = sig;
			s->file = pn;
		}

		if(debug['W'])
			print("	ANAME	%s\n", s->name);
		if(o < 0 || o >= nelem(h))
			mangle(pn);
		h[o] = s;
		if((v == D_EXTERN || v == D_STATIC) && s->type == 0)
			s->type = SXREF;
		if(v == D_FILE) {
			if(s->type != SFILE) {
				histgen++;
				s->type = SFILE;
				s->value = histgen;
			}
			if(histfrogp < MAXHIST) {
				histfrog[histfrogp] = s;
				histfrogp++;
			} else
				collapsefrog(s);
			dwarfaddfrag(s->value, s->name);
		}
		goto loop;
	}

	p = mal(sizeof(*p));
	p->as = o;
	p->line = Bget4(f);
	p->back = 2;
	p->ft = 0;
	p->tt = 0;
	zaddr(pn, f, &p->from, h);
	fromgotype = adrgotype;
	zaddr(pn, f, &p->to, h);

	if(debug['W'])
		print("%P\n", p);

	switch(p->as) {
	case AHISTORY:
		if(p->to.offset == -1) {
			addlib(src, pn);
			histfrogp = 0;
			goto loop;
		}
		if(src[0] == '\0')
			copyhistfrog(src, sizeof src);
		addhist(p->line, D_FILE);		/* 'z' */
		if(p->to.offset)
			addhist(p->to.offset, D_FILE1);	/* 'Z' */
		histfrogp = 0;
		goto loop;

	case AEND:
		histtoauto();
		if(cursym != nil && cursym->text)
			cursym->autom = curauto;
		curauto = 0;
		cursym = nil;
		if(Boffset(f) == eof)
			return;
		goto newloop;

	case AGLOBL:
		s = p->from.sym;
		if(s->type == 0 || s->type == SXREF) {
			s->type = SBSS;
			s->size = 0;
		}
		if(s->type != SBSS && !s->dupok) {
			diag("%s: redefinition: %s in %s",
				pn, s->name, TNAME);
			s->type = SBSS;
			s->size = 0;
		}
		if(p->to.offset > s->size)
			s->size = p->to.offset;
		if(p->from.scale & DUPOK)
			s->dupok = 1;
		if(p->from.scale & RODATA)
			s->type = SRODATA;
		goto loop;

	case ADATA:
		// Assume that AGLOBL comes after ADATA.
		// If we've seen an AGLOBL that said this sym was DUPOK,
		// ignore any more ADATA we see, which must be
		// redefinitions.
		s = p->from.sym;
		if(s->dupok) {
//			if(debug['v'])
//				Bprint(&bso, "skipping %s in %s: dupok\n", s->name, pn);
			goto loop;
		}
		if(s->file == nil)
			s->file = pn;
		else if(s->file != pn) {
			diag("multiple initialization for %s: in both %s and %s", s->name, s->file, pn);
			errorexit();
		}
		savedata(s, p, pn);
		unmal(p, sizeof *p);
		goto loop;

	case AGOK:
		diag("%s: GOK opcode in %s", pn, TNAME);
		pc++;
		goto loop;

	case ATEXT:
		s = p->from.sym;
		if(s->text != nil) {
			diag("%s: %s: redefinition", pn, s->name);
			return;
		}
		if(ntext++ == 0 && s->type != 0 && s->type != SXREF) {
			/* redefinition, so file has probably been seen before */
			if(debug['v'])
				diag("skipping: %s: redefinition: %s", pn, s->name);
			return;
		}
		if(cursym != nil && cursym->text) {
			histtoauto();
			cursym->autom = curauto;
			curauto = 0;
		}
		skip = 0;
		if(etextp)
			etextp->next = s;
		else
			textp = s;
		etextp = s;
		s->text = p;
		cursym = s;
		if(s->type != 0 && s->type != SXREF) {
			if(p->from.scale & DUPOK) {
				skip = 1;
				goto casdef;
			}
			diag("%s: redefinition: %s\n%P", pn, s->name, p);
		}
		s->type = STEXT;
		s->value = pc;
		lastp = p;
		p->pc = pc++;
		goto loop;

	case AFMOVF:
	case AFADDF:
	case AFSUBF:
	case AFSUBRF:
	case AFMULF:
	case AFDIVF:
	case AFDIVRF:
	case AFCOMF:
	case AFCOMFP:
		if(skip)
			goto casdef;
		if(p->from.type == D_FCONST) {
			/* size sb 9 max */
			sprint(literal, "$%ux", ieeedtof(&p->from.ieee));
			s = lookup(literal, 0);
			if(s->type == 0) {
				s->type = SDATA;
				adduint32(s, ieeedtof(&p->from.ieee));
				s->reachable = 0;
			}
			p->from.type = D_EXTERN;
			p->from.sym = s;
			p->from.offset = 0;
		}
		goto casdef;

	case AFMOVD:
	case AFADDD:
	case AFSUBD:
	case AFSUBRD:
	case AFMULD:
	case AFDIVD:
	case AFDIVRD:
	case AFCOMD:
	case AFCOMDP:
		if(skip)
			goto casdef;
		if(p->from.type == D_FCONST) {
			/* size sb 18 max */
			sprint(literal, "$%ux.%ux",
				p->from.ieee.l, p->from.ieee.h);
			s = lookup(literal, 0);
			if(s->type == 0) {
				s->type = SDATA;
				adduint32(s, p->from.ieee.l);
				adduint32(s, p->from.ieee.h);
				s->reachable = 0;
			}
			p->from.type = D_EXTERN;
			p->from.sym = s;
			p->from.offset = 0;
		}
		goto casdef;

	casdef:
	default:
		if(skip)
			nopout(p);
		p->pc = pc;
		pc++;

		if(p->to.type == D_BRANCH)
			p->to.offset += ipc;
		if(lastp == nil) {
			if(p->as != ANOP)
				diag("unexpected instruction: %P", p);
			goto loop;
		}
		lastp->link = p;
		lastp = p;
		goto loop;
	}

eof:
	diag("truncated object file: %s", pn);
}
Exemple #8
0
void
ldobj1(Biobuf *f, char *pkg, int64 len, char *pn)
{
	int32 ipc;
	Prog *p;
	Sym *h[NSYM], *s;
	int v, o, r, skip;
	uint32 sig;
	char *name;
	int ntext;
	int32 eof;
	char src[1024], *x;
	Prog *lastp;

	lastp = nil;
	ntext = 0;
	eof = Boffset(f) + len;
	src[0] = 0;

newloop:
	memset(h, 0, sizeof(h));
	version++;
	histfrogp = 0;
	ipc = pc;
	skip = 0;

loop:
	if(f->state == Bracteof || Boffset(f) >= eof)
		goto eof;
	o = BGETC(f);
	if(o == Beof)
		goto eof;

	if(o <= AXXX || o >= ALAST) {
		diag("%s:#%lld: opcode out of range: %#ux", pn, Boffset(f), o);
		print("	probably not a .5 file\n");
		errorexit();
	}
	if(o == ANAME || o == ASIGNAME) {
		sig = 0;
		if(o == ASIGNAME)
			sig = Bget4(f);
		v = BGETC(f); /* type */
		o = BGETC(f); /* sym */
		r = 0;
		if(v == D_STATIC)
			r = version;
		name = Brdline(f, '\0');
		if(name == nil) {
			if(Blinelen(f) > 0) {
				fprint(2, "%s: name too long\n", pn);
				errorexit();
			}
			goto eof;
		}
		x = expandpkg(name, pkg);
		s = lookup(x, r);
		if(x != name)
			free(x);

		if(sig != 0){
			if(s->sig != 0 && s->sig != sig)
				diag("incompatible type signatures %ux(%s) and %ux(%s) for %s", s->sig, s->file, sig, pn, s->name);
			s->sig = sig;
			s->file = pn;
		}

		if(debug['W'])
			print("	ANAME	%s\n", s->name);
		if(o < 0 || o >= nelem(h)) {
			fprint(2, "%s: mangled input file\n", pn);
			errorexit();
		}
		h[o] = s;
		if((v == D_EXTERN || v == D_STATIC) && s->type == 0)
			s->type = SXREF;
		if(v == D_FILE) {
			if(s->type != SFILE) {
				histgen++;
				s->type = SFILE;
				s->value = histgen;
			}
			if(histfrogp < MAXHIST) {
				histfrog[histfrogp] = s;
				histfrogp++;
			} else
				collapsefrog(s);
		}
		goto loop;
	}

	p = mal(sizeof(Prog));
	p->as = o;
	p->scond = BGETC(f);
	p->reg = BGETC(f);
	p->line = Bget4(f);

	zaddr(f, &p->from, h);
	zaddr(f, &p->to, h);

	if(p->as != ATEXT && p->as != AGLOBL && p->reg > NREG)
		diag("register out of range %A %d", p->as, p->reg);

	p->link = P;
	p->cond = P;

	if(debug['W'])
		print("%P\n", p);

	switch(o) {
	case AHISTORY:
		if(p->to.offset == -1) {
			addlib(src, pn);
			histfrogp = 0;
			goto loop;
		}
		if(src[0] == '\0')
			copyhistfrog(src, sizeof src);
		addhist(p->line, D_FILE);		/* 'z' */
		if(p->to.offset)
			addhist(p->to.offset, D_FILE1);	/* 'Z' */
		histfrogp = 0;
		goto loop;

	case AEND:
		histtoauto();
		if(cursym != nil && cursym->text)
			cursym->autom = curauto;
		curauto = 0;
		cursym = nil;
		if(Boffset(f) == eof)
			return;
		goto newloop;

	case AGLOBL:
		s = p->from.sym;
		if(s == S) {
			diag("GLOBL must have a name\n%P", p);
			errorexit();
		}
		if(s->type == 0 || s->type == SXREF) {
			s->type = SBSS;
			s->value = 0;
		}
		if(s->type != SBSS && s->type != SNOPTRBSS && !s->dupok) {
			diag("redefinition: %s\n%P", s->name, p);
			s->type = SBSS;
			s->value = 0;
		}
		if(p->to.offset > s->size)
			s->size = p->to.offset;
		if(p->reg & DUPOK)
			s->dupok = 1;
		if(p->reg & RODATA)
			s->type = SRODATA;
		else if(p->reg & NOPTR)
			s->type = SNOPTRBSS;
		break;

	case ADATA:
		// Assume that AGLOBL comes after ADATA.
		// If we've seen an AGLOBL that said this sym was DUPOK,
		// ignore any more ADATA we see, which must be
		// redefinitions.
		s = p->from.sym;
		if(s->dupok) {
//			if(debug['v'])
//				Bprint(&bso, "skipping %s in %s: dupok\n", s->name, pn);
			goto loop;
		}
		if(s->file == nil)
			s->file = pn;
		else if(s->file != pn) {
			diag("multiple initialization for %s: in both %s and %s", s->name, s->file, pn);
			errorexit();
		}
		savedata(s, p, pn);
		unmal(p, sizeof *p);
		break;

	case AGOK:
		diag("unknown opcode\n%P", p);
		p->pc = pc;
		pc++;
		break;

	case ATEXT:
		if(cursym != nil && cursym->text) {
			histtoauto();
			cursym->autom = curauto;
			curauto = 0;
		}
		s = p->from.sym;
		if(s == S) {
			diag("TEXT must have a name\n%P", p);
			errorexit();
		}
		cursym = s;
		if(s->type != 0 && s->type != SXREF && (p->reg & DUPOK)) {
			skip = 1;
			goto casedef;
		}
		if(ntext++ == 0 && s->type != 0 && s->type != SXREF) {
			/* redefinition, so file has probably been seen before */
			if(debug['v'])
				Bprint(&bso, "skipping: %s: redefinition: %s", pn, s->name);
			return;
		}
		skip = 0;
		if(s->type != 0 && s->type != SXREF)
			diag("redefinition: %s\n%P", s->name, p);
		if(etextp)
			etextp->next = s;
		else
			textp = s;
		etextp = s;
		p->align = 4;
		autosize = (p->to.offset+3L) & ~3L;
		p->to.offset = autosize;
		autosize += 4;
		s->type = STEXT;
		s->text = p;
		s->value = pc;
		lastp = p;
		p->pc = pc;
		pc++;
		break;

	case ASUB:
		if(p->from.type == D_CONST)
		if(p->from.name == D_NONE)
		if(p->from.offset < 0) {
			p->from.offset = -p->from.offset;
			p->as = AADD;
		}
		goto casedef;

	case AADD:
		if(p->from.type == D_CONST)
		if(p->from.name == D_NONE)
		if(p->from.offset < 0) {
			p->from.offset = -p->from.offset;
			p->as = ASUB;
		}
		goto casedef;

	case AMOVWD:
	case AMOVWF:
	case AMOVDW:
	case AMOVFW:
	case AMOVFD:
	case AMOVDF:
	// case AMOVF:
	// case AMOVD:
	case ACMPF:
	case ACMPD:
	case AADDF:
	case AADDD:
	case ASUBF:
	case ASUBD:
	case AMULF:
	case AMULD:
	case ADIVF:
	case ADIVD:
		goto casedef;

	case AMOVF:
		if(skip)
			goto casedef;

		if(p->from.type == D_FCONST && chipfloat(&p->from.ieee) < 0 &&
		   (chipzero(&p->from.ieee) < 0 || (p->scond & C_SCOND) != C_SCOND_NONE)) {
			/* size sb 9 max */
			sprint(literal, "$%ux", ieeedtof(&p->from.ieee));
			s = lookup(literal, 0);
			if(s->type == 0) {
				s->type = SBSS;
				adduint32(s, ieeedtof(&p->from.ieee));
				s->reachable = 0;
			}
			p->from.type = D_OREG;
			p->from.sym = s;
			p->from.name = D_EXTERN;
			p->from.offset = 0;
		}
		goto casedef;

	case AMOVD:
		if(skip)
			goto casedef;

		if(p->from.type == D_FCONST && chipfloat(&p->from.ieee) < 0 &&
		   (chipzero(&p->from.ieee) < 0 || (p->scond & C_SCOND) != C_SCOND_NONE)) {
			/* size sb 18 max */
			sprint(literal, "$%ux.%ux",
				p->from.ieee.l, p->from.ieee.h);
			s = lookup(literal, 0);
			if(s->type == 0) {
				s->type = SBSS;
				adduint32(s, p->from.ieee.l);
				adduint32(s, p->from.ieee.h);
				s->reachable = 0;
			}
			p->from.type = D_OREG;
			p->from.sym = s;
			p->from.name = D_EXTERN;
			p->from.offset = 0;
		}
		goto casedef;

	default:
	casedef:
		if(skip)
			nopout(p);
		p->pc = pc;
		pc++;
		if(p->to.type == D_BRANCH)
			p->to.offset += ipc;
		if(lastp == nil) {
			if(p->as != ANOP)
				diag("unexpected instruction: %P", p);
			break;
		}
		lastp->link = p;
		lastp = p;
		break;
	}
	goto loop;

eof:
	diag("truncated object file: %s", pn);
}
Exemple #9
0
int
main (int argc, char *argv[])
{

  double t1, t2, t3, t4, t5, t6, t7;	/*timers */

  MPI_Init (&argc, &argv);
  MPI_Comm_rank (MPI_COMM_WORLD, &ThisTask);
  MPI_Comm_size (MPI_COMM_WORLD, &NTask);

  t1 = MPI_Wtime ();

  initvars ();

  check_params (argc, argv);

  splitdomain ();		/*select mesh size for domain decomposition based on NTask, produce spx,spy,spz */

  read_header ();		/*read file header and set file format */

  MPI_Barrier (MPI_COMM_WORLD);

  read_part ();			/*read particles, allocate each task >> locind, locbuffer, NumThis */

  selectposition ();		/*set cell position this task > ithis,jthis,kthis */

  setbordersize ();		/*set border lenght bsize */

  MPI_Barrier (MPI_COMM_WORLD);
  t2 = MPI_Wtime ();

  /*Transfer temporary boundary particles in the 6 directions */
  selectborder (0);/*-x*/
  selectborder (1);		/*+x */
  selectborder (2);/*-y*/
  selectborder (3);		/*+y */
  selectborder (4);/*-z*/
  selectborder (5);		/*+z */

  MPI_Barrier (MPI_COMM_WORLD);

  t3 = MPI_Wtime ();
  printf ("Task=%d NumThis=%d NumThis_boundary=%d\n", ThisTask, NumThis,
	  NumThisb);

  if (NumThisb > NumThis) printf ("%s",warning2);

  /*run vt */
#ifndef LOWMEMORY
  runvt ();
#else
  if ((ThisTask % 2) == 0)
    runvt ();			/*run half jobs first to save some memory, slower */
  MPI_Barrier (MPI_COMM_WORLD);
  if ((ThisTask % 2) == 1)
    runvt ();
#endif
  t4 = MPI_Wtime ();

  computeneig ();		/* Neighbors computation */
#ifdef VERBOSE
  if (ThisTask == 0)
    printf ("Neighbors complete.\n");
#endif
  computedens ();		/* Density computation */
#ifdef VERBOSE
  if (ThisTask == 0)
    printf ("Density and Volume complete.\n");
#endif

#ifdef COMPUTEGRAD
 computegrad ();   	        /*VT gradient computation*/
  if (ThisTask == 0)
    printf ("Gradient complete.\n");
#endif
  t5 = MPI_Wtime ();
  MPI_Barrier (MPI_COMM_WORLD);
  t6 = MPI_Wtime ();


#ifdef WRITEDENSITY
  writedensopen ();
  if (ThisTask == 0)
    printf ("write density...");
  savedata (0);			/*gather and save density */
  if (ThisTask == 0)
    printf ("volumes...");
  savedata (1);			/*gather and save volumes */
#endif

#ifdef COMPUTEGRAD
  if (ThisTask == 0)
    printf ("gradient...");
  savedata (3);                 /*gather and save gradient x */
  savedata (4);
  savedata (5);
#endif

#ifdef WRITEDENSITY
  writedensclose ();
#endif

#ifdef WRITENEIGHBORS
  if (ThisTask == 0)
    printf ("neighbors...\n");
  writeneigopen ();
  savedata (2);			/*gather and save neighbors */
  writeneigclose ();
#else
  printf ("\n");
#endif

#ifdef COMPUTEGRID
  if (checkgrid ())
    {
      writegridopen ();
      computegrid ();
      writegridclose ();
    }
#endif
  t7 = MPI_Wtime ();
  MPI_Barrier (MPI_COMM_WORLD);
  if (ThisTask == 0)
    printf
      ("Time Stats: Read=%.2f Bdry=%.2f Comp=%.2f Write=%.2f Tot-I/O=%.2F Tot=%.2f\n",
       t2 - t1, t3 - t2, t6 - t3, t7 - t6, t6 - t2, t7 - t1);
#ifdef VERBOSE
  MPI_Barrier (MPI_COMM_WORLD);
  printf ("Task=%d Time VT_only=%.2f\n", ThisTask, t4 - t3);
  MPI_Barrier (MPI_COMM_WORLD);
#endif
  finalize ();			/*free memory and finalize code */
  return 0;
}				/* End Main */
static int Mouse(filter_t *p_filter, vlc_mouse_t *p_mouse, const vlc_mouse_t *p_old, const vlc_mouse_t *p_new)
{
    static bool mousemov;
    static bool hasPressed;
    static bool isLeftreleased;
    static bool isLeftPressed;

    p_filter->p_sys->point_x = p_new->i_x * p_filter->p_sys->f_scale;
    p_filter->p_sys->point_y = p_new->i_y * p_filter->p_sys->f_scale;
    hasPressed = vlc_mouse_HasPressed(p_old, p_new, MOUSE_BUTTON_LEFT);
    isLeftPressed = vlc_mouse_IsLeftPressed(p_new);
    mousemov = vlc_mouse_HasMoved(p_old, p_new);
    isLeftreleased = vlc_mouse_HasReleased(p_old, p_new, MOUSE_BUTTON_LEFT);


    if (isLeftPressed)
    {
        p_filter->p_sys->x_new = p_filter->p_sys->point_x;
        p_filter->p_sys->y_new = p_filter->p_sys->point_y;
    }
    if (hasPressed)
    {
        if (p_filter->p_sys->start == 0)
        {
            p_filter->p_sys->para = p_filter->p_sys->input_parameters->debugParam.thresh4;
            p_filter->p_sys->start = 1;
            p_filter->p_sys->radius_video = p_filter->p_sys->radius_video_temp-1;

            savedata(p_filter);
        }

        p_filter->p_sys->click = 1;

        p_filter->p_sys->x_old = p_filter->p_sys->point_x;
        p_filter->p_sys->y_old = p_filter->p_sys->point_y;
        p_filter->p_sys->Var_on_click_zoom = 1;
    }
    else if (mousemov)
    {
        p_filter->p_sys->mov = 1;
    }
    else if (isLeftreleased)
    {
        p_filter->p_sys->x_new = 0;
        p_filter->p_sys->y_new = 0;
        p_filter->p_sys->x_old = 0;
        p_filter->p_sys->y_old = 0;
        p_filter->p_sys->mov = 0;
        p_filter->p_sys->click = 0;
        p_filter->p_sys->Var_on_click_zoom = 0;

    }

    if (p_filter->p_sys->click == 1 && p_filter->p_sys->mov == 1)
    {
        p_filter->p_sys->x_new = p_filter->p_sys->point_x;
        p_filter->p_sys->y_new = p_filter->p_sys->point_y;
    }

    return VLC_SUCCESS;
}
ChineseCalendar::ChineseCalendar(QWidget *parent)
    : QWidget(parent)
{
    setupUi(this); m_strFileList.clear();
//    bg = new QPixmap(":/img/chinesecalendarBGyellow.png");
    icon = QIcon(":/img/icon.png");
    icon64 = QIcon(":/img/chinesecalendar-64.png");

    mycalendat=new CCBO;
    mycalendat->InitConnection(QDir::currentPath ());
    selectedDate = QDate::currentDate();
	monthCombo->setCurrentIndex(selectedDate.month() - 1);
    YearSelect->setCurrentIndex(selectedDate.year()-1900);

    connect(monthCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setMonth(int)));
    connect(monthCombo, SIGNAL(activated(int)), this, SLOT(setMonth(int)));
    connect(YearSelect, SIGNAL(currentIndexChanged(int)), this, SLOT(setYear(int)));
    connect(this->backtotoday, SIGNAL(clicked()), this, SLOT(backtoday()));

//    this->TbnextMonth->setStyleSheet("QPushButton{background-color:transparent;color:rgb(200,200,150);}QPushButton:hover{color:rgb(255,255,255);}");
//    this->TbnextYear->setStyleSheet("QPushButton{background-color:transparent;color:rgb(200,200,150);}QPushButton:hover{color:rgb(255,255,255);}");
//    this->TbpreviousMonth->setStyleSheet("QPushButton{background-color:transparent;color:rgb(200,200,150);}QPushButton:hover{color:rgb(255,255,255);}");
//    this->TbpreviousYear->setStyleSheet("QPushButton{background-color:transparent;color:rgb(200,200,150);}QPushButton:hover{color:rgb(255,255,255);}");
//    this->backtotoday->setStyleSheet("QPushButton{background-color:transparent;color:rgb(200,200,150);}QPushButton:hover{color:rgb(255,255,255);}");
//    this->YearSelect->setStyleSheet("QComboBox{border: 2px solid lightgray;border-radius: 5px;font:12pt;}");
//    this->monthCombo->setStyleSheet("QComboBox{border: 2px solid lightgray;border-radius: 5px;font:12pt;}");
//    this->label->setStyleSheet("QLabel{font:12pt;}");
//    this->label_2->setStyleSheet("QLabel{font:12pt;}");

    QString week;
    QDateTime dateTime = QDateTime::currentDateTime();

    if (dateTime.toString("ddd") == "Mon")
        week = "星期一"; // Monday
    else if (dateTime.toString("ddd") == "Tue")
        week = "星期二"; // Tuesday
    else if (dateTime.toString("ddd") == "Wed")
        week = "星期三"; // Wednesday
    else if (dateTime.toString("ddd") == "Thu")
        week = "星期四"; // Thursday
    else if(dateTime.toString("ddd") == "Fri")
        week = "星期五"; // Friday
    else if (dateTime.toString("ddd") == "Sat")
        week = "星期六"; // Saturday
    else
        week = "星期日"; // Sunday

    QString currentTime = dateTime.toString("yyyy-MM-dd %1").arg(week);
    QDate day = QDate::currentDate();
    struct CCalendar datebase;
    mycalendat->ctcl_solar_to_lunar(day.year(),day.month(),day.day(),&datebase);
    QString chinesemonth = datebase.cmonth;

    if (chinesemonth == "一月")
        chinesemonth = "正月";
    if (chinesemonth == "十一月")
        chinesemonth = "冬月";
    if (chinesemonth == "十二月")
        chinesemonth = "腊月";

    QString chineseday = QString("农历 %1%2").arg(chinesemonth).arg(datebase.cday);
    QString chineseyear = QString("%1年(%2年)").arg(datebase.ganzhi).arg(datebase.shengxiao);

    QString chineseyi = QString("%1").arg(datebase.yi);
    QStringList chineseyilist = chineseyi.split("、");
    QString chineseji = QString("%2").arg(datebase.ji);
    QStringList chinesejilist = chineseji.split("、");

    QFont font;
    QPalette pa;
    font.setPointSize(48);
    font.setBold(true);
    this->label_10->setFont(font);
    this->label_10->setText(QString::number(day.day()));
    font.setBold(false);
    font.setPointSize(9);
    this->label_12->setFont(font);
    this->label_12->setText(currentTime);
    font.setPointSize(10);
    this->label_13->setFont(font);
    this->label_13->setText(chineseday);
    this->label_14->setFont(font);
    this->label_14->setText(chineseyear);
    font.setPointSize(15);
    this->label_15->setFont(font);
    font.setPointSize(10);
    this->label_17->setFont(font);
    this->label_18->setFont(font);

    QString yi=QString("");
    QString ji=QString("");
    if(chineseyilist.count() == 0 )
       yi =QString("");
    if(chineseyilist.count() >= 5)
       yi = QString("").append(chineseyilist.at(0)).append("\n").append(chineseyilist.at(1)).append("\n").append(chineseyilist.at(2)).append("\n").append(chineseyilist.at(3)).append("\n").append(chineseyilist.at(4));
    if(chineseyilist.count() == 4)
       yi = QString("").append(chineseyilist.at(0)).append("\n").append(chineseyilist.at(1)).append("\n").append(chineseyilist.at(2)).append("\n").append(chineseyilist.at(3));
    if (chineseyilist.count() == 3)
       yi = QString("").append(chineseyilist.at(0)).append("\n").append(chineseyilist.at(1)).append("\n").append(chineseyilist.at(2));
    if (chineseyilist.count() == 2)
       yi = QString("").append(chineseyilist.at(0)).append("\n").append(chineseyilist.at(1));
    if (chineseyilist.count() == 1)
       yi = QString("").append(chineseyilist.at(0)).append("\n");
    this->label_17->setText(yi);

    if(chinesejilist.count() == 0 )
       ji =QString("");
    if(chinesejilist.count() >= 5)
       ji = QString("").append(chinesejilist.at(0)).append("\n").append(chinesejilist.at(1)).append("\n").append(chinesejilist.at(2)).append("\n").append(chinesejilist.at(3)).append("\n").append(chinesejilist.at(4));
    if(chinesejilist.count() == 4)
       ji = QString("").append(chinesejilist.at(0)).append("\n").append(chinesejilist.at(1)).append("\n").append(chinesejilist.at(2)).append("\n").append(chinesejilist.at(3));
    if (chinesejilist.count() == 3)
       ji = QString("").append(chinesejilist.at(0)).append("\n").append(chinesejilist.at(1)).append("\n").append(chinesejilist.at(2));
    if (chinesejilist.count() == 2)
       ji = QString("").append(chinesejilist.at(0)).append("\n").append(chinesejilist.at(1));
    if (chinesejilist.count() == 1)
       ji = QString("").append(chinesejilist.at(0)).append("\n");
    this->label_18->setText(ji);

    QString cnote=mycalendat->ctcl_displaydata(day.year(),day.month(),day.day());
    QString haveplan=QString("今日有行程安排");
    QString noplan=QString("今日无行程安排");
    int num = cnote.count();
    while (num > 0 && cnote.at(num-1).isSpace())
    {
        num--;
    }

    if(cnote.isEmpty() || num == 0)
        this->label_19->setText(noplan);
    else
        this->label_19->setText(haveplan);

    pa.setColor(QPalette::WindowText,Qt::white);
    this->label->setPalette(pa);
    this->label_2->setPalette(pa);
    this->label_15->setPalette(pa);
    this->label_4->setPalette(pa);
    this->label_5->setPalette(pa);
    this->label_6->setPalette(pa);
    this->label_7->setPalette(pa);
    this->label_8->setPalette(pa);

    pa.setColor(QPalette::WindowText,QColor(255,255,255));
    this->label_3->setPalette(pa);
    this->label_9->setPalette(pa); 

    pa.setColor(QPalette::WindowText,Qt::black);
    this->label_18->setPalette(pa);

    pa.setColor(QPalette::WindowText,QColor(235,74,20));
    this->label_10->setPalette(pa);
    this->label_12->setPalette(pa);
    this->label_13->setPalette(pa);
    this->label_14->setPalette(pa);

    pa.setColor(QPalette::WindowText,Qt::white);
    this->label_19->setPalette(pa);

    pa.setColor(QPalette::WindowText,Qt::red);
    this->label_11->setPalette(pa);
    this->label_17->setPalette(pa);

    map = new QMap<QString, DateItem *>();

    for (int i = 1; i <= 6; i++)
    {
        for (int j = 1; j <= 7; j++)
        {
            DateItem *dateitem = new DateItem(this);
            if (i <= 5)
            {
                dateitem->show();
            }
            else
            {
                dateitem->hide();
            }

            map->insert(QString("%1-%2").arg(i).arg(j), dateitem);

            if ((i < 6) || (i == 6 && (j == 1 || j == 2)))
            {
                connect(dateitem, SIGNAL(clicked(QString)), this, SLOT(resetcalendardate(QString)));
                connect(dateitem, SIGNAL(day(QString)), this, SLOT(setclickday(QString)));
                connect(dateitem, SIGNAL(resetColor()), this, SLOT(resetDateItemColor()));
            }
        }
    }

    setItemLayout();
    setCalendar();

    QTimer *timer = new QTimer(this);
    timer->setInterval(1000);
    connect(timer,SIGNAL(timeout()),this,SLOT(setTime()));
    timer->start();

    QBitmap objBitmap(size());
    QPainter painter(&objBitmap);
    painter.fillRect(rect(),Qt::white);
    painter.setBrush(QColor(0,0,0));
    painter.drawRoundedRect(this->rect(),10,10);
    setMask(objBitmap);

    aboutDlg = new AboutDialog();
    aboutDlg->hide();

    this->createTray();

    note = new Cnote;
    QDesktopWidget desktop;
    int width = desktop.screenGeometry().width();
    note->setGeometry(QRect(width-400,80,224,280));
    connect(note,SIGNAL(save(QString)),this,SLOT(savedata(QString)));
    note->hide();
}
Exemple #12
0
void wx::mbwxsave (char *taskname)
//*************************************************************************
// this task reads wx-data from serial line, saves it in intervals
// of 5min and puts current + recent (-1h) wx-data into global
// variable.
//*************************************************************************
{
  char name[20];
  strcpy(name, "wx:mbwxsave");
  time_t nextsavet = ad_time();
  int fd;
  char rawdata[80];
  long total_num = 0; // total number of measurements
  long comerr = 0; // total number of communication errors
  char lastcmd_s[50];
  int orgok;

  lastcmd("init");
  // configure tty device
  fd = configure_tty(m.wxtty);
  if (fd < 0)
    return;
  trace(replog, name, "WX logging started");
  // initialize wx-structure
  memset(&m.wx, 0, sizeof(m.wx));
  m.wx.data_valid = 0;
  // wait for data
  while (! runterfahren)
  {
    rawdata[0]=0;
    do
    {
      wdelay(50);
      while (! read_tty(fd, rawdata+strlen(rawdata), 79-strlen(rawdata)))
      {
        wdelay(50);
        // if no data received for >1min, old data is no longer valid
        if (m.wx.data_valid && ad_time()-m.wx.t > 600)
        {
          m.wx.data_valid = 0;
          lastcmd("no data");
          trace(report, name, "no data received");
        }
      }
      if (m.wxstnname[0] == '_')  //simple hack to get debug output
        trace(report, "wx", "rawdata: \"%s\"", rawdata);
      //correct string starts with !!...
      if (strlen(rawdata) > 2 && rawdata[0] != '!')
      {
        char *a = strstr(rawdata, "!!");
        if (a)
          memmove(rawdata, a, strlen(a)+1);
        else
        {
          rawdata[0]=0;
          comerr++;
        }
      }
    }
    // wait until line is complete (or buffer full)
    while(strlen(rawdata) < 70 && ! strstr(rawdata, "\n") &&
                                  ! strstr(rawdata, "\r"));
    rm_crlf(rawdata);
    //calculate data, and if correct test if data should be saved
    orgok = orgdata(&m.wx, rawdata);
    if (orgok)
      comerr++;
    else
      total_num++;
    sprintf(lastcmd_s, "data %ld/%ld", total_num, comerr);
    lastcmd(lastcmd_s);
    if (orgok && nextsavet <= m.wx.t)
    {
      if (nextsavet < ad_time())
        nextsavet = ad_time(); // if time is changed
      nextsavet += 300; //next time to save data is in 5min
      savedata(rawdata, &m.wx);
    }
  }
  close_tty(fd);
}
Exemple #13
0
	void init() {

#pragma region init
		hge = hgeCreate(HGE_VERSION);
		// Load settings
		Settings::load(TEXT("config.txt"));
		bool b_windowed = true;
		hge->System_SetState(HGE_LOGFILE, "resources/game.log");
		hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
		hge->System_SetState(HGE_RENDERFUNC, RenderFunc);
		hge->System_SetState(HGE_TITLE, "Project 3: basic animation and map loading");
		hge->System_SetState(HGE_WINDOWED, b_windowed);
		hge->System_SetState(HGE_SCREENBPP, 32);
		hge->System_SetState(HGE_FPS, 60);

		assert(hge->System_Initiate());
			//throw GCN_EXCEPTION("Unable to initialize HGE: " + std::tstring(hge->System_GetErrorMessage()));

		gui = new GUI();
		gui->registerWindow(hge->System_GetState(HGE_HWND), hge, b_windowed);
		// Load savedata
		myPlayer = new Player();
		std::ifstream savedata("resources/savedata.txt");
		if (savedata.is_open()) {
			char yolo[100];
			char *yololine = yolo;
			savedata.getline(yololine, 100);
			float x, y;
			x = strtof(yololine, &yololine);
			y = strtof(yololine, &yololine);
			myPlayer->SetXPosition(x);
			myPlayer->SetYPosition(y);
			myPlayer->setFriction(0.6f);
			myPlayer->setAcceleration(200);
			savedata.close();
		}
		else {
			perror("load savedata messed up!");
		}
#pragma endregion init


		std::cout << "Loading Map \"desert\"\n";
// 		world["desert"] = new TileMap("map1.tmx");
// 		world["little"] = new TileMap("map2.tmx");
// 		world["desert"]->Load();

		myPlayer->setZone(TEXT("desert"));


		hPortal = hge->Texture_Load("resources/gems.png");
		portalSprite = new hgeSprite(hPortal, 0, 31, 32, 32);
		portal = new Trigger_Portal(0);



// 		camera = new Camera();
// 		camera->SetXPosition(myPlayer->GetXPosition());
// 		camera->SetYPosition(myPlayer->GetYPosition());
// 		camera->SetDisplayLocation(0, 0);
// 		camera->SetDisplaySize_1(800, 600);
// 		camera->SetTarget(myPlayer);
// 		camera->Enter(world["desert"]);
// 		camera->SetWorld(world);
// 		camera->SetZone("desert");

		/*
		if (tileset->GetTiles().size() > 0) {
			// Get a tile from the tileset.
			const Tmx::Tile *tile = *(tileset->GetTiles().begin());

			// Print the properties of a tile.
			std::map< std::tstring, std::tstring > list = tile->GetProperties().GetList();
			std::map< std::tstring, std::tstring >::iterator iter;
			for (iter = list.begin(); iter != list.end(); ++iter) {
				printf("%s = %s\n", iter->first.c_str(), iter->second.c_str());
			}
		}
		*/
		//hge->System_SetState(HGE_FRAMEFUNC, MenuFrameFunc);
		//hge->System_SetState(HGE_RENDERFUNC, MenuRenderFunc);

		// Set up the quad we will use for background animation
		quad.blend = BLEND_ALPHABLEND | BLEND_COLORMUL | BLEND_NOZWRITE;

		for (int i = 0; i<4; i++)
		{
			// Set up z-coordinate of vertices
			quad.v[i].z = 0.5f;
			// Set up color. The format of DWORD col is 0xAARRGGBB
			quad.v[i].col = 0xFFFFFFFF;
		}

		quad.v[0].x = 0; quad.v[0].y = 0;
		quad.v[1].x = 800; quad.v[1].y = 0;
		quad.v[2].x = 800; quad.v[2].y = 600;
		quad.v[3].x = 0; quad.v[3].y = 600;

		quad.tex = hge->Texture_Load("resources/bg.png");
		hMouseTexture = hge->Texture_Load("resources/cursor.png");
		snd = hge->Effect_Load("resources/menu.wav");
		fnt = new hgeFont("resources/font1.fnt");
		fnt->SetColor(0xFF000000);

		mouseSprite = new hgeSprite(hMouseTexture, 0, 0, 32, 32);
		
		anitex = hge->Texture_Load("resources/aninew.png");
		ani = new hgeAnimation(anitex, 6, 6, 0, 0, 38, 46);
		ani->SetHotSpot(16, 16);
		ani->Play();

		myPlayer->setAnimation(ani);
	}
Exemple #14
0
/*----------------------------------------------------------------------------*/
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	switch(Msg)
	{
	case WM_INITDIALOG:
		{
			initport(hWndDlg, Msg, wParam, lParam);
			showdate(hWndDlg);
			return FALSE; // setfocus by ourself
		}
		break;	// WM_INITDIALOG
	case WM_COMMAND: // Windows Controls processing
		{
			switch(LOWORD(wParam)) // This switch identifies the control
			{
			case IDC_CB_PORTS:
				cbport(hWndDlg, Msg, wParam, lParam);
				break; // case IDC_CB_PORTS
			case IDC_CB_BAUDRATE:
				cbbaudrate(hWndDlg, Msg, wParam, lParam);
				break; // case IDC_CB_BAUDRATE
			case IDC_CB_DATABITS:
				cbdatabits(hWndDlg, Msg, wParam, lParam);
				break; // case IDC_CB_DATABITS
			case IDC_CB_PARITY:
				cbparity(hWndDlg, Msg, wParam, lParam);
				break; // case IDC_CB_PARITY
			case IDC_CB_STOPBITS:
				cbstopbits(hWndDlg, Msg, wParam, lParam);
				break; // case IDC_CB_STOPBITS
			case IDC_CB_FLOWCONTROL:
				cbflowcontrol(hWndDlg, Msg, wParam, lParam);
				break; // case IDC_CB_FLOWCONTROL
			case IDC_EDT_NUMBER:
				timerinterval(hWndDlg);
				break; // case IDC_EDT_NUMBER
			case IDC_BTN_OPEN:
				btnopen(hWndDlg);
				break; // case IDC_BTN_OPEN
			case IDC_BTN_CLOSE:
				btnclose(hWndDlg);
				break; // case IDC_BTN_CLOSE
			case IDC_BTN_CLEARSENT:
				btnclearsent(hWndDlg);
				break; // case IDC_BTN_CLEARSENT
			case IDC_BTN_CLEARMSENT:
				btnclearmsent();
				break; // case IDC_BTN_CLEARMSENT
			case IDC_BTN_CLEARRECEIVED:
				btnclearreceived();
				break; // case IDC_BTN_CLEARRECEIVED
			case IDC_BTN_RESET:
				btnreset(hWndDlg, Msg, wParam, lParam);
				break; // case IDC_BTN_RESET
			case IDC_BTN_EXIT:
				btnexit(hWndDlg);
				break; // case IDC_BTN_EXIT
			case IDM_SAVE:
				savedata();
				break; // IDM_SAVE
			case IDM_EXIT:
				btnexit(hWndDlg);
				break; // IDM_EXIT
			case IDM_ABOUT:
				MessageBox(NULL, TEXT("Author: thanh nguyen \n Email: [email protected]"), TEXT("About"), MB_OK); 
				break; // IDM_ABOUT
				
			case IDCANCEL:
				btnexit(hWndDlg);
				break;
			default: 
				return FALSE;
				break;
			}
		}
		break; // WM_COMMAND
	case WM_TIMER:
		switch (wParam) 
		{ 
		case ID_UPDATE_TIMER: 
            infloop(hWndDlg); 
			showdate(hWndDlg);
			break; // ID_UPDATE_TIMER
		case ID_TIMER:
		default:
			showdate(hWndDlg);
			break; // default
		} 
		break; // WM_TIMER
	case WM_CLOSE:
		btnexit(hWndDlg);
		break; // case WM_CLOSE:

	default:
		return FALSE;
		break; // default
	}

	return TRUE;
}
void NetGuard_Special_Limit::loaddata()
{
	struct	user_data * u_data;

	#ifdef userlist_use_simple
	struct	user_list * m_users = muser_data->get_list();
	while (m_users != NULL) {
		u_data = m_users->data;
	#else
	ip_storage_hash::iterator it;
	for (it=muser_data->get_list()->begin(); it != muser_data->get_list()->end(); it++) {
		u_data =  (*it).second;
	#endif
		struct user_special_accounting_data *accouning_data = (struct user_special_accounting_data *)u_data->module_data[user_special_limit_module_number];
		if (accouning_data) {
			user_shutdown(u_data);
		}
		user_init(u_data);
		#ifdef userlist_use_simple
		m_users = m_users->next;
		#endif
	}
}

void NetGuard_Special_Limit::savedata()
{
	struct	user_data * u_data;

	FILE *myfile;

	ng_logdebug_spam("saving users to %s",db_filename.c_str());

	myfile = fopen(db_filename.c_str(), "w+");
	if (!myfile) return;

	fwrite(ACC_SPECIAL_LIMIT_VERSION_MAGIC,strlen(ACC_SPECIAL_LIMIT_VERSION_MAGIC),1,myfile);

	struct user_special_limit_data * limit_data;

	int counter = 0;
	#ifdef userlist_use_simple
	struct	user_list * m_users = muser_data->get_list();
	while (m_users != NULL) {
		u_data = m_users->data;
	#else
	ip_storage_hash::iterator it;
	for (it=muser_data->get_list()->begin(); it != muser_data->get_list()->end(); it++) {
		u_data =  (*it).second;
	#endif
		limit_data = (struct user_special_limit_data *)u_data->module_data[user_special_limit_module_number];
		if	(limit_data) {
			counter++;
		}
		#ifdef userlist_use_simple
		m_users = m_users->next;
		#endif
	}
	//write number of users
	fwrite(&counter ,sizeof(counter),1, myfile);

	#ifdef userlist_use_simple
	m_users = muser_data->get_list();
	while (m_users != NULL) {
		u_data = m_users->data;
	#else
	for (it=muser_data->get_list()->begin(); it != muser_data->get_list()->end(); it++) {
		u_data =  (*it).second;
	#endif
		limit_data = (struct user_special_limit_data *)u_data->module_data[user_special_limit_module_number];
		if	(limit_data) {
			fwrite(&u_data->saddr ,sizeof(u_data->saddr),1, myfile);
		} else {
			ng_logerror("skipping user %-15s on saving - no data present",inet_ntoa(*(struct in_addr *)&u_data->saddr));
		}
		#ifdef userlist_use_simple
		m_users = m_users->next;
		#endif
	}

	#ifdef userlist_use_simple
	m_users = muser_data->get_list();
	while (m_users != NULL) {
		u_data = m_users->data;
	#else
	for (it=muser_data->get_list()->begin(); it != muser_data->get_list()->end(); it++) {
		u_data =  (*it).second;
	#endif
		limit_data = (struct user_special_limit_data *)u_data->module_data[user_special_limit_module_number];
		if	(limit_data) {
			fwrite(limit_data,sizeof(struct user_special_limit_data),1, myfile);
			ng_logdebug_spam("save user %-15s max %lld",inet_ntoa(*(struct in_addr *)&u_data->saddr),limit_data->limit);
		}
		#ifdef userlist_use_simple
		m_users = m_users->next;
		#endif
	}
	ng_logdebug_spam("saved %d users",counter);

	fwrite(ACC_SPECIAL_LIMIT_VERSION_MAGIC,strlen(ACC_SPECIAL_LIMIT_VERSION_MAGIC),1,myfile);
	fclose(myfile);
}

struct user_special_limit_data * NetGuard_Special_Limit::load_limit_data(struct user_data *u_data, char *filename, int rename_onfail){
	FILE *myfile;
	struct stat fileinfo;
	char *tmpdata;
	struct user_special_limit_data * limit_data = NULL;
	int i;
	off_t f_pos;

	ng_logdebug_spam("loading data from %s",db_filename.c_str());

	if (stat(db_filename.c_str(),&fileinfo)) {
		ng_logerror("cant stat data file %s",db_filename.c_str());
		return NULL;
	}
	myfile = fopen(db_filename.c_str(), "r");
	if (!myfile) {
		ng_logerror("cant open data file %s",db_filename.c_str());
		return NULL;
	}
	
	//check file version
	tmpdata = (char *)malloc(sizeof(unsigned char)*(strlen(ACC_SPECIAL_LIMIT_VERSION_MAGIC)+1));
	tmpdata[strlen(ACC_SPECIAL_LIMIT_VERSION_MAGIC)] = 0;
	int count = fread(&tmpdata[0],strlen(ACC_SPECIAL_LIMIT_VERSION_MAGIC),1,myfile);
	if ((count != 1) || strcmp(tmpdata,ACC_SPECIAL_LIMIT_VERSION_MAGIC) ) {
		ng_logerror("limit: cant read traffic data from %s - illegal format (%s <> %s)",db_filename.c_str(),(char *)tmpdata,ACC_SPECIAL_LIMIT_VERSION_MAGIC);

		if (rename_onfail)
		{
			free(tmpdata);
			tmpdata = (char *)malloc(sizeof(unsigned char)*(strlen(db_filename.c_str())+20));
			time_t now;
			time(&now);		/* get the current time */
			sprintf(tmpdata,"%s_%d",db_filename.c_str(),(int)now);
			ng_log("renaming file to %s",tmpdata);
			rename(db_filename.c_str(),tmpdata);
		}
		return NULL;
	}

	f_pos = ftell(myfile);
	fseek(myfile,fileinfo.st_size-strlen(ACC_SPECIAL_LIMIT_VERSION_MAGIC),SEEK_SET);
	count = fread(&tmpdata[0],strlen(ACC_SPECIAL_LIMIT_VERSION_MAGIC),1,myfile);
	if ((count != 1) || strcmp(tmpdata,ACC_SPECIAL_LIMIT_VERSION_MAGIC) ) {
		ng_logerror("cant read traffic data from %s - illegal (end) format (%s <> %s)",db_filename.c_str(),(char *)tmpdata,ACC_SPECIAL_LIMIT_VERSION_MAGIC);

		if (rename_onfail)
		{
			free(tmpdata);
			tmpdata = (char *)malloc(sizeof(unsigned char)*(strlen(db_filename.c_str())+20));
			time_t now;
			time(&now);		/* get the current time */
			sprintf(tmpdata,"%s_%d",db_filename.c_str(),(int)now);
			ng_log("renaming file to %s",tmpdata);
			rename(db_filename.c_str(),tmpdata);
		}
		return NULL;
	}
	//set to old position again
	fseek(myfile,f_pos,SEEK_SET);

	ng_logdebug_spam("loading %lu bytes data",fileinfo.st_size);

	int counter = 0;
	count = fread(&counter,sizeof(counter),1, myfile);
	if (count  != 1 ) return NULL;
	ng_logdebug_spam("found %d users in file",counter);

	u_int32_t saddr;
	int found = 0;
	unsigned int seek_pos = 0;
	for (i=1; i<=counter ; i++ )
	{
		count = fread(&saddr ,sizeof(saddr),1, myfile);
		if (count  != 1 ) return NULL;
		if (saddr == u_data->saddr)
		{
			found = 1;
			seek_pos = i;
			ng_logdebug_spam("found user %-15s on pos %d",inet_ntoa(*(struct in_addr *)&u_data->saddr),seek_pos);
		}
	}

	if (!found) return NULL;
	seek_pos = (seek_pos-1) * sizeof(struct user_special_limit_data) + ftell(myfile);
	fseek(myfile,seek_pos,SEEK_SET);


	limit_data = (struct user_special_limit_data *)malloc(sizeof(struct user_special_limit_data));
	count = fread(limit_data,sizeof(struct user_special_limit_data),1, myfile);
	if (count  != 1 ) {
		delete limit_data;
		return NULL;
	}
	ng_logdebug_spam("loaded user data for %-15s (max: %lld) ",inet_ntoa(*(struct in_addr *)&u_data->saddr),limit_data->limit);

	fclose(myfile);
	free(tmpdata);

	return limit_data;
}

int NetGuard_Special_Limit::init(NetGuard_Config *data)
{
	general_acccounting = NULL;
	muser_data = NULL;

	ng_logdebug_spam("init");
	if (!data) return -1;
	int ret = NetGuard_Module::init(data); //important to get needed links
	if (ret) return ret;

	if (data_->GetStr("user_special_limit_filename") == "")
	{
		ng_logerror("need a user_special_limit_filename in config data");
		return -2;
	}
	db_filename=data_->GetStr("user_special_limit_filename");

	if (data_->GetModule("module_general_accounting") == NULL) {
		ng_logerror("need general_accounting module needs to be loaded");
		return -2;
	}


	//filter for accountable traffic
	if (data_->GetStr("accounting_filter_own") == "")
	{
		ng_logerror("need an accounting_filter_own in config data");
		return -2;
	}
	std::string filter_name_own=data_->GetStr("accounting_filter_own");

	filter_own = NetGuard_Global_IP_Filter::Filter(filter_name_own);
	if (filter_own == NULL)
	{
		ng_logerror("filter passed with accounting_filter_own (%s) does not exists",filter_name_own.c_str());
		return -2;
	}
	ng_logdebug_spam("using filter (%s) for filtering accounting ips",filter_own->GetPrefixName().c_str());

	//filter for internal traffic
	if (data_->GetStr("accounting_filter_intern") == "")
	{
		ng_logerror("need an accounting_filter_intern in config data");
		return -2;
	}
	std::string filter_name_intern=data_->GetStr("accounting_filter_intern");

	filter_intern = NetGuard_Global_IP_Filter::Filter(filter_name_intern);
	if (filter_intern == NULL)
	{
		ng_logerror("filter passed with accounting_filter_intern (%s) does not exists",filter_name_intern.c_str());
		return -2;
	}
	ng_logdebug_spam("using filter (%s) for filtering internal traffic",filter_intern->GetPrefixName().c_str());


	if (data_->GetInt("default_limit") != MININT)
	{
		default_limit = data_->GetInt("default_limit");
		default_limit = default_limit*1024*1024;
		ng_logdebug("set default_limit to %llu",default_limit);
	}

	if (data_->GetInt("default_max_limit") != MININT)
	{
		default_max_limit = data_->GetInt("default_max_limit");
		default_max_limit = default_max_limit*1024*1024;
		ng_logdebug("set default_max_limit to %llu",default_max_limit);
	}

	if (data_->GetInt("default_daily_addition") != MININT)
	{
		default_daily_addition = data_->GetInt("default_daily_addition");
		default_daily_addition = default_daily_addition*1024*1024;
		ng_logdebug("set default_daily_addition to %llu",default_daily_addition);
	}

	general_acccounting = (NetGuard_General_Module*)data_->GetModule("module_general_accounting");
	muser_data = (User_Data_Tools*)general_acccounting->get_data(NULL);

	my_dis_state = NetGuard_State_Handler::get_state(GlobalCFG::GetStr("user_special_limit.disable_state","disabled"));
	if (!my_dis_state) {
		ng_logerror("%s state %s unkown",__FUNCTION__,GlobalCFG::GetStr("user_special_limit.disable_state","disabled").c_str());
		return -2;
	}

	my_fail_state = NetGuard_State_Handler::get_state(GlobalCFG::GetStr("user_special_limit.failure_state","failure"));
	if (!my_fail_state) {
		ng_logerror("%s state %s unkown",__FUNCTION__,GlobalCFG::GetStr("user_special_limit.failure_state","failure").c_str());
		return -2;
	}

	my_enabled_state = NetGuard_State_Handler::get_state(GlobalCFG::GetStr("user_special_limit.enabled_state","enabled"));
	if (!my_enabled_state) {
		ng_logerror("%s state %s unkown",__FUNCTION__,GlobalCFG::GetStr("user_special_limit.enabled_state","enabled").c_str());
		return -2;
	}

	loaddata();

	return 0;
}

void NetGuard_Special_Limit::shutdown()
{
	ng_logdebug_spam("shutdown");
	if (muser_data)
	{
		struct	user_data *u_data;
		#ifdef userlist_use_simple
		struct	user_list *m_users = muser_data->get_list();
		while (m_users != NULL) {
			u_data = m_users->data;
		#else
		ip_storage_hash::iterator it;
		for (it=muser_data->get_list()->begin(); it != muser_data->get_list()->end(); it++) {
			u_data =  (*it).second;
		#endif
			user_shutdown(u_data);
			#ifdef userlist_use_simple
			m_users = m_users->next;
			#endif
		}
	}

	general_acccounting = NULL;
	muser_data = NULL;
}

struct user_special_limit_data *NetGuard_Special_Limit::my_user_init(struct user_data *u_data, bool doload)
{
	struct user_special_limit_data * limit_data = NULL;
	
	//try to load it from file
	if (doload)
		limit_data = load_limit_data(u_data,NULL,1);

	if (limit_data == NULL)
	{
		ng_logdebug("setting new default special limits for %-15s",inet_ntoa(*(struct in_addr *)&u_data->saddr));
		//we need to init a new user
		//we need to init a new user
		limit_data = (struct user_special_limit_data *)malloc(sizeof(struct user_special_limit_data));

		//set default values
		memset(limit_data,0,sizeof(struct user_special_limit_data));
		limit_data->limit = (long long int)default_limit;
		limit_data->daily_addition = (unsigned long long int)default_daily_addition;
		limit_data->max_limit = (unsigned long long int)default_max_limit;
		u_data->external.bytes = limit_data->limit;
	};

	u_data->module_data[user_special_limit_module_number] = limit_data;

	return limit_data;	
}

void NetGuard_Special_Limit::user_init(struct user_data *u_data)
{
	if (!u_data) return;
	ng_logdebug_spam("user_init for %-15s",inet_ntoa(*(struct in_addr *)&u_data->saddr));
	my_user_init(u_data,true);
}

void NetGuard_Special_Limit::user_shutdown(struct user_data *u_data)
{
	struct user_special_limit_data * limit_data = (struct user_special_limit_data *)u_data->module_data[user_special_limit_module_number];
	if ( limit_data != NULL ) {		
		ng_logdebug_spam("free limits data for %-15s",inet_ntoa(*(struct in_addr *)&u_data->saddr));
		delete limit_data;
	}
	u_data->module_data[user_special_limit_module_number] = NULL;
}


void NetGuard_Special_Limit::do_user_data_forgetday(int day, struct user_data *u_data){

	struct user_special_limit_data *limit_data = (struct user_special_limit_data *)u_data->module_data[user_special_limit_module_number];
	long long int temp = u_data->external.bytes;

	if ( limit_data == NULL ) {
		limit_data = my_user_init(u_data,true);
	}

	if((u_data->external.bytes + limit_data->daily_addition) > limit_data->max_limit)
		 u_data->external.bytes = limit_data->max_limit;
	else
		 u_data->external.bytes += limit_data->daily_addition;

	NetGuard_User_State* nu_state = NetGuard_State_Handler::user_state(u_data);

	if (*nu_state == my_enabled_state) return;
	if (*nu_state == my_fail_state) return;

	if(temp == 0){
		if (!nu_state->set(my_enabled_state,GlobalCFG::GetStr("user_special_limit.enable_new_traffic","automatic enabling with new traffic"))) {
			ng_logerror("%s - %s - %d - ip: %s vlan: %d - could not do the state transition from %s to %s",__FUNCTION__,__FILE__,__LINE__,inet_ntoa(*(struct in_addr *)&nu_state->Getuser().saddr),nu_state->Getuser().vlan_id,nu_state->state()->GetName().c_str(),my_dis_state->GetName().c_str());
			return;
		}
	}
}

void NetGuard_Special_Limit::user_data_forgetday(int day)
{
	struct	user_data *u_data;

	#ifdef userlist_use_simple
	struct	user_list *m_users = muser_data->get_list();
	while (m_users != NULL) {
		u_data = m_users->data;
	#else
	ip_storage_hash::iterator it;
	for (it=muser_data->get_list()->begin(); it != muser_data->get_list()->end(); it++) {
		u_data =  (*it).second;
	#endif

		//forget this day for external traffic
		do_user_data_forgetday(day,u_data);

		#ifdef userlist_use_simple
		m_users = m_users->next;
		#endif
	}
}

void NetGuard_Special_Limit::checkmax(struct user_special_limit_data * limit_data,struct user_data *u_data) {

	if(limit_data->limit > 0)
	{
		if(u_data->external.bytes <= 0)
		{
			// we have somebody over the internal over all limit
			NetGuard_User_State* nu_state = NetGuard_State_Handler::user_state(u_data);

			//ignore if we are already in the same state
			if (*nu_state == my_dis_state) return;
			if (*nu_state == my_fail_state) return;

			//nu_state->params()->SetInt("external_limit_exceeded",nu_state->params()->GetInt("external_limit_exceeded",0)+1);
			if (!nu_state->set(my_dis_state,GlobalCFG::GetStr("user_limit.disable_int_state_overall_msg","user have no traffic left"))) {
				ng_logerror("%s - %s - %d - ip: %s vlan: %d - could not do the state transition from %s to %s",__FUNCTION__,__FILE__,__LINE__,inet_ntoa(*(struct in_addr *)&nu_state->Getuser().saddr),nu_state->Getuser().vlan_id,nu_state->state()->GetName().c_str(),my_dis_state->GetName().c_str());
				return;
			}
		}
	}
}

void NetGuard_Special_Limit::packet_in(struct user_data *u_data, int *mode, unsigned int *vlanid, struct tpacket_hdr *h, struct ether_header *eth, struct iphdr *ip, struct tcphdr *tcp, void *data)
{
	in_addr_t *index_addr;
	in_addr_t *index_addr2;
	index_addr = 0;
	index_addr2 = 0;

	//we are only interested in packages that are linked to a user already	
	if (!u_data) return;

	struct user_special_limit_data *limit_data = (struct user_special_limit_data *)u_data->module_data[user_special_limit_module_number];
	if ( limit_data == NULL ) {
		limit_data = my_user_init(u_data,true);
	}

	if (eth->ether_type == htons_ETHERTYPE_IP) {
		hl_saddr = ntohl(ip->saddr);
		hl_daddr = ntohl(ip->daddr);
		if ((*filter_own)==&hl_saddr) index_addr = &ip->saddr;
		if ((*filter_own)==&hl_daddr) index_addr2 = &ip->daddr;
	} else if (eth->ether_type == htons_ETHERTYPE_ARP) {
		struct ether_arp * arph;
		//#if __GNUC__ >= 4
		arph = (struct ether_arp *)ip;
		//#else
		//(void *)arph = (void *)ip;
		//#endif		
		hl_saddr = ntohl(*(uint32_t *)&arph->arp_spa);
		hl_daddr = ntohl(*(uint32_t *)&arph->arp_tpa);
		if ((*filter_own)==&hl_saddr) index_addr = (uint32_t *)&arph->arp_spa;
		if ((*filter_own)==&hl_daddr) index_addr2 = (uint32_t *)&arph->arp_tpa;
	}

	

	struct user_data_traffic *traffic_type;
	
	//set if internal or external traffic
	//default is internal for all non ip protocols


	if (eth->ether_type == htons_ETHERTYPE_IP) {
		//on ip its external per default
		traffic_type = &u_data->external;

		//if it match the filters its internal -> return
		if ((*filter_intern) == &hl_daddr && (*filter_intern)==&hl_saddr) return;
	}else
		return;

	signed long long int tmpval;
	tmpval = traffic_type->bytes;

	if((tmpval - h->tp_len) >= 0)
		traffic_type->bytes = traffic_type->bytes - h->tp_len;
	else 
		traffic_type->bytes = 0;

	checkmax(limit_data,u_data);
}

void NetGuard_Special_Limit::got_input(std::vector<std::string> params, std::vector<int> intparams, std::string command)
{
	if (params[0] == "help")
	{
		ng_logout("save - save limit data");
		ng_logout("dumpip <ip> <vlan> - show details for an ip");
		ng_logout("dumpip_all <ip> <vlan> - show details for an ip");
		ng_logout("set_limit <ip> <vlan> <start limit MB> <daily add MB> <maximum MB> - set limit data for an ip");
		//TODO: ng_logout("set_limit_reset <ip> <vlan> - set limit data for an ip to default"); 
		ng_logout("set_current_traffic <ip> <vlan> <traffic MB> - set the current traffic volume for an ip");
	}

	if (params[0] == "version")
	{
		ng_logext(100,"%s - Version: %s build: %s from %s at %s with %s",NetGuard_NAME, NetGuard_VERSION,NetGuard_COMPILE_DATE,NetGuard_COMPILE_BY,NetGuard_COMPILE_HOST,NetGuard_COMPILER);
	}

	if (params[0] == "save")
	{
		savedata();
	}

	if ((params[0] == "dumpip") ||  (params[0] == "dumpip_all"))
	{
		if (params.size() != 3)
		{
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan>",params[0].c_str());
			return;
		}
		struct in_addr m_ip;
		if (!inet_aton(params[1].c_str(),&m_ip ))
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan>",params[0].c_str());
			return;
		}
		if (intparams[2]==MININT)
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan>",params[0].c_str());
			return;
		}

		unsigned int tmpvlanid = intparams[2];
		struct user_data *u_data = muser_data->get_user(&m_ip.s_addr,&tmpvlanid);
		if (!u_data) 
		{
			ng_logout_not_found("could not find user with ip: %s vlan: %d",inet_ntoa(*(struct in_addr *)&m_ip.s_addr),intparams[2]);
			return;
		}
		

		#define EINHEIT 1024/1024
		struct user_special_limit_data *limit_data = (struct user_special_limit_data *)u_data->module_data[user_special_limit_module_number];
		if ( limit_data == NULL ) {
			limit_data = my_user_init(u_data,true);
		}

		ng_logout("start limit \t\t: %llu MByte",limit_data->limit/EINHEIT);
		ng_logout("daily addition \t\t: %llu MByte",limit_data->daily_addition/EINHEIT);
		ng_logout("max limit \t\t: %llu MByte",limit_data->max_limit/EINHEIT);

		ng_logout("current usage \t\t: %llu MByte",u_data->external.bytes/EINHEIT);
	}

	if ((params[0] == "set_limit"))
	{
		if (params.size() != 6)
		{
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <start limit MB> <daily add MB> <maximum MB>",params[0].c_str());
			return;
		}
		struct in_addr m_ip;
		if (!inet_aton(params[1].c_str(),&m_ip ))
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <start limit MB> <daily add MB> <maximum MB>",params[0].c_str());
			return;
		}
		if (intparams[2]==MININT)
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <start limit MB> <daily add MB> <maximum MB>",params[0].c_str());
			return;
		}

		if (intparams[3]==MININT)
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <start limit MB> <daily add MB> <maximum MB>",params[0].c_str());
			return;
		}

		if (intparams[4]==MININT)
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <start limit MB> <daily add MB> <maximum MB>",params[0].c_str());
			return;
		}

		if (intparams[5]==MININT)
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <start limit MB> <daily add MB> <maximum MB>",params[0].c_str());
			return;
		}

		unsigned int tmpvlanid = intparams[2];
		struct user_data *u_data = muser_data->get_user(&m_ip.s_addr,&tmpvlanid);
		if (!u_data) 
		{
			ng_logout_not_found("could not find user with ip: %s vlan: %d",inet_ntoa(*(struct in_addr *)&m_ip.s_addr),intparams[2]);
			return;
		}

		struct user_special_limit_data *special_limit_data = (struct user_special_limit_data *)u_data->module_data[user_special_limit_module_number];
		if ( special_limit_data == NULL ) {
			special_limit_data = my_user_init(u_data,true);
		}

		#define EINHEIT2 1024*1024

		unsigned long long int tmpval,tmpval2,tmpval3;
		tmpval = (unsigned long long int)intparams[3] * (unsigned long long int)EINHEIT2;
		tmpval2 = (unsigned long long int)intparams[4] * (unsigned long long int)EINHEIT2;
		tmpval3 = (unsigned long long int)intparams[5] * (unsigned long long int)EINHEIT2;

		ng_logout_ok("setting new special limit data");
		special_limit_data->limit = tmpval;
		special_limit_data->daily_addition = tmpval2;
		special_limit_data->max_limit = tmpval3;

	}

	if ((params[0] == "set_current_traffic"))
	{
		if (params.size() != 4)
		{
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <traffic MB>",params[0].c_str());
			return;
		}
		struct in_addr m_ip;
		if (!inet_aton(params[1].c_str(),&m_ip ))
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <traffic MB>",params[0].c_str());
			return;
		}
		if (intparams[2]==MININT)
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <traffic MB>",params[0].c_str());
			return;
		}

		if (intparams[3]==MININT)
		{	
			ng_logout_ret(RET_WRONG_SYNTAX,"usage: %s <ip> <vlan> <traffic MB>",params[0].c_str());
			return;
		}

		unsigned int tmpvlanid = intparams[2];
		struct user_data *u_data = muser_data->get_user(&m_ip.s_addr,&tmpvlanid);
		if (!u_data) 
		{
			ng_logout_not_found("could not find user with ip: %s vlan: %d",inet_ntoa(*(struct in_addr *)&m_ip.s_addr),intparams[2]);
			return;
		}

		#define EINHEIT 1024/1024
		#define EINHEIT2 1024*1024

		unsigned long long int tmpval;

		tmpval = (unsigned long long int)intparams[3] * (unsigned long long int)EINHEIT2;

		u_data->external.bytes = tmpval;
		ng_logout_ok("new traffic successfully set to: %llu MB",u_data->external.bytes/EINHEIT);
	}
}

void NetGuard_Special_Limit::timer_tick() {
}