@@ -23,9 +23,11 @@ static void file_log(std::string str) {
2323#ifdef GHOST_GUI
2424# include < QVector>
2525# define GHOST_LOG (x ) (file_log(x), emit this ->OnNewEvent (QString::fromStdString(x)))
26+ # define UI_EVENT (x ) (emit this ->UIEvent (x))
2627#else
2728# include < stdio.h>
2829# define GHOST_LOG (x ) (file_log(x), printf(" [LOG] %s\n " , std::string(x).c_str()))
30+ # define UI_EVENT (x ) ((void )0 )
2931#endif
3032
3133#define HEARTBEAT_RATE 5000
@@ -36,7 +38,7 @@ static void file_log(std::string str) {
3638#ifdef _WIN32
3739# define strcasecmp _stricmp
3840#else
39- # include < strings.h>
41+ # include < strings.h>
4042#endif
4143
4244static std::chrono::time_point<std::chrono::steady_clock> lastHeartbeat;
@@ -180,6 +182,8 @@ bool NetworkManager::StartServer(const int port)
180182 this ->serverThread = std::thread (&NetworkManager::RunServer, this );
181183 this ->serverThread .detach ();
182184
185+ UI_EVENT (" server_start" );
186+ UI_EVENT (" client_change" );
183187 GHOST_LOG (" Server started on " + this ->serverIP .toString () + " (public IP: " + sf::IpAddress::getPublicAddress ().toString () + " ) on port " + std::to_string (this ->serverPort ));
184188 GHOST_LOG (" Enter 'help' for a list of commands." );
185189
@@ -202,6 +206,8 @@ void NetworkManager::StopServer()
202206 this ->udpSocket .unbind ();
203207 this ->listener .close ();
204208
209+ UI_EVENT (" client_change" );
210+ UI_EVENT (" server_stop" );
205211 GHOST_LOG (" Server stopped!" );
206212}
207213
@@ -225,6 +231,7 @@ void NetworkManager::DisconnectPlayer(Client& c, const char *reason)
225231
226232 if (toErase != -1 ) {
227233 this ->clients .erase (this ->clients .begin () + toErase);
234+ UI_EVENT (" client_change" );
228235 }
229236}
230237
@@ -258,6 +265,7 @@ void NetworkManager::SetAccept(bool players, bool allow)
258265 this ->acceptingSpectators = allow;
259266 }
260267 if (!changed) return ;
268+ UI_EVENT (" accept_refuse" );
261269 GHOST_LOG (std::string (" Now " ) + (allow ? " accepting" : " refusing" ) + " connections from " + (players ? " players" : " spectators" ));
262270
263271}
@@ -357,6 +365,7 @@ void NetworkManager::CheckConnection()
357365 c.tcpSocket ->send (packet_notify_all);
358366 }
359367
368+ UI_EVENT (" client_change" );
360369 GHOST_LOG (" Connection: " + client.name + " (" + (client.spectator ? " spectator" : " player" ) + " ) @ " + client.IP .toString () + " :" + std::to_string (client.port ));
361370
362371 this ->clients .push_back (std::move (client));
@@ -430,6 +439,7 @@ void NetworkManager::Treat(sf::Packet& packet, sf::IpAddress ip, unsigned short
430439 std::string map;
431440 packet >> map;
432441 client->currentMap = map;
442+ UI_EVENT (" client_change" );
433443 GHOST_LOG (client->name + " is now on " + map);
434444 SEND_TO_OTHERS (packet);
435445 break ;
0 commit comments