Skip to content

Commit

Permalink
Fixed console parse gm command crash on select commands
Browse files Browse the repository at this point in the history
Also fixed an issue with socket flushing

Signed-off-by: shennetsind <ind@henn.et>
  • Loading branch information
shennetsind committed Feb 24, 2014
1 parent 24551d9 commit 3c87f3a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/common/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -873,13 +873,13 @@ int do_sockets(int next)

if(!session[i])
continue;


RFIFOFLUSH(i);
// after parse, check client's RFIFO size to know if there is an invalid packet (too big and not parsed)
if (session[i]->rdata_size == session[i]->max_rdata) {
set_eof(i);
continue;
}
RFIFOFLUSH(i);
}

#ifdef SHOW_SERVER_STATS
Expand Down
6 changes: 3 additions & 3 deletions src/map/clif.c
Original file line number Diff line number Diff line change
Expand Up @@ -5587,7 +5587,7 @@ void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val
void clif_displaymessage(const int fd, const char* mes) {
nullpo_retv(mes);

if( fd == -2 ) {
if( map->cpsd_active && fd == 0 ) {
ShowInfo("HCP: %s\n",mes);
} else if ( fd > 0 ) {
size_t len;
Expand Down Expand Up @@ -5619,7 +5619,7 @@ void clif_displaymessage2(const int fd, const char* mes) {
size_t len = strnlen(line, 255);

if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
if( fd == -2 ) {
if( map->cpsd_active && fd == 0 ) {
ShowInfo("HCP: %s\n",line);
} else {
WFIFOHEAD(fd, 5 + len);
Expand All @@ -5638,7 +5638,7 @@ void clif_displaymessage2(const int fd, const char* mes) {
void clif_displaymessage_sprintf(const int fd, const char* mes, ...) {
va_list ap;

if( fd == -2 ) {
if( map->cpsd_active && fd == 0 ) {
ShowInfo("HCP: ");
va_start(ap,mes);
_vShowMessage(MSG_NONE,mes,ap);
Expand Down
2 changes: 1 addition & 1 deletion src/map/intif.c
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,7 @@ void intif_parse_MessageToFD(int fd) {
int aid = RFIFOL(fd,8);
struct map_session_data * sd = session[u_fd]->session_data;
/* matching e.g. previous fd owner didn't dc during request or is still the same */
if( sd->bl.id == aid ) {
if( sd && sd->bl.id == aid ) {
char msg[512];
safestrncpy(msg, (char*)RFIFOP(fd,12), RFIFOW(fd,2) - 12);
clif->message(u_fd,msg);
Expand Down
10 changes: 7 additions & 3 deletions src/map/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -5423,13 +5423,15 @@ CPCMD(gm_use) {
ShowError("gm:use invalid syntax. use '"CL_WHITE"gm:use @command <optional params>"CL_RESET"'\n");
return;
}
map->cpsd->fd = -2;

map->cpsd_active = true;

if( !atcommand->exec(map->cpsd->fd, map->cpsd, line, false) )
ShowInfo("HCP: '"CL_WHITE"%s"CL_RESET"' failed\n",line);
else
ShowInfo("HCP: '"CL_WHITE"%s"CL_RESET"' was used\n",line);
map->cpsd->fd = 0;


map->cpsd_active = false;
}
/* Hercules Console Parser */
void map_cp_defaults(void) {
Expand Down Expand Up @@ -5840,6 +5842,8 @@ void map_defaults(void) {
sprintf(map->server_db,"ragnarok");
map->mysql_handle = NULL;

map->cpsd_active = false;

map->port = 0;
map->users = 0;
map->ip_set = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/map/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,8 @@ struct map_interface {
struct eri *flooritem_ers;
/* */
int bonus_id;
/* */
bool cpsd_active;
/* funcs */
void (*zone_init) (void);
void (*zone_remove) (int m);
Expand Down

0 comments on commit 3c87f3a

Please sign in to comment.