//pickup first item under player void cGameServer::doPickup(int id) { //get slot of item at player int itemSlot = topmostItemAt(player[id].map,player[id].x,player[id].y); //return if no items if(itemSlot == -1) return; int invSlot=-1; int qty=ml_items.item[itemSlot].qty; if(getWeight(id) + ml_items.item[itemSlot].weight * abs(qty) > maxWeight(id)) { sendChatMsg(itod(id),"^RIt's too heavy.."); return; } //check if can stack if(ml_items.item[itemSlot].qty>0) { invSlot = firstItem(id,ml_items.item[itemSlot].item_template); if(invSlot!=-1) { //combine and remove ml_items.item[player[id].inventory[invSlot]].qty+=ml_items.item[itemSlot].qty; updateItem(player[id].inventory[invSlot]); removeItem(itemSlot); } } //check for empty space for new item if space not found if(invSlot==-1) invSlot=nextInventorySlot(id); //if past inventory limit then exit if(invSlot==-1) return; //if not combined and removed then move item into inventory from map if(ml_items.item[itemSlot].qty!=0) { ml_items.item[itemSlot].map=-1; ml_items.item[itemSlot].owner=id; ml_items.item[itemSlot].slot=invSlot; ml_items.item[itemSlot].life=10; updateItem(itemSlot); player[id].inventory[invSlot]=itemSlot; } //update clients sendInventoryAdd(itod(id),ml_items.item[player[id].inventory[invSlot]].graphic,ml_items.item[player[id].inventory[invSlot]].name,invSlot,qty); sendRemoveMapItem(player[id].map,player[id].x,player[id].y); }
void cGameServer::doCreateAccount(int index,char *pass,char *conf,char *email) { //password must match confirmation if(strcmp(pass,conf)!=0) { sendChatMsg(itod(index),"^BPassword confirmation does not match original"); return; } //check length of password if(strlen(pass)<4 || strlen(pass)>16) { sendChatMsg(itod(index),"^BPassword must be between 4 and 16 characters in length."); return; } //no duplicate emails if(mydb.emailExists(email)) { sendChatMsg(itod(index),"^BThere is already an account using that email address."); return; } //generate unique 7 number id char id[256]; sprintf(id,"%d%d",(rand()%8000)+1999,(rand()%800)+199); while(mydb.accountExists(id)) sprintf(id,"%d%d",(rand()%8000)+1999,(rand()%800)+199); //send email and create account char body[1024]; sprintf(body,"Welcome to Mystera Legends!\n" "Make sure to write down your account\n" "information so you dont lose it:\n" "Account ID:%s\n" "Password :%s\n" ,id,pass); /*sendEmail( "mail.mysteralegends.com", "c3RlZWw5OQ==", "MDBqdWJibGU=", "*****@*****.**", email, "Mystera Legends account information", body);*/ mydb.createAccount(id,MD5.crypt(pass),email,player[index].ip); char themsg[128]; sprintf(themsg,"^BAccount created. Please write down your new account ID: ^G%s",id); sendChatMsg(itod(index),themsg); MAKE_MSG(dlog_msg,pmsg,DLOG_MSG); pmsg.dialog=1; nh.send((unsigned char *)&pmsg,sizeof(dlog_msg),SEND_GUARANTEED,itod(index)); }
//drop a portion of an inventory slot void cGameServer::doDrop(int id,int slot,int qty) { int item=player[id].inventory[slot]; if(item==-1 || qty<=0) return; //quantity same or more so drop all if(qty >= ml_items.item[item].qty) { doDrop(id,slot); return; } if(player[id].access<=0 || //no access ml_items.item[item].qty<=0) //cant drop portion of single or empty return; //drop item on map sendAddMapItem(ml_items.item[item].graphic,player[id].map,player[id].x,player[id].y); //remove some from player inventory cItem portion = ml_items.item[item]; portion.qty = qty; ml_items.item[item].qty-=qty; updateItem(item); item=ml_items.addMapItem(player[id].map,player[id].x,player[id].y,portion); addItem(item); //remove some from client inventory sendInventoryRemove(itod(id),slot,qty); }
//drop inventory slot void cGameServer::doDrop(int id,int slot) { int item=player[id].inventory[slot]; if(item<0 || item>=ml_items.item.size()) return; if(ml_items.item[item].qty==0)//cant drop empty return; //unequip unequipSlot(id,slot); //drop item on map sendAddMapItem(ml_items.item[item].graphic,player[id].map,player[id].x,player[id].y); //remove from player inventory ml_items.item[item].owner=-1; ml_items.item[item].map=player[id].map; ml_items.item[item].x=player[id].x; ml_items.item[item].y=player[id].y; updateItem(item); player[id].inventory[slot]=-1; //remove from client inventory sendInventoryRemove(itod(id),slot,ml_items.item[item].qty); }
struct dinode * ginode(ino_t inumber) { diskaddr_t iblk; diskaddr_t dblk; int ioff; static diskaddr_t curr_dblk; static char buf[MIN_PHYS_READ]; struct dinode *ibuf; if (inumber < UFSROOTINO || (int)inumber > imax) { (void) fprintf(stderr, "bad inode number %ld to ginode\n", inumber); exit(32); } iblk = itod(&sblock, (int)inumber); dblk = fsbtodb(&sblock, iblk); ioff = itoo(&sblock, (int)inumber); if (dblk != curr_dblk) { bread(dblk, &buf[0], sizeof (buf)); curr_dblk = dblk; inode_reads++; } ibuf = (struct dinode *)&buf[0]; ibuf += ioff; return (ibuf); }
void itod(int n) { if(n>=16) { itod(n/16); } switch(n%16) { case 0 : putchar('0');break; case 1 : putchar('1');break; case 2 : putchar('2');break; case 3 : putchar('3');break; case 4 : putchar('4');break; case 5 : putchar('5');break; case 6 : putchar('6');break; case 7 : putchar('7');break; case 8 : putchar('8');break; case 9 : putchar('9');break; case 10 : putchar('a');break; case 11 : putchar('b');break; case 12 : putchar('c');break; case 13 : putchar('d');break; case 14 : putchar('e');break; case 15 : putchar('f');break; default:break; } }
int main(void) { int n; scanf("%d",&n); itod(n); putchar('\n'); return 0; }
Dinode *iget(unsigned int inode) { unsigned int bnum; unsigned int inum; bnum = itod(inode); inum = itoo(inode); readBlock(bnum, (unsigned char *) inodeBlock); return &inodeBlock[inum]; }
/* itob: convert n into characters in s in base b */ void itob(unsigned n, char s[], int b) { int i; i = 0; do { /* generate digits in reverse */ s[i++] = itod((n % b), b); } while ((n /= b) > 0); s[i] = '\0'; reverse(s); }
void turnOnLcdAndWriteTime(){//done LCD_TurnOnDisplay(); LCD_BL_State(1); RTC_GetValue(&dateTime); char time[time_len], date[date_len]; itot(time, dateTime.tm_hour, dateTime.tm_min); itod(date, dateTime.tm_mday, dateTime.tm_mon, dateTime.tm_year); LCD_Goto(3,1); LCD_WriteString(date); LCD_Goto(5,2); LCD_WriteString(time); LCD_Goto(5,3); //if(count>=0)LCD_WriteChar('*'); }
static int diskuse (const char *device, struct usage *use_by_uid) { ino_t inode; daddr32_t inode_blk; int i; int fd; int num_inodes; struct dinode inode_tab [MAXBSIZE / sizeof (struct dinode)]; union sb_union sbu; if ((fd = open (device, O_RDONLY)) == -1) { err_ret ("diskuse: %s", device); return (-1); } sync (); if (pread (fd, &sb, SBSIZE, ldbtob (SBLOCK)) == -1) { close (fd); return (-1); } num_inodes = sb.fs_ipg * sb.fs_ncg; for (inode = 0; inode < num_inodes;) { inode_blk = fsbtodb (&sb, itod (&sb, inode)); if (pread (fd, inode_tab, sb.fs_bsize, ldbtob (inode_blk)) == -1) { close (fd); return (-1); } for (i = 0; i < INOPB (&sb) && inode < num_inodes; i++, inode++) { if (inode < UFSROOTINO) continue; if ((inode_tab [i].di_mode & IFMT) == 0) continue; use_by_uid [inode_tab [i].di_uid].blocks += inode_tab [i].di_blocks; use_by_uid [inode_tab [i].di_uid].inodes++; } } return (0); }
int find(const char *path) { const char *rest; int ch; int block, off, loc, ino = ROOTINO; struct dirent *dp; for (;;) { cnt = fs->fs_bsize; bnum = fsbtodb(fs,itod(fs,ino)) + boff; if (disk_read(bnum, cnt, (vm_offset_t)iobuf)) return 0; bcopy((char *)&((struct dinode *)iobuf)[ino % fs->fs_inopb], (char *)&inode.i_di, sizeof (struct dinode)); if (!*path) return 1; while (*path == '/') path++; if (!inode.i_size || ((inode.i_mode&IFMT) != IFDIR)) return 0; for (rest = path; (ch = *rest) && ch != '/'; rest++) ; loc = 0; for (;;) { if (loc >= inode.i_size) return 0; if (!(off = blkoff(fs, loc))) { block = lblkno(fs, loc); cnt = blksize(fs, &inode, block); bnum = fsbtodb(fs, block_map(block)) + boff; if (disk_read(bnum, cnt, (vm_offset_t)iobuf)) return 0; } dp = (struct dirent *)(iobuf + off); loc += dp->d_reclen; if (dp->d_ino == 0) continue; if (strncmp(path, dp->d_name, rest - path) == 0 && dp->d_name[rest - path] == 0) break; } ino = dp->d_ino; path = rest; } }
static int openi(int n, struct iob *io) { struct dinode *dp; int cc; #if ICACHE struct icommon *ip; if (icache == 0) { icache = cacheInit(ICACHE_SIZE, sizeof(struct icommon)); } #endif ICACHE io->i_offset = 0; io->i_bn = fsbtodb(io->i_fs, itod(io->i_fs, n)) + io->i_boff; io->i_cc = io->i_fs->fs_bsize; io->i_ma = io->i_buf; #if ICACHE if (cacheFind(icache, n, 0, (char **)&ip) == 1) { io->i_ino.i_ic = *ip; cc = 0; } else { #endif ICACHE cc = devread(io); dp = (struct dinode *)io->i_buf; #if BIG_ENDIAN_FS byte_swap_inode_in(&dp[itoo(io->i_fs, n)].di_ic, &io->i_ino.i_ic); #else io->i_ino.i_ic = dp[itoo(io->i_fs, n)].di_ic; #endif BIG_ENDIAN_FS #if ICACHE *ip = io->i_ino.i_ic; } #endif ICACHE io->i_ino.i_number = n; return (cc); }
void cGameServer::doDeath(int id) { //printf("%d(%s) type %d died to %d(%s) type %d\n",id,player[id].name,player[id].type,player[id].target,player[player[id].target].name,player[player[id].target].type); //run death script mlscript.run(1005,id); if(player[id].hp > 0)//script revived player return; //announce death and assign experience if(player[id].type==PLAYER) { //exp loss player[id].exp = (unsigned long) ( float(player[id].exp) * 0.666f); sendEXPMsg(id); } if(player[id].type==NPC && player[player[id].target].type==PLAYER && player[player[id].target].lvl<255) { player[player[id].target].exp+=player[id].worth;//+expBonus(player[player[id].target].wis,player[player[id].target].lvl); sendEXPMsg(player[id].target); } //set this spot to vacant world[player[id].map].map[player[id].y][player[id].x].space=VACANT; //do loot drop if(player[id].type==NPC && player[id].state != MERCHANT) { for(int c=0; c<MAX_INV; c++) if( player[id].inventory[c]>-1) { int invitem=player[id].inventory[c]; //switch from player to ground ml_items.item[invitem].owner=-1; ml_items.item[invitem].map=player[id].map; ml_items.item[invitem].x=player[id].x; ml_items.item[invitem].y=player[id].y; player[id].inventory[c]=-1; //send add map item sendAddMapItem(ml_items.item[invitem].graphic,player[id].map,player[id].x,player[id].y); //insert into db now that item is no longer on npc mydb.insertItem(&ml_items.item[invitem]); } //refill npcs inventory doNpcFill(id); } else if(player[id].type==PLAYER) { //unequip all player[id].eLeft=-1; player[id].eRight=-1; player[id].eBody=-1; player[id].eHead=-1; player[id].eSpecial=-1; sendEquipMsg(id); //death drop for(int c=0; c<MAX_INV; c++) if( player[id].inventory[c]>-1 && rand()%3==0 && player[id].lvl>=newbieLevel && ml_items.item[player[id].inventory[c]].stack!=PERMANENT) { //send inventory removal sendInventoryRemove(itod(id),ml_items.item[player[id].inventory[c]].slot,ml_items.item[player[id].inventory[c]].qty); //send add map item sendAddMapItem(ml_items.item[player[id].inventory[c]].graphic,player[id].map,player[id].x,player[id].y); //switch from player to ground ml_items.item[player[id].inventory[c]].owner=-1; ml_items.item[player[id].inventory[c]].map=player[id].map; ml_items.item[player[id].inventory[c]].x=player[id].x; ml_items.item[player[id].inventory[c]].y=player[id].y; updateItem(player[id].inventory[c]); player[id].inventory[c]=-1; //save item } player[id].x = player[id].origin_x; player[id].y = player[id].origin_y; player[id].map = player[id].origin_map; } //reset hp player[id].hp=player[id].mhp; player[id].mp=player[id].mmp; if(player[id].origin_map!=-1) { player[id].x = player[id].origin_x; player[id].y = player[id].origin_y; player[id].map = player[id].origin_map; } if(player[id].type==PLAYER) { //send to origin sendMycrMsg(itod(id),id); } //Sleep(1000); //Death bug emulation //send back to origin for NPC if(player[id].type==NPC) { if(player[id].origin_map==-1) { removeFromMap(id,player[id].map); player[id].current_map=-1; player[id].access=-1; } player[id].randomize(); //respawn time if(!player[id].total_time) { if(player[id].state==MERCHANT) player[id].total_time = 70; else player[id].total_time = 675; } int x=0; while(world[player[id].map].map[player[id].y][player[id].x].type!=OPEN || world[player[id].map].map[player[id].y][player[id].x].space!=VACANT) { player[id].randomize(); x++; if(x>600) { newLine("map %d too crowded!\n",player[id].map); break; } } } //send hp if player if(player[id].type==PLAYER) { //save player mydb.updatePlayer(&player[id]); //send hp here sendHPMsg(id); sendMPMsg(id); } else player[id].target=-1; }
int ffs_dir (char *dirname) { char *rest, ch; int block, off, loc, map, ino = ROOTINO; struct direct *dp; /* main loop to find destination inode */ loop: /* load current inode (defaults to the root inode) */ if (!devread (fsbtodb (SUPERBLOCK, itod (SUPERBLOCK, ino)), ino % (SUPERBLOCK->fs_inopb) * sizeof (struct dinode), sizeof (struct dinode), (char *) INODE)) return 0; /* XXX what return value? */ /* if we have a real file (and we're not just printing possibilities), then this is where we want to exit */ if (!*dirname || isspace (*dirname)) { if ((INODE->i_mode & IFMT) != IFREG) { errnum = ERR_BAD_FILETYPE; return 0; } filemax = INODE->i_size; /* incomplete implementation requires this! */ fsmax = (NDADDR + NINDIR (SUPERBLOCK)) * SUPERBLOCK->fs_bsize; return 1; } /* continue with file/directory name interpretation */ while (*dirname == '/') dirname++; if (!(INODE->i_size) || ((INODE->i_mode & IFMT) != IFDIR)) { errnum = ERR_BAD_FILETYPE; return 0; } for (rest = dirname; (ch = *rest) && !isspace (ch) && ch != '/'; rest++); *rest = 0; loc = 0; /* loop for reading a the entries in a directory */ do { if (loc >= INODE->i_size) { #if 0 putchar ('\n'); #endif if (print_possibilities < 0) return 1; errnum = ERR_FILE_NOT_FOUND; *rest = ch; return 0; } if (!(off = blkoff (SUPERBLOCK, loc))) { block = lblkno (SUPERBLOCK, loc); if ((map = block_map (block)) < 0 || !devread (fsbtodb (SUPERBLOCK, map), 0, blksize (SUPERBLOCK, INODE, block), (char *) FSYS_BUF)) { errnum = ERR_FSYS_CORRUPT; *rest = ch; return 0; } } dp = (struct direct *) (FSYS_BUF + off); loc += dp->d_reclen; #ifndef STAGE1_5 if (dp->d_ino && print_possibilities && ch != '/' && (!*dirname || substring (dirname, dp->d_name) <= 0)) { if (print_possibilities > 0) print_possibilities = -print_possibilities; print_a_completion (dp->d_name); } #endif /* STAGE1_5 */ } while (!dp->d_ino || (substring (dirname, dp->d_name) != 0 || (print_possibilities && ch != '/'))); /* only get here if we have a matching directory entry */ ino = dp->d_ino; *(dirname = rest) = ch; /* go back to main loop at top of function */ goto loop; }
/* write the memory-inode out to the inode-block */ void iput(struct inode *ip, int *aibc, s4_daddr *ib) { struct s4_dinode *dp; s4_daddr d; int i,j,k; s4_daddr ib2[NIDIR]; /* a double indirect block */ filsys->s_tinode--; d = itod(ip->i_number); if(d >= filsys->s_isize) { if(error == 0) printf("ilist too small\n"); error = 1; return; } /* get the existing disk inode block to modify */ rdfs(d, buf, s4b_ino ); dp = (struct s4_dinode *)buf; /* skip to the right entry */ dp += itoo(ip->i_number); /* convert memory to disk format in buffer */ dp->di_mode = ip->i_ftype | ip->i_mode; dp->di_nlink = ip->i_nlink; dp->di_uid = ip->i_uid; dp->di_gid = ip->i_gid; dp->di_size = ip->i_size; dp->di_atime = utime; dp->di_mtime = utime; dp->di_ctime = utime; switch(ip->i_ftype) { case S_IFDIR: case S_IFREG: /* handle direct pointers */ for(i=0; i<*aibc && i<LADDR; i++) { ip->i_faddr[i] = ib[i]; ib[i] = 0; } /* handle single indirect block */ if(i < *aibc) { for(j=0; i<*aibc && j<NIDIR; j++, i++) ib[j] = ib[i]; for(; j<NIDIR; j++) ib[j] = 0; ip->i_faddr[LADDR] = alloc(); wtfs(ip->i_faddr[LADDR], (char *)ib, s4b_idx); } /* handle double indirect block */ if(i < *aibc) { for(k=0; k<NIDIR && i<*aibc; k++) { for(j=0; i<*aibc && j<NIDIR; j++, i++) ib[j] = ib[i]; for(; j<NIDIR; j++) ib[j] = 0; ib2[k] = alloc(); wtfs(ib2[k], (char *)ib, s4b_idx); } for(; k<NIDIR; k++) ib2[k] = 0; ip->i_faddr[LADDR+1] = alloc(); wtfs(ip->i_faddr[LADDR+1], (char *)ib2, s4b_idx ); } /* triple indirect block? Nope. */ if(i < *aibc) { printf("triple indirect blocks not handled\n"); } break; default: printf("bogus ftype %o\n", ip->i_ftype); exit(1); } /* convert the address list to correct disk format */ if( doswap ) s4ltol3r(dp->di_addr, ip->i_faddr, S4_NADDR); else s4ltol3(dp->di_addr, ip->i_faddr, S4_NADDR); wtfs(d, buf, s4b_ino); }