/// <summary> /// Calls the corresponding method for each type of received message /// </summary> /// <param name="packet"> The packet that was received</param> /// <param name="handler"> The client handler that called this method</param> private void HandleMessage(Packet packet, ClientHandler handler) { //create a NetworkEvent from the received packet NetworkEvent networkEvent = NetworkEvent.Deserialize(packet.GetDataBytes()); Type type = networkEvent.GetType(); if (type == typeof(HeartBeat)) { RespondToHeartBeat(handler); } else if (type == typeof(InputUpdate)) { RespondToInputUpdate(networkEvent); } else if (type == typeof(ConnectPlayer)) { RespondToConnectPlayer(handler); } else if (type == typeof(DisconnectPlayer)) { RespondToDisconnectPlayer(networkEvent, handler); } else { RespondToUnknownMessage(handler); } }