--- deliantra/server/socket/request.C 2006/12/16 21:40:26 1.44 +++ deliantra/server/socket/request.C 2006/12/23 09:41:55 1.52 @@ -140,22 +140,19 @@ static void clear_map (player *pl) { - client &socket = *pl->socket; + memset (&pl->ns->lastmap, 0, sizeof (pl->ns->lastmap)); - memset (&socket.lastmap, 0, sizeof (socket.lastmap)); + if (pl->ns->newmapcmd == 1) + pl->ns->send_packet ("newmap"); - if (socket.newmapcmd == 1) - socket.send_packet ("newmap"); - - socket.update_look = 1; - socket.look_position = 0; + pl->ns->floorbox_reset (); } /** check for map change and send new map data */ static void check_map_change (player *pl) { - client &socket = *pl->socket; + client &socket = *pl->ns; object *ob = pl->ob; char buf[MAX_BUF]; /* eauugggh */ @@ -199,8 +196,7 @@ else { socket_map_scroll (&socket, ob->x - socket.current_x, ob->y - socket.current_y); - socket.update_look = 1; - socket.look_position = 0; + socket.floorbox_reset (); } } @@ -259,6 +255,12 @@ } void +ExtiCmd (char *buf, int len, client *ns) +{ + INVOKE_CLIENT (EXTICMD, ns, ARG_DATA (buf, len)); +} + +void MapInfoCmd (char *buf, int len, player *pl) { // ob->map; sint16 dx, dy; - int mapx = pl->socket->mapx / 2 - pl->ob->x; - int mapy = pl->socket->mapy / 2 - pl->ob->y; + int mapx = pl->ns->mapx / 2 - pl->ob->x; + int mapy = pl->ns->mapy / 2 - pl->ob->y; int max_distance = 8; // limit maximum path length to something generous while (*buf && map && max_distance) @@ -342,7 +344,7 @@ else snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); - pl->socket->send_packet (bigbuf); + pl->ns->send_packet (bigbuf); } /** This is the Setup cmd - easy first implementation */ @@ -399,10 +401,7 @@ safe_strcat (cmdback, param, &slen, HUGE_BUF); } else if (!strcmp (cmd, "exp64")) - { - ns->exp64 = atoi (param); - safe_strcat (cmdback, param, &slen, HUGE_BUF); - } + safe_strcat (cmdback, param, &slen, HUGE_BUF); else if (!strcmp (cmd, "spellmon")) { ns->monitor_spells = atoi (param); @@ -569,10 +568,7 @@ void AddMeCmd (char *buf, int len, client * ns) { - if (ns->status != Ns_Add || add_player (ns)) - ns->send_packet ("addme_failed"); - else - ns->send_packet ("addme_success"); + INVOKE_CLIENT (ADDME, ns, ARG_DATA (buf, len)); } /** Reply to ExtendedInfos command */ @@ -719,10 +715,9 @@ ns->faces_sent[face] |= NS_FACESENT_SMOOTH; - packet sl; + packet sl ("smooth"); - sl << "smooth " - << uint16 (face) + sl << uint16 (face) << uint16 (smoothface); ns->send_packet (sl); @@ -809,16 +804,27 @@ : time = (int) (MAX_TIME / FABS (pl->ob->speed)); /* Send confirmation of command execution now */ - packet sl; - sl << "comc " << uint16 (cmdid) << uint32 (time); - pl->socket->send_packet (sl); + packet sl ("comc"); + sl << uint16 (cmdid) << uint32 (time); + pl->ns->send_packet (sl); } - /** This is a reply to a previous query. */ void -ReplyCmd (char *buf, int len, player *pl) +ReplyCmd (char *buf, int len, client *ns) { + if (ns->state == ST_CUSTOM) + { + INVOKE_CLIENT (REPLY, ns, ARG_DATA (buf, len)); + return; + } + + if (!ns->pl) + return; //TODO: depends on the exact reply we are after + //TODO: but right now, we always have a ns->pl + + player *pl = ns->pl; + /* This is to synthesize how the data would be stored if it * was normally entered. A bit of a hack, and should be cleaned up * once all the X11 code is removed from the server. @@ -831,25 +837,13 @@ /* this avoids any hacking here */ - switch (pl->state) + switch (ns->state) { case ST_PLAYING: LOG (llevError, "Got reply message with ST_PLAYING input state\n"); break; - case ST_PLAY_AGAIN: - /* We can check this for return value (2==quit). Maybe we - * should, and do something appropriate? - */ - receive_play_again (pl->ob, buf[0]); - break; - - case ST_ROLL_STAT: - key_roll_stat (pl->ob, buf[0]); - break; - case ST_CHANGE_CLASS: - key_change_class (pl->ob, buf[0]); break; @@ -857,26 +851,12 @@ key_confirm_quit (pl->ob, buf[0]); break; - case ST_CONFIGURE: - LOG (llevError, "In client input handling, but into configure state\n"); - pl->state = ST_PLAYING; - break; - - case ST_GET_NAME: - receive_player_name (pl->ob, 13); - break; - - case ST_GET_PASSWORD: - case ST_CONFIRM_PASSWORD: - receive_player_password (pl->ob, 13); - break; - case ST_GET_PARTY_PASSWORD: /* Get password for party */ receive_party_password (pl->ob, 13); break; default: - LOG (llevError, "Unknown input state: %d\n", pl->state); + LOG (llevError, "Unknown input state: %d\n", ns->state); } } @@ -1033,8 +1013,7 @@ char buf[MAX_BUF]; uint16 flags; - packet sl; - sl << "stats "; + packet sl ("stats"); if (pl->ob) { @@ -1045,33 +1024,28 @@ AddIfShort (pl->last_stats.grace, pl->ob->stats.grace, CS_STAT_GRACE); AddIfShort (pl->last_stats.maxgrace, pl->ob->stats.maxgrace, CS_STAT_MAXGRACE); AddIfShort (pl->last_stats.Str, pl->ob->stats.Str, CS_STAT_STR); - AddIfShort (pl->last_stats.Int, pl->ob->stats.Int, CS_STAT_INT); - AddIfShort (pl->last_stats.Pow, pl->ob->stats.Pow, CS_STAT_POW); - AddIfShort (pl->last_stats.Wis, pl->ob->stats.Wis, CS_STAT_WIS); AddIfShort (pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); AddIfShort (pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON); + AddIfShort (pl->last_stats.Int, pl->ob->stats.Int, CS_STAT_INT); + AddIfShort (pl->last_stats.Wis, pl->ob->stats.Wis, CS_STAT_WIS); + AddIfShort (pl->last_stats.Pow, pl->ob->stats.Pow, CS_STAT_POW); AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); } - if (pl->socket->exp64) - for (int s = 0; s < NUM_SKILLS; s++) - if (pl->last_skill_ob[s] && pl->last_skill_exp[s] != pl->last_skill_ob[s]->stats.exp) - { - /* Always send along the level if exp changes. This is only - * 1 extra byte, but keeps processing simpler. - */ - sl << uint8 (s + CS_STAT_SKILLINFO) - << uint8 (pl->last_skill_ob[s]->level) - << uint64 (pl->last_skill_ob[s]->stats.exp); - - pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; - } + for (int s = 0; s < NUM_SKILLS; s++) + if (pl->last_skill_ob[s] && pl->last_skill_exp[s] != pl->last_skill_ob[s]->stats.exp) + { + /* Always send along the level if exp changes. This is only + * 1 extra byte, but keeps processing simpler. + */ + sl << uint8 (s + CS_STAT_SKILLINFO) + << uint8 (pl->last_skill_ob[s]->level) + << uint64 (pl->last_skill_ob[s]->stats.exp); - if (pl->socket->exp64) - { AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64) } - else - { AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP) } + pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; + } + AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64); AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); AddIfShort (pl->last_stats.wc, pl->ob->stats.wc, CS_STAT_WC); AddIfShort (pl->last_stats.ac, pl->ob->stats.ac, CS_STAT_AC); @@ -1090,7 +1064,7 @@ AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); - if (pl->socket->sc_version < 1025) + if (pl->ns->sc_version < 1025) { AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) } else for (int i = 0; i < NROFATTACKS; i++) @@ -1102,7 +1076,7 @@ AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]); } - if (pl->socket->monitor_spells) + if (pl->ns->monitor_spells) { AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); AddIfInt (pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL); @@ -1110,13 +1084,13 @@ } rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */ - AddIfString (pl->socket->stats.range, buf, CS_STAT_RANGE); + AddIfString (pl->ns->stats.range, buf, CS_STAT_RANGE); set_title (pl->ob, buf); - AddIfString (pl->socket->stats.title, buf, CS_STAT_TITLE); + AddIfString (pl->ns->stats.title, buf, CS_STAT_TITLE); /* Only send it away if we have some actual data */ if (sl.length () > 6) - pl->socket->send_packet (sl); + pl->ns->send_packet (sl); } /** @@ -1127,15 +1101,14 @@ { pl->last_weight = weight; - packet sl; - sl << "player "; + packet sl ("player"); sl << uint32 (pl->ob->count) << uint32 (weight) << uint32 (pl->ob->face->number) << data8 (pl->ob->name); - pl->socket->send_packet (sl); + pl->ns->send_packet (sl); SET_FLAG (pl->ob, FLAG_CLIENT_SENT); } @@ -1159,10 +1132,9 @@ return; } - packet sl; + packet sl ("anim"); - sl << "anim " - << uint16 (anim_num) + sl << uint16 (anim_num) << uint16 (0); /* flags - not used right now */ /* Build up the list of faces. Also, send any information (ie, the @@ -1593,7 +1565,7 @@ * and use the other 4 bits for other informatiion. For full documentation * of what we send, see the doc/Protocol file. * I will describe internally what we do: - * the socket->lastmap shows how the map last looked when sent to the client. + * the ns->lastmap shows how the map last looked when sent to the client. * in the lastmap structure, there is a cells array, which is set to the * maximum viewable size (As set in config.h). * in the cells, there are faces and a count value. @@ -1614,14 +1586,13 @@ uint8 extendedinfos; maptile *m; - client &socket = *pl->contr->socket; + client &socket = *pl->contr->ns; check_map_change (pl->contr); - packet sl; + packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a"); packet esl; - sl << (socket.mapmode == Map1Cmd ? "map1 " : "map1a "); startlen = sl.length (); /*Extendedmapinfo structure initialisation */ @@ -1675,7 +1646,6 @@ ax = 0; for (x = pl->x - socket.mapx / 2; x < max_x; x++, ax++) { - emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; /* If this space is out of the normal viewable area, we only check @@ -2015,29 +1985,25 @@ memset (&newmap, 0, sizeof (struct Map)); - for (j = (pl->y - pl->contr->socket->mapy / 2); j < (pl->y + (pl->contr->socket->mapy + 1) / 2); j++) - { - for (i = (pl->x - pl->contr->socket->mapx / 2); i < (pl->x + (pl->contr->socket->mapx + 1) / 2); i++) - { - ax = i; - ay = j; - m = pm; - mflags = get_map_flags (m, &m, ax, ay, &ax, &ay); + for (j = (pl->y - pl->contr->ns->mapy / 2); j < (pl->y + (pl->contr->ns->mapy + 1) / 2); j++) + for (i = (pl->x - pl->contr->ns->mapx / 2); i < (pl->x + (pl->contr->ns->mapx + 1) / 2); i++) + { + ax = i; + ay = j; + m = pm; + mflags = get_map_flags (m, &m, ax, ay, &ax, &ay); - if (mflags & P_OUT_OF_MAP) - continue; + if (mflags & P_OUT_OF_MAP) + continue; - if (mflags & P_NEED_UPDATE) - update_position (m, ax, ay); + /* If a map is visible to the player, we don't want to swap it out + * just to reload it. This should really call something like + * swap_map, but this is much more efficient and 'good enough' + */ + if (mflags & P_NEW_MAP) + m->timeout = 50; + } - /* If a map is visible to the player, we don't want to swap it out - * just to reload it. This should really call something like - * swap_map, but this is much more efficient and 'good enough' - */ - if (mflags & P_NEW_MAP) - m->timeout = 50; - } - } /* do LOS after calls to update_position */ if (pl->contr->do_los) { @@ -2062,7 +2028,7 @@ void send_plugin_custom_message (object *pl, char *buf) { - pl->contr->socket->send_packet (buf); + pl->contr->ns->send_packet (buf); } /** @@ -2117,7 +2083,7 @@ void esrv_update_spells (player *pl) { - if (!pl->socket->monitor_spells) + if (!pl->ns->monitor_spells) return; for (object *spell = pl->ob->inv; spell; spell = spell->below) @@ -2157,7 +2123,7 @@ if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); - pl->socket->send_packet (sl); + pl->ns->send_packet (sl); } } } @@ -2166,7 +2132,7 @@ void esrv_remove_spell (player *pl, object *spell) { - if (!pl->socket->monitor_spells) + if (!pl->ns->monitor_spells) return; if (!pl || !spell || spell->env != pl->ob) @@ -2175,12 +2141,11 @@ return; } - packet sl; + packet sl ("delspell"); - sl << "delspell " - << uint32 (spell->count); + sl << uint32 (spell->count); - pl->socket->send_packet (sl); + pl->ns->send_packet (sl); } /* appends the spell *spell to the Socklist we will send the data to. */ @@ -2238,11 +2203,10 @@ return; } - if (!pl->socket->monitor_spells) + if (!pl->ns->monitor_spells) return; - packet sl; - sl << "addspell "; + packet sl ("addspell"); if (!spell) { @@ -2266,7 +2230,7 @@ if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) { - pl->socket->send_packet (sl); + pl->ns->send_packet (sl); sl.reset (); sl << "addspell "; @@ -2290,6 +2254,6 @@ } /* finally, we can send the packet */ - pl->socket->send_packet (sl); + pl->ns->send_packet (sl); }