client common/script.c request map ?wonderfull? code
Posted: Fri Oct 09, 2015 9:39 pm
While testing and rewriting scripts to check for the player's position on the map, I had some problems with older clients writing wrong? x y positions back to stdin of the script .
client v.1.12.0 has this code :
# if ( strncmp(c,"pos",3)==0 ) { // v.1.12.0
# char buf[1024];
#
# snprintf(buf, sizeof(buf), "request map pos %d %d\n",pl_pos.x,pl_pos.y);
# write(scripts.out_fd,buf,strlen(buf));
# }
client 1.70.0 has this code :
# if (strncmp(c, "pos", 3) == 0) { // v1.70.0
# char buf[1024];
#
# snprintf(buf, sizeof(buf), "request map pos %d %d\n", pl_pos.x+use_config[CONFIG_MAPWIDTH]/2, pl_pos.y+use_config[CONFIG_MAPHEIGHT]/2);
# write(scripts.out_fd, buf, strlen(buf));
The 1.70.0 client uses additionally use_config that adds a few positive integers .
So code that works for the client v.1.70.0 does not work on 1.12.0 ( and lesser ) .
The client did not change much here from v.1.10.0 to v.1.12.0 except changing from sprintf to snprintf .
What makes me wondering, is that request map near already has this use_config included since at least v.1.10.0 :
# if ( strncmp(c,"near",4)==0 ) { // v.1.10.0
# for(y=0;y<3;++y)
# for(x=0;x<3;++x)
# send_map(i,
# x+pl_pos.x+use_config[CONFIG_MAPWIDTH]/2-1,
# y+pl_pos.y+use_config[CONFIG_MAPHEIGHT]/2-1
# );
# }
The next I am wondering , why there is a
# pl_pos.x+use_config[CONFIG_MAPWIDTH]/2, pl_pos.y+use_config[CONFIG_MAPHEIGHT]/2);
in request map pos
and a -1 in request map near :
# if (strncmp(c, "near", 4) == 0) { // v.1.70.0
# for (y = 0; y < 3; ++y)
# for (x = 0; x < 3; ++x)
# send_map(i,
# x+pl_pos.x+use_config[CONFIG_MAPWIDTH]/2-1,
# y+pl_pos.y+use_config[CONFIG_MAPHEIGHT]/2-1
# );
# }
I had a short look into client v.1.71.0 common/script.c and it seems to be still the code of v.1.70.0 .
If the client would have a -version parameter like the server, it would help much to toggle any code .
client v.1.12.0 has this code :
# if ( strncmp(c,"pos",3)==0 ) { // v.1.12.0
# char buf[1024];
#
# snprintf(buf, sizeof(buf), "request map pos %d %d\n",pl_pos.x,pl_pos.y);
# write(scripts.out_fd,buf,strlen(buf));
# }
client 1.70.0 has this code :
# if (strncmp(c, "pos", 3) == 0) { // v1.70.0
# char buf[1024];
#
# snprintf(buf, sizeof(buf), "request map pos %d %d\n", pl_pos.x+use_config[CONFIG_MAPWIDTH]/2, pl_pos.y+use_config[CONFIG_MAPHEIGHT]/2);
# write(scripts.out_fd, buf, strlen(buf));
The 1.70.0 client uses additionally use_config that adds a few positive integers .
So code that works for the client v.1.70.0 does not work on 1.12.0 ( and lesser ) .
The client did not change much here from v.1.10.0 to v.1.12.0 except changing from sprintf to snprintf .
What makes me wondering, is that request map near already has this use_config included since at least v.1.10.0 :
# if ( strncmp(c,"near",4)==0 ) { // v.1.10.0
# for(y=0;y<3;++y)
# for(x=0;x<3;++x)
# send_map(i,
# x+pl_pos.x+use_config[CONFIG_MAPWIDTH]/2-1,
# y+pl_pos.y+use_config[CONFIG_MAPHEIGHT]/2-1
# );
# }
The next I am wondering , why there is a
# pl_pos.x+use_config[CONFIG_MAPWIDTH]/2, pl_pos.y+use_config[CONFIG_MAPHEIGHT]/2);
in request map pos
and a -1 in request map near :
# if (strncmp(c, "near", 4) == 0) { // v.1.70.0
# for (y = 0; y < 3; ++y)
# for (x = 0; x < 3; ++x)
# send_map(i,
# x+pl_pos.x+use_config[CONFIG_MAPWIDTH]/2-1,
# y+pl_pos.y+use_config[CONFIG_MAPHEIGHT]/2-1
# );
# }
I had a short look into client v.1.71.0 common/script.c and it seems to be still the code of v.1.70.0 .
If the client would have a -version parameter like the server, it would help much to toggle any code .