+++ /dev/null
-#include <fcntl.h> /* For O_* constants */\r
-#include <stdio.h>\r
-#include <ctype.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <unistd.h>\r
-#include <sys/stat.h>\r
-#include <sys/mman.h>\r
-#include <sys/types.h>\r
-\r
-#include "sharedmemory_struct.h"\r
-\r
-enum{ NOP_SHM, WAIT_ATTACH_SHM, TRY_ATTACH_SHM, MAT_SHM, CLEAN_UP_SHM, RUN_SHM };\r
-\r
-int shm_fd;\r
-shm_t *shmptr = NULL;\r
-char shm_file_name[128];\r
-\r
-int wait = 0, opt;\r
-uint8_t last, shm_statem = TRY_ATTACH_SHM;\r
-\r
-void run_shm(void);\r
-\r
-int main(int argc, char **argv) \r
-{\r
- struct stat buf;\r
- int bindport = 0;\r
- \r
- while ( (opt = getopt(argc, argv, "wb:")) != -1 ) \r
- {\r
- switch(opt) \r
- {\r
- case 'w':\r
- wait = 1;\r
- break;\r
- case 'b':\r
- bindport = atoi(optarg);\r
- break; \r
- default: \r
- fprintf(stderr, "Usage: %s [-w] [-b <port>]\n", argv[0]);\r
- fprintf(stderr, "\t-w - Wait for umurmurd to create shm area. useful if you need to start from init.d script\n" );\r
- fprintf(stderr, "\t-b <port> - Change this to the port used when starting umurmurd. Defaults to \"/umurmurd:64738\" \n");\r
- exit(EXIT_FAILURE);\r
- }\r
- }\r
-\r
- shmptr = NULL;\r
- \r
- if( !bindport )\r
- {\r
- bindport = 64738;\r
- }\r
- \r
- sprintf( shm_file_name, "/umurmurd:%i", bindport );\r
- \r
- if( wait )\r
- shm_statem = WAIT_ATTACH_SHM;\r
- \r
- while( shm_statem )\r
- {\r
- switch( shm_statem )\r
- {\r
- case RUN_SHM:\r
- run_shm();\r
- break; \r
- case WAIT_ATTACH_SHM:\r
- printf( "Waiting for umurmurd to be run\n\r"); fflush(stdout);\r
- while( ( shm_fd = shm_open( shm_file_name, O_RDONLY, 0666 ) ) == -1 )\r
- sleep( 1 );\r
- shm_statem = MAT_SHM;\r
- break;\r
- case TRY_ATTACH_SHM:\r
- if( ( shm_fd = shm_open( shm_file_name, O_RDONLY, 0666 ) ) == -1 )\r
- {\r
- printf( "umurmurd doesn't seem to be running\n\r" ); \r
- exit(EXIT_FAILURE);\r
- }\r
- shm_statem = MAT_SHM;\r
- break;\r
- case MAT_SHM: \r
- fstat( shm_fd, &buf); \r
- if( ( shmptr = mmap(0, buf.st_size, PROT_READ, MAP_SHARED, shm_fd, 0) ) == MAP_FAILED ) \r
- {\r
- exit(EXIT_FAILURE);\r
- } \r
- printf( "umumurd PID: %u\n\r", shmptr->umurmurd_pid );\r
- shm_statem = RUN_SHM; \r
- break;\r
- case CLEAN_UP_SHM: \r
- \r
- break;\r
- \r
- }\r
- }\r
- fflush(stdout);\r
- return 0;\r
-}\r
-\r
-uint8_t check_serverTick(void)\r
-{\r
- last = shmptr->alive;\r
- sleep( 1 ); // Sleep for 1 sec\r
- return(shmptr->alive - last); \r
-}\r
-\r
-void run_shm(void)\r
-{\r
-\r
-int cc;\r
-\r
- printf( "\033[2J\033[H" ); fflush(stdout); //clear screen VT100\r
- printf( "%s Clients(CONECTED/MAX) %i/%i\n\n", shm_file_name, shmptr->clientcount, shmptr->server_max_clients ); \r
- \r
- for( cc = 0 ; cc < shmptr->server_max_clients ; cc++ )\r
- {\r
- \r
- if( !shmptr->client[cc].authenticated )\r
- continue; \r
- \r
- printf( "%s@%s:%i in channel: %s\n\\r
- \tclient_OS: %s %s\n\\r
- \tclient_info: %s\n\\r
- \tavailableBandwidth: %i\n\\r
- \tOnline(secs): %lu Idle(secs): %lu\n\\r
- \tusingUDP=%i\n\\r
- \tdeaf=%i, mute=%i\n\\r
- \tself_deaf=%i, self_mute=%i\n\\r
- \trecording=%i\n\\r
- \tbOpus=%i\n\\r
- \tisAdmin=%i\n\\r
- \tisSuppressed=%i\n\\r
- \tUDP_Avg/Var: %3.2f/%3.2f\n\\r
- \tTCP_Avg/Var: %3.2f/%3.2f\n\\r
- \tUDP_C/TCP_C: %lu/%lu\n", \r
- shmptr->client[cc].username,\r
- shmptr->client[cc].ipaddress,\r
- shmptr->client[cc].udp_port,\r
- shmptr->client[cc].channel,\r
- shmptr->client[cc].os,\r
- shmptr->client[cc].os_version,\r
- shmptr->client[cc].release,\r
- shmptr->client[cc].availableBandwidth,\r
- shmptr->client[cc].online_secs,\r
- shmptr->client[cc].idle_secs,\r
- \r
- shmptr->client[cc].bUDP,\r
- shmptr->client[cc].deaf,\r
- shmptr->client[cc].mute,\r
- shmptr->client[cc].self_deaf,\r
- shmptr->client[cc].self_mute,\r
- shmptr->client[cc].recording,\r
- shmptr->client[cc].bOpus,\r
- \r
- shmptr->client[cc].isAdmin,\r
- shmptr->client[cc].isSuppressed,\r
- \r
- shmptr->client[cc].UDPPingAvg,\r
- shmptr->client[cc].UDPPingVar,\r
- shmptr->client[cc].TCPPingAvg,\r
- shmptr->client[cc].TCPPingVar,\r
- shmptr->client[cc].UDPPackets,\r
- shmptr->client[cc].TCPPackets ); fflush(stdout); // fflush need because of sleep() call\r
- }\r
- if( !check_serverTick() )\r
- {\r
- exit(EXIT_FAILURE); //You dont have to exit you could just report the fact that the data is not valid \r
- }\r
-}\r