diff --git a/Makefile.am b/Makefile.am index bf8f0ac..ae69a3e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,7 +21,10 @@ DISTCLEANFILES = craftd.conf.dist crafdconfdir = ${sysconfdir}/craftd/ crafdconf_DATA = craftd.conf.dist motd.conf.dist - +# bstring extas +bstrdir = third-party/bstring +EXTRA_DIST += $(bstrdir)/license.txt $(bstrdir)/security.txt \ + $(bstrdir)/bstrlib.txt $(bstrdir)/porting.txt # Jansson extras jsondir = third-party/jansson diff --git a/README b/README index 6e126d1..ba420c5 100644 --- a/README +++ b/README @@ -37,8 +37,10 @@ You should have a good understanding of libevent-2. http://www.wangafu.net/~nickm/libevent-book/ http://mc.kev009.com/libevent - Up to date doxygen -Bundled JSON API (used for web GUI and config): +Bundled Libs: +JSON API (used for web GUI and config): Jansson (Git head) - http://github.com/akheron/jansson +bstring - Safer C strings - http://bstring.sourceforge.net/ Protocol reference: http://mc.kev009.com/wiki/ diff --git a/src/craftd.c b/src/craftd.c index ede8182..0cf204b 100644 --- a/src/craftd.c +++ b/src/craftd.c @@ -96,11 +96,7 @@ errorcb(struct bufferevent *bev, short error, void *ctx) if (error & BEV_EVENT_EOF) { - /* Connection closed, remove client from tables here */ - if (player->username != NULL) - LOG(LOG_INFO, "Connection closed for: %s", player->username->data); - else - LOG(LOG_INFO, "Connection closed ip: %s", player->ip); + /* Connection closed */ finished = 1; } else if (error & BEV_EVENT_ERROR) @@ -119,6 +115,23 @@ errorcb(struct bufferevent *bev, short error, void *ctx) if (finished) { + if (player->username != NULL) + { + /* In-band disconnect message */ + bstring dconmsg = bformat("%s has disconnected", + player->username->data); + send_syschat(dconmsg); + bstrFree(dconmsg); + + /* System log message */ + LOG(LOG_INFO, "Connection closed for: %s", player->username->data); + } + else + { + /* The user hasn't gotten far enough to register a username */ + LOG(LOG_INFO, "Connection closed ip: %s", player->ip); + } + //TODO: Add mutual exclusion so a worker doesn't get a null ptr //TODO: Convert this to a SLIST_FOREACH //XXXX Grab a rdlock until player is found, wrlock delete, free diff --git a/src/network/network.h b/src/network/network.h index 81ffb94..e8b1484 100644 --- a/src/network/network.h +++ b/src/network/network.h @@ -49,6 +49,7 @@ void *run_worker(void *arg); /* Public protocol functions that can be exposed to APIs */ void send_directchat(struct PL_entry *player, bstring message); void send_chat(struct PL_entry *player, bstring message); +void send_syschat(bstring message); void send_prechunk(struct PL_entry *player, int32_t x, int32_t z, bool mode); void send_chunk(struct PL_entry *player, int32_t x, int16_t y, int32_t z, uint8_t sizex, uint8_t sizey, uint8_t sizez); diff --git a/src/network/send.c b/src/network/send.c index 2d29802..3384e8d 100644 --- a/src/network/send.c +++ b/src/network/send.c @@ -72,7 +72,7 @@ process_login(struct PL_entry *player, bstring username, uint32_t ver) pthread_rwlock_unlock(&player->rwlock); send_loginresp(player); - send_prechunk(player, -1, -1, true); // TODO: pull spwan position from file + //send_prechunk(player, 0, -1, true); // TODO: pull spwan position from file //send_chunk(player, 0, 0, 0, 16, 128, 16); // TODO: pull spawn position for(int i = -4; i < 5; i++) @@ -87,6 +87,15 @@ process_login(struct PL_entry *player, bstring username, uint32_t ver) send_spawnpos(player, 32, 260, 32); // TODO: pull spawn position from file //send inv send_movelook(player, 0, 128.1, 128.2, 0, 0, 0, false); //TODO: pull position from file + + //send_directchat(player, motd); + + /* Login message */ + bstring loginmsg = bformat("Player %s has joined the game!", + player->username->data); + send_syschat(loginmsg); + bstrFree(loginmsg); + return; } @@ -200,10 +209,7 @@ send_chat(struct PL_entry *player, bstring message) { struct PL_entry *player_iter; - bstring newmsg = bfromcstr("<"); - bconcat(newmsg, player->username); - bcatcstr(newmsg, "> "); - bconcat(newmsg, message); + bstring newmsg = bformat("<%s> %s", player->username->data, message->data); LOG(LOG_INFO, "Chat: %s", newmsg->data); @@ -219,6 +225,23 @@ send_chat(struct PL_entry *player, bstring message) return; } +void +send_syschat(bstring message) +{ + struct PL_entry *player_iter; + + LOG(LOG_INFO, "Syschat: %s", message->data); + + pthread_rwlock_rdlock(&PL_rwlock); + SLIST_FOREACH(player_iter, &PL_head, PL_entries) + { + send_directchat(player_iter, message); + } + pthread_rwlock_unlock(&PL_rwlock); + + return; +} + /** * Send a prechunk packet to the player *