// Open a socket to a specific host/port. // static int mod_email_sock_open(const UTF8 *conhostname, u_short port, SOCKET *sock) { int cc = -1; // Let getaddrinfo() fill out the sockaddr structure for us. // MUX_ADDRINFO hints; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; hints.ai_flags = AI_ADDRCONFIG; UTF8 sPort[SBUF_SIZE]; mux_ltoa(port, sPort); MUX_ADDRINFO *servinfo; if (0 == mux_getaddrinfo(conhostname, sPort, &hints, &servinfo)) { for (MUX_ADDRINFO *p = servinfo; NULL != p; p = p->ai_next) { cc = -2; SOCKET mysock = socket(p->ai_family, p->ai_socktype, p->ai_protocol); if (0 == connect(mysock, p->ai_addr, p->ai_addrlen)) { *sock = mysock; cc = 0; break; } SOCKET_CLOSE(mysock); } mux_freeaddrinfo(servinfo); } return cc; }
// --------------------------------------------------------------------------- // add_to: Adjust an object's queue or semaphore count. // static int add_to(dbref executor, int am, int attrnum) { int aflags; dbref aowner; char *atr_gotten = atr_get(executor, attrnum, &aowner, &aflags); int num = mux_atol(atr_gotten); free_lbuf(atr_gotten); num += am; char buff[20]; size_t nlen = 0; *buff = '\0'; if (num) { nlen = mux_ltoa(num, buff); } atr_add_raw_LEN(executor, attrnum, buff, nlen); return num; }
/* --------------------------------------------------------------------------- * did_it_rlevel: Have player do something to/with thing, watching the * attributes. 'what' is actually ignored, the desclist match being used * instead. */ void did_it_rlevel ( dbref player, dbref thing, int what, const UTF8 *def, int owhat, const UTF8 *odef, int awhat, int ctrl_flags, const UTF8 *args[], int nargs ) { if (MuxAlarm.bAlarmed) { return; } UTF8 *d, *buff, *act, *charges, *bp; dbref aowner; int num, aflags; int i; bool found_a_desc; reg_ref **preserve = NULL; bool need_pres = false; // Message to player. // if (0 < what) { // Get description list. // DESC_INFO *desclist = desclist_match(player, thing); found_a_desc = false; for (i = 0; i < desclist->n; i++) { // Ok, if it's A_DESC, we need to check against A_IDESC. // if ( A_IDESC == what && A_DESC == desclist->descs[i]) { d = atr_pget(thing, A_IDESC, &aowner, &aflags); } else { d = atr_pget(thing, desclist->descs[i], &aowner, &aflags); } if ('\0' != d[0]) { // No need for the 'def' message. // found_a_desc = true; if (!need_pres) { need_pres = true; preserve = PushRegisters(MAX_GLOBAL_REGS); save_global_regs(preserve); } buff = bp = alloc_lbuf("did_it.1"); mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player, AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP), args, nargs); *bp = '\0'; if ( A_HTDESC == desclist->descs[i] && Html(player)) { safe_str(T("\r\n"), buff, &bp); *bp = '\0'; notify_html(player, buff); } else { notify(player, buff); } free_lbuf(buff); } free_lbuf(d); } if (!found_a_desc) { // No desc found... try the default desc (again). // A_DESC or A_HTDESC... the worst case we look for it twice. // d = atr_pget(thing, what, &aowner, &aflags); if ('\0' != d[0]) { // No need for the 'def' message // found_a_desc = true; if (!need_pres) { need_pres = true; preserve = PushRegisters(MAX_GLOBAL_REGS); save_global_regs(preserve); } buff = bp = alloc_lbuf("did_it.1"); mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player, AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP), args, nargs); *bp = '\0'; if ( A_HTDESC == what && Html(player)) { safe_str(T("\r\n"), buff, &bp); *bp = '\0'; notify_html(player, buff); } else { notify(player, buff); } free_lbuf(buff); } else if (def) { notify(player, def); } free_lbuf(d); } } else if ( what < 0 && def) { notify(player, def); } if (isPlayer(thing)) { d = atr_pget(mudconf.master_room, get_atr(T("ASSET_DESC")), &aowner, &aflags); if (*d) { if (!need_pres) { need_pres = true; preserve = PushRegisters(MAX_GLOBAL_REGS); save_global_regs(preserve); } buff = bp = alloc_lbuf("did_it.1"); mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player, AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP), args, nargs); *bp = '\0'; notify(player, buff); free_lbuf(buff); } free_lbuf(d); } // Message to neighbors. // dbref loc; if ( 0 < owhat && Has_location(player) && Good_obj(loc = Location(player))) { d = atr_pget(thing, owhat, &aowner, &aflags); if (*d) { if (!need_pres) { need_pres = true; preserve = PushRegisters(MAX_GLOBAL_REGS); save_global_regs(preserve); } buff = bp = alloc_lbuf("did_it.2"); mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player, AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP), args, nargs); *bp = '\0'; if (*buff) { if (aflags & AF_NONAME) { notify_except2_rlevel2(loc, player, player, thing, buff); } else { notify_except2_rlevel2(loc, player, player, thing, tprintf(T("%s %s"), Name(player), buff)); } } free_lbuf(buff); } else if (odef) { if (ctrl_flags & VERB_NONAME) { notify_except2_rlevel2(loc, player, player, thing, odef); } else { notify_except2_rlevel2(loc, player, player, thing, tprintf(T("%s %s"), Name(player), odef)); } } free_lbuf(d); } else if ( owhat < 0 && odef && Has_location(player) && Good_obj(loc = Location(player))) { if (ctrl_flags & VERB_NONAME) { notify_except2_rlevel2(loc, player, player, thing, odef); } else { notify_except2_rlevel2(loc, player, player, thing, tprintf(T("%s %s"), Name(player), odef)); } } // If we preserved the state of the global registers, restore them. // if (need_pres) { restore_global_regs(preserve); PopRegisters(preserve, MAX_GLOBAL_REGS); } // Do the action attribute. // if ( awhat > 0 && IsReal(thing, player)) { act = atr_pget(thing, awhat, &aowner, &aflags); if (*act != '\0') { charges = atr_pget(thing, A_CHARGES, &aowner, &aflags); if (*charges) { num = mux_atol(charges); if (num > 0) { buff = alloc_sbuf("did_it.charges"); mux_ltoa(num-1, buff); atr_add_raw(thing, A_CHARGES, buff); free_sbuf(buff); } else { buff = atr_pget(thing, A_RUNOUT, &aowner, &aflags); if (*buff != '\0') { free_lbuf(act); act = buff; } else { free_lbuf(act); free_lbuf(buff); free_lbuf(charges); return; } } } free_lbuf(charges); CLinearTimeAbsolute lta; wait_que(thing, player, player, AttrTrace(aflags, 0), false, lta, NOTHING, 0, act, nargs, args, mudstate.global_regs); } free_lbuf(act); } }