--- deliantra/server/socket/request.C 2006/12/13 18:51:50 1.28 +++ deliantra/server/socket/request.C 2006/12/14 01:21:58 1.33 @@ -104,10 +104,10 @@ int x, y, mx, my; { - char buf[MAXSOCKBUF]; + packet sl; - sprintf (buf, "map_scroll %d %d", dx, dy); - Write_String_To_Socket (ns, buf, strlen (buf)); + sl.printf ("map_scroll %d %d", dx, dy); + ns->send_packet (sl); } /* If we are using the Map1aCmd, we may in fact send @@ -163,7 +163,7 @@ memset (&socket.lastmap, 0, sizeof (socket.lastmap)); if (socket.newmapcmd == 1) - Write_String_To_Socket (&socket, "newmap", 6); + socket.send_packet ("newmap"); socket.update_look = 1; socket.look_position = 0; @@ -204,7 +204,7 @@ else snprintf (buf, MAX_BUF, "mapinfo current"); - Write_String_To_Socket (&socket, buf, strlen (buf)); + socket.send_packet (buf); } } else if (socket.current_x != ob->x || socket.current_y != ob->y) @@ -316,7 +316,7 @@ else snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); - Write_String_To_Socket (&pl->socket, bigbuf, strlen (bigbuf)); + pl->socket.send_packet (bigbuf); } /** This is the Setup cmd - easy first implementation */ @@ -333,16 +333,19 @@ * The client then must sort this out */ - LOG (llevInfo, "Get SetupCmd:: %s\n", buf); + //LOG (llevInfo, "Get SetupCmd:: %s\n", buf); + strcpy (cmdback, "setup"); - for (s = 0; s < len;) + for (s = 0; s < len; ) { - cmd = &buf[s]; /* find the next space, and put a null there */ - for (; buf[s] && buf[s] != ' '; s++); + for (; buf[s] && buf[s] != ' '; s++) + ; + buf[s++] = 0; + while (buf[s] == ' ') s++; @@ -351,8 +354,11 @@ param = &buf[s]; - for (; buf[s] && buf[s] != ' '; s++); + for (; buf[s] && buf[s] != ' '; s++) + ; + buf[s++] = 0; + while (buf[s] == ' ') s++; @@ -523,8 +529,9 @@ safe_strcat (cmdback, "FALSE", &slen, HUGE_BUF); } } /* for processing all the setup commands */ + LOG (llevInfo, "SendBack SetupCmd:: %s\n", cmdback); - Write_String_To_Socket (ns, cmdback, strlen (cmdback)); + ns->send_packet (cmdback); } /** @@ -540,9 +547,7 @@ oldsettings = settings; if (ns->status != Ns_Add || add_player (ns)) - { - Write_String_To_Socket (ns, "addme_failed", 12); - } + ns->send_packet ("addme_failed"); else { /* Basically, the add_player copies the socket structure into @@ -550,10 +555,11 @@ * is not needed anymore. The write below should still work, as the * stuff in ns is still relevant. */ - Write_String_To_Socket (ns, "addme_success", 13); + ns->send_packet ("addme_success"); socket_info.nconns--; ns->status = Ns_Avail; } + settings = oldsettings; } @@ -607,7 +613,7 @@ strcat (cmdback, "smoothing"); } - Write_String_To_Socket (ns, cmdback, strlen (cmdback)); + ns->send_packet (cmdback); } /* @@ -670,7 +676,7 @@ strcat (cmdback, temp); } - Write_String_To_Socket (ns, cmdback, strlen (cmdback)); + ns->send_packet (cmdback); } /** @@ -701,14 +707,13 @@ ns->faces_sent[face] |= NS_FACESENT_SMOOTH; - SockList sl (MAXSOCKBUF); + packet sl; sl << "smooth " << uint16 (face) << uint16 (smoothface); Send_With_Handling (ns, &sl); - sl.free (); } /** @@ -787,7 +792,7 @@ { int time, repeat; char command[MAX_BUF]; - short packet; + int pktlen; if (len < 7) { @@ -795,8 +800,9 @@ return; } - packet = GetShort_String (buf); - repeat = GetInt_String (buf + 2); + pktlen = net_uint16 (buf); + repeat = net_uint32 (buf + 2); + /* -1 is special - no repeat, but don't update */ if (repeat != -1) pl->count = repeat; @@ -838,10 +844,9 @@ /* Send confirmation of command execution now */ - SockList sl (MAXSOCKBUF); - sl << "comc " << uint16 (packet) << uint32 (time); + packet sl; + sl << "comc " << uint16 (pktlen) << uint32 (time); Send_With_Handling (&pl->socket, &sl); - sl.free (); } @@ -963,11 +968,11 @@ * requiing this minimal value reduces complexity of that code, and it * has been around for a long time. */ - if (!strcmp (" CF DX CLIENT", cp) || ns->sc_version < 1024) + if (ns->sc_version < 1026) { sprintf (version_warning, "drawinfo %d %s", NDI_RED, "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); - Write_String_To_Socket (ns, version_warning, strlen (version_warning)); + ns->send_packet (version_warning); } } @@ -1049,7 +1054,7 @@ char buf[MAX_BUF]; sprintf (buf, "query %d %s", flags, text ? text : ""); - Write_String_To_Socket (ns, buf, strlen (buf)); + ns->send_packet (buf); } #define AddIfInt64(Old,New,Type) if (Old != New) {\ @@ -1089,7 +1094,7 @@ char buf[MAX_BUF]; uint16 flags; - SockList sl (MAXSOCKBUF); + packet sl; sl << "stats "; if (pl->ob != NULL) @@ -1189,7 +1194,6 @@ Send_With_Handling (&pl->socket, &sl); } - sl.free (); } /** @@ -1200,7 +1204,7 @@ { pl->last_weight = weight; - SockList sl (MAXSOCKBUF); + packet sl; sl << "player "; sl << uint32 (pl->ob->count) @@ -1209,7 +1213,6 @@ << data8 (pl->ob->name); Send_With_Handling (&pl->socket, &sl); - sl.free (); SET_FLAG (pl->ob, FLAG_CLIENT_SENT); } @@ -1235,7 +1238,7 @@ return; } - SockList sl (MAXSOCKBUF); + packet sl; sl << "anim " << uint16 (anim_num) @@ -1252,7 +1255,6 @@ } Send_With_Handling (ns, &sl); - sl.free (); ns->anims_sent[anim_num] = 1; } @@ -1398,7 +1400,7 @@ static long frames, bytes, tbytes, tframes; char *cur; - SockList sl (MAXSOCKBUF); + packet sl; sl << "map "; cur = (char *) compactlayer (ns, (unsigned char *) sl.buf + sl.len, MAP_LAYERS, newmap); @@ -1421,7 +1423,6 @@ ns->sent_scroll = 0; } - sl.free (); } @@ -1473,7 +1474,7 @@ * sent, it returns zero. */ static int -check_head (SockList &sl, NewSocket &ns, int ax, int ay, int layer) +check_head (packet &sl, NewSocket &ns, int ax, int ay, int layer) { short face_num; @@ -1484,7 +1485,7 @@ if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) { - SockList_AddShort (&sl, face_num); + sl << uint16 (face_num); if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) esrv_send_face (&ns, face_num, 0); @@ -1517,7 +1518,7 @@ */ static int -update_space (SockList &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) +update_space (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) { object *ob, *head; uint16 face_num; @@ -1740,7 +1741,7 @@ */ static inline int -update_smooth (SockList &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) +update_smooth (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) { object *ob; int smoothlevel; /* old face_num; */ @@ -1834,8 +1835,8 @@ check_map_change (pl->contr); - SockList sl (MAXSOCKBUF); - SockList esl (MAXSOCKBUF); + packet sl; + packet esl; sl << (socket.mapmode == Map1Cmd ? "map1 " : "map1a "); startlen = sl.len; @@ -2197,9 +2198,6 @@ Send_With_Handling (&socket, &sl); socket.sent_scroll = 0; } - - sl.free (); - esl.free (); } /** @@ -2342,7 +2340,7 @@ void send_plugin_custom_message (object *pl, char *buf) { - cs_write_string (&pl->contr->socket, buf, strlen (buf)); + pl->contr->socket.send_packet (buf); } /** @@ -2352,11 +2350,11 @@ void send_skill_info (NewSocket *ns, char *params) { - SockList sl (MAXSOCKBUF); + packet sl; sl << "replyinfo skill_info\n"; for (int i = 1; i < NUM_SKILLS; i++) - sl.len += sprintf ((char *)sl.buf + sl.len, "%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); + sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); if (sl.len >= MAXSOCKBUF) { @@ -2365,7 +2363,6 @@ } Send_With_Handling (ns, &sl); - sl.free (); } /** @@ -2375,12 +2372,12 @@ void send_spell_paths (NewSocket * ns, char *params) { - SockList sl (MAXSOCKBUF); + packet sl; sl << "replyinfo spell_paths\n"; for (int i = 0; i < NRSPELLPATHS; i++) - sl.len += sprintf ((char *)sl.buf + sl.len, "%d:%s\n", 1 << i, spellpathnames[i]); + sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); if (sl.len >= MAXSOCKBUF) { @@ -2389,7 +2386,6 @@ } Send_With_Handling (ns, &sl); - sl.free (); } /** @@ -2429,7 +2425,7 @@ if (flags) { - SockList sl (MAXSOCKBUF); + packet sl; sl << "updspell " << uint8 (flags) @@ -2440,7 +2436,6 @@ if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); Send_With_Handling (&pl->socket, &sl); - sl.free (); } } } @@ -2458,18 +2453,17 @@ return; } - SockList sl (MAXSOCKBUF); + packet sl; sl << "delspell " << uint32 (spell->count); Send_With_Handling (&pl->socket, &sl); - sl.free (); } /* appends the spell *spell to the Socklist we will send the data to. */ static void -append_spell (player *pl, SockList &sl, object *spell) +append_spell (player *pl, packet &sl, object *spell) { int len, i, skill = 0; @@ -2525,7 +2519,7 @@ if (!pl->socket.monitor_spells) return; - SockList sl (MAXSOCKBUF); + packet sl; sl << "addspell "; @@ -2576,6 +2570,5 @@ /* finally, we can send the packet */ Send_With_Handling (&pl->socket, &sl); - sl.free (); }