static bool ItemDroppedOnBeggar(P_CLIENT ps, PKGx08 *pp, P_ITEM pi)
{
	UOXSOCKET s=ps->GetSocket();
	CHARACTER cc=ps->GetCurrChar();
	P_CHAR pc_currchar = MAKE_CHARREF_LRV(cc,false);
	int t=calcCharFromSer(pp->Tserial);
	if(pi->id()!=0x0EED)
	{
		sprintf((char*)temp,"Sorry %s i can only use gold",pc_currchar->name);
		npctalk(s,t,(char*)temp,0);
		return false;
	}
	sprintf((char*)temp,"Thank you %s for the %i gold!",pc_currchar->name,pi->amount);
	npctalk(s,t,(char*)temp,0);
	if(pi->amount<=100)
	{
		pc_currchar->karma += 10;
		sysmessage(s,"You have gain a little karma!");
	}
	else
	{
		pc_currchar->karma += 50;
		sysmessage(s,"You have gain some karma!");
	}
		Items->DeleItem(pi);
	    return true;
}
void cCommands::RegSpawnNum (int s, int r, int n) // rewrite by LB
{
	int i, spawn=0;
	unsigned int currenttime=uiCurrentTime;
	char *temps;

	r++;
	if (r<=0 || r>=255) return;

	temps = new char[100];

		spawn = (spawnregion[r].max-spawnregion[r].current);
		if (n > spawn) 
		{		
			sprintf(temps, "%d too many for region %d, spawning %d to reach MAX:%d instead.",n, r-1, spawn, spawnregion[r].max);
			sysmessage(s, temps);
			n=spawn;
		}		
		sprintf(temps, "Region %d is Spawning: %d NPCs/items, this will cause some lag.", r-1, spawn);
		sysbroadcast(temps);

		for(i=1;i<spawn;i++)
		{
			doregionspawn(r);
		}//for	
	
		spawnregion[r].nexttime=currenttime+(MY_CLOCKS_PER_SEC*60*RandomNum(spawnregion[r].mintime,spawnregion[r].maxtime));

		sprintf(temps, "Done. %d total NPCs/items spawned in Spawnregion %d.",spawn,r-1);
		sysmessage(s, temps);	
	    if (temps!=NULL) delete [] temps; // fixing memory leak, LB

}//regspawnnum
// guildtoggleabbreviation() Toggles the settings for showing or not showing the guild title
// Informs player about his change
void cGuildStone::ToggleAbbreviation(UOXSOCKET s)
{
	P_CHAR pc = currchar[s];

	if (!isMember(pc)) 
	{
		sysmessage(s, "you are not a guild member");
		return;
	}

	if (this->guildType != cGuildStone::standard)		// Check for Order/Chaos
	{
		sysmessage(s, "You are in an Order/Chaos guild, you cannot toggle your title.");
	}
	else
	{
		if (!pc->guildtoggle())									// If set to Off then
		{
			pc->setGuildtoggle(true);									// Turn it On
			sysmessage(s, "You toggled your abbreviation on.");	// Tell player about the change
		}
		else													// Otherwise
		{
			pc->setGuildtoggle(false);					// Turn if Off
			sysmessage(s, "You toggled your abbreviation off.");	// And tell him also
		}
	}
	this->Menu(s, 1);										// Send him back to the menu
	return;
}
// OKAY (but take another look)
// guildresign() : Player gets removed from the guilddatabase, and gets a message.
// Offcourse guilddatabase gets checked for members left, if everyone is gone, then vanish
// the guildstone. After Guildmaster resigns, the fealty of each remaining member calculates
// a new guildmaster, if there is a draw then we'll have no master until they change their minds ;)
void GuildResign(int s)
{

	P_CHAR pc = currchar[s];

	cGuildStone* pStone = dynamic_cast<cGuildStone*>(FindItemBySerial(pc->guildstone()));

	if (pStone == NULL)
	{
		sysmessage(s, "You are in no guild");
		return;
	}

	pStone->removeMember( currchar[s] );
	sysmessage(s,"You are no longer in that guild.");
	if ((pStone->ownserial == pc->serial) && (!pStone->member.empty()))
	{
		pStone->SetOwnSerial(INVALID_SERIAL);
		pStone->CalcMaster();
	}
	if (pStone->member.empty())
	{
		Items->DeleItem( pStone );
		sysmessage(s,"You have been the last member of that guild so the stone vanishes.");
	}
	return;
}
int
comport_command(int command, int arg)
{
    int size;
    int ret;
    unsigned char *obp;

    if (Nvt.comport->support == FALSE) {
	CLR_CMD_ACTIVE(command);	/* Synchronous operation */
	SET_EVENT(EV_RN, EV_RNCMDOK, 0, 0);
	return (0);
    }

    obp = &Comobuf[0];

    *obp++ = IAC;
    *obp++ = SB;
    *obp++ = NVT_COM_PORT_OPTION;
    *obp++ = (unsigned char) command;
    switch (command) {
    case USR_COM_SET_BAUDRATE:
	SET_VALUE_4(obp, arg);
	obp += 4;
	break;
    default:
	SET_VALUE_1(obp, arg);
	obp += 1;
	break;
    }
    *obp++ = IAC;
    *obp++ = SE;

    size = (int) (obp - &Comobuf[0]);
    obp = &Comobuf[0];

    if (Debug > 2) {
	sysmessage(MSG_DEBUG,
		   "Sock_write, %d bytes: %02X %02X %02X %02X %02X %02X %02X %02X\n",
		   size, Comobuf[0], Comobuf[1], Comobuf[2], Comobuf[3],
		   Comobuf[4], Comobuf[5], Comobuf[6], Comobuf[7]);
    }
    while (size) {
	if ((ret = sock_write(obp, size)) == -1) {
	    SET_EVENT(EV_RN, EV_RNHANG, 0, 0);
	    return (-1);
	}
	else if (ret != size) {
	    sysmessage(MSG_NOTICE,
		       "Partial write in send_comport: %d/%d\n", ret, size);
	    sysdelay(ROOM_DELAY);	/* Wait for room */
	}
	size -= ret;
	obp += ret;
    }
    return (0);
}
int
dev_getdata(void)
{

    struct buffer *bp = Pty.inbuff;
    int retc;
    int size;
    unsigned char type;

    size = Pty.iosize;

    if (Hold == TRUE) {
	Hold = FALSE;
	retc = 1;
	Databuf[0] = Holdbuf[0];
    }
    else {
	if ((retc = read(P_mfd, Databuf, size)) == -1) {
	    if (errno == EAGAIN) {
		retc = 0;
	    }
	    else {
		sysmessage(MSG_ERR,
			   "Can't read from master pty: %s\n",
			   strerror(errno));
# ifdef TSR_MEASURE
		devnreads++;
# endif
		return (retc);
	    }
	}
    }

    if (Debug > 2) {
	sysmessage(MSG_DEBUG, " DATA: %d bytes: ", retc);
    }
    if (Debug > 2) {
	int i;
	char debbuf[128];
	char oct[8];

	sprintf(debbuf, "DAT: ");
	for (i = 0; i < retc && i < 8; i++) {
	    sprintf(oct, "%02X ", (unsigned char) Databuf[i]);
	    strcat(debbuf, oct);
	}
	sysmessage(MSG_DEBUG, "%s\n", debbuf);
    }

    type = Databuf[0];

    parse_message(type, Databuf, retc);

    return (0);
}
void
parse_message(unsigned char type, char *buf, int size)
{
    char *msgt;
    int i;
    struct iocblk *iocp;
    struct buffer *bp = Pty.inbuff;


    print_msg(type, (unsigned char *) buf, size);

    if (size > 0) {
	switch (Pty.state) {
	case PTY_CLOSED:
	case PTY_OPERRONLY:
	    SET_EVENT(EV_UP, EV_UPOPEN, 0, 0);
	    break;
	}
    }
    else if (size == -1) {
	sysmessage(MSG_WARNING, "PARSE: Message data size == -1 \n");
	return;
    }

    switch (type) {
    case M_DATA:
# ifdef TSR_MEASURE
	devreads++;
	devrbytes += size;
# endif
	if (size == 0) {
	    SET_EVENT(EV_UP, EV_UPCLOSE, 0, 0);
	}
	else {
	    COPY_TO_BUFFER(bp, buf, size);
	    SET_EVENT(EV_UP, EV_UPDATA, 0, 0);
	}
	break;

    case M_IOCTL:
	iocp = (struct iocblk *) &buf[0];
	parse_ioctl(iocp->ioc_cmd, (void *) &buf[sizeof(struct iocblk)]);
	break;

    case M_FLUSH:
	parse_msgflush((int) buf[0]);
	break;

    default:
	sysmessage(MSG_DEBUG, "Unsupported stream message: %d\n", type);
	print_msg(type, (unsigned char *) buf, size);
	break;
    }
}
int
dev_config(void)
{
    int sfd;
    struct termios tios;
    struct portconfig *pcp = &Pty.comport->portconfig;
    int modes = Pty.portmodes;
    int mode;

    if (Debug > 1) {
	sysmessage(MSG_DEBUG, "Opening %s pseudo-tty \n", P_sname);
    }
    sysmessage(MSG_NOTICE, "Opening %s pseudo-tty\n", P_sname);
    if ((sfd = open(P_sname, O_RDWR | O_NOCTTY)) == -1) {
	sysmessage(MSG_ERR, "Can't open slave device : %s\n",
		   strerror(errno));
	return (E_FILEIO);
    }

    memset((void *) &tios, 0, sizeof(struct termios));

    portconfig_to_termios(pcp, &tios);

    tios.c_cflag |= CREAD;
    tios.c_lflag |= NOFLSH;

/* PTY modes */
    if (modes & PORT_HUPCL) {
	tios.c_cflag |= HUPCL;
    }

    if (modes & PORT_CLOCAL) {
	tios.c_cflag |= CLOCAL;
    }

    if (modes & PORT_IGNBRK) {
	tios.c_iflag |= IGNBRK;
    }

    if (modes & PORT_IGNPAR) {
	tios.c_iflag |= IGNPAR;
    }

    if (tcsetattr(sfd, TCSANOW, &tios) == -1) {
	sysmessage(MSG_ERR, "Can't set termios : %s\n", strerror(errno));
	(void) close(sfd);
	return (E_FILEIO);
    }

    P_sfd = sfd;

    return (E_NORMAL);
}
// guildtitlechange(character, text) copies the text info the characters title field (guildnumber
// gets calculated from the double clicked guildstones), changed character was buffered in the guilds
// private field (as backup buffer) and notifies editing player about the change.
void cGuildStone::ChangeTitle(UOXSOCKET s, char *text)
{
	P_CHAR member = FindCharBySerial(this->priv);

	if (member == NULL) member = currchar[s];
	this->priv = INVALID_SERIAL;
	member->setGuildtitle( text );
	if (member == currchar[s]) 
		sysmessage(s,"You changed your own title.");
	else 
		sysmessage(s,"You changed the title.");
	Menu(s,2);
}
int
dev_closeslave(void)
{
    if (Pty.state == PTY_OPER && P_sfd != -1) {
	if (Debug > 1) {
	    sysmessage(MSG_DEBUG, "Closing %s pseudo-tty \n", P_sname);
	}
	sysmessage(MSG_NOTICE, "Closing %s pseudo-tty \n", P_sname);
	(void) close(P_sfd);
	P_sfd = -1;
    }

    return (E_NORMAL);
}
void cCommands::RegSpawnMax (int s, int r) // rewrite LB
{
	int i, spawn;
	unsigned int currenttime=uiCurrentTime;
	char *temps;

	r++;
	if (r<=0 || r>=255) return;

	temps = new char[100];

	spawn = (spawnregion[r].max-spawnregion[r].current);

	sprintf(temps, "Region %d is Spawning %d items/NPCs, this will cause some lag.", r-1, spawn);
	sysbroadcast(temps);

	for(i=1;i<spawn;i++)
	{
		doregionspawn(r);

	}	
	
	spawnregion[r].nexttime=currenttime+(MY_CLOCKS_PER_SEC*60*RandomNum(spawnregion[r].mintime,spawnregion[r].maxtime));	
	sprintf(temps, "Done. %d total NPCs/items spawned in Spawnregion %d.",spawn,r-1);
	sysmessage(s, temps);

	if (temps!=NULL) delete [] temps;
}
void
termios_to_portconfig(struct termios *tp, struct portconfig *pcp)
{

/* Speed */
    speed_t speed = cfgetospeed(tp);
    pcp->speed = baud_index_to_int(speed);

    if (pcp->speed == -1) {
	sysmessage(MSG_DEBUG, "Unsupported speed: %d\n", speed);
	pcp->speed = 115200;
    }

/* Datasize */
    switch (tp->c_cflag & CSIZE) {
    case CS5:
	pcp->datasize = 5;
	break;
    case CS6:
	pcp->datasize = 6;
	break;
    case CS7:
	pcp->datasize = 7;
	break;
    case CS8:
    default:
	pcp->datasize = 8;
	break;
    }

/* Stopsize */
    if (tp->c_cflag & CSTOPB) {
	pcp->stopsize = COM_SSIZE_TWO;
    }
    else {
	pcp->stopsize = COM_SSIZE_ONE;
    }

/* Parity */
    if (tp->c_cflag & PARENB) {
	if (tp->c_cflag & PARODD) {
	    pcp->parity = COM_PARITY_ODD;
	}
	else {
	    pcp->parity = COM_PARITY_EVEN;
	}
    }
    else {
	pcp->parity = COM_PARITY_NONE;
    }

/* Flow Control */
    if (tp->c_iflag & IXON) {
	pcp->flowc = COM_FLOW_SOFT;
    }
    else {			/* Warning, assumes hardware flow control */
	pcp->flowc = COM_FLOW_HARD;
    }
}
int
get_slave_controlling(dev_t device)
{
    struct nlist nl[2];
    struct tty dummy;
    short procid;
    static int fd = -1;
    static off_t offset = 0;

    if (offset == 0) {
	if ((fd = open(MEM_NAME, O_RDONLY)) == -1) {
	    sysmessage(MSG_WARNING, "Can't open %s : %s\n",
		       MEM_NAME, strerror(errno));
	    return (0);
	}

	nl[0].n_name = PTY_TABLE;
	nl[1].n_name = (char *) NULL;
	if (nlist(KERNEL_NAME, &nl[0]) == -1) {
	    sysmessage(MSG_WARNING, "Can't nlist %s : %s\n",
		       MEM_NAME, strerror(errno));
	    return (0);
	}
	offset = nl[0].n_value;
	if (offset != 0) {
	    offset += (off_t) (minor(device) * sizeof(dummy)) +
		(off_t) & dummy.t_pgrp - (off_t) & dummy;
	}
	else {
	    sysmessage(MSG_WARNING,
		       "Kernel symbol not found : %s\n", PTY_TABLE);
	    return (0);
	}
    }
    if (lseek(fd, offset, 0) == -1) {
	printf("%s %s: mem seek error\n");
	return (0);
    }

    if (read(fd, (char *) &procid, sizeof(short)) <= 0) {
	sysmessage(MSG_WARNING, "Can't open %s : %s\n",
		   MEM_NAME, strerror(errno));
	return (0);
    }
    return ((int) procid);
}
void
print_all(void)
{
    if (Debugbuf[0] != 0) {
	sysmessage(MSG_DEBUG, "%s\n", Debugbuf);
    }
    Debugbuf[0] = 0;
}
void
portconfig_to_termios(struct portconfig *pcp, struct termios *tp)
{

/* Speed */
    speed_t speed = int_to_baud_index(pcp->speed);
    if (speed == B0 && pcp->speed != 0) {
	sysmessage(MSG_DEBUG, "Unsupported speed: %d\n", pcp->speed);
	speed = B115200;
    }
    cfsetospeed(tp, (speed_t) speed);
    cfsetispeed(tp, (speed_t) B0);

/* Datasize */
    switch (pcp->datasize) {
    case 5:
	tp->c_cflag |= CS5;
	break;
    case 6:
	tp->c_cflag |= CS6;
	break;
    case 7:
	tp->c_cflag |= CS7;
	break;
    case 8:
	tp->c_cflag |= CS8;
	break;
    }

/* Stopsize */
    if (pcp->stopsize == COM_SSIZE_TWO) {
	tp->c_cflag |= CSTOPB;
    }				/* else one stop bit */

/* Parity */
    switch (pcp->parity) {
    case COM_PARITY_EVEN:
	tp->c_cflag |= PARENB;
	break;
    case COM_PARITY_ODD:
	tp->c_cflag |= PARENB | PARODD;
	break;
    case COM_PARITY_NONE:
    default:
	break;
    }

/* Flow Control */
    switch (pcp->flowc) {
    case COM_FLOW_SOFT:
	tp->c_iflag |= IXON;
	break;
    default:
	break;
    }

}
void cChar::disturbMed(UOXSOCKET s)
{
	if (this->med) //Meditation
	{
		this->med = false;
		if (s != -1)
			sysmessage(s, "You break your concentration.");
	}
}
bool PlayerVendorSpeech(cChar* pVendor, const QString& comm, cChar* pPlayer, UOXSOCKET s)
{

	if (!(pVendor->npcaitype == 17))
	     return 0;

	if (pPlayer->dist(pVendor) > 4)
		return 0;

	if (!VendorChkName(pVendor,comm))
		return false;

	//if (strstr(comm, " BROWSE") || strstr(comm, " VIEW") || strstr(comm, " LOOK"))
	if ((comm.contains(" BROWSE")) || (comm.contains(" VIEW")) || (comm.contains(" LOOK")))
	{
		npctalk(s,pVendor,"Take a look at my goods.",1);
		P_ITEM pi_backpack = Packitem(pVendor);
		if (pi_backpack != NULL)
		{
			backpack(s, pi_backpack->serial);
		    return true;
		}
	}
	//if (strstr(comm, " BUY") || strstr(comm, " PURCHASE"))
	if ((comm.contains(" BUY")) || (comm.contains(" PURCHASE")))
	{
		addx[s]=pVendor->serial;
		npctalk(s,pVendor,"What would you like to buy?",0);
		target(s,0,1,0,224," ");
		return true;
	}

	if (!pPlayer->Owns(pVendor))
			return 0;

	//if (strstr( comm, " COLLECT") || strstr( comm, " GOLD") || strstr( comm, " GET"))
	if ((comm.contains(" COLLECT")) || (comm.contains(" GOLD")) || (comm.contains(" GET")))
	{
		PlVGetgold(s, pVendor);
		return true;
	}
	//if (strstr( comm, "PACKUP"))
	if (comm.contains("PACKUP"))
	{
		P_ITEM pDeed = Items->SpawnItem(pPlayer, 1, "employment deed", 0, 0x14F0, 0, 1);
		if (pDeed)
		{
			pDeed->type = 217;
			pDeed->value = 2000;
			RefreshItem( pDeed );
			Npcs->DeleteChar( pVendor );
			sysmessage(s, "Packed up vendor %s.", pVendor->name.c_str());
			return true;
		}
	}
	return false;
}
void cFishing::FishTarget(P_CLIENT ps)
{
	// fixes an exploit with fishing, LB
	int px,py,cx,cy;
	UOXSOCKET s=ps->socket();
	P_CHAR pPlayer=ps->player();
	if (!pPlayer) return;

	px=((buffer[s][0x0b]<<8)+(buffer[s][0x0c]%256));
	py=((buffer[s][0x0d]<<8)+(buffer[s][0x0e]%256));
	cx=abs(pPlayer->pos.x-px);
	cy=abs(pPlayer->pos.y-py);
//	int cz=abs(pPlayer->z-buffer[s][0x10]);

	if(!(cx<=6 && cy<=6))
	{
		sysmessage(s, "You are too far away to reach that");
		return;
	}
	// end exploit fix

	bool ok=false;
	if (IsFishWater(ShortFromCharPtr(buffer[s]+0x11)))
		ok = true;
	else
	{	// it might be offshore fishing (client returns id=0 for deep sea ) Duke, Thx for the hint goes to Avanoon guys
		map_st map = Map->SeekMap(Coord_cl(px, py, pPlayer->pos.map));	// search the ground tile where they casted
		if ( map.id == 0x00A8 || map.id == 0x00A9 || map.id == 0x00AA || map.id == 0x00AB )
			ok = true;
	}
	if (ok)
	{
		action(s,0x0b);
		if (SrvParams->randomtime()!=0) pPlayer->setFishingtimer(rand()%SrvParams->randomtime()+SrvParams->basetime());
		else
		pPlayer->setFishingtimer(SrvParams->basetime());
		
		soundeffect(s, 0x02, 0x3F);
		pPlayer->unhide();
		Fish(pPlayer);
	}
	else
		sysmessage(s, "You need to be closer to the water to fish!");
}
int
dev_probe(void)
{
    int retc;
    int retmsg;
    int mode;
    unsigned char type;

    if ((retc = read(P_mfd, Holdbuf, 1)) == -1) {
	if (errno == EAGAIN) {
	    retc = 0;
	}
	else {
	    sysmessage(MSG_ERR,
		       "Can't read from master pty: %s\n", strerror(errno));
	    return (retc);
	}
    }

    if (Debug > 2) {
	sysmessage(MSG_DEBUG, "PROBE: %d bytes: %d", retc, Holdbuf[0]);
    }
    if (retc != 0) {
	type = Holdbuf[0];
	if (type == TIOCPKT_DATA) {
	    retmsg = PROBE_DATA;
	}
	else if (type & (TIOCPKT_FLUSHREAD | TIOCPKT_FLUSHWRITE)) {
	    retmsg = PROBE_FLUSH;
	}
	else {
	    retmsg = PROBE_GENERIC;
	}
	Hold = TRUE;
    }
    else {
	retmsg = PROBE_EOF;
    }
    if (Debug > 1) {
	sysmessage(MSG_DEBUG, "PROBE: msg %d\n", retmsg);
    }
    return (retmsg);
}
void cBoat::PlankStuff(UOXSOCKET s, P_ITEM pi_plank)//If the plank is opened, double click Will send them here
{
	P_CHAR pc_cs,pc_b;

	pc_cs = currchar[s];

	P_ITEM boat = GetBoat(pc_cs);
	if(boat == NULL)//They aren't on a boat, so put then on the plank.
	{
		// LB, bugfix for tillerman not reacting if the boat was entered via plank !

		// we need to get the boat again after beaming the character to the boat's plank
		// otherweise only -1's will be added to the boat hash-table 
        
		pc_cs->moveTo(pi_plank->pos + Coord_cl(0,0,5));

		pc_cs->multis=-3; // we have to trick getboat to start the search !!!
		                              // will be corrected automatically by setserial...

		P_ITEM boat2 = GetBoat(pc_cs);
		if (boat2 == NULL)
			return;

		unsigned int a;	
		vector<SERIAL> vecCown = cownsp.getData(pc_cs->serial);
		for(a = 0; a < vecCown.size(); a++)//Put all their Pets/Hirlings on the boat too
		{
			pc_b = FindCharBySerial(vecCown[a]);

			if (pc_b != NULL) // never log -1's that indicate non existance !!!
			{
			   if (pc_b->isNpc() && pc_cs->Owns(pc_b))
			   {
				  pc_b->moveTo(boat2->pos + Coord_cl(1, 1, 2));
                  pc_b->SetMultiSerial(boat2->serial);
				  teleport(pc_b);
			   }
			}
		}
	

        OpenPlank(pi_plank); //lb

		if (boat2 != NULL) // now set the char coords to the boat !!!
		{
			pc_cs->moveTo(boat2->pos + Coord_cl(1, 1, 2));
		}

		sysmessage(s,"you entered a boat");
        pc_cs->SetMultiSerial(boat2->serial);
	} else {
		LeaveBoat(s, pi_plank);//They are on a boat, get off
	}
	teleport(pc_cs);//Show them they moved.
}
void cCommands::KillSpawn(int s, int r)  //courtesy of Revana
{
	int killed=0;

	char temp[512];

	r++; // synch with 1-indexed real storage, casue 0 is no region indicator, LB

	if (r<=0 || r>=255) return;

	sysmessage(s,"Killing spawn, this may cause lag...");

	AllCharsIterator iter_char;
	for(iter_char.Begin(); iter_char.GetData() != NULL; iter_char++)
	{
		P_CHAR toCheck = iter_char.GetData();
		if(toCheck->spawnregion==r && !toCheck->free)
		{
			bolteffect(DEREF_P_CHAR(toCheck), true);
			soundeffect2(DEREF_P_CHAR(toCheck), 0x00, 0x29);
			Npcs->DeleteChar(DEREF_P_CHAR(toCheck));
            killed++;
		}
	}

	AllItemsIterator iter_item;
	for(iter_item.Begin(); iter_item.GetData() != NULL; iter_item++)
	{
		P_ITEM toCheck = iter_item.GetData();
		if(toCheck->spawnregion == r && !toCheck->free)
		{			
			iter_item--; // Iterator will became invalid when we delete it.
			Items->DeleItem(toCheck);
            killed++;
		}
	}

	gcollect();
	sysmessage(s, "Done.");
	sprintf(temp, "%i of Spawn %i have been killed.",killed,r-1);
	sysmessage(s, temp);
}
void cCommands::KillAll(int s, int percent, const char* sysmsg)
{
	sysmessage(s,"Killing all characters, this may cause some lag...");
	sysbroadcast(sysmsg);
	AllCharsIterator iter_char;
	for (iter_char.Begin(); iter_char.GetData() != NULL; iter_char++)
	{
		P_CHAR pc = iter_char.GetData();
		if(!pc->isGM())
		{
			if(rand()%100+1<=percent)
			{
				bolteffect(DEREF_P_CHAR(pc), true);
				soundeffect2(DEREF_P_CHAR(pc), 0x00, 0x29);
				deathstuff(DEREF_P_CHAR(pc));
			}
		}
	}
	sysmessage(s, "Done.");
}
void cSetPrivLvlTarget::responsed( UOXSOCKET socket, PKGx6C targetInfo )
{
	if( !isCharSerial( targetInfo.Tserial ) )
		return;

	P_CHAR pc = FindCharBySerial( targetInfo.Tserial );
	if( pc == NULL )
		return;

	pc->setPrivLvl( plevel_ );
	sysmessage( socket, QString("PrivLvl set to : %1").arg(plevel_) );
};
// TESTED: OKAY
// Uhm.. do i need char or socket for sysmessage? hehe.. a socket ofcourse, FiXED iT!
// guildbroadcast(guildnumber, text) broadcasts message to all online members of guild
void cGuildStone::Broadcast(char *text)
{
	unsigned int i;
	for (i = 0; i < member.size(); ++i)
	{
		P_CHAR pc = FindCharBySerial( member[i] );
		if ( pc == NULL )
			continue;
		if ( online( pc ) ) 
			sysmessage( calcSocketFromChar( pc ), text);
	}
}
//o---------------------------------------------------------------------------o
//|   Function -  void cpage(int s,char *reason)
//|   Date     -  UnKnown
//|   Programmer  -  UnKnown 
//o---------------------------------------------------------------------------o
//|   Purpose     -  
//o---------------------------------------------------------------------------o
void cCommands::CPage(int s, char *reason) // Help button (Calls Counselor Call Menus up)
{
	int i, a1, a2, a3, a4, x;
	int x2=0;

	P_CHAR pc_currchar = MAKE_CHARREF_LR(currchar[s]);
	
	x=0;
	a1=pc_currchar->ser1;
	a2=pc_currchar->ser2;
	a3=pc_currchar->ser3;
	a4=pc_currchar->ser4;
	
	for(i=1;i<MAXPAGES;i++)
	{
		if(counspages[i].handled==1)
		{
			counspages[i].handled=0;
			counspages[i].name = pc_currchar->name;
			counspages[i].reason = reason;
			counspages[i].serial = pc_currchar->serial;
			time_t current_time = time(0);
			struct tm *local = localtime(&current_time);
			sprintf(counspages[i].timeofcall, "%02d:%02d:%02d", local->tm_hour, local->tm_min, local->tm_sec);
			sprintf((char*)temp,"%s [%d][%d][%d][%d] called at %s, %s",counspages[i].name.c_str(),a1,a2,a3,a4,counspages[i].timeofcall,counspages[i].reason.c_str());
			if(heartbeat) Writeslot((char*)temp);
			pc_currchar->playercallnum=i;
			pc_currchar->inputmode = cChar::enPageCouns;
			x2++;
			break;
		}
	}
	if(x2==0)
	{
		sysmessage(s,"The Counselor Queue is currently full. Contact the shard operator");
		sysmessage(s,"and ask them to increase the size of the queue.");
	}
	else
	{
		if(strcmp(reason,"OTHER"))
		{
			pc_currchar->inputmode = cChar::enNone;
			sprintf((char*)temp, "Counselor Page from %s [%x %x %x %x]: %s", pc_currchar->name, a1, a2, a3, a4, reason);
			for (i=0;i<now;i++)
				if (chars[currchar[i]].isCounselor() && perm[i])
				{
					x=1;
					sysmessage(i, (char*)temp);
				}
			if (x==1)
			{
				sysmessage(s, "Available Counselors have been notified of your request.");
			}
			else sysmessage(s, "There was no Counselor available to take your call.");
		}
		else sysmessage(s,"Please enter the reason for your Counselor request");
	}
}
void CheckPoisoning(UOXSOCKET sd, P_CHAR pc_attacker, P_CHAR pc_defender)
{
	if ((pc_attacker->poison)&&(pc_defender->poisoned<pc_attacker->poison))
	{
		if (rand()%3==0) // || fightskill==FENCING)//0 1 or 2 //fencing always poisons :) - AntiChrist
		{
			pc_defender->poisoned=pc_attacker->poison;
			pc_defender->poisontime=uiCurrentTime+(MY_CLOCKS_PER_SEC*(40/pc_defender->poisoned)); // a lev.1 poison takes effect after 40 secs, a deadly pois.(lev.4) takes 40/4 secs - AntiChrist
			pc_defender->poisonwearofftime=pc_defender->poisontime+(MY_CLOCKS_PER_SEC*SrvParams->poisonTimer()); //wear off starts after poison takes effect - AntiChrist
			if (sd != -1) 
			{
				impowncreate(sd, pc_defender, 1); //Lb, sends the green bar ! 
				sysmessage(sd, tr("You have been poisoned!"));//AntiChrist 
			}
		}
	}
}
void
handle_suboption(unsigned char *suboptp, int subsize)
{
    unsigned char subopt = *suboptp;

    print_option(subopt);

    switch (subopt) {
    case NVT_COM_PORT_OPTION:
	handle_com_port_command(++suboptp);
	subsize--;
	break;
    default:
	sysmessage(MSG_WARNING, "suboption not supported: %d\n", subopt);
	break;
    }
}
void
dev_interrupt(void)
{
    struct strbuf *ctlmsg = &Message.ctlbuf;
    struct strbuf *datamsg = &Message.databuf;
    ctlmsg->len = 1;
    ctlmsg->buf[0] = M_SIG;

    datamsg->len = 1;
    datamsg->buf[0] = SIGINT;

    if (putmsg(P_mfd, ctlmsg, datamsg, RS_HIPRI) == -1) {
	sysmessage(MSG_ERR,
		   "Can't send SIGINT to slave device : %s\n",
		   strerror(errno));
    }
}
// TESTED: OKAY
// guildnamechange(character, text) copies the text info the guildstones name field 
// (guildnumber gets calculated from the double clicked guildstones), and notifies all online
// guildmambers about the change.
void cGuildStone::ChangeName(UOXSOCKET s, char *text)
{
	list<SERIAL>::iterator it;
	for (it = guilds.begin(); it != guilds.end(); ++it)
	{
		P_ITEM pStone = FindItemBySerial(*it);
		if (pStone->name() == text) 
		{
			sysmessage(s,"This name is already taken by another guild.");
			return;
		}
	}
	this->setName( text );
	char txt[200];
	sprintf(txt, "Your guild got renamed to %s", this->name().ascii() );
	this->Broadcast(txt);
}
void
dev_hangup(void)
{
    struct strbuf *ctlmsg = &Message.ctlbuf;
    struct strbuf *datamsg = &Message.databuf;

    ctlmsg->len = 4;
    SET_VALUE_4(&ctlmsg->buf[0], M_SIG);

    datamsg->len = 4;
    SET_VALUE_4(&datamsg->buf[0], SIGHUP);

    if (putmsg(P_mfd, ctlmsg, datamsg, RS_HIPRI) == -1) {
	sysmessage(MSG_ERR,
		   "Can't send SIGHUP to slave device : %s\n",
		   strerror(errno));
    }
}