add NETWORK_BUF_CLEAR_ON_JOIN option

main
Dominik Madarász 2023-08-21 20:23:43 +02:00
parent 1928f0a531
commit 86e129e210
7 changed files with 57 additions and 6 deletions

View File

@ -2118,7 +2118,8 @@ enum { NETWORK_RANK = 0 };
enum { NETWORK_PING = 1 }; enum { NETWORK_PING = 1 };
enum { NETWORK_PORT = 2, NETWORK_IP, NETWORK_LIVE }; enum { NETWORK_PORT = 2, NETWORK_IP, NETWORK_LIVE };
enum { NETWORK_SEND_MS = 4 }; enum { NETWORK_SEND_MS = 4 };
enum { NETWORK_USERID = 5, NETWORK_COUNT , NETWORK_CAPACITY }; enum { NETWORK_BUF_CLEAR_ON_JOIN = 5 };
enum { NETWORK_USERID = 7, NETWORK_COUNT , NETWORK_CAPACITY };
int64_t network_get(uint64_t key); int64_t network_get(uint64_t key);
int64_t network_put(uint64_t key, int64_t value); int64_t network_put(uint64_t key, int64_t value);
void network_rpc(const char *signature, void *function); void network_rpc(const char *signature, void *function);

View File

@ -15948,7 +15948,8 @@ enum { NETWORK_RANK = 0 }; // [0..N] where 0 is server
enum { NETWORK_PING = 1 }; // NETWORK_BANDWIDTH, NETWORK_QUALITY }; enum { NETWORK_PING = 1 }; // NETWORK_BANDWIDTH, NETWORK_QUALITY };
enum { NETWORK_PORT = 2, NETWORK_IP, NETWORK_LIVE }; enum { NETWORK_PORT = 2, NETWORK_IP, NETWORK_LIVE };
enum { NETWORK_SEND_MS = 4 }; enum { NETWORK_SEND_MS = 4 };
enum { NETWORK_USERID = 5, /*NETWORK_SALT,*/ NETWORK_COUNT/*N users*/ /*...*/, NETWORK_CAPACITY }; enum { NETWORK_BUF_CLEAR_ON_JOIN = 5 };
enum { NETWORK_USERID = 7, /*NETWORK_SALT,*/ NETWORK_COUNT/*N users*/ /*...*/, NETWORK_CAPACITY };
API int64_t network_get(uint64_t key); API int64_t network_get(uint64_t key);
API int64_t network_put(uint64_t key, int64_t value); API int64_t network_put(uint64_t key, int64_t value);
@ -338767,6 +338768,7 @@ void network_create(unsigned max_clients, const char *ip, const char *port_, uns
network_put(NETWORK_LIVE, -1); network_put(NETWORK_LIVE, -1);
network_put(NETWORK_COUNT, 0); network_put(NETWORK_COUNT, 0);
network_put(NETWORK_CAPACITY, max_clients); network_put(NETWORK_CAPACITY, max_clients);
network_put(NETWORK_BUF_CLEAR_ON_JOIN, 1);
if( !(flags&NETWORK_CONNECT) || flags&NETWORK_BIND ) { if( !(flags&NETWORK_CONNECT) || flags&NETWORK_BIND ) {
// server, else client // server, else client
@ -338924,6 +338926,16 @@ char** server_poll(unsigned timeout_ms) {
} }
else client_id = next_client_id++; else client_id = next_client_id++;
if (network_get(NETWORK_BUF_CLEAR_ON_JOIN)) {
array(netbuffer_t) *list = map_find(buffers, client_id);
if (list)
for(int i = 0, end = array_count(list); i < end; ++i) {
netbuffer_t *nb = &list[i];
memset(nb->ptr, 0, nb->sz);
}
}
map_find_or_add(clients, event.peer, client_id); map_find_or_add(clients, event.peer, client_id);
map_find_or_add(peers, client_id, event.peer); map_find_or_add(peers, client_id, event.peer);
network_put(NETWORK_COUNT, network_get(NETWORK_COUNT)+1); network_put(NETWORK_COUNT, network_get(NETWORK_COUNT)+1);

View File

@ -305,6 +305,7 @@ void network_create(unsigned max_clients, const char *ip, const char *port_, uns
network_put(NETWORK_LIVE, -1); network_put(NETWORK_LIVE, -1);
network_put(NETWORK_COUNT, 0); network_put(NETWORK_COUNT, 0);
network_put(NETWORK_CAPACITY, max_clients); network_put(NETWORK_CAPACITY, max_clients);
network_put(NETWORK_BUF_CLEAR_ON_JOIN, 1);
if( !(flags&NETWORK_CONNECT) || flags&NETWORK_BIND ) { if( !(flags&NETWORK_CONNECT) || flags&NETWORK_BIND ) {
// server, else client // server, else client
@ -462,6 +463,16 @@ char** server_poll(unsigned timeout_ms) {
} }
else client_id = next_client_id++; else client_id = next_client_id++;
if (network_get(NETWORK_BUF_CLEAR_ON_JOIN)) {
array(netbuffer_t) *list = map_find(buffers, client_id);
if (list)
for(int i = 0, end = array_count(list); i < end; ++i) {
netbuffer_t *nb = &list[i];
memset(nb->ptr, 0, nb->sz);
}
}
map_find_or_add(clients, event.peer, client_id); map_find_or_add(clients, event.peer, client_id);
map_find_or_add(peers, client_id, event.peer); map_find_or_add(peers, client_id, event.peer);
network_put(NETWORK_COUNT, network_get(NETWORK_COUNT)+1); network_put(NETWORK_COUNT, network_get(NETWORK_COUNT)+1);

View File

@ -45,7 +45,8 @@ enum { NETWORK_RANK = 0 }; // [0..N] where 0 is server
enum { NETWORK_PING = 1 }; // NETWORK_BANDWIDTH, NETWORK_QUALITY }; enum { NETWORK_PING = 1 }; // NETWORK_BANDWIDTH, NETWORK_QUALITY };
enum { NETWORK_PORT = 2, NETWORK_IP, NETWORK_LIVE }; enum { NETWORK_PORT = 2, NETWORK_IP, NETWORK_LIVE };
enum { NETWORK_SEND_MS = 4 }; enum { NETWORK_SEND_MS = 4 };
enum { NETWORK_USERID = 5, /*NETWORK_SALT,*/ NETWORK_COUNT/*N users*/ /*...*/, NETWORK_CAPACITY }; enum { NETWORK_BUF_CLEAR_ON_JOIN = 5 };
enum { NETWORK_USERID = 7, /*NETWORK_SALT,*/ NETWORK_COUNT/*N users*/ /*...*/, NETWORK_CAPACITY };
API int64_t network_get(uint64_t key); API int64_t network_get(uint64_t key);
API int64_t network_put(uint64_t key, int64_t value); API int64_t network_put(uint64_t key, int64_t value);

View File

@ -9782,6 +9782,7 @@ void network_create(unsigned max_clients, const char *ip, const char *port_, uns
network_put(NETWORK_LIVE, -1); network_put(NETWORK_LIVE, -1);
network_put(NETWORK_COUNT, 0); network_put(NETWORK_COUNT, 0);
network_put(NETWORK_CAPACITY, max_clients); network_put(NETWORK_CAPACITY, max_clients);
network_put(NETWORK_BUF_CLEAR_ON_JOIN, 1);
if( !(flags&NETWORK_CONNECT) || flags&NETWORK_BIND ) { if( !(flags&NETWORK_CONNECT) || flags&NETWORK_BIND ) {
// server, else client // server, else client
@ -9939,6 +9940,16 @@ char** server_poll(unsigned timeout_ms) {
} }
else client_id = next_client_id++; else client_id = next_client_id++;
if (network_get(NETWORK_BUF_CLEAR_ON_JOIN)) {
array(netbuffer_t) *list = map_find(buffers, client_id);
if (list)
for(int i = 0, end = array_count(list); i < end; ++i) {
netbuffer_t *nb = &list[i];
memset(nb->ptr, 0, nb->sz);
}
}
map_find_or_add(clients, event.peer, client_id); map_find_or_add(clients, event.peer, client_id);
map_find_or_add(peers, client_id, event.peer); map_find_or_add(peers, client_id, event.peer);
network_put(NETWORK_COUNT, network_get(NETWORK_COUNT)+1); network_put(NETWORK_COUNT, network_get(NETWORK_COUNT)+1);

View File

@ -2031,7 +2031,8 @@ enum { NETWORK_RANK = 0 }; // [0..N] where 0 is server
enum { NETWORK_PING = 1 }; // NETWORK_BANDWIDTH, NETWORK_QUALITY }; enum { NETWORK_PING = 1 }; // NETWORK_BANDWIDTH, NETWORK_QUALITY };
enum { NETWORK_PORT = 2, NETWORK_IP, NETWORK_LIVE }; enum { NETWORK_PORT = 2, NETWORK_IP, NETWORK_LIVE };
enum { NETWORK_SEND_MS = 4 }; enum { NETWORK_SEND_MS = 4 };
enum { NETWORK_USERID = 5, /*NETWORK_SALT,*/ NETWORK_COUNT/*N users*/ /*...*/, NETWORK_CAPACITY }; enum { NETWORK_BUF_CLEAR_ON_JOIN = 5 };
enum { NETWORK_USERID = 7, /*NETWORK_SALT,*/ NETWORK_COUNT/*N users*/ /*...*/, NETWORK_CAPACITY };
API int64_t network_get(uint64_t key); API int64_t network_get(uint64_t key);
API int64_t network_put(uint64_t key, int64_t value); API int64_t network_put(uint64_t key, int64_t value);

View File

@ -596,7 +596,7 @@ details > summary::-webkit-details-marker {
|Version: | 2023.7 | |Version: | 2023.7 |
|:--------------|:------------| |:--------------|:------------|
|Branch: | main | |Branch: | main |
|Commit: | 58 | |Commit: | 59 |
<!--| Documentation last modified | { {LAST_MODIFIED} } |--> <!--| Documentation last modified | { {LAST_MODIFIED} } |-->
# [V·4·K 2023.7 ](https://dev.v4.games/zaklaus/v4k) # [V·4·K 2023.7 ](https://dev.v4.games/zaklaus/v4k)
@ -6626,7 +6626,21 @@ Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#str
<details><summary><code lang=C>🄴 enum {;</code></summary> <details><summary><code lang=C>🄴 enum {;</code></summary>
~~~~~~C ~~~~~~C
enum { enum {
NETWORK_USERID = 5, NETWORK_BUF_CLEAR_ON_JOIN = 5
};
~~~~~~
Under construction. Yet to be documented.
Other documentation examples: [dll](#dll), [strsplit](#strsplit), [strjoin](#strjoin), [IMAGE_FLAGS](#IMAGE_FLAGS) or [image_t](#image_t).
</details>
<a name="{"></a>
<details><summary><code lang=C>🄴 enum {;</code></summary>
~~~~~~C
enum {
NETWORK_USERID = 7,
NETWORK_COUNT, NETWORK_COUNT,
NETWORK_CAPACITY NETWORK_CAPACITY
}; };