From b0361ff113aaa873b1f9d9696f2e5e1e5c73d574 Mon Sep 17 00:00:00 2001 From: ai4rei Date: Sun, 12 Dec 2010 14:53:57 +0000 Subject: * Cleaned up MOTD reading (related r292 and r4552). - Added a warning for common client crash caused by the sequence ' :' in MOTD. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14584 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/atcommand.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'src/map/atcommand.c') diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 6f008c3af..0c584223f 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -6862,26 +6862,36 @@ ACMD_FUNC(identify) *------------------------------------------*/ ACMD_FUNC(gmotd) { - char buf[CHAT_SIZE_MAX]; - FILE *fp; - nullpo_retr(-1, sd); - if((fp = fopen(motd_txt, "r"))!=NULL){ - while(fgets(buf, sizeof(buf), fp) != NULL) + char buf[CHAT_SIZE_MAX]; + size_t len; + FILE* fp; + + if( ( fp = fopen(motd_txt, "r") ) != NULL ) + { + while( fgets(buf, sizeof(buf), fp) ) + { + if( buf[0] == '/' && buf[1] == '/' ) { - int i; - if (buf[0] == '/' && buf[1] == '/') - continue; - for(i=0; buf[i]; i++){ - if(buf[i]=='\r' || buf[i]=='\n'){ - buf[i]=0; - break; - } - } - intif_broadcast(buf, strlen(buf)+1, 0); + continue; + } + + len = strlen(buf); + + while( len && ( buf[len-1] == '\r' || buf[len-1] == '\n' ) ) + {// strip trailing EOL characters + len--; + } + + if( len ) + { + buf[len] = 0; + + intif_broadcast(buf, len+1, 0); } - fclose(fp); } - return 0; + fclose(fp); + } + return 0; } ACMD_FUNC(misceffect) -- cgit v1.2.3-60-g2f50