refactor network packets
[carveJwlIkooP6JGAAIwe30JlM.git] / network.c
index 3235c697e84ee7359a9d9a3bd4c739fdd082d2a6..53ebd4bc0bf63ed0e17dfae9e21f806db0e3f411 100644 (file)
--- a/network.c
+++ b/network.c
@@ -1,6 +1,7 @@
 #include "player.h"
 #include "network.h"
 #include "network_msg.h"
+#include "network_common.h"
 #include "player_remote.h"
 
 static void scores_update(void);
@@ -131,18 +132,18 @@ static void server_routine_update(void){
 #endif
 
 static void network_send_username(void){
-   netmsg_playerusername update;
-   memset( &update, 0, sizeof(update) );
-   update.inetmsg_id = k_inetmsg_playerusername;
-   update.index = 0xffffffff;
+   netmsg_playerusername *update = alloca( sizeof(netmsg_playerusername)+
+                                           NETWORK_USERNAME_MAX );
+   update->inetmsg_id = k_inetmsg_playerusername;
+   update->index = 0xffffffff;
 
    ISteamFriends *hSteamFriends = SteamAPI_SteamFriends();
    const char *username = SteamAPI_ISteamFriends_GetPersonaName(hSteamFriends);
-   str_utf8_collapse( username, update.username, sizeof(update.username) );
+   u32 chs = str_utf8_collapse( username, update->name, NETWORK_USERNAME_MAX );
 
    SteamAPI_ISteamNetworkingSockets_SendMessageToConnection(
          hSteamNetworkingSockets, network_client.remote, 
-         &update, sizeof(update),
+         update, sizeof(netmsg_playerusername)+chs+1,
          k_nSteamNetworkingSend_Reliable, NULL );
 }