summaryrefslogtreecommitdiff
path: root/src/net_server.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/net_server.c')
-rw-r--r--src/net_server.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/net_server.c b/src/net_server.c
index 0cba08c..731e232 100644
--- a/src/net_server.c
+++ b/src/net_server.c
@@ -159,6 +159,26 @@ void server_start_game(int* clients, const uint8_t clientcount, const player_lis
}
/**
+ * Server side function; broadcast a selected table stack to all clients
+ * @param[in] clients Array of sockets with connections to clients
+ * @param[in] clientcount Number of sockets/clients
+ * @param[in] stackindex Selected stack to broadcast
+ */
+void server_send_selected_stack(int* clients, const uint8_t clientcount, const uint8_t stackindex)
+{
+ assert(clients != NULL);
+ assert(stackindex <= NUM_TABLE_STACKS);
+
+ uint8_t buf[3];
+ buf[NET_MSG_OFFSET_TYPE] = msg_type_selected_stack_s;
+ buf[NET_MSG_OFFSET_PAYLOAD_LENGTH] = 1;
+ buf[NET_MSG_OFFSET_PAYLOAD] = stackindex;
+
+ for(int i=0; i<clientcount; i++)
+ send(clients[i], buf, 3, 0);
+}
+
+/**
* Server side function; receive hello message from client and read username
* @param[in] sock Socket to use
* @return Username of client
@@ -193,6 +213,17 @@ card* server_recv_selected_card(const uint8_t* payload, const uint8_t payload_le
return c;
}
+uint8_t* server_recv_selected_stack(const uint8_t* payload, const uint8_t payload_len)
+{
+ assert(payload != NULL && payload_len == 1);
+
+ uint8_t* index = malloc(sizeof(uint8_t));
+ assert(index != NULL);
+ *index = payload[0];
+
+ return index;
+}
+
/**
* Server side function; deal cards to a client (send hand)
* @param[in] sock Socket to use