Beispiel #1
0
	GLBuffer::GLBuffer(GLfloat *data, uint32_t size, GLuint dimensions, GLuint gltype) :
		_index(0), _dimensions(dimensions), _gltype(gltype)
	{
		glGenBuffers(1, &_index);
		set_data(data, size);
	}
Beispiel #2
0
static int init(void)
{
	unsigned char req_data[MAX_PACKET_LEN];
	int len;
	int r;

	alloc_transfers();

	wmlog_msg(2, "Continuous async read start...");
	CHECK_DISCONNECTED(libusb_submit_transfer(req_transfer));

	len = fill_protocol_info_req(req_data,
			USB_HOST_SUPPORT_SELECTIVE_SUSPEND | USB_HOST_SUPPORT_DL_SIX_BYTES_HEADER |
			USB_HOST_SUPPORT_UL_SIX_BYTES_HEADER | USB_HOST_SUPPORT_DL_MULTI_PACKETS);
	set_data(req_data, len);

	process_events_by_mask(500, WDS_PROTO_FLAGS);

	len = fill_mac_lowlevel_req(req_data);
	set_data(req_data, len);

	process_events_by_mask(500, WDS_OTHER);

	len = fill_init_cmd(req_data);
	set_data(req_data, len);

	len = fill_string_info_req(req_data);
	set_data(req_data, len);

	process_events_by_mask(500, WDS_CHIP | WDS_FIRMWARE);

	wmlog_msg(1, "Chip info: %s", wd_status.chip);
	wmlog_msg(1, "Firmware info: %s", wd_status.firmware);

	len = fill_diode_control_cmd(req_data, diode_on);
	set_data(req_data, len);

	len = fill_mac_req(req_data);
	set_data(req_data, len);

	process_events_by_mask(500, WDS_MAC);

	wmlog_msg(1, "MAC: %02x:%02x:%02x:%02x:%02x:%02x", wd_status.mac[0], wd_status.mac[1], wd_status.mac[2], wd_status.mac[3], wd_status.mac[4], wd_status.mac[5]);

	len = fill_string_info_req(req_data);
	set_data(req_data, len);

	process_events_by_mask(500, WDS_CHIP | WDS_FIRMWARE);

	len = fill_auth_policy_req(req_data);
	set_data(req_data, len);

	process_events_by_mask(500, WDS_OTHER);

	len = fill_auth_method_req(req_data);
	set_data(req_data, len);

	process_events_by_mask(500, WDS_OTHER);

	len = fill_auth_set_cmd(req_data, ssid);
	set_data(req_data, len);

	return 0;
}
Beispiel #3
0
static int ft245r_paged_write_flash(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
                                    int page_size, int addr, int n_bytes) {
    unsigned int    i,j;
    int addr_save,buf_pos,do_page_write,req_count;
    unsigned char buf[FT245R_FRAGMENT_SIZE+1+128];

    req_count = 0;
    for (i=0; i<n_bytes; ) {
        addr_save = addr;
        buf_pos = 0;
        do_page_write = 0;
        for (j=0; j< FT245R_FRAGMENT_SIZE/8/FT245R_CYCLES/4; j++) {
            buf_pos += set_data(pgm, buf+buf_pos, (addr & 1)?0x48:0x40 );
            buf_pos += set_data(pgm, buf+buf_pos, (addr >> 9) & 0xff );
            buf_pos += set_data(pgm, buf+buf_pos, (addr >> 1) & 0xff );
            buf_pos += set_data(pgm, buf+buf_pos, m->buf[addr]);
            addr ++;
            i++;
            if ( (m->paged) &&
                    (((i % m->page_size) == 0) || (i == n_bytes))) {
                do_page_write = 1;
                break;
            }
        }
#if defined(USE_INLINE_WRITE_PAGE)
        if (do_page_write) {
            int addr_wk = addr_save - (addr_save % m->page_size);
            /* If this device has a "load extended address" command, issue it. */
            if (m->op[AVR_OP_LOAD_EXT_ADDR]) {
                unsigned char cmd[4];
                OPCODE *lext = m->op[AVR_OP_LOAD_EXT_ADDR];

                memset(cmd, 0, 4);
                avr_set_bits(lext, cmd);
                avr_set_addr(lext, cmd, addr_wk/2);
                buf_pos += set_data(pgm, buf+buf_pos, cmd[0]);
                buf_pos += set_data(pgm, buf+buf_pos, cmd[1]);
                buf_pos += set_data(pgm, buf+buf_pos, cmd[2]);
                buf_pos += set_data(pgm, buf+buf_pos, cmd[3]);
            }
            buf_pos += set_data(pgm, buf+buf_pos, 0x4C); /* Issue Page Write */
            buf_pos += set_data(pgm, buf+buf_pos,(addr_wk >> 9) & 0xff);
            buf_pos += set_data(pgm, buf+buf_pos,(addr_wk >> 1) & 0xff);
            buf_pos += set_data(pgm, buf+buf_pos, 0);
        }
#endif
        if (i >= n_bytes) {
            ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_AVR_SCK,0); // sck down
            buf[buf_pos++] = ft245r_out;
        }
        ft245r_send(pgm, buf, buf_pos);
        put_request(addr_save, buf_pos, 0);
        //ft245r_sync(pgm);
#if 0
        fprintf(stderr, "send addr 0x%04x bufsize %d [%02x %02x] page_write %d\n",
                addr_save,buf_pos,
                extract_data_out(pgm, buf , (0*4 + 3) ),
                extract_data_out(pgm, buf , (1*4 + 3) ),
                do_page_write);
#endif
        req_count++;
        if (req_count > REQ_OUTSTANDINGS)
            do_request(pgm, m);
        if (do_page_write) {
#if defined(USE_INLINE_WRITE_PAGE)
            while (do_request(pgm, m))
                ;
            usleep(m->max_write_delay);
#else
            int addr_wk = addr_save - (addr_save % m->page_size);
            int rc;
            while (do_request(pgm, m))
                ;
            rc = avr_write_page(pgm, p, m, addr_wk);
            if (rc != 0) {
                return -2;
            }
#endif
            req_count = 0;
        }
    }
    while (do_request(pgm, m))
        ;
    return i;
}
void clubmaster_driver(int cn,int ret,int lastact)
{
	struct clubmaster_driver_data *dat;
        int co,in,n,rank,cc,val;
        struct msg *msg,*next;
	char *ptr,tmp[80],name[80];

        dat=set_data(cn,DRD_CLUBMASTERDRIVER,sizeof(struct clubmaster_driver_data));
	if (!dat) return;	// oops...

        if (ch[cn].arg) {
                clubmaster_driver_parse(cn,dat);
		ch[cn].arg=NULL;
	}

        // loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

		// did we see someone?
		if (msg->type==NT_CHAR) {
			
                        co=msg->dat1;

			// dont talk to someone we cant see, and dont talk to ourself
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }

			// dont talk to someone far away
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }

			// dont talk to the same person twice
			if (mem_check_driver(cn,co,7)) { remove_message(cn,msg); continue; }

			if (!get_char_club(cn) && !get_char_clan(cn)) quiet_say(cn,"Hello %s! Would you like to found a °c4club°c0?",ch[co].name);
			mem_add_driver(cn,co,7);
		}

                // talk back
		if (msg->type==NT_TEXT) {
			analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,msg->dat3);

                        if ((msg->dat1==1 || msg->dat1==2) && (co=msg->dat3)!=cn) {	// talk, and not our talk				
                                if ((ptr=strcasestr((char*)msg->dat2,"found:"))) {
					if (!(ch[co].flags&CF_PAID)) {
						quiet_say(cn,"I'm sorry, %s, but only paying players may found clubs.",ch[co].name);
					} else if (!get_char_clan(co) && !get_char_club(co)) {
						if (ch[co].gold>=10000*100) {
							ptr+=6;
							while (isspace(*ptr)) ptr++;
							for (n=0; n<79; n++) {
								if (!(isalpha(*ptr) || *ptr==' ')) break;
								name[n]=*ptr++;
							}
							name[n]=0;
							
							if ((n=create_club(name))) {
								take_money(co,10000*100);
								ch[co].clan=n+CLUBOFFSET;
								ch[co].clan_serial=club[n].serial;
								ch[co].clan_rank=2;
								quiet_say(cn,"Congratulations, %s, you are now the leader of the club %s.",ch[co].name,club[n].name);
								dlog(co,0,"created club %d %s",n,club[n].name);
							} else quiet_say(cn,"Something's wrong with the name.");
						} else quiet_say(cn,"You cannot pay the fee of 10,000 gold.");
					} else quiet_say(cn,"You are already a member of a clan or club. You cannot found a new one.");
				}
				if ((ptr=strcasestr((char*)msg->dat2,"accept:"))) {
					if (!get_char_club(co) || ch[co].clan_rank<1) {
                                                quiet_say(cn,"You are not a club leader, %s.",ch[co].name);
					} else {
						ptr+=7;
						while (isspace(*ptr)) ptr++;
						for (n=0; n<79; n++) {
							if (!*ptr || *ptr=='"') break;
							dat->accept[n]=*ptr++;
						}
						dat->accept[n]=0;
						strcpy(dat->join,ch[co].name);
						dat->accept_clan=get_char_club(co);
						dat->accept_cn=co;

						quiet_say(cn,"To join %s's club %s, say: 'join: %s'",dat->join,dat->accept,dat->join);
					}
				}
				if ((ptr=strcasestr((char*)msg->dat2,"join:"))) {
					if (get_char_clan(co) || get_char_club(co)) {
                                                quiet_say(cn,"You are already a clan or club member, %s.",ch[co].name);
					} else {
						ptr+=5;
						while (isspace(*ptr)) ptr++;
						for (n=0; n<79; n++) {
							if (!*ptr || *ptr=='"') break;
							tmp[n]=*ptr++;
						}
						tmp[n]=0;
                                                if (strcasecmp(dat->accept,ch[co].name)) {
							quiet_say(cn,"You have not been invited, %s.",ch[co].name);
						} else if (strcasecmp(dat->join,tmp)) {
							quiet_say(cn,"%s has not invited you, %s.",tmp,ch[co].name);
						} else {
                                                        //add_member(co,dat->accept_clan,dat->join);
							ch[co].clan=dat->accept_clan+CLUBOFFSET;
							ch[co].clan_serial=club[dat->accept_clan].serial;
							ch[co].clan_rank=0;
							quiet_say(cn,"%s, you are now a member of %s's club.",ch[co].name,dat->join);
							dat->accept[0]=0;
							dat->accept_clan=0;
							dat->join[0]=0;
						}
						
					}
				}
				if ((ptr=strcasestr((char*)msg->dat2,"leave!"))) {
					if (!get_char_club(co)) {
                                                quiet_say(cn,"You are not a club member, %s.",ch[co].name);
					} else {
						remove_member(co,co);
						quiet_say(cn,"You are no longer a member of any club, %s",ch[co].name);
					}
				}
				if ((ptr=strcasestr((char*)msg->dat2,"rank:"))) {
					if (!get_char_club(co) || ch[co].clan_rank<2) {
                                                quiet_say(cn,"You are not a club founder, %s.",ch[co].name);
					} else {
						ptr+=6;
						while (isspace(*ptr)) ptr++;
						for (n=0; n<79; n++) {
							if (!*ptr || *ptr=='"' || isspace(*ptr)) break;
							tmp[n]=*ptr++;
						}
						tmp[n]=0;
						
						rank=atoi(ptr);

						if (rank<0 || rank>1) {
							quiet_say(cn,"You must use a rank between 0 and 1.");
							remove_message(cn,msg);
							continue;
						}

						for (cc=getfirst_char(); cc; cc=getnext_char(cc)) {
							if (!strcasecmp(tmp,ch[cc].name) && (ch[cc].flags&CF_PLAYER)) break;
						}
						if (cc) {
							if (!(ch[cc].flags&CF_PAID) && rank>0) {
                                                                quiet_say(cn,"%s is not a paying player, you cannot set the rank higher than 0.",ch[cc].name);
							} else if (ch[cc].clan_rank==2) {
								quiet_say(cn,"%s is the club's founder, cannot change rank.",ch[cc].name);
							} else if (get_char_club(cc)==get_char_club(co)) {
								ch[cc].clan_rank=rank;
								quiet_say(cn,"Set %s's rank to %d.",ch[cc].name,rank);
							} else quiet_say(cn,"You cannot change the rank of those not belonging to your club.");
						} else {
							int uID;

							uID=lookup_name(tmp,NULL);
							if (uID==0) continue;
							if (uID==-1) {
								quiet_say(cn,"Sorry, no player by the name %s found.",tmp);
							} else {
								task_set_clan_rank(uID,ch[co].ID,get_char_club(co)+CLUBOFFSET,rank,ch[co].name);
								quiet_say(cn,"Update scheduled (%s,%d).",tmp,rank);
							}
						}
					}
				}
				if ((ptr=strcasestr((char*)msg->dat2,"fire:"))) {
					if (!get_char_club(co) || ch[co].clan_rank<1) {
                                                quiet_say(cn,"You are not a club leader, %s.",ch[co].name);
					} else {
						ptr+=6;
						while (isspace(*ptr)) ptr++;
						for (n=0; n<79; n++) {
							if (!*ptr || *ptr=='"' || isspace(*ptr)) break;
							tmp[n]=*ptr++;
						}
						tmp[n]=0;
						
                                                for (cc=getfirst_char(); cc; cc=getnext_char(cc)) {
							if (!strcasecmp(tmp,ch[cc].name) && (ch[cc].flags&CF_PLAYER)) break;
						}
						if (cc) {
							if (get_char_club(cc)==get_char_club(co)) {
								if (ch[cc].clan_rank<2) {
									remove_member(cc,co);
									quiet_say(cn,"Fired: %s.",ch[cc].name);
								} else quiet_say(cn,"You cannot fire the founder of the club.");
							} else quiet_say(cn,"You cannot fire those not belonging to your club.");
						} else {
							int uID;

							uID=lookup_name(tmp,NULL);
							if (uID==0) continue;
							if (uID==-1) {
								quiet_say(cn,"Sorry, no player by the name %s found.",tmp);
							} else {
								task_fire_from_clan(uID,ch[co].ID,get_char_club(co)+CLUBOFFSET,ch[co].name);
								quiet_say(cn,"Update scheduled (%s).",tmp);
							}
						}
					}
				}

				if ((ptr=strcasestr((char*)msg->dat2,"deposit:"))) {
					if (!(n=get_char_club(co))) {
                                                quiet_say(cn,"You are not a club member, %s.",ch[co].name);
					} else {
						val=atoi(ptr+8)*100;

						if (val>0 && ch[co].gold>=val) {
							club[n].money+=val;
							take_money(co,val);
							quiet_say(cn,"You have deposited %dG, for a total of %dG, %s.",val/100,club[n].money/100,ch[co].name);
							dlog(co,0,"Deposited %dG into club %d, for a new total of %dG",val/100,n,club[n].money/100);
							db_update_club(n);
						} else quiet_say(cn,"You do not have that much gold, %s.",ch[co].name);
					}
				}
				if ((ptr=strcasestr((char*)msg->dat2,"withdraw:"))) {
					if (!(n=get_char_club(co)) || ch[co].clan_rank<2) {
                                                quiet_say(cn,"You are not a club founder, %s.",ch[co].name);
					} else {
						val=atoi(ptr+9)*100;

						if (val>0 && club[n].money>=val) {
							club[n].money-=val;
							give_money(co,val,"club withdrawal");
							quiet_say(cn,"You have withdrawn %dG, money left in club %dG, %s.",val/100,club[n].money/100,ch[co].name);
							dlog(co,0,"Withdrew %dG from club %d, for a new total of %dG",val/100,n,club[n].money/100);
							db_update_club(n);
						} else quiet_say(cn,"The club does not have that much gold, %s.",ch[co].name);
					}
				}
			}			
		}

		// got an item?
		if (msg->type==NT_GIVE) {
			co=msg->dat1;

                        if ((in=ch[cn].citem)) {	// we still have it
				// try to give it back
                                if (give_char_item(cn,co)) return;
				
				// didnt work, let it vanish, then
				destroy_item(ch[cn].citem);
				ch[cn].citem=0;
			}
		}
                remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

	if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,dat->dir,ret,lastact)) return;

        if (ticker>dat->last_talk+TICKS*60 && !RANDOM(25)) {
		switch(RANDOM(8)) {
			case 0:		murmur(cn,"My back itches."); break;
			case 1:		whisper(cn,"There's something stuck between your teeth."); break;
			case 2:		murmur(cn,"Oh yeah, those were the days."); break;
			case 3:		murmur(cn,"Now where did I put it?"); break;
			case 4:		murmur(cn,"Oh my, life is hard but unfair."); break;
                        case 5:		murmur(cn,"Beware of the fire snails!"); break;
			case 6:         murmur(cn,"I love the clicking of coins."); break;
			case 7:		murmur(cn,"Gold and Silver, Silver and Gold."); break;
			default:	break;
		}
		
		dat->last_talk=ticker;
	}

	if (ticker>dat->memcleartimer) {
		mem_erase_driver(cn,7);
		dat->memcleartimer=ticker+TICKS*60*60*12;
	}

        do_idle(cn,TICKS*2);
}
Beispiel #5
0
void yoatin_driver(int cn,int ret,int lastact)
{
	struct yoatin_data *dat;
	struct staffer_ppd *ppd;
        int co,in,didsay=0,talkdir=0;
	struct msg *msg,*next;

        dat=set_data(cn,DRD_YOATINDRIVER,sizeof(struct yoatin_data));
	if (!dat) return;	// oops...

	// loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                // did we see someone?
		if (msg->type==NT_CHAR) {
			
                        co=msg->dat1;

			// dont talk to other NPCs
			if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }

			// dont talk to players without connection
			if (ch[co].driver==CDR_LOSTCON) { remove_message(cn,msg); continue; }
			
			// only talk every ten seconds
			if (ticker<dat->last_talk+TICKS*4) { remove_message(cn,msg); continue; }

			if (ticker<dat->last_talk+TICKS*10 && dat->current_victim!=co) { remove_message(cn,msg); continue; }

                        // dont talk to someone we cant see, and dont talk to ourself
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }

			// dont talk to someone far away
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }

                        // get current status with player
                        ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));

                        if (ppd) {
                                switch(ppd->yoatin_state) {					
					case 0:         quiet_say(cn,"Greetings stranger!");
							questlog_open(co,39);
							ppd->yoatin_state++; didsay=1;
                                                        break;
                                        case 1:		quiet_say(cn,"Wait...I recognize you from the description my brother gave - you must be %s!",ch[co].name);
							ppd->yoatin_state++; didsay=1;
                                                        break;
					case 2:		quiet_say(cn,"My brother's name is Yoakin. It seems you did him a great service slaying the bears of Cameron.");
                                                        ppd->yoatin_state++; didsay=1;
                                                        break;
					case 3:		quiet_say(cn,"Mayhap you could assist me with a problem I have?");
							ppd->yoatin_state++; didsay=1;
                                                        break;
					case 4:		quiet_say(cn,"A family from the town beyond this forest has asked me to hunt down the bear that killed their son.");
							ppd->yoatin_state++; didsay=1;
                                                        break;
					case 5:		quiet_say(cn,"I am not quite the hunter my brother is and well... to be frank, bears scare the living daylights out of me.");
							ppd->yoatin_state++; didsay=1;
                                                        break;
					case 6:		quiet_say(cn,"If you could fetch me proof of the bear being slain, I would reward thee greatly.");
							ppd->yoatin_state++; didsay=1;
                                                        break;
					case 7:		quiet_say(cn,"Take care as you travel! The whole forest is full of bears and bear caves.");
							ppd->yoatin_state++; didsay=1;
                                                        break;
					case 8:		break; // waiting for bear to die
					case 9:		break; // all done
					
					
				}
				if (didsay) {
					dat->last_talk=ticker;
					talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
					dat->current_victim=co;
				}
			}
		}

                // talk back
		if (msg->type==NT_TEXT) {
			co=msg->dat3;

			if (ch[co].flags&CF_PLAYER) {
				ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));
                                switch((didsay=analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,co))) {
					case 2:         if (ppd && ppd->yoatin_state<=8) { dat->last_talk=0; ppd->yoatin_state=0; }
                                                        break;				
					case 3:		if (ch[co].flags&CF_GOD) { say(cn,"reset done"); ppd->yoatin_state=0; }
							break;
				}
                                if (didsay) {
					talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
					dat->current_victim=co;
				}
			}
		}

		// got an item?
		if (msg->type==NT_GIVE) {
			co=msg->dat1;

                        if ((in=ch[cn].citem)) {	// we still have it

				ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));

				if (it[in].ID==IID_STAFF_BEARHEAD && ppd && ppd->yoatin_state<=8) {
					quiet_say(cn,"Thank you %s! This will be perfect proof. Here, take my belt, you are clearly the greater hunter!",ch[co].name);
					questlog_done(co,39);
					destroy_item_byID(co,IID_STAFF_BEARHEAD);
                                        if ((in=create_item("WS_Hunter_Belt"))) {
						if (!give_char_item(co,in)) destroy_item(in);						
					}
                                        ppd->yoatin_state=9;
				} else {
					say(cn,"Thou hast better use for this than I do. Well, if there is a use for it at all.");
                                        if (!give_char_item(co,ch[cn].citem)) destroy_item(ch[cn].citem);
                                        ch[cn].citem=0;
				}
				
				// let it vanish, then
				if (ch[cn].citem) {
					destroy_item(ch[cn].citem);
					ch[cn].citem=0;
				}
			}
		}

		remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

	dat->amgivingback=0;

	if (talkdir) turn(cn,talkdir);

	if (dat->last_talk+TICKS*30<ticker) {
		if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_LEFT,ret,lastact)) return;
	}

        do_idle(cn,TICKS);
}
Beispiel #6
0
void questlog_reopen(int cn,int qnr)
{
	struct quest *quest;
	int ret=1;

	if (qnr<0 || qnr>=MAXQUEST) return;

	if (!(quest=set_data(cn,DRD_QUESTLOG_PPD,sizeof(struct quest)*MAXQUEST))) return;
	if (quest[qnr].done>9) {
		log_char(cn,LOG_SYSTEM,0,"You cannot open this quest again.");
		return;
	}
	if ((!questlog[qnr].flags&QLF_REPEATABLE)) {
		log_char(cn,LOG_SYSTEM,0,"You cannot open this quest again.");
		return;
	}
	if (!(quest[qnr].flags&QF_DONE)) {
		log_char(cn,LOG_SYSTEM,0,"You cannot open this quest at the moment.");
		return;
	}

	switch(qnr) {
		case 0:		questlog_reopen_q0(cn); break;
		case 1:		ret=questlog_reopen_q1(cn,0,quest); break;
		case 2:		ret=questlog_reopen_q1(cn,6,quest); break;
		case 3:		ret=questlog_reopen_q1(cn,10,quest); break;
		case 4:		ret=questlog_reopen_q1(cn,13,quest); break;
		case 5:		questlog_reopen_q5(cn); break;
		case 6:		ret=0; break; //questlog_reopen_q6(cn); break;
		case 7:		ret=questlog_reopen_q7(cn,0,quest); break;
		case 8:		ret=questlog_reopen_q7(cn,6,quest); break;
		case 9:		questlog_reopen_q9(cn); break;
		case 10:	ret=0; break;
		case 11:	ret=0; break;
		case 12:	ret=questlog_reopen_q10(cn,12,quest); break;
		case 13:	questlog_reopen_q13(cn); break;
		case 14:	ret=0; break;
		case 15:	ret=0; break;
		case 16:	questlog_reopen_q16(cn); break;
		case 17:	ret=0; break;
		case 18:	ret=0; break; //ret=questlog_reopen_q18(cn,0,quest); break;
		case 19:	ret=0; break; //ret=questlog_reopen_q18(cn,12,quest); break;
		case 20:	questlog_reopen_q20(cn); break;
		case 21:	ret=0; break;
		case 22:	ret=questlog_reopen_q22(cn,quest); break;
		case 23:	ret=0; break;
		case 24:	ret=0; break;
		case 25:	ret=0; break;
		case 26:	ret=0; break;
		case 27:	ret=0; break;
		case 28:	ret=0; break;
		case 29:	ret=0; break;
		case 30:	questlog_reopen_q30(cn); break;
		case 31:	questlog_reopen_q31(cn); break;
		case 32:	ret=0; break;
		case 33:	ret=0; break;
		case 34:	ret=0; break;
		case 35:	ret=questlog_reopen_q35(cn,0,quest); break;
		case 36:	ret=0; //questlog_reopen_q35(cn,5,quest); break;
		case 37:	ret=questlog_reopen_q35(cn,7,quest); break;
		case 38:	questlog_reopen_q38(cn); break;
		case 39:	questlog_reopen_q39(cn); break;
		case 40:	questlog_reopen_q40(cn); break;
		case 41:	ret=questlog_reopen_q41(cn,0,quest); break;
		case 42:	ret=questlog_reopen_q41(cn,5,quest); break;
		case 43:	ret=questlog_reopen_q41(cn,9,quest); break;
		case 44:	questlog_reopen_q44(cn); break;
		case 45:	ret=questlog_reopen_q45(cn,0,quest); break;
		case 46:	ret=0; break;
		case 47:	ret=0; break;
		case 48:	ret=0; break;
		case 49:	ret=0; break;
		case 50:	ret=0; break;
		case 51:	ret=0; break;
		case 52:	ret=0; break;
		case 53:	ret=0; break;

	}
	if (ret) quest[qnr].flags=QF_OPEN;
	sendquestlog(cn,ch[cn].player);
}
void professor_driver(int cn,int ret,int lastact)
{
	struct professor_driver_data *dat;
        int co,in;
	struct msg *msg,*next;

        dat=set_data(cn,DRD_PROFDRIVER,sizeof(struct professor_driver_data));
	if (!dat) return;	// oops...

        if (ch[cn].arg) {
                professor_driver_parse(cn,dat);
		ch[cn].arg=NULL;
	}

	// loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                // did we see someone?
		if (msg->type==NT_CHAR) {
			
                        co=msg->dat1;

			// dont talk to someone we cant see, and dont talk to ourself
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }

			// dont offer to teach anyone not having the profession skill
			if (!ch[co].value[1][V_PROFESSION]) { remove_message(cn,msg); continue; }

			// dont talk to someone far away
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }

			// dont talk to the same person twice
			if (mem_check_driver(cn,co,7)) { remove_message(cn,msg); continue; }

			say(cn,"Hello %s! I am a professor at Aston University, and I °c4teach°c0 °c4%s°c0.",ch[co].name,prof[dat->nr].name);
			mem_add_driver(cn,co,7);
		}

                // talk back
		if (msg->type==NT_TEXT) {
			co=msg->dat3;
                        ret=analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,co);
			switch(ret) {
				case 2:		switch(dat->quest) {
							case 0:		say(cn,"If thou wishest to learn the art of the %s, thou must pay %d gold coins and %d profession points. Say °c4learn°c0 if this is thy wish. Thou canst also °c4improve°c0 thy knowledge of this art for the fee of %d gold coins and %d profession points.",prof[dat->nr].name,dat->quest_option,prof[dat->nr].base,dat->improve_cost*prof[dat->nr].step,prof[dat->nr].step); break;
							default:	say(cn,"You've found bug #418a"); break;
						}
						break;
				case 3:		switch(dat->nr) {
							case P_ATHLETE:		say(cn,"The art of the athlete are fast, precise movements. Skilled athletes make better use of their endurance and move faster than untrained humans."); break;
							case P_ALCHEMIST:	say(cn,"The alchemist can create better potions, calling on the powers of the moons and the seasons at any time."); break;
							case P_MINER:		say(cn,"A skilled miner will make better use of every vein of precious metal he finds. He will also not exhaust as fast as an unskilled miner."); break;
							case P_ASSASSIN:	say(cn,"The assassin is especially skilled at attacking an enemy from the side or behind, and he can backstab an unware opponent from behind."); break;
							case P_THIEF:		say(cn,"A skilled thief can remain unseen even when next to another person. But when he uses this skill of stealth he cannot do anything but wait or walk, and the effort of remaining unseen will drain his endurance."); break;
							case P_LIGHT:		say(cn,"A master of light will receive a bonus to his basic abilities during the day. If he masters this skill he will also be able to see all undead creatures in the dark."); break;
							case P_DARK:		say(cn,"A master of dark will receive a bonus to his basic abilities during the night. If he masters this skill he will also be able to see all living creatures in the dark."); break;
							case P_TRADER:		say(cn,"A skilled trader will get better prices when dealing with merchants."); break;
							case P_MERCENARY:	say(cn,"Those skilled in the art of the mercenary will advance in military rank faster. They will also collect pay for their missions."); break;
							case P_CLAN:		say(cn,"A clan master has received special training in the art of clan warfare. He will be at an advantage in any fight in the clan catacombs."); break;
							case P_HERBALIST:	say(cn,"A herbalist knows the art of making plants ripe faster. Any flower, berry or mushroom he picks will grow back in less time."); break;

							default: 		say(cn,"You've found bug #418b"); break;
						}
						break;
				case 4:		switch(dat->quest) {
							case 0:		if (ch[co].gold<dat->quest_option*100) { say(cn,"But thou cannot afford my fee of %dG.",dat->quest_option); break; }
									if (!learn_prof(cn,co,dat->nr)) break;
									ch[co].gold-=dat->quest_option*100;
									ch[co].flags|=CF_ITEMS;
									break;
							default:	say(cn,"You've found bug #418a"); break;
						}
						break;
				case 5:		if (ch[co].gold<dat->improve_cost*prof[dat->nr].step*100) { say(cn,"But thou cannot afford my fee of %dG.",dat->improve_cost*prof[dat->nr].step); break; }
						if (!improve_prof(cn,co,dat->nr)) break;
						ch[co].gold-=dat->improve_cost*prof[dat->nr].step*100;
						ch[co].flags|=CF_ITEMS;
                                                break;
			}

		}

		// got an item?
		if (msg->type==NT_GIVE) {
			co=msg->dat1;

                        if ((in=ch[cn].citem)) {	// we still have it
				// let it vanish
				destroy_item(ch[cn].citem);
				ch[cn].citem=0;
			}
		}

                remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

        if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,dat->dir,ret,lastact)) return;		

        do_idle(cn,TICKS);
}
Beispiel #8
0
void warpfighter(int cn,int ret,int lastact)
{
    struct warpfighter_data *dat;
    struct msg *msg,*next;
    int co,in,fre;

    dat=set_data(cn,DRD_WARPFIGHTER,sizeof(struct warpfighter_data));
    if (!dat) return;	// oops...

    // loop through our messages
    for (msg=ch[cn].msg; msg; msg=next) {
        next=msg->next;

        switch(msg->type) {
        case NT_CREATE:
            fight_driver_set_dist(cn,40,0,40);
            dat->creation_time=ticker;
            break;

        case NT_TEXT:
            co=msg->dat3;
            tabunga(cn,co,(char*)msg->dat2);
            break;
        }


        standard_message_driver(cn,msg,1,0);
        remove_message(cn,msg);
    }

    // do something. whenever possible, call do_idle with as high a tick count
    // as reasonable when doing nothing.

    co=dat->co;
    if (!ch[co].flags || ch[co].serial!=dat->cser || ch[co].x<dat->xs || ch[co].y<dat->ys || ch[co].x>dat->xe || ch[co].y>dat->ye) {
        remove_char(cn);
        destroy_char(cn);
        //xlog("self-destruct %d %d %d %d %d %d (%d)",!ch[co].flags,ch[co].serial!=dat->cser,ch[co].x<dat->xs,ch[co].y<dat->ys,ch[co].x>dat->xe,ch[co].y>dat->ye,dat->co);
        return;
    }

    if (dat->pot_done<1 && ticker>dat->creation_time+TICKS*2) {
        dat->pot_done++;
        if (ch[cn].level>60 && !RANDOM(6)) {
            if (RANDOM(2)) {
                emote(cn,"drinks a potion of freeze");
                ch[cn].value[1][V_FREEZE]=ch[cn].value[1][V_ATTACK]+ch[cn].value[1][V_ATTACK]/4;
                ch[cn].value[1][V_MANA]=10;
                update_char(cn);
                ch[cn].mana=POWERSCALE*10;
            } else {
                if ((fre=may_add_spell(cn,IDR_FREEZE)) && (in=create_item("freeze_spell"))) {
                    emote(cn,"drinks a spoiled potion of freeze");
                    it[in].mod_value[0]=-ch[cn].value[0][V_SPEED]-100;
                    it[in].driver=IDR_FREEZE;
                    it[in].carried=cn;
                    ch[cn].item[fre]=in;
                    *(signed long*)(it[in].drdata)=ticker+TICKS*60;
                    *(signed long*)(it[in].drdata+4)=ticker;
                    create_spell_timer(cn,in,fre);
                    update_char(cn);
                }
            }
        }
    }

    if (ch[cn].lifeshield<POWERSCALE*5 && ch[cn].endurance<ch[cn].value[0][V_WARCRY]*POWERSCALE/3 && dat->pot_done<3) {
        dat->pot_done++;
        if (ch[cn].level>50 && !RANDOM(4)) {
            emote(cn,"drinks an endurance potion");
            ch[cn].endurance=min(ch[cn].value[0][V_ENDURANCE]*POWERSCALE,ch[cn].endurance+32*POWERSCALE);
        }
    }

    if (ch[cn].hp<ch[cn].value[0][V_ENDURANCE]*POWERSCALE/2 && dat->pot_done<5) {
        dat->pot_done++;
        if (ch[cn].level>40 && !RANDOM(4)) {
            emote(cn,"drinks a healing potion");
            ch[cn].hp=min(ch[cn].value[0][V_HP]*POWERSCALE,ch[cn].hp+32*POWERSCALE);
        }
    }

    fight_driver_update(cn);
    if (fight_driver_attack_visible(cn,0)) return;
    if (fight_driver_follow_invisible(cn)) return;

    if (regenerate_driver(cn)) return;
    if (spell_self_driver(cn)) return;

    if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_DOWN,ret,lastact)) return;

    do_idle(cn,TICKS);
}
Beispiel #9
0
void warpmaster(int cn,int ret,int lastact)
{
    int co,in,type,in2,flag=0,code,n;
    struct msg *msg,*next;
    struct warped_ppd *ppd;

    // loop through our messages
    for (msg=ch[cn].msg; msg; msg=next) {
        next=msg->next;

        // did we see someone?
        if (msg->type==NT_CHAR) {
            co=msg->dat1;

            // dont talk to someone we cant see, and dont talk to ourself
            if (!char_see_char(cn,co) || cn==co) {
                remove_message(cn,msg);
                continue;
            }

            // dont talk to someone far away
            if (char_dist(cn,co)>10) {
                remove_message(cn,msg);
                continue;
            }

            // dont talk to the same person twice
            if (mem_check_driver(cn,co,7)) {
                remove_message(cn,msg);
                continue;
            }

            if (ch[co].level<30) say(cn,"Hello %s! You'd better leave this area - it is too dangerous for you.",ch[co].name);
            else say(cn,"Hello %s! Welcome to Rodney's °c4Warped World°c0! Would you like to buy some °c4keys°c0?",ch[co].name);
            mem_add_driver(cn,co,7);
        }

        // talk back
        if (msg->type==NT_TEXT) {
            co=msg->dat3;

            if (!(ch[co].flags&CF_PLAYER)) {
                remove_message(cn,msg);
                continue;
            }

            code=analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,co);
            if (code==2 && (ppd=set_data(co,DRD_WARP_PPD,sizeof(struct warped_ppd)))) {	// reset
                ppd->points=0;
                for (n=0; n<MAXWARPBONUS; n++) ppd->bonuslast_used[n]=0;
                ppd->nostepexp=1;
                say(cn,"Done.");
            }
        }

        // got an item?
        if (msg->type==NT_GIVE) {
            co=msg->dat1;

            if ((in=ch[cn].citem)) {

                type=it[in].drdata[0];
                if (it[in].ID==IID_ALCHEMY_INGREDIENT) {
                    if (type==23) {
                        in2=create_item("warped_door_key");
                        if (give_char_item(co,in2)) flag=1;
                        else destroy_item(in2);
                        say(cn,"Here you go, one key.");
                    }
                    if (type==21) {
                        in2=create_item("warped_door_key");
                        if (give_char_item(co,in2)) flag=1;
                        else destroy_item(in2);
                        in2=create_item("warped_door_key");
                        if (give_char_item(co,in2)) flag=1;
                        else destroy_item(in2);
                        say(cn,"Here you go, two keys.");

                    }
                    if (type==22) {
                        in2=create_item("warped_door_key");
                        if (give_char_item(co,in2)) flag=1;
                        else destroy_item(in2);
                        in2=create_item("warped_door_key");
                        if (give_char_item(co,in2)) flag=1;
                        else destroy_item(in2);
                        in2=create_item("warped_door_key");
                        if (give_char_item(co,in2)) flag=1;
                        else destroy_item(in2);
                        say(cn,"Here you go, three keys.");
                    }
                    if (type==24) {
                        in2=create_item("warped_door_key");
                        if (give_char_item(co,in2)) flag=1;
                        else destroy_item(in2);
                        in2=create_item("warped_door_key");
                        if (give_char_item(co,in2)) flag=1;
                        else destroy_item(in2);
                        in2=create_item("warped_door_key");
                        if (give_char_item(co,in2)) flag=1;
                        else destroy_item(in2);
                        in2=create_item("warped_door_key");
                        if (give_char_item(co,in2)) flag=1;
                        else destroy_item(in2);
                        say(cn,"Here you go, four keys.");
                    }
                }
                if (flag || !give_char_item(co,in)) {
                    destroy_item(ch[cn].citem);
                }
                ch[cn].citem=0;
            }
        }

        remove_message(cn,msg);
    }
    // do something. whenever possible, call do_idle with as high a tick count
    // as reasonable when doing nothing.

    if (spell_self_driver(cn)) return;

    if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_RIGHT,ret,lastact)) return;

    if (ticker%345600==0) {
        mem_erase_driver(cn,7);
    }

    do_idle(cn,TICKS);
}
Beispiel #10
0
void warpbonus_driver(int in,int cn)
{
    int ID,n,old_n=0,old_val=0,level,in2=0,in3;
    struct warped_ppd *ppd;

    if (!cn) return;

    ppd=set_data(cn,DRD_WARP_PPD,sizeof(struct warped_ppd));
    if (!ppd) return;	// oops...
    if (!ppd->base) ppd->base=40;

    if (ppd->base>139) {
        log_char(cn,LOG_SYSTEM,0,"You're done. Finished. It's over. You're there. You've solved the final level.");
        return;
    }

    ID=(int)it[in].x+((int)(it[in].y)<<8)+(areaID<<16);

    for (n=0; n<MAXWARPBONUS; n++) {
        if (ppd->bonusID[n]==ID) break;
        if (realtime-ppd->bonuslast_used[n]>old_val) {
            old_val=realtime-ppd->bonuslast_used[n];
            old_n=n;
        }
    }

    if (n==MAXWARPBONUS) n=old_n;
    else if (ppd->bonuslast_used[n]>=ppd->base) {
        log_char(cn,LOG_SYSTEM,0,"Nothing happened.");
        return;
    }

    if (ppd->points+1>=ppd->base/4 && (!(in2=ch[cn].citem) || it[in2].ID!=IID_AREA25_TELEKEY)) {
        log_char(cn,LOG_SYSTEM,0,"Nothing happened. You sense that you'll need one of the spheres this time.");
        return;
    }

    ppd->bonusID[n]=ID;
    ppd->bonuslast_used[n]=ppd->base;

    level=min(ch[cn].level,(int)(ppd->base*0.80));

    ppd->points++;
    if (ppd->points>=ppd->base/4) {
        ppd->points=0;
        ppd->base+=5;
        ppd->nostepexp=0;

        if (ppd->base>139) log_char(cn,LOG_SYSTEM,0,"You've finished the final level.");
        else if (ppd->base>134) log_char(cn,LOG_SYSTEM,0,"You've reached the final level.");
        else log_char(cn,LOG_SYSTEM,0,"You advanced a level! Take care!");

        if (in2 && it[in2].ID==IID_AREA25_TELEKEY) {
            switch(it[in2].drdata[0]) {
            case 1:
                give_exp_bonus(cn,level_value(level)/7);
                log_char(cn,LOG_SYSTEM,0,"You received experience.");
                break;
            case 2:
                if (ch[cn].saves<10 && !(ch[cn].flags&CF_HARDCORE)) {
                    ch[cn].saves++;
                    log_char(cn,LOG_SYSTEM,0,"You received a save.");
                }
                break;
            case 3:
                log_char(cn,LOG_SYSTEM,0,"You received military rank.");
                give_military_pts_no_npc(cn,level,0);
                break;
            case 4:
                ch[cn].gold+=level*level*10;
                ch[cn].flags|=CF_ITEMS;
                log_char(cn,LOG_SYSTEM,0,"You received %d gold.",level*level/10);
                break;
            case 5:
                in3=create_item("lollipop");
                if (give_char_item(cn,in3)) log_char(cn,LOG_SYSTEM,0,"You received a lollipop.");
                else destroy_item(in3);
                break;
            }
        }
        if (ppd->base>139) return;
    } else if (!ppd->nostepexp) give_exp_bonus(cn,level_value(level)/70);

    log_char(cn,LOG_SYSTEM,0,"You are at level %d, and you have %d of %d points.",(ppd->base-35)/5,ppd->points,ppd->base/4);
}
Beispiel #11
0
int warptrialdoor_driver(int in,int cn)
{
    int xs,ys,xe,ye,x,y,m,in2,dx,dy,dir,co;
    struct warpfighter_data *dat;
    struct warped_ppd *ppd;

    ppd=set_data(cn,DRD_WARP_PPD,sizeof(struct warped_ppd));
    if (!ppd) return 2;	// oops...
    if (!ppd->base) ppd->base=40;

    if (!it[in].drdata[2]) {
        xs=xe=ys=ye=in2=0;

        for (x=it[in].x+1,y=it[in].y; x<it[in].x+15; x++) {
            if (map[x+y*MAXMAP].it && it[map[x+y*MAXMAP].it].driver==IDR_WARPTRIALDOOR) {
                in2=map[x+y*MAXMAP].it;
                xs=it[in].x;
                xe=it[in2].x;

                for (x=it[in].x+1,y=it[in].y; y<it[in].y+15; y++) {
                    if (map[x+y*MAXMAP].flags&MF_MOVEBLOCK) {
                        ye=y;
                        break;
                    }
                }
                for (x=it[in].x+1,y=it[in].y; y>it[in].y-15; y--) {
                    if (map[x+y*MAXMAP].flags&MF_MOVEBLOCK) {
                        ys=y;
                        break;
                    }
                }
                break;
            }
            if (map[x+y*MAXMAP].flags&(MF_MOVEBLOCK|MF_TMOVEBLOCK)) break;
        }

        if (!in2) {
            for (x=it[in].x-1,y=it[in].y; x>it[in].x-15; x--) {
                if (map[x+y*MAXMAP].it && it[map[x+y*MAXMAP].it].driver==IDR_WARPTRIALDOOR) {
                    in2=map[x+y*MAXMAP].it;
                    xe=it[in].x;
                    xs=it[in2].x;

                    for (x=it[in].x-1,y=it[in].y; y<it[in].y+15; y++) {
                        if (map[x+y*MAXMAP].flags&MF_MOVEBLOCK) {
                            ye=y;
                            break;
                        }
                    }
                    for (x=it[in].x-1,y=it[in].y; y>it[in].y-15; y--) {
                        if (map[x+y*MAXMAP].flags&MF_MOVEBLOCK) {
                            ys=y;
                            break;
                        }
                    }
                    break;
                }
                if (map[x+y*MAXMAP].flags&(MF_MOVEBLOCK|MF_TMOVEBLOCK)) break;
            }
        }

        if (!in2) {
            for (x=it[in].x,y=it[in].y+1; y<it[in].y+15; y++) {
                if (map[x+y*MAXMAP].it && it[map[x+y*MAXMAP].it].driver==IDR_WARPTRIALDOOR) {
                    in2=map[x+y*MAXMAP].it;
                    ys=it[in].y;
                    ye=it[in2].y;

                    for (x=it[in].x,y=it[in].y+1; x<it[in].x+15; x++) {
                        if (map[x+y*MAXMAP].flags&MF_MOVEBLOCK) {
                            xe=x;
                            break;
                        }
                    }
                    for (x=it[in].x,y=it[in].y+1; x>it[in].x-15; x--) {
                        if (map[x+y*MAXMAP].flags&MF_MOVEBLOCK) {
                            xs=x;
                            break;
                        }
                    }
                    break;
                }
                if (map[x+y*MAXMAP].flags&(MF_MOVEBLOCK|MF_TMOVEBLOCK)) break;
            }
        }

        if (!in2) {
            for (x=it[in].x,y=it[in].y-1; y>it[in].y-15; y--) {
                if (map[x+y*MAXMAP].it && it[map[x+y*MAXMAP].it].driver==IDR_WARPTRIALDOOR) {
                    in2=map[x+y*MAXMAP].it;
                    ye=it[in].y;
                    ys=it[in2].y;

                    for (x=it[in].x,y=it[in].y-1; x<it[in].x+15; x++) {
                        if (map[x+y*MAXMAP].flags&MF_MOVEBLOCK) {
                            xe=x;
                            break;
                        }
                    }
                    for (x=it[in].x,y=it[in].y-1; x>it[in].x-15; x--) {
                        if (map[x+y*MAXMAP].flags&MF_MOVEBLOCK) {
                            xs=x;
                            break;
                        }
                    }
                    break;
                }
                if (map[x+y*MAXMAP].flags&(MF_MOVEBLOCK|MF_TMOVEBLOCK)) break;
            }
        }

        //xlog("xs=%d, ys=%d, xe=%d, ye=%d, in=%d, in2=%d",xs,ys,xe,ye,in,in2);

        it[in].drdata[2]=xs;
        it[in].drdata[3]=ys;
        it[in].drdata[4]=xe;
        it[in].drdata[5]=ye;
        *(unsigned short*)(it[in].drdata+6)=in2;
    }

    if (!cn) return 2;

    xs=it[in].drdata[2];
    ys=it[in].drdata[3];
    xe=it[in].drdata[4];
    ye=it[in].drdata[5];
    in2=*(unsigned short*)(it[in].drdata+6);

    if (ch[cn].x>=xs && ch[cn].x<=xe && ch[cn].y>=ys && ch[cn].y<=ye) {
        log_char(cn,LOG_SYSTEM,0,"You cannot open the door from this side.");
        return 2;
    }

    for (y=ys+1; y<ye; y++) {
        for (x=xs+1,m=x+y*MAXMAP; x<xe; x++,m++) {
            if ((co=map[m].ch) && ch[co].driver!=CDR_SIMPLEBADDY) {
                log_char(cn,LOG_SYSTEM,0,"You hear fighting noises and the door won't open.");
                return 2;
            }
        }
    }
    co=create_char("warped_fighter",0);
    if (!co) {
        log_char(cn,LOG_SYSTEM,0,"Bug #319i, sorry.");
        return 2;
    }
    if (!drop_char(co,(xs+xe)/2,(ys+ye)/2,0)) {
        log_char(cn,LOG_SYSTEM,0,"Bug #319j, sorry.");
        destroy_char(co);
        return 2;
    }
    ch[co].tmpx=ch[co].x;
    ch[co].tmpy=ch[co].y;

    warped_raise(co,ppd->base);

    update_char(co);

    ch[co].hp=ch[co].value[0][V_HP]*POWERSCALE;
    ch[co].endurance=ch[co].value[0][V_ENDURANCE]*POWERSCALE;
    ch[co].mana=ch[co].value[0][V_MANA]*POWERSCALE;
    ch[co].lifeshield=ch[co].value[0][V_MAGICSHIELD]*POWERSCALE;

    ch[co].dir=DX_RIGHTDOWN;

    dat=set_data(co,DRD_WARPFIGHTER,sizeof(struct warpfighter_data));
    if (!dat) {
        log_char(cn,LOG_SYSTEM,0,"Bug #319k, sorry.");
        remove_char(co);
        destroy_char(co);
        return 2;
    }
    dir=offset2dx(it[in].x,it[in].y,it[in2].x,it[in2].y);
    if (!dir) {
        log_char(cn,LOG_SYSTEM,0,"Bug #319l, sorry.");
        remove_char(co);
        destroy_char(co);
        return 2;
    }
    dx2offset(dir,&dx,&dy,NULL);

    dat->co=cn;
    dat->cser=ch[cn].serial;
    dat->tx=it[in2].x+dx;
    dat->ty=it[in2].y+dy;
    dat->xs=xs;
    dat->xe=xe;
    dat->ys=ys;
    dat->ye=ye;

    teleport_char_driver(cn,it[in].x+dx,it[in].y+dy);

    return 1;
}
int main (void)
{
	char x, y;
	//char a = 0;
    ioinit(); //Setup IO pins and defaults
	USART_Init( MYUBRR);
	rprintf_devopen(put_char); /* init rrprintf */
	
	//set_data(0x55);

	//PORTC |= ((1 << RESET) | (1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2) | (1 << RS));//all high
	
	//while(1);
	
	/*
	while(1)
	{
		PORTC &= ~((1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2));//down
		delay_ms(500);
		//PORTC |= ((1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2));//all high
		PORTC |= ((1 << RESET) | (1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2) | (1 << RS));//all high
		delay_ms(500);
	}
	*/
	/*
	DDRC = 0b00000001;
	
	while(1)
	{
		PORTC |= 0b00000001;
		delay_1uS();
		PORTC &= 0b11111110;
		delay_1uS();
	
	}
	*/
	
	//Reset the display
	//PORTC = 0b11110111;
	PORTC &= ~(1 << RESET);
	delay_ms(50);
	PORTC |= (1 << RESET);
	delay_ms(500);
	
	clear_screen();
	
	set_page(0);
	set_x(0);
	
	display_on();
	
	//set display start line to 0
	//set control lines
	
	PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));//down
	set_port_out();
	//set_data(0xC0);
	set_data(0xC0);
	delay_us(4);
	PORTC |= (1 << EN);//up
	delay_us(4);
	PORTC &= ~(1 << EN);//down
	delay_us(4);
	PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));//all high
	
	set_port_in();
	delay_us(4);
	
	
	x_offset = 0;

	set_page(0);
	
	//Backlight on
	PORTB &= (~(1<<BL_EN));
	
	//demo();  
	//put_char('X');
	
	while(1)
	{
		if(RX_in != RX_read)
		{
			x = RX_array[RX_read];
			RX_read++;
			if(RX_read >= 256) RX_read = 0;
			
			
			
			//Backspace===================================================
			if(x == 8) del_char(0);
			
			//Special commands
			else if (x == 124)
			{	
				//make sure the next byte is there
				while(RX_in == RX_read);
				
				//0, clear screen======================================================
				if(RX_array[RX_read] == 0)
				{
					clear_screen();
					RX_read++;
					if(RX_read >= 256) RX_read = 0;
				}
				
				
				//Backlight on/off
				else if(RX_array[RX_read] == 2)
				{
					y = PINB;
					if (y & (1<<BL_EN)) PORTB &= (~(1<<BL_EN));
					else PORTB |= (1<<BL_EN);
					RX_read++;
				}
				
				//demo mode
				else if(RX_array[RX_read] == 4)
				{
					RX_in = 0, RX_read = 0;
					demo();
					clear_screen();
					RX_in = 0;
				}
				
				else
				{				
					//set x or y=========================================================
					if((RX_array[RX_read] == 24) | (RX_array[RX_read] == 25))
					{
						RX_read++;
						if(RX_read >= 256) RX_read = 0;
						while(RX_in == RX_read);//wait for byte
						if (RX_array[RX_read-1] == 24) x_offset = RX_array[RX_read];
						else if (RX_array[RX_read-1] == 25) y_offset = RX_array[RX_read];
						
						RX_read++;
						if(RX_read >= 256) RX_read = 0;
						
						if (x_offset > 127) x_offset = 127;
						if (y_offset > 63) y_offset = 63;

					}

					//set pixel=========================================================
					if (RX_array[RX_read] == 16)
					{
						//need 3 bytes
						for (y = 0; y < 3; y++)
						{
							RX_read++;
							if(RX_read >= 256) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						pixel(RX_array[RX_read], RX_array[RX_read-2], RX_array[RX_read-1]);
						
						RX_read++;
						if(RX_read >= 256) RX_read = 0;

					}

					//<ctrl>c, circle======================================================
					if(RX_array[RX_read] == 3)
					{
						//need 4 bytes
						for (y = 0; y < 4; y++)
						{
							RX_read++;
							if(RX_read >= 256) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						circle(RX_array[RX_read], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1]);
						
						RX_read++;
						if(RX_read >= 256) RX_read = 0;
					}
					
					
					//<ctrl>e, erase block======================================================
					if(RX_array[RX_read] == 5)
					{
						//need 4 bytes
						for (y = 0; y < 4; y++)
						{
							RX_read++;
							if(RX_read >= 256) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						erase_block(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
						
						RX_read++;
						if(RX_read >= 256) RX_read = 0;
					}
					
					
					//<ctrl>o, box, running out of meaningful letters======================================================
					if(RX_array[RX_read] == 15)
					{
						//need 4 bytes
						for (y = 0; y < 4; y++)
						{
							RX_read++;
							if(RX_read >= 256) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						box(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
						
						RX_read++;
						if(RX_read >= 256) RX_read = 0;
					}
					

					//<ctrl>L, line========================================================
					else if (RX_array[RX_read] == 12)
					{
						//need 5 bytes
						for (y = 0; y < 5; y++)
						{
							RX_read++;
							if(RX_read >= 256) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						line(RX_array[RX_read], RX_array[RX_read-4], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read+-1]);
						RX_read++;
						if(RX_read >= 256) RX_read = 0;
					}
					
					
				}
	
			}
			
			//print character to the screen===============================================
			else
			{
				
				del_char(1);
				//put_char('L');
				print_char(1, x);
				
			}
			
			//set_data(0xFF);
			//set_port_in();
			//display_on();
			//y = PINB;
			//PORTB = y;
		}
		
	}
	
}
Beispiel #13
0
int main(int argc, char *argv[])
{
    int cwnd;
    cwnd = 4000; // default cwnd

    timeout = 0;

    int WINDOW_SIZE;

	double p_loss, p_corrupt;
    p_loss = 0.0;
    p_corrupt = 0.0;
    
    struct sockaddr_in serv_si, cli_si;
	struct packet snd_pkt, rcv_pkt;

    FILE *file;
    struct stat file_stat;
    int n_packets;
    int readlength;
     
    int portno, sockfd, i, recv_len, send_len;
    int slen = sizeof(cli_si);

    if (argc < 2)
    {
        fprintf(stderr, "Usage: %s port [cwnd] [loss ratio] [corrupt ratio]\n", argv[0]);
        exit(0);
    }

    switch (argc)
    {
        case 5:
            p_corrupt = atof(argv[4]);
        case 4:
            p_loss = atof(argv[3]);
        case 3:
            cwnd = atoi(argv[2]);
        default:
            portno = atoi(argv[1]);
            break;
    }

    WINDOW_SIZE = cwnd / PACKET_SIZE;

    //create a UDP socket
    if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
    {
        die("socketfd error", sockfd);
    }
     
    // zero out the structure
    memset((char *) &serv_si, 0, sizeof(serv_si));
     
    serv_si.sin_family = AF_INET;
    serv_si.sin_port = htons(portno);
    serv_si.sin_addr.s_addr = htonl(INADDR_ANY);
     
    //bind socket to port
    if(bind(sockfd , (struct sockaddr*)&serv_si, sizeof(serv_si)) == -1)
    {
        die("error in bind\n", sockfd);
    }

    rcv_pkt = make_packet();
    
    msg("Waiting for file request...\n");
    if ((recv_len = recvfrom(sockfd, &rcv_pkt, sizeof(rcv_pkt), 0, (struct sockaddr *) &cli_si, (socklen_t*)&slen)) == -1)
	{
        die("error receive syn", sockfd);
	}

    snd_pkt = make_packet();
    
    if (check_syn(&rcv_pkt)) {
        msg("Received file request for %s\n", rcv_pkt.data);

    	file = fopen(rcv_pkt.data, "rb");

        if (file == NULL) // no file exists
        {
            msg("No such file, sending NONE packet...\n");

            set_none(&snd_pkt);
            if ((send_len = sendto(sockfd, &snd_pkt, sizeof(snd_pkt), 0, (struct sockaddr*)&cli_si, slen)) == -1)
            {
                die("Error sending NONE", sockfd);
            }

            teardown(file, sockfd);
        }
    }

    stat(rcv_pkt.data, &file_stat);
    n_packets = file_stat.st_size / DATA_SIZE;
    if (file_stat.st_size % DATA_SIZE)
    {
        n_packets++;
    }
    
    int base, next_seq, last_ack = 1;

    base = 1;
    next_seq = 1;
    last_ack = 0;

    int pktindex;

    struct packet pkt_win[WINDOW_SIZE];
    char buf[PACKET_SIZE];

    struct sigaction act;
    memset (&act, '\0', sizeof(act));
    act.sa_sigaction = &handle_sigalrm;
    act.sa_flags = 0;
    sigaction(SIGALRM, &act, NULL); //sets timeout handler

    // Send initial packets
    for (i = 0; i < min(WINDOW_SIZE, n_packets); i++) {
        memset(buf, 0, PACKET_SIZE);

        snd_pkt = make_packet();
        snd_pkt.seq_num = i + 1;

        readlength = fread(buf, sizeof(char), DATA_SIZE, file);
        set_data(&snd_pkt, buf, readlength);

        pkt_win[i] = snd_pkt;

        msg("<- DATA: SEQNUM %d ...\n", snd_pkt.seq_num);

        if (sendto(sockfd, &snd_pkt, sizeof(snd_pkt), 0, (struct sockaddr *)&cli_si, slen) < 0)
        {
            error("ERROR on sending");
        }

        next_seq++;
    }

	while (base <= n_packets) {
        if (timeout) {
            int n_char;
            int resend_base = base;

            msg("TIMEOUT: resending packets %d - %d\n", resend_base, min(resend_base + WINDOW_SIZE - 1, n_packets));
            
            while (resend_base < next_seq) {
                pktindex = (resend_base - 1) % WINDOW_SIZE;
                send_len = sendto(sockfd, &pkt_win[pktindex], sizeof(pkt_win[pktindex]), 0, (struct sockaddr*)&cli_si, slen);
                if (send_len < 0)
                {
                    die("Error sending packet during timeout", sockfd);
                }
                msg("Retransmitting DATA with SEQNUM %d ...\n", resend_base);
                resend_base++;
            }

            timeout = 0;
            alarm(TO_SEC);
        }

		rcv_pkt = make_packet();

		if ((recv_len = recvfrom(sockfd, &rcv_pkt, sizeof(rcv_pkt), 0, (struct sockaddr *) &cli_si, (socklen_t*)&slen)) == -1)
		{
	        // Timed out, recvfrom unblocked. 
            // Continue, let loop hit timeout block above
            continue;
		}
        else if (chance() < p_loss)
        {
            msg("Packet from receiver LOST\n");
        }
		else if (chance() < p_corrupt)
		{
			msg("Packet from receiver CORRUPT\n");
		}
		else if (check_fin(&rcv_pkt)) {
			msg("-> FIN-ACK\n");
			teardown(file, sockfd);
		}
		else if (rcv_pkt.seq_num == base) {
			// Correct ACK received, stop timer
            alarm(0);

            msg("-> ACK: SEQNUM %d\n", rcv_pkt.seq_num);
            last_ack = rcv_pkt.seq_num;
            base = rcv_pkt.seq_num + 1;

            // Send packets
            if (next_seq <= min(base + WINDOW_SIZE, n_packets + 1)) {
                memset(buf, 0, PACKET_SIZE);

                if ((readlength = fread(buf, sizeof(char), DATA_SIZE, file)) == 0) {
                    // struct packet fin_pkt = make_packet();

                    // set_fin(fin_pkt);
                    // fin_pkt.seq_num = next_seq;

                    
                    // if ((send_len = sendto(sockfd, &finpkt, sizeof(finpkt), 0, (struct sockaddr*)&cli_si, slen)) < 0) {
                    //     die("Error sending packet during fin", sockfd);
                    // }
                    // else {
                    //     msg("<- FIN ...\n");
                    //     alarm(TO_SEC);
                    // }
                    alarm(TO_SEC);
                }
                else {
                    snd_pkt = make_packet();

                    set_data(&snd_pkt, buf, readlength);
                    snd_pkt.seq_num = next_seq;

                    pktindex = (next_seq - 1) % WINDOW_SIZE;
                    pkt_win[pktindex] = snd_pkt;

                    msg("<- DATA: SEQNUM %d ...\n", next_seq);

                    if ((send_len = sendto(sockfd, &pkt_win[pktindex], sizeof(pkt_win[pktindex]), 0, (struct sockaddr*)&cli_si, slen)) < 0) {
                        die("Error sending packet during data", sockfd);
                    }

                    if (next_seq == base) {
                        alarm(TO_SEC);
                    }

                    if (next_seq <= n_packets)
                    {
                        next_seq++;
                    }
                }
            }
		}
		else {
			// Incorrect ACK received, restart timer
            alarm(TO_SEC);
		}
	}

    // Send FIN
    snd_pkt = make_packet();
    set_fin(&snd_pkt);
    msg("<- FIN ...\n");

    if ((send_len = sendto(sockfd, &snd_pkt, sizeof(snd_pkt), 0, (struct sockaddr*)&cli_si, slen)) < 0) {
        die("Error sending packet during teardown", sockfd);
    }

    rcv_pkt = make_packet();

    if ((recv_len = recvfrom(sockfd, &rcv_pkt, sizeof(rcv_pkt), 0, (struct sockaddr *) &cli_si, (socklen_t*)&slen)) > 0)
    {
        if (check_fin(&rcv_pkt)) {
            msg("-> FIN-ACK\n");
            teardown(file, sockfd);
        }
    }

    teardown(file, sockfd);
    return 0;
}
Beispiel #14
0
void load_history(const char *name)
{
    DIR *d = NULL;
    struct dirent *de = NULL;
    char file_list[512][15];
    int i=0,j=0,m=0;
    int cnt=0;
    char year_j[5]= {0},year_m[5]= {0},tmp_file[15]= {0};
    char mon_j[3]= {0},mon_m[3]= {0};
    char day_j[3]= {0},day_m[3]= {0};

    printf(HISTORY_TAG"begin to shmat\n");
    g_history_co = (struct nano *)shmat(shmid_co, 0, 0);
    g_history_co2 = (struct nano *)shmat(shmid_co2, 0, 0);
    g_history_hcho = (struct nano *)shmat(shmid_hcho, 0, 0);
    g_history_shidu = (struct nano *)shmat(shmid_shidu, 0, 0);
    g_history_temp = (struct nano *)shmat(shmid_temp, 0, 0);
    g_history_pm25 = (struct nano *)shmat(shmid_pm25, 0, 0);
    g_co_cnt = (long *)shmat(shmid_co_cnt, 0, 0);
    g_co2_cnt = (long *)shmat(shmid_co2_cnt, 0, 0);
    g_hcho_cnt = (long *)shmat(shmid_hcho_cnt, 0, 0);
    g_temp_cnt = (long *)shmat(shmid_temp_cnt, 0, 0);
    g_shidu_cnt = (long *)shmat(shmid_shidu_cnt, 0, 0);
    g_pm25_cnt = (long *)shmat(shmid_pm25_cnt, 0, 0);
    history_done = (int *)shmat(history_load_done_shmid,0,0);
    printf(HISTORY_TAG"end to shmat\n");
    *history_done=0;
    printf(HISTORY_TAG"load=>history_done %d\n",*history_done);
    d = opendir(name);
    if(d == 0)
    {
        printf(HISTORY_TAG"open failed %s , %s",name,strerror(errno));
        return;
    }

    while((de = readdir(d))!=0)
    {
        if(strncmp(de->d_name,".",strlen("."))==0||strncmp(de->d_name,"..",strlen(".."))==0)
            continue;
        memset(file_list[i],'\0',15);
        strcpy(file_list[i],de->d_name);
        i++;
    }
    closedir(d);
    //compare year
    for(j=0; j<i-1; j++)
    {
        for(m=j+1; m<i; m++)
        {
            memcpy(year_j,file_list[j],4);
            memcpy(year_m,file_list[m],4);
            if(atoi(year_j)>atoi(year_m))
            {
                strcpy(tmp_file,file_list[j]);
                strcpy(file_list[j],file_list[m]);
                strcpy(file_list[m],tmp_file);
            }
        }
    }
    for(j=0; j<i-1; j++)
    {
        for(m=j+1; m<i; m++)
        {
            memcpy(year_j,file_list[j],4);
            memcpy(mon_j,file_list[j]+5,2);
            memcpy(year_m,file_list[m],4);
            memcpy(mon_m,file_list[m]+5,2);
            if((atoi(mon_j)>atoi(mon_m)) && (atoi(year_m)==atoi(year_j)))
            {
                strcpy(tmp_file,file_list[j]);
                strcpy(file_list[j],file_list[m]);
                strcpy(file_list[m],tmp_file);
            }
        }
    }
    for(j=0; j<i-1; j++)
    {
        for(m=j+1; m<i; m++)
        {
            memcpy(year_j,file_list[j],4);
            memcpy(mon_j,file_list[j]+5,2);
            memcpy(day_j,file_list[j]+8,2);
            memcpy(year_m,file_list[m],4);
            memcpy(mon_m,file_list[m]+5,2);
            memcpy(day_m,file_list[m]+8,2);
            if((atoi(day_j)>atoi(day_m)) && (atoi(mon_j)==atoi(mon_m)) && (atoi(year_m)==atoi(year_j)))
            {
                //printf(HISTORY_TAG"switch day_j %s,day_m %s,mon_j %s,mon_m %s,year_j %s,year_m %s\n",day_j,day_m,mon_j,mon_m,year_j,year_m);
                strcpy(tmp_file,file_list[j]);
                strcpy(file_list[j],file_list[m]);
                strcpy(file_list[m],tmp_file);
            }
        }
    }
    for(j=0; j<i; j++)
    {
        char *line=NULL;
        char file_path[32]= {0};
        int len;
        printf(HISTORY_TAG"==> %s\n",file_list[j]);
        strcpy(file_path,"/home/user/history/");
        strcat(file_path,file_list[j]);
        FILE *fp = fopen(file_path, "r");
        while (getline(&line, &len, fp) != -1)
        {
            if((cnt%2)!=0)
            {
                //get co,co2,hcho,pm25,shidu,temp
                set_data(line,ID_CAP_CO,g_history_co,g_co_cnt);
                set_data(line,ID_CAP_CO2,g_history_co2,g_co2_cnt);
                set_data(line,ID_CAP_HCHO,g_history_hcho,g_hcho_cnt);
                set_data(line,ID_CAP_SHI_DU,g_history_shidu,g_shidu_cnt);
                set_data(line,ID_CAP_TEMPERATURE,g_history_temp,g_temp_cnt);
                set_data(line,ID_CAP_PM_25,g_history_pm25,g_pm25_cnt);
            }
            else
            {
                set_time(file_list[j],line,g_history_co,g_co_cnt);
                set_time(file_list[j],line,g_history_co2,g_co2_cnt);
                set_time(file_list[j],line,g_history_temp,g_temp_cnt);
                set_time(file_list[j],line,g_history_hcho,g_hcho_cnt);
                set_time(file_list[j],line,g_history_shidu,g_shidu_cnt);
                set_time(file_list[j],line,g_history_pm25,g_pm25_cnt);
            }
            cnt++;
        }
        fclose(fp);
    }
    *history_done=1;
    printf(HISTORY_TAG"load=>history_done %d\n",*history_done);
}
Beispiel #15
0
int swearing(int cn,char *text)
{
	struct swear_ppd *ppd;
	int n,flag;

	if (!(ch[cn].flags&CF_PLAYER)) return 0;

	ppd=set_data(cn,DRD_SWEAR_PPD,sizeof(struct swear_ppd));
	if (!ppd) return 0;	// oops...

	if (ppd->banned_till>realtime) {
		log_char(cn,LOG_SYSTEM,0,"°c3Chat is blocked for %.2f minutes.",(ppd->banned_till-realtime)/60.0);
		return 1;
	}

	if (ch[cn].flags&CF_GOD) return 0;

	if (realtime-ppd->bad<30) {
		log_char(cn,LOG_SYSTEM,0,"°c3Chat is blocked.");
		return 1;
	}

        if (realtime-ppd->lasttalk[1]<1) {	// 0.3s per line
		log_char(cn,LOG_SYSTEM,0,"°c3Chat has been blocked for 30 seconds for excessive usage (1).");
		ppd->bad=realtime;
		return 1;
	}
	if (realtime-ppd->lasttalk[4]<10) {	// 2s per line
		log_char(cn,LOG_SYSTEM,0,"°c3Chat has been blocked for 30 seconds for excessive usage (2).");
		ppd->bad=realtime;
		return 1;
	}
	if (realtime-ppd->lasttalk[9]<30) {	// 3s per line
		log_char(cn,LOG_SYSTEM,0,"°c3Chat has been blocked for 30 seconds for excessive usage (3).");
		ppd->bad=realtime;
		return 1;
	}

	if (strcasestr(text,"a3res") || strcasestr(text,"c**t") || strcasestr(text,"f****t")) {
		log_char(cn,LOG_SYSTEM,0,"°c3Swearing is illegal in this game. While only a few words are blocked by the system, you will get punished and eventually banned if you swear using non-blocked words.");
		log_char(cn,LOG_SYSTEM,0,"°c3Chat has been blocked for 30 seconds.");
		ppd->bad=realtime;
		return 1;
	}

	if (strlen(text)>3 && all_upper(text)) {
		log_char(cn,LOG_SYSTEM,0,"°c3Using capitalized letters only is impolite. Trying to get around the block by using mostly caps will get you punished and eventually banned.");
		log_char(cn,LOG_SYSTEM,0,"°c3Chat has been blocked for 30 seconds.");
		ppd->bad=realtime;
		return 1;
	}

	// test for repeating long sentences
	if (strlen(text)>20) {
		for (n=flag=0; n<10; n++) {
			if (!strncmp(ppd->last_sentence[n],text,78) && realtime-ppd->last_time[n]<30) {
				if (ppd->last_cnt[n]>2 || realtime-ppd->last_time[n]<4) {
					log_char(cn,LOG_SYSTEM,0,"°c3Repeating the same sentence is impolite. Repeating variants of the same sentence will get you punished and eventually banned.");
					log_char(cn,LOG_SYSTEM,0,"°c3Chat has been blocked for 30 seconds.");
					ppd->bad=realtime;
					return 1;
				}
				ppd->last_cnt[n]++;
				ppd->last_time[ppd->last_pos]=realtime;
				flag=1;
				break;
			}
		}
		if (!flag) {
			if (ppd->last_pos<0 || ppd->last_pos>9) ppd->last_pos=0;
			strncpy(ppd->last_sentence[ppd->last_pos],text,78); ppd->last_sentence[ppd->last_pos][78]=0;
			ppd->last_time[ppd->last_pos]=realtime;
			ppd->last_cnt[ppd->last_pos]=1;
			ppd->last_pos++;
		}
	}

	for (n=9; n>0; n--)
		ppd->lasttalk[n]=ppd->lasttalk[n-1];
	
	ppd->lasttalk[0]=realtime;

	return 0;
}
void VSObjectTransformation::copy_from(const VSObjectTransformation &X) {
	set_data(X.m_data);
}
Beispiel #17
0
void merchant_driver(int cn,int ret,int lastact)
{
	struct merchant_driver_data *dat;
        int co,in,n;
	struct msg *msg,*next;

        dat=set_data(cn,DRD_MERCHANTDRIVER,sizeof(struct merchant_driver_data));
	if (!dat) return;	// oops...

        if (ch[cn].arg) {
		dat->open=6; dat->close=23;
		merchant_driver_parse(cn,dat);
		ch[cn].arg=NULL;
	}
	if (!ch[cn].store) {
		if (dat->pricemulti) create_store(cn,dat->ignore,dat->pricemulti);
		else create_store(cn,dat->ignore,400);
		if (dat->special) {
			for (n=0; n<5; n++) add_special_store(cn);
		}
	}
	
	// loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                // did we see someone?
		if (msg->type==NT_CHAR) {
			
                        co=msg->dat1;

			// dont talk to someone we cant see, and dont talk to ourself
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }

			// dont talk to someone far away
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }

			// dont talk to the same person twice
			if (mem_check_driver(cn,co,7)) { remove_message(cn,msg); continue; }

			quiet_say(cn,"Hello %s! If you'd like to trade, say: '°c4%s, trade°c0!",ch[co].name,ch[cn].name);
			mem_add_driver(cn,co,7);
		}

                // talk back
		if (msg->type==NT_TEXT) {
			analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,msg->dat3);

			if ((msg->dat1==1 || msg->dat1==2) && (co=msg->dat3)!=cn) {	// talk, and not our talk
				if (strcasestr((char*)msg->dat2,ch[cn].name) &&
				    strcasestr((char*)msg->dat2,"trade")) {
					/*if (abuser(ch[co].ID)) {
						switch(RANDOM(3)) {
                                                        case 0:		murmur(cn,"I hate cheaters."); break;
							case 1:		emote(cn,"clenches his fists and stares at %s.",ch[co].name); break;
							case 2:		murmur(cn,"I wish the cheaters would leave me alone."); break;
						}
					}*/
					ch[co].merchant=cn;
				}
			}			
		}

		// got an item?
		if (msg->type==NT_GIVE) {
			co=msg->dat1;

                        if ((in=ch[cn].citem)) {	// we still have it
				// let it vanish
				destroy_item(ch[cn].citem);
				ch[cn].citem=0;
			}
		}

                remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

	if (dat->dayx) {	// we have day / night positions
		if (!opening_time(dat->open,dat->close)) {	// we're closed
                        if (dat->doorx && !is_closed(dat->doorx,dat->doory)) {	// door is still open
				if (!is_room_empty(dat->storefx,dat->storefy,dat->storetx,dat->storety)) {	// store is not empty
					quiet_say(cn,"We're closing, please leave now!");
					do_idle(cn,TICKS);
					return;
				} else {
					if (use_item_at(cn,dat->doorx,dat->doory,0)) return;
					do_idle(cn,TICKS);
					return;
				}
			}
			if (secure_move_driver(cn,dat->nightx,dat->nighty,dat->nightdir,ret,lastact)) return;
		} else {	// we're open
                        if (dat->doorx && is_closed(dat->doorx,dat->doory)) {	// door is still closed
                                if (use_item_at(cn,dat->doorx,dat->doory,0)) return;
				do_idle(cn,TICKS);
				return;			
			}

			if (secure_move_driver(cn,dat->dayx,dat->dayy,dat->daydir,ret,lastact)) return;			
		}
	} else {		// just one position
		if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,dat->dir,ret,lastact)) return;		
	}

        if (ticker>dat->last_talk+TICKS*60 && !RANDOM(25)) {
		switch(RANDOM(11)) {
			case 0:		murmur(cn,"My back itches."); break;
			case 1:		whisper(cn,"There's something stuck between your teeth."); break;
			case 2:		murmur(cn,"Oh yeah, those were the days."); break;
			case 3:		murmur(cn,"Now where did I put it?"); break;
			case 4:		murmur(cn,"Oh my, life is hard but unfair."); break;
			case 5:		murmur(cn,"Beware of the fire snails!"); break;	
			case 6:		murmur(cn,"Ishtar! Oh, what has become of us!"); break;
			case 7:		murmur(cn,"The demons will get you."); break;
			case 8:		emote(cn,"scratches %s back",hisname(cn)); break;
			case 9:		if (map[ch[cn].x+ch[cn].y*MAXMAP].flags&MF_INDOORS) emote(cn,"stares at the ceiling");
					else emote(cn,"stares at the sky");
					break;
			case 10:	emote(cn,"twiddles %s thumbs",hisname(cn)); break;

			default:	break;
		}
		
		dat->last_talk=ticker;
	}
	if (dat->special && ticker>dat->lastadd+TICKS*60*60*12) {
		add_special_store(cn);
		dat->lastadd=ticker;
	}

	if (ticker>dat->memcleartimer) {
		mem_erase_driver(cn,7);
		dat->memcleartimer=ticker+TICKS*60*60*12;
	}

        do_idle(cn,TICKS*2);
}
Beispiel #18
0
CL_DNSPacket::CL_DNSPacket(const CL_DataBuffer &data)
: impl(new CL_DNSPacket_Impl)
{
	set_data(data);
}
Beispiel #19
0
	void cui::fcl::dataset::set_data_from_ptr(const void * p_data, t_size size, t_uint32 type, t_import_feedback & feedback, abort_callback & p_abort)
	{
		stream_reader_memblock_ref reader(p_data, size);
		return set_data(&reader, size, type, feedback, p_abort);
	}
Beispiel #20
0
static void make_debug_instrument(void)
{
    set_data("p_dc_blocker_enabled.json", "false");

    set_data("au_02/proc_00/in_00/p_manifest.json", "{}");
    set_data("au_02/proc_00/out_00/p_manifest.json", "{}");
    set_data("au_02/proc_00/p_manifest.json", "{ \"type\": \"debug\" }");
    set_data("au_02/proc_00/p_signal_type.json", "\"voice\"");

    set_data("au_02/proc_01/out_00/p_manifest.json", "{}");
    set_data("au_02/proc_01/p_manifest.json", "{ \"type\": \"pitch\" }");
    set_data("au_02/proc_01/p_signal_type.json", "\"voice\"");

    set_data("au_02/p_manifest.json", "{ \"type\": \"instrument\" }");
    set_data("au_02/out_00/p_manifest.json", "{}");
    set_data("au_02/p_connections.json",
            "[ [\"proc_00/C/out_00\", \"out_00\"]"
            ", [\"proc_01/C/out_00\", \"proc_00/C/in_00\"]"
            "]");

    return;
}
bool FnZorbaParseXmlFragmentIterator::nextImpl(
    store::Item_t& result,
    PlanState& planState) const
{
  store::Store& lStore = GENV.getStore();
  zstring docString;
  store::Item_t tempItem;
  bool validated = true;

  FnZorbaParseXmlFragmentIteratorState* state;
  DEFAULT_STACK_INIT(FnZorbaParseXmlFragmentIteratorState, state, planState);

  if (consumeNext(result, theChildren[0].getp(), planState))
  {
    if (result->isStreamable())
    {
      state->theFragmentStream.theStream = &result->getStream();
      state->theFragmentStream.setStreamReleaser(result->getStreamReleaser());
      result->setStreamReleaser(nullptr);
    }
    else
    {
      result->getStringValue2(docString);
      state->theFragmentStream.theIss = new std::istringstream(docString.c_str());
      state->theFragmentStream.theStream = state->theFragmentStream.theIss;
    }

    // read options
    consumeNext(tempItem, theChildren[1].getp(), planState);
    state->theProperties.setBaseUri(theSctx->get_base_uri());
    state->theProperties.setStoreDocument(false);
    state->theProperties.setUseCachedDocument(false);
    processOptions(tempItem, state->theProperties, theSctx, loc);
    state->theProperties.setCreateDocParentLink(false);

    // baseURI serves both as the base URI used by the XML parser
    // to resolve relative entity references within the document,
    // and as the base URI of the document node that is returned.
    state->baseUri = state->theProperties.getBaseUri();
    state->docUri = state->theProperties.getBaseUri();


    ////////////////////////////////////////////////////////////////////////
    // External parsed entity processing
    ////////////////////////////////////////////////////////////////////////
    if (state->theProperties.getParseExternalParsedEntity())
    {
      state->theFragmentStream.root_elements_to_skip =
      state->theProperties.getSkipRootNodes();

      while ( ! state->theFragmentStream.stream_is_consumed())
      {
        try
        {
          result = lStore.loadDocument(state->baseUri,
                                       state->docUri,
                                       state->theFragmentStream,
                                       state->theProperties);
        }
        catch ( ZorbaException const &e )
        {
          if ( !state->theProperties.getNoError() )
          {
            XQueryException xe(
              XQUERY_EXCEPTION(
                err::FODC0006,
                ERROR_PARAMS( "parse-xml:parse()", e.what() ),
                ERROR_LOC( loc )
              )
            );
            set_data( xe, e );
            throw xe;
          }
          result = nullptr;
        }

        if (result == NULL)
          continue;

        // Return the children of document node
        state->theFragmentStream.children = result->getChildren();
        while (state->theFragmentStream.children->next(result) && result != NULL)
        {
          if (state->theProperties.getSkipTopLevelTextNodes() && result->getNodeKind() == store::StoreConsts::textNode)
            continue;

          STACK_PUSH(true, state);
        }
      }
    }
    ////////////////////////////////////////////////////////////////////////
    // XML document processing
    ////////////////////////////////////////////////////////////////////////
    else  // if (!state->theProperties.getEnableExtParsedEntity())
    {
      try 
      {
        result = lStore.loadDocument(state->baseUri, state->docUri, *state->theFragmentStream.theStream, state->theProperties);
      }
      catch ( ZorbaException const &e )
      {
        if ( !state->theProperties.getNoError() )
        {
          XQueryException xe(
            XQUERY_EXCEPTION(
              err::FODC0006,
              ERROR_PARAMS( "parse-xml:parse()", e.what() ),
              ERROR_LOC( loc )
            )
          );
          set_data( xe, e );
          throw xe;
        }
        result = nullptr;
      }

      if (result != NULL)
      {
#ifndef ZORBA_NO_XMLSCHEMA
        if (state->theProperties.getSchemaLaxValidate() ||
            state->theProperties.getSchemaStrictValidate())
        {
          try
          {
            tempItem = NULL; // used as the effectiveValidationValue()'s typeName
            validated = Validator::effectiveValidationValue(
                          result,
                          result,
                          tempItem,
                          theSctx->get_typemanager(),
                          state->theProperties.getSchemaLaxValidate() ? ParseConstants::val_lax : ParseConstants::val_strict,
                          theSctx,
                          this->loc);
          }
          catch (ZorbaException& /*e*/)
          {
            if ( ! state->theProperties.getNoError())
              throw;
            else
            {
              result = NULL;
              validated = false;
            }
          }
        }
#endif
        // Ignore the schema validation options if Zorba is built without schema support

        STACK_PUSH(validated, state);
      } // if (result != NULL)
    } // if (state->theProperties.getEnableExtParsedEntity())
  } // if (consumeNext(result, theChildren[0].getp(), planState))

  STACK_END(state);
}
Beispiel #22
0
int id3_read_id3v2(FILE *file, TrackInfo *ti, const char *file_type)
{
	char id[3];
	int  result = 0;

	rewind(file);
	if (fread(id, 3, 1, file) && strncmp(id, "ID3", 3) == 0) {
		unsigned char ver_major, ver_minor, flags, size[4];

		ver_major = fgetc(file);
		ver_minor = fgetc(file);
		flags     = fgetc(file);
		if (fread(size, 4, 1, file)) {
			wdprintf(V_INFO, "id3", "ID3v2.%d.%d detected!\n", ver_major, ver_minor);
			snprintf(ti->file_type, SIZE_FILE_TYPE, "%s (ID3v2.%d.%d)",
					 file_type, ver_major, ver_minor);
			if (ver_major > 4 || ver_major < 3) {
				wdprintf(V_WARNING, "id3", "Unsupported ID3 version.\n");
			} else if ((flags & (1+2+4+8)) > 0) {
				wdprintf(V_WARNING, "id3", "Tag error!\n");
			} else {
				int           i, error = 0, global_unsync = 0, real_size = 0;
				unsigned char frame_size[5];

				if ((flags & 16) > 0) /* bit 4 */
					wdprintf(V_DEBUG, "id3", "ID3v2: Footer present.\n");
				if ((flags & 32) > 0) /* bit 5 */
					wdprintf(V_DEBUG, "id3", "ID3v2: Experimental indicator is set.\n");
				if ((flags & 64) > 0) /* bit 6 */
					wdprintf(V_DEBUG, "id3", "ID3v2: Extended header bit is set.\n");
				if ((flags & 128) > 0) { /* bit 7 */
					wdprintf(V_DEBUG, "id3", "ID3v2: Unsynchronisation bit is set.\n");
					global_unsync = 1;
				}
				real_size = calc_size_unsync(size);
				wdprintf(V_DEBUG, "id3", "Tag size: %d bytes\n", real_size);
				for (i = 0; i < 4; i++)
					if (size[i] > 127) {
						wdprintf(V_WARNING, "id3", "Error in ID3 tag.\n");
						error = 1;
						break;
					}
				if (!error) {
					int  byte_counter = 0;
					char frame_id[5] = "X", frame_flags[3];

					if (real_size - 10 > ID3V2_MAX_SIZE) frame_id[0] = 0;
					while (byte_counter < real_size - 10 && frame_id[0] != 0) {
						int fsize, frame_unsync = 0;

						if (fread(frame_id,    4, 1, file) &&
						    fread(frame_size,  4, 1, file) &&
						    fread(frame_flags, 2, 1, file)) {
							byte_counter += 10;
							fsize = calc_size(frame_size);
							/*wdprintf(V_DEBUG, "id3", "Frame ID: %s - Frame size: %d bytes\n", frame_id, fsize);*/

							if (ver_major == 4)
								frame_unsync = (frame_flags[1] & 2) ? 1 : 0;
							/*wdprintf(V_DEBUG, "id3", "bytecounter=%d fsize=%d realsize=%d r-b=%d\n",
									   byte_counter, fsize, real_size, real_size - byte_counter);*/
							if (fsize > 0 && fsize <= real_size - byte_counter) {
								char    *frame_data = malloc(fsize+1);
								Charset  charset    = ISO_8859_1;
								char    *tmp_charset;

								if ((global_unsync && ver_major == 3 ) || frame_unsync) {
									fread_unsync(frame_data, fsize, file);
									/*wdprintf(V_DEBUG, "id3", "Decoded unsync scheme.\n");*/
								} else {
									if (!fread(frame_data, fsize, 1, file)) {
										wdprintf(V_ERROR, "id3", "ERROR: Incomplete data.\n");
										break;
									}
								}
								byte_counter += fsize;
								frame_data[fsize] = '\0';
								switch(frame_data[0]) {
									case 0:
										charset = ISO_8859_1;
										tmp_charset = "ISO-8859-1";
										break;
									case 1:
										charset = UTF_16_BOM;
										tmp_charset = "UTF-16 (with BOM)";
										break;
									case 2:
										charset = UTF_16;
										tmp_charset = "UTF-16 (without BOM)";
										break;
									case 3:
										charset = UTF_8;
										tmp_charset = "UTF-8";
										break;
									default:
										tmp_charset = "unknown";
										break;
								}
								wdprintf(V_INFO, "id3", "%s charset: %s\n", frame_id, tmp_charset);
								/*wdprintf(V_DEBUG, "id3", "Frame data: %s\n", frame_data+1);*/

								if (strncmp(frame_id, "TIT2", 4) == 0) {
									int r = set_data(ti, TITLE, frame_data+1, fsize-1, charset);
									if (!result) result = r;
								} else if (strncmp(frame_id, "TPE1", 4) == 0) {
									int r = set_data(ti, ARTIST, frame_data+1, fsize-1, charset);
									if (!result) result = r;
								} else if (strncmp(frame_id, "TALB", 4) == 0) {
									set_data(ti, ALBUM, frame_data+1, fsize-1, charset);	
								} else if (strncmp(frame_id, "TRCK", 4) == 0) {
									set_data(ti, TRACKNR, frame_data+1, fsize-1, charset);
								} else if (strncmp(frame_id, "TYER", 4) == 0) { /* 2.3.0 */
									set_data(ti, DATE, frame_data+1, fsize-1, charset);						
								} else if (strncmp(frame_id, "TDRC", 4) == 0) { /* 2.4.0 */
									set_data(ti, DATE, frame_data+1, fsize-1, charset);
								} else if (strncmp(frame_id, "COMM", 4) == 0) {
									set_data(ti, COMMENT, frame_data+1, fsize-1, charset);
								} else if (strncmp(frame_id, "APIC", 4) == 0) {
									set_cover_art(ti, frame_data+1, fsize-1, charset);
								} else if (strncmp(frame_id, "USLT", 4) == 0) {
									set_lyrics(ti, frame_data+4, fsize-4, charset);
								}
								free(frame_data);
							} else {
								break;
							}
						} else {
							break;
						}
					}
				}
			}
		}
	}
	return result;
}
Beispiel #23
0
void aristocrat_driver(int cn,int ret,int lastact)
{
	struct aristocrat_data *dat;
	struct staffer_ppd *ppd;
        int co,in,didsay=0,talkdir=0;
	struct msg *msg,*next;

        dat=set_data(cn,DRD_ARISTOCRATDRIVER,sizeof(struct aristocrat_data));
	if (!dat) return;	// oops...

	// loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                // did we see someone?
		if (msg->type==NT_CHAR) {
			
                        co=msg->dat1;

			// dont talk to other NPCs
			if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }

			// dont talk to players without connection
			if (ch[co].driver==CDR_LOSTCON) { remove_message(cn,msg); continue; }
			
			// only talk every ten seconds
			if (ticker<dat->last_talk+TICKS*4) { remove_message(cn,msg); continue; }

			if (ticker<dat->last_talk+TICKS*10 && dat->current_victim!=co) { remove_message(cn,msg); continue; }

                        // dont talk to someone we cant see, and dont talk to ourself
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }

			// dont talk to someone far away
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }

                        // get current status with player
                        ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));

                        if (ppd) {
                                switch(ppd->aristocrat_state) {
					case 0:         quiet_say(cn,"Greetings stranger!");
							questlog_open(co,38);
							ppd->aristocrat_state++; didsay=1;
                                                        break;
                                        case 1:		quiet_say(cn,"Say! You look like quite a buoyant adventurer.");
							ppd->aristocrat_state++; didsay=1;
                                                        break;
					case 2:		quiet_say(cn,"Oh no, I didn't mean it that way! Please don't growl at me!");
                                                        ppd->aristocrat_state++; didsay=1;
                                                        break;
					case 3:		quiet_say(cn,"I was watching the local wildlife at a large lake north of here...");
							ppd->aristocrat_state++; didsay=1;
                                                        break;
                                        case 4:		quiet_say(cn,"When one of the larger natives suddenly lurched out of the water and attacked me.");
							ppd->aristocrat_state++; didsay=1;
                                                        break;
					case 5:		quiet_say(cn,"I managed to escape with my life, but alas my Amulet was lost.");
							ppd->aristocrat_state++; didsay=1;
                                                        break;
					case 6:		quiet_say(cn,"I would reward you well if you could retrieve this family heirloom for me.");
							ppd->aristocrat_state++; didsay=1;
                                                        break;
					case 7:		break; // waiting for amulet
					case 8:		break; // all done
				}
				if (didsay) {
					dat->last_talk=ticker;
					talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
					dat->current_victim=co;
				}
			}
		}

                // talk back
		if (msg->type==NT_TEXT) {
			co=msg->dat3;

			if (ch[co].flags&CF_PLAYER) {
				ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));
                                switch((didsay=analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,co))) {
					case 2:         if (ppd && ppd->aristocrat_state<=7) { dat->last_talk=0; ppd->aristocrat_state=0; }
                                                        break;
					case 3:		if (ch[co].flags&CF_GOD) { say(cn,"reset done"); ppd->aristocrat_state=0; }
							break;
				}
                                if (didsay) {
					talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
					dat->current_victim=co;
				}
			}
		}

		// got an item?
		if (msg->type==NT_GIVE) {
			co=msg->dat1;

                        if ((in=ch[cn].citem)) {	// we still have it

				ppd=set_data(co,DRD_STAFFER_PPD,sizeof(struct staffer_ppd));

				if (it[in].ID==IID_STAFF_ARIAMULET && ppd && ppd->aristocrat_state<=7) {
					int tmp;
                                        quiet_say(cn,"Yes! Many thanks adventurer! Please accept this reward.");
					tmp=questlog_done(co,38);
					destroy_item_byID(co,IID_STAFF_ARIAMULET);
					destroy_item_byID(co,IID_STAFF_ARIKEY);
                                        ppd->aristocrat_state=8;
					if (tmp==1 && (in=create_money_item(1000*100))) {
						if (!give_char_item(co,in)) destroy_item(in);						
					}
				} else {
					say(cn,"Thou hast better use for this than I do. Well, if there is a use for it at all.");
                                        if (!give_char_item(co,ch[cn].citem)) destroy_item(ch[cn].citem);
                                        ch[cn].citem=0;
				}
				
				// let it vanish, then
				if (ch[cn].citem) {
					destroy_item(ch[cn].citem);
					ch[cn].citem=0;
				}
			}
		}

		remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

	dat->amgivingback=0;

	if (talkdir) turn(cn,talkdir);

	if (dat->last_talk+TICKS*30<ticker) {
		if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_LEFT,ret,lastact)) return;
	}

        do_idle(cn,TICKS);
}
Beispiel #24
0
static inline int do_16(unsigned long inst, struct pt_regs *regs)
{
	int imm, regular, load, len, addr_mode, idx_mode;
	unsigned long unaligned_addr, target_val, source_idx, target_idx,
	    shift = 0;
	switch ((inst >> 9) & 0x3F) {

	case 0x12:		/* LHI333    */
		imm = 1;
		regular = 1;
		load = 1;
		len = 2;
		addr_mode = 3;
		idx_mode = 3;
		break;
	case 0x10:		/* LWI333    */
		imm = 1;
		regular = 1;
		load = 1;
		len = 4;
		addr_mode = 3;
		idx_mode = 3;
		break;
	case 0x11:		/* LWI333.bi */
		imm = 1;
		regular = 0;
		load = 1;
		len = 4;
		addr_mode = 3;
		idx_mode = 3;
		break;
	case 0x1A:		/* LWI450    */
		imm = 0;
		regular = 1;
		load = 1;
		len = 4;
		addr_mode = 5;
		idx_mode = 4;
		break;
	case 0x16:		/* SHI333    */
		imm = 1;
		regular = 1;
		load = 0;
		len = 2;
		addr_mode = 3;
		idx_mode = 3;
		break;
	case 0x14:		/* SWI333    */
		imm = 1;
		regular = 1;
		load = 0;
		len = 4;
		addr_mode = 3;
		idx_mode = 3;
		break;
	case 0x15:		/* SWI333.bi */
		imm = 1;
		regular = 0;
		load = 0;
		len = 4;
		addr_mode = 3;
		idx_mode = 3;
		break;
	case 0x1B:		/* SWI450    */
		imm = 0;
		regular = 1;
		load = 0;
		len = 4;
		addr_mode = 5;
		idx_mode = 4;
		break;

	default:
		return -EFAULT;
	}

	if (addr_mode == 3) {
		unaligned_addr = *idx_to_addr(regs, RA3(inst));
		source_idx = RA3(inst);
	} else {
		unaligned_addr = *idx_to_addr(regs, RA5(inst));
		source_idx = RA5(inst);
	}

	if (idx_mode == 3)
		target_idx = RT3(inst);
	else
		target_idx = RT4(inst);

	if (imm)
		shift = IMM3U(inst) * len;

	if (regular)
		unaligned_addr += shift;

	if (load) {
		if (!access_ok(VERIFY_READ, (void *)unaligned_addr, len))
			return -EACCES;

		get_data(unaligned_addr, &target_val, len);
		*idx_to_addr(regs, target_idx) = target_val;
	} else {
		if (!access_ok(VERIFY_WRITE, (void *)unaligned_addr, len))
			return -EACCES;
		target_val = *idx_to_addr(regs, target_idx);
		set_data((void *)unaligned_addr, target_val, len);
	}

	if (!regular)
		*idx_to_addr(regs, source_idx) = unaligned_addr + shift;
	regs->ipc += 2;

	return 0;
fault:
	return -EACCES;
}
Beispiel #25
0
 void set(T &t) {
   set_data(&t);
   set_size(sizeof(t));
 }
Beispiel #26
0
static inline int do_32(unsigned long inst, struct pt_regs *regs)
{
	int imm, regular, load, len, sign_ext;
	unsigned long unaligned_addr, target_val, shift;

	unaligned_addr = *idx_to_addr(regs, RA(inst));

	switch ((inst >> 25) << 1) {

	case 0x02:		/* LHI       */
		imm = 1;
		regular = 1;
		load = 1;
		len = 2;
		sign_ext = 0;
		break;
	case 0x0A:		/* LHI.bi    */
		imm = 1;
		regular = 0;
		load = 1;
		len = 2;
		sign_ext = 0;
		break;
	case 0x22:		/* LHSI      */
		imm = 1;
		regular = 1;
		load = 1;
		len = 2;
		sign_ext = 1;
		break;
	case 0x2A:		/* LHSI.bi   */
		imm = 1;
		regular = 0;
		load = 1;
		len = 2;
		sign_ext = 1;
		break;
	case 0x04:		/* LWI       */
		imm = 1;
		regular = 1;
		load = 1;
		len = 4;
		sign_ext = 0;
		break;
	case 0x0C:		/* LWI.bi    */
		imm = 1;
		regular = 0;
		load = 1;
		len = 4;
		sign_ext = 0;
		break;
	case 0x12:		/* SHI       */
		imm = 1;
		regular = 1;
		load = 0;
		len = 2;
		sign_ext = 0;
		break;
	case 0x1A:		/* SHI.bi    */
		imm = 1;
		regular = 0;
		load = 0;
		len = 2;
		sign_ext = 0;
		break;
	case 0x14:		/* SWI       */
		imm = 1;
		regular = 1;
		load = 0;
		len = 4;
		sign_ext = 0;
		break;
	case 0x1C:		/* SWI.bi    */
		imm = 1;
		regular = 0;
		load = 0;
		len = 4;
		sign_ext = 0;
		break;

	default:
		switch (inst & 0xff) {

		case 0x01:	/* LH        */
			imm = 0;
			regular = 1;
			load = 1;
			len = 2;
			sign_ext = 0;
			break;
		case 0x05:	/* LH.bi     */
			imm = 0;
			regular = 0;
			load = 1;
			len = 2;
			sign_ext = 0;
			break;
		case 0x11:	/* LHS       */
			imm = 0;
			regular = 1;
			load = 1;
			len = 2;
			sign_ext = 1;
			break;
		case 0x15:	/* LHS.bi    */
			imm = 0;
			regular = 0;
			load = 1;
			len = 2;
			sign_ext = 1;
			break;
		case 0x02:	/* LW        */
			imm = 0;
			regular = 1;
			load = 1;
			len = 4;
			sign_ext = 0;
			break;
		case 0x06:	/* LW.bi     */
			imm = 0;
			regular = 0;
			load = 1;
			len = 4;
			sign_ext = 0;
			break;
		case 0x09:	/* SH        */
			imm = 0;
			regular = 1;
			load = 0;
			len = 2;
			sign_ext = 0;
			break;
		case 0x0D:	/* SH.bi     */
			imm = 0;
			regular = 0;
			load = 0;
			len = 2;
			sign_ext = 0;
			break;
		case 0x0A:	/* SW        */
			imm = 0;
			regular = 1;
			load = 0;
			len = 4;
			sign_ext = 0;
			break;
		case 0x0E:	/* SW.bi     */
			imm = 0;
			regular = 0;
			load = 0;
			len = 4;
			sign_ext = 0;
			break;

		default:
			return -EFAULT;
		}
	}

	if (imm)
		shift = GET_IMMSVAL(IMM(inst)) * len;
	else
		shift = *idx_to_addr(regs, RB(inst)) << SV(inst);

	if (regular)
		unaligned_addr += shift;

	if (load) {

		if (!access_ok(VERIFY_READ, (void *)unaligned_addr, len))
			return -EACCES;

		get_data(unaligned_addr, &target_val, len);

		if (sign_ext)
			*idx_to_addr(regs, RT(inst)) =
			    sign_extend(target_val, len);
		else
			*idx_to_addr(regs, RT(inst)) = target_val;
	} else {

		if (!access_ok(VERIFY_WRITE, (void *)unaligned_addr, len))
			return -EACCES;

		target_val = *idx_to_addr(regs, RT(inst));
		set_data((void *)unaligned_addr, target_val, len);
	}

	if (!regular)
		*idx_to_addr(regs, RA(inst)) = unaligned_addr + shift;

	regs->ipc += 4;

	return 0;
fault:
	return -EACCES;
}
Beispiel #27
0
void dochallenge() {
  string inpfile = CONFIG->GetTmpfile_path() + tmpnam();
  retbott.Settype(CHALLENGE_REPORT);
  datagen = NULL;
  retbott.Setcha_id(bott->Getcha_id());
  if (set_data(inpfile)) {
    //failtogen
    retbott.Setcha_result("Challenge Error");
    retbott.Setcha_detail("Generator Failed: " + datagen->Getresult());
    if (datagen != NULL) delete datagen;
  } else {
    string check_result_filename = CONFIG->GetTmpfile_path() + tmpnam();
    int check_stat = check_data(bott->Getpid(), inpfile, check_result_filename);
    if (check_stat == 1) {
      retbott.Setcha_result("Challenge Error");
      retbott.Setcha_detail("Data Check Failed: " + checker->Getresult() +
      "\nChecker Output Detail:\n--------------------------\n" +
      Loadallfromfile(check_result_filename) +
      "\n--------------------------\nInvalid Data!!");
    } else if (check_stat == -1) {
      retbott.Setcha_result("Challenge Error");
      retbott.Setcha_detail("No Config File For Problem: " +
      Inttostring(bott->Getpid()));
    } else {
      stdprogram = new Program;
      int stdres = run_program(stdprogram, inpfile,
                               Loadallfromfile(problem->Getsolution_filename()),
                               problem->Getsolution_language());
      while (stdprogram->Getresult() == "Compile Error") {
        stdprogram->Setcompiled(false);
        stdprogram->Run();
        if (stdprogram->Getresult() != "Normal") stdres = 1;
        else stdres = 0;
      }
      usrprogram = new Program;
      int usrres = run_program(usrprogram, inpfile, bott->Getsrc(),
                               bott->Getlanguage());
      while (usrprogram->Getresult() == "Compile Error") {
        usrprogram->Setcompiled(false);
        usrprogram->Run();
        if (usrprogram->Getresult() != "Normal") usrres = 1;
        else usrres = 0;
      }
      if (stdres != 0) {
        retbott.Setcha_result("Challenge Error");
        retbott.Setcha_detail(
            "Standard Program Failed: " + stdprogram->Getresult());
      } else if (usrres != 0) {
        retbott.Setcha_result("Challenge Success");
        string newf = "cha_" + tmpnam();
        copyfile(
            stdprogram->Getin_filename(),
            "testdata/" + Inttostring(bott->Getpid()) + "/" + newf + ".in");
        copyfile(
            stdprogram->Getout_filename(),
            "testdata/" + Inttostring(bott->Getpid()) + "/" + newf + ".out");
        retbott.Setcha_detail("Standard: " + stdprogram->Getresult() +
            "  User: "******"Challenge Failed");
          retbott.Setcha_detail("Same Result.");
        } else if (cres == PE_STATUS) {
          retbott.Setcha_result("Challenge Success");
          retbott.Setcha_detail(
              "Presentation Error.\nComparator Output Detail:"
              "\n--------------------------\n" + cmp->Getdetail() +
              "\n--------------------------");
          string newf = "cha_" + tmpnam();
          copyfile(
              stdprogram->Getin_filename(),
              "testdata/" + Inttostring(bott->Getpid()) + "/" + newf + ".in");
          copyfile(
              stdprogram->Getout_filename(),
              "testdata/" + Inttostring(bott->Getpid()) + "/" + newf + ".out");
        } else if (cres == JE_STATUS) {
          retbott.Setcha_result("Challenge Failed");
          retbott.Setcha_detail("No SPJ.");
        } else {
          retbott.Setcha_result("Challenge Success");
          string newf = "cha_" + tmpnam();
          copyfile(
              stdprogram->Getin_filename(),
              "testdata/" + Inttostring(bott->Getpid()) + "/" + newf + ".in");
          copyfile(
              stdprogram->Getout_filename(),
              "testdata/" + Inttostring(bott->Getpid()) + "/" + newf + ".out");
          retbott.Setcha_detail(
              "Wrong Answer.\nComparator Output Detail:"
              "\n--------------------------\n" + cmp->Getdetail() +
              "\n--------------------------");
        }
        delete cmp;
      }
      delete stdprogram;
      delete usrprogram;
    }
    delete problem;
    delete checker;
    if (datagen != NULL) delete datagen;
  }
  retbott.Setout_filename("cha_results/" + Inttostring(retbott.Getcha_id()));
  retbott.toFile();
  send_result(retbott.Getout_filename());
}
Beispiel #28
0
bool session::flush()
{
	if (!dirty_)
		return true;
	dirty_ = false;

	string buf(256);

	// 调用纯虚接口,获得原来的 sid 数据
	if (get_data(sid_->buf, buf) == true)
	{
		if (!sid_saved_)
			sid_saved_ = true;
		deserialize(buf, attrs_);  // 反序列化
	}

	std::map<string, VBUF*>::iterator it_cache = attrs_cache_.begin();
	for (; it_cache != attrs_cache_.end(); ++it_cache)
	{
		// 如果该属性已存在,则需要先释放原来的属性值后再添加新值

		std::map<string, VBUF*>::iterator it_attr =
			attrs_.find(it_cache->first);
		if (it_attr == attrs_.end())
		{
			if (it_cache->second->todo == TODO_SET)
				attrs_[it_cache->first] = it_cache->second;
			else
				vbuf_free(it_cache->second);
		}
		else if (it_cache->second->todo == TODO_SET)
		{
			// 清除旧的数据
			vbuf_free(it_attr->second);
			// 设置新的数据
			attrs_[it_cache->first] = it_cache->second;
		}
		else if (it_cache->second->todo == TODO_DEL)
		{
			vbuf_free(it_attr->second);
			attrs_.erase(it_attr);
			vbuf_free(it_cache->second);
		}
		else
		{
			logger_warn("unknown todo(%d)", (int) it_cache->second->todo);
			vbuf_free(it_cache->second);
		}
	}

	// 清除缓存的数据:因为内部的数据已经被添加至 attrs_ 中,
	// 所以只需要将 attrs_cache_ 空间清除即可
	attrs_cache_.clear();

	serialize(attrs_, buf);  // 序列化数据
	attrs_clear(attrs_);  // 清除属性集合数据

	// 调用纯虚接口,向 memcached 或类似缓存中添加数据
	if (set_data(sid_->buf, buf.c_str(), buf.length(), ttl_) == false)
	{
		logger_error("set cache error, sid(%s)", sid_->buf);
		return false;
	}

	if (!sid_saved_)
		sid_saved_ = true;
	return true;
}
CL_GUIMessage_Close::CL_GUIMessage_Close()
{
	set_type("window close");
	set_data("window close", CL_SharedPtr<CL_GUIMessage_CloseData>(new CL_GUIMessage_CloseData));
}
int main (void)
{
        char x, y, temp, q;
    ioinit(); //Setup IO pins and defaults
        //USART_Init( MYUBRR);
        set_baud(6);//115200
        rprintf_devopen(put_char); /* init rrprintf */
        
        //check for existing preset values==============================================================
        temp = EEPROM_read((unsigned int)BPS);
        
        if ((temp < 1) | (temp > 6))//BPS will only be 1-6
        {
                cli();//Disable Interrupts
                
                EEPROM_write((unsigned int) BPS, 6);
                EEPROM_write((unsigned int) BACKLIGHT, 100);
                EEPROM_write((unsigned int) SPLASH, 1);
                EEPROM_write((unsigned int) REV, 0);
                
                sei();//Enable Interrupts
                
                BL_dutycycle = 100;
                baud_rate = 6;
                splash_screen = 1;
                reverse = 0;
        }
        
        else
        {
                baud_rate = temp;
                BL_dutycycle = EEPROM_read((unsigned int)BACKLIGHT);
                splash_screen = EEPROM_read((unsigned int)SPLASH);
                reverse = EEPROM_read((unsigned int)REV);
        }
        
        
        //Reset the display
        PORTC &= ~(1 << RESET);
        delay_ms(50);
        PORTC |= (1 << RESET);
        //delay_ms(500);

        
        clear_screen();

        set_page(0);
        
        set_x(0);
        
        display_on();
        
        //set display start line to 0
        //set control lines
        PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));//down
        
        set_data(0xC0);
        //set_data(0xFF);
        delay();
        PORTC |= (1 << EN);//up
        delay();
        PORTC &= ~(1 << EN);//down
        delay();
        PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));//all high
        
        delay();
        
        x_offset = 0;

        set_page(0);
        
        DDRB |= (1<<BL_EN);//set PB2 as output
        
        set_backlight(BL_dutycycle);
        
        //Logo==========================================================
        if (splash_screen == 1)
        {
                y = 40;
                
                for (q = 0; q < 30; q++)
                {
                        temp = logo[q];
                        for (x = 56; x < 64; x++)
                        {
                                if (temp & 0x80) pixel(1,x,y);
                                
                                temp <<= 1;
                        }
                        
                        q++;
                        
                        temp = logo[q];
                        for (x = 64; x < 72; x++)
                        {
                                if (temp & 0x80) pixel(1,x,y);
                                
                                temp <<= 1;
                        }
                        y--;
        
                }        
        }
        
        pixel(0,0,0);//cheat
        
        RX_in = 0;
        
        delay_ms(1000);
        clear_screen();
        
        if (RX_in > 0)//revert to 115200
        {
                print_char(1,'1');
                print_char(1,'1');
                print_char(1,'5');
                print_char(1,'2');
                print_char(1,'0');
                print_char(1,'0');
                
                baud_rate = 6;
                set_baud(6);//115200
                
                cli();
                
                EEPROM_write((unsigned int) BPS, 6);
                
                sei();//Enable Interrupts
        }
        
        else (set_baud(baud_rate));
        
        delay_ms(1000);
        clear_screen();
        
        //main loop===================================================
        while(1)
        {
                if(RX_in != RX_read)
                {
                        x = RX_array[RX_read];
                        RX_read++;
                        if(RX_read >= 416) RX_read = 0;
                        
                        //Backspace===================================================
                        if(x == 8) del_char(0);
                        
                        //Special commands
                        else if (x == 124)
                        {        
                                //make sure the next byte is there
                                while(RX_in == RX_read);
                                
                                //0, clear screen======================================================
                                if(RX_array[RX_read] == 0)//^@
                                {
                                        clear_screen();
                                        RX_read++;
                                        if(RX_read >= 416) RX_read = 0;
                                }
                                
                                //demo mode
                                else if(RX_array[RX_read] == 4)//^d
                                {
                                        RX_in = 0, RX_read = 0;
                                        demo();
                                        clear_screen();
                                        RX_in = 0;
                                }
                                
                                
                                //reverse mode
                                else if(RX_array[RX_read] == 18)//^r
                                {
                                        reverse ^= 1;
                                        clear_screen();
                                        RX_read++;
                                        if(RX_read >= 416) RX_read = 0;
                                        
                                        cli();
                                        EEPROM_write((unsigned int) REV, reverse);
                                        sei();
                                }
                                
                                
                                //toggle spasl screen
                                else if(RX_array[RX_read] == 19)//^s
                                {
                                        splash_screen ^= 1;
                                        //clear_screen();
                                        RX_read++;
                                        if(RX_read >= 416) RX_read = 0;
                                        
                                        cli();
                                        EEPROM_write((unsigned int) SPLASH, splash_screen);
                                        sei();
                                }
                                
                                else
                                {
                                        //set backlight (0 to 100)=========================================================
                                        if(RX_array[RX_read] == 2)//^b
                                        {
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                                while(RX_in == RX_read);//wait for byte
                                                BL_dutycycle = RX_array[RX_read];
                                                
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                                
                                                set_backlight(BL_dutycycle);
                                                
                                                cli();
                                                EEPROM_write((unsigned int) BACKLIGHT, BL_dutycycle);
                                                sei();
                                                
                                                

                                        }
                                        
                                        
                                        //change baud rate=========================================================
                                        if(RX_array[RX_read] == 7)//^g
                                        {
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                                while(RX_in == RX_read);//wait for byte
                                                //if (RX_array[RX_read] == '1') USART_Init( 1000000/2400-1);//4800
                                                //else if (RX_array[RX_read] == '2') USART_Init( 1000000/4800-1);//9600
                                                //else if (RX_array[RX_read] == '3') USART_Init( 1000000/9600-1);//19200
                                                //else if (RX_array[RX_read] == '4') USART_Init( 1000000/19200-1);//38400
                                                //else if (RX_array[RX_read] == '5') USART_Init( 1000000/28800-1);//57600
                                                //else if (RX_array[RX_read] == '6') USART_Init( 1000000/57600-1);//115200
                                                
                                                if ((RX_array[RX_read] > '0') * (RX_array[RX_read] < '7')) baud_rate = (RX_array[RX_read]) - 48;
                                                
                                                set_baud(baud_rate);
                                                
                                                cli();
                                                EEPROM_write((unsigned int) BPS, baud_rate);
                                                sei();
                                                
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                                
                                        }        
                                        
                                        
                                        //set x or y=========================================================
                                        if((RX_array[RX_read] == 24) | (RX_array[RX_read] == 25))//^x or ^y
                                        {
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                                while(RX_in == RX_read);//wait for byte
                                                if (RX_array[RX_read-1] == 24) x_offset = RX_array[RX_read];
                                                else if (RX_array[RX_read-1] == 25) y_offset = RX_array[RX_read];
                                                
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                                
                                                if (x_offset > 159) x_offset = 159;
                                                if (y_offset > 127) y_offset = 127;

                                        }

                                        //set pixel=========================================================
                                        if (RX_array[RX_read] == 16)//^p
                                        {
                                                //need 3 bytes
                                                for (y = 0; y < 3; y++)
                                                {
                                                        RX_read++;
                                                        if(RX_read >= 416) RX_read = 0;
                                                        while(RX_in == RX_read);//wait for byte
                                                }
                                                
                                                pixel(RX_array[RX_read], RX_array[RX_read-2], RX_array[RX_read-1]);
                                                
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;

                                        }

                                        
                                        //<ctrl>c, circle======================================================
                                        if(RX_array[RX_read] == 3)//^c
                                        {
                                                //need 4 bytes
                                                for (y = 0; y < 4; y++)
                                                {
                                                        RX_read++;
                                                        if(RX_read >= 416) RX_read = 0;
                                                        while(RX_in == RX_read);//wait for byte
                                                }
                                                
                                                circle(RX_array[RX_read], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1]);
                                                
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                        }
                                        
                                        
                                        //<ctrl>e, erase block======================================================
                                        if(RX_array[RX_read] == 5)//^e
                                        {
                                                //need 4 bytes
                                                for (y = 0; y < 4; y++)
                                                {
                                                        RX_read++;
                                                        if(RX_read >= 416) RX_read = 0;
                                                        while(RX_in == RX_read);//wait for byte
                                                }
                                                
                                                erase_block(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
                                                
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                        }
                                        
                                        
                                        //box======================================================
                                        if(RX_array[RX_read] == 15)//^o
                                        {
                                                //need 4 bytes
                                                for (y = 0; y < 4; y++)
                                                {
                                                        RX_read++;
                                                        if(RX_read >= 416) RX_read = 0;
                                                        while(RX_in == RX_read);//wait for byte
                                                }
                                                
                                                box(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
                                                
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                        }


                                        //line========================================================
                                        else if (RX_array[RX_read] == 12)//^l
                                        {
                                                //need 5 bytes
                                                for (y = 0; y < 5; y++)
                                                {
                                                        RX_read++;
                                                        if(RX_read >= 416) RX_read = 0;
                                                        while(RX_in == RX_read);//wait for byte
                                                }
                                                
                                                line(RX_array[RX_read], RX_array[RX_read-4], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read+-1]);
                                                RX_read++;
                                                if(RX_read >= 416) RX_read = 0;
                                        }
                                        
                                        
                                }
        
                        }
                        
                        //print character to the screen===============================================
                        else
                        {
                                del_char(1);
                                print_char(1, x);
                        }
                }
                
        }
        
        //demo();
        


    
}