[ScryMUD] SVN Commit Info r728 - branches/version-2-1/mud/grrmud/server
scrymud at wanfear.com
scrymud at wanfear.com
Thu Dec 2 15:20:30 PST 2004
Author: eroper
Date: 2004-12-02 15:20:29 -0800 (Thu, 02 Dec 2004)
New Revision: 728
Modified:
branches/version-2-1/mud/grrmud/server/ServerConfig.cc
branches/version-2-1/mud/grrmud/server/ServerConfig.h
branches/version-2-1/mud/grrmud/server/command2.cc
branches/version-2-1/mud/grrmud/server/grrmud.cc
branches/version-2-1/mud/grrmud/server/spec_prc.cc
Log:
Removed some redundant code in favor of an ugly while() loop. Thought about
using goto, who knows. If anyone has a better way to handle this, please let
me know.
Vending machines now allow purchases by index ID (list). Eventually it might
be nice to merge this code in with do_buy_proc() which is used for shop
keepers.
New configuration file option: "hostname". This allows ScryMUD to bind to a
specific IP/Hostname on the machine. The default if not configured or set to
"all" is to bind to INADDR_ANY.
Fixed SO_REUSEADDR, it actually gets turned on now. This should dramatically
improve our reboot/DB-load times as we'll no longer have to wait for things in
TIME_WAIT/FIN/FIN2/etc. Actually I believe the previous code would've been
turning it off (if it were defaulted to on, which it isn't).
Attempted to fix "-1" as the first inventory id for vending machines/shop
keepers. Gave up after failing miserably. The problem is that when you issue
"buy" with no args i_th is set to 1 by the parser. Unfortunately i_th is what
is passed as the requested index id. This leads to accidental purchases, hence
the -1 "hack". I think the only way to handle this properly will be with
special-case handling in the parser. (I haven't even looked at it yet).
BUGS I FOUND BUT HAVEN'T FIXED:
Vending machines always have perm-inventory, yet add_perm_inv builder-command
attempts to work on them. This leads to some incredibly odd things happening
to the World DB.
--Khaav
Modified: branches/version-2-1/mud/grrmud/server/ServerConfig.cc
===================================================================
--- branches/version-2-1/mud/grrmud/server/ServerConfig.cc 2004-12-02 13:06:57 UTC (rev 727)
+++ branches/version-2-1/mud/grrmud/server/ServerConfig.cc 2004-12-02 23:20:29 UTC (rev 728)
@@ -2,6 +2,7 @@
ServerConfig::ServerConfig() {
port=4000;
+ hostname="all";
daemonize=0;
suid=0;
@@ -100,6 +101,9 @@
if (strcasecmp(key, "port") == 0) {
port = (int)strtol(val, NULL, 0);
}
+ else if (strcasecmp(key, "hostname") == 0) {
+ hostname=val;
+ }
else if (strcasecmp(key, "bootLoadModifier") == 0) {
bootLoadModifier = (int)strtol(val, NULL, 0);
}
Modified: branches/version-2-1/mud/grrmud/server/ServerConfig.h
===================================================================
--- branches/version-2-1/mud/grrmud/server/ServerConfig.h 2004-12-02 13:06:57 UTC (rev 727)
+++ branches/version-2-1/mud/grrmud/server/ServerConfig.h 2004-12-02 23:20:29 UTC (rev 728)
@@ -24,6 +24,7 @@
// Network
int port;
+ String hostname;
// Percent Load Modifiers
int bootLoadModifier;
Modified: branches/version-2-1/mud/grrmud/server/command2.cc
===================================================================
--- branches/version-2-1/mud/grrmud/server/command2.cc 2004-12-02 13:06:57 UTC (rev 727)
+++ branches/version-2-1/mud/grrmud/server/command2.cc 2004-12-02 23:20:29 UTC (rev 728)
@@ -1906,231 +1906,133 @@
inv.head(cell);
int id_num;
int cnt = 0;
- while ((obj_ptr = cell.next())) {
-
- id_num = obj_ptr->getIdNum();
-
- if (!obj_ptr->in_list &&
- (item_counts[id_num] == -1)) { //already done it
- continue;
- }
-
- if (detect(pc.SEE_BIT, (obj_ptr->OBJ_VIS_BIT | ROOM.getVisBit()))) {
- if (crit_owner) {
- price = crit_owner->findItemSalePrice(*obj_ptr, pc);
- }
- else if (obj_owner) {
- price = obj_ptr->getDefaultPrice();
- }
- else {
- return -1;
- }
-
- if (price < 0) {
- continue; //buf = " NOT FOR SALE NOW.";
- }//if
- // Build object restrictions string, this is retarded... should have
- // a method.
- restrict_buf = NULL_STRING;
- if (obj_ptr->OBJ_FLAGS.get(1))
- restrict_buf += "Anti-Evil ";
- if (obj_ptr->OBJ_FLAGS.get(2))
- restrict_buf += "Anti-Neutral ";
- if (obj_ptr->OBJ_FLAGS.get(3))
- restrict_buf += "Anti-Good ";
- if (obj_ptr->OBJ_FLAGS.get(4))
- restrict_buf += "Anti-Donate ";
- if (obj_ptr->OBJ_FLAGS.get(5))
- restrict_buf += "Anti-Drop ";
- if (obj_ptr->OBJ_FLAGS.get(6))
- restrict_buf += "Anti-Remove ";
- if (obj_ptr->OBJ_FLAGS.get(7))
- restrict_buf += "Anti-Mortal ";
- if (obj_ptr->OBJ_FLAGS.get(11))
- restrict_buf += "Anti-Warrior ";
- if (obj_ptr->OBJ_FLAGS.get(12))
- restrict_buf += "Anti-Sage ";
- if (obj_ptr->OBJ_FLAGS.get(13))
- restrict_buf += "Anti-Wizard ";
- if (obj_ptr->OBJ_FLAGS.get(14))
- restrict_buf += "Anti-Ranger ";
- if (obj_ptr->OBJ_FLAGS.get(15))
- restrict_buf += "Anti-Thief ";
- if (obj_ptr->OBJ_FLAGS.get(16))
- restrict_buf += "Anti-Alchemist ";
- if (obj_ptr->OBJ_FLAGS.get(17))
- restrict_buf += "Anti-Cleric ";
- if (obj_ptr->OBJ_FLAGS.get(18))
- restrict_buf += "Anti-Bard ";
- if (obj_ptr->OBJ_FLAGS.get(20))
- restrict_buf += "Anti-PC ";
- // End of object restrictions string building.
+ int done = 0;
- if (pc.shouldShowVnums()) {
- if (obj_ptr->in_list || (item_counts[id_num] == 1)) {
- Sprintf(buf, " [%i][lvl: %i]%P06 %S%P50%i %S", id_num,
- obj_ptr->getLevel(),
- &(obj_ptr->short_desc), price,
- &restrict_buf);
- }
- else {
- Sprintf(buf, " [%i][lvl: %i]%P06 [qty: %i]%P12 %S%P50%i %S", id_num,
- obj_ptr->getLevel(),
- item_counts[id_num], &(obj_ptr->short_desc), price,
- &restrict_buf);
- }
+ // This is to prevent code duplication, I debated just using goto :p
+ while ( done < 2) {
+ while ((obj_ptr = cell.next())) {
+
+ id_num = obj_ptr->getIdNum();
+
+ if (!obj_ptr->in_list &&
+ (item_counts[id_num] == -1)) { //already done it
+ continue;
}
- else {
- cnt++;
- int hack = cnt;
- if (hack == 1) {
- hack = -1;
+
+ if (detect(pc.SEE_BIT, (obj_ptr->OBJ_VIS_BIT | ROOM.getVisBit()))) {
+ if (crit_owner) {
+ price = crit_owner->findItemSalePrice(*obj_ptr, pc);
}
- if (obj_ptr->in_list || (item_counts[id_num] == 1)) {
- Sprintf(buf, " [%i][lvl: %i]%P12 %S%P50%i %S", hack,
- obj_ptr->getLevel(),
- &(obj_ptr->short_desc),
- price,
- &restrict_buf);
+ else if (obj_owner) {
+ price = obj_ptr->getDefaultPrice();
}
else {
- Sprintf(buf, " [%i][lvl: %i] [qty: %i]%P12 %S%P50%i %S", hack,
- obj_ptr->getLevel(),
- item_counts[id_num],
- &(obj_ptr->short_desc), price,
- &restrict_buf);
+ return -1;
}
- }
-
- item_counts[id_num] = -1;
-
- //if ((!obj_wear_by(*obj_ptr, pc, -1, FALSE)) &&
- // (!obj_ptr->isFood()))
- // buf.Prepend("**");
-
- if (obj_ptr->OBJ_VIS_BIT & 2) //if invisible
- buf.Append(" *\n");
- else
- buf.Append("\n");
- show(buf, pc);
- }//if detectable
- }//while
- perm_inv.head(cell);
- while ((obj_ptr = cell.next())) {
-
- id_num = obj_ptr->getIdNum();
-
- if (!obj_ptr->in_list &&
- (item_counts[id_num] == -1)) { //already done it
- continue;
- }
-
- if (detect(pc.SEE_BIT, (obj_ptr->OBJ_VIS_BIT | ROOM.getVisBit()))) {
- if (crit_owner) {
- price = crit_owner->findItemSalePrice(*obj_ptr, pc);
- }
- else if (obj_owner) {
- price = obj_owner->getDefaultPrice();
- }
- else {
- return -1;
- }
-
- if (price < 0) {
- continue; //buf = " NOT FOR SALE NOW.";
- }//if
-
- // Build object restrictions string, this is retarded... should have
- // a method.
- restrict_buf = NULL_STRING;
+ if (price < 0) {
+ continue; //buf = " NOT FOR SALE NOW.";
+ }//if
- if (obj_ptr->OBJ_FLAGS.get(1))
- restrict_buf += "Anti-Evil ";
- if (obj_ptr->OBJ_FLAGS.get(2))
- restrict_buf += "Anti-Neutral ";
- if (obj_ptr->OBJ_FLAGS.get(3))
- restrict_buf += "Anti-Good ";
- if (obj_ptr->OBJ_FLAGS.get(4))
- restrict_buf += "Anti-Donate ";
- if (obj_ptr->OBJ_FLAGS.get(5))
- restrict_buf += "Anti-Drop ";
- if (obj_ptr->OBJ_FLAGS.get(6))
- restrict_buf += "Anti-Remove ";
- if (obj_ptr->OBJ_FLAGS.get(7))
- restrict_buf += "Anti-Mortal ";
- if (obj_ptr->OBJ_FLAGS.get(11))
- restrict_buf += "Anti-Warrior ";
- if (obj_ptr->OBJ_FLAGS.get(12))
- restrict_buf += "Anti-Sage ";
- if (obj_ptr->OBJ_FLAGS.get(13))
- restrict_buf += "Anti-Wizard ";
- if (obj_ptr->OBJ_FLAGS.get(14))
- restrict_buf += "Anti-Ranger ";
- if (obj_ptr->OBJ_FLAGS.get(15))
- restrict_buf += "Anti-Thief ";
- if (obj_ptr->OBJ_FLAGS.get(16))
- restrict_buf += "Anti-Alchemist ";
- if (obj_ptr->OBJ_FLAGS.get(17))
- restrict_buf += "Anti-Cleric ";
- if (obj_ptr->OBJ_FLAGS.get(18))
- restrict_buf += "Anti-Bard ";
- if (obj_ptr->OBJ_FLAGS.get(20))
- restrict_buf += "Anti-PC ";
- // End of object restrictions string building.
-
- if (pc.shouldShowVnums()) {
- if (obj_ptr->in_list || (item_counts[id_num] == 1)) {
- Sprintf(buf, " [%i][%i]%P06 %S%P50%i %S", id_num,
- obj_ptr->getLevel(),
- &(obj_ptr->short_desc), price,
- &restrict_buf);
+ // Build object restrictions string, this is retarded... should have
+ // a method.
+ restrict_buf = NULL_STRING;
+
+ if (obj_ptr->OBJ_FLAGS.get(1))
+ restrict_buf += "Anti-Evil ";
+ if (obj_ptr->OBJ_FLAGS.get(2))
+ restrict_buf += "Anti-Neutral ";
+ if (obj_ptr->OBJ_FLAGS.get(3))
+ restrict_buf += "Anti-Good ";
+ if (obj_ptr->OBJ_FLAGS.get(4))
+ restrict_buf += "Anti-Donate ";
+ if (obj_ptr->OBJ_FLAGS.get(5))
+ restrict_buf += "Anti-Drop ";
+ if (obj_ptr->OBJ_FLAGS.get(6))
+ restrict_buf += "Anti-Remove ";
+ if (obj_ptr->OBJ_FLAGS.get(7))
+ restrict_buf += "Anti-Mortal ";
+ if (obj_ptr->OBJ_FLAGS.get(11))
+ restrict_buf += "Anti-Warrior ";
+ if (obj_ptr->OBJ_FLAGS.get(12))
+ restrict_buf += "Anti-Sage ";
+ if (obj_ptr->OBJ_FLAGS.get(13))
+ restrict_buf += "Anti-Wizard ";
+ if (obj_ptr->OBJ_FLAGS.get(14))
+ restrict_buf += "Anti-Ranger ";
+ if (obj_ptr->OBJ_FLAGS.get(15))
+ restrict_buf += "Anti-Thief ";
+ if (obj_ptr->OBJ_FLAGS.get(16))
+ restrict_buf += "Anti-Alchemist ";
+ if (obj_ptr->OBJ_FLAGS.get(17))
+ restrict_buf += "Anti-Cleric ";
+ if (obj_ptr->OBJ_FLAGS.get(18))
+ restrict_buf += "Anti-Bard ";
+ if (obj_ptr->OBJ_FLAGS.get(20))
+ restrict_buf += "Anti-PC ";
+ // End of object restrictions string building.
+
+ if (pc.shouldShowVnums()) {
+ if (obj_ptr->in_list || (item_counts[id_num] == 1)) {
+ Sprintf(buf, " [onum: %i][lvl: %i]%P06 %S%P50%i %S", id_num,
+ obj_ptr->getLevel(),
+ &(obj_ptr->short_desc), price,
+ &restrict_buf);
+ }
+ else {
+ Sprintf(buf, " [onum: %i][lvl: %i]%P06 [qty: %i]%P12 %S%P50%i %S", id_num,
+ obj_ptr->getLevel(),
+ item_counts[id_num], &(obj_ptr->short_desc), price,
+ &restrict_buf);
+ }
}
else {
- Sprintf(buf, " [%i][%i]%P06 [*%i]%P12 %S%P50%i %S", id_num,
- obj_ptr->getLevel(),
- item_counts[id_num], &(obj_ptr->short_desc), price,
- &restrict_buf);
+ cnt++;
+ int hack = cnt;
+
+ // if this isn't here you can't buy the first item by id. This
+ // is because the parser will set i_th to 1 if you just issue
+ // the "buy" command with no args. Unfortunately this means
+ // that we protect against these accidental purchases in buy()
+ if (hack == 1) {
+ hack = -1;
+ }
+
+ if (obj_ptr->in_list || (item_counts[id_num] == 1)) {
+ Sprintf(buf, " [%i][lvl: %i]%P12 %S%P50%i %S", hack,
+ obj_ptr->getLevel(),
+ &(obj_ptr->short_desc),
+ price,
+ &restrict_buf);
+ }
+ else {
+ Sprintf(buf, " [%i][lvl: %i] [qty: %i]%P12 %S%P50%i %S", hack,
+ obj_ptr->getLevel(),
+ item_counts[id_num],
+ &(obj_ptr->short_desc), price,
+ &restrict_buf);
+ }
}
- }
- else {
- cnt++;
- int hack = cnt;
- if (hack == 1) {
- hack = -1;
- }
- if (obj_ptr->in_list || (item_counts[id_num] == 1)) {
- Sprintf(buf, " [%i][%i]%P12 %S%P50%i %S", hack,
- obj_ptr->getLevel(),
- &(obj_ptr->short_desc),
- price,
- &restrict_buf);
- }
- else {
- Sprintf(buf, " [%i][%i] [*%i]%P12 %S%P50%i %S", hack,
- obj_ptr->getLevel(),
- item_counts[id_num],
- &(obj_ptr->short_desc), price,
- &restrict_buf);
- }
- }
-
- item_counts[id_num] = -1;
-
- //if ((!obj_wear_by(*obj_ptr, pc, -1, FALSE)) &&
- // (!obj_ptr->isFood()))
- // buf.Prepend("**");
-
- if (obj_ptr->OBJ_VIS_BIT & 2) //if invisible
- buf.Append(" *\n");
- else
- buf.Append("\n");
- show(buf, pc);
- }//if detectable
-
- }//while
+
+ item_counts[id_num] = -1;
+
+ //if ((!obj_wear_by(*obj_ptr, pc, -1, FALSE)) &&
+ // (!obj_ptr->isFood()))
+ // buf.Prepend("**");
+
+ if (obj_ptr->OBJ_VIS_BIT & 2) //if invisible
+ buf.Append(" *\n");
+ else
+ buf.Append("\n");
+ show(buf, pc);
+ }//if detectable
+ }//while
+ done++;
+ perm_inv.head(cell);
+ }//while (done < 2)
+
return 0;
}//do_list_merchandise
Modified: branches/version-2-1/mud/grrmud/server/grrmud.cc
===================================================================
--- branches/version-2-1/mud/grrmud/server/grrmud.cc 2004-12-02 13:06:57 UTC (rev 727)
+++ branches/version-2-1/mud/grrmud/server/grrmud.cc 2004-12-02 23:20:29 UTC (rev 728)
@@ -1369,7 +1369,7 @@
int init_socket(int port) {
int s;
- char *opt;
+ int so_reuseaddr_opt;
char hostname[MAX_HOSTNAME+1];
struct sockaddr_in sa;
struct hostent *hp;
@@ -1377,17 +1377,34 @@
mudlog.log(TRC, "in init_socket\n");
memset((char*)(&sa), 0, sizeof(struct sockaddr_in ));
+
+
+ /*
if (gethostname(hostname, MAX_HOSTNAME) < 0) {
mudlog << "ERROR: gethostname: " << strerror(errno) << endl;
//strcpy(hostname, "mogul");
}//if
- hp = gethostbyname(hostname);
- if (hp == NULL) {
- mudlog << "ERROR: gethostbyname: " << strerror(errno) << endl;
- do_shutdown = TRUE;
- exit(100);
- }//if
- sa.sin_family = hp->h_addrtype;
+ */
+
+ cout << config.hostname << endl;
+ //if ( Strncompare(config.hostname, "all") == 0 ) {
+ if ( config.hostname == "all" ) {
+ cout << "hostname any found" << endl;
+ sa.sin_addr.s_addr = htonl(INADDR_ANY);
+ sa.sin_family = AF_INET;
+ } else {
+ hp = gethostbyname(config.hostname);
+ if (hp == NULL) {
+ mudlog << "ERROR: gethostbyname: " << strerror(errno) << endl;
+ do_shutdown = TRUE;
+ exit(100);
+ } else {
+ memcpy((void *)&sa.sin_addr, (void *)hp->h_addr_list[0],
+ sizeof(sa.sin_addr));
+ sa.sin_family = hp->h_addrtype;
+ }
+ }
+
sa.sin_port = htons(port);
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
@@ -1396,7 +1413,9 @@
exit(100);
}//if
- if (setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof (opt))
+ so_reuseaddr_opt = 1;
+ if (setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (void *)&so_reuseaddr_opt,
+ sizeof(int))
< 0) {
mudlog << "ERROR: setsockopt: " << strerror(errno) << endl;
do_shutdown = TRUE;
Modified: branches/version-2-1/mud/grrmud/server/spec_prc.cc
===================================================================
--- branches/version-2-1/mud/grrmud/server/spec_prc.cc 2004-12-02 13:06:57 UTC (rev 727)
+++ branches/version-2-1/mud/grrmud/server/spec_prc.cc 2004-12-02 23:20:29 UTC (rev 728)
@@ -1111,7 +1111,7 @@
mudlog.log(ERROR, "ERROR: keeper has no proc_data in do_buy_proc.\n");
return -1;
}//else
- }//if
+ }//if (keeper.mob)
else {
mudlog.log(ERROR, "ERROR: keeper's mob is NULL in do_buy_proc.\n");
return -1;
@@ -1167,60 +1167,38 @@
keeper.inv.head(cell);
int id_num;
int cnt = 0;
- while ((tmp_optr = cell.next())) {
-
- id_num = tmp_optr->getIdNum();
-
- if (!tmp_optr->in_list &&
- (item_counts[id_num] == -1)) { //already done it
- continue;
- }
-
- if (detect(pc.SEE_BIT, (tmp_optr->OBJ_VIS_BIT | ROOM.getVisBit()))) {
- price = keeper.findItemSalePrice(*tmp_optr, pc);
-
- if (price < 0) {
- continue; //buf = " NOT FOR SALE NOW.";
- }//if
-
- cnt++;
- if (i_th == cnt) {
- obj_ptr = tmp_optr;
- break;
- }
+ int done = 0;
+ // This is to prevent code duplication, I debated just using goto :p
+ while ( done < 2 ) {
+ while ((tmp_optr = cell.next())) {
- item_counts[id_num] = -1;
- }//if detectable
- }//while
+ id_num = tmp_optr->getIdNum();
- keeper.PERM_INV.head(cell);
- while ((tmp_optr = cell.next())) {
-
- id_num = tmp_optr->getIdNum();
-
- if (!tmp_optr->in_list &&
- (item_counts[id_num] == -1)) { //already done it
- continue;
- }
-
- if (detect(pc.SEE_BIT, (tmp_optr->OBJ_VIS_BIT | ROOM.getVisBit()))) {
- price = keeper.findItemSalePrice(*tmp_optr, pc);
-
- if (price < 0) {
- continue; //buf = " NOT FOR SALE NOW.";
- }//if
-
- cnt++;
- if (i_th == cnt) {
- obj_ptr = tmp_optr;
- break;
+ if (!tmp_optr->in_list &&
+ (item_counts[id_num] == -1)) { //already done it
+ continue;
}
- item_counts[id_num] = -1;
-
- }//if detectable
+ if (detect(pc.SEE_BIT, (tmp_optr->OBJ_VIS_BIT | ROOM.getVisBit()))) {
+ price = keeper.findItemSalePrice(*tmp_optr, pc);
- }//while
+ if (price < 0) {
+ continue; //buf = " NOT FOR SALE NOW.";
+ }//if
+
+ cnt++;
+ if (i_th == cnt) {
+ obj_ptr = tmp_optr;
+ break;
+ }
+
+ item_counts[id_num] = -1;
+ }//if detectable
+ }//while
+ done++;
+ keeper.PERM_INV.head(cell);
+ }//while (done<2)
+
}//else, tried to get it by index only.
if (!obj_ptr) {
@@ -1300,7 +1278,44 @@
return -1;
}//if
- obj_ptr = have_obj_named(vendor.inv, i_th, item, pc.SEE_BIT, ROOM);
+ if (! (obj_ptr = have_obj_named(vendor.inv, i_th, item, pc.SEE_BIT, ROOM)) ) {
+ //maybe they are trying to purchase by inventory index id?
+ Cell<object*> cell(vendor.inv);
+ object* tmp_ptr = NULL;
+ static int item_counts[NUMBER_OF_ITEMS + 1];
+ int cnt;
+ int id_num;
+ cnt = id_num = 0;
+
+ memset(item_counts, 0, sizeof(int) * (NUMBER_OF_ITEMS + 1));
+
+ vendor.inv.head(cell);
+ while ( (tmp_ptr = cell.next()) ) {
+ item_counts[tmp_ptr->getIdNum()]++;
+ }
+
+ vendor.inv.head(cell);
+ while ( (tmp_ptr = cell.next()) ) {
+ id_num = tmp_ptr->getIdNum();
+
+ //already done it
+ if (!tmp_ptr->in_list && (item_counts[id_num] == -1)) {
+ continue;
+ }
+
+ if (detect(pc.SEE_BIT, (tmp_ptr->OBJ_VIS_BIT | ROOM.getVisBit()))) {
+
+ cnt++;
+ if (i_th == cnt) {
+ obj_ptr = tmp_ptr;
+ break;
+ }
+
+ item_counts[id_num] = -1;
+ }//if detectable
+ }//while
+ }//if we had to dig via index numbers...
+
if (!obj_ptr) {
Sprintf(buf, "%S doesn't dispense that.\n",
long_name_of_obj(vendor, pc.SEE_BIT));
More information about the ScryMUD
mailing list