X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=shm_utils%2Fmon-umurmurd%2Fmon-umurmurd.c;h=7c02759df65a01b766e3b078f21917ac24810482;hb=8fd71184fa820302e47c2d168f9c989274c08b6a;hp=7a1a5b2eb0396dd7feddf3d8dcccbb98d151c221;hpb=a738ff892738e239ad74f5aa686108298efa7cea;p=umurmur.git diff --git a/shm_utils/mon-umurmurd/mon-umurmurd.c b/shm_utils/mon-umurmurd/mon-umurmurd.c index 7a1a5b2..7c02759 100644 --- a/shm_utils/mon-umurmurd/mon-umurmurd.c +++ b/shm_utils/mon-umurmurd/mon-umurmurd.c @@ -4,13 +4,18 @@ #include #include #include +#include #include #include -#include "../../src/sharedmemory.h" -#include "../../src/sharedmemory_global.h" + +#include "sharedmemory_struct.h" enum{ NOP_SHM, WAIT_ATTACH_SHM, TRY_ATTACH_SHM, MAT_SHM, CLEAN_UP_SHM, RUN_SHM }; +int shm_fd; +shm_t *shmptr = NULL; +char shm_file_name[128]; + int wait = 0, opt; uint8_t last, shm_statem = TRY_ATTACH_SHM; @@ -18,25 +23,35 @@ void run_shm(void); int main(int argc, char **argv) { - - - while ( (opt = getopt(argc, argv, "w")) != -1 ) - { + struct stat buf; + int bindport = 0; + + while ( (opt = getopt(argc, argv, "wb:")) != -1 ) + { switch(opt) - { + { case 'w': wait = 1; break; - default: - fprintf(stderr, "Usage: %s [-w]\n", argv[0]); + case 'b': + bindport = atoi(optarg); + break; + default: + fprintf(stderr, "Usage: %s [-w] [-b ]\n", argv[0]); fprintf(stderr, "\t-w - Wait for umurmurd to create shm area. useful if you need to start from init.d script\n" ); + fprintf(stderr, "\t-b - Change this to the port used when starting umurmurd. Defaults to \"/umurmurd:64738\" \n"); exit(EXIT_FAILURE); } } shmptr = NULL; - sprintf( shm_file_name, "/umurmurd:%i", 64738 ); + if( !bindport ) + { + bindport = 64738; + } + + sprintf( shm_file_name, "/umurmurd:%i", bindport ); if( wait ) shm_statem = WAIT_ATTACH_SHM; @@ -62,10 +77,10 @@ int main(int argc, char **argv) } shm_statem = MAT_SHM; break; - case MAT_SHM: - if( ( shmptr = mmap(0, 1, PROT_READ, MAP_SHARED, shm_fd, 0) ) == (void *) (-1) ) //MJP BUG? + case MAT_SHM: + fstat( shm_fd, &buf); + if( ( shmptr = mmap(0, buf.st_size, PROT_READ, MAP_SHARED, shm_fd, 0) ) == MAP_FAILED ) { - exit(EXIT_FAILURE); } printf( "umumurd PID: %u\n\r", shmptr->umurmurd_pid ); @@ -84,8 +99,8 @@ int main(int argc, char **argv) uint8_t check_serverTick(void) { last = shmptr->alive; - sleep( 1 ); // Sleep for 1 sec - return(shmptr->alive - last); + sleep( 1 ); // Sleep for 1 sec + return(shmptr->alive - last); } void run_shm(void) @@ -93,49 +108,61 @@ void run_shm(void) int cc; - printf( "\033[2J\033[H" ); //clear screen VT100 - + printf( "\033[2J\033[H" ); fflush(stdout); //clear screen VT100 + printf( "%s Clients(CONECTED/MAX) %i/%i\n\n", shm_file_name, shmptr->clientcount, shmptr->server_max_clients ); - for( cc = 0 ; cc < shmptr->server_max_clients ; cc++ ) + for( cc = 0 ; cc < shmptr->server_max_clients ; cc++ ) { if( !shmptr->client[cc].authenticated ) continue; - printf( "%s@%s:%i in channel: %s\n\ - \tOnline(secs): %lu Idle(secs): %lu\n\ - \tusingUDP=%i\n\ - \tdeaf=%i, mute=%i\n\ - \tself_deaf=%i, self_mute=%i\n\ - \trecording=%i\n\ - \tbOpus=%i\n\ - \tUDP_Avg/Var: %3.2f/%3.2f \n\ - \tTCP_Avg/Var: %3.2f/%3.2f \n\ - \tUDP_C/TCP_C: %lu/%lu\n", - shmptr->client[cc].username, - shmptr->client[cc].ipaddress, - shmptr->client[cc].udp_port, - shmptr->client[cc].channel, - shmptr->client[cc].online_secs, - shmptr->client[cc].idle_secs, + printf( "%s@%s:%i in channel: %s\n\ + \tclient_OS: %s %s\n\ + \tclient_info: %s\n\ + \tavailableBandwidth: %i\n\ + \tOnline(secs): %lu Idle(secs): %lu\n\ + \tusingUDP=%i\n\ + \tdeaf=%i, mute=%i\n\ + \tself_deaf=%i, self_mute=%i\n\ + \trecording=%i\n\ + \tbOpus=%i\n\ + \tisAdmin=%i\n\ + \tisSuppressed=%i\n\ + \tUDP_Avg/Var: %3.2f/%3.2f\n\ + \tTCP_Avg/Var: %3.2f/%3.2f\n\ + \tUDP_C/TCP_C: %lu/%lu\n", + shmptr->client[cc].username, + shmptr->client[cc].ipaddress, + shmptr->client[cc].udp_port, + shmptr->client[cc].channel, + shmptr->client[cc].os, + shmptr->client[cc].os_version, + shmptr->client[cc].release, + shmptr->client[cc].availableBandwidth, + shmptr->client[cc].online_secs, + shmptr->client[cc].idle_secs, - shmptr->client[cc].bUDP, - shmptr->client[cc].deaf, - shmptr->client[cc].mute, - shmptr->client[cc].self_deaf, - shmptr->client[cc].self_mute, - shmptr->client[cc].recording, - shmptr->client[cc].bOpus, + shmptr->client[cc].bUDP, + shmptr->client[cc].deaf, + shmptr->client[cc].mute, + shmptr->client[cc].self_deaf, + shmptr->client[cc].self_mute, + shmptr->client[cc].recording, + shmptr->client[cc].bOpus, + + shmptr->client[cc].isAdmin, + shmptr->client[cc].isSuppressed, - shmptr->client[cc].UDPPingAvg, - shmptr->client[cc].UDPPingVar, - shmptr->client[cc].TCPPingAvg, - shmptr->client[cc].TCPPingVar, - shmptr->client[cc].UDPPackets, - shmptr->client[cc].TCPPackets ); fflush(stdout); // fflush need because of sleep() call + shmptr->client[cc].UDPPingAvg, + shmptr->client[cc].UDPPingVar, + shmptr->client[cc].TCPPingAvg, + shmptr->client[cc].TCPPingVar, + shmptr->client[cc].UDPPackets, + shmptr->client[cc].TCPPackets ); fflush(stdout); // fflush need because of sleep() call } - if( !check_serverTick() ) + if( !check_serverTick() ) { - exit(EXIT_FAILURE); //You dont have to exit you could just report the fact that the data is not valid - } -} \ No newline at end of file + exit(EXIT_FAILURE); //You dont have to exit you could just report the fact that the data is not valid + } +}