public static void Destroy(this NetworkingMessage message) { if (message.release == IntPtr.Zero) { throw new InvalidOperationException("Message not created"); } throw new NotImplementedException("Destroy function is not provided in the flat interface on the native side"); }
public static void CopyTo(this NetworkingMessage message, byte[] destination) { if (destination == null) { throw new ArgumentNullException("destination"); } Marshal.Copy(message.data, destination, 0, message.length); }
void OnMessage(ref Valve.Sockets.NetworkingMessage netMessage) { // Debug.Log(String.Format("Message received server - ID: {0}, Channel ID: {1}, Data length: {2}", netMessage.connection, netMessage.channel, netMessage.length)); byte[] messageDataBuffer = new byte[netMessage.length]; netMessage.CopyTo(messageDataBuffer); netMessage.Destroy(); try { NetworkingMessage msg = NetworkingMessageTranslator.ParseMessage(messageDataBuffer); UInt32 clientID = netMessage.connection; switch (msg.type) { case NetworkingMessageType.GAME_STATE: GameState gs = (GameState)NetworkingMessageTranslator.ByteArrayToObject(msg.content); Debug.Log("Server recieved game state: " + gs.state); break; case NetworkingMessageType.CLIENT_USERNAME: string username = (string)NetworkingMessageTranslator.ByteArrayToObject(msg.content); sgr.pm.UpdateUsername(clientID, username); break; case NetworkingMessageType.USER_COMMANDS: UnitCommand uc = (UnitCommand)NetworkingMessageTranslator.ByteArrayToObject(msg.content); Debug.Log("Server recieved unit command: " + uc.entityID); sgr.ReceiveUnitCommand(uc); break; } } catch (Exception ex) { Debug.LogWarning(ex.ToString()); } }
void OnMessage(ref Valve.Sockets.NetworkingMessage netMessage) { // Debug.Log(String.Format("Message received client - ID: {0}, Channel ID: {1}, Data length: {2}", netMessage.connection, netMessage.channel, netMessage.length)); byte[] messageDataBuffer = new byte[netMessage.length]; netMessage.CopyTo(messageDataBuffer); netMessage.Destroy(); try { NetworkingMessage msg = NetworkingMessageTranslator.ParseMessage(messageDataBuffer); switch (msg.type) { case NetworkingMessageType.GAME_STATE: GameState gs = (GameState)NetworkingMessageTranslator.ByteArrayToObject(msg.content); Instance.cgr.ReceiveGameState(gs, msg.frame); break; case NetworkingMessageType.SERVER_SEND_ID: Instance.cgr.playerID = (uint)NetworkingMessageTranslator.ByteArrayToObject(msg.content); Debug.Log("Client received client ID: " + Instance.cgr.playerID); break; case NetworkingMessageType.ENTITY_DATA: List <EntityData> ed = (List <EntityData>)NetworkingMessageTranslator.ByteArrayToObject(msg.content); Instance.cgr.ReceiveEntityData(ed, msg.frame); break; case NetworkingMessageType.ENTITY_STATE: List <EntityState> es = (List <EntityState>)NetworkingMessageTranslator.ByteArrayToObject(msg.content); Instance.cgr.ReceiveEntityState(es, msg.frame); break; case NetworkingMessageType.PLAYER_DATA: List <PlayerData> pd = (List <PlayerData>)NetworkingMessageTranslator.ByteArrayToObject(msg.content); Instance.cgr.ReceivePlayerData(pd, msg.frame); break; case NetworkingMessageType.PLAYER_STATE: List <PlayerState> ps = (List <PlayerState>)NetworkingMessageTranslator.ByteArrayToObject(msg.content); Instance.cgr.ReceivePlayerState(ps, msg.frame); break; } } catch (Exception ex) { Debug.LogWarning(ex.ToString()); } }