-#include "sharedmemory.h"\r
-\r
-int shm_fd;\r
-shm_t *shmptr = NULL;\r
-char shm_file_name[128];\r
-\r
-void Sharedmemory_init( int bindport, int bindport6 )\r
-{\r
-\r
- int server_max_clients = getIntConf(MAX_CLIENTS);\r
- int shmtotal_size = sizeof( shm_t ) + (sizeof( shmclient_t ) * server_max_clients);\r
-\r
- if( !bindport )\r
- {\r
- bindport = getIntConf(BINDPORT);\r
- }\r
-\r
- sprintf( shm_file_name, "/umurmurd:%i", bindport );\r
- Log_info("SHM_API: shm_fd=\"%s\"", shm_file_name );\r
-\r
- shm_fd = shm_open( shm_file_name, O_CREAT | O_RDWR, 0660 );\r
- if(shm_fd == -1)\r
- {\r
- Log_fatal( "SHM_API: Open failed:%s\n", strerror(errno));\r
- exit(EXIT_FAILURE);\r
- }\r
-\r
- if( ftruncate( shm_fd, shmtotal_size ) == -1 )\r
- {\r
- Sharedmemory_deinit();\r
- Log_fatal( "SHM_API: ftruncate : %s\n", strerror(errno));\r
- exit(EXIT_FAILURE);\r
- }\r
-\r
- shmptr = mmap( 0, shmtotal_size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0 );\r
- if (shmptr == MAP_FAILED)\r
- {\r
- Log_fatal( "SHM_API: mmap failed : %s\n", strerror(errno));\r
- exit(EXIT_FAILURE);\r
- }\r
-\r
- memset( shmptr, 0, shmtotal_size );\r
-\r
- shmptr->umurmurd_pid = getpid();\r
- shmptr->server_max_clients = server_max_clients;\r
- shmptr->shmtotal_size = shmtotal_size;\r
- shmptr->shmclient_size = sizeof( shmclient_t ) * shmptr->server_max_clients;\r
-\r
-}\r
-\r
-void Sharedmemory_update(void)\r
-{\r
-\r
- uint64_t now;\r
- unsigned int cc = 0;\r
- client_t *client_itr = NULL;\r
-\r
- memset( &shmptr->client[0], 0, shmptr->shmclient_size );\r
- shmptr->clientcount = Client_count();\r
-\r
- if( shmptr->clientcount )\r
- {\r
- Timer_init( &now );\r
- while( Client_iterate(&client_itr) != NULL )\r
- {\r
- if( client_itr->authenticated )\r
- {\r
- channel_t *channel = client_itr->channel;\r
-\r
- char* clientAddressString = Util_clientAddressToString( client_itr );\r
-\r
- strncpy( shmptr->client[cc].username, client_itr->username, 120 );\r
- strncpy( shmptr->client[cc].ipaddress, clientAddressString, INET6_ADDRSTRLEN - 1 );\r
- strncpy( shmptr->client[cc].channel, channel->name, 120 );\r
-\r
- strncpy( shmptr->client[cc].os, client_itr->os, 120 );\r
- strncpy( shmptr->client[cc].release, client_itr->release, 120 );\r
- strncpy( shmptr->client[cc].os_version, client_itr->os_version, 120 );\r
-\r
- shmptr->client[cc].tcp_port = Util_clientAddressToPortTCP( client_itr );\r
- shmptr->client[cc].udp_port = Util_clientAddressToPortUDP( client_itr );\r
-\r
- shmptr->client[cc].online_secs = ( now - client_itr->connectTime ) / 1000000LL;\r
- shmptr->client[cc].idle_secs = ( now - client_itr->idleTime ) / 1000000LL;\r
-\r
- shmptr->client[cc].bUDP = client_itr->bUDP;\r
- shmptr->client[cc].deaf = client_itr->deaf;\r
- shmptr->client[cc].mute = client_itr->mute;\r
- shmptr->client[cc].bOpus = client_itr->bOpus;\r
- shmptr->client[cc].self_deaf = client_itr->self_deaf;\r
- shmptr->client[cc].self_mute = client_itr->self_mute;\r
- shmptr->client[cc].recording = client_itr->recording;\r
- shmptr->client[cc].authenticated = client_itr->authenticated;\r
-\r
- shmptr->client[cc].availableBandwidth = client_itr->availableBandwidth;\r
-\r
- shmptr->client[cc].UDPPingAvg = client_itr->UDPPingAvg;\r
- shmptr->client[cc].UDPPingVar = client_itr->UDPPingVar;\r
- shmptr->client[cc].TCPPingAvg = client_itr->TCPPingAvg;\r
- shmptr->client[cc].TCPPingVar = client_itr->TCPPingVar;\r
-\r
- shmptr->client[cc].isAdmin = client_itr->isAdmin;\r
- shmptr->client[cc].isSuppressed = client_itr->isSuppressed;\r
-\r
- shmptr->client[cc].UDPPackets = client_itr->UDPPackets;\r
- shmptr->client[cc].TCPPackets = client_itr->TCPPackets;\r
-\r
- free(clientAddressString);\r
- }\r
- cc++;\r
- }\r
- }\r
-}\r
-void Sharedmemory_alivetick(void)\r
-{\r
- shmptr->alive++;\r
-}\r
-\r
-void Sharedmemory_deinit(void)\r
-{\r
- close( shm_fd );\r
- shm_unlink( shm_file_name );\r
- shmptr->umurmurd_pid = 0;\r
-}\r
+#include "sharedmemory.h"
+
+int shm_fd;
+shm_t *shmptr = NULL;
+char shm_file_name[128];
+
+void Sharedmemory_init( int bindport, int bindport6 )
+{
+
+ int server_max_clients = getIntConf(MAX_CLIENTS);
+ int shmtotal_size = sizeof( shm_t ) + (sizeof( shmclient_t ) * server_max_clients);
+
+ if( !bindport )
+ {
+ bindport = getIntConf(BINDPORT);
+ }
+
+ sprintf( shm_file_name, "/umurmurd:%i", bindport );
+ Log_info("SHM_API: shm_fd=\"%s\"", shm_file_name );
+
+ shm_fd = shm_open( shm_file_name, O_CREAT | O_RDWR, 0660 );
+ if(shm_fd == -1)
+ {
+ Log_fatal( "SHM_API: Open failed:%s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ if( ftruncate( shm_fd, shmtotal_size ) == -1 )
+ {
+ Sharedmemory_deinit();
+ Log_fatal( "SHM_API: ftruncate : %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ shmptr = mmap( 0, shmtotal_size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0 );
+ if (shmptr == MAP_FAILED)
+ {
+ Log_fatal( "SHM_API: mmap failed : %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ memset( shmptr, 0, shmtotal_size );
+
+ shmptr->umurmurd_pid = getpid();
+ shmptr->server_max_clients = server_max_clients;
+ shmptr->shmtotal_size = shmtotal_size;
+ shmptr->shmclient_size = sizeof( shmclient_t ) * shmptr->server_max_clients;
+
+}
+
+void Sharedmemory_update(void)
+{
+
+ uint64_t now;
+ unsigned int cc = 0;
+ client_t *client_itr = NULL;
+
+ memset( &shmptr->client[0], 0, shmptr->shmclient_size );
+ shmptr->clientcount = Client_count();
+
+ if( shmptr->clientcount )
+ {
+ Timer_init( &now );
+ while( Client_iterate(&client_itr) != NULL )
+ {
+ if( client_itr->authenticated )
+ {
+ channel_t *channel = client_itr->channel;
+
+ char* clientAddressString = Util_clientAddressToString( client_itr );
+
+ strncpy( shmptr->client[cc].username, client_itr->username, 120 );
+ strncpy( shmptr->client[cc].ipaddress, clientAddressString, INET6_ADDRSTRLEN - 1 );
+ strncpy( shmptr->client[cc].channel, channel->name, 120 );
+
+ strncpy( shmptr->client[cc].os, client_itr->os, 120 );
+ strncpy( shmptr->client[cc].release, client_itr->release, 120 );
+ strncpy( shmptr->client[cc].os_version, client_itr->os_version, 120 );
+
+ shmptr->client[cc].tcp_port = Util_clientAddressToPortTCP( client_itr );
+ shmptr->client[cc].udp_port = Util_clientAddressToPortUDP( client_itr );
+
+ shmptr->client[cc].online_secs = ( now - client_itr->connectTime ) / 1000000LL;
+ shmptr->client[cc].idle_secs = ( now - client_itr->idleTime ) / 1000000LL;
+
+ shmptr->client[cc].bUDP = client_itr->bUDP;
+ shmptr->client[cc].deaf = client_itr->deaf;
+ shmptr->client[cc].mute = client_itr->mute;
+ shmptr->client[cc].bOpus = client_itr->bOpus;
+ shmptr->client[cc].self_deaf = client_itr->self_deaf;
+ shmptr->client[cc].self_mute = client_itr->self_mute;
+ shmptr->client[cc].recording = client_itr->recording;
+ shmptr->client[cc].authenticated = client_itr->authenticated;
+
+ shmptr->client[cc].availableBandwidth = client_itr->availableBandwidth;
+
+ shmptr->client[cc].UDPPingAvg = client_itr->UDPPingAvg;
+ shmptr->client[cc].UDPPingVar = client_itr->UDPPingVar;
+ shmptr->client[cc].TCPPingAvg = client_itr->TCPPingAvg;
+ shmptr->client[cc].TCPPingVar = client_itr->TCPPingVar;
+
+ shmptr->client[cc].isAdmin = client_itr->isAdmin;
+ shmptr->client[cc].isSuppressed = client_itr->isSuppressed;
+
+ shmptr->client[cc].UDPPackets = client_itr->UDPPackets;
+ shmptr->client[cc].TCPPackets = client_itr->TCPPackets;
+
+ free(clientAddressString);
+ }
+ cc++;
+ }
+ }
+}
+void Sharedmemory_alivetick(void)
+{
+ shmptr->alive++;
+}
+
+void Sharedmemory_deinit(void)
+{
+ close( shm_fd );
+ shm_unlink( shm_file_name );
+ shmptr->umurmurd_pid = 0;
+}
-#include <arpa/inet.h>\r
-#include <stdint.h>\r
-#include "types.h"\r
-\r
-typedef struct\r
-{\r
-\r
- char username[121];\r
- char ipaddress[INET6_ADDRSTRLEN];\r
- char channel[121];\r
- char os[121], release[121], os_version[121];\r
- int tcp_port, udp_port;\r
- bool_t bUDP, authenticated, deaf, mute, self_deaf, self_mute, recording, bOpus;\r
- int availableBandwidth;\r
- uint32_t online_secs, idle_secs;\r
- bool_t isAdmin;\r
- bool_t isSuppressed;\r
- float UDPPingAvg, UDPPingVar, TCPPingAvg, TCPPingVar;\r
- uint32_t UDPPackets, TCPPackets;\r
-\r
-}shmclient_t;\r
-\r
-typedef struct\r
-{\r
-\r
- int shmtotal_size, shmclient_size;\r
- int clientcount, server_max_clients;\r
- unsigned int umurmurd_pid;\r
- uint8_t alive;\r
- shmclient_t client[];\r
-\r
-}shm_t;\r
+#include <arpa/inet.h>
+#include <stdint.h>
+#include "types.h"
+
+typedef struct
+{
+
+ char username[121];
+ char ipaddress[INET6_ADDRSTRLEN];
+ char channel[121];
+ char os[121], release[121], os_version[121];
+ int tcp_port, udp_port;
+ bool_t bUDP, authenticated, deaf, mute, self_deaf, self_mute, recording, bOpus;
+ int availableBandwidth;
+ uint32_t online_secs, idle_secs;
+ bool_t isAdmin;
+ bool_t isSuppressed;
+ float UDPPingAvg, UDPPingVar, TCPPingAvg, TCPPingVar;
+ uint32_t UDPPackets, TCPPackets;
+
+} shmclient_t;
+
+typedef struct
+{
+
+ int shmtotal_size, shmclient_size;
+ int clientcount, server_max_clients;
+ unsigned int umurmurd_pid;
+ uint8_t alive;
+ shmclient_t client[];
+
+} shm_t;